gst: structure: deprecate Quarks and use IdStr

Update Structure API:

* Quarks API are deprecated. Methods which were internally calling quarks
  methods now call C string based methods.
* Added new `IdStr` methods.

See also:

* https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7432
* https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7613
* https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7644

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1531>
This commit is contained in:
François Laignel 2024-10-06 22:01:23 +02:00
parent c2cc048803
commit 2d2ded555e
8 changed files with 1459 additions and 67 deletions

View file

@ -1,6 +1,6 @@
use std::ops::{Bound::*, RangeBounds}; use std::ops::{Bound::*, RangeBounds};
use gst::Caps; use gst::{Caps, IdStr};
use glib::IntoGStr; use glib::IntoGStr;
@ -422,6 +422,36 @@ impl<T> AudioCapsBuilder<T> {
} }
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given value `value`.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_static(
self,
name: impl AsRef<glib::GStr> + 'static,
value: impl Into<glib::Value> + Send,
) -> Self {
Self {
builder: self.builder.field_with_static(name, value),
}
}
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given value `value`.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_id(
self,
name: impl AsRef<IdStr>,
value: impl Into<glib::Value> + Send,
) -> Self {
Self {
builder: self.builder.field_with_id(name, value),
}
}
gst::impl_builder_gvalue_extra_setters!(field); gst::impl_builder_gvalue_extra_setters!(field);
#[must_use] #[must_use]

View file

@ -1,6 +1,6 @@
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use gst::prelude::*; use gst::{prelude::*, IdStr};
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Wrapper around `gst::Structure` for `element-properties` /// Wrapper around `gst::Structure` for `element-properties`
@ -150,6 +150,32 @@ impl ElementPropertiesGeneralBuilder {
self self
} }
// rustdoc-stripper-ignore-next
/// Sets property `property_name` to the given value `value`.
///
/// Overrides any default or previously defined value for `property_name`.
pub fn field_with_static(
mut self,
property_name: impl AsRef<glib::GStr> + 'static,
value: impl Into<glib::Value> + Send,
) -> Self {
self.structure.set_with_static(property_name, value);
self
}
// rustdoc-stripper-ignore-next
/// Sets property `property_name` to the given value `value`.
///
/// Overrides any default or previously defined value for `property_name`.
pub fn field_with_id(
mut self,
property_name: impl AsRef<IdStr>,
value: impl Into<glib::Value> + Send,
) -> Self {
self.structure.set_with_id(property_name, value);
self
}
gst::impl_builder_gvalue_extra_setters!(field); gst::impl_builder_gvalue_extra_setters!(field);
pub fn field_value(mut self, property_name: &str, value: glib::SendValue) -> Self { pub fn field_value(mut self, property_name: &str, value: glib::SendValue) -> Self {
@ -288,6 +314,32 @@ impl ElementPropertiesMapItemBuilder {
self self
} }
// rustdoc-stripper-ignore-next
/// Sets property `property_name` to the given value `value`.
///
/// Overrides any default or previously defined value for `property_name`.
pub fn field_with_static(
mut self,
property_name: impl AsRef<glib::GStr> + 'static,
value: impl Into<glib::Value> + Send,
) -> Self {
self.structure.set_with_static(property_name, value);
self
}
// rustdoc-stripper-ignore-next
/// Sets property `property_name` to the given value `value`.
///
/// Overrides any default or previously defined value for `property_name`.
pub fn field_with_id(
mut self,
property_name: impl AsRef<IdStr>,
value: impl Into<glib::Value> + Send,
) -> Self {
self.structure.set_with_id(property_name, value);
self
}
gst::impl_builder_gvalue_extra_setters!(field); gst::impl_builder_gvalue_extra_setters!(field);
pub fn field_value(mut self, property_name: &str, value: glib::SendValue) -> Self { pub fn field_value(mut self, property_name: &str, value: glib::SendValue) -> Self {

View file

@ -4,6 +4,7 @@ use std::fmt;
use crate::ffi; use crate::ffi;
use glib::{translate::*, SendValue}; use glib::{translate::*, SendValue};
use gst::IdStr;
gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || { gst::mini_object_wrapper!(RTSPToken, RTSPTokenRef, ffi::GstRTSPToken, || {
ffi::gst_rtsp_token_get_type() ffi::gst_rtsp_token_get_type()
@ -108,6 +109,32 @@ impl Builder {
self self
} }
pub fn field_with_static(
mut self,
name: impl AsRef<glib::GStr> + 'static,
value: impl Into<glib::Value> + Send,
) -> Self {
self.token
.get_mut()
.unwrap()
.structure_mut()
.set_with_static(name, value);
self
}
pub fn field_with_id(
mut self,
name: impl AsRef<IdStr>,
value: impl Into<glib::Value> + Send,
) -> Self {
self.token
.get_mut()
.unwrap()
.structure_mut()
.set_with_id(name, value);
self
}
gst::impl_builder_gvalue_extra_setters!(field); gst::impl_builder_gvalue_extra_setters!(field);
#[must_use = "Building the structure without using it has no effect"] #[must_use = "Building the structure without using it has no effect"]

View file

@ -1,7 +1,7 @@
use std::ops::{Bound::*, RangeBounds}; use std::ops::{Bound::*, RangeBounds};
use glib::translate::*; use glib::translate::*;
use gst::Caps; use gst::{Caps, IdStr};
use crate::VideoFormat; use crate::VideoFormat;
@ -530,6 +530,36 @@ impl<T> VideoCapsBuilder<T> {
} }
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given value `value`.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_static(
self,
name: impl AsRef<glib::GStr> + 'static,
value: impl Into<glib::Value> + Send,
) -> Self {
Self {
builder: self.builder.field_with_static(name, value),
}
}
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given value `value`.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_id(
self,
name: impl AsRef<IdStr>,
value: impl Into<glib::Value> + Send,
) -> Self {
Self {
builder: self.builder.field_with_id(name, value),
}
}
gst::impl_builder_gvalue_extra_setters!(field); gst::impl_builder_gvalue_extra_setters!(field);
#[must_use] #[must_use]

View file

@ -8,7 +8,7 @@ use glib::{
value::{SendValue, ToSendValue}, value::{SendValue, ToSendValue},
}; };
use crate::{caps_features::*, ffi, structure::*, CapsIntersectMode}; use crate::{caps_features::*, ffi, structure::*, CapsIntersectMode, IdStr};
mini_object_wrapper!(Caps, CapsRef, ffi::GstCaps, || { ffi::gst_caps_get_type() }); mini_object_wrapper!(Caps, CapsRef, ffi::GstCaps, || { ffi::gst_caps_get_type() });
@ -1116,6 +1116,34 @@ impl<T> Builder<T> {
self self
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given value `value`.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_static(
mut self,
name: impl AsRef<glib::GStr> + 'static,
value: impl Into<glib::Value> + Send,
) -> Self {
self.s.set_with_static(name, value);
self
}
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given value `value`.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_id(
mut self,
name: impl AsRef<IdStr>,
value: impl Into<glib::Value> + Send,
) -> Self {
self.s.set_with_id(name, value);
self
}
impl_builder_gvalue_extra_setters!(field); impl_builder_gvalue_extra_setters!(field);
#[must_use = "Building the caps without using them has no effect"] #[must_use = "Building the caps without using them has no effect"]

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,7 @@ use crate::{
date_time_serde, value::*, value_serde::*, Buffer, DateTime, Sample, Structure, StructureRef, date_time_serde, value::*, value_serde::*, Buffer, DateTime, Sample, Structure, StructureRef,
}; };
struct FieldSe<'a>(&'static str, &'a glib::SendValue); struct FieldSe<'a>(&'a str, &'a glib::SendValue);
impl<'a> Serialize for FieldSe<'a> { impl<'a> Serialize for FieldSe<'a> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
ser_value!(self.1, |type_, value| { ser_value!(self.1, |type_, value| {

View file

@ -1481,6 +1481,34 @@ macro_rules! impl_builder_gvalue_extra_setters (
} }
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given inner value if the `predicate` evaluates to `true`.
///
/// This has no effect if the `predicate` evaluates to `false`,
/// i.e. default or previous value for `name` is kept.
#[inline]
pub fn field_with_static_if(self, name: impl AsRef<$crate::glib::GStr> + 'static, value: impl Into<$crate::glib::Value> + Send, predicate: bool) -> Self {
if predicate {
self.field_with_static(name, value)
} else {
self
}
}
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given inner value if the `predicate` evaluates to `true`.
///
/// This has no effect if the `predicate` evaluates to `false`,
/// i.e. default or previous value for `name` is kept.
#[inline]
pub fn field_with_id_if(self, name: impl AsRef<$crate::IdStr>, value: impl Into<$crate::glib::Value> + Send, predicate: bool) -> Self {
if predicate {
self.field_with_id(name, value)
} else {
self
}
}
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Sets field `name` to the given inner value if `value` is `Some`. /// Sets field `name` to the given inner value if `value` is `Some`.
/// ///
@ -1494,6 +1522,32 @@ macro_rules! impl_builder_gvalue_extra_setters (
} }
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given inner value if `value` is `Some`.
///
/// This has no effect if the value is `None`, i.e. default or previous value for `name` is kept.
#[inline]
pub fn field_with_static_if_some(self, name: impl AsRef<$crate::glib::GStr> + 'static, value: Option<impl Into<$crate::glib::Value> + Send>) -> Self {
if let Some(value) = value {
self.field_with_static(name, value)
} else {
self
}
}
// rustdoc-stripper-ignore-next
/// Sets field `name` to the given inner value if `value` is `Some`.
///
/// This has no effect if the value is `None`, i.e. default or previous value for `name` is kept.
#[inline]
pub fn field_with_id_if_some(self, name: impl AsRef<$crate::IdStr>, value: Option<impl Into<$crate::glib::Value> + Send>) -> Self {
if let Some(value) = value {
self.field_with_id(name, value)
} else {
self
}
}
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Sets field `name` using the given `ValueType` `V` built from `iter`'s the `Item`s. /// Sets field `name` using the given `ValueType` `V` built from `iter`'s the `Item`s.
/// ///
@ -1508,6 +1562,34 @@ macro_rules! impl_builder_gvalue_extra_setters (
self.field(name, V::from_iter(iter)) self.field(name, V::from_iter(iter))
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` using the given `ValueType` `V` built from `iter`'s the `Item`s.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_static_from_iter<V: $crate::glib::value::ValueType + Into<$crate::glib::Value> + FromIterator<$crate::glib::SendValue> + Send>(
self,
name: impl AsRef<$crate::glib::GStr> + 'static,
iter: impl IntoIterator<Item = impl $crate::glib::value::ToSendValue>,
) -> Self {
let iter = iter.into_iter().map(|item| item.to_send_value());
self.field_with_static(name, V::from_iter(iter))
}
// rustdoc-stripper-ignore-next
/// Sets field `name` using the given `ValueType` `V` built from `iter`'s the `Item`s.
///
/// Overrides any default or previously defined value for `name`.
#[inline]
pub fn field_with_id_from_iter<V: $crate::glib::value::ValueType + Into<$crate::glib::Value> + FromIterator<$crate::glib::SendValue> + Send>(
self,
name: impl AsRef<$crate::IdStr>,
iter: impl IntoIterator<Item = impl $crate::glib::value::ToSendValue>,
) -> Self {
let iter = iter.into_iter().map(|item| item.to_send_value());
self.field_with_id(name, V::from_iter(iter))
}
// rustdoc-stripper-ignore-next // rustdoc-stripper-ignore-next
/// Sets field `name` using the given `ValueType` `V` built from `iter`'s Item`s, /// Sets field `name` using the given `ValueType` `V` built from `iter`'s Item`s,
/// if `iter` is not empty. /// if `iter` is not empty.
@ -1527,6 +1609,46 @@ macro_rules! impl_builder_gvalue_extra_setters (
self self
} }
} }
// rustdoc-stripper-ignore-next
/// Sets field `name` using the given `ValueType` `V` built from `iter`'s Item`s,
/// if `iter` is not empty.
///
/// This has no effect if `iter` is empty, i.e. previous value for `name` is unchanged.
#[inline]
pub fn field_with_static_if_not_empty<V: $crate::glib::value::ValueType + Into<$crate::glib::Value> + FromIterator<$crate::glib::SendValue> + Send>(
self,
name: impl AsRef<$crate::glib::GStr> + 'static,
iter: impl IntoIterator<Item = impl $crate::glib::value::ToSendValue>,
) -> Self {
let mut iter = iter.into_iter().peekable();
if iter.peek().is_some() {
let iter = iter.map(|item| item.to_send_value());
self.field_with_static(name, V::from_iter(iter))
} else {
self
}
}
// rustdoc-stripper-ignore-next
/// Sets field `name` using the given `ValueType` `V` built from `iter`'s Item`s,
/// if `iter` is not empty.
///
/// This has no effect if `iter` is empty, i.e. previous value for `name` is unchanged.
#[inline]
pub fn field_with_id_if_not_empty<V: $crate::glib::value::ValueType + Into<$crate::glib::Value> + FromIterator<$crate::glib::SendValue> + Send>(
self,
name: impl AsRef<IdStr>,
iter: impl IntoIterator<Item = impl $crate::glib::value::ToSendValue>,
) -> Self {
let mut iter = iter.into_iter().peekable();
if iter.peek().is_some() {
let iter = iter.map(|item| item.to_send_value());
self.field_with_id(name, V::from_iter(iter))
} else {
self
}
}
}; };
(other_field) => { (other_field) => {