Add StaticCaps and StaticPadTemplate bindings

No way to create them though, just use lazy_static from Rust instead if
something like this is needed.
This commit is contained in:
Sebastian Dröge 2017-10-15 11:08:56 +03:00
parent faae914f72
commit 9206ddba61
7 changed files with 288 additions and 9 deletions

View file

@ -83,6 +83,8 @@ manual = [
"GLib.DateTime", "GLib.DateTime",
"GObject.Object", "GObject.Object",
"Gst.Segment", "Gst.Segment",
"Gst.StaticCaps",
"Gst.StaticPadTemplate",
] ]
[[object]] [[object]]
@ -447,6 +449,11 @@ status = "generate"
# Pass by value # Pass by value
ignore = true ignore = true
[[object.function]]
name = "new_from_static_template"
# Correct mutability
ignore = true
[[object]] [[object]]
name = "Gst.PadTemplate" name = "Gst.PadTemplate"
status = "generate" status = "generate"

View file

@ -7,6 +7,7 @@ use ElementFactoryListType;
use Object; use Object;
use PadDirection; use PadDirection;
use Rank; use Rank;
use StaticPadTemplate;
use URIType; use URIType;
use ffi; use ffi;
use glib; use glib;
@ -81,9 +82,11 @@ impl ElementFactory {
} }
} }
//pub fn get_static_pad_templates(&self) -> /*Ignored*/Vec<StaticPadTemplate> { pub fn get_static_pad_templates(&self) -> Vec<StaticPadTemplate> {
// unsafe { TODO: call ffi::gst_element_factory_get_static_pad_templates() } unsafe {
//} FromGlibPtrContainer::from_glib_none(ffi::gst_element_factory_get_static_pad_templates(self.to_glib_none().0))
}
}
pub fn get_uri_protocols(&self) -> Vec<String> { pub fn get_uri_protocols(&self) -> Vec<String> {
unsafe { unsafe {

View file

@ -50,10 +50,6 @@ impl Pad {
} }
} }
//pub fn new_from_static_template(templ: /*Ignored*/&mut StaticPadTemplate, name: &str) -> Pad {
// unsafe { TODO: call ffi::gst_pad_new_from_static_template() }
//}
pub fn new_from_template<'a, P: Into<Option<&'a str>>>(templ: &PadTemplate, name: P) -> Pad { pub fn new_from_template<'a, P: Into<Option<&'a str>>>(templ: &PadTemplate, name: P) -> Pad {
skip_assert_initialized!(); skip_assert_initialized!();
let name = name.into(); let name = name.into();

View file

@ -83,6 +83,10 @@ pub mod event;
pub use event::{Event, EventRef, EventView}; pub use event::{Event, EventRef, EventView};
pub mod context; pub mod context;
pub use context::{Context, ContextRef}; pub use context::{Context, ContextRef};
mod static_caps;
pub use static_caps::*;
mod static_pad_template;
pub use static_pad_template::*;
mod element; mod element;
mod bin; mod bin;

View file

@ -15,6 +15,7 @@ use FlowReturn;
use Query; use Query;
use QueryRef; use QueryRef;
use Event; use Event;
use StaticPadTemplate;
use miniobject::MiniObject; use miniobject::MiniObject;
use std::mem::transmute; use std::mem::transmute;
@ -24,8 +25,8 @@ use std::cell::RefCell;
use glib; use glib;
use glib::{IsA, StaticType}; use glib::{IsA, StaticType};
use glib::translate::{from_glib, from_glib_borrow, from_glib_full, from_glib_none, FromGlib, use glib::translate::{mut_override, from_glib, from_glib_borrow, from_glib_full, from_glib_none,
ToGlib, ToGlibPtr}; FromGlib, ToGlib, ToGlibPtr};
use glib::source::CallbackGuard; use glib::source::CallbackGuard;
use glib_ffi; use glib_ffi;
use glib_ffi::gpointer; use glib_ffi::gpointer;
@ -35,6 +36,15 @@ use libc;
use ffi; use ffi;
impl Pad {
pub fn new_from_static_template(templ: &StaticPadTemplate, name: &str) -> Pad {
assert_initialized_main_thread!();
unsafe {
from_glib_none(ffi::gst_pad_new_from_static_template(mut_override(templ.to_glib_none().0), name.to_glib_none().0))
}
}
}
#[derive(Debug, Default, PartialEq, Eq)] #[derive(Debug, Default, PartialEq, Eq)]
pub struct PadProbeId(libc::c_ulong); pub struct PadProbeId(libc::c_ulong);
pub const PAD_PROBE_ID_INVALID: PadProbeId = PadProbeId(0); pub const PAD_PROBE_ID_INVALID: PadProbeId = PadProbeId(0);

View file

@ -0,0 +1,119 @@
// Copyright (C) 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 Caps;
use ffi;
use glib_ffi;
use gobject_ffi;
use std::ptr;
use glib;
use glib::translate::{from_glib_full, from_glib_none, mut_override, FromGlibPtrNone, ToGlibPtr,
ToGlibPtrMut};
#[repr(C)]
pub struct StaticCaps(ffi::GstStaticCaps);
impl StaticCaps {
pub fn get(&self) -> Caps {
unsafe { from_glib_full(ffi::gst_static_caps_get(mut_override(&self.0))) }
}
}
unsafe impl Send for StaticCaps {}
unsafe impl Sync for StaticCaps {}
impl glib::types::StaticType for StaticCaps {
fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(ffi::gst_static_caps_get_type()) }
}
}
#[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for StaticCaps {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<StaticCaps>::from_glib_none(
gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as *mut ffi::GstStaticCaps,
)
}
}
#[doc(hidden)]
impl glib::value::SetValue for StaticCaps {
unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(this).0 as
glib_ffi::gpointer,
)
}
}
#[doc(hidden)]
impl glib::value::SetValueOptional for StaticCaps {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(&this).0 as
glib_ffi::gpointer,
)
}
}
#[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticCaps {
type GlibType = *mut ffi::GstStaticCaps;
}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCaps {
type Storage = &'a StaticCaps;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> {
glib::translate::Stash(&self.0, self)
}
fn to_glib_full(&self) -> *const ffi::GstStaticCaps {
unimplemented!()
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstStaticCaps) -> Self {
StaticCaps(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstStaticCaps) -> Self {
StaticCaps(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticCaps) -> Self {
StaticCaps(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_full(ptr: *mut ffi::GstStaticCaps) -> Self {
let caps = from_glib_none(ptr);
glib_ffi::g_free(ptr as *mut _);
caps
}
}

View file

@ -0,0 +1,140 @@
// Copyright (C) 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 PadTemplate;
use Caps;
use ffi;
use glib_ffi;
use gobject_ffi;
use std::ffi::CStr;
use std::ptr;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, mut_override, FromGlibPtrNone,
ToGlibPtr, ToGlibPtrMut};
#[repr(C)]
pub struct StaticPadTemplate(ffi::GstStaticPadTemplate);
impl StaticPadTemplate {
pub fn get(&self) -> PadTemplate {
unsafe { from_glib_full(ffi::gst_static_pad_template_get(mut_override(&self.0))) }
}
pub fn get_caps(&self) -> Caps {
unsafe { from_glib_full(ffi::gst_static_pad_template_get_caps(mut_override(&self.0))) }
}
pub fn name_template<'a>(&self) -> &'a str {
unsafe { CStr::from_ptr(self.0.name_template).to_str().unwrap() }
}
pub fn direction(&self) -> ::PadDirection {
from_glib(self.0.direction)
}
pub fn presence(&self) -> ::PadPresence {
from_glib(self.0.presence)
}
}
unsafe impl Send for StaticPadTemplate {}
unsafe impl Sync for StaticPadTemplate {}
impl glib::types::StaticType for StaticPadTemplate {
fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(ffi::gst_static_pad_template_get_type()) }
}
}
#[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for StaticPadTemplate {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<StaticPadTemplate>::from_glib_none(
gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as
*mut ffi::GstStaticPadTemplate,
)
}
}
#[doc(hidden)]
impl glib::value::SetValue for StaticPadTemplate {
unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(this).0 as
glib_ffi::gpointer,
)
}
}
#[doc(hidden)]
impl glib::value::SetValueOptional for StaticPadTemplate {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(&this).0 as
glib_ffi::gpointer,
)
}
}
#[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticPadTemplate {
type GlibType = *mut ffi::GstStaticPadTemplate;
}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate {
type Storage = &'a StaticPadTemplate;
fn to_glib_none(
&'a self,
) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> {
glib::translate::Stash(&self.0, self)
}
fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate {
unimplemented!()
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline]
unsafe fn from_glib_none(ptr: *const ffi::GstStaticPadTemplate) -> Self {
StaticPadTemplate(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline]
unsafe fn from_glib_none(ptr: *mut ffi::GstStaticPadTemplate) -> Self {
StaticPadTemplate(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline]
unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticPadTemplate) -> Self {
StaticPadTemplate(ptr::read(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline]
unsafe fn from_glib_full(ptr: *mut ffi::GstStaticPadTemplate) -> Self {
let templ = from_glib_none(ptr);
glib_ffi::g_free(ptr as *mut _);
templ
}
}