Commit graph

39 commits

Author SHA1 Message Date
François Laignel e0d9f886e3 gst/format: add Signed::{positive, negative}
It's more convenient to use than:

```rust
    signed_val.positive_or(()).ok()
```
2022-09-21 17:20:43 +00:00
Sebastian Dröge 8a6de3ca4f gstreamer: Implement various operations on Signed for working with it more easily 2022-09-14 12:20:47 +03:00
François Laignel 069c6a2c01 Rename feature 'ser_de' as 'serde'
When I introduced the 'ser_de' feature, I couldn't find a way to
name it 'serde' while also make it pull the optional 'serde'
crate together with the other related dependencies.

With rustc >= 1.60 we can use 'dep:serde' to refer to the 'serde'
dependency as part of the 'serde' feature.
2022-09-12 19:36:30 +02:00
François Laignel 414222aa99 gst/format: Signed wrapper
Functions such as Segment::to_running_time_full replicate the C
signature for the return type: an integer indicates whether the
resulting value must be interpreted as positive or negative.
In Rust, alternatives are usually represented using an enum.

This commit implements an enum wrapper to represent the sign
and adds functions to FormattedValue to ease Signed handling.
2022-07-18 23:26:20 +02:00
François Laignel 865df62f8d gst/format: add CompatibleFormattedValue
The trait CompatibleFormattedValue can be used to check argument
compatibility to a certain Format. This is convenient to define
function which accept several FormattedValues which must hold
values of the same Format.

This trait enforces format compatibility at compilation time for
SpecificFormattedValues and at runtime when a GenericFormattedValue
is provided.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
2022-07-11 19:45:52 +02:00
François Laignel fe319af598 Implement FormattedValue on any candidate type
The trait FormattedValue was only implemented on types which
could implement the full range of values for a Format. In order
to declare a function which could take both the intrinsic type
of any Format (e.g. `ClockTime`) as well the full range of values
(e.g. `Option<ClockTime>`), the argument was declared:

```rust
    impl Into<GenericFormattedValue>,
```

This commit implements `FormattedValue` for any type representing
a format. E.g.: both `ClockTime` and `Option<ClockTime>` will now
implement `FormattedValue`. The trait `FormattedValueFullRange`
is implemented on types which can be built from any raw value.

These changes are intended to help for the implementation of a
means to enforce format conformity at compilation time for
functions with multiple formatted value arguments.

The following signatures were found to be incorrect and are fixed:

- `message::StepDone`: forced the type for `amount` and `duration`
  to be of the same type, when `duration` is expected to be of the
  `Time` format.
- `query::Convert::set`: the two arguments were forced to the same
  type, so potentialy the same format, unless a
  `GenericFormattedValue` was used.

See https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1059
2022-07-11 19:45:52 +02:00
Sebastian Dröge f6dc14b946 Add a few missing docs aliases for constants 2021-12-03 10:19:22 +02:00
Sebastian Dröge cdfe4b3d67 Remove unneeded std::convert::TryFrom/TryInto and std::str::FromStr imports 2021-10-31 18:20:31 +02:00
François Laignel deb22b264e format, clock_time: gather macros together
The modules format and clock_time share common macros which are
scattered between each modules. This cross reference makes it
difficult to maintain the macros.

This commit also make it possible to use macro
impl_common_ops_for_newtype_uint for Percent.
2021-10-18 14:30:59 +02:00
François Laignel 986a136492 clock_time & format: basic opt-ops impl
The option-operations crate provides traits to improve usability
when dealing with `Option`s, which is often the case with
`ClockTime` & most formats.
2021-10-18 14:30:59 +02:00
François Laignel 051df59cd1 clock_time, format: fix checked, saturating, wrapping ops
These operations were implemented using the integer implementations.
These types' MAX values are different from the integers so they must
use specific implementations.

Also add the overflowing variants.
2021-10-18 14:30:59 +02:00
François Laignel 90bb458e64 Rework ClockTime & FormattedValues 2021-06-04 22:09:38 +02:00
François Laignel 49583597ed manual code: fix-getters-def doc aliases 2021-05-03 20:46:57 +02:00
Marijn Suijten 1eb0c483fe gstreamer: Fix some clippy::use_self warnings 2021-04-30 10:58:36 +02:00
François Laignel e80a29372a fix-getters-def 0.3.0 pass 2021-04-20 18:18:02 +02:00
François Laignel 53be8e5f58 fix-getters-{def,calls} pass 2021-04-13 17:54:40 +02:00
Marijn Suijten c4a06e515b gstreamer/format,value: Skip init in functions that contain self
These functions were changed to return Self instead of the direct name
of the type, and are hence caught by the init checker.

Also remove some tabs that sit in the macro but are not cleaned up by
the formatter.
2021-01-08 11:50:31 +01:00
Marijn Suijten 4cb6b64e2d gstreamer/format,value: Use Self in more places 2021-01-08 11:49:46 +01:00
Marijn Suijten 9890803cc6 gstreamer: Fix clippy::from_over_into 2021-01-08 11:43:14 +01:00
Guillaume Gomez ff5a36561a Fix license header situation 2020-12-15 11:53:31 +01:00
Sebastian Dröge 9d9522016b gstreamer: Update manual code to 2018 edition 2020-11-22 19:15:20 +02:00
François Laignel ae9d97dfca ClockTime & opt Formats: fix PartialOrd impl, remove Ord and add min & max
- `PartialOrd` was returning `true` for expressions such as
  - `ClockTime::none() < ClockTime::from_seconds(1)`.
  - `ClockTime::from_seconds(1) > ClockTime::none()`.
- Remove `Ord` because `ClockTime` is not a total order due to
  `ClockTime::none()`. See test `not_ord`.

This also applies to others `Format(Option<{u32,u64}>)` types.
2020-10-20 23:40:18 +02:00
Sebastian Dröge d417656707 Use thiserror more widely for deriving Error/Display impls of error types 2020-05-26 19:26:35 +03:00
Guillaume Gomez c07fe14191 gstreamer*: Add missing init checks 2020-04-12 17:25:54 +03:00
Sebastian Dröge 94ace06883 Remove deprecated std::error::Error::description() impls 2020-04-11 19:39:04 +03:00
Sebastian Dröge d44c293753 Use TryFrom/TryInto traits where it makes sense instead of our previous ad-hoc solutions 2019-06-03 18:42:34 +03:00
Sebastian Dröge fdb95f0033 gstreamer/format: Implement formatted value arithmetic with overflow checks
We have a value to represent invalid/overflow anyway, so let's make sure
that all operations are actually not overflowing and if they do we
assigned that value to the result.
2019-06-03 08:25:43 +00:00
Sebastian Dröge fbcdf90386 gstreamer/format: Add various other arithmetic operation impls for the different formatted values
This includes gst::ClockTime.
2019-06-03 08:25:43 +00:00
François Laignel 9f2f684188 format: serde: avoid redundant () for some types 2018-07-30 23:18:30 +03:00
François Laignel ab9cd29bd6 serde: fmt pass
Note: clippy didn't raise any warning
2018-07-30 23:18:30 +03:00
François Laignel 90b046fbcf serde: separate serde impl and tests from base module
+ fix erroneous `datetime` instead of `buffer` in `BufferRef::serialize`
+ remove ser/de for `Value`s with types `ULong` & `ILong`
2018-07-30 23:18:30 +03:00
François Laignel a2c4e78f70 GenericFormattedValue: serde impl 2018-07-30 23:18:30 +03:00
Sebastian Dröge 694bcaa697 Fix all clippy warnings
Or silence the ones we don't care about.
2018-07-20 10:28:20 +03:00
Sebastian Dröge 2cefd9aea6 Re-run everything through rustfmt 2018-04-25 11:13:14 +03:00
Sebastian Dröge 492c3d656c Run everything through rustfmt again 2018-04-01 11:57:58 +03:00
Sebastian Dröge e0dc84c10a Run everything through rustfmt again 2017-12-20 19:30:14 +02:00
Sebastian Dröge 5065bc76ee Rename FormattedValue::from_glib/to_glib to from_raw/to_raw_value
Otherwise we conflict with GLib translation traits, which causes some
annoyances.
2017-12-10 12:10:25 +02:00
Sebastian Dröge c99928d030 Change FormatValue related API to be more convenient to use
FormatValue is now renamed to GenericFormattedValue and the API slightly
changed. In addition there is now a FormattedValue trait, and a
SpecificFormattedValue trait plus types for Bytes, Buffers and the
existing ClockTime.

This allows to create functions like
  Pad::query_duration<F: SpecificFormattedValue>() -> Option<F>
and doesn't require the caller to unwrap the generic value anymore,
which is completely unneeded in these cases.

In addition, Segment became FormattedSegment<T> with API to
upcast/downcast between the specific formatted values and the generic
formatted value. This greatly simplifies usage of Segments.
2017-12-09 19:45:18 +02:00
Sebastian Dröge c39c0c7264 Implement ClockTime as ClockTime(Option<u64>)
And also implement a FormatValue type that holds a value together with
its format to make usage of the positions/durations/seek positions/etc
more convenient and safe.

Fixes https://github.com/sdroege/gstreamer-rs/issues/3
2017-11-11 11:57:29 +01:00