Move all minobjects to newtype wrapper types

For consistency with external crates and to help rustdoc, which gets
confused on impl blocks for type aliases.
This commit is contained in:
Sebastian Dröge 2018-09-28 18:11:46 +03:00
parent 26ee546d1a
commit 6fd0ed4cb3
12 changed files with 105 additions and 307 deletions

View file

@ -21,19 +21,19 @@ use ClockTime;
use ffi; use ffi;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
use glib_ffi; use glib_ffi;
pub enum Readable {} pub enum Readable {}
pub enum Writable {} pub enum Writable {}
#[repr(C)] gst_define_mini_object_wrapper!(
pub struct BufferRef(ffi::GstBuffer); Buffer,
pub type Buffer = GstRc<BufferRef>; BufferRef,
ffi::GstBuffer,
unsafe impl MiniObject for BufferRef { [Debug, PartialEq, Eq,],
type GstType = ffi::GstBuffer; || ffi::gst_buffer_get_type()
} );
pub struct BufferMap<'a, T> { pub struct BufferMap<'a, T> {
buffer: &'a BufferRef, buffer: &'a BufferRef,
@ -47,7 +47,7 @@ pub struct MappedBuffer<T> {
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
impl GstRc<BufferRef> { impl Buffer {
pub fn new() -> Self { pub fn new() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
@ -161,7 +161,7 @@ impl GstRc<BufferRef> {
} }
} }
impl Default for GstRc<BufferRef> { impl Default for Buffer {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
@ -369,23 +369,6 @@ impl BufferRef {
} }
} }
unsafe impl Sync for BufferRef {}
unsafe impl Send for BufferRef {}
impl glib::types::StaticType for BufferRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_buffer_get_type()) }
}
}
impl ToOwned for BufferRef {
type Owned = GstRc<BufferRef>;
fn to_owned(&self) -> GstRc<BufferRef> {
unsafe { from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _) }
}
}
impl fmt::Debug for BufferRef { impl fmt::Debug for BufferRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Buffer") f.debug_struct("Buffer")

View file

@ -8,22 +8,23 @@
use ffi; use ffi;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlibPtr};
use glib::StaticType; use glib_ffi;
use std::fmt; use std::fmt;
use miniobject::*; use miniobject::*;
use Buffer; use Buffer;
use BufferRef; use BufferRef;
pub type BufferList = GstRc<BufferListRef>; gst_define_mini_object_wrapper!(
pub struct BufferListRef(ffi::GstBufferList); BufferList,
BufferListRef,
ffi::GstBufferList,
[Debug,],
|| ffi::gst_buffer_list_get_type()
);
unsafe impl MiniObject for BufferListRef { impl BufferList {
type GstType = ffi::GstBufferList;
}
impl GstRc<BufferListRef> {
pub fn new() -> Self { pub fn new() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_buffer_list_new()) } unsafe { from_glib_full(ffi::gst_buffer_list_new()) }
@ -95,23 +96,12 @@ impl BufferListRef {
} }
} }
impl Default for GstRc<BufferListRef> { impl Default for BufferList {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
} }
impl ToOwned for BufferListRef {
type Owned = GstRc<BufferListRef>;
fn to_owned(&self) -> GstRc<BufferListRef> {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _)
}
}
}
impl fmt::Debug for BufferListRef { impl fmt::Debug for BufferListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let size = self.iter().map(|b| b.get_size()).sum::<usize>(); let size = self.iter().map(|b| b.get_size()).sum::<usize>();
@ -130,15 +120,6 @@ impl fmt::Debug for BufferListRef {
} }
} }
impl StaticType for BufferListRef {
fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_buffer_list_get_type()) }
}
}
unsafe impl Sync for BufferListRef {}
unsafe impl Send for BufferListRef {}
pub struct Iter<'a> { pub struct Iter<'a> {
list: &'a BufferListRef, list: &'a BufferListRef,
idx: u32, idx: u32,

View file

@ -17,19 +17,15 @@ use CapsIntersectMode;
use ffi; use ffi;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
use glib::value::ToSendValue; use glib::value::ToSendValue;
use glib_ffi;
#[repr(C)] gst_define_mini_object_wrapper!(Caps, CapsRef, ffi::GstCaps, [Debug, PartialEq, Eq,], || {
pub struct CapsRef(ffi::GstCaps); ffi::gst_caps_get_type()
});
pub type Caps = GstRc<CapsRef>; impl Caps {
unsafe impl MiniObject for CapsRef {
type GstType = ffi::GstCaps;
}
impl GstRc<CapsRef> {
pub fn builder(name: &str) -> Builder { pub fn builder(name: &str) -> Builder {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
Builder::new(name) Builder::new(name)
@ -340,12 +336,6 @@ impl CapsRef {
} }
} }
impl glib::types::StaticType for CapsRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_caps_get_type()) }
}
}
macro_rules! define_iter( macro_rules! define_iter(
($name:ident, $typ:ty, $styp:ty, $get_item:expr) => { ($name:ident, $typ:ty, $styp:ty, $get_item:expr) => {
pub struct $name<'a> { pub struct $name<'a> {
@ -500,17 +490,6 @@ impl PartialEq for CapsRef {
impl Eq for CapsRef {} impl Eq for CapsRef {}
impl ToOwned for CapsRef {
type Owned = GstRc<CapsRef>;
fn to_owned(&self) -> GstRc<CapsRef> {
unsafe { from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _) }
}
}
unsafe impl Sync for CapsRef {}
unsafe impl Send for CapsRef {}
pub struct Builder<'a> { pub struct Builder<'a> {
s: ::Structure, s: ::Structure,
features: Option<&'a [&'a str]>, features: Option<&'a [&'a str]>,

View file

@ -12,20 +12,17 @@ use std::fmt;
use ffi; use ffi;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
use glib::StaticType; use glib_ffi;
use miniobject::*; use miniobject::*;
use StructureRef; use StructureRef;
pub type Context = GstRc<ContextRef>; gst_define_mini_object_wrapper!(Context, ContextRef, ffi::GstContext, [Debug,], || {
pub struct ContextRef(ffi::GstContext); ffi::gst_context_get_type()
});
unsafe impl MiniObject for ContextRef { impl Context {
type GstType = ffi::GstContext;
}
impl GstRc<ContextRef> {
pub fn new(context_type: &str, persistent: bool) -> Self { pub fn new(context_type: &str, persistent: bool) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
@ -71,12 +68,6 @@ impl ContextRef {
} }
} }
impl StaticType for ContextRef {
fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_context_get_type()) }
}
}
impl fmt::Debug for ContextRef { impl fmt::Debug for ContextRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Context") f.debug_struct("Context")
@ -85,17 +76,3 @@ impl fmt::Debug for ContextRef {
.finish() .finish()
} }
} }
impl ToOwned for ContextRef {
type Owned = GstRc<ContextRef>;
fn to_owned(&self) -> GstRc<ContextRef> {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _)
}
}
}
unsafe impl Sync for ContextRef {}
unsafe impl Send for ContextRef {}

View file

@ -19,8 +19,9 @@ use std::ops::Deref;
use std::ptr; use std::ptr;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, FromGlib, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, from_glib_none, FromGlib, ToGlib, ToGlibPtr};
use glib::value::ToSendValue; use glib::value::ToSendValue;
use glib_ffi;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
use glib::translate::FromGlibPtrContainer; use glib::translate::FromGlibPtrContainer;
@ -110,18 +111,6 @@ impl FromGlib<u32> for GroupId {
} }
} }
#[repr(C)]
pub struct EventRef(ffi::GstEvent);
pub type Event = GstRc<EventRef>;
unsafe impl Sync for EventRef {}
unsafe impl Send for EventRef {}
unsafe impl MiniObject for EventRef {
type GstType = ffi::GstEvent;
}
impl EventType { impl EventType {
pub fn is_upstream(self) -> bool { pub fn is_upstream(self) -> bool {
(self.to_glib() as u32) & ffi::GST_EVENT_TYPE_UPSTREAM != 0 (self.to_glib() as u32) & ffi::GST_EVENT_TYPE_UPSTREAM != 0
@ -176,6 +165,10 @@ impl PartialOrd for EventType {
} }
} }
gst_define_mini_object_wrapper!(Event, EventRef, ffi::GstEvent, [Debug,], || {
ffi::gst_event_get_type()
});
impl EventRef { impl EventRef {
pub fn get_seqnum(&self) -> Seqnum { pub fn get_seqnum(&self) -> Seqnum {
unsafe { from_glib(ffi::gst_event_get_seqnum(self.as_mut_ptr())) } unsafe { from_glib(ffi::gst_event_get_seqnum(self.as_mut_ptr())) }
@ -266,7 +259,7 @@ impl EventRef {
} }
} }
impl GstRc<EventRef> { impl Event {
pub fn new_flush_start<'a>() -> FlushStartBuilder<'a> { pub fn new_flush_start<'a>() -> FlushStartBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
FlushStartBuilder::new() FlushStartBuilder::new()
@ -452,12 +445,6 @@ impl GstRc<EventRef> {
} }
} }
impl glib::types::StaticType for EventRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_event_get_type()) }
}
}
impl fmt::Debug for EventRef { impl fmt::Debug for EventRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Event") f.debug_struct("Event")
@ -471,14 +458,6 @@ impl fmt::Debug for EventRef {
} }
} }
impl ToOwned for EventRef {
type Owned = GstRc<EventRef>;
fn to_owned(&self) -> GstRc<EventRef> {
unsafe { from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _) }
}
}
pub enum EventView<'a> { pub enum EventView<'a> {
FlushStart(FlushStart<'a>), FlushStart(FlushStart<'a>),
FlushStop(FlushStop<'a>), FlushStop(FlushStop<'a>),

View file

@ -71,6 +71,7 @@ pub use log::*;
mod error; mod error;
pub use error::*; pub use error::*;
#[macro_use]
pub mod miniobject; pub mod miniobject;
pub use miniobject::{GstRc, MiniObject}; pub use miniobject::{GstRc, MiniObject};
pub mod message; pub mod message;

View file

@ -27,18 +27,11 @@ use glib::translate::{from_glib, from_glib_full, from_glib_none, mut_override, T
use glib::value::ToSendValue; use glib::value::ToSendValue;
use glib::Cast; use glib::Cast;
use glib::IsA; use glib::IsA;
use glib_ffi;
#[repr(C)] gst_define_mini_object_wrapper!(Message, MessageRef, ffi::GstMessage, [Debug,], || {
pub struct MessageRef(ffi::GstMessage); ffi::gst_message_get_type()
});
pub type Message = GstRc<MessageRef>;
unsafe impl Sync for MessageRef {}
unsafe impl Send for MessageRef {}
unsafe impl MiniObject for MessageRef {
type GstType = ffi::GstMessage;
}
impl MessageRef { impl MessageRef {
pub fn get_src(&self) -> Option<Object> { pub fn get_src(&self) -> Option<Object> {
@ -113,7 +106,7 @@ impl MessageRef {
} }
} }
impl GstRc<MessageRef> { impl Message {
pub fn new_eos<'a>() -> EosBuilder<'a> { pub fn new_eos<'a>() -> EosBuilder<'a> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
EosBuilder::new() EosBuilder::new()
@ -348,12 +341,6 @@ impl GstRc<MessageRef> {
} }
} }
impl glib::types::StaticType for MessageRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_message_get_type()) }
}
}
impl fmt::Debug for MessageRef { impl fmt::Debug for MessageRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Message") f.debug_struct("Message")
@ -368,14 +355,6 @@ impl fmt::Debug for MessageRef {
} }
} }
impl ToOwned for MessageRef {
type Owned = GstRc<MessageRef>;
fn to_owned(&self) -> GstRc<MessageRef> {
unsafe { from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _) }
}
}
pub enum MessageView<'a> { pub enum MessageView<'a> {
Eos(Eos<'a>), Eos(Eos<'a>),
Error(Error<'a>), Error(Error<'a>),

View file

@ -501,15 +501,15 @@ macro_rules! gst_define_mini_object_wrapper(
impl $name { impl $name {
pub unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self { pub unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
$name(from_glib_none(ptr)) $name(glib::translate::from_glib_none(ptr))
} }
pub unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self { pub unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
$name(from_glib_full(ptr)) $name(glib::translate::from_glib_full(ptr))
} }
pub unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self { pub unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
$name(from_glib_borrow(ptr)) $name(glib::translate::from_glib_borrow(ptr))
} }
pub unsafe fn into_ptr(self) -> *mut $ffi_name { pub unsafe fn into_ptr(self) -> *mut $ffi_name {
@ -517,6 +517,18 @@ macro_rules! gst_define_mini_object_wrapper(
} }
} }
impl From<$crate::GstRc<$ref_name>> for $name {
fn from(rc: $crate::GstRc<$ref_name>) -> $name {
$name(rc)
}
}
impl Into<$crate::GstRc<$ref_name>> for $name {
fn into(self) -> $crate::GstRc<$ref_name> {
self.0
}
}
impl ::std::ops::Deref for $name { impl ::std::ops::Deref for $name {
type Target = $crate::GstRc<$ref_name>; type Target = $crate::GstRc<$ref_name>;
@ -595,7 +607,7 @@ macro_rules! gst_define_mini_object_wrapper(
skip_assert_initialized!(); skip_assert_initialized!();
let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect(); let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect(); let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
v_ptr.push(ptr::null_mut() as *mut $ffi_name); v_ptr.push(::std::ptr::null_mut() as *mut $ffi_name);
(v_ptr.as_ptr() as *mut *mut $ffi_name, (v, Some(v_ptr))) (v_ptr.as_ptr() as *mut *mut $ffi_name, (v, Some(v_ptr)))
} }
@ -605,11 +617,11 @@ macro_rules! gst_define_mini_object_wrapper(
let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect(); let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
let v_ptr = unsafe { let v_ptr = unsafe {
let v_ptr = glib_ffi::g_malloc0(mem::size_of::<*mut $ffi_name>() * t.len() + 1) let v_ptr = glib_ffi::g_malloc0(::std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
as *mut *mut $ffi_name; as *mut *mut $ffi_name;
for (i, s) in v.iter().enumerate() { for (i, s) in v.iter().enumerate() {
ptr::write(v_ptr.offset(i as isize), s.0); ::std::ptr::write(v_ptr.offset(i as isize), s.0);
} }
v_ptr v_ptr
@ -621,11 +633,11 @@ macro_rules! gst_define_mini_object_wrapper(
fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name { fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let v_ptr = glib_ffi::g_malloc0(mem::size_of::<*mut $ffi_name>() * t.len() + 1) let v_ptr = glib_ffi::g_malloc0(::std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
as *mut *mut $ffi_name; as *mut *mut $ffi_name;
for (i, s) in t.iter().enumerate() { for (i, s) in t.iter().enumerate() {
ptr::write(v_ptr.offset(i as isize), s.to_glib_full()); ::std::ptr::write(v_ptr.offset(i as isize), s.to_glib_full());
} }
v_ptr v_ptr
@ -708,7 +720,7 @@ macro_rules! gst_define_mini_object_wrapper(
let mut res = Vec::with_capacity(num); let mut res = Vec::with_capacity(num);
for i in 0..num { for i in 0..num {
res.push(from_glib_none(ptr::read(ptr.offset(i as isize)))); res.push(from_glib_none(::std::ptr::read(ptr.offset(i as isize))));
} }
res res
} }
@ -726,7 +738,7 @@ macro_rules! gst_define_mini_object_wrapper(
let mut res = Vec::with_capacity(num); let mut res = Vec::with_capacity(num);
for i in 0..num { for i in 0..num {
res.push(from_glib_full(ptr::read(ptr.offset(i as isize)))); res.push(from_glib_full(::std::ptr::read(ptr.offset(i as isize))));
} }
glib_ffi::g_free(ptr as *mut _); glib_ffi::g_free(ptr as *mut _);
res res
@ -788,19 +800,19 @@ macro_rules! gst_define_mini_object_wrapper(
for $name for $name
{ {
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> { unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
<gst::GstRc<$ref_name> as glib::value::FromValueOptional>::from_value_optional(v).map($name) <$crate::GstRc<$ref_name> as glib::value::FromValueOptional>::from_value_optional(v).map($name)
} }
} }
impl glib::value::SetValue for $name { impl glib::value::SetValue for $name {
unsafe fn set_value(v: &mut glib::Value, s: &Self) { unsafe fn set_value(v: &mut glib::Value, s: &Self) {
<gst::GstRc<$ref_name> as glib::value::SetValue>::set_value(v, &s.0) <$crate::GstRc<$ref_name> as glib::value::SetValue>::set_value(v, &s.0)
} }
} }
impl glib::value::SetValueOptional for $name { impl glib::value::SetValueOptional for $name {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) { unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
<gst::GstRc<$ref_name> as glib::value::SetValueOptional>::set_value_optional(v, s.map(|s| &s.0)) <$crate::GstRc<$ref_name> as glib::value::SetValueOptional>::set_value_optional(v, s.map(|s| &s.0))
} }
} }

View file

@ -19,20 +19,13 @@ use std::ptr;
use glib; use glib;
use glib::translate::*; use glib::translate::*;
use glib_ffi;
#[repr(C)] gst_define_mini_object_wrapper!(Query, QueryRef, ffi::GstQuery, [Debug,], || {
pub struct QueryRef(ffi::GstQuery); ffi::gst_query_get_type()
});
unsafe impl Send for QueryRef {} impl Query {
unsafe impl Sync for QueryRef {}
pub type Query = GstRc<QueryRef>;
unsafe impl MiniObject for QueryRef {
type GstType = ffi::GstQuery;
}
impl GstRc<QueryRef> {
pub fn new_position(fmt: ::Format) -> Position<Self> { pub fn new_position(fmt: ::Format) -> Position<Self> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { Position::<Self>(from_glib_full(ffi::gst_query_new_position(fmt.to_glib()))) } unsafe { Position::<Self>(from_glib_full(ffi::gst_query_new_position(fmt.to_glib()))) }
@ -199,12 +192,6 @@ impl QueryRef {
} }
} }
impl glib::types::StaticType for QueryRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_query_get_type()) }
}
}
impl fmt::Debug for QueryRef { impl fmt::Debug for QueryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Query") f.debug_struct("Query")

View file

@ -13,7 +13,7 @@ use ffi;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, mut_override, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, from_glib_none, mut_override, ToGlibPtr};
use glib::StaticType; use glib_ffi;
use miniobject::*; use miniobject::*;
use Buffer; use Buffer;
@ -25,14 +25,11 @@ use Segment;
use Structure; use Structure;
use StructureRef; use StructureRef;
pub type Sample = GstRc<SampleRef>; gst_define_mini_object_wrapper!(Sample, SampleRef, ffi::GstSample, [Debug,], || {
pub struct SampleRef(ffi::GstSample); ffi::gst_sample_get_type()
});
unsafe impl MiniObject for SampleRef { impl Sample {
type GstType = ffi::GstSample;
}
impl GstRc<SampleRef> {
pub fn new<F: FormattedValue>( pub fn new<F: FormattedValue>(
buffer: Option<&Buffer>, buffer: Option<&Buffer>,
caps: Option<&Caps>, caps: Option<&Caps>,
@ -96,23 +93,6 @@ impl SampleRef {
} }
} }
impl StaticType for SampleRef {
fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_sample_get_type()) }
}
}
impl ToOwned for SampleRef {
type Owned = GstRc<SampleRef>;
fn to_owned(&self) -> GstRc<SampleRef> {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _)
}
}
}
impl fmt::Debug for SampleRef { impl fmt::Debug for SampleRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Sample") f.debug_struct("Sample")
@ -124,9 +104,6 @@ impl fmt::Debug for SampleRef {
} }
} }
unsafe impl Sync for SampleRef {}
unsafe impl Send for SampleRef {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -13,9 +13,9 @@ use std::mem;
use ffi; use ffi;
use glib; use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr, ToGlibPtrMut};
use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue}; use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue};
use glib::StaticType; use glib_ffi;
use miniobject::*; use miniobject::*;
@ -337,21 +337,22 @@ impl_tag!(
); );
impl_tag!(PrivateData, Sample, TAG_PRIVATE_DATA, GST_TAG_PRIVATE_DATA); impl_tag!(PrivateData, Sample, TAG_PRIVATE_DATA, GST_TAG_PRIVATE_DATA);
pub type TagList = GstRc<TagListRef>; gst_define_mini_object_wrapper!(
pub struct TagListRef(ffi::GstTagList); TagList,
TagListRef,
ffi::GstTagList,
[Debug, PartialEq, Eq,],
|| ffi::gst_tag_list_get_type()
);
unsafe impl MiniObject for TagListRef { impl TagList {
type GstType = ffi::GstTagList;
}
impl GstRc<TagListRef> {
pub fn new() -> Self { pub fn new() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_tag_list_new_empty()) } unsafe { from_glib_full(ffi::gst_tag_list_new_empty()) }
} }
} }
impl Default for GstRc<TagListRef> { impl Default for TagList {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()
} }
@ -508,23 +509,6 @@ impl PartialEq for TagListRef {
impl Eq for TagListRef {} impl Eq for TagListRef {}
impl ToOwned for TagListRef {
type Owned = GstRc<TagListRef>;
fn to_owned(&self) -> GstRc<TagListRef> {
unsafe { from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _) }
}
}
impl StaticType for TagListRef {
fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_tag_list_get_type()) }
}
}
unsafe impl Sync for TagListRef {}
unsafe impl Send for TagListRef {}
pub struct TagIterator<'a, T: Tag<'a>> { pub struct TagIterator<'a, T: Tag<'a>> {
taglist: &'a TagListRef, taglist: &'a TagListRef,
idx: u32, idx: u32,

View file

@ -16,6 +16,7 @@ use glib;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlibPtrContainer, ToGlib, ToGlibPtr, from_glib, from_glib_full, from_glib_none, FromGlibPtrContainer, ToGlib, ToGlibPtr,
}; };
use glib_ffi;
use miniobject::*; use miniobject::*;
use TagList; use TagList;
@ -24,14 +25,15 @@ use TocEntryType;
use TocLoopType; use TocLoopType;
use TocScope; use TocScope;
pub type Toc = GstRc<TocRef>; gst_define_mini_object_wrapper!(
pub struct TocRef(ffi::GstToc); Toc,
TocRef,
ffi::GstToc,
[Debug,],
|| ffi::gst_toc_get_type()
);
unsafe impl MiniObject for TocRef { impl Toc {
type GstType = ffi::GstToc;
}
impl GstRc<TocRef> {
pub fn new(scope: TocScope) -> Self { pub fn new(scope: TocScope) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gst_toc_new(scope.to_glib())) } unsafe { from_glib_full(ffi::gst_toc_new(scope.to_glib())) }
@ -80,23 +82,6 @@ impl TocRef {
} }
} }
impl glib::types::StaticType for TocRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_toc_get_type()) }
}
}
impl ToOwned for TocRef {
type Owned = GstRc<TocRef>;
fn to_owned(&self) -> GstRc<TocRef> {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _)
}
}
}
impl fmt::Debug for TocRef { impl fmt::Debug for TocRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Toc") f.debug_struct("Toc")
@ -107,17 +92,11 @@ impl fmt::Debug for TocRef {
} }
} }
unsafe impl Sync for TocRef {} gst_define_mini_object_wrapper!(TocEntry, TocEntryRef, ffi::GstTocEntry, [Debug,], || {
unsafe impl Send for TocRef {} ffi::gst_toc_entry_get_type()
});
pub type TocEntry = GstRc<TocEntryRef>; impl TocEntry {
pub struct TocEntryRef(ffi::GstTocEntry);
unsafe impl MiniObject for TocEntryRef {
type GstType = ffi::GstTocEntry;
}
impl GstRc<TocEntryRef> {
pub fn new(type_: TocEntryType, uid: &str) -> Self { pub fn new(type_: TocEntryType, uid: &str) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
@ -228,23 +207,6 @@ impl TocEntryRef {
} }
} }
impl glib::types::StaticType for TocEntryRef {
fn static_type() -> glib::types::Type {
unsafe { from_glib(ffi::gst_toc_entry_get_type()) }
}
}
impl ToOwned for TocEntryRef {
type Owned = GstRc<TocEntryRef>;
fn to_owned(&self) -> GstRc<TocEntryRef> {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe {
from_glib_full(ffi::gst_mini_object_copy(self.as_ptr() as *const _) as *mut _)
}
}
}
impl fmt::Debug for TocEntryRef { impl fmt::Debug for TocEntryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("TocEntry") f.debug_struct("TocEntry")
@ -260,9 +222,6 @@ impl fmt::Debug for TocEntryRef {
} }
} }
unsafe impl Sync for TocEntryRef {}
unsafe impl Send for TocEntryRef {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;