forked from mirrors/gstreamer-rs
pbutils/element-properties: Add ElementPropertiesMapItem
Also add `field_value` counterpart on both ElementPropertiesGeneralBuilder and ElementPropertiesMapBuilder.
This commit is contained in:
parent
c64b6ac68b
commit
238f9baee5
2 changed files with 102 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
use gst::prelude::*;
|
use gst::prelude::*;
|
||||||
|
|
||||||
use std::ops::Deref;
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
// rustdoc-stripper-ignore-next
|
// rustdoc-stripper-ignore-next
|
||||||
/// Wrapper around `gst::Structure` for `element-properties`
|
/// Wrapper around `gst::Structure` for `element-properties`
|
||||||
|
@ -17,11 +17,11 @@ use std::ops::Deref;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use gstreamer_pbutils::ElementProperties;
|
/// # use gstreamer_pbutils::{ElementProperties, ElementPropertiesMapItem};
|
||||||
/// # gst::init().unwrap();
|
/// # gst::init().unwrap();
|
||||||
/// ElementProperties::builder_map()
|
/// ElementProperties::builder_map()
|
||||||
/// .item(
|
/// .item(
|
||||||
/// gst::Structure::builder("vp8enc")
|
/// ElementPropertiesMapItem::builder("vp8enc")
|
||||||
/// .field("max-quantizer", 17)
|
/// .field("max-quantizer", 17)
|
||||||
/// .field("buffer-size", 20000)
|
/// .field("buffer-size", 20000)
|
||||||
/// .field("threads", 16)
|
/// .field("threads", 16)
|
||||||
|
@ -41,7 +41,7 @@ impl Default for ElementProperties {
|
||||||
impl Deref for ElementProperties {
|
impl Deref for ElementProperties {
|
||||||
type Target = gst::StructureRef;
|
type Target = gst::StructureRef;
|
||||||
|
|
||||||
fn deref(&self) -> &gst::StructureRef {
|
fn deref(&self) -> &Self::Target {
|
||||||
self.0.as_ref()
|
self.0.as_ref()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,9 +102,9 @@ impl ElementProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
// rustdoc-stripper-ignore-next
|
// rustdoc-stripper-ignore-next
|
||||||
/// Returns the inner list of `gst::Structure` if self is_general()
|
/// Returns the inner vec of `ElementPropertiesMapItem` if self is_map()
|
||||||
/// or `None` if self is_map().
|
/// or `None` if self is_general().
|
||||||
pub fn map(&self) -> Option<Vec<gst::Structure>> {
|
pub fn map(&self) -> Option<Vec<ElementPropertiesMapItem>> {
|
||||||
if !self.is_map() {
|
if !self.is_map() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,9 @@ impl ElementProperties {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_slice()
|
.as_slice()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|props_map| props_map.get::<gst::Structure>().unwrap())
|
.map(|props_map| {
|
||||||
|
ElementPropertiesMapItem(props_map.get::<gst::Structure>().unwrap())
|
||||||
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -140,6 +142,11 @@ impl ElementPropertiesGeneralBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn field_value(mut self, property_name: &str, value: glib::SendValue) -> Self {
|
||||||
|
self.structure.set_value(property_name, value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn build(self) -> ElementProperties {
|
pub fn build(self) -> ElementProperties {
|
||||||
ElementProperties(self.structure)
|
ElementProperties(self.structure)
|
||||||
}
|
}
|
||||||
|
@ -152,13 +159,8 @@ pub struct ElementPropertiesMapBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElementPropertiesMapBuilder {
|
impl ElementPropertiesMapBuilder {
|
||||||
// rustdoc-stripper-ignore-next
|
pub fn item(mut self, item: ElementPropertiesMapItem) -> Self {
|
||||||
/// Insert a new `element-properties-map` map item.
|
self.map.push(item.into_inner().to_send_value());
|
||||||
///
|
|
||||||
/// The `structure`s name is the element factory's name
|
|
||||||
/// and each field corresponds to a property-value pair.
|
|
||||||
pub fn item(mut self, structure: gst::Structure) -> Self {
|
|
||||||
self.map.push(structure.to_send_value());
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +173,88 @@ impl ElementPropertiesMapBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rustdoc-stripper-ignore-next
|
||||||
|
/// Wrapper around `gst::Structure` for `element-properties-map` map item.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # use gstreamer_pbutils::{ElementProperties, ElementPropertiesMapItem};
|
||||||
|
/// # gst::init().unwrap();
|
||||||
|
/// ElementProperties::builder_map()
|
||||||
|
/// .item(
|
||||||
|
/// ElementPropertiesMapItem::builder("vp8enc")
|
||||||
|
/// .field("max-quantizer", 17)
|
||||||
|
/// .field("buffer-size", 20000)
|
||||||
|
/// .field("threads", 16)
|
||||||
|
/// .build(),
|
||||||
|
/// )
|
||||||
|
/// .build();
|
||||||
|
/// ```
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ElementPropertiesMapItem(gst::Structure);
|
||||||
|
|
||||||
|
impl Deref for ElementPropertiesMapItem {
|
||||||
|
type Target = gst::StructureRef;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
self.0.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for ElementPropertiesMapItem {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
self.0.deref_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ElementPropertiesMapItem> for gst::Structure {
|
||||||
|
fn from(e: ElementPropertiesMapItem) -> Self {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
|
||||||
|
e.into_inner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ElementPropertiesMapItem {
|
||||||
|
pub fn builder(factory_name: &str) -> ElementPropertiesMapItemBuilder {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
|
ElementPropertiesMapItemBuilder {
|
||||||
|
structure: gst::Structure::new_empty(factory_name),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn into_inner(self) -> gst::Structure {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use = "The builder must be built to be used"]
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ElementPropertiesMapItemBuilder {
|
||||||
|
structure: gst::Structure,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ElementPropertiesMapItemBuilder {
|
||||||
|
pub fn field<T>(mut self, property_name: &str, value: T) -> Self
|
||||||
|
where
|
||||||
|
T: ToSendValue + Sync,
|
||||||
|
{
|
||||||
|
self.structure.set(property_name, value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn field_value(mut self, property_name: &str, value: glib::SendValue) -> Self {
|
||||||
|
self.structure.set_value(property_name, value);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build(self) -> ElementPropertiesMapItem {
|
||||||
|
ElementPropertiesMapItem(self.structure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -187,7 +271,7 @@ mod test {
|
||||||
assert!(!elem_props_general.is_map());
|
assert!(!elem_props_general.is_map());
|
||||||
assert_eq!(elem_props_general.map(), None);
|
assert_eq!(elem_props_general.map(), None);
|
||||||
|
|
||||||
let elem_factory_props_map = gst::Structure::builder("vp8enc")
|
let elem_factory_props_map = ElementPropertiesMapItem::builder("vp8enc")
|
||||||
.field("cq-level", 13)
|
.field("cq-level", 13)
|
||||||
.field("resize-allowed", false)
|
.field("resize-allowed", false)
|
||||||
.build();
|
.build();
|
||||||
|
@ -217,7 +301,7 @@ mod test {
|
||||||
fn element_properties_map_builder() {
|
fn element_properties_map_builder() {
|
||||||
gst::init().unwrap();
|
gst::init().unwrap();
|
||||||
|
|
||||||
let props_map = gst::Structure::builder("vp8enc")
|
let props_map = ElementPropertiesMapItem::builder("vp8enc")
|
||||||
.field("cq-level", 13)
|
.field("cq-level", 13)
|
||||||
.field("resize-allowed", false)
|
.field("resize-allowed", false)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -46,7 +46,7 @@ pub use crate::auto::*;
|
||||||
#[cfg(feature = "v1_20")]
|
#[cfg(feature = "v1_20")]
|
||||||
mod element_properties;
|
mod element_properties;
|
||||||
#[cfg(feature = "v1_20")]
|
#[cfg(feature = "v1_20")]
|
||||||
pub use crate::element_properties::ElementProperties;
|
pub use crate::element_properties::{ElementProperties, ElementPropertiesMapItem};
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
mod flag_serde;
|
mod flag_serde;
|
||||||
|
|
Loading…
Reference in a new issue