gstreamer: Simplify MiniObject bindings by removing one layer of abstraction

And instead directly implementing this via the macro on the target
types.
This commit is contained in:
Sebastian Dröge 2020-06-30 00:12:46 +03:00
parent 947ac8db5c
commit af01f1bc67
45 changed files with 321 additions and 670 deletions

View file

@ -78,7 +78,6 @@ mod custom_meta {
use glib::glib_sys;
use glib::translate::*;
use gst::gst_sys;
use gst::prelude::*;
use once_cell::sync::Lazy;
use std::mem;
use std::ptr;

View file

@ -12,7 +12,6 @@ use gst_sys;
use glib;
use glib::translate::{from_glib, Borrowed, FromGlibPtrNone, ToGlibPtr};
use gst;
use gst::miniobject::MiniObject;
use std::fmt;
use std::marker::PhantomData;

View file

@ -14,7 +14,6 @@ use std::mem;
use glib;
use glib::translate::{from_glib, ToGlib};
use gst;
use gst::MiniObject;
use array_init;

View file

@ -15,7 +15,6 @@ use glib::translate::*;
use glib::subclass::prelude::*;
use gst;
use gst::subclass::prelude::*;
use gst::MiniObject;
use gst_base;
use std::mem;

View file

@ -15,7 +15,6 @@ use glib::translate::*;
use glib::subclass::prelude::*;
use gst;
use gst::subclass::prelude::*;
use gst::MiniObject;
use std::ptr;

View file

@ -8,7 +8,6 @@
use glib::translate::*;
use gst;
use gst::MiniObject;
use gst_base_sys;
use std::convert::TryFrom;
use std::fmt;

View file

@ -12,10 +12,9 @@ use glib_sys;
use gst_base_sys;
use gst_sys;
use glib::translate::*;
use prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use gst;
use gst::subclass::prelude::*;

View file

@ -10,10 +10,9 @@ use glib_sys;
use gst_base_sys;
use gst_sys;
use glib::translate::*;
use prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use gst;
use gst::subclass::prelude::*;

View file

@ -10,10 +10,9 @@ use glib_sys;
use gst_base_sys;
use gst_sys;
use glib::translate::*;
use prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use gst;
use gst::subclass::prelude::*;

View file

@ -9,10 +9,9 @@
use gst_base_sys;
use gst_sys;
use glib::translate::*;
use prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use gst;
use gst::subclass::prelude::*;

View file

@ -8,7 +8,7 @@
use glib::translate::*;
use glib::IsA;
use gst::{ContextRef, MiniObject};
use gst::ContextRef;
use gst_gl_sys;
use std::ptr;
use GLDisplay;

View file

@ -13,7 +13,6 @@ use gst_video_sys;
use glib::translate::{from_glib, ToGlibPtr};
use gst;
use gst::MiniObject;
use gst_video::video_frame::Readable;
use gst_video::*;

View file

@ -9,7 +9,6 @@
use glib;
use glib::translate::*;
use gst;
use gst::MiniObject;
use gst_pbutils_sys;
use std::ptr;

View file

@ -5,7 +5,6 @@ use std::mem;
use std::ptr;
use std::slice;
use gst::MiniObject;
use gst_rtp_sys;
pub enum Readable {}

View file

@ -1,14 +1,12 @@
use glib;
use glib::translate::*;
use gst_rtsp_server_sys;
use gst::prelude::*;
use gst_rtsp_server_sys;
gst_define_mini_object_wrapper!(
RTSPThread,
RTSPThreadRef,
gst_rtsp_server_sys::GstRTSPThread,
[],
|| gst_rtsp_server_sys::gst_rtsp_thread_get_type()
);

View file

@ -2,7 +2,6 @@ use glib;
use glib::translate::*;
use glib::value::ToSendValue;
use gst;
use gst::miniobject::*;
use gst_rtsp_server_sys;
use std::fmt;
@ -11,7 +10,6 @@ gst_define_mini_object_wrapper!(
RTSPToken,
RTSPTokenRef,
gst_rtsp_server_sys::GstRTSPToken,
[Debug,],
|| gst_rtsp_server_sys::gst_rtsp_token_get_type()
);
@ -78,6 +76,12 @@ impl RTSPTokenRef {
}
}
impl fmt::Debug for RTSPToken {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
RTSPTokenRef::fmt(self, f)
}
}
impl fmt::Debug for RTSPTokenRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("RTSPToken")

View file

@ -8,11 +8,9 @@
use gst_rtsp_server_sys;
use glib::subclass::prelude::*;
use glib::translate::*;
use glib::subclass::prelude::*;
use gst::prelude::*;
use std::ptr;
use RTSPMedia;

View file

@ -15,7 +15,7 @@ use std::ptr;
use glib::translate::*;
use gst;
use gst::prelude::*;
use gst_sdp_sys;
use sdp_attribute::SDPAttribute;

View file

@ -16,7 +16,6 @@ use std::ptr;
use glib::translate::*;
use gobject_sys;
use gst;
use gst::MiniObject;
use gst_sdp_sys;
use sdp_attribute::SDPAttribute;

View file

@ -16,7 +16,6 @@ use glib::translate::*;
use glib::subclass::prelude::*;
use gst;
use gst::subclass::prelude::*;
use gst::MiniObject;
use gst_base;
use crate::prelude::*;

View file

@ -16,7 +16,6 @@ use glib::translate::*;
use glib::subclass::prelude::*;
use gst;
use gst::subclass::prelude::*;
use gst::MiniObject;
use crate::prelude::*;
use video_codec_state::{Readable, VideoCodecState};

View file

@ -9,7 +9,6 @@
use glib::translate::*;
use gst;
use gst::miniobject::MiniObject;
use gst_video_sys;
use std::fmt;
use std::mem;

View file

@ -16,7 +16,6 @@ use std::ptr;
use utils::HasStreamLock;
use gst;
use gst::miniobject::MiniObject;
use video_info::VideoInfo;

View file

@ -12,7 +12,6 @@ use gst_video_sys;
use glib::translate::{from_glib, from_glib_full, ToGlib};
use glib::ToSendValue;
use gst;
use gst::MiniObject;
use std::mem;
// FIXME: Copy from gstreamer/src/event.rs

View file

@ -12,7 +12,6 @@ use gst_video_sys;
use glib;
use glib::translate::{from_glib, Borrowed, ToGlibPtr};
use gst;
use gst::miniobject::MiniObject;
use std::fmt;
use std::marker::PhantomData;

View file

@ -8,7 +8,6 @@
use glib::translate::*;
use gst;
use gst::prelude::*;
use gst_video_sys;
use libc::uintptr_t;
use VideoOverlay;

View file

@ -10,7 +10,6 @@ use std::fmt;
use std::mem;
use gst;
use gst::miniobject::*;
use gst_video_sys;
use glib;
@ -20,10 +19,15 @@ gst_define_mini_object_wrapper!(
VideoOverlayRectangle,
VideoOverlayRectangleRef,
gst_video_sys::GstVideoOverlayRectangle,
[Debug,],
|| gst_video_sys::gst_video_overlay_rectangle_get_type()
);
impl fmt::Debug for VideoOverlayRectangle {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
VideoOverlayRectangleRef::fmt(self, f)
}
}
impl fmt::Debug for VideoOverlayRectangleRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("VideoOverlayRectangle")
@ -188,10 +192,15 @@ gst_define_mini_object_wrapper!(
VideoOverlayComposition,
VideoOverlayCompositionRef,
gst_video_sys::GstVideoOverlayComposition,
[Debug,],
|| gst_video_sys::gst_video_overlay_composition_get_type()
);
impl fmt::Debug for VideoOverlayComposition {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
VideoOverlayCompositionRef::fmt(self, f)
}
}
impl fmt::Debug for VideoOverlayCompositionRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("VideoOverlayComposition").finish()

View file

@ -16,7 +16,6 @@ use std::u64;
use std::usize;
use meta::*;
use miniobject::*;
use BufferCursor;
use BufferFlags;
use BufferRefCursor;
@ -32,13 +31,9 @@ use gst_sys;
pub enum Readable {}
pub enum Writable {}
gst_define_mini_object_wrapper!(
Buffer,
BufferRef,
gst_sys::GstBuffer,
[Debug, PartialEq, Eq,],
|| gst_sys::gst_buffer_get_type()
);
gst_define_mini_object_wrapper!(Buffer, BufferRef, gst_sys::GstBuffer, || {
gst_sys::gst_buffer_get_type()
});
pub struct BufferMap<'a, T> {
buffer: &'a BufferRef,
@ -832,6 +827,20 @@ define_iter!(
|buffer: &BufferRef, idx| { buffer.get_memory(idx) }
);
impl fmt::Debug for Buffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
BufferRef::fmt(self, f)
}
}
impl PartialEq for Buffer {
fn eq(&self, other: &Buffer) -> bool {
BufferRef::eq(self, other)
}
}
impl Eq for Buffer {}
impl fmt::Debug for BufferRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use std::cell::RefCell;

View file

@ -14,7 +14,6 @@ use std::ptr;
use std::u64;
use std::usize;
use miniobject::*;
use Buffer;
use BufferRef;

View file

@ -98,7 +98,7 @@ mod tests {
buffer.set_offset(3);
buffer.set_offset_end(4);
buffer.set_duration(5.into());
buffer.set_flags(BufferFlags::LIVE | BufferFlags::LAST);
buffer.set_flags(BufferFlags::LIVE | BufferFlags::DISCONT);
}
let mut pretty_config = ron::ser::PrettyConfig::default();
@ -114,7 +114,7 @@ mod tests {
" offset: 3,",
" offset_end: 4,",
" flags: (",
" bits: 1048592,",
" bits: 80,",
" ),",
" buffer: \"AQIDBA==\",",
")"
@ -132,7 +132,7 @@ mod tests {
"\"duration\":5,",
"\"offset\":3,",
"\"offset_end\":4,",
"\"flags\":{\"bits\":1048592},",
"\"flags\":{\"bits\":80},",
"\"buffer\":[1,2,3,4]",
"}"
)
@ -153,7 +153,7 @@ mod tests {
offset: 3,
offset_end: 4,
flags: (
bits: 1048592,
bits: 80,
),
buffer: "AQIDBA==",
)
@ -164,7 +164,7 @@ mod tests {
assert_eq!(buffer.get_offset(), 3);
assert_eq!(buffer.get_offset_end(), 4);
assert_eq!(buffer.get_duration(), 5.into());
assert_eq!(buffer.get_flags(), BufferFlags::LIVE | BufferFlags::LAST);
assert_eq!(buffer.get_flags(), BufferFlags::LIVE | BufferFlags::DISCONT);
{
let data = buffer.map_readable().unwrap();
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());
@ -177,7 +177,7 @@ mod tests {
"duration":5,
"offset":3,
"offset_end":4,
"flags":{"bits":1048592},
"flags":{"bits":80},
"buffer":[1,2,3,4]
}
"#;
@ -187,7 +187,7 @@ mod tests {
assert_eq!(buffer.get_offset(), 3);
assert_eq!(buffer.get_offset_end(), 4);
assert_eq!(buffer.get_duration(), 5.into());
assert_eq!(buffer.get_flags(), BufferFlags::LIVE | BufferFlags::LAST);
assert_eq!(buffer.get_flags(), BufferFlags::LIVE | BufferFlags::DISCONT);
{
let data = buffer.map_readable().unwrap();
assert_eq!(data.as_slice(), vec![1, 2, 3, 4].as_slice());
@ -205,7 +205,7 @@ mod tests {
buffer.set_offset(3);
buffer.set_offset_end(4);
buffer.set_duration(5.into());
buffer.set_flags(BufferFlags::LIVE | BufferFlags::LAST);
buffer.set_flags(BufferFlags::LIVE | BufferFlags::DISCONT);
}
// Ron

View file

@ -11,17 +11,12 @@ use glib::translate::{from_glib_full, from_glib_none};
use gst_sys;
use std::fmt;
use miniobject::*;
use Buffer;
use BufferRef;
gst_define_mini_object_wrapper!(
BufferList,
BufferListRef,
gst_sys::GstBufferList,
[Debug,],
|| gst_sys::gst_buffer_list_get_type()
);
gst_define_mini_object_wrapper!(BufferList, BufferListRef, gst_sys::GstBufferList, || {
gst_sys::gst_buffer_list_get_type()
});
impl BufferList {
pub fn new() -> Self {
@ -112,6 +107,12 @@ impl Default for BufferList {
}
}
impl fmt::Debug for BufferList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
BufferListRef::fmt(self, f)
}
}
impl fmt::Debug for BufferListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let size = self.iter().map(|b| b.get_size()).sum::<usize>();

View file

@ -7,7 +7,6 @@
// except according to those terms.
use caps_features::*;
use miniobject::*;
use std::fmt;
use std::marker::PhantomData;
use std::ptr;
@ -21,13 +20,9 @@ use glib::translate::{from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlib
use glib::value::ToSendValue;
use gst_sys;
gst_define_mini_object_wrapper!(
Caps,
CapsRef,
gst_sys::GstCaps,
[Debug, PartialEq, Eq,],
|| gst_sys::gst_caps_get_type()
);
gst_define_mini_object_wrapper!(Caps, CapsRef, gst_sys::GstCaps, || {
gst_sys::gst_caps_get_type()
});
impl Caps {
pub fn builder(name: &str) -> Builder<NoFeature> {
@ -179,12 +174,6 @@ impl str::FromStr for Caps {
}
}
impl fmt::Display for Caps {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl CapsRef {
pub fn set_simple(&mut self, values: &[(&str, &dyn ToSendValue)]) {
for &(name, value) in values {
@ -557,6 +546,26 @@ define_iter!(
}
);
impl fmt::Debug for Caps {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<CapsRef as fmt::Debug>::fmt(self, f)
}
}
impl fmt::Display for Caps {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<CapsRef as fmt::Display>::fmt(self, f)
}
}
impl PartialEq for Caps {
fn eq(&self, other: &Caps) -> bool {
CapsRef::eq(self, other)
}
}
impl Eq for Caps {}
impl fmt::Debug for CapsRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("Caps").field(&self.to_string()).finish()

View file

@ -14,10 +14,9 @@ use gst_sys;
use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
use miniobject::*;
use StructureRef;
gst_define_mini_object_wrapper!(Context, ContextRef, gst_sys::GstContext, [Debug,], || {
gst_define_mini_object_wrapper!(Context, ContextRef, gst_sys::GstContext, || {
gst_sys::gst_context_get_type()
});
@ -69,6 +68,12 @@ impl ContextRef {
}
}
impl fmt::Debug for Context {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
ContextRef::fmt(self, f)
}
}
impl fmt::Debug for ContextRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Context")

View file

@ -20,7 +20,6 @@ use glib::translate::FromGlibPtrBorrow;
use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrContainer, ToGlib, ToGlibPtr,
};
use miniobject::MiniObject;
use ClockTime;
use ElementFlags;
use Event;

View file

@ -7,7 +7,6 @@
// except according to those terms.
use gst_sys;
use miniobject::*;
use structure::*;
use GenericFormattedValue;
@ -137,7 +136,7 @@ impl PartialOrd for EventType {
}
}
gst_define_mini_object_wrapper!(Event, EventRef, gst_sys::GstEvent, [Debug,], || {
gst_define_mini_object_wrapper!(Event, EventRef, gst_sys::GstEvent, || {
gst_sys::gst_event_get_type()
});
@ -543,6 +542,12 @@ impl Event {
}
}
impl fmt::Debug for Event {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
EventRef::fmt(self, f)
}
}
impl fmt::Debug for EventRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Event")

View file

@ -83,7 +83,6 @@ pub use error::*;
#[macro_use]
pub mod miniobject;
pub use miniobject::{GstRc, MiniObject};
pub mod message;
pub use message::{Message, MessageErrorDomain, MessageRef, MessageView};
@ -372,7 +371,6 @@ pub mod prelude {
pub use typefind::TypeFindImpl;
pub use value::GstValueExt;
pub use miniobject::MiniObject;
pub use tags::{CustomTag, Tag};
pub use muldiv::MulDiv;

View file

@ -18,13 +18,11 @@ use gst_sys;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlibPtr};
use miniobject::MiniObject;
use AllocationParams;
use Allocator;
use MemoryFlags;
gst_define_mini_object_wrapper!(Memory, MemoryRef, gst_sys::GstMemory, [Debug,], || {
gst_define_mini_object_wrapper!(Memory, MemoryRef, gst_sys::GstMemory, || {
gst_sys::gst_memory_get_type()
});
@ -40,6 +38,12 @@ pub struct MappedMemory<T> {
phantom: PhantomData<T>,
}
impl fmt::Debug for Memory {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
MemoryRef::fmt(self, f)
}
}
impl fmt::Debug for MemoryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Memory")

View file

@ -7,7 +7,6 @@
// except according to those terms.
use gst_sys;
use miniobject::*;
use structure::*;
use GenericFormattedValue;
use GroupId;
@ -30,7 +29,7 @@ use glib::value::ToSendValue;
use glib::Cast;
use glib::IsA;
gst_define_mini_object_wrapper!(Message, MessageRef, gst_sys::GstMessage, [Debug,], || {
gst_define_mini_object_wrapper!(Message, MessageRef, gst_sys::GstMessage, || {
gst_sys::gst_message_get_type()
});
@ -514,6 +513,12 @@ impl Message {
}
}
impl fmt::Debug for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
MessageRef::fmt(self, f)
}
}
impl fmt::Debug for MessageRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Message")

View file

@ -10,7 +10,6 @@ use std::fmt;
use std::marker::PhantomData;
use std::ops;
use miniobject::MiniObject;
use Buffer;
use BufferRef;
#[cfg(any(feature = "v1_14", feature = "dox"))]

View file

@ -1,4 +1,4 @@
// Copyright (C) 2016-2017 Sebastian Dröge <sebastian@centricular.com>
// Copyright (C) 2016-2020 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
@ -6,573 +6,136 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::marker::PhantomData;
use std::mem;
use std::ptr;
use std::{borrow, fmt, ops};
use glib;
use glib::translate::*;
use glib_sys;
use glib_sys::gpointer;
use gobject_sys;
use gst_sys;
pub struct GstRc<T: MiniObject> {
obj: ptr::NonNull<T>,
phantom: PhantomData<T>,
}
impl<T: MiniObject> GstRc<T> {
pub unsafe fn from_glib_none(ptr: *const T::GstType) -> Self {
skip_assert_initialized!();
assert!(!ptr.is_null());
gst_sys::gst_mini_object_ref(ptr as *mut gst_sys::GstMiniObject);
GstRc {
obj: ptr::NonNull::new_unchecked(ptr as *mut T::GstType as *mut T),
phantom: PhantomData,
}
}
pub unsafe fn from_glib_full(ptr: *const T::GstType) -> Self {
assert!(!ptr.is_null());
GstRc {
obj: ptr::NonNull::new_unchecked(ptr as *mut T::GstType as *mut T),
phantom: PhantomData,
}
}
pub unsafe fn from_glib_borrow(ptr: *const T::GstType) -> Borrowed<Self> {
assert!(!ptr.is_null());
Borrowed::new(GstRc {
obj: ptr::NonNull::new_unchecked(ptr as *mut T::GstType as *mut T),
phantom: PhantomData,
})
}
pub unsafe fn replace_ptr(&mut self, ptr: *mut T::GstType) {
assert!(!ptr.is_null());
self.obj = ptr::NonNull::new_unchecked(ptr as *mut T);
}
pub fn make_mut(&mut self) -> &mut T {
unsafe {
if self.is_writable() {
return self.obj.as_mut();
}
let ptr = gst_sys::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut gst_sys::GstMiniObject
);
self.replace_ptr(ptr as *mut T::GstType);
assert!(self.is_writable());
self.obj.as_mut()
}
}
pub fn get_mut(&mut self) -> Option<&mut T> {
if self.is_writable() {
Some(unsafe { self.obj.as_mut() })
} else {
None
}
}
pub fn is_writable(&self) -> bool {
unsafe {
from_glib(gst_sys::gst_mini_object_is_writable(
self.as_ptr() as *const gst_sys::GstMiniObject
))
}
}
pub unsafe fn into_ptr(self) -> *mut T::GstType {
let s = mem::ManuallyDrop::new(self);
s.as_mut_ptr()
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn add_parent<U: MiniObject>(&self, parent: &U) {
unsafe {
gst_sys::gst_mini_object_add_parent(
self.as_ptr() as *mut gst_sys::GstMiniObject,
parent.as_ptr() as *mut gst_sys::GstMiniObject,
);
}
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
pub fn remove_parent<U: MiniObject>(&self, parent: &U) {
unsafe {
gst_sys::gst_mini_object_remove_parent(
self.as_ptr() as *mut gst_sys::GstMiniObject,
parent.as_ptr() as *mut gst_sys::GstMiniObject,
);
}
}
}
impl<T: MiniObject> ops::Deref for GstRc<T> {
type Target = T;
fn deref(&self) -> &T {
self.as_ref()
}
}
impl<T: MiniObject> AsRef<T> for GstRc<T> {
fn as_ref(&self) -> &T {
unsafe { self.obj.as_ref() }
}
}
impl<T: MiniObject> borrow::Borrow<T> for GstRc<T> {
fn borrow(&self) -> &T {
self.as_ref()
}
}
impl<T: MiniObject> Clone for GstRc<T> {
fn clone(&self) -> GstRc<T> {
unsafe { GstRc::from_glib_none(self.as_ptr()) }
}
}
impl<T: MiniObject> Drop for GstRc<T> {
fn drop(&mut self) {
unsafe {
gst_sys::gst_mini_object_unref(self.as_mut_ptr() as *mut gst_sys::GstMiniObject);
}
}
}
unsafe impl<T: MiniObject + Sync + Send> Sync for GstRc<T> {}
unsafe impl<T: MiniObject + Sync + Send> Send for GstRc<T> {}
impl<T: MiniObject + PartialEq> PartialEq for GstRc<T> {
fn eq(&self, other: &Self) -> bool {
self.as_ref().eq(other.as_ref())
}
}
impl<T: MiniObject + Eq> Eq for GstRc<T> {}
impl<T: MiniObject + fmt::Debug> fmt::Debug for GstRc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_ref().fmt(f)
}
}
impl<T: MiniObject + fmt::Display> fmt::Display for GstRc<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_ref().fmt(f)
}
}
pub unsafe trait MiniObject
where
Self: Sized,
{
type GstType;
unsafe fn as_ptr(&self) -> *const Self::GstType {
self as *const Self as *const Self::GstType
}
unsafe fn as_mut_ptr(&self) -> *mut Self::GstType {
self as *const Self as *mut Self::GstType
}
unsafe fn from_ptr<'a>(ptr: *const Self::GstType) -> &'a Self {
assert!(!ptr.is_null());
&*(ptr as *const Self)
}
unsafe fn from_mut_ptr<'a>(ptr: *mut Self::GstType) -> &'a mut Self {
assert!(!ptr.is_null());
assert_ne!(
gst_sys::gst_mini_object_is_writable(ptr as *mut gst_sys::GstMiniObject),
glib_sys::GFALSE
);
&mut *(ptr as *mut Self)
}
fn copy(&self) -> GstRc<Self> {
unsafe {
GstRc::from_glib_full(gst_sys::gst_mini_object_copy(
self.as_ptr() as *const gst_sys::GstMiniObject
) as *const Self::GstType)
}
}
}
impl<'a, T: MiniObject + 'static> ToGlibPtr<'a, *const T::GstType> for GstRc<T> {
type Storage = &'a Self;
fn to_glib_none(&'a self) -> Stash<'a, *const T::GstType, Self> {
Stash(unsafe { self.as_ptr() }, self)
}
fn to_glib_full(&self) -> *const T::GstType {
unsafe {
gst_sys::gst_mini_object_ref(self.as_mut_ptr() as *mut gst_sys::GstMiniObject);
self.as_ptr()
}
}
}
impl<'a, T: MiniObject + 'static> ToGlibPtr<'a, *mut T::GstType> for GstRc<T> {
type Storage = &'a Self;
fn to_glib_none(&'a self) -> Stash<'a, *mut T::GstType, Self> {
Stash(unsafe { self.as_mut_ptr() }, self)
}
fn to_glib_full(&self) -> *mut T::GstType {
unsafe {
gst_sys::gst_mini_object_ref(self.as_mut_ptr() as *mut gst_sys::GstMiniObject);
self.as_mut_ptr()
}
}
}
impl<'a, T: MiniObject + 'static> ToGlibPtrMut<'a, *mut T::GstType> for GstRc<T> {
type Storage = &'a mut Self;
fn to_glib_none_mut(&'a mut self) -> StashMut<*mut T::GstType, Self> {
self.make_mut();
StashMut(unsafe { self.as_mut_ptr() }, self)
}
}
impl<'a, T: MiniObject + 'static> ToGlibContainerFromSlice<'a, *mut *mut T::GstType> for GstRc<T> {
#[allow(clippy::type_complexity)]
type Storage = (
Vec<Stash<'a, *mut T::GstType, GstRc<T>>>,
Option<Vec<*mut T::GstType>>,
);
fn to_glib_none_from_slice(t: &'a [GstRc<T>]) -> (*mut *mut T::GstType, Self::Storage) {
skip_assert_initialized!();
let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
let mut v_ptr: Vec<_> = v.iter().map(|s| s.0).collect();
v_ptr.push(ptr::null_mut() as *mut T::GstType);
(v_ptr.as_ptr() as *mut *mut T::GstType, (v, Some(v_ptr)))
}
fn to_glib_container_from_slice(t: &'a [GstRc<T>]) -> (*mut *mut T::GstType, Self::Storage) {
skip_assert_initialized!();
let v: Vec<_> = t.iter().map(|s| s.to_glib_none()).collect();
let v_ptr = unsafe {
let v_ptr = glib_sys::g_malloc0(mem::size_of::<*mut T::GstType>() * t.len() + 1)
as *mut *mut T::GstType;
for (i, s) in v.iter().enumerate() {
ptr::write(v_ptr.add(i), s.0);
}
v_ptr
};
(v_ptr, (v, None))
}
fn to_glib_full_from_slice(t: &[GstRc<T>]) -> *mut *mut T::GstType {
skip_assert_initialized!();
unsafe {
let v_ptr = glib_sys::g_malloc0(mem::size_of::<*mut T::GstType>() * t.len() + 1)
as *mut *mut T::GstType;
for (i, s) in t.iter().enumerate() {
ptr::write(v_ptr.add(i), s.to_glib_full());
}
v_ptr
}
}
}
impl<'a, T: MiniObject + 'static> ToGlibContainerFromSlice<'a, *const *mut T::GstType>
for GstRc<T>
{
#[allow(clippy::type_complexity)]
type Storage = (
Vec<Stash<'a, *mut T::GstType, GstRc<T>>>,
Option<Vec<*mut T::GstType>>,
);
fn to_glib_none_from_slice(t: &'a [GstRc<T>]) -> (*const *mut T::GstType, Self::Storage) {
skip_assert_initialized!();
let (ptr, stash) =
ToGlibContainerFromSlice::<'a, *mut *mut T::GstType>::to_glib_none_from_slice(t);
(ptr as *const *mut T::GstType, stash)
}
fn to_glib_container_from_slice(_: &'a [GstRc<T>]) -> (*const *mut T::GstType, Self::Storage) {
skip_assert_initialized!();
// Can't have consumer free a *const pointer
unimplemented!()
}
fn to_glib_full_from_slice(_: &[GstRc<T>]) -> *const *mut T::GstType {
skip_assert_initialized!();
// Can't have consumer free a *const pointer
unimplemented!()
}
}
impl<T: MiniObject + 'static> FromGlibPtrNone<*const T::GstType> for GstRc<T> {
unsafe fn from_glib_none(ptr: *const T::GstType) -> Self {
Self::from_glib_none(ptr)
}
}
impl<T: MiniObject + 'static> FromGlibPtrNone<*mut T::GstType> for GstRc<T> {
unsafe fn from_glib_none(ptr: *mut T::GstType) -> Self {
Self::from_glib_none(ptr)
}
}
impl<T: MiniObject + 'static> FromGlibPtrFull<*const T::GstType> for GstRc<T> {
unsafe fn from_glib_full(ptr: *const T::GstType) -> Self {
Self::from_glib_full(ptr)
}
}
impl<T: MiniObject + 'static> FromGlibPtrFull<*mut T::GstType> for GstRc<T> {
unsafe fn from_glib_full(ptr: *mut T::GstType) -> Self {
Self::from_glib_full(ptr)
}
}
impl<T: MiniObject + 'static> FromGlibPtrBorrow<*const T::GstType> for GstRc<T> {
unsafe fn from_glib_borrow(ptr: *const T::GstType) -> Borrowed<Self> {
Self::from_glib_borrow(ptr)
}
}
impl<T: MiniObject + 'static> FromGlibPtrBorrow<*mut T::GstType> for GstRc<T> {
unsafe fn from_glib_borrow(ptr: *mut T::GstType) -> Borrowed<Self> {
Self::from_glib_borrow(ptr)
}
}
impl<T: MiniObject + 'static> FromGlibContainerAsVec<*mut T::GstType, *mut *mut T::GstType>
for GstRc<T>
{
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut T::GstType, num: usize) -> Vec<Self> {
if num == 0 || ptr.is_null() {
return Vec::new();
}
let mut res = Vec::with_capacity(num);
for i in 0..num {
res.push(from_glib_none(ptr::read(ptr.add(i))));
}
res
}
unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut T::GstType, num: usize) -> Vec<Self> {
let res = FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
glib_sys::g_free(ptr as *mut _);
res
}
unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut T::GstType, num: usize) -> Vec<Self> {
if num == 0 || ptr.is_null() {
return Vec::new();
}
let mut res = Vec::with_capacity(num);
for i in 0..num {
res.push(from_glib_full(ptr::read(ptr.add(i))));
}
glib_sys::g_free(ptr as *mut _);
res
}
}
impl<T: MiniObject + 'static> FromGlibPtrArrayContainerAsVec<*mut T::GstType, *mut *mut T::GstType>
for GstRc<T>
{
unsafe fn from_glib_none_as_vec(ptr: *mut *mut T::GstType) -> Vec<Self> {
FromGlibContainerAsVec::from_glib_none_num_as_vec(
ptr,
glib::translate::c_ptr_array_len(ptr),
)
}
unsafe fn from_glib_container_as_vec(ptr: *mut *mut T::GstType) -> Vec<Self> {
FromGlibContainerAsVec::from_glib_container_num_as_vec(
ptr,
glib::translate::c_ptr_array_len(ptr),
)
}
unsafe fn from_glib_full_as_vec(ptr: *mut *mut T::GstType) -> Vec<Self> {
FromGlibContainerAsVec::from_glib_full_num_as_vec(
ptr,
glib::translate::c_ptr_array_len(ptr),
)
}
}
impl<T: MiniObject + 'static> FromGlibContainerAsVec<*mut T::GstType, *const *mut T::GstType>
for GstRc<T>
{
unsafe fn from_glib_none_num_as_vec(ptr: *const *mut T::GstType, num: usize) -> Vec<Self> {
FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr as *mut *mut _, num)
}
unsafe fn from_glib_container_num_as_vec(_: *const *mut T::GstType, _: usize) -> Vec<Self> {
// Can't free a *const
unimplemented!()
}
unsafe fn from_glib_full_num_as_vec(_: *const *mut T::GstType, _: usize) -> Vec<Self> {
// Can't free a *const
unimplemented!()
}
}
impl<T: MiniObject + 'static>
FromGlibPtrArrayContainerAsVec<*mut T::GstType, *const *mut T::GstType> for GstRc<T>
{
unsafe fn from_glib_none_as_vec(ptr: *const *mut T::GstType) -> Vec<Self> {
FromGlibPtrArrayContainerAsVec::from_glib_none_as_vec(ptr as *mut *mut _)
}
unsafe fn from_glib_container_as_vec(_: *const *mut T::GstType) -> Vec<Self> {
// Can't free a *const
unimplemented!()
}
unsafe fn from_glib_full_as_vec(_: *const *mut T::GstType) -> Vec<Self> {
// Can't free a *const
unimplemented!()
}
}
impl<T: MiniObject + glib::StaticType> glib::StaticType for GstRc<T> {
fn static_type() -> glib::types::Type {
T::static_type()
}
}
impl<'a, T: MiniObject + glib::StaticType + 'static> glib::value::FromValueOptional<'a>
for GstRc<T>
{
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
let ptr = gobject_sys::g_value_get_boxed(v.to_glib_none().0);
from_glib_none(ptr as *const T::GstType)
}
}
impl<T: MiniObject + glib::StaticType> glib::value::SetValue for GstRc<T> {
unsafe fn set_value(v: &mut glib::Value, s: &Self) {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
}
}
impl<T: MiniObject + glib::StaticType> glib::value::SetValueOptional for GstRc<T> {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
if let Some(s) = s {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} else {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut());
}
}
}
impl<T: MiniObject + 'static> GlibPtrDefault for GstRc<T> {
type GlibType = *mut T::GstType;
}
#[macro_export]
macro_rules! gst_define_mini_object_wrapper(
($name:ident, $ref_name:ident, $gst_sys_name:path, [$($derives:ident,)*], $get_type:expr) => {
#[derive($($derives,)*)]
#[derive(Clone)]
pub struct $name($crate::GstRc<$ref_name>);
($name:ident, $ref_name:ident, $gst_sys_name:path, $get_type:expr) => {
pub struct $name {
obj: ::std::ptr::NonNull<$ref_name>,
phantom: ::std::marker::PhantomData<$ref_name>,
}
#[repr(C)]
pub struct $ref_name($gst_sys_name);
impl $name {
pub unsafe fn from_glib_none(ptr: *const $gst_sys_name) -> Self {
$name($crate::glib::translate::from_glib_none(ptr))
skip_assert_initialized!();
assert!(!ptr.is_null());
$crate::gst_sys::gst_mini_object_ref(ptr as *mut $crate::gst_sys::GstMiniObject);
$name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
phantom: ::std::marker::PhantomData,
}
}
pub unsafe fn from_glib_full(ptr: *const $gst_sys_name) -> Self {
$name($crate::glib::translate::from_glib_full(ptr))
skip_assert_initialized!();
assert!(!ptr.is_null());
$name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
phantom: ::std::marker::PhantomData,
}
}
pub unsafe fn from_glib_borrow(ptr: *const $gst_sys_name) -> $crate::glib::translate::Borrowed<Self> {
$crate::glib::translate::Borrowed::new(
$name(
$crate::glib::translate::from_glib_borrow::<_, $crate::GstRc::<$ref_name>>(ptr)
.into_inner()
)
)
skip_assert_initialized!();
assert!(!ptr.is_null());
$crate::glib::translate::Borrowed::new($name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
phantom: ::std::marker::PhantomData,
})
}
pub unsafe fn replace_ptr(&mut self, ptr: *mut $gst_sys_name) {
assert!(!ptr.is_null());
self.obj = ::std::ptr::NonNull::new_unchecked(ptr as *mut $ref_name);
}
pub fn make_mut(&mut self) -> &mut $ref_name {
unsafe {
if self.is_writable() {
return self.obj.as_mut();
}
let ptr = $crate::gst_sys::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject
);
self.replace_ptr(ptr as *mut $gst_sys_name);
assert!(self.is_writable());
self.obj.as_mut()
}
}
pub fn get_mut(&mut self) -> Option<&mut $ref_name> {
if self.is_writable() {
Some(unsafe { self.obj.as_mut() })
} else {
None
}
}
pub fn is_writable(&self) -> bool {
unsafe {
$crate::glib::translate::from_glib($crate::gst_sys::gst_mini_object_is_writable(
self.as_ptr() as *const $crate::gst_sys::GstMiniObject
))
}
}
pub unsafe fn into_ptr(self) -> *mut $gst_sys_name {
self.0.into_ptr()
}
pub fn copy(&self) -> Self {
self.0.copy()
let s = ::std::mem::ManuallyDrop::new(self);
s.as_mut_ptr()
}
}
impl $ref_name {
fn copy(&self) -> $name {
$name(<$ref_name as $crate::MiniObject>::copy(self))
impl Clone for $name {
fn clone(&self) -> Self {
unsafe { $name::from_glib_none(self.as_ptr()) }
}
}
impl From<$crate::GstRc<$ref_name>> for $name {
fn from(rc: $crate::GstRc<$ref_name>) -> $name {
skip_assert_initialized!();
$name(rc)
}
}
impl Into<$crate::GstRc<$ref_name>> for $name {
fn into(self) -> $crate::GstRc<$ref_name> {
self.0
impl Drop for $name {
fn drop(&mut self) {
unsafe {
$crate::gst_sys::gst_mini_object_unref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject);
}
}
}
impl ::std::ops::Deref for $name {
type Target = $crate::GstRc<$ref_name>;
type Target = $ref_name;
fn deref(&self) -> &Self::Target {
&self.0
unsafe { &*(self.obj.as_ptr() as *const Self::Target) }
}
}
impl ::std::ops::DerefMut for $name {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
unsafe { &mut *(self.obj.as_ptr() as *mut Self::Target) }
}
}
impl AsRef<$ref_name> for $name {
fn as_ref(&self) -> &$ref_name {
self.0.as_ref()
&*self
}
}
impl AsMut<$ref_name> for $name {
fn as_mut(&mut self) -> &mut $ref_name {
&mut *self
}
}
impl ::std::borrow::Borrow<$ref_name> for $name {
fn borrow(&self) -> &$ref_name {
self.as_ref()
&*self
}
}
@ -583,44 +146,48 @@ macro_rules! gst_define_mini_object_wrapper(
}
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *const $gst_sys_name> for $name {
type Storage = $crate::glib::translate::Stash<'a, *const $gst_sys_name, $crate::GstRc<$ref_name>>;
type Storage = &'a Self;
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *const $gst_sys_name, Self> {
let stash = $crate::glib::translate::ToGlibPtr::to_glib_none(&self.0);
$crate::glib::translate::Stash(stash.0, stash)
$crate::glib::translate::Stash(unsafe { self.as_ptr() }, self)
}
fn to_glib_full(&self) -> *const $gst_sys_name {
$crate::glib::translate::ToGlibPtr::to_glib_full(&self.0)
unsafe {
$crate::gst_sys::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject);
self.as_ptr()
}
}
}
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *mut $gst_sys_name> for $name {
type Storage = $crate::glib::translate::Stash<'a, *mut $gst_sys_name, $crate::GstRc<$ref_name>>;
type Storage = &'a Self;
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *mut $gst_sys_name, Self> {
let stash = $crate::glib::translate::ToGlibPtr::to_glib_none(&self.0);
$crate::glib::translate::Stash(stash.0, stash)
$crate::glib::translate::Stash(unsafe { self.as_mut_ptr() }, self)
}
fn to_glib_full(&self) -> *mut $gst_sys_name {
$crate::glib::translate::ToGlibPtr::to_glib_full(&self.0)
unsafe {
$crate::gst_sys::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject);
self.as_mut_ptr()
}
}
}
impl<'a> $crate::glib::translate::ToGlibPtrMut<'a, *mut $gst_sys_name> for $name {
type Storage = $crate::glib::translate::StashMut<'a, *mut $gst_sys_name, $crate::GstRc<$ref_name>>;
type Storage = &'a mut Self;
fn to_glib_none_mut(&'a mut self) -> $crate::glib::translate::StashMut<*mut $gst_sys_name, Self> {
let stash = $crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(&mut self.0);
$crate::glib::translate::StashMut(stash.0, stash)
self.make_mut();
$crate::glib::translate::StashMut(unsafe { self.as_mut_ptr() }, self)
}
}
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *mut *mut $gst_sys_name> for $name {
#[allow(clippy::type_complexity)]
type Storage = (
Vec<$crate::glib::translate::Stash<'a, *mut $gst_sys_name, $name>>,
Vec<$crate::glib::translate::Stash<'a, *mut $gst_sys_name, Self>>,
Option<Vec<*mut $gst_sys_name>>,
);
@ -658,7 +225,7 @@ macro_rules! gst_define_mini_object_wrapper(
as *mut *mut $gst_sys_name;
for (i, s) in t.iter().enumerate() {
::std::ptr::write(v_ptr.add(i), $crate::glib::translate::ToGlibPtr::to_glib_full(&s));
::std::ptr::write(v_ptr.add(i), $crate::glib::translate::ToGlibPtr::to_glib_full(s));
}
v_ptr
@ -821,19 +388,24 @@ macro_rules! gst_define_mini_object_wrapper(
for $name
{
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
<$crate::GstRc<$ref_name> as $crate::glib::value::FromValueOptional>::from_value_optional(v).map($name)
let ptr = $crate::gobject_sys::g_value_get_boxed($crate::glib::translate::ToGlibPtr::to_glib_none(v).0);
$crate::glib::translate::from_glib_none(ptr as *const $gst_sys_name)
}
}
impl $crate::glib::value::SetValue for $name {
unsafe fn set_value(v: &mut glib::Value, s: &Self) {
<$crate::GstRc<$ref_name> as $crate::glib::value::SetValue>::set_value(v, &s.0)
$crate::gobject_sys::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, s.as_ptr() as $crate::glib_sys::gpointer);
}
}
impl $crate::glib::value::SetValueOptional for $name {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
<$crate::GstRc<$ref_name> as $crate::glib::value::SetValueOptional>::set_value_optional(v, s.map(|s| &s.0))
if let Some(s) = s {
$crate::gobject_sys::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, s.as_ptr() as $crate::glib_sys::gpointer);
} else {
$crate::gobject_sys::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, ::std::ptr::null_mut());
}
}
}
@ -841,8 +413,36 @@ macro_rules! gst_define_mini_object_wrapper(
type GlibType = *mut $gst_sys_name;
}
unsafe impl $crate::MiniObject for $ref_name {
type GstType = $gst_sys_name;
impl $ref_name {
pub unsafe fn as_ptr(&self) -> *const $gst_sys_name {
self as *const Self as *const $gst_sys_name
}
pub unsafe fn as_mut_ptr(&self) -> *mut $gst_sys_name {
self as *const Self as *mut $gst_sys_name
}
pub unsafe fn from_ptr<'a>(ptr: *const $gst_sys_name) -> &'a Self {
assert!(!ptr.is_null());
&*(ptr as *const Self)
}
pub unsafe fn from_mut_ptr<'a>(ptr: *mut $gst_sys_name) -> &'a mut Self {
assert!(!ptr.is_null());
assert_ne!(
$crate::gst_sys::gst_mini_object_is_writable(ptr as *mut $crate::gst_sys::GstMiniObject),
$crate::glib_sys::GFALSE
);
&mut *(ptr as *mut Self)
}
pub fn copy(&self) -> $name {
unsafe {
$name::from_glib_full($crate::gst_sys::gst_mini_object_copy(
self.as_ptr() as *const $crate::gst_sys::GstMiniObject
) as *const $gst_sys_name)
}
}
}
impl $crate::glib::types::StaticType for $ref_name {
@ -851,6 +451,10 @@ macro_rules! gst_define_mini_object_wrapper(
}
}
impl $crate::glib::translate::GlibPtrDefault for $ref_name {
type GlibType = *mut $gst_sys_name;
}
impl<'a> $crate::glib::value::FromValueOptional<'a>
for &'a $ref_name
{
@ -877,5 +481,7 @@ macro_rules! gst_define_mini_object_wrapper(
unsafe impl Sync for $ref_name {}
unsafe impl Send for $ref_name {}
unsafe impl Sync for $name {}
unsafe impl Send for $name {}
}
);

View file

@ -6,7 +6,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use miniobject::MiniObject;
use Buffer;
use BufferList;
use Event;

View file

@ -7,7 +7,6 @@
// except according to those terms.
use gst_sys;
use miniobject::*;
use structure::*;
use GenericFormattedValue;
@ -21,7 +20,7 @@ use glib;
use glib::translate::*;
use glib_sys;
gst_define_mini_object_wrapper!(Query, QueryRef, gst_sys::GstQuery, [Debug,], || {
gst_define_mini_object_wrapper!(Query, QueryRef, gst_sys::GstQuery, || {
gst_sys::gst_query_get_type()
});
@ -243,6 +242,12 @@ impl QueryRef {
}
}
impl fmt::Debug for Query {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
QueryRef::fmt(self, f)
}
}
impl fmt::Debug for QueryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Query")
@ -266,31 +271,31 @@ pub unsafe trait AsMutPtr: AsPtr {
unsafe impl AsPtr for Query {
unsafe fn as_ptr(&self) -> *mut gst_sys::GstQuery {
self.as_ref().as_ptr() as *mut gst_sys::GstQuery
QueryRef::as_ptr(self) as *mut gst_sys::GstQuery
}
}
unsafe impl AsMutPtr for Query {
unsafe fn as_mut_ptr(&self) -> *mut gst_sys::GstQuery {
self.as_ref().as_mut_ptr()
QueryRef::as_ptr(self) as *mut gst_sys::GstQuery
}
}
unsafe impl<'a> AsPtr for &'a QueryRef {
unsafe fn as_ptr(&self) -> *mut gst_sys::GstQuery {
MiniObject::as_ptr(self as &QueryRef) as *mut gst_sys::GstQuery
QueryRef::as_ptr(self) as *mut gst_sys::GstQuery
}
}
unsafe impl<'a> AsPtr for &'a mut QueryRef {
unsafe fn as_ptr(&self) -> *mut gst_sys::GstQuery {
MiniObject::as_ptr(self as &QueryRef) as *mut gst_sys::GstQuery
QueryRef::as_ptr(self) as *mut gst_sys::GstQuery
}
}
unsafe impl<'a> AsMutPtr for &'a mut QueryRef {
unsafe fn as_mut_ptr(&self) -> *mut gst_sys::GstQuery {
MiniObject::as_mut_ptr(self as &QueryRef) as *mut gst_sys::GstQuery
QueryRef::as_ptr(self) as *mut gst_sys::GstQuery
}
}

View file

@ -14,7 +14,6 @@ use gst_sys;
use glib;
use glib::translate::{from_glib_full, from_glib_none, mut_override, ToGlibPtr};
use miniobject::*;
use Buffer;
use BufferList;
use BufferListRef;
@ -27,7 +26,7 @@ use Segment;
use Structure;
use StructureRef;
gst_define_mini_object_wrapper!(Sample, SampleRef, gst_sys::GstSample, [Debug,], || {
gst_define_mini_object_wrapper!(Sample, SampleRef, gst_sys::GstSample, || {
gst_sys::gst_sample_get_type()
});
@ -215,6 +214,12 @@ impl SampleRef {
}
}
impl fmt::Debug for Sample {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
SampleRef::fmt(self, f)
}
}
impl fmt::Debug for SampleRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Sample")

View file

@ -22,8 +22,6 @@ use glib::StaticType;
use gobject_sys;
use gst_sys;
use miniobject::*;
use Sample;
use TagError;
use TagMergeMode;
@ -341,13 +339,9 @@ impl_tag!(
);
impl_tag!(PrivateData, Sample, TAG_PRIVATE_DATA, GST_TAG_PRIVATE_DATA);
gst_define_mini_object_wrapper!(
TagList,
TagListRef,
gst_sys::GstTagList,
[Debug, PartialEq, Eq,],
|| gst_sys::gst_tag_list_get_type()
);
gst_define_mini_object_wrapper!(TagList, TagListRef, gst_sys::GstTagList, || {
gst_sys::gst_tag_list_get_type()
});
impl TagList {
pub fn new() -> Self {
@ -362,12 +356,6 @@ impl Default for TagList {
}
}
impl fmt::Display for TagList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
impl TagListRef {
pub fn add<'a, T: Tag<'a>>(&mut self, value: &T::TagType, mode: TagMergeMode)
where
@ -513,6 +501,26 @@ impl TagListRef {
}
}
impl fmt::Debug for TagList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<TagListRef as fmt::Debug>::fmt(self, f)
}
}
impl fmt::Display for TagList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
<TagListRef as fmt::Display>::fmt(self, f)
}
}
impl PartialEq for TagList {
fn eq(&self, other: &TagList) -> bool {
TagListRef::eq(self, other)
}
}
impl Eq for TagList {}
impl fmt::Debug for TagListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("TagList").field(&self.to_string()).finish()

View file

@ -17,14 +17,13 @@ use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlibPtrContainer, ToGlib, ToGlibPtr,
};
use miniobject::*;
use TagList;
use TagMergeMode;
use TocEntryType;
use TocLoopType;
use TocScope;
gst_define_mini_object_wrapper!(Toc, TocRef, gst_sys::GstToc, [Debug,], || {
gst_define_mini_object_wrapper!(Toc, TocRef, gst_sys::GstToc, || {
gst_sys::gst_toc_get_type()
});
@ -82,6 +81,12 @@ impl TocRef {
}
}
impl fmt::Debug for Toc {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
TocRef::fmt(self, f)
}
}
impl fmt::Debug for TocRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Toc")
@ -92,13 +97,9 @@ impl fmt::Debug for TocRef {
}
}
gst_define_mini_object_wrapper!(
TocEntry,
TocEntryRef,
gst_sys::GstTocEntry,
[Debug,],
|| gst_sys::gst_toc_entry_get_type()
);
gst_define_mini_object_wrapper!(TocEntry, TocEntryRef, gst_sys::GstTocEntry, || {
gst_sys::gst_toc_entry_get_type()
});
impl TocEntry {
pub fn new(type_: TocEntryType, uid: &str) -> Self {
@ -220,6 +221,12 @@ impl TocEntryRef {
}
}
impl fmt::Debug for TocEntry {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
TocEntryRef::fmt(self, f)
}
}
impl fmt::Debug for TocEntryRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("TocEntry")