Add initial caps bindings

This commit is contained in:
Sebastian Dröge 2017-07-11 00:02:08 +03:00
parent 944c71f953
commit c0707bed94
27 changed files with 564 additions and 175 deletions

View file

@ -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"

View file

@ -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/"))
};

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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<Option<&'a str>>>(&self, name: P) -> Option<Element>;
//fn get_caps(&self) -> /*Ignored*/Option<Caps>;
fn get_caps(&self) -> Option<Caps>;
fn get_device_class(&self) -> Option<String>;
fn get_display_name(&self) -> Option<String>;
fn get_properties(&self) -> Option<Structure>;
fn has_classes(&self, classes: &str) -> bool;
fn has_classesv(&self, classes: &[&str]) -> bool;
fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> bool;
//fn get_property_caps(&self) -> /*Ignored*/Option<Caps>;
fn get_property_device_class(&self) -> Option<String>;
fn get_property_display_name(&self) -> Option<String>;
@ -59,9 +61,11 @@ impl<O: IsA<Device> + IsA<glib::object::Object>> DeviceExt for O {
}
}
//fn get_caps(&self) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_device_get_caps() }
//}
fn get_caps(&self) -> Option<Caps> {
unsafe {
from_glib_full(ffi::gst_device_get_caps(self.to_glib_none().0))
}
}
fn get_device_class(&self) -> Option<String> {
unsafe {
@ -75,6 +79,12 @@ impl<O: IsA<Device> + IsA<glib::object::Object>> DeviceExt for O {
}
}
fn get_properties(&self) -> Option<Structure> {
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<O: IsA<Device> + IsA<glib::object::Object>> DeviceExt for O {
}
}
//fn get_property_caps(&self) -> /*Ignored*/Option<Caps> {
// 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<String> {
let mut value = Value::from(None::<&str>);
unsafe {

View file

@ -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<Option<&'a str>>, Q: Into<Option<&'b /*Ignored*/Caps>>>(&self, classes: P, caps: Q) -> u32;
fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, classes: P, caps: Q) -> u32;
fn get_bus(&self) -> Option<Bus>;
@ -56,9 +57,15 @@ pub trait DeviceMonitorExt {
}
impl<O: IsA<DeviceMonitor> + IsA<glib::object::Object>> DeviceMonitorExt for O {
//fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b /*Ignored*/Caps>>>(&self, classes: P, caps: Q) -> u32 {
// unsafe { TODO: call ffi::gst_device_monitor_add_filter() }
//}
fn add_filter<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&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<Bus> {
unsafe {

View file

@ -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;

View file

@ -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;

View file

@ -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<Clock>;
//fn get_compatible_pad<'a, P: IsA<Pad>, Q: Into<Option<&'a /*Ignored*/Caps>>>(&self, pad: &P, caps: Q) -> Option<Pad>;
fn get_compatible_pad<'a, P: IsA<Pad>, Q: Into<Option<&'a Caps>>>(&self, pad: &P, caps: Q) -> Option<Pad>;
fn get_compatible_pad_template(&self, compattempl: &PadTemplate) -> Option<PadTemplate>;
@ -135,13 +136,13 @@ pub trait ElementExt {
fn link<P: IsA<Element>>(&self, dest: &P) -> Result<(), glib::error::BoolError>;
//fn link_filtered<'a, P: IsA<Element>, Q: Into<Option<&'a /*Ignored*/Caps>>>(&self, dest: &P, filter: Q) -> bool;
fn link_filtered<'a, P: IsA<Element>, Q: Into<Option<&'a Caps>>>(&self, dest: &P, filter: Q) -> Result<(), glib::error::BoolError>;
//fn link_many<P: IsA<Element>>(&self, element_2: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool;
fn link_pads<'a, 'b, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&self, srcpadname: P, dest: &Q, destpadname: R) -> Result<(), glib::error::BoolError>;
//fn link_pads_filtered<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>, S: Into<Option<&'c /*Ignored*/Caps>>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> bool;
fn link_pads_filtered<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>, S: Into<Option<&'c Caps>>>(&self, srcpadname: P, dest: &Q, destpadname: R, filter: S) -> Result<(), glib::error::BoolError>;
//fn link_pads_full<'a, 'b, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&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<Option<&'a str>>, Q: Into<Option<&'b /*Ignored*/Caps>>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option<Pad>;
fn request_pad<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option<Pad>;
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<O: IsA<Element> + IsA<glib::object::Object>> ElementExt for O {
}
}
//fn get_compatible_pad<'a, P: IsA<Pad>, Q: Into<Option<&'a /*Ignored*/Caps>>>(&self, pad: &P, caps: Q) -> Option<Pad> {
// unsafe { TODO: call ffi::gst_element_get_compatible_pad() }
//}
fn get_compatible_pad<'a, P: IsA<Pad>, Q: Into<Option<&'a Caps>>>(&self, pad: &P, caps: Q) -> Option<Pad> {
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<PadTemplate> {
unsafe {
@ -361,9 +366,13 @@ impl<O: IsA<Element> + IsA<glib::object::Object>> ElementExt for O {
}
}
//fn link_filtered<'a, P: IsA<Element>, Q: Into<Option<&'a /*Ignored*/Caps>>>(&self, dest: &P, filter: Q) -> bool {
// unsafe { TODO: call ffi::gst_element_link_filtered() }
//}
fn link_filtered<'a, P: IsA<Element>, Q: Into<Option<&'a Caps>>>(&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<P: IsA<Element>>(&self, element_2: &P, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> bool {
// unsafe { TODO: call ffi::gst_element_link_many() }
@ -379,9 +388,17 @@ impl<O: IsA<Element> + IsA<glib::object::Object>> ElementExt for O {
}
}
//fn link_pads_filtered<'a, 'b, 'c, P: Into<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>, S: Into<Option<&'c /*Ignored*/Caps>>>(&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<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>, S: Into<Option<&'c Caps>>>(&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<Option<&'a str>>, Q: IsA<Element>, R: Into<Option<&'b str>>>(&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<O: IsA<Element> + IsA<glib::object::Object>> ElementExt for O {
}
}
//fn request_pad<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b /*Ignored*/Caps>>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option<Pad> {
// unsafe { TODO: call ffi::gst_element_request_pad() }
//}
fn request_pad<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(&self, templ: &PadTemplate, name: P, caps: Q) -> Option<Pad> {
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 {

View file

@ -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<Option<&'a str>>>(&self, name: P) -> Option<Element> {
let name = name.into();
@ -101,9 +111,12 @@ impl ElementFactory {
}
}
//pub fn list_filter(list: &[ElementFactory], caps: /*Ignored*/&Caps, direction: PadDirection, subsetonly: bool) -> Vec<ElementFactory> {
// unsafe { TODO: call ffi::gst_element_factory_list_filter() }
//}
pub fn list_filter(list: &[ElementFactory], caps: &Caps, direction: PadDirection, subsetonly: bool) -> Vec<ElementFactory> {
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<ElementFactory> {
// unsafe { TODO: call ffi::gst_element_factory_list_get_elements() }

View file

@ -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<ffi::GstPadLinkReturn> 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<ffi::GstPadPresence> 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,

View file

@ -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;

View file

@ -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<Caps> {
//pub fn value_get_caps(value: /*Ignored*/&glib::Value) -> Option<Caps> {
// 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() }
//}

View file

@ -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;

View file

@ -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;

View file

@ -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<P: Into<Option</*Unimplemented*/Fundamental: Pointer>>>(&self, forward: /*Unknown conversion*//*Unimplemented*/PadForwardFunction, user_data: P) -> bool;
//fn get_allowed_caps(&self) -> /*Ignored*/Option<Caps>;
fn get_allowed_caps(&self) -> Option<Caps>;
//fn get_current_caps(&self) -> /*Ignored*/Option<Caps>;
fn get_current_caps(&self) -> Option<Caps>;
fn get_direction(&self) -> PadDirection;
@ -103,7 +104,7 @@ pub trait PadExt {
fn get_pad_template(&self) -> Option<PadTemplate>;
//fn get_pad_template_caps(&self) -> /*Ignored*/Option<Caps>;
fn get_pad_template_caps(&self) -> Option<Caps>;
fn get_parent_element(&self) -> Option<Element>;
@ -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<Option<&'a /*Ignored*/Caps>>>(&self, filter: P) -> /*Ignored*/Option<Caps>;
fn peer_query_caps<'a, P: Into<Option<&'a Caps>>>(&self, filter: P) -> Option<Caps>;
fn peer_query_convert(&self, src_format: Format, src_val: i64, dest_format: Format) -> Option<i64>;
@ -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<Option<&'a /*Ignored*/Caps>>>(&self, filter: P) -> /*Ignored*/Option<Caps>;
fn query_caps<'a, P: Into<Option<&'a Caps>>>(&self, filter: P) -> Option<Caps>;
fn query_convert(&self, src_format: Format, src_val: i64, dest_format: Format) -> Option<i64>;
@ -233,8 +234,6 @@ pub trait PadExt {
fn use_fixed_caps(&self);
//fn get_property_caps(&self) -> /*Ignored*/Option<Caps>;
fn get_property_template(&self) -> Option<PadTemplate>;
fn set_property_template(&self, template: Option<&PadTemplate>);
@ -297,13 +296,17 @@ impl<O: IsA<Pad> + IsA<glib::object::Object>> PadExt for O {
// unsafe { TODO: call ffi::gst_pad_forward() }
//}
//fn get_allowed_caps(&self) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_pad_get_allowed_caps() }
//}
fn get_allowed_caps(&self) -> Option<Caps> {
unsafe {
from_glib_full(ffi::gst_pad_get_allowed_caps(self.to_glib_none().0))
}
}
//fn get_current_caps(&self) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_pad_get_current_caps() }
//}
fn get_current_caps(&self) -> Option<Caps> {
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<O: IsA<Pad> + IsA<glib::object::Object>> PadExt for O {
}
}
//fn get_pad_template_caps(&self) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_pad_get_pad_template_caps() }
//}
fn get_pad_template_caps(&self) -> Option<Caps> {
unsafe {
from_glib_full(ffi::gst_pad_get_pad_template_caps(self.to_glib_none().0))
}
}
fn get_parent_element(&self) -> Option<Element> {
unsafe {
@ -457,13 +462,19 @@ impl<O: IsA<Pad> + IsA<glib::object::Object>> 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<Option<&'a /*Ignored*/Caps>>>(&self, filter: P) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_pad_peer_query_caps() }
//}
fn peer_query_caps<'a, P: Into<Option<&'a Caps>>>(&self, filter: P) -> Option<Caps> {
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<i64> {
unsafe {
@ -517,13 +528,19 @@ impl<O: IsA<Pad> + IsA<glib::object::Object>> 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<Option<&'a /*Ignored*/Caps>>>(&self, filter: P) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_pad_query_caps() }
//}
fn query_caps<'a, P: Into<Option<&'a Caps>>>(&self, filter: P) -> Option<Caps> {
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<i64> {
unsafe {
@ -653,14 +670,6 @@ impl<O: IsA<Pad> + IsA<glib::object::Object>> PadExt for O {
}
}
//fn get_property_caps(&self) -> /*Ignored*/Option<Caps> {
// 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<PadTemplate> {
let mut value = Value::from(None::<&PadTemplate>);
unsafe {

View file

@ -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<Caps>;
fn get_caps(&self) -> Option<Caps>;
fn pad_created<P: IsA<Pad>>(&self, pad: &P);
@ -42,15 +47,17 @@ pub trait PadTemplateExt {
fn get_property_name_template(&self) -> Option<String>;
//fn get_property_presence(&self) -> /*Ignored*/PadPresence;
fn get_property_presence(&self) -> PadPresence;
fn connect_pad_created<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> u64;
}
impl<O: IsA<PadTemplate> + IsA<glib::object::Object>> PadTemplateExt for O {
//fn get_caps(&self) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_pad_template_get_caps() }
//}
fn get_caps(&self) -> Option<Caps> {
unsafe {
from_glib_full(ffi::gst_pad_template_get_caps(self.to_glib_none().0))
}
}
fn pad_created<P: IsA<Pad>>(&self, pad: &P) {
unsafe {
@ -74,13 +81,13 @@ impl<O: IsA<PadTemplate> + IsA<glib::object::Object>> 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::<i32>().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::<i32>().unwrap()))
}
}
fn connect_pad_created<F: Fn(&Self, &Pad) + Send + Sync + 'static>(&self, f: F) -> u64 {
unsafe {

View file

@ -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;

View file

@ -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;

View file

@ -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<Option<&'a str>>, Q: Into<Option<&'b /*Ignored*/Caps>>>(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<Option<&'a str>>, Q: Into<Option<&'b Caps>>>(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<Caps>;
#[cfg(feature = "v1_10")]
fn get_caps(&self) -> Option<Caps>;
#[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<TagList>;
//#[cfg(feature = "v1_10")]
//fn set_caps<'a, P: Into<Option<&'a /*Ignored*/Caps>>>(&self, caps: P);
#[cfg(feature = "v1_10")]
fn set_caps<'a, P: Into<Option<&'a Caps>>>(&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<Option<&'a /*Ignored*/TagList>>>(&self, tags: P);
//fn get_property_caps(&self) -> /*Ignored*/Option<Caps>;
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<O: IsA<Stream> + IsA<glib::object::Object>> StreamExt for O {
//#[cfg(feature = "v1_10")]
//fn get_caps(&self) -> /*Ignored*/Option<Caps> {
// unsafe { TODO: call ffi::gst_stream_get_caps() }
//}
#[cfg(feature = "v1_10")]
fn get_caps(&self) -> Option<Caps> {
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<O: IsA<Stream> + IsA<glib::object::Object>> StreamExt for O {
// unsafe { TODO: call ffi::gst_stream_get_tags() }
//}
//#[cfg(feature = "v1_10")]
//fn set_caps<'a, P: Into<Option<&'a /*Ignored*/Caps>>>(&self, caps: P) {
// unsafe { TODO: call ffi::gst_stream_set_caps() }
//}
#[cfg(feature = "v1_10")]
fn set_caps<'a, P: Into<Option<&'a Caps>>>(&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<O: IsA<Stream> + IsA<glib::object::Object>> StreamExt for O {
// unsafe { TODO: call ffi::gst_stream_set_tags() }
//}
//fn get_property_caps(&self) -> /*Ignored*/Option<Caps> {
// 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);

View file

@ -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;

View file

@ -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;

263
gstreamer/src/caps.rs Normal file
View file

@ -0,0 +1,263 @@
// Copyright (C) 2016-2017 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<CapsRef>;
unsafe impl MiniObject for CapsRef {
type GstType = ffi::GstCaps;
}
impl CapsRef {
pub fn new_empty() -> GstRc<Self> {
unsafe { from_glib_full(ffi::gst_caps_new_empty()) }
}
pub fn new_any() -> GstRc<Self> {
unsafe { from_glib_full(ffi::gst_caps_new_any()) }
}
pub fn new_simple(name: &str, values: &[(&str, glib::Value)]) -> GstRc<Self> {
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<GstRc<Self>> {
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<CapsRef> {
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<Self::Item> {
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<usize>) {
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<Self::Item> {
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<CapsRef>;
fn to_owned(&self) -> GstRc<CapsRef> {
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()
);
}
}
*/

View file

@ -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;

View file

@ -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);
}
}