From c0707bed941c91d426788496c9b31a678033c768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 11 Jul 2017 00:02:08 +0300 Subject: [PATCH] Add initial caps bindings --- Gir_Gst.toml | 29 +- examples/src/decodebin.rs | 14 +- gstreamer/src/auto/alias.rs | 2 +- gstreamer/src/auto/bin.rs | 2 +- gstreamer/src/auto/bus.rs | 2 +- gstreamer/src/auto/clock.rs | 2 +- gstreamer/src/auto/device.rs | 32 ++- gstreamer/src/auto/device_monitor.rs | 17 +- gstreamer/src/auto/device_provider.rs | 2 +- gstreamer/src/auto/device_provider_factory.rs | 2 +- gstreamer/src/auto/element.rs | 57 ++-- gstreamer/src/auto/element_factory.rs | 45 +-- gstreamer/src/auto/enums.rs | 38 ++- gstreamer/src/auto/flags.rs | 2 +- gstreamer/src/auto/functions.rs | 6 +- gstreamer/src/auto/mod.rs | 3 +- gstreamer/src/auto/object.rs | 2 +- gstreamer/src/auto/pad.rs | 87 +++--- gstreamer/src/auto/pad_template.rs | 39 +-- gstreamer/src/auto/pipeline.rs | 2 +- gstreamer/src/auto/plugin.rs | 2 +- gstreamer/src/auto/stream.rs | 76 ++--- gstreamer/src/auto/stream_collection.rs | 2 +- gstreamer/src/auto/u_r_i_handler.rs | 2 +- gstreamer/src/caps.rs | 263 ++++++++++++++++++ gstreamer/src/lib.rs | 2 + gstreamer/src/structure.rs | 7 +- 27 files changed, 564 insertions(+), 175 deletions(-) create mode 100644 gstreamer/src/caps.rs diff --git a/Gir_Gst.toml b/Gir_Gst.toml index e198dea2b..e63d6ce97 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -24,6 +24,7 @@ generate = [ "Gst.FlowReturn", "Gst.PadDirection", "Gst.PadTemplate", + "Gst.PadPresence", "Gst.URIHandler", "Gst.URIType", "Gst.ElementFactoryListType", @@ -100,6 +101,11 @@ trait = false # Uses enum as flags ignore = true +[[object]] +name = "Gst.Caps" +status = "manual" +ref_mode = "ref" + [[object]] name = "Gst.Clock" status = "generate" @@ -131,11 +137,21 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to link elements" + [[object.function]] + name = "link_filtered" + [object.function.return] + bool_return_is_error = "Failed to link elements" + [[object.function]] name = "link_pads" [object.function.return] bool_return_is_error = "Failed to link pads" + [[object.function]] + name = "link_pads_filtered" + [object.function.return] + bool_return_is_error = "Failed to link pads" + [[object.function]] name = "seek" [object.function.return] @@ -164,14 +180,14 @@ trait = false [[object]] name = "Gst.Device" status = "generate" - [[object.function]] - name = "get_properties" + [[object.property]] + name = "properties" # Structure is not a GObject ignore = true [[object.property]] - name = "properties" - # Structure is not a GObject + name = "caps" + # Caps is not a GObject ignore = true @@ -231,6 +247,11 @@ status = "generate" [object.function.return] bool_return_is_error = "Failed to activate pad" + [[object.property]] + name = "caps" + # Caps is not a GObject + ignore = true + [[object]] name = "Gst.Plugin" status = "generate" diff --git a/examples/src/decodebin.rs b/examples/src/decodebin.rs index e156297c1..7f4db08ef 100644 --- a/examples/src/decodebin.rs +++ b/examples/src/decodebin.rs @@ -4,10 +4,6 @@ use gst::ObjectExt as GstObjectExt; extern crate glib; use glib::ObjectExt; -use glib::translate::{from_glib_none, ToGlibPtr}; - -extern crate gstreamer_sys as gst_ffi; -extern crate gobject_sys as gobject_ffi; use std::env; use std::u64; @@ -36,12 +32,10 @@ fn main() { decodebin.connect_pad_added(move |_, src_pad| { let ref pipeline = pipeline_clone; - // FIXME: Needs caps/structure bindings - let (is_audio, is_video) = unsafe { - let caps = gst_ffi::gst_pad_get_current_caps(src_pad.to_glib_none().0); - let structure = gst_ffi::gst_caps_get_structure(caps, 0); - - let name: String = from_glib_none(gst_ffi::gst_structure_get_name(structure)); + let (is_audio, is_video) = { + let caps = src_pad.get_current_caps().unwrap(); + let structure = caps.get_structure(0).unwrap(); + let name = structure.get_name(); (name.starts_with("audio/"), name.starts_with("video/")) }; diff --git a/gstreamer/src/auto/alias.rs b/gstreamer/src/auto/alias.rs index a886f120c..ed26d3760 100644 --- a/gstreamer/src/auto/alias.rs +++ b/gstreamer/src/auto/alias.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT pub type ClockTime = u64; diff --git a/gstreamer/src/auto/bin.rs b/gstreamer/src/auto/bin.rs index ee65abe33..eaf5ec87d 100644 --- a/gstreamer/src/auto/bin.rs +++ b/gstreamer/src/auto/bin.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Element; diff --git a/gstreamer/src/auto/bus.rs b/gstreamer/src/auto/bus.rs index 435c8c1bc..96ac247da 100644 --- a/gstreamer/src/auto/bus.rs +++ b/gstreamer/src/auto/bus.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use ClockTime; diff --git a/gstreamer/src/auto/clock.rs b/gstreamer/src/auto/clock.rs index 4ad64e5b0..ae5ce9638 100644 --- a/gstreamer/src/auto/clock.rs +++ b/gstreamer/src/auto/clock.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use ClockTime; diff --git a/gstreamer/src/auto/device.rs b/gstreamer/src/auto/device.rs index 25f38a187..cd9344f96 100644 --- a/gstreamer/src/auto/device.rs +++ b/gstreamer/src/auto/device.rs @@ -1,8 +1,10 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT +use Caps; use Element; use Object; +use Structure; use ffi; use glib; use glib::Value; @@ -29,20 +31,20 @@ unsafe impl Sync for Device {} pub trait DeviceExt { fn create_element<'a, P: Into>>(&self, name: P) -> Option; - //fn get_caps(&self) -> /*Ignored*/Option; + fn get_caps(&self) -> Option; fn get_device_class(&self) -> Option; fn get_display_name(&self) -> Option; + fn get_properties(&self) -> Option; + fn has_classes(&self, classes: &str) -> bool; fn has_classesv(&self, classes: &[&str]) -> bool; fn reconfigure_element>(&self, element: &P) -> bool; - //fn get_property_caps(&self) -> /*Ignored*/Option; - fn get_property_device_class(&self) -> Option; fn get_property_display_name(&self) -> Option; @@ -59,9 +61,11 @@ impl + IsA> DeviceExt for O { } } - //fn get_caps(&self) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_device_get_caps() } - //} + fn get_caps(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_device_get_caps(self.to_glib_none().0)) + } + } fn get_device_class(&self) -> Option { unsafe { @@ -75,6 +79,12 @@ impl + IsA> DeviceExt for O { } } + fn get_properties(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_device_get_properties(self.to_glib_none().0)) + } + } + fn has_classes(&self, classes: &str) -> bool { unsafe { from_glib(ffi::gst_device_has_classes(self.to_glib_none().0, classes.to_glib_none().0)) @@ -93,14 +103,6 @@ impl + IsA> DeviceExt for O { } } - //fn get_property_caps(&self) -> /*Ignored*/Option { - // let mut value = Value::from(None::<&/*Ignored*/Caps>); - // unsafe { - // gobject_ffi::g_object_get_property(self.to_glib_none().0, "caps".to_glib_none().0, value.to_glib_none_mut().0); - // } - // value.get() - //} - fn get_property_device_class(&self) -> Option { let mut value = Value::from(None::<&str>); unsafe { diff --git a/gstreamer/src/auto/device_monitor.rs b/gstreamer/src/auto/device_monitor.rs index 229ca7497..1c1862582 100644 --- a/gstreamer/src/auto/device_monitor.rs +++ b/gstreamer/src/auto/device_monitor.rs @@ -1,7 +1,8 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Bus; +use Caps; use Device; use Object; use ffi; @@ -32,7 +33,7 @@ unsafe impl Send for DeviceMonitor {} unsafe impl Sync for DeviceMonitor {} pub trait DeviceMonitorExt { - //fn add_filter<'a, 'b, P: Into>, Q: Into>>(&self, classes: P, caps: Q) -> u32; + fn add_filter<'a, 'b, P: Into>, Q: Into>>(&self, classes: P, caps: Q) -> u32; fn get_bus(&self) -> Option; @@ -56,9 +57,15 @@ pub trait DeviceMonitorExt { } impl + IsA> DeviceMonitorExt for O { - //fn add_filter<'a, 'b, P: Into>, Q: Into>>(&self, classes: P, caps: Q) -> u32 { - // unsafe { TODO: call ffi::gst_device_monitor_add_filter() } - //} + fn add_filter<'a, 'b, P: Into>, Q: Into>>(&self, classes: P, caps: Q) -> u32 { + let classes = classes.into(); + let classes = classes.to_glib_none(); + let caps = caps.into(); + let caps = caps.to_glib_none(); + unsafe { + ffi::gst_device_monitor_add_filter(self.to_glib_none().0, classes.0, caps.0) + } + } fn get_bus(&self) -> Option { unsafe { diff --git a/gstreamer/src/auto/device_provider.rs b/gstreamer/src/auto/device_provider.rs index 23759126c..485a6ee06 100644 --- a/gstreamer/src/auto/device_provider.rs +++ b/gstreamer/src/auto/device_provider.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Bus; diff --git a/gstreamer/src/auto/device_provider_factory.rs b/gstreamer/src/auto/device_provider_factory.rs index 650edcf46..7180c1704 100644 --- a/gstreamer/src/auto/device_provider_factory.rs +++ b/gstreamer/src/auto/device_provider_factory.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use DeviceProvider; diff --git a/gstreamer/src/auto/element.rs b/gstreamer/src/auto/element.rs index d1ada6d09..7d77671d8 100644 --- a/gstreamer/src/auto/element.rs +++ b/gstreamer/src/auto/element.rs @@ -1,7 +1,8 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Bus; +use Caps; use Clock; use ClockTime; use ElementFactory; @@ -105,7 +106,7 @@ pub trait ElementExt { fn get_clock(&self) -> Option; - //fn get_compatible_pad<'a, P: IsA, Q: Into>>(&self, pad: &P, caps: Q) -> Option; + fn get_compatible_pad<'a, P: IsA, Q: Into>>(&self, pad: &P, caps: Q) -> Option; fn get_compatible_pad_template(&self, compattempl: &PadTemplate) -> Option; @@ -135,13 +136,13 @@ pub trait ElementExt { fn link>(&self, dest: &P) -> Result<(), glib::error::BoolError>; - //fn link_filtered<'a, P: IsA, Q: Into>>(&self, dest: &P, filter: Q) -> bool; + fn link_filtered<'a, P: IsA, Q: Into>>(&self, dest: &P, filter: Q) -> Result<(), glib::error::BoolError>; //fn link_many>(&self, element_2: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool; fn link_pads<'a, 'b, P: Into>, Q: IsA, R: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R) -> Result<(), glib::error::BoolError>; - //fn link_pads_filtered<'a, 'b, 'c, P: Into>, Q: IsA, R: Into>, S: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> bool; + fn link_pads_filtered<'a, 'b, 'c, P: Into>, Q: IsA, R: Into>, S: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> Result<(), glib::error::BoolError>; //fn link_pads_full<'a, 'b, P: Into>, Q: IsA, R: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R, flags: /*Ignored*/PadLinkCheck) -> bool; @@ -173,7 +174,7 @@ pub trait ElementExt { #[cfg(feature = "v1_10")] fn remove_property_notify_watch(&self, watch_id: libc::c_ulong); - //fn request_pad<'a, 'b, P: Into>, Q: Into>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option; + fn request_pad<'a, 'b, P: Into>, Q: Into>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option; fn seek(&self, rate: f64, format: Format, flags: SeekFlags, start_type: SeekType, start: i64, stop_type: SeekType, stop: i64) -> Result<(), glib::error::BoolError>; @@ -282,9 +283,13 @@ impl + IsA> ElementExt for O { } } - //fn get_compatible_pad<'a, P: IsA, Q: Into>>(&self, pad: &P, caps: Q) -> Option { - // unsafe { TODO: call ffi::gst_element_get_compatible_pad() } - //} + fn get_compatible_pad<'a, P: IsA, Q: Into>>(&self, pad: &P, caps: Q) -> Option { + let caps = caps.into(); + let caps = caps.to_glib_none(); + unsafe { + from_glib_full(ffi::gst_element_get_compatible_pad(self.to_glib_none().0, pad.to_glib_none().0, caps.0)) + } + } fn get_compatible_pad_template(&self, compattempl: &PadTemplate) -> Option { unsafe { @@ -361,9 +366,13 @@ impl + IsA> ElementExt for O { } } - //fn link_filtered<'a, P: IsA, Q: Into>>(&self, dest: &P, filter: Q) -> bool { - // unsafe { TODO: call ffi::gst_element_link_filtered() } - //} + fn link_filtered<'a, P: IsA, Q: Into>>(&self, dest: &P, filter: Q) -> Result<(), glib::error::BoolError> { + let filter = filter.into(); + let filter = filter.to_glib_none(); + unsafe { + glib::error::BoolError::from_glib(ffi::gst_element_link_filtered(self.to_glib_none().0, dest.to_glib_none().0, filter.0), "Failed to link elements") + } + } //fn link_many>(&self, element_2: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool { // unsafe { TODO: call ffi::gst_element_link_many() } @@ -379,9 +388,17 @@ impl + IsA> ElementExt for O { } } - //fn link_pads_filtered<'a, 'b, 'c, P: Into>, Q: IsA, R: Into>, S: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> bool { - // unsafe { TODO: call ffi::gst_element_link_pads_filtered() } - //} + fn link_pads_filtered<'a, 'b, 'c, P: Into>, Q: IsA, R: Into>, S: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> Result<(), glib::error::BoolError> { + let srcpadname = srcpadname.into(); + let srcpadname = srcpadname.to_glib_none(); + let destpadname = destpadname.into(); + let destpadname = destpadname.to_glib_none(); + let filter = filter.into(); + let filter = filter.to_glib_none(); + unsafe { + glib::error::BoolError::from_glib(ffi::gst_element_link_pads_filtered(self.to_glib_none().0, srcpadname.0, dest.to_glib_none().0, destpadname.0, filter.0), "Failed to link pads") + } + } //fn link_pads_full<'a, 'b, P: Into>, Q: IsA, R: Into>>(&self, srcpadname: P, dest: &Q, destpadname: R, flags: /*Ignored*/PadLinkCheck) -> bool { // unsafe { TODO: call ffi::gst_element_link_pads_full() } @@ -467,9 +484,15 @@ impl + IsA> ElementExt for O { } } - //fn request_pad<'a, 'b, P: Into>, Q: Into>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option { - // unsafe { TODO: call ffi::gst_element_request_pad() } - //} + fn request_pad<'a, 'b, P: Into>, Q: Into>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option { + let name = name.into(); + let name = name.to_glib_none(); + let caps = caps.into(); + let caps = caps.to_glib_none(); + unsafe { + from_glib_full(ffi::gst_element_request_pad(self.to_glib_none().0, templ.to_glib_none().0, name.0, caps.0)) + } + } fn seek(&self, rate: f64, format: Format, flags: SeekFlags, start_type: SeekType, start: i64, stop_type: SeekType, stop: i64) -> Result<(), glib::error::BoolError> { unsafe { diff --git a/gstreamer/src/auto/element_factory.rs b/gstreamer/src/auto/element_factory.rs index df909c9d8..1986d783c 100644 --- a/gstreamer/src/auto/element_factory.rs +++ b/gstreamer/src/auto/element_factory.rs @@ -1,9 +1,11 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT +use Caps; use Element; use ElementFactoryListType; use Object; +use PadDirection; use URIType; use ffi; use glib; @@ -18,21 +20,29 @@ glib_wrapper! { } impl ElementFactory { - //pub fn can_sink_all_caps(&self, caps: /*Ignored*/&Caps) -> bool { - // unsafe { TODO: call ffi::gst_element_factory_can_sink_all_caps() } - //} + pub fn can_sink_all_caps(&self, caps: &Caps) -> bool { + unsafe { + from_glib(ffi::gst_element_factory_can_sink_all_caps(self.to_glib_none().0, caps.to_glib_none().0)) + } + } - //pub fn can_sink_any_caps(&self, caps: /*Ignored*/&Caps) -> bool { - // unsafe { TODO: call ffi::gst_element_factory_can_sink_any_caps() } - //} + pub fn can_sink_any_caps(&self, caps: &Caps) -> bool { + unsafe { + from_glib(ffi::gst_element_factory_can_sink_any_caps(self.to_glib_none().0, caps.to_glib_none().0)) + } + } - //pub fn can_src_all_caps(&self, caps: /*Ignored*/&Caps) -> bool { - // unsafe { TODO: call ffi::gst_element_factory_can_src_all_caps() } - //} + pub fn can_src_all_caps(&self, caps: &Caps) -> bool { + unsafe { + from_glib(ffi::gst_element_factory_can_src_all_caps(self.to_glib_none().0, caps.to_glib_none().0)) + } + } - //pub fn can_src_any_caps(&self, caps: /*Ignored*/&Caps) -> bool { - // unsafe { TODO: call ffi::gst_element_factory_can_src_any_caps() } - //} + pub fn can_src_any_caps(&self, caps: &Caps) -> bool { + unsafe { + from_glib(ffi::gst_element_factory_can_src_any_caps(self.to_glib_none().0, caps.to_glib_none().0)) + } + } pub fn create<'a, P: Into>>(&self, name: P) -> Option { let name = name.into(); @@ -101,9 +111,12 @@ impl ElementFactory { } } - //pub fn list_filter(list: &[ElementFactory], caps: /*Ignored*/&Caps, direction: PadDirection, subsetonly: bool) -> Vec { - // unsafe { TODO: call ffi::gst_element_factory_list_filter() } - //} + pub fn list_filter(list: &[ElementFactory], caps: &Caps, direction: PadDirection, subsetonly: bool) -> Vec { + assert_initialized_main_thread!(); + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_element_factory_list_filter(list.to_glib_none().0, caps.to_glib_none().0, direction.to_glib(), subsetonly.to_glib())) + } + } //pub fn list_get_elements(type_: ElementFactoryListType, minrank: /*Ignored*/Rank) -> Vec { // unsafe { TODO: call ffi::gst_element_factory_list_get_elements() } diff --git a/gstreamer/src/auto/enums.rs b/gstreamer/src/auto/enums.rs index abbdb2817..af5f9b228 100644 --- a/gstreamer/src/auto/enums.rs +++ b/gstreamer/src/auto/enums.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use ffi; @@ -419,6 +419,42 @@ impl FromGlib for PadLinkReturn { } } +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +pub enum PadPresence { + Always, + Sometimes, + Request, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl ToGlib for PadPresence { + type GlibType = ffi::GstPadPresence; + + fn to_glib(&self) -> ffi::GstPadPresence { + match *self { + PadPresence::Always => ffi::GST_PAD_ALWAYS, + PadPresence::Sometimes => ffi::GST_PAD_SOMETIMES, + PadPresence::Request => ffi::GST_PAD_REQUEST, + PadPresence::__Unknown(value) => unsafe{std::mem::transmute(value)} + } + } +} + +#[doc(hidden)] +impl FromGlib for PadPresence { + fn from_glib(value: ffi::GstPadPresence) -> Self { + skip_assert_initialized!(); + match value as i32 { + 0 => PadPresence::Always, + 1 => PadPresence::Sometimes, + 2 => PadPresence::Request, + value => PadPresence::__Unknown(value), + } + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub enum ParseError { Syntax, diff --git a/gstreamer/src/auto/flags.rs b/gstreamer/src/auto/flags.rs index 9e76d53c4..d8747ce9e 100644 --- a/gstreamer/src/auto/flags.rs +++ b/gstreamer/src/auto/flags.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use ffi; diff --git a/gstreamer/src/auto/functions.rs b/gstreamer/src/auto/functions.rs index fd135b788..212c7f352 100644 --- a/gstreamer/src/auto/functions.rs +++ b/gstreamer/src/auto/functions.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Bin; @@ -628,7 +628,7 @@ pub fn util_uint64_scale_round(val: u64, num: u64, denom: u64) -> u64 { // unsafe { TODO: call ffi::gst_value_get_bitmask() } //} -//pub fn value_get_caps(value: /*Ignored*/&glib::Value) -> /*Ignored*/Option { +//pub fn value_get_caps(value: /*Ignored*/&glib::Value) -> Option { // unsafe { TODO: call ffi::gst_value_get_caps() } //} @@ -724,7 +724,7 @@ pub fn util_uint64_scale_round(val: u64, num: u64, denom: u64) -> u64 { // unsafe { TODO: call ffi::gst_value_set_bitmask() } //} -//pub fn value_set_caps(value: /*Ignored*/&mut glib::Value, caps: /*Ignored*/&Caps) { +//pub fn value_set_caps(value: /*Ignored*/&mut glib::Value, caps: &Caps) { // unsafe { TODO: call ffi::gst_value_set_caps() } //} diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index 247047f81..695fac582 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT mod bin; @@ -80,6 +80,7 @@ pub use self::enums::Format; pub use self::enums::LibraryError; pub use self::enums::PadDirection; pub use self::enums::PadLinkReturn; +pub use self::enums::PadPresence; pub use self::enums::ParseError; pub use self::enums::PluginError; pub use self::enums::ProgressType; diff --git a/gstreamer/src/auto/object.rs b/gstreamer/src/auto/object.rs index ec159261d..d5fdd5591 100644 --- a/gstreamer/src/auto/object.rs +++ b/gstreamer/src/auto/object.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use ClockTime; diff --git a/gstreamer/src/auto/pad.rs b/gstreamer/src/auto/pad.rs index 4138b0b8c..86ef8070c 100644 --- a/gstreamer/src/auto/pad.rs +++ b/gstreamer/src/auto/pad.rs @@ -1,6 +1,7 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT +use Caps; use Element; use FlowReturn; use Format; @@ -89,9 +90,9 @@ pub trait PadExt { //fn forward>>(&self, forward: /*Unknown conversion*//*Unimplemented*/PadForwardFunction, user_data: P) -> bool; - //fn get_allowed_caps(&self) -> /*Ignored*/Option; + fn get_allowed_caps(&self) -> Option; - //fn get_current_caps(&self) -> /*Ignored*/Option; + fn get_current_caps(&self) -> Option; fn get_direction(&self) -> PadDirection; @@ -103,7 +104,7 @@ pub trait PadExt { fn get_pad_template(&self) -> Option; - //fn get_pad_template_caps(&self) -> /*Ignored*/Option; + fn get_pad_template_caps(&self) -> Option; fn get_parent_element(&self) -> Option; @@ -153,9 +154,9 @@ pub trait PadExt { //fn peer_query(&self, query: /*Ignored*/&mut Query) -> bool; - //fn peer_query_accept_caps(&self, caps: /*Ignored*/&mut Caps) -> bool; + fn peer_query_accept_caps(&self, caps: &Caps) -> bool; - //fn peer_query_caps<'a, P: Into>>(&self, filter: P) -> /*Ignored*/Option; + fn peer_query_caps<'a, P: Into>>(&self, filter: P) -> Option; fn peer_query_convert(&self, src_format: Format, src_val: i64, dest_format: Format) -> Option; @@ -177,9 +178,9 @@ pub trait PadExt { //fn query(&self, query: /*Ignored*/&mut Query) -> bool; - //fn query_accept_caps(&self, caps: /*Ignored*/&mut Caps) -> bool; + fn query_accept_caps(&self, caps: &Caps) -> bool; - //fn query_caps<'a, P: Into>>(&self, filter: P) -> /*Ignored*/Option; + fn query_caps<'a, P: Into>>(&self, filter: P) -> Option; fn query_convert(&self, src_format: Format, src_val: i64, dest_format: Format) -> Option; @@ -233,8 +234,6 @@ pub trait PadExt { fn use_fixed_caps(&self); - //fn get_property_caps(&self) -> /*Ignored*/Option; - fn get_property_template(&self) -> Option; fn set_property_template(&self, template: Option<&PadTemplate>); @@ -297,13 +296,17 @@ impl + IsA> PadExt for O { // unsafe { TODO: call ffi::gst_pad_forward() } //} - //fn get_allowed_caps(&self) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_pad_get_allowed_caps() } - //} + fn get_allowed_caps(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_pad_get_allowed_caps(self.to_glib_none().0)) + } + } - //fn get_current_caps(&self) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_pad_get_current_caps() } - //} + fn get_current_caps(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_pad_get_current_caps(self.to_glib_none().0)) + } + } fn get_direction(&self) -> PadDirection { unsafe { @@ -333,9 +336,11 @@ impl + IsA> PadExt for O { } } - //fn get_pad_template_caps(&self) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_pad_get_pad_template_caps() } - //} + fn get_pad_template_caps(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_pad_get_pad_template_caps(self.to_glib_none().0)) + } + } fn get_parent_element(&self) -> Option { unsafe { @@ -457,13 +462,19 @@ impl + IsA> PadExt for O { // unsafe { TODO: call ffi::gst_pad_peer_query() } //} - //fn peer_query_accept_caps(&self, caps: /*Ignored*/&mut Caps) -> bool { - // unsafe { TODO: call ffi::gst_pad_peer_query_accept_caps() } - //} + fn peer_query_accept_caps(&self, caps: &Caps) -> bool { + unsafe { + from_glib(ffi::gst_pad_peer_query_accept_caps(self.to_glib_none().0, caps.to_glib_none().0)) + } + } - //fn peer_query_caps<'a, P: Into>>(&self, filter: P) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_pad_peer_query_caps() } - //} + fn peer_query_caps<'a, P: Into>>(&self, filter: P) -> Option { + let filter = filter.into(); + let filter = filter.to_glib_none(); + unsafe { + from_glib_full(ffi::gst_pad_peer_query_caps(self.to_glib_none().0, filter.0)) + } + } fn peer_query_convert(&self, src_format: Format, src_val: i64, dest_format: Format) -> Option { unsafe { @@ -517,13 +528,19 @@ impl + IsA> PadExt for O { // unsafe { TODO: call ffi::gst_pad_query() } //} - //fn query_accept_caps(&self, caps: /*Ignored*/&mut Caps) -> bool { - // unsafe { TODO: call ffi::gst_pad_query_accept_caps() } - //} + fn query_accept_caps(&self, caps: &Caps) -> bool { + unsafe { + from_glib(ffi::gst_pad_query_accept_caps(self.to_glib_none().0, caps.to_glib_none().0)) + } + } - //fn query_caps<'a, P: Into>>(&self, filter: P) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_pad_query_caps() } - //} + fn query_caps<'a, P: Into>>(&self, filter: P) -> Option { + let filter = filter.into(); + let filter = filter.to_glib_none(); + unsafe { + from_glib_full(ffi::gst_pad_query_caps(self.to_glib_none().0, filter.0)) + } + } fn query_convert(&self, src_format: Format, src_val: i64, dest_format: Format) -> Option { unsafe { @@ -653,14 +670,6 @@ impl + IsA> PadExt for O { } } - //fn get_property_caps(&self) -> /*Ignored*/Option { - // let mut value = Value::from(None::<&/*Ignored*/Caps>); - // unsafe { - // gobject_ffi::g_object_get_property(self.to_glib_none().0, "caps".to_glib_none().0, value.to_glib_none_mut().0); - // } - // value.get() - //} - fn get_property_template(&self) -> Option { let mut value = Value::from(None::<&PadTemplate>); unsafe { diff --git a/gstreamer/src/auto/pad_template.rs b/gstreamer/src/auto/pad_template.rs index dc731aad6..bb31e1f48 100644 --- a/gstreamer/src/auto/pad_template.rs +++ b/gstreamer/src/auto/pad_template.rs @@ -1,9 +1,11 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT +use Caps; use Object; use Pad; use PadDirection; +use PadPresence; use ffi; use glib; use glib::Value; @@ -25,16 +27,19 @@ glib_wrapper! { } impl PadTemplate { - //pub fn new(name_template: &str, direction: PadDirection, presence: /*Ignored*/PadPresence, caps: /*Ignored*/&mut Caps) -> PadTemplate { - // unsafe { TODO: call ffi::gst_pad_template_new() } - //} + pub fn new(name_template: &str, direction: PadDirection, presence: PadPresence, caps: &Caps) -> PadTemplate { + assert_initialized_main_thread!(); + unsafe { + from_glib_none(ffi::gst_pad_template_new(name_template.to_glib_none().0, direction.to_glib(), presence.to_glib(), caps.to_glib_none().0)) + } + } } unsafe impl Send for PadTemplate {} unsafe impl Sync for PadTemplate {} pub trait PadTemplateExt { - //fn get_caps(&self) -> /*Ignored*/Option; + fn get_caps(&self) -> Option; fn pad_created>(&self, pad: &P); @@ -42,15 +47,17 @@ pub trait PadTemplateExt { fn get_property_name_template(&self) -> Option; - //fn get_property_presence(&self) -> /*Ignored*/PadPresence; + fn get_property_presence(&self) -> PadPresence; fn connect_pad_created(&self, f: F) -> u64; } impl + IsA> PadTemplateExt for O { - //fn get_caps(&self) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_pad_template_get_caps() } - //} + fn get_caps(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_pad_template_get_caps(self.to_glib_none().0)) + } + } fn pad_created>(&self, pad: &P) { unsafe { @@ -74,13 +81,13 @@ impl + IsA> PadTemplateExt for O { value.get() } - //fn get_property_presence(&self) -> /*Ignored*/PadPresence { - // let mut value = Value::from(&0); - // unsafe { - // gobject_ffi::g_object_get_property(self.to_glib_none().0, "presence".to_glib_none().0, value.to_glib_none_mut().0); - // from_glib(transmute(value.get::().unwrap())) - // } - //} + fn get_property_presence(&self) -> PadPresence { + let mut value = Value::from(&0); + unsafe { + gobject_ffi::g_object_get_property(self.to_glib_none().0, "presence".to_glib_none().0, value.to_glib_none_mut().0); + from_glib(transmute(value.get::().unwrap())) + } + } fn connect_pad_created(&self, f: F) -> u64 { unsafe { diff --git a/gstreamer/src/auto/pipeline.rs b/gstreamer/src/auto/pipeline.rs index e71d92d0f..07f0f9a9f 100644 --- a/gstreamer/src/auto/pipeline.rs +++ b/gstreamer/src/auto/pipeline.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Bin; diff --git a/gstreamer/src/auto/plugin.rs b/gstreamer/src/auto/plugin.rs index fa3bc54c5..db568330f 100644 --- a/gstreamer/src/auto/plugin.rs +++ b/gstreamer/src/auto/plugin.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Error; diff --git a/gstreamer/src/auto/stream.rs b/gstreamer/src/auto/stream.rs index 090fd8e88..d3e18eb42 100644 --- a/gstreamer/src/auto/stream.rs +++ b/gstreamer/src/auto/stream.rs @@ -1,6 +1,7 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT +use Caps; use Object; use StreamFlags; use StreamType; @@ -21,18 +22,25 @@ glib_wrapper! { } impl Stream { - //#[cfg(feature = "v1_10")] - //pub fn new<'a, 'b, P: Into>, Q: Into>>(stream_id: P, caps: Q, type_: StreamType, flags: StreamFlags) -> Stream { - // unsafe { TODO: call ffi::gst_stream_new() } - //} + #[cfg(feature = "v1_10")] + pub fn new<'a, 'b, P: Into>, Q: Into>>(stream_id: P, caps: Q, type_: StreamType, flags: StreamFlags) -> Stream { + assert_initialized_main_thread!(); + let stream_id = stream_id.into(); + let stream_id = stream_id.to_glib_none(); + let caps = caps.into(); + let caps = caps.to_glib_none(); + unsafe { + from_glib_full(ffi::gst_stream_new(stream_id.0, caps.0, type_.to_glib(), flags.to_glib())) + } + } } unsafe impl Send for Stream {} unsafe impl Sync for Stream {} pub trait StreamExt { - //#[cfg(feature = "v1_10")] - //fn get_caps(&self) -> /*Ignored*/Option; + #[cfg(feature = "v1_10")] + fn get_caps(&self) -> Option; #[cfg(feature = "v1_10")] fn get_stream_flags(&self) -> StreamFlags; @@ -46,8 +54,8 @@ pub trait StreamExt { //#[cfg(feature = "v1_10")] //fn get_tags(&self) -> /*Ignored*/Option; - //#[cfg(feature = "v1_10")] - //fn set_caps<'a, P: Into>>(&self, caps: P); + #[cfg(feature = "v1_10")] + fn set_caps<'a, P: Into>>(&self, caps: P); #[cfg(feature = "v1_10")] fn set_stream_flags(&self, flags: StreamFlags); @@ -58,9 +66,9 @@ pub trait StreamExt { //#[cfg(feature = "v1_10")] //fn set_tags<'a, P: Into>>(&self, tags: P); - //fn get_property_caps(&self) -> /*Ignored*/Option; + fn get_property_caps(&self) -> Option<&Caps>; - //fn set_property_caps(&self, caps: /*Ignored*/Option<&Caps>); + fn set_property_caps(&self, caps: Option<&Caps>); fn get_property_stream_flags(&self) -> StreamFlags; @@ -78,10 +86,12 @@ pub trait StreamExt { } impl + IsA> StreamExt for O { - //#[cfg(feature = "v1_10")] - //fn get_caps(&self) -> /*Ignored*/Option { - // unsafe { TODO: call ffi::gst_stream_get_caps() } - //} + #[cfg(feature = "v1_10")] + fn get_caps(&self) -> Option { + unsafe { + from_glib_full(ffi::gst_stream_get_caps(self.to_glib_none().0)) + } + } #[cfg(feature = "v1_10")] fn get_stream_flags(&self) -> StreamFlags { @@ -109,10 +119,14 @@ impl + IsA> StreamExt for O { // unsafe { TODO: call ffi::gst_stream_get_tags() } //} - //#[cfg(feature = "v1_10")] - //fn set_caps<'a, P: Into>>(&self, caps: P) { - // unsafe { TODO: call ffi::gst_stream_set_caps() } - //} + #[cfg(feature = "v1_10")] + fn set_caps<'a, P: Into>>(&self, caps: P) { + let caps = caps.into(); + let caps = caps.to_glib_none(); + unsafe { + ffi::gst_stream_set_caps(self.to_glib_none().0, caps.0); + } + } #[cfg(feature = "v1_10")] fn set_stream_flags(&self, flags: StreamFlags) { @@ -133,19 +147,19 @@ impl + IsA> StreamExt for O { // unsafe { TODO: call ffi::gst_stream_set_tags() } //} - //fn get_property_caps(&self) -> /*Ignored*/Option { - // let mut value = Value::from(None::<&/*Ignored*/Caps>); - // unsafe { - // gobject_ffi::g_object_get_property(self.to_glib_none().0, "caps".to_glib_none().0, value.to_glib_none_mut().0); - // } - // value.get() - //} + fn get_property_caps(&self) -> Option<&Caps> { + let mut value = Value::from(None::<&Caps>); + unsafe { + gobject_ffi::g_object_get_property(self.to_glib_none().0, "caps".to_glib_none().0, value.to_glib_none_mut().0); + } + value.get() + } - //fn set_property_caps(&self, caps: /*Ignored*/Option<&Caps>) { - // unsafe { - // gobject_ffi::g_object_set_property(self.to_glib_none().0, "caps".to_glib_none().0, Value::from(caps).to_glib_none().0); - // } - //} + fn set_property_caps(&self, caps: Option<&Caps>) { + unsafe { + gobject_ffi::g_object_set_property(self.to_glib_none().0, "caps".to_glib_none().0, Value::from(caps).to_glib_none().0); + } + } fn get_property_stream_flags(&self) -> StreamFlags { let mut value = Value::from(&0u32); diff --git a/gstreamer/src/auto/stream_collection.rs b/gstreamer/src/auto/stream_collection.rs index be06b181b..2eab96070 100644 --- a/gstreamer/src/auto/stream_collection.rs +++ b/gstreamer/src/auto/stream_collection.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Object; diff --git a/gstreamer/src/auto/u_r_i_handler.rs b/gstreamer/src/auto/u_r_i_handler.rs index a1d8b0990..549d0520e 100644 --- a/gstreamer/src/auto/u_r_i_handler.rs +++ b/gstreamer/src/auto/u_r_i_handler.rs @@ -1,4 +1,4 @@ -// This file was generated by gir (33e9567) from gir-files (???) +// This file was generated by gir (33e9567+) from gir-files (???) // DO NOT EDIT use Error; diff --git a/gstreamer/src/caps.rs b/gstreamer/src/caps.rs new file mode 100644 index 000000000..b0131c66e --- /dev/null +++ b/gstreamer/src/caps.rs @@ -0,0 +1,263 @@ +// Copyright (C) 2016-2017 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::ffi::CString; +use std::ffi::CStr; +use std::fmt; +use miniobject::*; +use structure::*; + +use glib; +use glib_ffi; +use ffi; +use glib::translate::{from_glib, from_glib_none, from_glib_full, mut_override, ToGlibPtr, ToGlib}; + +#[repr(C)] +pub struct CapsRef(ffi::GstCaps); + +pub type Caps = GstRc; + +unsafe impl MiniObject for CapsRef { + type GstType = ffi::GstCaps; +} + +impl CapsRef { + pub fn new_empty() -> GstRc { + unsafe { from_glib_full(ffi::gst_caps_new_empty()) } + } + + pub fn new_any() -> GstRc { + unsafe { from_glib_full(ffi::gst_caps_new_any()) } + } + + pub fn new_simple(name: &str, values: &[(&str, glib::Value)]) -> GstRc { + let mut caps = CapsRef::new_empty(); + + let structure = unsafe { ffi::gst_structure_new_empty(name.to_glib_none().0) }; + + unsafe { + ffi::gst_caps_append_structure(caps.as_mut_ptr(), structure); + } + + caps.get_mut().unwrap().set_simple(values); + + caps + } + + pub fn from_string(value: &str) -> Option> { + unsafe { + let caps_ptr = ffi::gst_caps_from_string(value.to_glib_none().0); + + if caps_ptr.is_null() { + None + } else { + Some(from_glib_full(caps_ptr)) + } + } + } + + pub fn set_simple(&mut self, values: &[(&str, glib::Value)]) { + for &(name, ref value) in values { + unsafe { + ffi::gst_caps_set_value(self.as_mut_ptr(), name.to_glib_none().0, value.to_glib_none().0); + } + } + } + + pub fn to_string(&self) -> String { + unsafe { + from_glib_full(ffi::gst_caps_to_string(self.as_ptr())) + } + } + + pub fn get_structure(&self, idx: u32) -> Option<&StructureRef> { + unsafe { + let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx); + if structure.is_null() { + return None; + } + + Some(StructureRef::from_glib_borrow( + structure as *const ffi::GstStructure, + )) + } + } + + pub fn get_mut_structure<'a>(&'a mut self, idx: u32) -> Option<&'a mut StructureRef> { + unsafe { + let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx); + if structure.is_null() { + return None; + } + + Some(StructureRef::from_glib_borrow_mut( + structure as *mut ffi::GstStructure, + )) + } + } + + pub fn get_size(&self) -> u32 { + unsafe { ffi::gst_caps_get_size(self.as_ptr()) } + } + + pub fn iter(&self) -> Iter { + Iter::new(self) + } + + //pub fn iter_mut(&mut self) -> IterMut { + // IterMut::new(self) + //} + + // TODO: All kinds of caps operations +} + +impl glib::types::StaticType for GstRc { + fn static_type() -> glib::types::Type { + unsafe { + from_glib(ffi::gst_caps_get_type()) + } + } +} + +macro_rules! define_iter( + ($name:ident, $typ:ty, $styp:ty, $getter:ident) => { + +pub struct $name<'a> { + caps: $typ, + idx: u32, + n_structures: u32, +} + +impl<'a> $name<'a> { + pub fn new(caps: $typ) -> $name<'a> { + let n_structures = caps.get_size(); + + $name { + caps: caps, + idx: 0, + n_structures: n_structures, + } + } +} + +impl<'a> Iterator for $name<'a> { + type Item = $styp; + + fn next(&mut self) -> Option { + if self.idx >= self.n_structures { + return None; + } + + if let Some(s) = self.caps.$getter(self.idx) { + self.idx += 1; + Some(s) + } else { + None + } + } + + fn size_hint(&self) -> (usize, Option) { + if self.idx == self.n_structures { + return (0, Some(0)); + } + + let remaining = (self.n_structures - self.idx) as usize; + + (remaining, Some(remaining)) + } +} + +impl<'a> DoubleEndedIterator for $name<'a> { + fn next_back(&mut self) -> Option { + if self.idx == self.n_structures { + return None; + } + + self.n_structures -= 1; + if let Some(s) = self.caps.$getter(self.n_structures) { + Some(s) + } else { + None + } + } +} + +impl<'a> ExactSizeIterator for $name<'a> {} +} +); + +define_iter!(Iter, &'a CapsRef, &'a StructureRef, get_structure); +//define_iter!(IterMut, &'a mut CapsRef, &'a mut Structure, get_mut_structure); + +impl fmt::Debug for CapsRef { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(&self.to_string()) + } +} + +impl PartialEq for CapsRef { + fn eq(&self, other: &CapsRef) -> bool { + unsafe { from_glib(ffi::gst_caps_is_equal(self.as_ptr(), other.as_ptr())) } + } +} + +impl Eq for CapsRef {} + +impl ToOwned for CapsRef { + type Owned = GstRc; + + fn to_owned(&self) -> GstRc { + unsafe { from_glib_none(self.as_ptr()) } + } +} + +unsafe impl Sync for CapsRef {} +unsafe impl Send for CapsRef {} + +/* +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_simple() { + gst::init(); + + let caps = CapsRef::new_simple( + "foo/bar", + &[ + ("int", 12.into()), + ("bool", true.into()), + ("string", "bla".into()), + ("fraction", (1, 2).into()), + ("array", vec![1.into(), 2.into()].into()), + ], + ); + assert_eq!( + caps.to_string(), + "foo/bar, int=(int)12, bool=(boolean)true, string=(string)bla, \ + fraction=(fraction)1/2, array=(int)< 1, 2 >" + ); + + let s = caps.get_structure(0).unwrap(); + assert_eq!( + s, + OwnedStructure::new( + "foo/bar", + &[ + ("int", 12.into()), + ("bool", true.into()), + ("string", "bla".into()), + ("fraction", (1, 2).into()), + ("array", vec![1.into(), 2.into()].into()), + ], + ).as_ref() + ); + } +} +*/ diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index a1587d9ad..1b3e6559a 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -60,6 +60,8 @@ pub use message::Message; pub use message::MessageView; pub mod structure; pub use structure::Structure; +pub mod caps; +pub use caps::Caps; mod element; mod bin; diff --git a/gstreamer/src/structure.rs b/gstreamer/src/structure.rs index e69168602..fb24d7a53 100644 --- a/gstreamer/src/structure.rs +++ b/gstreamer/src/structure.rs @@ -283,9 +283,7 @@ impl StructureRef { pub fn get_value<'a>(&'a self, name: &str) -> Option<&Value> { unsafe { - let name_cstr = CString::new(name).unwrap(); - - let value = ffi::gst_structure_get_value(&self.0, name_cstr.as_ptr()); + let value = ffi::gst_structure_get_value(&self.0, name.to_glib_none().0); if value.is_null() { return None; @@ -302,8 +300,7 @@ impl StructureRef { pub fn set_value(&mut self, name: &str, mut value: Value) { unsafe { - let name_cstr = CString::new(name).unwrap(); - ffi::gst_structure_take_value(&mut self.0, name_cstr.as_ptr(), value.to_glib_none_mut().0); + ffi::gst_structure_take_value(&mut self.0, name.to_glib_none().0, value.to_glib_none_mut().0); mem::forget(value); } }