gstreamer: Update manual code to 2018 edition

This commit is contained in:
Sebastian Dröge 2020-11-21 15:46:48 +02:00
parent b933931d6c
commit 9d9522016b
92 changed files with 3513 additions and 3773 deletions

View file

@ -11,14 +11,13 @@ homepage = "https://gstreamer.freedesktop.org"
documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer/" documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer/"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"] keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs" build = "build.rs"
edition = "2018"
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
cfg-if = "1.0" cfg-if = "1.0"
libc = "0.2" libc = "0.2"
glib-sys = { git = "https://github.com/gtk-rs/gtk-rs" } ffi = { package = "gstreamer-sys", path = "../gstreamer/sys", features = ["v1_8"] }
gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer-sys = { path = "../gstreamer/sys", features = ["v1_8"] }
glib = { git = "https://github.com/gtk-rs/gtk-rs" } glib = { git = "https://github.com/gtk-rs/gtk-rs" }
num-rational = { version = "0.3", default-features = false, features = [] } num-rational = { version = "0.3", default-features = false, features = [] }
once_cell = "1.0" once_cell = "1.0"
@ -43,14 +42,14 @@ futures-executor = "0.3.1"
[features] [features]
default = [] default = []
v1_10 = ["gstreamer-sys/v1_10"] v1_10 = ["ffi/v1_10"]
v1_12 = ["gstreamer-sys/v1_12", "v1_10"] v1_12 = ["ffi/v1_12", "v1_10"]
v1_14 = ["gstreamer-sys/v1_14", "v1_12"] v1_14 = ["ffi/v1_14", "v1_12"]
v1_16 = ["gstreamer-sys/v1_16", "v1_14"] v1_16 = ["ffi/v1_16", "v1_14"]
v1_18 = ["gstreamer-sys/v1_18", "v1_16"] v1_18 = ["ffi/v1_18", "v1_16"]
embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"] embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"] purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
dox = ["v1_18", "gstreamer-sys/dox", "glib/dox", "ser_de"] dox = ["v1_18", "ffi/dox", "glib/dox", "ser_de"]
ser_de = ["num-rational/serde", "serde", "serde_bytes", "serde_derive"] ser_de = ["num-rational/serde", "serde", "serde_bytes", "serde_derive"]
[package.metadata.docs.rs] [package.metadata.docs.rs]

View file

@ -171,7 +171,7 @@ final_type = true
name = "Gst.BufferFlags" name = "Gst.BufferFlags"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.member]] [[object.member]]
@ -225,7 +225,7 @@ status = "generate"
name = "Gst.Format" name = "Gst.Format"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.derive]] [[object.derive]]
name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash" name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash"
@ -247,7 +247,7 @@ status = "generate"
name = "Gst.SegmentFlags" name = "Gst.SegmentFlags"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.member]] [[object.member]]
name = "trickmode_forward_predicted" name = "trickmode_forward_predicted"
@ -282,7 +282,7 @@ manual_traits = ["TagSetterExtManual"]
name = "Gst.TocScope" name = "Gst.TocScope"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.derive]] [[object.derive]]
name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash" name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash"
@ -291,7 +291,7 @@ status = "generate"
name = "Gst.TocEntryType" name = "Gst.TocEntryType"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.derive]] [[object.derive]]
name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash" name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash"
@ -300,7 +300,7 @@ status = "generate"
name = "Gst.TocLoopType" name = "Gst.TocLoopType"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.derive]] [[object.derive]]
name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash" name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash"
@ -411,7 +411,7 @@ ref_mode = "ref"
name = "Gst.TagScope" name = "Gst.TagScope"
status = "generate" status = "generate"
[[object.derive]] [[object.derive]]
name = "Serialize, Deserialize" name = "serde::Serialize, serde::Deserialize"
cfg_condition = "feature = \"ser_de\"" cfg_condition = "feature = \"ser_de\""
[[object.derive]] [[object.derive]]
name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash" name = "Debug, PartialEq, Eq, PartialOrd, Ord, Hash"

View file

@ -10,10 +10,10 @@ use std::mem;
use glib::translate::*; use glib::translate::*;
use MemoryFlags; use crate::MemoryFlags;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AllocationParams(gst_sys::GstAllocationParams); pub struct AllocationParams(ffi::GstAllocationParams);
unsafe impl Send for AllocationParams {} unsafe impl Send for AllocationParams {}
unsafe impl Sync for AllocationParams {} unsafe impl Sync for AllocationParams {}
@ -38,7 +38,7 @@ impl AllocationParams {
pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self { pub fn new(flags: MemoryFlags, align: usize, prefix: usize, padding: usize) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let allocationparams = unsafe { let allocationparams = unsafe {
let mut allocationparams: gst_sys::GstAllocationParams = mem::zeroed(); let mut allocationparams: ffi::GstAllocationParams = mem::zeroed();
allocationparams.flags = flags.to_glib(); allocationparams.flags = flags.to_glib();
allocationparams.align = align; allocationparams.align = align;
@ -51,13 +51,13 @@ impl AllocationParams {
AllocationParams(allocationparams) AllocationParams(allocationparams)
} }
pub fn as_ptr(&self) -> *const gst_sys::GstAllocationParams { pub fn as_ptr(&self) -> *const ffi::GstAllocationParams {
&self.0 &self.0
} }
} }
impl From<gst_sys::GstAllocationParams> for AllocationParams { impl From<ffi::GstAllocationParams> for AllocationParams {
fn from(params: gst_sys::GstAllocationParams) -> Self { fn from(params: ffi::GstAllocationParams) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
AllocationParams(params) AllocationParams(params)
} }

View file

@ -8,14 +8,12 @@
use std::ptr; use std::ptr;
use gst_sys;
use glib::translate::from_glib_full; use glib::translate::from_glib_full;
use glib::IsA; use glib::IsA;
use AllocationParams; use crate::AllocationParams;
use Allocator; use crate::Allocator;
use Memory; use crate::Memory;
pub trait AllocatorExtManual: 'static { pub trait AllocatorExtManual: 'static {
fn alloc( fn alloc(
@ -32,7 +30,7 @@ impl<O: IsA<Allocator>> AllocatorExtManual for O {
params: Option<&AllocationParams>, params: Option<&AllocationParams>,
) -> Result<Memory, glib::BoolError> { ) -> Result<Memory, glib::BoolError> {
unsafe { unsafe {
let ret = gst_sys::gst_allocator_alloc( let ret = ffi::gst_allocator_alloc(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
size, size,
match params { match params {
@ -41,7 +39,7 @@ impl<O: IsA<Allocator>> AllocatorExtManual for O {
}, },
); );
if ret.is_null() { if ret.is_null() {
Err(glib_bool_error!("Failed to allocate memory")) Err(glib::glib_bool_error!("Failed to allocate memory"))
} else { } else {
Ok(from_glib_full(ret)) Ok(from_glib_full(ret))
} }

View file

@ -6,12 +6,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use Bin; use crate::Bin;
use BinFlags; use crate::BinFlags;
use Element; use crate::Element;
use LoggableError; use crate::LoggableError;
use glib;
use glib::object::Cast; use glib::object::Cast;
use glib::object::IsA; use glib::object::IsA;
use glib::signal::connect_raw; use glib::signal::connect_raw;
@ -19,8 +18,6 @@ use glib::signal::SignalHandlerId;
use glib::translate::*; use glib::translate::*;
use glib::GString; use glib::GString;
use gst_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem::transmute; use std::mem::transmute;
use std::path; use std::path;
@ -36,20 +33,24 @@ pub trait GstBinExtManual: 'static {
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
fn iterate_all_by_element_factory_name(&self, factory_name: &str) -> ::Iterator<Element>; fn iterate_all_by_element_factory_name(&self, factory_name: &str) -> crate::Iterator<Element>;
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element>; fn iterate_all_by_interface(&self, iface: glib::types::Type) -> crate::Iterator<Element>;
fn iterate_elements(&self) -> ::Iterator<Element>; fn iterate_elements(&self) -> crate::Iterator<Element>;
fn iterate_recurse(&self) -> ::Iterator<Element>; fn iterate_recurse(&self) -> crate::Iterator<Element>;
fn iterate_sinks(&self) -> ::Iterator<Element>; fn iterate_sinks(&self) -> crate::Iterator<Element>;
fn iterate_sorted(&self) -> ::Iterator<Element>; fn iterate_sorted(&self) -> crate::Iterator<Element>;
fn iterate_sources(&self) -> ::Iterator<Element>; fn iterate_sources(&self) -> crate::Iterator<Element>;
fn get_children(&self) -> Vec<Element>; fn get_children(&self) -> Vec<Element>;
fn debug_to_dot_data(&self, details: ::DebugGraphDetails) -> GString; fn debug_to_dot_data(&self, details: crate::DebugGraphDetails) -> GString;
fn debug_to_dot_file<Q: AsRef<path::Path>>(&self, details: ::DebugGraphDetails, file_name: Q); fn debug_to_dot_file<Q: AsRef<path::Path>>(
&self,
details: crate::DebugGraphDetails,
file_name: Q,
);
fn debug_to_dot_file_with_ts<Q: AsRef<path::Path>>( fn debug_to_dot_file_with_ts<Q: AsRef<path::Path>>(
&self, &self,
details: ::DebugGraphDetails, details: crate::DebugGraphDetails,
file_name: Q, file_name: Q,
); );
@ -64,11 +65,8 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> { fn add_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
for e in elements { for e in elements {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_bin_add( ffi::gst_bin_add(self.as_ref().to_glib_none().0, e.as_ref().to_glib_none().0),
self.as_ref().to_glib_none().0,
e.as_ref().to_glib_none().0
),
"Failed to add elements" "Failed to add elements"
)?; )?;
} }
@ -80,8 +78,8 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> { fn remove_many<E: IsA<Element>>(&self, elements: &[&E]) -> Result<(), glib::BoolError> {
for e in elements { for e in elements {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_bin_remove( ffi::gst_bin_remove(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
e.as_ref().to_glib_none().0, e.as_ref().to_glib_none().0,
), ),
@ -112,108 +110,96 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
fn iterate_all_by_element_factory_name(&self, factory_name: &str) -> ::Iterator<Element> { fn iterate_all_by_element_factory_name(&self, factory_name: &str) -> crate::Iterator<Element> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_bin_iterate_all_by_element_factory_name( from_glib_full(ffi::gst_bin_iterate_all_by_element_factory_name(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
factory_name.to_glib_none().0, factory_name.to_glib_none().0,
)) ))
} }
} }
fn iterate_all_by_interface(&self, iface: glib::types::Type) -> ::Iterator<Element> { fn iterate_all_by_interface(&self, iface: glib::types::Type) -> crate::Iterator<Element> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_bin_iterate_all_by_interface( from_glib_full(ffi::gst_bin_iterate_all_by_interface(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
iface.to_glib(), iface.to_glib(),
)) ))
} }
} }
fn iterate_elements(&self) -> ::Iterator<Element> { fn iterate_elements(&self) -> crate::Iterator<Element> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_bin_iterate_elements( from_glib_full(ffi::gst_bin_iterate_elements(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
)) ))
} }
} }
fn iterate_recurse(&self) -> ::Iterator<Element> { fn iterate_recurse(&self) -> crate::Iterator<Element> {
unsafe { unsafe { from_glib_full(ffi::gst_bin_iterate_recurse(self.as_ref().to_glib_none().0)) }
from_glib_full(gst_sys::gst_bin_iterate_recurse(
self.as_ref().to_glib_none().0,
))
}
} }
fn iterate_sinks(&self) -> ::Iterator<Element> { fn iterate_sinks(&self) -> crate::Iterator<Element> {
unsafe { unsafe { from_glib_full(ffi::gst_bin_iterate_sinks(self.as_ref().to_glib_none().0)) }
from_glib_full(gst_sys::gst_bin_iterate_sinks(
self.as_ref().to_glib_none().0,
))
}
} }
fn iterate_sorted(&self) -> ::Iterator<Element> { fn iterate_sorted(&self) -> crate::Iterator<Element> {
unsafe { unsafe { from_glib_full(ffi::gst_bin_iterate_sorted(self.as_ref().to_glib_none().0)) }
from_glib_full(gst_sys::gst_bin_iterate_sorted(
self.as_ref().to_glib_none().0,
))
}
} }
fn iterate_sources(&self) -> ::Iterator<Element> { fn iterate_sources(&self) -> crate::Iterator<Element> {
unsafe { unsafe { from_glib_full(ffi::gst_bin_iterate_sources(self.as_ref().to_glib_none().0)) }
from_glib_full(gst_sys::gst_bin_iterate_sources(
self.as_ref().to_glib_none().0,
))
}
} }
fn get_children(&self) -> Vec<Element> { fn get_children(&self) -> Vec<Element> {
unsafe { unsafe {
let bin: &gst_sys::GstBin = &*(self.as_ptr() as *const _); let bin: &ffi::GstBin = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&bin.element.object.lock); let _guard = crate::utils::MutexGuard::lock(&bin.element.object.lock);
FromGlibPtrContainer::from_glib_none(bin.children) FromGlibPtrContainer::from_glib_none(bin.children)
} }
} }
fn debug_to_dot_data(&self, details: ::DebugGraphDetails) -> GString { fn debug_to_dot_data(&self, details: crate::DebugGraphDetails) -> GString {
::debug_bin_to_dot_data(self, details) crate::debug_bin_to_dot_data(self, details)
} }
fn debug_to_dot_file<Q: AsRef<path::Path>>(&self, details: ::DebugGraphDetails, file_name: Q) { fn debug_to_dot_file<Q: AsRef<path::Path>>(
::debug_bin_to_dot_file(self, details, file_name) &self,
details: crate::DebugGraphDetails,
file_name: Q,
) {
crate::debug_bin_to_dot_file(self, details, file_name)
} }
fn debug_to_dot_file_with_ts<Q: AsRef<path::Path>>( fn debug_to_dot_file_with_ts<Q: AsRef<path::Path>>(
&self, &self,
details: ::DebugGraphDetails, details: crate::DebugGraphDetails,
file_name: Q, file_name: Q,
) { ) {
::debug_bin_to_dot_file_with_ts(self, details, file_name) crate::debug_bin_to_dot_file_with_ts(self, details, file_name)
} }
fn set_bin_flags(&self, flags: BinFlags) { fn set_bin_flags(&self, flags: BinFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib(); (*ptr).flags |= flags.to_glib();
} }
} }
fn unset_bin_flags(&self, flags: BinFlags) { fn unset_bin_flags(&self, flags: BinFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib(); (*ptr).flags &= !flags.to_glib();
} }
} }
fn get_bin_flags(&self) -> BinFlags { fn get_bin_flags(&self) -> BinFlags {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags) from_glib((*ptr).flags)
} }
} }
@ -223,9 +209,9 @@ unsafe extern "C" fn do_latency_trampoline<
P, P,
F: Fn(&P) -> Result<(), LoggableError> + Send + Sync + 'static, F: Fn(&P) -> Result<(), LoggableError> + Send + Sync + 'static,
>( >(
this: *mut gst_sys::GstBin, this: *mut ffi::GstBin,
f: glib_sys::gpointer, f: glib::ffi::gpointer,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
P: IsA<Bin>, P: IsA<Bin>,
{ {
@ -243,16 +229,16 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use prelude::*; use crate::prelude::*;
#[test] #[test]
fn test_get_children() { fn test_get_children() {
::init().unwrap(); crate::init().unwrap();
let bin = ::Bin::new(None); let bin = crate::Bin::new(None);
bin.add(&::ElementFactory::make("identity", Some("identity0")).unwrap()) bin.add(&crate::ElementFactory::make("identity", Some("identity0")).unwrap())
.unwrap(); .unwrap();
bin.add(&::ElementFactory::make("identity", Some("identity1")).unwrap()) bin.add(&crate::ElementFactory::make("identity", Some("identity1")).unwrap())
.unwrap(); .unwrap();
let mut child_names = bin let mut child_names = bin

View file

@ -15,35 +15,32 @@ use std::slice;
use std::u64; use std::u64;
use std::usize; use std::usize;
use meta::*; use crate::meta::*;
use BufferCursor; use crate::BufferCursor;
use BufferFlags; use crate::BufferFlags;
use BufferRefCursor; use crate::BufferRefCursor;
use ClockTime; use crate::ClockTime;
use Memory; use crate::Memory;
use MemoryRef; use crate::MemoryRef;
use glib;
use glib::translate::{from_glib, from_glib_full, FromGlib, FromGlibPtrFull, ToGlib}; use glib::translate::{from_glib, from_glib_full, FromGlib, FromGlibPtrFull, ToGlib};
use glib_sys;
use gst_sys;
pub enum Readable {} pub enum Readable {}
pub enum Writable {} pub enum Writable {}
gst_define_mini_object_wrapper!(Buffer, BufferRef, gst_sys::GstBuffer, || { gst_define_mini_object_wrapper!(Buffer, BufferRef, ffi::GstBuffer, || {
gst_sys::gst_buffer_get_type() ffi::gst_buffer_get_type()
}); });
pub struct BufferMap<'a, T> { pub struct BufferMap<'a, T> {
buffer: &'a BufferRef, buffer: &'a BufferRef,
map_info: gst_sys::GstMapInfo, map_info: ffi::GstMapInfo,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
pub struct MappedBuffer<T> { pub struct MappedBuffer<T> {
buffer: Option<Buffer>, buffer: Option<Buffer>,
map_info: gst_sys::GstMapInfo, map_info: ffi::GstMapInfo,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -51,23 +48,23 @@ impl Buffer {
pub fn new() -> Self { pub fn new() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_buffer_new()) } unsafe { from_glib_full(ffi::gst_buffer_new()) }
} }
pub fn with_size(size: usize) -> Result<Self, glib::BoolError> { pub fn with_size(size: usize) -> Result<Self, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
Option::<_>::from_glib_full(gst_sys::gst_buffer_new_allocate( Option::<_>::from_glib_full(ffi::gst_buffer_new_allocate(
ptr::null_mut(), ptr::null_mut(),
size, size,
ptr::null_mut(), ptr::null_mut(),
)) ))
.ok_or_else(|| glib_bool_error!("Failed to allocate buffer")) .ok_or_else(|| glib::glib_bool_error!("Failed to allocate buffer"))
} }
} }
unsafe extern "C" fn drop_box<T>(vec: glib_sys::gpointer) { unsafe extern "C" fn drop_box<T>(vec: glib::ffi::gpointer) {
let slice: Box<T> = Box::from_raw(vec as *mut T); let slice: Box<T> = Box::from_raw(vec as *mut T);
drop(slice); drop(slice);
} }
@ -82,13 +79,13 @@ impl Buffer {
(slice.len(), slice.as_mut_ptr()) (slice.len(), slice.as_mut_ptr())
}; };
let user_data = Box::into_raw(b); let user_data = Box::into_raw(b);
from_glib_full(gst_sys::gst_buffer_new_wrapped_full( from_glib_full(ffi::gst_buffer_new_wrapped_full(
0, 0,
data as glib_sys::gpointer, data as glib::ffi::gpointer,
size, size,
0, 0,
size, size,
user_data as glib_sys::gpointer, user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>), Some(Self::drop_box::<T>),
)) ))
} }
@ -104,13 +101,13 @@ impl Buffer {
(slice.len(), slice.as_ptr()) (slice.len(), slice.as_ptr())
}; };
let user_data = Box::into_raw(b); let user_data = Box::into_raw(b);
from_glib_full(gst_sys::gst_buffer_new_wrapped_full( from_glib_full(ffi::gst_buffer_new_wrapped_full(
gst_sys::GST_MEMORY_FLAG_READONLY, ffi::GST_MEMORY_FLAG_READONLY,
data as glib_sys::gpointer, data as glib::ffi::gpointer,
size, size,
0, 0,
size, size,
user_data as glib_sys::gpointer, user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>), Some(Self::drop_box::<T>),
)) ))
} }
@ -119,10 +116,10 @@ impl Buffer {
pub fn into_mapped_buffer_readable(self) -> Result<MappedBuffer<Readable>, Self> { pub fn into_mapped_buffer_readable(self) -> Result<MappedBuffer<Readable>, Self> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res: bool = from_glib(gst_sys::gst_buffer_map( let res: bool = from_glib(ffi::gst_buffer_map(
self.as_mut_ptr(), self.as_mut_ptr(),
map_info.as_mut_ptr(), map_info.as_mut_ptr(),
gst_sys::GST_MAP_READ, ffi::GST_MAP_READ,
)); ));
if res { if res {
Ok(MappedBuffer { Ok(MappedBuffer {
@ -139,10 +136,10 @@ impl Buffer {
pub fn into_mapped_buffer_writable(self) -> Result<MappedBuffer<Writable>, Self> { pub fn into_mapped_buffer_writable(self) -> Result<MappedBuffer<Writable>, Self> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res: bool = from_glib(gst_sys::gst_buffer_map( let res: bool = from_glib(ffi::gst_buffer_map(
self.as_mut_ptr(), self.as_mut_ptr(),
map_info.as_mut_ptr(), map_info.as_mut_ptr(),
gst_sys::GST_MAP_READWRITE, ffi::GST_MAP_READWRITE,
)); ));
if res { if res {
Ok(MappedBuffer { Ok(MappedBuffer {
@ -167,7 +164,7 @@ impl Buffer {
pub fn append(&mut self, other: Self) { pub fn append(&mut self, other: Self) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_buffer_append(self.as_mut_ptr(), other.into_ptr()); let ptr = ffi::gst_buffer_append(self.as_mut_ptr(), other.into_ptr());
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
} }
@ -183,19 +180,16 @@ impl BufferRef {
pub fn map_readable(&self) -> Result<BufferMap<Readable>, glib::BoolError> { pub fn map_readable(&self) -> Result<BufferMap<Readable>, glib::BoolError> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_buffer_map( let res =
self.as_mut_ptr(), ffi::gst_buffer_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
map_info.as_mut_ptr(), if res == glib::ffi::GTRUE {
gst_sys::GST_MAP_READ,
);
if res == glib_sys::GTRUE {
Ok(BufferMap { Ok(BufferMap {
buffer: self, buffer: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } else {
Err(glib_bool_error!("Failed to map buffer readable")) Err(glib::glib_bool_error!("Failed to map buffer readable"))
} }
} }
} }
@ -203,52 +197,52 @@ impl BufferRef {
pub fn map_writable(&mut self) -> Result<BufferMap<Writable>, glib::BoolError> { pub fn map_writable(&mut self) -> Result<BufferMap<Writable>, glib::BoolError> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_buffer_map( let res = ffi::gst_buffer_map(
self.as_mut_ptr(), self.as_mut_ptr(),
map_info.as_mut_ptr(), map_info.as_mut_ptr(),
gst_sys::GST_MAP_READWRITE, ffi::GST_MAP_READWRITE,
); );
if res == glib_sys::GTRUE { if res == glib::ffi::GTRUE {
Ok(BufferMap { Ok(BufferMap {
buffer: self, buffer: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } else {
Err(glib_bool_error!("Failed to map buffer writable")) Err(glib::glib_bool_error!("Failed to map buffer writable"))
} }
} }
} }
pub fn copy_region( pub fn copy_region(
&self, &self,
flags: ::BufferCopyFlags, flags: crate::BufferCopyFlags,
offset: usize, offset: usize,
size: Option<usize>, size: Option<usize>,
) -> Result<Buffer, glib::BoolError> { ) -> Result<Buffer, glib::BoolError> {
let size_real = size.unwrap_or(usize::MAX); let size_real = size.unwrap_or(usize::MAX);
unsafe { unsafe {
Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_region( Option::<_>::from_glib_full(ffi::gst_buffer_copy_region(
self.as_mut_ptr(), self.as_mut_ptr(),
flags.to_glib(), flags.to_glib(),
offset, offset,
size_real, size_real,
)) ))
.ok_or_else(|| glib_bool_error!("Failed to copy region of buffer")) .ok_or_else(|| glib::glib_bool_error!("Failed to copy region of buffer"))
} }
} }
pub fn copy_into( pub fn copy_into(
&self, &self,
dest: &mut BufferRef, dest: &mut BufferRef,
flags: ::BufferCopyFlags, flags: crate::BufferCopyFlags,
offset: usize, offset: usize,
size: Option<usize>, size: Option<usize>,
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
let size_real = size.unwrap_or(usize::MAX); let size_real = size.unwrap_or(usize::MAX);
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_buffer_copy_into( ffi::gst_buffer_copy_into(
dest.as_mut_ptr(), dest.as_mut_ptr(),
self.as_mut_ptr(), self.as_mut_ptr(),
flags.to_glib(), flags.to_glib(),
@ -268,10 +262,10 @@ impl BufferRef {
let copied = unsafe { let copied = unsafe {
let src = slice.as_ptr(); let src = slice.as_ptr();
gst_sys::gst_buffer_fill( ffi::gst_buffer_fill(
self.as_mut_ptr(), self.as_mut_ptr(),
offset, offset,
src as glib_sys::gconstpointer, src as glib::ffi::gconstpointer,
size, size,
) )
}; };
@ -291,7 +285,7 @@ impl BufferRef {
let copied = unsafe { let copied = unsafe {
let dest = slice.as_mut_ptr(); let dest = slice.as_mut_ptr();
gst_sys::gst_buffer_extract(self.as_mut_ptr(), offset, dest as glib_sys::gpointer, size) ffi::gst_buffer_extract(self.as_mut_ptr(), offset, dest as glib::ffi::gpointer, size)
}; };
if copied == size { if copied == size {
@ -303,19 +297,19 @@ impl BufferRef {
pub fn copy_deep(&self) -> Result<Buffer, glib::BoolError> { pub fn copy_deep(&self) -> Result<Buffer, glib::BoolError> {
unsafe { unsafe {
Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_deep(self.as_ptr())) Option::<_>::from_glib_full(ffi::gst_buffer_copy_deep(self.as_ptr()))
.ok_or_else(|| glib_bool_error!("Failed to deep copy buffer")) .ok_or_else(|| glib::glib_bool_error!("Failed to deep copy buffer"))
} }
} }
pub fn get_size(&self) -> usize { pub fn get_size(&self) -> usize {
unsafe { gst_sys::gst_buffer_get_size(self.as_mut_ptr()) } unsafe { ffi::gst_buffer_get_size(self.as_mut_ptr()) }
} }
pub fn get_maxsize(&self) -> usize { pub fn get_maxsize(&self) -> usize {
unsafe { unsafe {
let mut maxsize = mem::MaybeUninit::uninit(); let mut maxsize = mem::MaybeUninit::uninit();
gst_sys::gst_buffer_get_sizes_range( ffi::gst_buffer_get_sizes_range(
self.as_mut_ptr(), self.as_mut_ptr(),
0, 0,
-1, -1,
@ -331,7 +325,7 @@ impl BufferRef {
assert!(self.get_maxsize() >= size); assert!(self.get_maxsize() >= size);
unsafe { unsafe {
gst_sys::gst_buffer_set_size(self.as_mut_ptr(), size as isize); ffi::gst_buffer_set_size(self.as_mut_ptr(), size as isize);
} }
} }
@ -398,7 +392,7 @@ impl BufferRef {
pub fn get_meta<T: MetaAPI>(&self) -> Option<MetaRef<T>> { pub fn get_meta<T: MetaAPI>(&self) -> Option<MetaRef<T>> {
unsafe { unsafe {
let meta = gst_sys::gst_buffer_get_meta(self.as_mut_ptr(), T::get_meta_api().to_glib()); let meta = ffi::gst_buffer_get_meta(self.as_mut_ptr(), T::get_meta_api().to_glib());
if meta.is_null() { if meta.is_null() {
None None
} else { } else {
@ -407,9 +401,9 @@ impl BufferRef {
} }
} }
pub fn get_meta_mut<T: MetaAPI>(&mut self) -> Option<MetaRefMut<T, ::meta::Standalone>> { pub fn get_meta_mut<T: MetaAPI>(&mut self) -> Option<MetaRefMut<T, crate::meta::Standalone>> {
unsafe { unsafe {
let meta = gst_sys::gst_buffer_get_meta(self.as_mut_ptr(), T::get_meta_api().to_glib()); let meta = ffi::gst_buffer_get_meta(self.as_mut_ptr(), T::get_meta_api().to_glib());
if meta.is_null() { if meta.is_null() {
None None
} else { } else {
@ -428,10 +422,10 @@ impl BufferRef {
pub fn foreach_meta<F: FnMut(MetaRef<Meta>) -> bool>(&self, func: F) -> bool { pub fn foreach_meta<F: FnMut(MetaRef<Meta>) -> bool>(&self, func: F) -> bool {
unsafe extern "C" fn trampoline<F: FnMut(MetaRef<Meta>) -> bool>( unsafe extern "C" fn trampoline<F: FnMut(MetaRef<Meta>) -> bool>(
buffer: *mut gst_sys::GstBuffer, buffer: *mut ffi::GstBuffer,
meta: *mut *mut gst_sys::GstMeta, meta: *mut *mut ffi::GstMeta,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *const _ as usize as *mut F;
let res = (*func)(Meta::from_ptr(BufferRef::from_ptr(buffer), *meta)); let res = (*func)(Meta::from_ptr(BufferRef::from_ptr(buffer), *meta));
@ -441,7 +435,7 @@ impl BufferRef {
unsafe { unsafe {
let func_ptr: &F = &func; let func_ptr: &F = &func;
from_glib(gst_sys::gst_buffer_foreach_meta( from_glib(ffi::gst_buffer_foreach_meta(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as usize as *mut _,
@ -449,17 +443,19 @@ impl BufferRef {
} }
} }
pub fn foreach_meta_mut<F: FnMut(MetaRefMut<Meta, ::meta::Iterated>) -> Result<bool, bool>>( pub fn foreach_meta_mut<
F: FnMut(MetaRefMut<Meta, crate::meta::Iterated>) -> Result<bool, bool>,
>(
&mut self, &mut self,
func: F, func: F,
) -> bool { ) -> bool {
unsafe extern "C" fn trampoline< unsafe extern "C" fn trampoline<
F: FnMut(MetaRefMut<Meta, ::meta::Iterated>) -> Result<bool, bool>, F: FnMut(MetaRefMut<Meta, crate::meta::Iterated>) -> Result<bool, bool>,
>( >(
buffer: *mut gst_sys::GstBuffer, buffer: *mut ffi::GstBuffer,
meta: *mut *mut gst_sys::GstMeta, meta: *mut *mut ffi::GstMeta,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *const _ as usize as *mut F;
let res = (*func)(Meta::from_mut_ptr(BufferRef::from_mut_ptr(buffer), *meta)); let res = (*func)(Meta::from_mut_ptr(BufferRef::from_mut_ptr(buffer), *meta));
@ -475,7 +471,7 @@ impl BufferRef {
unsafe { unsafe {
let func_ptr: &F = &func; let func_ptr: &F = &func;
from_glib(gst_sys::gst_buffer_foreach_meta( from_glib(ffi::gst_buffer_foreach_meta(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as usize as *mut _,
@ -484,7 +480,7 @@ impl BufferRef {
} }
pub fn append_memory(&mut self, mem: Memory) { pub fn append_memory(&mut self, mem: Memory) {
unsafe { gst_sys::gst_buffer_append_memory(self.as_mut_ptr(), mem.into_ptr()) } unsafe { ffi::gst_buffer_append_memory(self.as_mut_ptr(), mem.into_ptr()) }
} }
pub fn find_memory(&self, offset: usize, size: Option<usize>) -> Option<(u32, u32, usize)> { pub fn find_memory(&self, offset: usize, size: Option<usize>) -> Option<(u32, u32, usize)> {
@ -493,7 +489,7 @@ impl BufferRef {
let mut length = mem::MaybeUninit::uninit(); let mut length = mem::MaybeUninit::uninit();
let mut skip = mem::MaybeUninit::uninit(); let mut skip = mem::MaybeUninit::uninit();
let res = from_glib(gst_sys::gst_buffer_find_memory( let res = from_glib(ffi::gst_buffer_find_memory(
self.as_mut_ptr(), self.as_mut_ptr(),
offset, offset,
size.unwrap_or(usize::MAX), size.unwrap_or(usize::MAX),
@ -512,7 +508,7 @@ impl BufferRef {
pub fn get_all_memory(&self) -> Option<Memory> { pub fn get_all_memory(&self) -> Option<Memory> {
unsafe { unsafe {
let res = gst_sys::gst_buffer_get_all_memory(self.as_mut_ptr()); let res = ffi::gst_buffer_get_all_memory(self.as_mut_ptr());
if res.is_null() { if res.is_null() {
None None
} else { } else {
@ -522,7 +518,7 @@ impl BufferRef {
} }
pub fn get_max_memory() -> u32 { pub fn get_max_memory() -> u32 {
unsafe { gst_sys::gst_buffer_get_max_memory() } unsafe { ffi::gst_buffer_get_max_memory() }
} }
pub fn get_memory(&self, idx: u32) -> Option<Memory> { pub fn get_memory(&self, idx: u32) -> Option<Memory> {
@ -530,7 +526,7 @@ impl BufferRef {
None None
} else { } else {
unsafe { unsafe {
let res = gst_sys::gst_buffer_get_memory(self.as_mut_ptr(), idx); let res = ffi::gst_buffer_get_memory(self.as_mut_ptr(), idx);
if res.is_null() { if res.is_null() {
None None
} else { } else {
@ -543,7 +539,7 @@ impl BufferRef {
pub fn get_memory_range(&self, idx: u32, length: Option<u32>) -> Option<Memory> { pub fn get_memory_range(&self, idx: u32, length: Option<u32>) -> Option<Memory> {
assert!(idx + length.unwrap_or(0) < self.n_memory()); assert!(idx + length.unwrap_or(0) < self.n_memory());
unsafe { unsafe {
let res = gst_sys::gst_buffer_get_memory_range( let res = ffi::gst_buffer_get_memory_range(
self.as_mut_ptr(), self.as_mut_ptr(),
idx, idx,
match length { match length {
@ -561,7 +557,7 @@ impl BufferRef {
pub fn insert_memory(&mut self, idx: Option<u32>, mem: Memory) { pub fn insert_memory(&mut self, idx: Option<u32>, mem: Memory) {
unsafe { unsafe {
gst_sys::gst_buffer_insert_memory( ffi::gst_buffer_insert_memory(
self.as_mut_ptr(), self.as_mut_ptr(),
match idx { match idx {
Some(val) => val as i32, Some(val) => val as i32,
@ -573,16 +569,12 @@ impl BufferRef {
} }
pub fn is_all_memory_writable(&self) -> bool { pub fn is_all_memory_writable(&self) -> bool {
unsafe { unsafe { from_glib(ffi::gst_buffer_is_all_memory_writable(self.as_mut_ptr())) }
from_glib(gst_sys::gst_buffer_is_all_memory_writable(
self.as_mut_ptr(),
))
}
} }
pub fn is_memory_range_writable(&self, idx: u32, length: Option<u16>) -> bool { pub fn is_memory_range_writable(&self, idx: u32, length: Option<u16>) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_buffer_is_memory_range_writable( from_glib(ffi::gst_buffer_is_memory_range_writable(
self.as_mut_ptr(), self.as_mut_ptr(),
idx, idx,
match length { match length {
@ -594,22 +586,22 @@ impl BufferRef {
} }
pub fn n_memory(&self) -> u32 { pub fn n_memory(&self) -> u32 {
unsafe { gst_sys::gst_buffer_n_memory(self.as_ptr() as *mut _) } unsafe { ffi::gst_buffer_n_memory(self.as_ptr() as *mut _) }
} }
pub fn peek_memory(&self, idx: u32) -> &MemoryRef { pub fn peek_memory(&self, idx: u32) -> &MemoryRef {
assert!(idx < self.n_memory()); assert!(idx < self.n_memory());
unsafe { MemoryRef::from_ptr(gst_sys::gst_buffer_peek_memory(self.as_mut_ptr(), idx)) } unsafe { MemoryRef::from_ptr(ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx)) }
} }
pub fn peek_memory_mut(&mut self, idx: u32) -> Result<&mut MemoryRef, glib::BoolError> { pub fn peek_memory_mut(&mut self, idx: u32) -> Result<&mut MemoryRef, glib::BoolError> {
assert!(idx < self.n_memory()); assert!(idx < self.n_memory());
unsafe { unsafe {
let mem = gst_sys::gst_buffer_peek_memory(self.as_mut_ptr(), idx); let mem = ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx);
if gst_sys::gst_mini_object_is_writable(mem as *mut _) == glib_sys::GFALSE { if ffi::gst_mini_object_is_writable(mem as *mut _) == glib::ffi::GFALSE {
Err(glib_bool_error!("Memory not writable")) Err(glib::glib_bool_error!("Memory not writable"))
} else { } else {
Ok(MemoryRef::from_mut_ptr(gst_sys::gst_buffer_peek_memory( Ok(MemoryRef::from_mut_ptr(ffi::gst_buffer_peek_memory(
self.as_mut_ptr(), self.as_mut_ptr(),
idx, idx,
))) )))
@ -618,22 +610,22 @@ impl BufferRef {
} }
pub fn prepend_memory(&mut self, mem: Memory) { pub fn prepend_memory(&mut self, mem: Memory) {
unsafe { gst_sys::gst_buffer_prepend_memory(self.as_mut_ptr(), mem.into_ptr()) } unsafe { ffi::gst_buffer_prepend_memory(self.as_mut_ptr(), mem.into_ptr()) }
} }
pub fn remove_all_memory(&mut self) { pub fn remove_all_memory(&mut self) {
unsafe { gst_sys::gst_buffer_remove_all_memory(self.as_mut_ptr()) } unsafe { ffi::gst_buffer_remove_all_memory(self.as_mut_ptr()) }
} }
pub fn remove_memory(&mut self, idx: u32) { pub fn remove_memory(&mut self, idx: u32) {
assert!(idx < self.n_memory()); assert!(idx < self.n_memory());
unsafe { gst_sys::gst_buffer_remove_memory(self.as_mut_ptr(), idx) } unsafe { ffi::gst_buffer_remove_memory(self.as_mut_ptr(), idx) }
} }
pub fn remove_memory_range(&mut self, idx: u32, length: Option<u32>) { pub fn remove_memory_range(&mut self, idx: u32, length: Option<u32>) {
assert!(idx + length.unwrap_or(0) < self.n_memory()); assert!(idx + length.unwrap_or(0) < self.n_memory());
unsafe { unsafe {
gst_sys::gst_buffer_remove_memory_range( ffi::gst_buffer_remove_memory_range(
self.as_mut_ptr(), self.as_mut_ptr(),
idx, idx,
match length { match length {
@ -645,18 +637,18 @@ impl BufferRef {
} }
pub fn replace_all_memory(&mut self, mem: Memory) { pub fn replace_all_memory(&mut self, mem: Memory) {
unsafe { gst_sys::gst_buffer_replace_all_memory(self.as_mut_ptr(), mem.into_ptr()) } unsafe { ffi::gst_buffer_replace_all_memory(self.as_mut_ptr(), mem.into_ptr()) }
} }
pub fn replace_memory(&mut self, idx: u32, mem: Memory) { pub fn replace_memory(&mut self, idx: u32, mem: Memory) {
assert!(idx < self.n_memory()); assert!(idx < self.n_memory());
unsafe { gst_sys::gst_buffer_replace_memory(self.as_mut_ptr(), idx, mem.into_ptr()) } unsafe { ffi::gst_buffer_replace_memory(self.as_mut_ptr(), idx, mem.into_ptr()) }
} }
pub fn replace_memory_range(&mut self, idx: u32, length: Option<u32>, mem: Memory) { pub fn replace_memory_range(&mut self, idx: u32, length: Option<u32>, mem: Memory) {
assert!(idx + length.unwrap_or(0) < self.n_memory()); assert!(idx + length.unwrap_or(0) < self.n_memory());
unsafe { unsafe {
gst_sys::gst_buffer_replace_memory_range( ffi::gst_buffer_replace_memory_range(
self.as_mut_ptr(), self.as_mut_ptr(),
idx, idx,
match length { match length {
@ -674,7 +666,7 @@ impl BufferRef {
pub fn iter_memories_mut(&mut self) -> Result<IterMut, glib::BoolError> { pub fn iter_memories_mut(&mut self) -> Result<IterMut, glib::BoolError> {
if !self.is_all_memory_writable() { if !self.is_all_memory_writable() {
Err(glib_bool_error!("Not all memory are writable")) Err(glib::glib_bool_error!("Not all memory are writable"))
} else { } else {
Ok(IterMut::new(self)) Ok(IterMut::new(self))
} }
@ -699,7 +691,7 @@ macro_rules! define_meta_iter(
($name:ident, $typ:ty, $mtyp:ty, $prepare_buffer:expr, $from_ptr:expr) => { ($name:ident, $typ:ty, $mtyp:ty, $prepare_buffer:expr, $from_ptr:expr) => {
pub struct $name<'a, T: MetaAPI + 'a> { pub struct $name<'a, T: MetaAPI + 'a> {
buffer: $typ, buffer: $typ,
state: glib_sys::gpointer, state: glib::ffi::gpointer,
meta_api: glib::Type, meta_api: glib::Type,
items: PhantomData<$mtyp>, items: PhantomData<$mtyp>,
} }
@ -737,7 +729,7 @@ macro_rules! define_meta_iter(
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
loop { loop {
unsafe { unsafe {
let meta = gst_sys::gst_buffer_iterate_meta(self.buffer.as_mut_ptr(), &mut self.state); let meta = ffi::gst_buffer_iterate_meta(self.buffer.as_mut_ptr(), &mut self.state);
if meta.is_null() { if meta.is_null() {
return None; return None;
@ -758,14 +750,14 @@ define_meta_iter!(
MetaIter, MetaIter,
&'a BufferRef, &'a BufferRef,
MetaRef<'a, T>, MetaRef<'a, T>,
|buffer: *const gst_sys::GstBuffer| BufferRef::from_ptr(buffer), |buffer: *const ffi::GstBuffer| BufferRef::from_ptr(buffer),
|buffer, meta| T::from_ptr(buffer, meta as *const <T as MetaAPI>::GstType) |buffer, meta| T::from_ptr(buffer, meta as *const <T as MetaAPI>::GstType)
); );
define_meta_iter!( define_meta_iter!(
MetaIterMut, MetaIterMut,
&'a mut BufferRef, &'a mut BufferRef,
MetaRefMut<'a, T, ::meta::Iterated>, MetaRefMut<'a, T, crate::meta::Iterated>,
|buffer: *mut gst_sys::GstBuffer| BufferRef::from_mut_ptr(buffer), |buffer: *mut ffi::GstBuffer| BufferRef::from_mut_ptr(buffer),
|buffer: &'a mut BufferRef, meta| T::from_mut_ptr(buffer, meta as *mut <T as MetaAPI>::GstType) |buffer: &'a mut BufferRef, meta| T::from_mut_ptr(buffer, meta as *mut <T as MetaAPI>::GstType)
); );
@ -852,11 +844,11 @@ define_iter!(
&'a BufferRef, &'a BufferRef,
&'a MemoryRef, &'a MemoryRef,
|buffer: &BufferRef, idx| { |buffer: &BufferRef, idx| {
let ptr = gst_sys::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx); let ptr = ffi::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
Some(MemoryRef::from_ptr(ptr as *const gst_sys::GstMemory)) Some(MemoryRef::from_ptr(ptr as *const ffi::GstMemory))
} }
} }
); );
@ -866,11 +858,11 @@ define_iter!(
&'a mut BufferRef, &'a mut BufferRef,
&'a mut MemoryRef, &'a mut MemoryRef,
|buffer: &mut BufferRef, idx| { |buffer: &mut BufferRef, idx| {
let ptr = gst_sys::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx); let ptr = ffi::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
Some(MemoryRef::from_mut_ptr(ptr as *mut gst_sys::GstMemory)) Some(MemoryRef::from_mut_ptr(ptr as *mut ffi::GstMemory))
} }
} }
); );
@ -922,7 +914,7 @@ impl fmt::Debug for BufferRef {
.field( .field(
"metas", "metas",
&DebugIter(RefCell::new( &DebugIter(RefCell::new(
self.iter_meta::<::Meta>().map(|m| m.get_api()), self.iter_meta::<crate::Meta>().map(|m| m.get_api()),
)), )),
) )
.finish() .finish()
@ -1012,7 +1004,7 @@ impl<'a, T> Eq for BufferMap<'a, T> {}
impl<'a, T> Drop for BufferMap<'a, T> { impl<'a, T> Drop for BufferMap<'a, T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
gst_sys::gst_buffer_unmap(self.buffer.as_mut_ptr(), &mut self.map_info); ffi::gst_buffer_unmap(self.buffer.as_mut_ptr(), &mut self.map_info);
} }
} }
} }
@ -1036,7 +1028,7 @@ impl<T> MappedBuffer<T> {
pub fn into_buffer(mut self) -> Buffer { pub fn into_buffer(mut self) -> Buffer {
let buffer = self.buffer.take().unwrap(); let buffer = self.buffer.take().unwrap();
unsafe { unsafe {
gst_sys::gst_buffer_unmap(buffer.as_mut_ptr(), &mut self.map_info); ffi::gst_buffer_unmap(buffer.as_mut_ptr(), &mut self.map_info);
} }
buffer buffer
@ -1079,7 +1071,7 @@ impl<T> Drop for MappedBuffer<T> {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(ref buffer) = self.buffer { if let Some(ref buffer) = self.buffer {
unsafe { unsafe {
gst_sys::gst_buffer_unmap(buffer.as_mut_ptr(), &mut self.map_info); ffi::gst_buffer_unmap(buffer.as_mut_ptr(), &mut self.map_info);
} }
} }
} }
@ -1104,10 +1096,10 @@ impl<T> Eq for MappedBuffer<T> {}
unsafe impl<T> Send for MappedBuffer<T> {} unsafe impl<T> Send for MappedBuffer<T> {}
unsafe impl<T> Sync for MappedBuffer<T> {} unsafe impl<T> Sync for MappedBuffer<T> {}
pub const BUFFER_COPY_METADATA: ::BufferCopyFlags = pub const BUFFER_COPY_METADATA: crate::BufferCopyFlags =
::BufferCopyFlags::from_bits_truncate(gst_sys::GST_BUFFER_COPY_METADATA); crate::BufferCopyFlags::from_bits_truncate(ffi::GST_BUFFER_COPY_METADATA);
pub const BUFFER_COPY_ALL: ::BufferCopyFlags = pub const BUFFER_COPY_ALL: crate::BufferCopyFlags =
::BufferCopyFlags::from_bits_truncate(gst_sys::GST_BUFFER_COPY_ALL); crate::BufferCopyFlags::from_bits_truncate(ffi::GST_BUFFER_COPY_ALL);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -1115,7 +1107,7 @@ mod tests {
#[test] #[test]
fn test_fields() { fn test_fields() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
@ -1136,7 +1128,7 @@ mod tests {
#[test] #[test]
fn test_writability() { fn test_writability() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]); let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{ {
@ -1184,16 +1176,16 @@ mod tests {
#[test] #[test]
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
fn test_memories() { fn test_memories() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 10])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 10]));
} }
assert!(buffer.is_all_memory_writable()); assert!(buffer.is_all_memory_writable());
@ -1295,78 +1287,84 @@ mod tests {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
#[test] #[test]
fn test_meta_foreach() { fn test_meta_foreach() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
::ReferenceTimestampMeta::add( crate::ReferenceTimestampMeta::add(
buffer, buffer,
&::Caps::builder("foo/bar").build(), &crate::Caps::builder("foo/bar").build(),
::ClockTime::from(0), crate::ClockTime::from(0),
::CLOCK_TIME_NONE, crate::CLOCK_TIME_NONE,
); );
::ReferenceTimestampMeta::add( crate::ReferenceTimestampMeta::add(
buffer, buffer,
&::Caps::builder("foo/bar").build(), &crate::Caps::builder("foo/bar").build(),
::SECOND, crate::SECOND,
::CLOCK_TIME_NONE, crate::CLOCK_TIME_NONE,
); );
} }
let mut res = vec![]; let mut res = vec![];
buffer.foreach_meta(|meta| { buffer.foreach_meta(|meta| {
let meta = meta.downcast_ref::<::ReferenceTimestampMeta>().unwrap(); let meta = meta
.downcast_ref::<crate::ReferenceTimestampMeta>()
.unwrap();
res.push(meta.get_timestamp()); res.push(meta.get_timestamp());
true true
}); });
assert_eq!(&[::ClockTime::from(0), ::SECOND][..], &res[..]); assert_eq!(&[crate::ClockTime::from(0), crate::SECOND][..], &res[..]);
} }
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
#[test] #[test]
fn test_meta_foreach_mut() { fn test_meta_foreach_mut() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
::ReferenceTimestampMeta::add( crate::ReferenceTimestampMeta::add(
buffer, buffer,
&::Caps::builder("foo/bar").build(), &crate::Caps::builder("foo/bar").build(),
::ClockTime::from(0), crate::ClockTime::from(0),
::CLOCK_TIME_NONE, crate::CLOCK_TIME_NONE,
); );
::ReferenceTimestampMeta::add( crate::ReferenceTimestampMeta::add(
buffer, buffer,
&::Caps::builder("foo/bar").build(), &crate::Caps::builder("foo/bar").build(),
::SECOND, crate::SECOND,
::CLOCK_TIME_NONE, crate::CLOCK_TIME_NONE,
); );
} }
let mut res = vec![]; let mut res = vec![];
buffer.get_mut().unwrap().foreach_meta_mut(|mut meta| { buffer.get_mut().unwrap().foreach_meta_mut(|mut meta| {
let meta = meta.downcast_ref::<::ReferenceTimestampMeta>().unwrap(); let meta = meta
.downcast_ref::<crate::ReferenceTimestampMeta>()
.unwrap();
res.push(meta.get_timestamp()); res.push(meta.get_timestamp());
if meta.get_timestamp() == ::SECOND { if meta.get_timestamp() == crate::SECOND {
Ok(false) Ok(false)
} else { } else {
Ok(true) Ok(true)
} }
}); });
assert_eq!(&[::ClockTime::from(0), ::SECOND][..], &res[..]); assert_eq!(&[crate::ClockTime::from(0), crate::SECOND][..], &res[..]);
let mut res = vec![]; let mut res = vec![];
buffer.foreach_meta(|meta| { buffer.foreach_meta(|meta| {
let meta = meta.downcast_ref::<::ReferenceTimestampMeta>().unwrap(); let meta = meta
.downcast_ref::<crate::ReferenceTimestampMeta>()
.unwrap();
res.push(meta.get_timestamp()); res.push(meta.get_timestamp());
true true
}); });
assert_eq!(&[::ClockTime::from(0)][..], &res[..]); assert_eq!(&[crate::ClockTime::from(0)][..], &res[..]);
} }
} }

View file

@ -14,14 +14,10 @@ use std::ptr;
use std::u64; use std::u64;
use std::usize; use std::usize;
use Buffer; use crate::Buffer;
use BufferRef; use crate::BufferRef;
use glib; use crate::buffer::{Readable, Writable};
use glib_sys;
use gst_sys;
use buffer::{Readable, Writable};
pub struct BufferCursor<T> { pub struct BufferCursor<T> {
buffer: Option<Buffer>, buffer: Option<Buffer>,
@ -30,7 +26,7 @@ pub struct BufferCursor<T> {
cur_mem_idx: u32, cur_mem_idx: u32,
cur_offset: u64, cur_offset: u64,
cur_mem_offset: usize, cur_mem_offset: usize,
map_info: gst_sys::GstMapInfo, map_info: ffi::GstMapInfo,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -41,7 +37,7 @@ pub struct BufferRefCursor<T> {
cur_mem_idx: u32, cur_mem_idx: u32,
cur_offset: u64, cur_offset: u64,
cur_mem_offset: usize, cur_mem_offset: usize,
map_info: gst_sys::GstMapInfo, map_info: ffi::GstMapInfo,
} }
macro_rules! define_seek_impl( macro_rules! define_seek_impl(
@ -91,7 +87,7 @@ macro_rules! define_seek_impl(
if idx != self.cur_mem_idx && !self.map_info.memory.is_null() { if idx != self.cur_mem_idx && !self.map_info.memory.is_null() {
unsafe { unsafe {
gst_sys::gst_memory_unmap(self.map_info.memory, &mut self.map_info); ffi::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
self.map_info.memory = ptr::null_mut(); self.map_info.memory = ptr::null_mut();
} }
} }
@ -124,14 +120,14 @@ macro_rules! define_read_write_fn_impl(
unsafe { unsafe {
// Work around lifetime annotation issues with closures // Work around lifetime annotation issues with closures
let get_buffer_ref: fn(&Self) -> &BufferRef = $get_buffer_ref; let get_buffer_ref: fn(&Self) -> &BufferRef = $get_buffer_ref;
let memory = gst_sys::gst_buffer_peek_memory( let memory = ffi::gst_buffer_peek_memory(
get_buffer_ref($self).as_mut_ptr(), get_buffer_ref($self).as_mut_ptr(),
$self.cur_mem_idx, $self.cur_mem_idx,
); );
assert!(!memory.is_null()); assert!(!memory.is_null());
if gst_sys::gst_memory_map(memory, &mut $self.map_info, $map_flags) if ffi::gst_memory_map(memory, &mut $self.map_info, $map_flags)
== glib_sys::GFALSE == glib::ffi::GFALSE
{ {
return Err(io::Error::new( return Err(io::Error::new(
io::ErrorKind::InvalidData, io::ErrorKind::InvalidData,
@ -162,7 +158,7 @@ macro_rules! define_read_write_fn_impl(
// If we're at the end of the current memory, unmap and advance to the next memory // If we're at the end of the current memory, unmap and advance to the next memory
if $self.cur_mem_offset == $self.map_info.size { if $self.cur_mem_offset == $self.map_info.size {
unsafe { unsafe {
gst_sys::gst_memory_unmap($self.map_info.memory, &mut $self.map_info); ffi::gst_memory_unmap($self.map_info.memory, &mut $self.map_info);
} }
$self.map_info.memory = ptr::null_mut(); $self.map_info.memory = ptr::null_mut();
$self.cur_mem_idx += 1; $self.cur_mem_idx += 1;
@ -182,8 +178,8 @@ macro_rules! define_read_impl(
data, data,
&mut [u8], &mut [u8],
$get_buffer_ref, $get_buffer_ref,
gst_sys::GST_MAP_READ, ffi::GST_MAP_READ,
|map_info: &gst_sys::GstMapInfo, off, data: &mut [u8], to_copy| unsafe { |map_info: &ffi::GstMapInfo, off, data: &mut [u8], to_copy| unsafe {
ptr::copy_nonoverlapping( ptr::copy_nonoverlapping(
(map_info.data as *const u8).add(off), (map_info.data as *const u8).add(off),
data.as_mut_ptr(), data.as_mut_ptr(),
@ -204,8 +200,8 @@ macro_rules! define_write_impl(
data, data,
&[u8], &[u8],
$get_buffer_ref, $get_buffer_ref,
gst_sys::GST_MAP_WRITE, ffi::GST_MAP_WRITE,
|map_info: &gst_sys::GstMapInfo, off, data: &[u8], to_copy| unsafe { |map_info: &ffi::GstMapInfo, off, data: &[u8], to_copy| unsafe {
ptr::copy_nonoverlapping( ptr::copy_nonoverlapping(
data.as_ptr(), data.as_ptr(),
(map_info.data as *mut u8).add(off), (map_info.data as *mut u8).add(off),
@ -219,7 +215,7 @@ macro_rules! define_write_impl(
fn flush(&mut self) -> Result<(), io::Error> { fn flush(&mut self) -> Result<(), io::Error> {
if !self.map_info.memory.is_null() { if !self.map_info.memory.is_null() {
unsafe { unsafe {
gst_sys::gst_memory_unmap(self.map_info.memory, &mut self.map_info); ffi::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
self.map_info.memory = ptr::null_mut(); self.map_info.memory = ptr::null_mut();
} }
} }
@ -247,7 +243,7 @@ impl<T> Drop for BufferCursor<T> {
fn drop(&mut self) { fn drop(&mut self) {
if !self.map_info.memory.is_null() { if !self.map_info.memory.is_null() {
unsafe { unsafe {
gst_sys::gst_memory_unmap(self.map_info.memory, &mut self.map_info); ffi::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
} }
} }
} }
@ -306,7 +302,7 @@ impl BufferCursor<Writable> {
pub(crate) fn new_writable(buffer: Buffer) -> Result<BufferCursor<Writable>, glib::BoolError> { pub(crate) fn new_writable(buffer: Buffer) -> Result<BufferCursor<Writable>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
if !buffer.is_writable() || !buffer.is_all_memory_writable() { if !buffer.is_writable() || !buffer.is_all_memory_writable() {
return Err(glib_bool_error!("Not all memories are writable")); return Err(glib::glib_bool_error!("Not all memories are writable"));
} }
let size = buffer.get_size() as u64; let size = buffer.get_size() as u64;
@ -346,7 +342,7 @@ impl<T> Drop for BufferRefCursor<T> {
fn drop(&mut self) { fn drop(&mut self) {
if !self.map_info.memory.is_null() { if !self.map_info.memory.is_null() {
unsafe { unsafe {
gst_sys::gst_memory_unmap(self.map_info.memory, &mut self.map_info); ffi::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
} }
} }
} }
@ -410,7 +406,7 @@ impl<'a> BufferRefCursor<&'a mut BufferRef> {
) -> Result<BufferRefCursor<&'a mut BufferRef>, glib::BoolError> { ) -> Result<BufferRefCursor<&'a mut BufferRef>, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
if !buffer.is_all_memory_writable() { if !buffer.is_all_memory_writable() {
return Err(glib_bool_error!("Not all memories are writable")); return Err(glib::glib_bool_error!("Not all memories are writable"));
} }
let size = buffer.get_size() as u64; let size = buffer.get_size() as u64;
@ -440,16 +436,16 @@ mod tests {
fn test_buffer_cursor() { fn test_buffer_cursor() {
use std::io::{self, Read, Seek, Write}; use std::io::{self, Read, Seek, Write};
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 10])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 10]));
} }
assert!(buffer.is_all_memory_writable()); assert!(buffer.is_all_memory_writable());
@ -532,16 +528,16 @@ mod tests {
fn test_buffer_cursor_ref() { fn test_buffer_cursor_ref() {
use std::io::{self, Read, Seek, Write}; use std::io::{self, Read, Seek, Write};
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
{ {
let buffer = buffer.get_mut().unwrap(); let buffer = buffer.get_mut().unwrap();
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 10])); buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 10]));
} }
assert!(buffer.is_all_memory_writable()); assert!(buffer.is_all_memory_writable());

View file

@ -6,17 +6,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use AllocationParams; use crate::AllocationParams;
use Allocator; use crate::Allocator;
use BufferPool; use crate::BufferPool;
use Structure; use crate::Structure;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr, ToGlibPtrMut}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr, ToGlibPtrMut};
use glib::IsA; use glib::IsA;
use gst_sys;
use std::mem; use std::mem;
use std::ops; use std::ops;
use std::ptr; use std::ptr;
@ -25,27 +22,27 @@ use std::ptr;
pub struct BufferPoolConfig(Structure); pub struct BufferPoolConfig(Structure);
impl ops::Deref for BufferPoolConfig { impl ops::Deref for BufferPoolConfig {
type Target = ::StructureRef; type Target = crate::StructureRef;
fn deref(&self) -> &::StructureRef { fn deref(&self) -> &crate::StructureRef {
self.0.deref() self.0.deref()
} }
} }
impl ops::DerefMut for BufferPoolConfig { impl ops::DerefMut for BufferPoolConfig {
fn deref_mut(&mut self) -> &mut ::StructureRef { fn deref_mut(&mut self) -> &mut crate::StructureRef {
self.0.deref_mut() self.0.deref_mut()
} }
} }
impl AsRef<::StructureRef> for BufferPoolConfig { impl AsRef<crate::StructureRef> for BufferPoolConfig {
fn as_ref(&self) -> &::StructureRef { fn as_ref(&self) -> &crate::StructureRef {
self.0.as_ref() self.0.as_ref()
} }
} }
impl AsMut<::StructureRef> for BufferPoolConfig { impl AsMut<crate::StructureRef> for BufferPoolConfig {
fn as_mut(&mut self) -> &mut ::StructureRef { fn as_mut(&mut self) -> &mut crate::StructureRef {
self.0.as_mut() self.0.as_mut()
} }
} }
@ -53,7 +50,7 @@ impl AsMut<::StructureRef> for BufferPoolConfig {
impl BufferPoolConfig { impl BufferPoolConfig {
pub fn add_option(&mut self, option: &str) { pub fn add_option(&mut self, option: &str) {
unsafe { unsafe {
gst_sys::gst_buffer_pool_config_add_option( ffi::gst_buffer_pool_config_add_option(
self.0.to_glib_none_mut().0, self.0.to_glib_none_mut().0,
option.to_glib_none().0, option.to_glib_none().0,
); );
@ -62,7 +59,7 @@ impl BufferPoolConfig {
pub fn has_option(&self, option: &str) -> bool { pub fn has_option(&self, option: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_buffer_pool_config_has_option( from_glib(ffi::gst_buffer_pool_config_has_option(
self.0.to_glib_none().0, self.0.to_glib_none().0,
option.to_glib_none().0, option.to_glib_none().0,
)) ))
@ -71,11 +68,11 @@ impl BufferPoolConfig {
pub fn get_options(&self) -> Vec<String> { pub fn get_options(&self) -> Vec<String> {
unsafe { unsafe {
let n = gst_sys::gst_buffer_pool_config_n_options(self.0.to_glib_none().0) as usize; let n = ffi::gst_buffer_pool_config_n_options(self.0.to_glib_none().0) as usize;
let mut options = Vec::with_capacity(n); let mut options = Vec::with_capacity(n);
for i in 0..n { for i in 0..n {
options.push(from_glib_none(gst_sys::gst_buffer_pool_config_get_option( options.push(from_glib_none(ffi::gst_buffer_pool_config_get_option(
self.0.to_glib_none().0, self.0.to_glib_none().0,
i as u32, i as u32,
))); )));
@ -87,13 +84,13 @@ impl BufferPoolConfig {
pub fn set_params( pub fn set_params(
&mut self, &mut self,
caps: Option<&::Caps>, caps: Option<&crate::Caps>,
size: u32, size: u32,
min_buffers: u32, min_buffers: u32,
max_buffers: u32, max_buffers: u32,
) { ) {
unsafe { unsafe {
gst_sys::gst_buffer_pool_config_set_params( ffi::gst_buffer_pool_config_set_params(
self.0.to_glib_none_mut().0, self.0.to_glib_none_mut().0,
caps.to_glib_none().0, caps.to_glib_none().0,
size, size,
@ -103,14 +100,14 @@ impl BufferPoolConfig {
} }
} }
pub fn get_params(&self) -> Option<(Option<::Caps>, u32, u32, u32)> { pub fn get_params(&self) -> Option<(Option<crate::Caps>, u32, u32, u32)> {
unsafe { unsafe {
let mut caps = ptr::null_mut(); let mut caps = ptr::null_mut();
let mut size = mem::MaybeUninit::uninit(); let mut size = mem::MaybeUninit::uninit();
let mut min_buffers = mem::MaybeUninit::uninit(); let mut min_buffers = mem::MaybeUninit::uninit();
let mut max_buffers = mem::MaybeUninit::uninit(); let mut max_buffers = mem::MaybeUninit::uninit();
let ret: bool = from_glib(gst_sys::gst_buffer_pool_config_get_params( let ret: bool = from_glib(ffi::gst_buffer_pool_config_get_params(
self.0.to_glib_none().0, self.0.to_glib_none().0,
&mut caps, &mut caps,
size.as_mut_ptr(), size.as_mut_ptr(),
@ -132,14 +129,14 @@ impl BufferPoolConfig {
pub fn validate_params( pub fn validate_params(
&self, &self,
caps: Option<&::Caps>, caps: Option<&crate::Caps>,
size: u32, size: u32,
min_buffers: u32, min_buffers: u32,
max_buffers: u32, max_buffers: u32,
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_buffer_pool_config_validate_params( ffi::gst_buffer_pool_config_validate_params(
self.0.to_glib_none().0, self.0.to_glib_none().0,
caps.to_glib_none().0, caps.to_glib_none().0,
size, size,
@ -155,7 +152,7 @@ impl BufferPoolConfig {
unsafe { unsafe {
let mut allocator = ptr::null_mut(); let mut allocator = ptr::null_mut();
let mut params = mem::MaybeUninit::zeroed(); let mut params = mem::MaybeUninit::zeroed();
let ret = from_glib(gst_sys::gst_buffer_pool_config_get_allocator( let ret = from_glib(ffi::gst_buffer_pool_config_get_allocator(
self.0.to_glib_none().0, self.0.to_glib_none().0,
&mut allocator, &mut allocator,
params.as_mut_ptr(), params.as_mut_ptr(),
@ -171,7 +168,7 @@ impl BufferPoolConfig {
pub fn set_allocator(&self, allocator: Option<&Allocator>, params: Option<&AllocationParams>) { pub fn set_allocator(&self, allocator: Option<&Allocator>, params: Option<&AllocationParams>) {
assert!(allocator.is_some() || params.is_some()); assert!(allocator.is_some() || params.is_some());
unsafe { unsafe {
gst_sys::gst_buffer_pool_config_set_allocator( ffi::gst_buffer_pool_config_set_allocator(
self.0.to_glib_none().0, self.0.to_glib_none().0,
allocator.to_glib_none().0, allocator.to_glib_none().0,
match params { match params {
@ -185,16 +182,16 @@ impl BufferPoolConfig {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams); pub struct BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams);
unsafe impl Send for BufferPoolAcquireParams {} unsafe impl Send for BufferPoolAcquireParams {}
unsafe impl Sync for BufferPoolAcquireParams {} unsafe impl Sync for BufferPoolAcquireParams {}
impl BufferPoolAcquireParams { impl BufferPoolAcquireParams {
pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self { pub fn with_flags(flags: crate::BufferPoolAcquireFlags) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams { BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
format: gst_sys::GST_FORMAT_UNDEFINED, format: ffi::GST_FORMAT_UNDEFINED,
start: -1, start: -1,
stop: -1, stop: -1,
flags: flags.to_glib(), flags: flags.to_glib(),
@ -202,14 +199,14 @@ impl BufferPoolAcquireParams {
}) })
} }
pub fn with_start_stop<T: ::SpecificFormattedValue>( pub fn with_start_stop<T: crate::SpecificFormattedValue>(
start: T, start: T,
stop: T, stop: T,
flags: ::BufferPoolAcquireFlags, flags: crate::BufferPoolAcquireFlags,
) -> Self { ) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams { BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
format: start.get_format().to_glib(), format: start.get_format().to_glib(),
start: start.to_raw_value(), start: start.to_raw_value(),
stop: stop.to_raw_value(), stop: stop.to_raw_value(),
@ -219,20 +216,20 @@ impl BufferPoolAcquireParams {
} }
} }
pub fn flags(&self) -> ::BufferPoolAcquireFlags { pub fn flags(&self) -> crate::BufferPoolAcquireFlags {
from_glib(self.0.flags) from_glib(self.0.flags)
} }
pub fn format(&self) -> ::Format { pub fn format(&self) -> crate::Format {
from_glib(self.0.format) from_glib(self.0.format)
} }
pub fn start(&self) -> ::GenericFormattedValue { pub fn start(&self) -> crate::GenericFormattedValue {
::GenericFormattedValue::new(from_glib(self.0.format), self.0.start) crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.start)
} }
pub fn stop(&self) -> ::GenericFormattedValue { pub fn stop(&self) -> crate::GenericFormattedValue {
::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop) crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop)
} }
} }
@ -247,23 +244,23 @@ impl PartialEq for BufferPoolAcquireParams {
impl Eq for BufferPoolAcquireParams {} impl Eq for BufferPoolAcquireParams {}
#[doc(hidden)] #[doc(hidden)]
impl<'a> ToGlibPtr<'a, *const gst_sys::GstBufferPoolAcquireParams> for BufferPoolAcquireParams { impl<'a> ToGlibPtr<'a, *const ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none( fn to_glib_none(
&'a self, &'a self,
) -> glib::translate::Stash<'a, *const gst_sys::GstBufferPoolAcquireParams, Self> { ) -> glib::translate::Stash<'a, *const ffi::GstBufferPoolAcquireParams, Self> {
glib::translate::Stash(&self.0, self) glib::translate::Stash(&self.0, self)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> ToGlibPtrMut<'a, *mut gst_sys::GstBufferPoolAcquireParams> for BufferPoolAcquireParams { impl<'a> ToGlibPtrMut<'a, *mut ffi::GstBufferPoolAcquireParams> for BufferPoolAcquireParams {
type Storage = &'a mut Self; type Storage = &'a mut Self;
fn to_glib_none_mut( fn to_glib_none_mut(
&'a mut self, &'a mut self,
) -> glib::translate::StashMut<'a, *mut gst_sys::GstBufferPoolAcquireParams, Self> { ) -> glib::translate::StashMut<'a, *mut ffi::GstBufferPoolAcquireParams, Self> {
glib::translate::StashMut(&mut self.0, self) glib::translate::StashMut(&mut self.0, self)
} }
} }
@ -271,12 +268,12 @@ impl<'a> ToGlibPtrMut<'a, *mut gst_sys::GstBufferPoolAcquireParams> for BufferPo
impl BufferPool { impl BufferPool {
pub fn new() -> BufferPool { pub fn new() -> BufferPool {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let (major, minor, _, _) = ::version(); let (major, minor, _, _) = crate::version();
if (major, minor) > (1, 12) { if (major, minor) > (1, 12) {
unsafe { from_glib_full(gst_sys::gst_buffer_pool_new()) } unsafe { from_glib_full(ffi::gst_buffer_pool_new()) }
} else { } else {
// Work-around for 1.14 switching from transfer-floating to transfer-full // Work-around for 1.14 switching from transfer-floating to transfer-full
unsafe { from_glib_none(gst_sys::gst_buffer_pool_new()) } unsafe { from_glib_none(ffi::gst_buffer_pool_new()) }
} }
} }
} }
@ -296,22 +293,22 @@ pub trait BufferPoolExtManual: 'static {
fn acquire_buffer( fn acquire_buffer(
&self, &self,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<::Buffer, ::FlowError>; ) -> Result<crate::Buffer, crate::FlowError>;
fn release_buffer(&self, buffer: ::Buffer); fn release_buffer(&self, buffer: crate::Buffer);
} }
impl<O: IsA<BufferPool>> BufferPoolExtManual for O { impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
fn get_config(&self) -> BufferPoolConfig { fn get_config(&self) -> BufferPoolConfig {
unsafe { unsafe {
let ptr = gst_sys::gst_buffer_pool_get_config(self.as_ref().to_glib_none().0); let ptr = ffi::gst_buffer_pool_get_config(self.as_ref().to_glib_none().0);
BufferPoolConfig(from_glib_full(ptr)) BufferPoolConfig(from_glib_full(ptr))
} }
} }
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError> { fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_buffer_pool_set_config( ffi::gst_buffer_pool_set_config(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
config.0.into_ptr() config.0.into_ptr()
), ),
@ -323,7 +320,7 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
fn is_flushing(&self) -> bool { fn is_flushing(&self) -> bool {
unsafe { unsafe {
let stash = self.as_ref().to_glib_none(); let stash = self.as_ref().to_glib_none();
let ptr: *mut gst_sys::GstBufferPool = stash.0; let ptr: *mut ffi::GstBufferPool = stash.0;
from_glib((*ptr).flushing) from_glib((*ptr).flushing)
} }
@ -332,12 +329,12 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
fn acquire_buffer( fn acquire_buffer(
&self, &self,
params: Option<&BufferPoolAcquireParams>, params: Option<&BufferPoolAcquireParams>,
) -> Result<::Buffer, ::FlowError> { ) -> Result<crate::Buffer, crate::FlowError> {
let params_ptr = params.to_glib_none().0 as *mut _; let params_ptr = params.to_glib_none().0 as *mut _;
unsafe { unsafe {
let mut buffer = ptr::null_mut(); let mut buffer = ptr::null_mut();
let ret: ::FlowReturn = from_glib(gst_sys::gst_buffer_pool_acquire_buffer( let ret: crate::FlowReturn = from_glib(ffi::gst_buffer_pool_acquire_buffer(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
&mut buffer, &mut buffer,
params_ptr, params_ptr,
@ -347,12 +344,9 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
} }
} }
fn release_buffer(&self, buffer: ::Buffer) { fn release_buffer(&self, buffer: crate::Buffer) {
unsafe { unsafe {
gst_sys::gst_buffer_pool_release_buffer( ffi::gst_buffer_pool_release_buffer(self.as_ref().to_glib_none().0, buffer.into_ptr());
self.as_ref().to_glib_none().0,
buffer.into_ptr(),
);
} }
} }
} }
@ -360,20 +354,21 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use prelude::*; use crate::prelude::*;
#[test] #[test]
fn test_pool() { fn test_pool() {
::init().unwrap(); crate::init().unwrap();
let pool = ::BufferPool::new(); let pool = crate::BufferPool::new();
let mut config = pool.get_config(); let mut config = pool.get_config();
config.set_params(Some(&::Caps::new_simple("foo/bar", &[])), 1024, 0, 2); config.set_params(Some(&crate::Caps::new_simple("foo/bar", &[])), 1024, 0, 2);
pool.set_config(config).unwrap(); pool.set_config(config).unwrap();
pool.set_active(true).unwrap(); pool.set_active(true).unwrap();
let params = ::BufferPoolAcquireParams::with_flags(::BufferPoolAcquireFlags::DONTWAIT); let params =
crate::BufferPoolAcquireParams::with_flags(crate::BufferPoolAcquireFlags::DONTWAIT);
let _buf1 = pool.acquire_buffer(Some(&params)).unwrap(); let _buf1 = pool.acquire_buffer(Some(&params)).unwrap();
let buf2 = pool.acquire_buffer(Some(&params)).unwrap(); let buf2 = pool.acquire_buffer(Some(&params)).unwrap();

View file

@ -11,10 +11,10 @@ use serde::ser;
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use serde_bytes::{ByteBuf, Bytes}; use serde_bytes::{ByteBuf, Bytes};
use Buffer; use crate::Buffer;
use BufferFlags; use crate::BufferFlags;
use BufferRef; use crate::BufferRef;
use ClockTime; use crate::ClockTime;
// TODO: try `Either<ByteBuf, Bytes>` to merge the base reprensentations for ser and de // TODO: try `Either<ByteBuf, Bytes>` to merge the base reprensentations for ser and de
// while avoiding unneeded copy // while avoiding unneeded copy
@ -44,7 +44,7 @@ impl<'a> Serialize for Buffer {
} }
} }
#[derive(Deserialize)] #[derive(serde::Deserialize)]
struct BufferDe { struct BufferDe {
pts: ClockTime, pts: ClockTime,
dts: ClockTime, dts: ClockTime,
@ -81,15 +81,12 @@ impl<'de> Deserialize<'de> for Buffer {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::Buffer;
extern crate serde_json; use crate::BufferFlags;
use Buffer;
use BufferFlags;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]); let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{ {
@ -143,7 +140,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
let buffer_ron = r#" let buffer_ron = r#"
( (
@ -196,7 +193,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]); let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{ {

View file

@ -6,35 +6,33 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib};
use gst_sys;
use std::fmt; use std::fmt;
use std::ptr; use std::ptr;
use Buffer; use crate::Buffer;
use BufferRef; use crate::BufferRef;
gst_define_mini_object_wrapper!(BufferList, BufferListRef, gst_sys::GstBufferList, || { gst_define_mini_object_wrapper!(BufferList, BufferListRef, ffi::GstBufferList, || {
gst_sys::gst_buffer_list_get_type() ffi::gst_buffer_list_get_type()
}); });
impl BufferList { impl BufferList {
pub fn new() -> Self { pub fn new() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_buffer_list_new()) } unsafe { from_glib_full(ffi::gst_buffer_list_new()) }
} }
pub fn new_sized(size: usize) -> Self { pub fn new_sized(size: usize) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_buffer_list_new_sized(size as u32)) } unsafe { from_glib_full(ffi::gst_buffer_list_new_sized(size as u32)) }
} }
} }
impl BufferListRef { impl BufferListRef {
pub fn insert(&mut self, idx: i32, buffer: Buffer) { pub fn insert(&mut self, idx: i32, buffer: Buffer) {
unsafe { unsafe {
gst_sys::gst_buffer_list_insert(self.as_mut_ptr(), idx, buffer.into_ptr()); ffi::gst_buffer_list_insert(self.as_mut_ptr(), idx, buffer.into_ptr());
} }
} }
@ -43,16 +41,16 @@ impl BufferListRef {
} }
pub fn copy_deep(&self) -> BufferList { pub fn copy_deep(&self) -> BufferList {
unsafe { from_glib_full(gst_sys::gst_buffer_list_copy_deep(self.as_ptr())) } unsafe { from_glib_full(ffi::gst_buffer_list_copy_deep(self.as_ptr())) }
} }
pub fn remove(&mut self, idx: u32, len: u32) { pub fn remove(&mut self, idx: u32, len: u32) {
unsafe { gst_sys::gst_buffer_list_remove(self.as_mut_ptr(), idx, len) } unsafe { ffi::gst_buffer_list_remove(self.as_mut_ptr(), idx, len) }
} }
pub fn get(&self, idx: u32) -> Option<&BufferRef> { pub fn get(&self, idx: u32) -> Option<&BufferRef> {
unsafe { unsafe {
let ptr = gst_sys::gst_buffer_list_get(self.as_mut_ptr(), idx); let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -63,7 +61,7 @@ impl BufferListRef {
pub fn get_owned(&self, idx: u32) -> Option<Buffer> { pub fn get_owned(&self, idx: u32) -> Option<Buffer> {
unsafe { unsafe {
let ptr = gst_sys::gst_buffer_list_get(self.as_mut_ptr(), idx); let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
from_glib_none(ptr) from_glib_none(ptr)
} }
} }
@ -72,7 +70,7 @@ impl BufferListRef {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
pub fn get_writable(&mut self, idx: u32) -> Option<&mut BufferRef> { pub fn get_writable(&mut self, idx: u32) -> Option<&mut BufferRef> {
unsafe { unsafe {
let ptr = gst_sys::gst_buffer_list_get_writable(self.as_mut_ptr(), idx); let ptr = ffi::gst_buffer_list_get_writable(self.as_mut_ptr(), idx);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -82,13 +80,13 @@ impl BufferListRef {
} }
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
unsafe { gst_sys::gst_buffer_list_length(self.as_mut_ptr()) as usize } unsafe { ffi::gst_buffer_list_length(self.as_mut_ptr()) as usize }
} }
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
pub fn calculate_size(&self) -> usize { pub fn calculate_size(&self) -> usize {
unsafe { gst_sys::gst_buffer_list_calculate_size(self.as_mut_ptr()) as usize } unsafe { ffi::gst_buffer_list_calculate_size(self.as_mut_ptr()) as usize }
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
@ -105,10 +103,10 @@ impl BufferListRef {
pub fn foreach<F: FnMut(&BufferRef, u32) -> bool>(&self, func: F) -> bool { pub fn foreach<F: FnMut(&BufferRef, u32) -> bool>(&self, func: F) -> bool {
unsafe extern "C" fn trampoline<F: FnMut(&BufferRef, u32) -> bool>( unsafe extern "C" fn trampoline<F: FnMut(&BufferRef, u32) -> bool>(
buffer: *mut *mut gst_sys::GstBuffer, buffer: *mut *mut ffi::GstBuffer,
idx: u32, idx: u32,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *const _ as usize as *mut F;
let res = (*func)(BufferRef::from_ptr(*buffer), idx); let res = (*func)(BufferRef::from_ptr(*buffer), idx);
@ -118,7 +116,7 @@ impl BufferListRef {
unsafe { unsafe {
let func_ptr: &F = &func; let func_ptr: &F = &func;
from_glib(gst_sys::gst_buffer_list_foreach( from_glib(ffi::gst_buffer_list_foreach(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as usize as *mut _,
@ -133,10 +131,10 @@ impl BufferListRef {
unsafe extern "C" fn trampoline< unsafe extern "C" fn trampoline<
F: FnMut(Buffer, u32) -> Result<Option<Buffer>, Option<Buffer>>, F: FnMut(Buffer, u32) -> Result<Option<Buffer>, Option<Buffer>>,
>( >(
buffer: *mut *mut gst_sys::GstBuffer, buffer: *mut *mut ffi::GstBuffer,
idx: u32, idx: u32,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F; let func = user_data as *const _ as usize as *mut F;
let res = (*func)(Buffer::from_glib_full(*buffer), idx); let res = (*func)(Buffer::from_glib_full(*buffer), idx);
@ -147,11 +145,11 @@ impl BufferListRef {
} }
Ok(Some(b)) => { Ok(Some(b)) => {
*buffer = b.into_ptr(); *buffer = b.into_ptr();
glib_sys::GTRUE glib::ffi::GTRUE
} }
Err(Some(b)) => { Err(Some(b)) => {
*buffer = b.into_ptr(); *buffer = b.into_ptr();
glib_sys::GFALSE glib::ffi::GFALSE
} }
} }
} }
@ -159,7 +157,7 @@ impl BufferListRef {
unsafe { unsafe {
let func_ptr: &F = &func; let func_ptr: &F = &func;
from_glib(gst_sys::gst_buffer_list_foreach( from_glib(ffi::gst_buffer_list_foreach(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
Some(trampoline::<F>), Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _, func_ptr as *const _ as usize as *mut _,
@ -186,7 +184,7 @@ impl fmt::Debug for BufferListRef {
let (pts, dts) = self let (pts, dts) = self
.get(0) .get(0)
.map(|b| (b.get_pts(), b.get_dts())) .map(|b| (b.get_pts(), b.get_dts()))
.unwrap_or((::ClockTime::none(), ::ClockTime::none())); .unwrap_or((crate::ClockTime::none(), crate::ClockTime::none()));
f.debug_struct("BufferList") f.debug_struct("BufferList")
.field("ptr", unsafe { &self.as_ptr() }) .field("ptr", unsafe { &self.as_ptr() })
@ -272,17 +270,17 @@ mod tests {
#[test] #[test]
fn test_foreach() { fn test_foreach() {
::init().unwrap(); crate::init().unwrap();
let mut buffer_list = BufferList::new(); let mut buffer_list = BufferList::new();
{ {
let buffer_list = buffer_list.get_mut().unwrap(); let buffer_list = buffer_list.get_mut().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(::ClockTime::from(0)); buffer.get_mut().unwrap().set_pts(crate::ClockTime::from(0));
buffer_list.add(buffer); buffer_list.add(buffer);
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(::SECOND); buffer.get_mut().unwrap().set_pts(crate::SECOND);
buffer_list.add(buffer); buffer_list.add(buffer);
} }
@ -293,26 +291,26 @@ mod tests {
true true
}); });
assert_eq!(res, &[(::ClockTime::from(0), 0), (::SECOND, 1)]); assert_eq!(res, &[(crate::ClockTime::from(0), 0), (crate::SECOND, 1)]);
} }
#[test] #[test]
fn test_foreach_mut() { fn test_foreach_mut() {
::init().unwrap(); crate::init().unwrap();
let mut buffer_list = BufferList::new(); let mut buffer_list = BufferList::new();
{ {
let buffer_list = buffer_list.get_mut().unwrap(); let buffer_list = buffer_list.get_mut().unwrap();
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(::ClockTime::from(0)); buffer.get_mut().unwrap().set_pts(crate::ClockTime::from(0));
buffer_list.add(buffer); buffer_list.add(buffer);
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(::SECOND); buffer.get_mut().unwrap().set_pts(crate::SECOND);
buffer_list.add(buffer); buffer_list.add(buffer);
let mut buffer = Buffer::new(); let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(2 * ::SECOND); buffer.get_mut().unwrap().set_pts(2 * crate::SECOND);
buffer_list.add(buffer); buffer_list.add(buffer);
} }
@ -320,20 +318,24 @@ mod tests {
buffer_list.get_mut().unwrap().foreach_mut(|buffer, idx| { buffer_list.get_mut().unwrap().foreach_mut(|buffer, idx| {
res.push((buffer.get_pts(), idx)); res.push((buffer.get_pts(), idx));
if buffer.get_pts() == ::ClockTime::from(0) { if buffer.get_pts() == crate::ClockTime::from(0) {
Ok(Some(buffer)) Ok(Some(buffer))
} else if buffer.get_pts() == ::SECOND { } else if buffer.get_pts() == crate::SECOND {
Ok(None) Ok(None)
} else { } else {
let mut new_buffer = Buffer::new(); let mut new_buffer = Buffer::new();
new_buffer.get_mut().unwrap().set_pts(3 * ::SECOND); new_buffer.get_mut().unwrap().set_pts(3 * crate::SECOND);
Ok(Some(new_buffer)) Ok(Some(new_buffer))
} }
}); });
assert_eq!( assert_eq!(
res, res,
&[(::ClockTime::from(0), 0), (::SECOND, 1), (2 * ::SECOND, 1)] &[
(crate::ClockTime::from(0), 0),
(crate::SECOND, 1),
(2 * crate::SECOND, 1)
]
); );
let mut res = vec![]; let mut res = vec![];
@ -343,6 +345,9 @@ mod tests {
true true
}); });
assert_eq!(res, &[(::ClockTime::from(0), 0), (3 * ::SECOND, 1)]); assert_eq!(
res,
&[(crate::ClockTime::from(0), 0), (3 * crate::SECOND, 1)]
);
} }
} }

View file

@ -11,9 +11,9 @@ use serde::ser::{Serialize, SerializeSeq, Serializer};
use std::fmt; use std::fmt;
use Buffer; use crate::Buffer;
use BufferList; use crate::BufferList;
use BufferListRef; use crate::BufferListRef;
impl Serialize for BufferListRef { impl Serialize for BufferListRef {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
@ -67,15 +67,13 @@ impl<'de> Deserialize<'de> for BufferList {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::BufferList;
use BufferList;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
use Buffer; use crate::Buffer;
::init().unwrap(); crate::init().unwrap();
let mut buffer_list = BufferList::new(); let mut buffer_list = BufferList::new();
{ {
@ -140,7 +138,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
let buffer_list_ron = r#" let buffer_list_ron = r#"
[ [
@ -189,9 +187,9 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
use Buffer; use crate::Buffer;
::init().unwrap(); crate::init().unwrap();
let mut buffer_list = BufferList::new(); let mut buffer_list = BufferList::new();
{ {

View file

@ -9,26 +9,23 @@
use futures_channel::mpsc::{self, UnboundedReceiver}; use futures_channel::mpsc::{self, UnboundedReceiver};
use futures_core::Stream; use futures_core::Stream;
use futures_util::{future, StreamExt}; use futures_util::{future, StreamExt};
use glib; use glib::ffi::{gboolean, gpointer};
use glib::prelude::*; use glib::prelude::*;
use glib::source::{Continue, Priority, SourceId}; use glib::source::{Continue, Priority, SourceId};
use glib::translate::*; use glib::translate::*;
use glib_sys;
use glib_sys::{gboolean, gpointer};
use gst_sys;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem::transmute; use std::mem::transmute;
use std::pin::Pin; use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use Bus; use crate::Bus;
use BusSyncReply; use crate::BusSyncReply;
use Message; use crate::Message;
use MessageType; use crate::MessageType;
unsafe extern "C" fn trampoline_watch<F: FnMut(&Bus, &Message) -> Continue + 'static>( unsafe extern "C" fn trampoline_watch<F: FnMut(&Bus, &Message) -> Continue + 'static>(
bus: *mut gst_sys::GstBus, bus: *mut ffi::GstBus,
msg: *mut gst_sys::GstMessage, msg: *mut ffi::GstMessage,
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
let func: &RefCell<F> = &*(func as *const RefCell<F>); let func: &RefCell<F> = &*(func as *const RefCell<F>);
@ -50,15 +47,15 @@ fn into_raw_watch<F: FnMut(&Bus, &Message) -> Continue + 'static>(func: F) -> gp
unsafe extern "C" fn trampoline_sync< unsafe extern "C" fn trampoline_sync<
F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static, F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static,
>( >(
bus: *mut gst_sys::GstBus, bus: *mut ffi::GstBus,
msg: *mut gst_sys::GstMessage, msg: *mut ffi::GstMessage,
func: gpointer, func: gpointer,
) -> gst_sys::GstBusSyncReply { ) -> ffi::GstBusSyncReply {
let f: &F = &*(func as *const F); let f: &F = &*(func as *const F);
let res = f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib(); let res = f(&from_glib_borrow(bus), &Message::from_glib_borrow(msg)).to_glib();
if res == gst_sys::GST_BUS_DROP { if res == ffi::GST_BUS_DROP {
gst_sys::gst_mini_object_unref(msg as *mut _); ffi::gst_mini_object_unref(msg as *mut _);
} }
res res
@ -82,7 +79,7 @@ fn into_raw_sync<F: Fn(&Bus, &Message) -> BusSyncReply + Send + Sync + 'static>(
impl Bus { impl Bus {
pub fn add_signal_watch_full(&self, priority: Priority) { pub fn add_signal_watch_full(&self, priority: Priority) {
unsafe { unsafe {
gst_sys::gst_bus_add_signal_watch_full(self.to_glib_none().0, priority.to_glib()); ffi::gst_bus_add_signal_watch_full(self.to_glib_none().0, priority.to_glib());
} }
} }
@ -92,20 +89,20 @@ impl Bus {
{ {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let source = gst_sys::gst_bus_create_watch(self.to_glib_none().0); let source = ffi::gst_bus_create_watch(self.to_glib_none().0);
glib_sys::g_source_set_callback( glib::ffi::g_source_set_callback(
source, source,
Some(transmute::< Some(transmute::<
_, _,
unsafe extern "C" fn(glib_sys::gpointer) -> i32, unsafe extern "C" fn(glib::ffi::gpointer) -> i32,
>(trampoline_watch::<F> as *const ())), >(trampoline_watch::<F> as *const ())),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );
glib_sys::g_source_set_priority(source, priority.to_glib()); glib::ffi::g_source_set_priority(source, priority.to_glib());
if let Some(name) = name { if let Some(name) = name {
glib_sys::g_source_set_name(source, name.to_glib_none().0); glib::ffi::g_source_set_name(source, name.to_glib_none().0);
} }
from_glib_full(source) from_glib_full(source)
@ -117,16 +114,16 @@ impl Bus {
F: FnMut(&Bus, &Message) -> Continue + Send + 'static, F: FnMut(&Bus, &Message) -> Continue + Send + 'static,
{ {
unsafe { unsafe {
let res = gst_sys::gst_bus_add_watch_full( let res = ffi::gst_bus_add_watch_full(
self.to_glib_none().0, self.to_glib_none().0,
glib_sys::G_PRIORITY_DEFAULT, glib::ffi::G_PRIORITY_DEFAULT,
Some(trampoline_watch::<F>), Some(trampoline_watch::<F>),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );
if res == 0 { if res == 0 {
Err(glib_bool_error!("Bus already has a watch")) Err(glib::glib_bool_error!("Bus already has a watch"))
} else { } else {
Ok(from_glib(res)) Ok(from_glib(res))
} }
@ -140,16 +137,16 @@ impl Bus {
unsafe { unsafe {
assert!(glib::MainContext::ref_thread_default().is_owner()); assert!(glib::MainContext::ref_thread_default().is_owner());
let res = gst_sys::gst_bus_add_watch_full( let res = ffi::gst_bus_add_watch_full(
self.to_glib_none().0, self.to_glib_none().0,
glib_sys::G_PRIORITY_DEFAULT, glib::ffi::G_PRIORITY_DEFAULT,
Some(trampoline_watch::<F>), Some(trampoline_watch::<F>),
into_raw_watch(func), into_raw_watch(func),
Some(destroy_closure_watch::<F>), Some(destroy_closure_watch::<F>),
); );
if res == 0 { if res == 0 {
Err(glib_bool_error!("Bus already has a watch")) Err(glib::glib_bool_error!("Bus already has a watch"))
} else { } else {
Ok(from_glib(res)) Ok(from_glib(res))
} }
@ -169,21 +166,21 @@ impl Bus {
// This is not thread-safe before 1.16.3, see // This is not thread-safe before 1.16.3, see
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416
if ::version() < (1, 16, 3, 0) { if crate::version() < (1, 16, 3, 0) {
if !gobject_sys::g_object_get_qdata(bus as *mut _, SET_ONCE_QUARK.to_glib()) if !glib::gobject_ffi::g_object_get_qdata(bus as *mut _, SET_ONCE_QUARK.to_glib())
.is_null() .is_null()
{ {
panic!("Bus sync handler can only be set once"); panic!("Bus sync handler can only be set once");
} }
gobject_sys::g_object_set_qdata( glib::gobject_ffi::g_object_set_qdata(
bus as *mut _, bus as *mut _,
SET_ONCE_QUARK.to_glib(), SET_ONCE_QUARK.to_glib(),
1 as *mut _, 1 as *mut _,
); );
} }
gst_sys::gst_bus_set_sync_handler( ffi::gst_bus_set_sync_handler(
bus, bus,
Some(trampoline_sync::<F>), Some(trampoline_sync::<F>),
into_raw_sync(func), into_raw_sync(func),
@ -195,14 +192,14 @@ impl Bus {
pub fn unset_sync_handler(&self) { pub fn unset_sync_handler(&self) {
// This is not thread-safe before 1.16.3, see // This is not thread-safe before 1.16.3, see
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/merge_requests/416
if ::version() < (1, 16, 3, 0) { if crate::version() < (1, 16, 3, 0) {
return; return;
} }
unsafe { unsafe {
use std::ptr; use std::ptr;
gst_sys::gst_bus_set_sync_handler(self.to_glib_none().0, None, ptr::null_mut(), None) ffi::gst_bus_set_sync_handler(self.to_glib_none().0, None, ptr::null_mut(), None)
} }
} }
@ -210,7 +207,7 @@ impl Bus {
self.iter_timed(0.into()) self.iter_timed(0.into())
} }
pub fn iter_timed(&self, timeout: ::ClockTime) -> Iter { pub fn iter_timed(&self, timeout: crate::ClockTime) -> Iter {
Iter { bus: self, timeout } Iter { bus: self, timeout }
} }
@ -223,7 +220,7 @@ impl Bus {
pub fn iter_timed_filtered<'a>( pub fn iter_timed_filtered<'a>(
&'a self, &'a self,
timeout: ::ClockTime, timeout: crate::ClockTime,
msg_types: &'a [MessageType], msg_types: &'a [MessageType],
) -> impl Iterator<Item = Message> + 'a { ) -> impl Iterator<Item = Message> + 'a {
self.iter_timed(timeout) self.iter_timed(timeout)
@ -232,7 +229,7 @@ impl Bus {
pub fn timed_pop_filtered( pub fn timed_pop_filtered(
&self, &self,
timeout: ::ClockTime, timeout: crate::ClockTime,
msg_types: &[MessageType], msg_types: &[MessageType],
) -> Option<Message> { ) -> Option<Message> {
loop { loop {
@ -271,7 +268,7 @@ impl Bus {
#[derive(Debug)] #[derive(Debug)]
pub struct Iter<'a> { pub struct Iter<'a> {
bus: &'a Bus, bus: &'a Bus,
timeout: ::ClockTime, timeout: crate::ClockTime,
} }
impl<'a> Iterator for Iter<'a> { impl<'a> Iterator for Iter<'a> {
@ -330,7 +327,7 @@ mod tests {
#[test] #[test]
fn test_sync_handler() { fn test_sync_handler() {
::init().unwrap(); crate::init().unwrap();
let bus = Bus::new(); let bus = Bus::new();
let msgs = Arc::new(Mutex::new(Vec::new())); let msgs = Arc::new(Mutex::new(Vec::new()));
@ -340,31 +337,31 @@ mod tests {
BusSyncReply::Pass BusSyncReply::Pass
}); });
bus.post(&::message::Eos::new()).unwrap(); bus.post(&crate::message::Eos::new()).unwrap();
let msgs = msgs.lock().unwrap(); let msgs = msgs.lock().unwrap();
assert_eq!(msgs.len(), 1); assert_eq!(msgs.len(), 1);
match msgs[0].view() { match msgs[0].view() {
::MessageView::Eos(_) => (), crate::MessageView::Eos(_) => (),
_ => unreachable!(), _ => unreachable!(),
} }
} }
#[test] #[test]
fn test_bus_stream() { fn test_bus_stream() {
::init().unwrap(); crate::init().unwrap();
let bus = Bus::new(); let bus = Bus::new();
let bus_stream = bus.stream(); let bus_stream = bus.stream();
let eos_message = ::message::Eos::new(); let eos_message = crate::message::Eos::new();
bus.post(&eos_message).unwrap(); bus.post(&eos_message).unwrap();
let bus_future = bus_stream.into_future(); let bus_future = bus_stream.into_future();
let (message, _) = futures_executor::block_on(bus_future); let (message, _) = futures_executor::block_on(bus_future);
match message.unwrap().view() { match message.unwrap().view() {
::MessageView::Eos(_) => (), crate::MessageView::Eos(_) => (),
_ => unreachable!(), _ => unreachable!(),
} }
} }

View file

@ -7,9 +7,8 @@
// except according to those terms. // except according to those terms.
#[macro_use] #[macro_use]
cfg_if! { cfg_if::cfg_if! {
if #[cfg(unix)] { if #[cfg(unix)] {
use gst_sys;
use glib::translate::ToGlibPtr; use glib::translate::ToGlibPtr;
use std::mem; use std::mem;
@ -35,7 +34,7 @@ impl UnixBusExtManual for Bus {
#[cfg(unix)] #[cfg(unix)]
unsafe { unsafe {
let mut pollfd = mem::MaybeUninit::zeroed(); let mut pollfd = mem::MaybeUninit::zeroed();
gst_sys::gst_bus_get_pollfd(self.to_glib_none().0, pollfd.as_mut_ptr()); ffi::gst_bus_get_pollfd(self.to_glib_none().0, pollfd.as_mut_ptr());
let pollfd = pollfd.assume_init(); let pollfd = pollfd.assume_init();
pollfd.fd pollfd.fd
} }

View file

@ -7,9 +7,8 @@
// except according to those terms. // except according to those terms.
#[macro_use] #[macro_use]
cfg_if! { cfg_if::cfg_if! {
if #[cfg(windows)] { if #[cfg(windows)] {
use gst_sys;
use glib::translate::ToGlibPtr; use glib::translate::ToGlibPtr;
use std::mem; use std::mem;
@ -35,7 +34,7 @@ impl WindowsBusExtManual for Bus {
#[cfg(windows)] #[cfg(windows)]
unsafe { unsafe {
let mut pollfd = mem::MaybeUninit::zeroed(); let mut pollfd = mem::MaybeUninit::zeroed();
gst_sys::gst_bus_get_pollfd(self.to_glib_none().0, pollfd.as_mut_ptr()); ffi::gst_bus_get_pollfd(self.to_glib_none().0, pollfd.as_mut_ptr());
let pollfd = pollfd.assume_init(); let pollfd = pollfd.assume_init();
pollfd.fd as *mut _ pollfd.fd as *mut _
} }

View file

@ -6,23 +6,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use caps_features::*; use crate::caps_features::*;
use crate::structure::*;
use std::fmt; use std::fmt;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ptr; use std::ptr;
use std::str; use std::str;
use structure::*;
use CapsIntersectMode; use crate::CapsIntersectMode;
use glib;
use glib::translate::{from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr};
use glib::value::ToSendValue; use glib::value::ToSendValue;
use gst_sys;
gst_define_mini_object_wrapper!(Caps, CapsRef, gst_sys::GstCaps, || { gst_define_mini_object_wrapper!(Caps, CapsRef, ffi::GstCaps, || { ffi::gst_caps_get_type() });
gst_sys::gst_caps_get_type()
});
impl Caps { impl Caps {
pub fn builder(name: &str) -> Builder<NoFeature> { pub fn builder(name: &str) -> Builder<NoFeature> {
@ -47,12 +43,12 @@ impl Caps {
pub fn new_empty() -> Self { pub fn new_empty() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_caps_new_empty()) } unsafe { from_glib_full(ffi::gst_caps_new_empty()) }
} }
pub fn new_any() -> Self { pub fn new_any() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_caps_new_any()) } unsafe { from_glib_full(ffi::gst_caps_new_any()) }
} }
pub fn new_simple(name: &str, values: &[(&str, &dyn ToSendValue)]) -> Self { pub fn new_simple(name: &str, values: &[(&str, &dyn ToSendValue)]) -> Self {
@ -101,9 +97,9 @@ impl Caps {
// See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/388 // See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/388
assert!(!self.is_any()); assert!(!self.is_any());
let ptr = if self.is_empty() { let ptr = if self.is_empty() {
gst_sys::gst_caps_new_empty() ffi::gst_caps_new_empty()
} else { } else {
gst_sys::gst_caps_fixate(self.as_mut_ptr()) ffi::gst_caps_fixate(self.as_mut_ptr())
}; };
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
@ -112,7 +108,7 @@ impl Caps {
pub fn merge(&mut self, other: Self) { pub fn merge(&mut self, other: Self) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_merge(self.as_mut_ptr(), other.into_ptr()); let ptr = ffi::gst_caps_merge(self.as_mut_ptr(), other.into_ptr());
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
} }
@ -120,7 +116,7 @@ impl Caps {
pub fn merge_structure(&mut self, structure: Structure) { pub fn merge_structure(&mut self, structure: Structure) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_merge_structure(self.as_mut_ptr(), structure.into_ptr()); let ptr = ffi::gst_caps_merge_structure(self.as_mut_ptr(), structure.into_ptr());
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
} }
@ -128,7 +124,7 @@ impl Caps {
pub fn merge_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) { pub fn merge_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_merge_structure_full( let ptr = ffi::gst_caps_merge_structure_full(
self.as_mut_ptr(), self.as_mut_ptr(),
structure.into_ptr(), structure.into_ptr(),
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()), features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
@ -140,7 +136,7 @@ impl Caps {
pub fn normalize(&mut self) { pub fn normalize(&mut self) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_normalize(self.as_mut_ptr()); let ptr = ffi::gst_caps_normalize(self.as_mut_ptr());
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
} }
@ -148,7 +144,7 @@ impl Caps {
pub fn simplify(&mut self) { pub fn simplify(&mut self) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_simplify(self.as_mut_ptr()); let ptr = ffi::gst_caps_simplify(self.as_mut_ptr());
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
} }
@ -156,7 +152,7 @@ impl Caps {
pub fn truncate(&mut self) { pub fn truncate(&mut self) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_truncate(self.as_mut_ptr()); let ptr = ffi::gst_caps_truncate(self.as_mut_ptr());
self.replace_ptr(ptr); self.replace_ptr(ptr);
} }
} }
@ -168,8 +164,8 @@ impl str::FromStr for Caps {
fn from_str(s: &str) -> Result<Self, glib::BoolError> { fn from_str(s: &str) -> Result<Self, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
Option::<_>::from_glib_full(gst_sys::gst_caps_from_string(s.to_glib_none().0)) Option::<_>::from_glib_full(ffi::gst_caps_from_string(s.to_glib_none().0))
.ok_or_else(|| glib_bool_error!("Failed to parse caps from string")) .ok_or_else(|| glib::glib_bool_error!("Failed to parse caps from string"))
} }
} }
} }
@ -180,7 +176,7 @@ impl CapsRef {
let value = value.to_value(); let value = value.to_value();
unsafe { unsafe {
gst_sys::gst_caps_set_value( ffi::gst_caps_set_value(
self.as_mut_ptr(), self.as_mut_ptr(),
name.to_glib_none().0, name.to_glib_none().0,
value.to_glib_none().0, value.to_glib_none().0,
@ -195,7 +191,7 @@ impl CapsRef {
} }
unsafe { unsafe {
let structure = gst_sys::gst_caps_get_structure(self.as_ptr(), idx); let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx);
if structure.is_null() { if structure.is_null() {
return None; return None;
} }
@ -210,7 +206,7 @@ impl CapsRef {
} }
unsafe { unsafe {
let structure = gst_sys::gst_caps_get_structure(self.as_ptr(), idx); let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx);
if structure.is_null() { if structure.is_null() {
return None; return None;
} }
@ -225,7 +221,7 @@ impl CapsRef {
} }
unsafe { unsafe {
let features = gst_sys::gst_caps_get_features(self.as_ptr(), idx); let features = ffi::gst_caps_get_features(self.as_ptr(), idx);
Some(CapsFeaturesRef::from_glib_borrow(features)) Some(CapsFeaturesRef::from_glib_borrow(features))
} }
} }
@ -236,7 +232,7 @@ impl CapsRef {
} }
unsafe { unsafe {
let features = gst_sys::gst_caps_get_features(self.as_ptr(), idx); let features = ffi::gst_caps_get_features(self.as_ptr(), idx);
Some(CapsFeaturesRef::from_glib_borrow_mut(features)) Some(CapsFeaturesRef::from_glib_borrow_mut(features))
} }
} }
@ -245,7 +241,7 @@ impl CapsRef {
assert!(idx < self.get_size()); assert!(idx < self.get_size());
unsafe { unsafe {
gst_sys::gst_caps_set_features( ffi::gst_caps_set_features(
self.as_mut_ptr(), self.as_mut_ptr(),
idx, idx,
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()), features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
@ -257,7 +253,7 @@ impl CapsRef {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_features_simple(&mut self, features: Option<CapsFeatures>) { pub fn set_features_simple(&mut self, features: Option<CapsFeatures>) {
unsafe { unsafe {
gst_sys::gst_caps_set_features_simple( ffi::gst_caps_set_features_simple(
self.as_mut_ptr(), self.as_mut_ptr(),
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()), features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
) )
@ -265,7 +261,7 @@ impl CapsRef {
} }
pub fn get_size(&self) -> u32 { pub fn get_size(&self) -> u32 {
unsafe { gst_sys::gst_caps_get_size(self.as_ptr()) } unsafe { ffi::gst_caps_get_size(self.as_ptr()) }
} }
pub fn iter(&self) -> Iter { pub fn iter(&self) -> Iter {
@ -285,12 +281,12 @@ impl CapsRef {
} }
pub fn append_structure(&mut self, structure: Structure) { pub fn append_structure(&mut self, structure: Structure) {
unsafe { gst_sys::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr()) } unsafe { ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr()) }
} }
pub fn append_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) { pub fn append_structure_full(&mut self, structure: Structure, features: Option<CapsFeatures>) {
unsafe { unsafe {
gst_sys::gst_caps_append_structure_full( ffi::gst_caps_append_structure_full(
self.as_mut_ptr(), self.as_mut_ptr(),
structure.into_ptr(), structure.into_ptr(),
features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()), features.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
@ -299,25 +295,20 @@ impl CapsRef {
} }
pub fn remove_structure(&mut self, idx: u32) { pub fn remove_structure(&mut self, idx: u32) {
unsafe { gst_sys::gst_caps_remove_structure(self.as_mut_ptr(), idx) } unsafe { ffi::gst_caps_remove_structure(self.as_mut_ptr(), idx) }
} }
pub fn append(&mut self, other: Caps) { pub fn append(&mut self, other: Caps) {
unsafe { gst_sys::gst_caps_append(self.as_mut_ptr(), other.into_ptr()) } unsafe { ffi::gst_caps_append(self.as_mut_ptr(), other.into_ptr()) }
} }
pub fn can_intersect(&self, other: &Self) -> bool { pub fn can_intersect(&self, other: &Self) -> bool {
unsafe { unsafe { from_glib(ffi::gst_caps_can_intersect(self.as_ptr(), other.as_ptr())) }
from_glib(gst_sys::gst_caps_can_intersect(
self.as_ptr(),
other.as_ptr(),
))
}
} }
pub fn intersect(&self, other: &Self) -> Caps { pub fn intersect(&self, other: &Self) -> Caps {
unsafe { unsafe {
from_glib_full(gst_sys::gst_caps_intersect( from_glib_full(ffi::gst_caps_intersect(
self.as_mut_ptr(), self.as_mut_ptr(),
other.as_mut_ptr(), other.as_mut_ptr(),
)) ))
@ -326,7 +317,7 @@ impl CapsRef {
pub fn intersect_with_mode(&self, other: &Self, mode: CapsIntersectMode) -> Caps { pub fn intersect_with_mode(&self, other: &Self, mode: CapsIntersectMode) -> Caps {
unsafe { unsafe {
from_glib_full(gst_sys::gst_caps_intersect_full( from_glib_full(ffi::gst_caps_intersect_full(
self.as_mut_ptr(), self.as_mut_ptr(),
other.as_mut_ptr(), other.as_mut_ptr(),
mode.to_glib(), mode.to_glib(),
@ -336,7 +327,7 @@ impl CapsRef {
pub fn is_always_compatible(&self, other: &Self) -> bool { pub fn is_always_compatible(&self, other: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_caps_is_always_compatible( from_glib(ffi::gst_caps_is_always_compatible(
self.as_ptr(), self.as_ptr(),
other.as_ptr(), other.as_ptr(),
)) ))
@ -344,29 +335,24 @@ impl CapsRef {
} }
pub fn is_any(&self) -> bool { pub fn is_any(&self) -> bool {
unsafe { from_glib(gst_sys::gst_caps_is_any(self.as_ptr())) } unsafe { from_glib(ffi::gst_caps_is_any(self.as_ptr())) }
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
unsafe { from_glib(gst_sys::gst_caps_is_empty(self.as_ptr())) } unsafe { from_glib(ffi::gst_caps_is_empty(self.as_ptr())) }
} }
pub fn is_fixed(&self) -> bool { pub fn is_fixed(&self) -> bool {
unsafe { from_glib(gst_sys::gst_caps_is_fixed(self.as_ptr())) } unsafe { from_glib(ffi::gst_caps_is_fixed(self.as_ptr())) }
} }
pub fn is_equal_fixed(&self, other: &Self) -> bool { pub fn is_equal_fixed(&self, other: &Self) -> bool {
unsafe { unsafe { from_glib(ffi::gst_caps_is_equal_fixed(self.as_ptr(), other.as_ptr())) }
from_glib(gst_sys::gst_caps_is_equal_fixed(
self.as_ptr(),
other.as_ptr(),
))
}
} }
pub fn is_strictly_equal(&self, other: &Self) -> bool { pub fn is_strictly_equal(&self, other: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_caps_is_strictly_equal( from_glib(ffi::gst_caps_is_strictly_equal(
self.as_ptr(), self.as_ptr(),
other.as_ptr(), other.as_ptr(),
)) ))
@ -374,17 +360,12 @@ impl CapsRef {
} }
pub fn is_subset(&self, superset: &Self) -> bool { pub fn is_subset(&self, superset: &Self) -> bool {
unsafe { unsafe { from_glib(ffi::gst_caps_is_subset(self.as_ptr(), superset.as_ptr())) }
from_glib(gst_sys::gst_caps_is_subset(
self.as_ptr(),
superset.as_ptr(),
))
}
} }
pub fn is_subset_structure(&self, structure: &StructureRef) -> bool { pub fn is_subset_structure(&self, structure: &StructureRef) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_caps_is_subset_structure( from_glib(ffi::gst_caps_is_subset_structure(
self.as_ptr(), self.as_ptr(),
structure.as_ptr(), structure.as_ptr(),
)) ))
@ -397,7 +378,7 @@ impl CapsRef {
features: Option<&CapsFeaturesRef>, features: Option<&CapsFeaturesRef>,
) -> bool { ) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_caps_is_subset_structure_full( from_glib(ffi::gst_caps_is_subset_structure_full(
self.as_ptr(), self.as_ptr(),
structure.as_ptr(), structure.as_ptr(),
features.map(|f| f.as_ptr()).unwrap_or(ptr::null()), features.map(|f| f.as_ptr()).unwrap_or(ptr::null()),
@ -408,7 +389,7 @@ impl CapsRef {
pub fn subtract(&self, other: &Self) -> Caps { pub fn subtract(&self, other: &Self) -> Caps {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_caps_subtract( from_glib_full(ffi::gst_caps_subtract(
self.as_mut_ptr(), self.as_mut_ptr(),
other.as_mut_ptr(), other.as_mut_ptr(),
)) ))
@ -487,12 +468,12 @@ define_iter!(
&'a CapsRef, &'a CapsRef,
&'a StructureRef, &'a StructureRef,
|caps: &CapsRef, idx| { |caps: &CapsRef, idx| {
let ptr = gst_sys::gst_caps_get_structure(caps.as_ptr(), idx); let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
Some(StructureRef::from_glib_borrow( Some(StructureRef::from_glib_borrow(
ptr as *const gst_sys::GstStructure, ptr as *const ffi::GstStructure,
)) ))
} }
} }
@ -502,12 +483,12 @@ define_iter!(
&'a mut CapsRef, &'a mut CapsRef,
&'a mut StructureRef, &'a mut StructureRef,
|caps: &CapsRef, idx| { |caps: &CapsRef, idx| {
let ptr = gst_sys::gst_caps_get_structure(caps.as_ptr(), idx); let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
Some(StructureRef::from_glib_borrow_mut( Some(StructureRef::from_glib_borrow_mut(
ptr as *mut gst_sys::GstStructure, ptr as *mut ffi::GstStructure,
)) ))
} }
} }
@ -517,14 +498,14 @@ define_iter!(
&'a CapsRef, &'a CapsRef,
(&'a StructureRef, &'a CapsFeaturesRef), (&'a StructureRef, &'a CapsFeaturesRef),
|caps: &CapsRef, idx| { |caps: &CapsRef, idx| {
let ptr1 = gst_sys::gst_caps_get_structure(caps.as_ptr(), idx); let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
let ptr2 = gst_sys::gst_caps_get_features(caps.as_ptr(), idx); let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx);
if ptr1.is_null() || ptr2.is_null() { if ptr1.is_null() || ptr2.is_null() {
None None
} else { } else {
Some(( Some((
StructureRef::from_glib_borrow(ptr1 as *const gst_sys::GstStructure), StructureRef::from_glib_borrow(ptr1 as *const ffi::GstStructure),
CapsFeaturesRef::from_glib_borrow(ptr2 as *const gst_sys::GstCapsFeatures), CapsFeaturesRef::from_glib_borrow(ptr2 as *const ffi::GstCapsFeatures),
)) ))
} }
} }
@ -534,14 +515,14 @@ define_iter!(
&'a mut CapsRef, &'a mut CapsRef,
(&'a mut StructureRef, &'a mut CapsFeaturesRef), (&'a mut StructureRef, &'a mut CapsFeaturesRef),
|caps: &CapsRef, idx| { |caps: &CapsRef, idx| {
let ptr1 = gst_sys::gst_caps_get_structure(caps.as_ptr(), idx); let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
let ptr2 = gst_sys::gst_caps_get_features(caps.as_ptr(), idx); let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx);
if ptr1.is_null() || ptr2.is_null() { if ptr1.is_null() || ptr2.is_null() {
None None
} else { } else {
Some(( Some((
StructureRef::from_glib_borrow_mut(ptr1 as *mut gst_sys::GstStructure), StructureRef::from_glib_borrow_mut(ptr1 as *mut ffi::GstStructure),
CapsFeaturesRef::from_glib_borrow_mut(ptr2 as *mut gst_sys::GstCapsFeatures), CapsFeaturesRef::from_glib_borrow_mut(ptr2 as *mut ffi::GstCapsFeatures),
)) ))
} }
} }
@ -575,15 +556,14 @@ impl fmt::Debug for CapsRef {
impl fmt::Display for CapsRef { impl fmt::Display for CapsRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = let s = unsafe { glib::GString::from_glib_full(ffi::gst_caps_to_string(self.as_ptr())) };
unsafe { glib::GString::from_glib_full(gst_sys::gst_caps_to_string(self.as_ptr())) };
f.write_str(&s) f.write_str(&s)
} }
} }
impl PartialEq for CapsRef { impl PartialEq for CapsRef {
fn eq(&self, other: &CapsRef) -> bool { fn eq(&self, other: &CapsRef) -> bool {
unsafe { from_glib(gst_sys::gst_caps_is_equal(self.as_ptr(), other.as_ptr())) } unsafe { from_glib(ffi::gst_caps_is_equal(self.as_ptr(), other.as_ptr())) }
} }
} }
@ -593,7 +573,7 @@ pub enum NoFeature {}
pub enum HasFeatures {} pub enum HasFeatures {}
pub struct Builder<T> { pub struct Builder<T> {
s: ::Structure, s: crate::Structure,
features: Option<CapsFeatures>, features: Option<CapsFeatures>,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -612,7 +592,7 @@ impl Builder<NoFeature> {
fn new(name: &str) -> Builder<NoFeature> { fn new(name: &str) -> Builder<NoFeature> {
skip_assert_initialized!(); skip_assert_initialized!();
Builder { Builder {
s: ::Structure::new_empty(name), s: crate::Structure::new_empty(name),
features: None, features: None,
phantom: PhantomData, phantom: PhantomData,
} }
@ -655,7 +635,7 @@ pub enum AnyFeatures {}
pub enum SomeFeatures {} pub enum SomeFeatures {}
pub struct BuilderFull<T> { pub struct BuilderFull<T> {
caps: ::Caps, caps: crate::Caps,
features: Option<CapsFeatures>, features: Option<CapsFeatures>,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -744,12 +724,12 @@ impl<T> BuilderFull<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use Array; use crate::Array;
use Fraction; use crate::Fraction;
#[test] #[test]
fn test_simple() { fn test_simple() {
::init().unwrap(); crate::init().unwrap();
let mut caps = Caps::new_simple( let mut caps = Caps::new_simple(
"foo/bar", "foo/bar",
@ -786,7 +766,7 @@ mod tests {
assert!(caps assert!(caps
.get_features(0) .get_features(0)
.unwrap() .unwrap()
.is_equal(::CAPS_FEATURES_MEMORY_SYSTEM_MEMORY.as_ref())); .is_equal(crate::CAPS_FEATURES_MEMORY_SYSTEM_MEMORY.as_ref()));
{ {
let caps = caps.get_mut().unwrap(); let caps = caps.get_mut().unwrap();
@ -800,7 +780,7 @@ mod tests {
#[test] #[test]
fn test_builder() { fn test_builder() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::builder("foo/bar") let caps = Caps::builder("foo/bar")
.field("int", &12) .field("int", &12)
@ -829,7 +809,7 @@ mod tests {
#[test] #[test]
fn test_display() { fn test_display() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::new_simple("foo/bar", &[]); let caps = Caps::new_simple("foo/bar", &[]);
format!("{}", caps); format!("{}", caps);
@ -837,7 +817,7 @@ mod tests {
#[test] #[test]
fn test_builder_full() { fn test_builder_full() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::builder_full() let caps = Caps::builder_full()
.structure(Structure::builder("audio/x-raw").build()) .structure(Structure::builder("audio/x-raw").build())
@ -873,7 +853,7 @@ mod tests {
#[test] #[test]
fn test_builder_full_with_features() { fn test_builder_full_with_features() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::builder_full_with_features(CapsFeatures::new(&["foo:bla"])) let caps = Caps::builder_full_with_features(CapsFeatures::new(&["foo:bla"]))
.structure(Structure::builder("audio/x-raw").build()) .structure(Structure::builder("audio/x-raw").build())
@ -890,7 +870,7 @@ mod tests {
#[test] #[test]
fn test_builder_full_with_any_features() { fn test_builder_full_with_any_features() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::builder_full_with_any_features() let caps = Caps::builder_full_with_any_features()
.structure(Structure::builder("audio/x-raw").build()) .structure(Structure::builder("audio/x-raw").build())
@ -906,7 +886,7 @@ mod tests {
#[test] #[test]
fn test_new_from_iter() { fn test_new_from_iter() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::builder_full_with_any_features() let caps = Caps::builder_full_with_any_features()
.structure(Structure::builder("audio/x-raw").build()) .structure(Structure::builder("audio/x-raw").build())

View file

@ -16,14 +16,11 @@ use std::str;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use glib; use glib::ffi::gpointer;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, Stash, StashMut, from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, Stash, StashMut,
ToGlibPtr, ToGlibPtrMut, ToGlibPtr, ToGlibPtrMut,
}; };
use glib_sys::gpointer;
use gobject_sys;
use gst_sys;
pub struct CapsFeatures(ptr::NonNull<CapsFeaturesRef>); pub struct CapsFeatures(ptr::NonNull<CapsFeaturesRef>);
unsafe impl Send for CapsFeatures {} unsafe impl Send for CapsFeatures {}
@ -45,7 +42,7 @@ impl CapsFeatures {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
CapsFeatures(ptr::NonNull::new_unchecked( CapsFeatures(ptr::NonNull::new_unchecked(
gst_sys::gst_caps_features_new_empty() as *mut CapsFeaturesRef, ffi::gst_caps_features_new_empty() as *mut CapsFeaturesRef,
)) ))
} }
} }
@ -54,14 +51,14 @@ impl CapsFeatures {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
CapsFeatures(ptr::NonNull::new_unchecked( CapsFeatures(ptr::NonNull::new_unchecked(
gst_sys::gst_caps_features_new_any() as *mut CapsFeaturesRef, ffi::gst_caps_features_new_any() as *mut CapsFeaturesRef,
)) ))
} }
} }
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstCapsFeatures { pub unsafe fn into_ptr(self) -> *mut ffi::GstCapsFeatures {
let s = mem::ManuallyDrop::new(self); let s = mem::ManuallyDrop::new(self);
s.0.as_ptr() as *mut CapsFeaturesRef as *mut gst_sys::GstCapsFeatures s.0.as_ptr() as *mut CapsFeaturesRef as *mut ffi::GstCapsFeatures
} }
} }
@ -94,7 +91,7 @@ impl AsMut<CapsFeaturesRef> for CapsFeatures {
impl Clone for CapsFeatures { impl Clone for CapsFeatures {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { unsafe {
let ptr = gst_sys::gst_caps_features_copy(&self.0.as_ref().0) as *mut CapsFeaturesRef; let ptr = ffi::gst_caps_features_copy(&self.0.as_ref().0) as *mut CapsFeaturesRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr)) CapsFeatures(ptr::NonNull::new_unchecked(ptr))
} }
@ -103,7 +100,7 @@ impl Clone for CapsFeatures {
impl Drop for CapsFeatures { impl Drop for CapsFeatures {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { gst_sys::gst_caps_features_free(&mut self.0.as_mut().0) } unsafe { ffi::gst_caps_features_free(&mut self.0.as_mut().0) }
} }
} }
@ -129,9 +126,9 @@ impl str::FromStr for CapsFeatures {
fn from_str(s: &str) -> Result<Self, glib::BoolError> { fn from_str(s: &str) -> Result<Self, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let ptr = gst_sys::gst_caps_features_from_string(s.to_glib_none().0); let ptr = ffi::gst_caps_features_from_string(s.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
return Err(glib_bool_error!( return Err(glib::glib_bool_error!(
"Failed to parse caps features from string" "Failed to parse caps features from string"
)); ));
} }
@ -157,69 +154,69 @@ impl BorrowMut<CapsFeaturesRef> for CapsFeatures {
impl glib::types::StaticType for CapsFeatures { impl glib::types::StaticType for CapsFeatures {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_caps_features_get_type()) } unsafe { from_glib(ffi::gst_caps_features_get_type()) }
} }
} }
impl<'a> ToGlibPtr<'a, *const gst_sys::GstCapsFeatures> for CapsFeatures { impl<'a> ToGlibPtr<'a, *const ffi::GstCapsFeatures> for CapsFeatures {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none(&'a self) -> Stash<'a, *const gst_sys::GstCapsFeatures, Self> { fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstCapsFeatures, Self> {
unsafe { Stash(&self.0.as_ref().0, self) } unsafe { Stash(&self.0.as_ref().0, self) }
} }
fn to_glib_full(&self) -> *const gst_sys::GstCapsFeatures { fn to_glib_full(&self) -> *const ffi::GstCapsFeatures {
unsafe { gst_sys::gst_caps_features_copy(&self.0.as_ref().0) } unsafe { ffi::gst_caps_features_copy(&self.0.as_ref().0) }
} }
} }
impl<'a> ToGlibPtr<'a, *mut gst_sys::GstCapsFeatures> for CapsFeatures { impl<'a> ToGlibPtr<'a, *mut ffi::GstCapsFeatures> for CapsFeatures {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none(&'a self) -> Stash<'a, *mut gst_sys::GstCapsFeatures, Self> { fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstCapsFeatures, Self> {
unsafe { Stash(&self.0.as_ref().0 as *const _ as *mut _, self) } unsafe { Stash(&self.0.as_ref().0 as *const _ as *mut _, self) }
} }
fn to_glib_full(&self) -> *mut gst_sys::GstCapsFeatures { fn to_glib_full(&self) -> *mut ffi::GstCapsFeatures {
unsafe { gst_sys::gst_caps_features_copy(&self.0.as_ref().0) } unsafe { ffi::gst_caps_features_copy(&self.0.as_ref().0) }
} }
} }
impl<'a> ToGlibPtrMut<'a, *mut gst_sys::GstCapsFeatures> for CapsFeatures { impl<'a> ToGlibPtrMut<'a, *mut ffi::GstCapsFeatures> for CapsFeatures {
type Storage = &'a mut Self; type Storage = &'a mut Self;
fn to_glib_none_mut(&'a mut self) -> StashMut<*mut gst_sys::GstCapsFeatures, Self> { fn to_glib_none_mut(&'a mut self) -> StashMut<*mut ffi::GstCapsFeatures, Self> {
unsafe { StashMut(&mut self.0.as_mut().0, self) } unsafe { StashMut(&mut self.0.as_mut().0, self) }
} }
} }
impl FromGlibPtrNone<*const gst_sys::GstCapsFeatures> for CapsFeatures { impl FromGlibPtrNone<*const ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_none(ptr: *const gst_sys::GstCapsFeatures) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstCapsFeatures) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_caps_features_copy(ptr); let ptr = ffi::gst_caps_features_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef)) CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
} }
} }
impl FromGlibPtrNone<*mut gst_sys::GstCapsFeatures> for CapsFeatures { impl FromGlibPtrNone<*mut ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_none(ptr: *mut gst_sys::GstCapsFeatures) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstCapsFeatures) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_caps_features_copy(ptr); let ptr = ffi::gst_caps_features_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef)) CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
} }
} }
impl FromGlibPtrFull<*const gst_sys::GstCapsFeatures> for CapsFeatures { impl FromGlibPtrFull<*const ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *const gst_sys::GstCapsFeatures) -> Self { unsafe fn from_glib_full(ptr: *const ffi::GstCapsFeatures) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef)) CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
} }
} }
impl FromGlibPtrFull<*mut gst_sys::GstCapsFeatures> for CapsFeatures { impl FromGlibPtrFull<*mut ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstCapsFeatures) -> Self { unsafe fn from_glib_full(ptr: *mut ffi::GstCapsFeatures) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef)) CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
} }
@ -248,35 +245,33 @@ impl glib::value::SetValueOptional for CapsFeatures {
} }
impl GlibPtrDefault for CapsFeatures { impl GlibPtrDefault for CapsFeatures {
type GlibType = *mut gst_sys::GstCapsFeatures; type GlibType = *mut ffi::GstCapsFeatures;
} }
#[repr(transparent)] #[repr(transparent)]
pub struct CapsFeaturesRef(gst_sys::GstCapsFeatures); pub struct CapsFeaturesRef(ffi::GstCapsFeatures);
impl CapsFeaturesRef { impl CapsFeaturesRef {
pub unsafe fn from_glib_borrow<'a>( pub unsafe fn from_glib_borrow<'a>(ptr: *const ffi::GstCapsFeatures) -> &'a CapsFeaturesRef {
ptr: *const gst_sys::GstCapsFeatures,
) -> &'a CapsFeaturesRef {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
&*(ptr as *mut CapsFeaturesRef) &*(ptr as *mut CapsFeaturesRef)
} }
pub unsafe fn from_glib_borrow_mut<'a>( pub unsafe fn from_glib_borrow_mut<'a>(
ptr: *mut gst_sys::GstCapsFeatures, ptr: *mut ffi::GstCapsFeatures,
) -> &'a mut CapsFeaturesRef { ) -> &'a mut CapsFeaturesRef {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
&mut *(ptr as *mut CapsFeaturesRef) &mut *(ptr as *mut CapsFeaturesRef)
} }
pub unsafe fn as_ptr(&self) -> *const gst_sys::GstCapsFeatures { pub unsafe fn as_ptr(&self) -> *const ffi::GstCapsFeatures {
self as *const Self as *const gst_sys::GstCapsFeatures self as *const Self as *const ffi::GstCapsFeatures
} }
pub unsafe fn as_mut_ptr(&self) -> *mut gst_sys::GstCapsFeatures { pub unsafe fn as_mut_ptr(&self) -> *mut ffi::GstCapsFeatures {
self as *const Self as *mut gst_sys::GstCapsFeatures self as *const Self as *mut ffi::GstCapsFeatures
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
@ -284,12 +279,12 @@ impl CapsFeaturesRef {
} }
pub fn is_any(&self) -> bool { pub fn is_any(&self) -> bool {
unsafe { from_glib(gst_sys::gst_caps_features_is_any(self.as_ptr())) } unsafe { from_glib(ffi::gst_caps_features_is_any(self.as_ptr())) }
} }
pub fn contains(&self, feature: &str) -> bool { pub fn contains(&self, feature: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_caps_features_contains( from_glib(ffi::gst_caps_features_contains(
self.as_ptr(), self.as_ptr(),
feature.to_glib_none().0, feature.to_glib_none().0,
)) ))
@ -297,7 +292,7 @@ impl CapsFeaturesRef {
} }
pub fn get_size(&self) -> u32 { pub fn get_size(&self) -> u32 {
unsafe { gst_sys::gst_caps_features_get_size(self.as_ptr()) } unsafe { ffi::gst_caps_features_get_size(self.as_ptr()) }
} }
pub fn get_nth(&self, idx: u32) -> Option<&str> { pub fn get_nth(&self, idx: u32) -> Option<&str> {
@ -306,7 +301,7 @@ impl CapsFeaturesRef {
} }
unsafe { unsafe {
let feature = gst_sys::gst_caps_features_get_nth(self.as_ptr(), idx); let feature = ffi::gst_caps_features_get_nth(self.as_ptr(), idx);
if feature.is_null() { if feature.is_null() {
return None; return None;
} }
@ -316,11 +311,11 @@ impl CapsFeaturesRef {
} }
pub fn add(&mut self, feature: &str) { pub fn add(&mut self, feature: &str) {
unsafe { gst_sys::gst_caps_features_add(self.as_mut_ptr(), feature.to_glib_none().0) } unsafe { ffi::gst_caps_features_add(self.as_mut_ptr(), feature.to_glib_none().0) }
} }
pub fn remove(&mut self, feature: &str) { pub fn remove(&mut self, feature: &str) {
unsafe { gst_sys::gst_caps_features_remove(self.as_mut_ptr(), feature.to_glib_none().0) } unsafe { ffi::gst_caps_features_remove(self.as_mut_ptr(), feature.to_glib_none().0) }
} }
pub fn iter(&self) -> Iter { pub fn iter(&self) -> Iter {
@ -330,7 +325,7 @@ impl CapsFeaturesRef {
// This is not an equivalence relation with regards to ANY. Everything is equal to ANY // This is not an equivalence relation with regards to ANY. Everything is equal to ANY
pub fn is_equal(&self, other: &CapsFeaturesRef) -> bool { pub fn is_equal(&self, other: &CapsFeaturesRef) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_caps_features_is_equal( from_glib(ffi::gst_caps_features_is_equal(
self.as_ptr(), self.as_ptr(),
other.as_ptr(), other.as_ptr(),
)) ))
@ -340,18 +335,18 @@ impl CapsFeaturesRef {
impl glib::types::StaticType for CapsFeaturesRef { impl glib::types::StaticType for CapsFeaturesRef {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_structure_get_type()) } unsafe { from_glib(ffi::gst_structure_get_type()) }
} }
} }
impl<'a> glib::value::FromValueOptional<'a> for &'a CapsFeaturesRef { impl<'a> glib::value::FromValueOptional<'a> for &'a CapsFeaturesRef {
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> { unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
let ptr = gobject_sys::g_value_get_boxed(v.to_glib_none().0); let ptr = glib::gobject_ffi::g_value_get_boxed(v.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
Some(CapsFeaturesRef::from_glib_borrow( Some(CapsFeaturesRef::from_glib_borrow(
ptr as *const gst_sys::GstCapsFeatures, ptr as *const ffi::GstCapsFeatures,
)) ))
} }
} }
@ -359,16 +354,16 @@ impl<'a> glib::value::FromValueOptional<'a> for &'a CapsFeaturesRef {
impl glib::value::SetValue for CapsFeaturesRef { impl glib::value::SetValue for CapsFeaturesRef {
unsafe fn set_value(v: &mut glib::Value, s: &Self) { 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); glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} }
} }
impl glib::value::SetValueOptional for CapsFeaturesRef { impl glib::value::SetValueOptional for CapsFeaturesRef {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) { unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
if let Some(s) = s { if let Some(s) = s {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer); glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} else { } else {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut()); glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut());
} }
} }
} }
@ -402,7 +397,7 @@ impl<'a> Iterator for Iter<'a> {
} }
unsafe { unsafe {
let feature = gst_sys::gst_caps_features_get_nth(self.caps_features.as_ptr(), self.idx); let feature = ffi::gst_caps_features_get_nth(self.caps_features.as_ptr(), self.idx);
if feature.is_null() { if feature.is_null() {
return None; return None;
} }
@ -434,7 +429,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
unsafe { unsafe {
let feature = let feature =
gst_sys::gst_caps_features_get_nth(self.caps_features.as_ptr(), self.n_features); ffi::gst_caps_features_get_nth(self.caps_features.as_ptr(), self.n_features);
if feature.is_null() { if feature.is_null() {
return None; return None;
} }
@ -457,7 +452,7 @@ impl fmt::Debug for CapsFeaturesRef {
impl fmt::Display for CapsFeaturesRef { impl fmt::Display for CapsFeaturesRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = unsafe { let s = unsafe {
glib::GString::from_glib_full(gst_sys::gst_caps_features_to_string(self.as_ptr())) glib::GString::from_glib_full(ffi::gst_caps_features_to_string(self.as_ptr()))
}; };
f.write_str(&s) f.write_str(&s)
} }
@ -467,9 +462,7 @@ impl ToOwned for CapsFeaturesRef {
type Owned = CapsFeatures; type Owned = CapsFeatures;
fn to_owned(&self) -> CapsFeatures { fn to_owned(&self) -> CapsFeatures {
unsafe { unsafe { from_glib_full(ffi::gst_caps_features_copy(self.as_ptr() as *const _) as *mut _) }
from_glib_full(gst_sys::gst_caps_features_copy(self.as_ptr() as *const _) as *mut _)
}
} }
} }
@ -477,7 +470,7 @@ unsafe impl Sync for CapsFeaturesRef {}
unsafe impl Send for CapsFeaturesRef {} unsafe impl Send for CapsFeaturesRef {}
pub static CAPS_FEATURE_MEMORY_SYSTEM_MEMORY: Lazy<&'static str> = Lazy::new(|| unsafe { pub static CAPS_FEATURE_MEMORY_SYSTEM_MEMORY: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY) CStr::from_ptr(ffi::GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
@ -490,7 +483,7 @@ mod tests {
#[test] #[test]
fn test_from_value_optional() { fn test_from_value_optional() {
::init().unwrap(); crate::init().unwrap();
let a = glib::value::Value::from(None::<&CapsFeatures>); let a = glib::value::Value::from(None::<&CapsFeatures>);
assert!(a.get::<CapsFeatures>().unwrap().is_none()); assert!(a.get::<CapsFeatures>().unwrap().is_none());

View file

@ -12,8 +12,8 @@ use serde::ser::{Serialize, SerializeSeq, Serializer};
use std::fmt; use std::fmt;
use CapsFeatures; use crate::CapsFeatures;
use CapsFeaturesRef; use crate::CapsFeaturesRef;
enum CapsFeaturesVariantKinds { enum CapsFeaturesVariantKinds {
Any, Any,

View file

@ -12,12 +12,12 @@ use serde::ser::{Serialize, SerializeSeq, SerializeTuple, Serializer};
use std::fmt; use std::fmt;
use Caps; use crate::Caps;
use CapsFeatures; use crate::CapsFeatures;
use CapsFeaturesRef; use crate::CapsFeaturesRef;
use CapsRef; use crate::CapsRef;
use Structure; use crate::Structure;
use StructureRef; use crate::StructureRef;
enum CapsVariantKinds { enum CapsVariantKinds {
Any, Any,
@ -57,7 +57,7 @@ impl<'a> Serialize for CapsForIterSe<'a> {
let mut seq = serializer.serialize_seq(Some(size))?; let mut seq = serializer.serialize_seq(Some(size))?;
for (structure, features) in iter { for (structure, features) in iter {
let features = if !features.is_any() let features = if !features.is_any()
&& features.is_equal(::CAPS_FEATURES_MEMORY_SYSTEM_MEMORY.as_ref()) && features.is_equal(crate::CAPS_FEATURES_MEMORY_SYSTEM_MEMORY.as_ref())
{ {
None None
} else { } else {
@ -229,16 +229,14 @@ impl<'de> Deserialize<'de> for Caps {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::Array;
use crate::Caps;
use Array; use crate::CapsFeatures;
use Caps; use crate::Fraction;
use CapsFeatures;
use Fraction;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::builder("foo/bar") let caps = Caps::builder("foo/bar")
.field("int", &12) .field("int", &12)
@ -349,9 +347,9 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
use Structure; use crate::Structure;
::init().unwrap(); crate::init().unwrap();
let caps_ron = "Any"; let caps_ron = "Any";
let caps: Caps = ron::de::from_str(caps_ron).unwrap(); let caps: Caps = ron::de::from_str(caps_ron).unwrap();
@ -468,7 +466,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let caps = Caps::new_any(); let caps = Caps::new_any();
let caps_ser = ron::ser::to_string(&caps).unwrap(); let caps_ser = ron::ser::to_string(&caps).unwrap();

View file

@ -6,12 +6,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib; use crate::ChildProxy;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use std::ptr; use std::ptr;
use ChildProxy;
pub trait ChildProxyExtManual: 'static { pub trait ChildProxyExtManual: 'static {
fn get_child_property(&self, name: &str) -> Option<glib::Value>; fn get_child_property(&self, name: &str) -> Option<glib::Value>;
@ -25,7 +23,7 @@ pub trait ChildProxyExtManual: 'static {
impl<O: IsA<ChildProxy>> ChildProxyExtManual for O { impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
fn get_child_property(&self, name: &str) -> Option<glib::Value> { fn get_child_property(&self, name: &str) -> Option<glib::Value> {
unsafe { unsafe {
let found: bool = from_glib(gst_sys::gst_child_proxy_lookup( let found: bool = from_glib(ffi::gst_child_proxy_lookup(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
ptr::null_mut(), ptr::null_mut(),
@ -36,7 +34,7 @@ impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
} }
let mut value = glib::Value::uninitialized(); let mut value = glib::Value::uninitialized();
gst_sys::gst_child_proxy_get_property( ffi::gst_child_proxy_get_property(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
@ -51,18 +49,18 @@ impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
value: &dyn glib::ToValue, value: &dyn glib::ToValue,
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
unsafe { unsafe {
let found: bool = from_glib(gst_sys::gst_child_proxy_lookup( let found: bool = from_glib(ffi::gst_child_proxy_lookup(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
)); ));
if !found { if !found {
return Err(glib_bool_error!("Child property not found")); return Err(glib::glib_bool_error!("Child property not found"));
} }
let value = value.to_value(); let value = value.to_value();
gst_sys::gst_child_proxy_set_property( ffi::gst_child_proxy_set_property(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
value.to_glib_none().0, value.to_glib_none().0,

View file

@ -6,26 +6,24 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib; use crate::Clock;
use crate::ClockEntryType;
use crate::ClockError;
use crate::ClockFlags;
use crate::ClockReturn;
use crate::ClockSuccess;
use crate::ClockTime;
use crate::ClockTimeDiff;
use glib::ffi::{gboolean, gpointer};
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
use glib::prelude::*; use glib::prelude::*;
use glib::translate::*; use glib::translate::*;
use glib::IsA; use glib::IsA;
use glib_sys::{gboolean, gpointer};
use gst_sys;
use libc::c_void; use libc::c_void;
use std::cmp; use std::cmp;
use std::convert; use std::convert;
use std::ptr; use std::ptr;
use Clock;
use ClockEntryType;
use ClockError;
use ClockFlags;
use ClockReturn;
use ClockSuccess;
use ClockTime;
use ClockTimeDiff;
use futures_core::{Future, Stream}; use futures_core::{Future, Stream};
use std::marker::Unpin; use std::marker::Unpin;
@ -33,40 +31,37 @@ use std::pin::Pin;
use std::sync::atomic; use std::sync::atomic;
use std::sync::atomic::AtomicI32; use std::sync::atomic::AtomicI32;
glib_wrapper! { glib::glib_wrapper! {
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct ClockId(Shared<c_void>); pub struct ClockId(Shared<c_void>);
match fn { match fn {
ref => |ptr| gst_sys::gst_clock_id_ref(ptr), ref => |ptr| ffi::gst_clock_id_ref(ptr),
unref => |ptr| gst_sys::gst_clock_id_unref(ptr), unref => |ptr| ffi::gst_clock_id_unref(ptr),
} }
} }
impl ClockId { impl ClockId {
pub fn get_time(&self) -> ClockTime { pub fn get_time(&self) -> ClockTime {
unsafe { from_glib(gst_sys::gst_clock_id_get_time(self.to_glib_none().0)) } unsafe { from_glib(ffi::gst_clock_id_get_time(self.to_glib_none().0)) }
} }
pub fn unschedule(&self) { pub fn unschedule(&self) {
unsafe { gst_sys::gst_clock_id_unschedule(self.to_glib_none().0) } unsafe { ffi::gst_clock_id_unschedule(self.to_glib_none().0) }
} }
pub fn wait(&self) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) { pub fn wait(&self) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe { unsafe {
let mut jitter = 0; let mut jitter = 0;
let res: ClockReturn = from_glib(gst_sys::gst_clock_id_wait( let res: ClockReturn =
self.to_glib_none().0, from_glib(ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter));
&mut jitter,
));
(res.into_result(), jitter) (res.into_result(), jitter)
} }
} }
pub fn compare_by_time(&self, other: &Self) -> cmp::Ordering { pub fn compare_by_time(&self, other: &Self) -> cmp::Ordering {
unsafe { unsafe {
let res = let res = ffi::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0);
gst_sys::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0);
res.cmp(&0) res.cmp(&0)
} }
} }
@ -74,14 +69,14 @@ impl ClockId {
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn get_clock(&self) -> Option<Clock> { pub fn get_clock(&self) -> Option<Clock> {
unsafe { from_glib_full(gst_sys::gst_clock_id_get_clock(self.to_glib_none().0)) } unsafe { from_glib_full(ffi::gst_clock_id_get_clock(self.to_glib_none().0)) }
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn uses_clock<P: IsA<Clock>>(&self, clock: &P) -> bool { pub fn uses_clock<P: IsA<Clock>>(&self, clock: &P) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_clock_id_uses_clock( from_glib(ffi::gst_clock_id_uses_clock(
self.to_glib_none().0, self.to_glib_none().0,
clock.as_ref().as_ptr(), clock.as_ref().as_ptr(),
)) ))
@ -90,14 +85,14 @@ impl ClockId {
pub fn get_type(&self) -> ClockEntryType { pub fn get_type(&self) -> ClockEntryType {
unsafe { unsafe {
let ptr: *mut gst_sys::GstClockEntry = self.to_glib_none().0 as *mut _; let ptr: *mut ffi::GstClockEntry = self.to_glib_none().0 as *mut _;
from_glib((*ptr).type_) from_glib((*ptr).type_)
} }
} }
pub fn get_status(&self) -> &AtomicClockReturn { pub fn get_status(&self) -> &AtomicClockReturn {
unsafe { unsafe {
let ptr: *mut gst_sys::GstClockEntry = self.to_glib_none().0 as *mut _; let ptr: *mut ffi::GstClockEntry = self.to_glib_none().0 as *mut _;
&*((&(*ptr).status) as *const i32 as *const AtomicClockReturn) &*((&(*ptr).status) as *const i32 as *const AtomicClockReturn)
} }
} }
@ -128,7 +123,7 @@ impl convert::TryFrom<ClockId> for SingleShotClockId {
skip_assert_initialized!(); skip_assert_initialized!();
match id.get_type() { match id.get_type() {
ClockEntryType::Single => Ok(SingleShotClockId(id)), ClockEntryType::Single => Ok(SingleShotClockId(id)),
_ => Err(glib_bool_error!("Not a single-shot clock id")), _ => Err(glib::glib_bool_error!("Not a single-shot clock id")),
} }
} }
} }
@ -143,8 +138,8 @@ impl SingleShotClockId {
F: FnOnce(&Clock, ClockTime, &ClockId) + Send + 'static, F: FnOnce(&Clock, ClockTime, &ClockId) + Send + 'static,
{ {
unsafe extern "C" fn trampoline<F: FnOnce(&Clock, ClockTime, &ClockId) + Send + 'static>( unsafe extern "C" fn trampoline<F: FnOnce(&Clock, ClockTime, &ClockId) + Send + 'static>(
clock: *mut gst_sys::GstClock, clock: *mut ffi::GstClock,
time: gst_sys::GstClockTime, time: ffi::GstClockTime,
id: gpointer, id: gpointer,
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
@ -157,7 +152,7 @@ impl SingleShotClockId {
&from_glib_borrow(id), &from_glib_borrow(id),
); );
glib_sys::GTRUE glib::ffi::GTRUE
} }
unsafe extern "C" fn destroy_notify< unsafe extern "C" fn destroy_notify<
@ -171,7 +166,7 @@ impl SingleShotClockId {
let func: Box<Option<F>> = Box::new(Some(func)); let func: Box<Option<F>> = Box::new(Some(func));
let ret: ClockReturn = unsafe { let ret: ClockReturn = unsafe {
from_glib(gst_sys::gst_clock_id_wait_async( from_glib(ffi::gst_clock_id_wait_async(
self.to_glib_none().0, self.to_glib_none().0,
Some(trampoline::<F>), Some(trampoline::<F>),
Box::into_raw(func) as gpointer, Box::into_raw(func) as gpointer,
@ -236,7 +231,7 @@ impl convert::TryFrom<ClockId> for PeriodicClockId {
skip_assert_initialized!(); skip_assert_initialized!();
match id.get_type() { match id.get_type() {
ClockEntryType::Periodic => Ok(PeriodicClockId(id)), ClockEntryType::Periodic => Ok(PeriodicClockId(id)),
_ => Err(glib_bool_error!("Not a periodic clock id")), _ => Err(glib::glib_bool_error!("Not a periodic clock id")),
} }
} }
} }
@ -244,7 +239,7 @@ impl convert::TryFrom<ClockId> for PeriodicClockId {
impl PeriodicClockId { impl PeriodicClockId {
pub fn get_interval(&self) -> ClockTime { pub fn get_interval(&self) -> ClockTime {
unsafe { unsafe {
let ptr: *mut gst_sys::GstClockEntry = self.to_glib_none().0 as *mut _; let ptr: *mut ffi::GstClockEntry = self.to_glib_none().0 as *mut _;
from_glib((*ptr).interval) from_glib((*ptr).interval)
} }
} }
@ -258,8 +253,8 @@ impl PeriodicClockId {
F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static, F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static,
{ {
unsafe extern "C" fn trampoline<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>( unsafe extern "C" fn trampoline<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(
clock: *mut gst_sys::GstClock, clock: *mut ffi::GstClock,
time: gst_sys::GstClockTime, time: ffi::GstClockTime,
id: gpointer, id: gpointer,
func: gpointer, func: gpointer,
) -> gboolean { ) -> gboolean {
@ -269,7 +264,7 @@ impl PeriodicClockId {
from_glib(time), from_glib(time),
&from_glib_borrow(id), &from_glib_borrow(id),
); );
glib_sys::GTRUE glib::ffi::GTRUE
} }
unsafe extern "C" fn destroy_notify<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>( unsafe extern "C" fn destroy_notify<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(
@ -280,7 +275,7 @@ impl PeriodicClockId {
let func: Box<F> = Box::new(func); let func: Box<F> = Box::new(func);
let ret: ClockReturn = unsafe { let ret: ClockReturn = unsafe {
from_glib(gst_sys::gst_clock_id_wait_async( from_glib(ffi::gst_clock_id_wait_async(
self.to_glib_none().0, self.to_glib_none().0,
Some(trampoline::<F>), Some(trampoline::<F>),
Box::into_raw(func) as gpointer, Box::into_raw(func) as gpointer,
@ -351,7 +346,7 @@ impl Clock {
) -> ClockTime { ) -> ClockTime {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib(gst_sys::gst_clock_adjust_with_calibration( from_glib(ffi::gst_clock_adjust_with_calibration(
ptr::null_mut(), ptr::null_mut(),
internal_target.to_glib(), internal_target.to_glib(),
cinternal.to_glib(), cinternal.to_glib(),
@ -371,7 +366,7 @@ impl Clock {
) -> ClockTime { ) -> ClockTime {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib(gst_sys::gst_clock_unadjust_with_calibration( from_glib(ffi::gst_clock_unadjust_with_calibration(
ptr::null_mut(), ptr::null_mut(),
external_target.to_glib(), external_target.to_glib(),
cinternal.to_glib(), cinternal.to_glib(),
@ -412,10 +407,10 @@ impl<O: IsA<Clock>> ClockExtManual for O {
fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> PeriodicClockId { fn new_periodic_id(&self, start_time: ClockTime, interval: ClockTime) -> PeriodicClockId {
assert!(start_time.is_some()); assert!(start_time.is_some());
assert!(interval.is_some()); assert!(interval.is_some());
assert_ne!(interval, ::ClockTime::from(0)); assert_ne!(interval, crate::ClockTime::from(0));
unsafe { unsafe {
PeriodicClockId(from_glib_full(gst_sys::gst_clock_new_periodic_id( PeriodicClockId(from_glib_full(ffi::gst_clock_new_periodic_id(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
start_time.to_glib(), start_time.to_glib(),
interval.to_glib(), interval.to_glib(),
@ -431,7 +426,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let res: bool = from_glib(gst_sys::gst_clock_periodic_id_reinit( let res: bool = from_glib(ffi::gst_clock_periodic_id_reinit(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
id.to_glib_none().0, id.to_glib_none().0,
start_time.to_glib(), start_time.to_glib(),
@ -440,7 +435,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
if res { if res {
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!("Failed to reinit periodic clock id")) Err(glib::glib_bool_error!("Failed to reinit periodic clock id"))
} }
} }
} }
@ -449,7 +444,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
assert!(time.is_some()); assert!(time.is_some());
unsafe { unsafe {
SingleShotClockId(from_glib_full(gst_sys::gst_clock_new_single_shot_id( SingleShotClockId(from_glib_full(ffi::gst_clock_new_single_shot_id(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
time.to_glib(), time.to_glib(),
))) )))
@ -462,7 +457,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
time: ClockTime, time: ClockTime,
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
unsafe { unsafe {
let res: bool = from_glib(gst_sys::gst_clock_single_shot_id_reinit( let res: bool = from_glib(ffi::gst_clock_single_shot_id_reinit(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
id.to_glib_none().0, id.to_glib_none().0,
time.to_glib(), time.to_glib(),
@ -470,31 +465,33 @@ impl<O: IsA<Clock>> ClockExtManual for O {
if res { if res {
Ok(()) Ok(())
} else { } else {
Err(glib_bool_error!("Failed to reinit single shot clock id")) Err(glib::glib_bool_error!(
"Failed to reinit single shot clock id"
))
} }
} }
} }
fn set_clock_flags(&self, flags: ClockFlags) { fn set_clock_flags(&self, flags: ClockFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib(); (*ptr).flags |= flags.to_glib();
} }
} }
fn unset_clock_flags(&self, flags: ClockFlags) { fn unset_clock_flags(&self, flags: ClockFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib(); (*ptr).flags &= !flags.to_glib();
} }
} }
fn get_clock_flags(&self) -> ClockFlags { fn get_clock_flags(&self) -> ClockFlags {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags) from_glib((*ptr).flags)
} }
} }
@ -508,11 +505,11 @@ mod tests {
#[test] #[test]
fn test_wait() { fn test_wait() {
::init().unwrap(); crate::init().unwrap();
let clock = SystemClock::obtain(); let clock = SystemClock::obtain();
let now = clock.get_time(); let now = clock.get_time();
let id = clock.new_single_shot_id(now + 20 * ::MSECOND); let id = clock.new_single_shot_id(now + 20 * crate::MSECOND);
let (res, _) = id.wait(); let (res, _) = id.wait();
assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early)); assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early));
@ -520,13 +517,13 @@ mod tests {
#[test] #[test]
fn test_wait_async() { fn test_wait_async() {
::init().unwrap(); crate::init().unwrap();
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let clock = SystemClock::obtain(); let clock = SystemClock::obtain();
let now = clock.get_time(); let now = clock.get_time();
let id = clock.new_single_shot_id(now + 20 * ::MSECOND); let id = clock.new_single_shot_id(now + 20 * crate::MSECOND);
let res = id.wait_async(move |_, _, _| { let res = id.wait_async(move |_, _, _| {
sender.send(()).unwrap(); sender.send(()).unwrap();
}); });
@ -538,11 +535,11 @@ mod tests {
#[test] #[test]
fn test_wait_periodic() { fn test_wait_periodic() {
::init().unwrap(); crate::init().unwrap();
let clock = SystemClock::obtain(); let clock = SystemClock::obtain();
let now = clock.get_time(); let now = clock.get_time();
let id = clock.new_periodic_id(now + 20 * ::MSECOND, 20 * ::MSECOND); let id = clock.new_periodic_id(now + 20 * crate::MSECOND, 20 * crate::MSECOND);
let (res, _) = id.wait(); let (res, _) = id.wait();
assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early)); assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early));
@ -553,13 +550,13 @@ mod tests {
#[test] #[test]
fn test_wait_async_periodic() { fn test_wait_async_periodic() {
::init().unwrap(); crate::init().unwrap();
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let clock = SystemClock::obtain(); let clock = SystemClock::obtain();
let now = clock.get_time(); let now = clock.get_time();
let id = clock.new_periodic_id(now + 20 * ::MSECOND, 20 * ::MSECOND); let id = clock.new_periodic_id(now + 20 * crate::MSECOND, 20 * crate::MSECOND);
let res = id.wait_async(move |_, _, _| { let res = id.wait_async(move |_, _, _| {
let _ = sender.send(()); let _ = sender.send(());
}); });

View file

@ -6,9 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use std::time::Duration; use std::time::Duration;
use std::{cmp, convert, fmt}; use std::{cmp, convert, fmt};
@ -17,27 +15,27 @@ pub struct ClockTime(pub Option<u64>);
impl ClockTime { impl ClockTime {
pub fn hours(&self) -> Option<u64> { pub fn hours(&self) -> Option<u64> {
(*self / ::SECOND / 60 / 60).0 (*self / crate::SECOND / 60 / 60).0
} }
pub fn minutes(&self) -> Option<u64> { pub fn minutes(&self) -> Option<u64> {
(*self / ::SECOND / 60).0 (*self / crate::SECOND / 60).0
} }
pub fn seconds(&self) -> Option<u64> { pub fn seconds(&self) -> Option<u64> {
(*self / ::SECOND).0 (*self / crate::SECOND).0
} }
pub fn mseconds(&self) -> Option<u64> { pub fn mseconds(&self) -> Option<u64> {
(*self / ::MSECOND).0 (*self / crate::MSECOND).0
} }
pub fn useconds(&self) -> Option<u64> { pub fn useconds(&self) -> Option<u64> {
(*self / ::USECOND).0 (*self / crate::USECOND).0
} }
pub fn nseconds(&self) -> Option<u64> { pub fn nseconds(&self) -> Option<u64> {
(*self / ::NSECOND).0 (*self / crate::NSECOND).0
} }
pub fn nanoseconds(&self) -> Option<u64> { pub fn nanoseconds(&self) -> Option<u64> {
@ -46,22 +44,22 @@ impl ClockTime {
pub fn from_seconds(seconds: u64) -> ClockTime { pub fn from_seconds(seconds: u64) -> ClockTime {
skip_assert_initialized!(); skip_assert_initialized!();
seconds * ::SECOND seconds * crate::SECOND
} }
pub fn from_mseconds(mseconds: u64) -> ClockTime { pub fn from_mseconds(mseconds: u64) -> ClockTime {
skip_assert_initialized!(); skip_assert_initialized!();
mseconds * ::MSECOND mseconds * crate::MSECOND
} }
pub fn from_useconds(useconds: u64) -> ClockTime { pub fn from_useconds(useconds: u64) -> ClockTime {
skip_assert_initialized!(); skip_assert_initialized!();
useconds * ::USECOND useconds * crate::USECOND
} }
pub fn from_nseconds(nseconds: u64) -> ClockTime { pub fn from_nseconds(nseconds: u64) -> ClockTime {
skip_assert_initialized!(); skip_assert_initialized!();
nseconds * ::NSECOND nseconds * crate::NSECOND
} }
} }
@ -182,22 +180,22 @@ impl fmt::Display for ClockTime {
#[doc(hidden)] #[doc(hidden)]
impl ToGlib for ClockTime { impl ToGlib for ClockTime {
type GlibType = gst_sys::GstClockTime; type GlibType = ffi::GstClockTime;
fn to_glib(&self) -> gst_sys::GstClockTime { fn to_glib(&self) -> ffi::GstClockTime {
match self.0 { match self.0 {
None => gst_sys::GST_CLOCK_TIME_NONE, None => ffi::GST_CLOCK_TIME_NONE,
Some(v) => v, Some(v) => v,
} }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<gst_sys::GstClockTime> for ClockTime { impl FromGlib<ffi::GstClockTime> for ClockTime {
fn from_glib(value: gst_sys::GstClockTime) -> Self { fn from_glib(value: ffi::GstClockTime) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
match value { match value {
gst_sys::GST_CLOCK_TIME_NONE => ClockTime(None), ffi::GST_CLOCK_TIME_NONE => ClockTime(None),
value => ClockTime(Some(value)), value => ClockTime(Some(value)),
} }
} }
@ -239,7 +237,7 @@ impl From<Duration> for ClockTime {
let nanos = d.as_nanos(); let nanos = d.as_nanos();
if nanos > std::u64::MAX as u128 { if nanos > std::u64::MAX as u128 {
::CLOCK_TIME_NONE crate::CLOCK_TIME_NONE
} else { } else {
ClockTime::from_nseconds(nanos as u64) ClockTime::from_nseconds(nanos as u64)
} }
@ -254,7 +252,7 @@ impl convert::TryFrom<ClockTime> for Duration {
t.nanoseconds() t.nanoseconds()
.map(Duration::from_nanos) .map(Duration::from_nanos)
.ok_or_else(|| glib_bool_error!("Can't convert ClockTime::NONE to Duration")) .ok_or_else(|| glib::glib_bool_error!("Can't convert ClockTime::NONE to Duration"))
} }
} }

View file

@ -12,7 +12,7 @@ use serde::ser::{Serialize, Serializer};
use std::fmt; use std::fmt;
use ClockTime; use crate::ClockTime;
impl<'a> Serialize for ClockTime { impl<'a> Serialize for ClockTime {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
@ -52,14 +52,11 @@ impl<'de> Deserialize<'de> for ClockTime {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::ClockTime;
extern crate serde_json;
use ClockTime;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
// Some // Some
let clocktime = ClockTime::from_nseconds(42_123_456_789); let clocktime = ClockTime::from_nseconds(42_123_456_789);
@ -85,7 +82,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
// Some // Some
let clocktime_ron = "Some(42123456789)"; let clocktime_ron = "Some(42123456789)";
@ -114,7 +111,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
// Some // Some
let clocktime = ClockTime::from_nseconds(42_123_456_789); let clocktime = ClockTime::from_nseconds(42_123_456_789);

View file

@ -9,22 +9,19 @@
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use gst_sys;
use glib;
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
use StructureRef; use crate::StructureRef;
gst_define_mini_object_wrapper!(Context, ContextRef, gst_sys::GstContext, || { gst_define_mini_object_wrapper!(Context, ContextRef, ffi::GstContext, || {
gst_sys::gst_context_get_type() ffi::gst_context_get_type()
}); });
impl Context { impl Context {
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 {
from_glib_full(gst_sys::gst_context_new( from_glib_full(ffi::gst_context_new(
context_type.to_glib_none().0, context_type.to_glib_none().0,
persistent.to_glib(), persistent.to_glib(),
)) ))
@ -35,14 +32,14 @@ impl Context {
impl ContextRef { impl ContextRef {
pub fn get_context_type(&self) -> &str { pub fn get_context_type(&self) -> &str {
unsafe { unsafe {
let raw = gst_sys::gst_context_get_context_type(self.as_mut_ptr()); let raw = ffi::gst_context_get_context_type(self.as_mut_ptr());
CStr::from_ptr(raw).to_str().unwrap() CStr::from_ptr(raw).to_str().unwrap()
} }
} }
pub fn has_context_type(&self, context_type: &str) -> bool { pub fn has_context_type(&self, context_type: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_context_has_context_type( from_glib(ffi::gst_context_has_context_type(
self.as_mut_ptr(), self.as_mut_ptr(),
context_type.to_glib_none().0, context_type.to_glib_none().0,
)) ))
@ -50,18 +47,16 @@ impl ContextRef {
} }
pub fn is_persistent(&self) -> bool { pub fn is_persistent(&self) -> bool {
unsafe { from_glib(gst_sys::gst_context_is_persistent(self.as_mut_ptr())) } unsafe { from_glib(ffi::gst_context_is_persistent(self.as_mut_ptr())) }
} }
pub fn get_structure(&self) -> &StructureRef { pub fn get_structure(&self) -> &StructureRef {
unsafe { unsafe { StructureRef::from_glib_borrow(ffi::gst_context_get_structure(self.as_mut_ptr())) }
StructureRef::from_glib_borrow(gst_sys::gst_context_get_structure(self.as_mut_ptr()))
}
} }
pub fn get_mut_structure(&mut self) -> &mut StructureRef { pub fn get_mut_structure(&mut self) -> &mut StructureRef {
unsafe { unsafe {
StructureRef::from_glib_borrow_mut(gst_sys::gst_context_writable_structure( StructureRef::from_glib_borrow_mut(ffi::gst_context_writable_structure(
self.as_mut_ptr(), self.as_mut_ptr(),
)) ))
} }

View file

@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::ClockTime;
use crate::ControlBinding;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use ClockTime;
use ControlBinding;
pub trait ControlBindingExtManual: 'static { pub trait ControlBindingExtManual: 'static {
fn get_g_value_array( fn get_g_value_array(
@ -30,13 +29,13 @@ impl<O: IsA<ControlBinding>> ControlBindingExtManual for O {
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let n_values = values.len() as u32; let n_values = values.len() as u32;
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_control_binding_get_g_value_array( ffi::gst_control_binding_get_g_value_array(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
timestamp.to_glib(), timestamp.to_glib(),
interval.to_glib(), interval.to_glib(),
n_values, n_values,
values.as_mut_ptr() as *mut gobject_sys::GValue, values.as_mut_ptr() as *mut glib::gobject_ffi::GValue,
), ),
"Failed to get value array" "Failed to get value array"
) )

View file

@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::ClockTime;
use crate::ControlSource;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use ClockTime;
use ControlSource;
pub trait ControlSourceExtManual: 'static { pub trait ControlSourceExtManual: 'static {
fn get_value_array( fn get_value_array(
@ -30,8 +29,8 @@ impl<O: IsA<ControlSource>> ControlSourceExtManual for O {
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let n_values = values.len() as u32; let n_values = values.len() as u32;
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_control_source_get_value_array( ffi::gst_control_source_get_value_array(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
timestamp.to_glib(), timestamp.to_glib(),
interval.to_glib(), interval.to_glib(),

View file

@ -10,7 +10,7 @@ use std::cmp;
use std::convert; use std::convert;
use std::fmt; use std::fmt;
use DateTime; use crate::DateTime;
impl DateTime { impl DateTime {
pub fn to_utc(&self) -> Result<DateTime, glib::BoolError> { pub fn to_utc(&self) -> Result<DateTime, glib::BoolError> {
@ -28,7 +28,7 @@ impl DateTime {
self.to_g_date_time() self.to_g_date_time()
.and_then(|d| { .and_then(|d| {
d.to_utc() d.to_utc()
.ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) .ok_or_else(|| glib::glib_bool_error!("Can't convert datetime to UTC"))
}) })
.and_then(|d| DateTime::from_g_date_time(&d)) .and_then(|d| DateTime::from_g_date_time(&d))
} else { } else {
@ -48,7 +48,7 @@ impl DateTime {
.and_then(|d| d.to_g_date_time()) .and_then(|d| d.to_g_date_time())
.and_then(|d| { .and_then(|d| {
d.to_utc() d.to_utc()
.ok_or_else(|| glib_bool_error!("Can't convert datetime to UTC")) .ok_or_else(|| glib::glib_bool_error!("Can't convert datetime to UTC"))
}) })
.and_then(|d| { .and_then(|d| {
DateTime::new( DateTime::new(
@ -273,7 +273,7 @@ mod tests {
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
#[test] #[test]
fn test_to_utc() { fn test_to_utc() {
::init().unwrap(); crate::init().unwrap();
// Hour offset // Hour offset
let utc_date_time = DateTime::new(2f32, 2019, 8, 20, 20, 9, 42.123_456f64) let utc_date_time = DateTime::new(2f32, 2019, 8, 20, 20, 9, 42.123_456f64)
@ -324,7 +324,7 @@ mod tests {
#[test] #[test]
fn test_partial_ord() { fn test_partial_ord() {
::init().unwrap(); crate::init().unwrap();
// Different years // Different years
assert!( assert!(
@ -429,7 +429,7 @@ mod tests {
#[test] #[test]
fn test_eq() { fn test_eq() {
::init().unwrap(); crate::init().unwrap();
assert_eq!( assert_eq!(
DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap(), DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap(),

View file

@ -12,12 +12,12 @@ use glib::translate::{FromGlib, ToGlib};
use glib::value::{SetValue, SetValueOptional}; use glib::value::{SetValue, SetValueOptional};
use glib::StaticType; use glib::StaticType;
use crate::DateTime;
use serde::de::{Deserialize, Deserializer, Error}; use serde::de::{Deserialize, Deserializer, Error};
use serde::ser; use serde::ser;
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use DateTime;
#[derive(Serialize, Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
enum DateTimeVariants { enum DateTimeVariants {
Y(i32), Y(i32),
YM(i32, i32), YM(i32, i32),
@ -115,18 +115,18 @@ impl TryFrom<DateTimeVariants> for Date {
DateTimeVariants::YMD(y, m, d) => { DateTimeVariants::YMD(y, m, d) => {
let month = glib::DateMonth::from_glib(m); let month = glib::DateMonth::from_glib(m);
if let glib::DateMonth::__Unknown(_) = month { if let glib::DateMonth::__Unknown(_) = month {
return Err(glib_bool_error!("Out of range `month` for `Date`")); return Err(glib::glib_bool_error!("Out of range `month` for `Date`"));
} }
Ok(Date(glib::Date::new_dmy( Ok(Date(glib::Date::new_dmy(
d.try_into() d.try_into()
.map_err(|_| glib_bool_error!("Out of range `day` for `Date`"))?, .map_err(|_| glib::glib_bool_error!("Out of range `day` for `Date`"))?,
month, month,
y.try_into() y.try_into()
.map_err(|_| glib_bool_error!("Out of range `year` for `Date`"))?, .map_err(|_| glib::glib_bool_error!("Out of range `year` for `Date`"))?,
))) )))
} }
_ => Err(glib_bool_error!( _ => Err(glib::glib_bool_error!(
"Incompatible variant for `Date` (expecting \"YMD\")" "Incompatible variant for `Date` (expecting \"YMD\")"
)), )),
} }
@ -171,14 +171,11 @@ impl<'de> Deserialize<'de> for DateTime {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::DateTime;
extern crate serde_json;
use DateTime;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default(); let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string(); pretty_config.new_line = "".to_string();
@ -215,7 +212,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
let datetime_ron = "YMDhmsTz(2018, 5, 28, 16, 6, 42.123456, 2)"; let datetime_ron = "YMDhmsTz(2018, 5, 28, 16, 6, 42.123456, 2)";
let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap(); let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap();
@ -253,7 +250,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap(); let datetime = DateTime::new(2f32, 2018, 5, 28, 16, 6, 42.123_456f64).unwrap();
let datetime_ser = ron::ser::to_string(&datetime).unwrap(); let datetime_ser = ron::ser::to_string(&datetime).unwrap();

View file

@ -6,26 +6,23 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use Caps; use crate::Caps;
use DeviceMonitor; use crate::DeviceMonitor;
use glib;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use std::num::NonZeroU32; use std::num::NonZeroU32;
impl DeviceMonitor { impl DeviceMonitor {
pub fn new() -> DeviceMonitor { pub fn new() -> DeviceMonitor {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let (major, minor, _, _) = ::version(); let (major, minor, _, _) = crate::version();
if (major, minor) > (1, 12) { if (major, minor) > (1, 12) {
unsafe { from_glib_full(gst_sys::gst_device_monitor_new()) } unsafe { from_glib_full(ffi::gst_device_monitor_new()) }
} else { } else {
// Work-around for 1.14 switching from transfer-floating to transfer-full // Work-around for 1.14 switching from transfer-floating to transfer-full
unsafe { from_glib_none(gst_sys::gst_device_monitor_new()) } unsafe { from_glib_none(ffi::gst_device_monitor_new()) }
} }
} }
} }
@ -73,7 +70,7 @@ impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {
caps: Option<&Caps>, caps: Option<&Caps>,
) -> Option<DeviceMonitorFilterId> { ) -> Option<DeviceMonitorFilterId> {
let id = unsafe { let id = unsafe {
gst_sys::gst_device_monitor_add_filter( ffi::gst_device_monitor_add_filter(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
classes.to_glib_none().0, classes.to_glib_none().0,
caps.to_glib_none().0, caps.to_glib_none().0,
@ -92,8 +89,8 @@ impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {
filter_id: DeviceMonitorFilterId, filter_id: DeviceMonitorFilterId,
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_device_monitor_remove_filter( ffi::gst_device_monitor_remove_filter(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
filter_id.to_glib() filter_id.to_glib()
), ),

View file

@ -6,9 +6,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use DeviceProvider; use crate::DeviceProvider;
use Plugin; use crate::Plugin;
use Rank; use crate::Rank;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::ToGlib; use glib::translate::ToGlib;
@ -16,9 +16,6 @@ use glib::translate::ToGlibPtr;
use std::ffi::CStr; use std::ffi::CStr;
use gobject_sys;
use gst_sys;
impl DeviceProvider { impl DeviceProvider {
pub fn register( pub fn register(
plugin: Option<&Plugin>, plugin: Option<&Plugin>,
@ -28,8 +25,8 @@ impl DeviceProvider {
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_device_provider_register( ffi::gst_device_provider_register(
plugin.to_glib_none().0, plugin.to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
rank.to_glib() as u32, rank.to_glib() as u32,
@ -48,10 +45,10 @@ pub trait DeviceProviderExtManual: 'static {
impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O { impl<O: IsA<DeviceProvider>> DeviceProviderExtManual for O {
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> { fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
unsafe { unsafe {
let klass = (*(self.as_ptr() as *mut gobject_sys::GTypeInstance)).g_class let klass = (*(self.as_ptr() as *mut glib::gobject_ffi::GTypeInstance)).g_class
as *mut gst_sys::GstDeviceProviderClass; as *mut ffi::GstDeviceProviderClass;
let ptr = gst_sys::gst_device_provider_class_get_metadata(klass, key.to_glib_none().0); let ptr = ffi::gst_device_provider_class_get_metadata(klass, key.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
None None

View file

@ -6,11 +6,27 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use Element; use crate::Element;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use glib; use crate::ClockTime;
use crate::ElementFlags;
use crate::Event;
use crate::Format;
use crate::FormattedValue;
use crate::GenericFormattedValue;
use crate::Pad;
use crate::PadTemplate;
use crate::Plugin;
use crate::QueryRef;
use crate::Rank;
use crate::SpecificFormattedValue;
use crate::State;
use crate::StateChange;
use crate::StateChangeError;
use crate::StateChangeReturn;
use crate::StateChangeSuccess;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
use glib::object::Cast; use glib::object::Cast;
@ -21,23 +37,6 @@ use glib::translate::FromGlibPtrBorrow;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrContainer, ToGlib, ToGlibPtr, from_glib, from_glib_full, from_glib_none, FromGlib, FromGlibPtrContainer, ToGlib, ToGlibPtr,
}; };
use ClockTime;
use ElementFlags;
use Event;
use Format;
use FormattedValue;
use GenericFormattedValue;
use Pad;
use PadTemplate;
use Plugin;
use QueryRef;
use Rank;
use SpecificFormattedValue;
use State;
use StateChange;
use StateChangeError;
use StateChangeReturn;
use StateChangeSuccess;
use std::ffi::CStr; use std::ffi::CStr;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
@ -52,21 +51,13 @@ use std::num::NonZeroU64;
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
use std::pin::Pin; use std::pin::Pin;
use libc;
#[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
use glib_sys;
use gobject_sys;
use gst_sys;
impl Element { impl Element {
pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> { pub fn link_many<E: IsA<Element>>(elements: &[&E]) -> Result<(), glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
for e in elements.windows(2) { for e in elements.windows(2) {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_element_link( ffi::gst_element_link(
e[0].as_ref().to_glib_none().0, e[0].as_ref().to_glib_none().0,
e[1].as_ref().to_glib_none().0, e[1].as_ref().to_glib_none().0,
), ),
@ -82,7 +73,7 @@ impl Element {
skip_assert_initialized!(); skip_assert_initialized!();
for e in elements.windows(2) { for e in elements.windows(2) {
unsafe { unsafe {
gst_sys::gst_element_unlink( ffi::gst_element_unlink(
e[0].as_ref().to_glib_none().0, e[0].as_ref().to_glib_none().0,
e[1].as_ref().to_glib_none().0, e[1].as_ref().to_glib_none().0,
); );
@ -98,8 +89,8 @@ impl Element {
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_element_register( ffi::gst_element_register(
plugin.to_glib_none().0, plugin.to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
rank.to_glib() as u32, rank.to_glib() as u32,
@ -163,7 +154,7 @@ pub trait ElementExtManual: 'static {
fn get_pad_template_list(&self) -> Vec<PadTemplate>; fn get_pad_template_list(&self) -> Vec<PadTemplate>;
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn message_full<T: ::MessageErrorDomain>( fn message_full<T: crate::MessageErrorDomain>(
&self, &self,
type_: ElementMessageType, type_: ElementMessageType,
code: T, code: T,
@ -183,7 +174,7 @@ pub trait ElementExtManual: 'static {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn message_full_with_details<T: ::MessageErrorDomain>( fn message_full_with_details<T: crate::MessageErrorDomain>(
&self, &self,
type_: ElementMessageType, type_: ElementMessageType,
code: T, code: T,
@ -192,15 +183,15 @@ pub trait ElementExtManual: 'static {
file: &str, file: &str,
function: &str, function: &str,
line: u32, line: u32,
structure: ::Structure, structure: crate::Structure,
); );
fn post_message(&self, message: ::Message) -> Result<(), glib::error::BoolError>; fn post_message(&self, message: crate::Message) -> Result<(), glib::error::BoolError>;
fn post_error_message(&self, msg: ::ErrorMessage); fn post_error_message(&self, msg: crate::ErrorMessage);
fn iterate_pads(&self) -> ::Iterator<Pad>; fn iterate_pads(&self) -> crate::Iterator<Pad>;
fn iterate_sink_pads(&self) -> ::Iterator<Pad>; fn iterate_sink_pads(&self) -> crate::Iterator<Pad>;
fn iterate_src_pads(&self) -> ::Iterator<Pad>; fn iterate_src_pads(&self) -> crate::Iterator<Pad>;
fn get_pads(&self) -> Vec<Pad>; fn get_pads(&self) -> Vec<Pad>;
fn get_sink_pads(&self) -> Vec<Pad>; fn get_sink_pads(&self) -> Vec<Pad>;
@ -249,15 +240,15 @@ pub trait ElementExtManual: 'static {
fn seek<V: Into<GenericFormattedValue>>( fn seek<V: Into<GenericFormattedValue>>(
&self, &self,
rate: f64, rate: f64,
flags: ::SeekFlags, flags: crate::SeekFlags,
start_type: ::SeekType, start_type: crate::SeekType,
start: V, start: V,
stop_type: ::SeekType, stop_type: crate::SeekType,
stop: V, stop: V,
) -> Result<(), glib::error::BoolError>; ) -> Result<(), glib::error::BoolError>;
fn seek_simple<V: Into<GenericFormattedValue>>( fn seek_simple<V: Into<GenericFormattedValue>>(
&self, &self,
seek_flags: ::SeekFlags, seek_flags: crate::SeekFlags,
seek_pos: V, seek_pos: V,
) -> Result<(), glib::error::BoolError>; ) -> Result<(), glib::error::BoolError>;
@ -277,14 +268,14 @@ pub trait ElementExtManual: 'static {
F: FnOnce(&Self) -> T + Send + 'static, F: FnOnce(&Self) -> T + Send + 'static,
T: Send + 'static; T: Send + 'static;
fn get_current_running_time(&self) -> ::ClockTime; fn get_current_running_time(&self) -> crate::ClockTime;
fn get_current_clock_time(&self) -> ::ClockTime; fn get_current_clock_time(&self) -> crate::ClockTime;
} }
impl<O: IsA<Element>> ElementExtManual for O { impl<O: IsA<Element>> ElementExtManual for O {
fn get_element_class(&self) -> &glib::Class<Element> { fn get_element_class(&self) -> &glib::Class<Element> {
unsafe { unsafe {
let klass = (*(self.as_ptr() as *mut gobject_sys::GTypeInstance)).g_class let klass = (*(self.as_ptr() as *mut glib::gobject_ffi::GTypeInstance)).g_class
as *const glib::Class<Element>; as *const glib::Class<Element>;
&*klass &*klass
} }
@ -295,7 +286,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
transition: StateChange, transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> { ) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe { let ret: StateChangeReturn = unsafe {
from_glib(gst_sys::gst_element_change_state( from_glib(ffi::gst_element_change_state(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
transition.to_glib(), transition.to_glib(),
)) ))
@ -308,7 +299,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
ret: StateChangeReturn, ret: StateChangeReturn,
) -> Result<StateChangeSuccess, StateChangeError> { ) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe { let ret: StateChangeReturn = unsafe {
from_glib(gst_sys::gst_element_continue_state( from_glib(ffi::gst_element_continue_state(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
ret.to_glib(), ret.to_glib(),
)) ))
@ -323,7 +314,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
unsafe { unsafe {
let mut state = mem::MaybeUninit::uninit(); let mut state = mem::MaybeUninit::uninit();
let mut pending = mem::MaybeUninit::uninit(); let mut pending = mem::MaybeUninit::uninit();
let ret: StateChangeReturn = from_glib(gst_sys::gst_element_get_state( let ret: StateChangeReturn = from_glib(ffi::gst_element_get_state(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
state.as_mut_ptr(), state.as_mut_ptr(),
pending.as_mut_ptr(), pending.as_mut_ptr(),
@ -339,7 +330,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> { fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe { let ret: StateChangeReturn = unsafe {
from_glib(gst_sys::gst_element_set_state( from_glib(ffi::gst_element_set_state(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
state.to_glib(), state.to_glib(),
)) ))
@ -349,7 +340,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn query(&self, query: &mut QueryRef) -> bool { fn query(&self, query: &mut QueryRef) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_element_query( from_glib(ffi::gst_element_query(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
query.as_mut_ptr(), query.as_mut_ptr(),
)) ))
@ -358,7 +349,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn send_event(&self, event: Event) -> bool { fn send_event(&self, event: Event) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_element_send_event( from_glib(ffi::gst_element_send_event(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
event.into_ptr(), event.into_ptr(),
)) ))
@ -379,29 +370,29 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn set_element_flags(&self, flags: ElementFlags) { fn set_element_flags(&self, flags: ElementFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib(); (*ptr).flags |= flags.to_glib();
} }
} }
fn unset_element_flags(&self, flags: ElementFlags) { fn unset_element_flags(&self, flags: ElementFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib(); (*ptr).flags &= !flags.to_glib();
} }
} }
fn get_element_flags(&self) -> ElementFlags { fn get_element_flags(&self) -> ElementFlags {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags) from_glib((*ptr).flags)
} }
} }
fn message_full<T: ::MessageErrorDomain>( fn message_full<T: crate::MessageErrorDomain>(
&self, &self,
type_: ElementMessageType, type_: ElementMessageType,
code: T, code: T,
@ -413,12 +404,12 @@ impl<O: IsA<Element>> ElementExtManual for O {
) { ) {
unsafe { unsafe {
let type_ = match type_ { let type_ = match type_ {
ElementMessageType::Error => gst_sys::GST_MESSAGE_ERROR, ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
ElementMessageType::Warning => gst_sys::GST_MESSAGE_WARNING, ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
ElementMessageType::Info => gst_sys::GST_MESSAGE_INFO, ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
}; };
gst_sys::gst_element_message_full( ffi::gst_element_message_full(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
type_, type_,
T::domain().to_glib(), T::domain().to_glib(),
@ -434,7 +425,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
fn message_full_with_details<T: ::MessageErrorDomain>( fn message_full_with_details<T: crate::MessageErrorDomain>(
&self, &self,
type_: ElementMessageType, type_: ElementMessageType,
code: T, code: T,
@ -443,16 +434,16 @@ impl<O: IsA<Element>> ElementExtManual for O {
file: &str, file: &str,
function: &str, function: &str,
line: u32, line: u32,
structure: ::Structure, structure: crate::Structure,
) { ) {
unsafe { unsafe {
let type_ = match type_ { let type_ = match type_ {
ElementMessageType::Error => gst_sys::GST_MESSAGE_ERROR, ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
ElementMessageType::Warning => gst_sys::GST_MESSAGE_WARNING, ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
ElementMessageType::Info => gst_sys::GST_MESSAGE_INFO, ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
}; };
gst_sys::gst_element_message_full_with_details( ffi::gst_element_message_full_with_details(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
type_, type_,
T::domain().to_glib(), T::domain().to_glib(),
@ -467,20 +458,17 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn post_message(&self, message: ::Message) -> Result<(), glib::error::BoolError> { fn post_message(&self, message: crate::Message) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_element_post_message( ffi::gst_element_post_message(self.as_ref().to_glib_none().0, message.into_ptr()),
self.as_ref().to_glib_none().0,
message.into_ptr()
),
"Failed to post message" "Failed to post message"
) )
} }
} }
fn post_error_message(&self, msg: ::ErrorMessage) { fn post_error_message(&self, msg: crate::ErrorMessage) {
let ::ErrorMessage { let crate::ErrorMessage {
error_domain, error_domain,
error_code, error_code,
ref message, ref message,
@ -491,9 +479,9 @@ impl<O: IsA<Element>> ElementExtManual for O {
} = msg; } = msg;
unsafe { unsafe {
gst_sys::gst_element_message_full( ffi::gst_element_message_full(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
gst_sys::GST_MESSAGE_ERROR, ffi::GST_MESSAGE_ERROR,
error_domain.to_glib(), error_domain.to_glib(),
error_code, error_code,
message.to_glib_full(), message.to_glib_full(),
@ -505,25 +493,25 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn iterate_pads(&self) -> ::Iterator<Pad> { fn iterate_pads(&self) -> crate::Iterator<Pad> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_element_iterate_pads( from_glib_full(ffi::gst_element_iterate_pads(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
)) ))
} }
} }
fn iterate_sink_pads(&self) -> ::Iterator<Pad> { fn iterate_sink_pads(&self) -> crate::Iterator<Pad> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_element_iterate_sink_pads( from_glib_full(ffi::gst_element_iterate_sink_pads(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
)) ))
} }
} }
fn iterate_src_pads(&self) -> ::Iterator<Pad> { fn iterate_src_pads(&self) -> crate::Iterator<Pad> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_element_iterate_src_pads( from_glib_full(ffi::gst_element_iterate_src_pads(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
)) ))
} }
@ -531,48 +519,48 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn get_pads(&self) -> Vec<Pad> { fn get_pads(&self) -> Vec<Pad> {
unsafe { unsafe {
let elt: &gst_sys::GstElement = &*(self.as_ptr() as *const _); let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&elt.object.lock); let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
FromGlibPtrContainer::from_glib_none(elt.pads) FromGlibPtrContainer::from_glib_none(elt.pads)
} }
} }
fn get_sink_pads(&self) -> Vec<Pad> { fn get_sink_pads(&self) -> Vec<Pad> {
unsafe { unsafe {
let elt: &gst_sys::GstElement = &*(self.as_ptr() as *const _); let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&elt.object.lock); let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
FromGlibPtrContainer::from_glib_none(elt.sinkpads) FromGlibPtrContainer::from_glib_none(elt.sinkpads)
} }
} }
fn get_src_pads(&self) -> Vec<Pad> { fn get_src_pads(&self) -> Vec<Pad> {
unsafe { unsafe {
let elt: &gst_sys::GstElement = &*(self.as_ptr() as *const _); let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&elt.object.lock); let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
FromGlibPtrContainer::from_glib_none(elt.srcpads) FromGlibPtrContainer::from_glib_none(elt.srcpads)
} }
} }
fn num_pads(&self) -> u16 { fn num_pads(&self) -> u16 {
unsafe { unsafe {
let elt: &gst_sys::GstElement = &*(self.as_ptr() as *const _); let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&elt.object.lock); let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
elt.numpads elt.numpads
} }
} }
fn num_sink_pads(&self) -> u16 { fn num_sink_pads(&self) -> u16 {
unsafe { unsafe {
let elt: &gst_sys::GstElement = &*(self.as_ptr() as *const _); let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&elt.object.lock); let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
elt.numsinkpads elt.numsinkpads
} }
} }
fn num_src_pads(&self) -> u16 { fn num_src_pads(&self) -> u16 {
unsafe { unsafe {
let elt: &gst_sys::GstElement = &*(self.as_ptr() as *const _); let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = ::utils::MutexGuard::lock(&elt.object.lock); let _guard = crate::utils::MutexGuard::lock(&elt.object.lock);
elt.numsrcpads elt.numsrcpads
} }
} }
@ -586,7 +574,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
) -> NotifyWatchId { ) -> NotifyWatchId {
let property_name = property_name.to_glib_none(); let property_name = property_name.to_glib_none();
unsafe { unsafe {
from_glib(gst_sys::gst_element_add_property_deep_notify_watch( from_glib(ffi::gst_element_add_property_deep_notify_watch(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
property_name.0, property_name.0,
include_value.to_glib(), include_value.to_glib(),
@ -603,7 +591,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
) -> NotifyWatchId { ) -> NotifyWatchId {
let property_name = property_name.to_glib_none(); let property_name = property_name.to_glib_none();
unsafe { unsafe {
from_glib(gst_sys::gst_element_add_property_notify_watch( from_glib(ffi::gst_element_add_property_notify_watch(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
property_name.0, property_name.0,
include_value.to_glib(), include_value.to_glib(),
@ -615,7 +603,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
fn remove_property_notify_watch(&self, watch_id: NotifyWatchId) { fn remove_property_notify_watch(&self, watch_id: NotifyWatchId) {
unsafe { unsafe {
gst_sys::gst_element_remove_property_notify_watch( ffi::gst_element_remove_property_notify_watch(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
watch_id.to_glib(), watch_id.to_glib(),
); );
@ -629,7 +617,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
let src_val = src_val.into(); let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_element_query_convert( let ret = from_glib(ffi::gst_element_query_convert(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
src_val.get_format().to_glib(), src_val.get_format().to_glib(),
src_val.to_raw_value(), src_val.to_raw_value(),
@ -652,7 +640,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
let src_val = src_val.into(); let src_val = src_val.into();
unsafe { unsafe {
let mut dest_val = mem::MaybeUninit::uninit(); let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_element_query_convert( let ret = from_glib(ffi::gst_element_query_convert(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
src_val.get_format().to_glib(), src_val.get_format().to_glib(),
src_val.get_value(), src_val.get_value(),
@ -673,7 +661,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn query_duration<T: SpecificFormattedValue>(&self) -> Option<T> { fn query_duration<T: SpecificFormattedValue>(&self) -> Option<T> {
unsafe { unsafe {
let mut duration = mem::MaybeUninit::uninit(); let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_element_query_duration( let ret = from_glib(ffi::gst_element_query_duration(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::get_default_format().to_glib(), T::get_default_format().to_glib(),
duration.as_mut_ptr(), duration.as_mut_ptr(),
@ -689,7 +677,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue> { fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue> {
unsafe { unsafe {
let mut duration = mem::MaybeUninit::uninit(); let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_element_query_duration( let ret = from_glib(ffi::gst_element_query_duration(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
format.to_glib(), format.to_glib(),
duration.as_mut_ptr(), duration.as_mut_ptr(),
@ -705,7 +693,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn query_position<T: SpecificFormattedValue>(&self) -> Option<T> { fn query_position<T: SpecificFormattedValue>(&self) -> Option<T> {
unsafe { unsafe {
let mut cur = mem::MaybeUninit::uninit(); let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_element_query_position( let ret = from_glib(ffi::gst_element_query_position(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
T::get_default_format().to_glib(), T::get_default_format().to_glib(),
cur.as_mut_ptr(), cur.as_mut_ptr(),
@ -721,7 +709,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue> { fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue> {
unsafe { unsafe {
let mut cur = mem::MaybeUninit::uninit(); let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_element_query_position( let ret = from_glib(ffi::gst_element_query_position(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
format.to_glib(), format.to_glib(),
cur.as_mut_ptr(), cur.as_mut_ptr(),
@ -737,10 +725,10 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn seek<V: Into<GenericFormattedValue>>( fn seek<V: Into<GenericFormattedValue>>(
&self, &self,
rate: f64, rate: f64,
flags: ::SeekFlags, flags: crate::SeekFlags,
start_type: ::SeekType, start_type: crate::SeekType,
start: V, start: V,
stop_type: ::SeekType, stop_type: crate::SeekType,
stop: V, stop: V,
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let start = start.into(); let start = start.into();
@ -749,8 +737,8 @@ impl<O: IsA<Element>> ElementExtManual for O {
assert_eq!(stop.get_format(), start.get_format()); assert_eq!(stop.get_format(), start.get_format());
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_element_seek( ffi::gst_element_seek(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
rate, rate,
start.get_format().to_glib(), start.get_format().to_glib(),
@ -767,13 +755,13 @@ impl<O: IsA<Element>> ElementExtManual for O {
fn seek_simple<V: Into<GenericFormattedValue>>( fn seek_simple<V: Into<GenericFormattedValue>>(
&self, &self,
seek_flags: ::SeekFlags, seek_flags: crate::SeekFlags,
seek_pos: V, seek_pos: V,
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let seek_pos = seek_pos.into(); let seek_pos = seek_pos.into();
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_element_seek_simple( ffi::gst_element_seek_simple(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
seek_pos.get_format().to_glib(), seek_pos.get_format().to_glib(),
seek_flags.to_glib(), seek_flags.to_glib(),
@ -793,8 +781,8 @@ impl<O: IsA<Element>> ElementExtManual for O {
let user_data: Box<Option<F>> = Box::new(Some(func)); let user_data: Box<Option<F>> = Box::new(Some(func));
unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>( unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
element: *mut gst_sys::GstElement, element: *mut ffi::GstElement,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) { ) {
let user_data: &mut Option<F> = &mut *(user_data as *mut _); let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap(); let callback = user_data.take().unwrap();
@ -803,13 +791,13 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>( unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) { ) {
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _); let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
} }
unsafe { unsafe {
gst_sys::gst_element_call_async( ffi::gst_element_call_async(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
Some(trampoline::<Self, F>), Some(trampoline::<Self, F>),
Box::into_raw(user_data) as *mut _, Box::into_raw(user_data) as *mut _,
@ -840,8 +828,8 @@ impl<O: IsA<Element>> ElementExtManual for O {
Box::pin(receiver.map(|res| res.expect("sender dropped"))) Box::pin(receiver.map(|res| res.expect("sender dropped")))
} }
fn get_current_running_time(&self) -> ::ClockTime { fn get_current_running_time(&self) -> crate::ClockTime {
use ElementExt; use crate::ElementExt;
let base_time = self.get_base_time(); let base_time = self.get_base_time();
let clock_time = self.get_current_clock_time(); let clock_time = self.get_current_clock_time();
@ -849,14 +837,14 @@ impl<O: IsA<Element>> ElementExtManual for O {
clock_time - base_time clock_time - base_time
} }
fn get_current_clock_time(&self) -> ::ClockTime { fn get_current_clock_time(&self) -> crate::ClockTime {
use ClockExt; use crate::ClockExt;
use ElementExt; use crate::ElementExt;
if let Some(clock) = self.get_clock() { if let Some(clock) = self.get_clock() {
clock.get_time() clock.get_time()
} else { } else {
::CLOCK_TIME_NONE crate::CLOCK_TIME_NONE
} }
} }
} }
@ -864,10 +852,9 @@ impl<O: IsA<Element>> ElementExtManual for O {
pub unsafe trait ElementClassExt { pub unsafe trait ElementClassExt {
fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> { fn get_metadata<'a>(&self, key: &str) -> Option<&'a str> {
unsafe { unsafe {
let klass = self as *const _ as *const gst_sys::GstElementClass; let klass = self as *const _ as *const ffi::GstElementClass;
let ptr = let ptr = ffi::gst_element_class_get_metadata(klass as *mut _, key.to_glib_none().0);
gst_sys::gst_element_class_get_metadata(klass as *mut _, key.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
None None
@ -879,9 +866,9 @@ pub unsafe trait ElementClassExt {
fn get_pad_template(&self, name: &str) -> Option<PadTemplate> { fn get_pad_template(&self, name: &str) -> Option<PadTemplate> {
unsafe { unsafe {
let klass = self as *const _ as *const gst_sys::GstElementClass; let klass = self as *const _ as *const ffi::GstElementClass;
from_glib_none(gst_sys::gst_element_class_get_pad_template( from_glib_none(ffi::gst_element_class_get_pad_template(
klass as *mut _, klass as *mut _,
name.to_glib_none().0, name.to_glib_none().0,
)) ))
@ -890,9 +877,9 @@ pub unsafe trait ElementClassExt {
fn get_pad_template_list(&self) -> Vec<PadTemplate> { fn get_pad_template_list(&self) -> Vec<PadTemplate> {
unsafe { unsafe {
let klass = self as *const _ as *const gst_sys::GstElementClass; let klass = self as *const _ as *const ffi::GstElementClass;
FromGlibPtrContainer::from_glib_none(gst_sys::gst_element_class_get_pad_template_list( FromGlibPtrContainer::from_glib_none(ffi::gst_element_class_get_pad_template_list(
klass as *mut _, klass as *mut _,
)) ))
} }
@ -902,32 +889,32 @@ pub unsafe trait ElementClassExt {
unsafe impl<T: IsA<Element>> ElementClassExt for glib::object::Class<T> {} unsafe impl<T: IsA<Element>> ElementClassExt for glib::object::Class<T> {}
pub static ELEMENT_METADATA_AUTHOR: Lazy<&'static str> = Lazy::new(|| unsafe { pub static ELEMENT_METADATA_AUTHOR: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_AUTHOR) CStr::from_ptr(ffi::GST_ELEMENT_METADATA_AUTHOR)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
pub static ELEMENT_METADATA_DESCRIPTION: Lazy<&'static str> = Lazy::new(|| unsafe { pub static ELEMENT_METADATA_DESCRIPTION: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_DESCRIPTION) CStr::from_ptr(ffi::GST_ELEMENT_METADATA_DESCRIPTION)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
pub static ELEMENT_METADATA_DOC_URI: Lazy<&'static str> = Lazy::new(|| unsafe { pub static ELEMENT_METADATA_DOC_URI: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_DOC_URI) CStr::from_ptr(ffi::GST_ELEMENT_METADATA_DOC_URI)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
pub static ELEMENT_METADATA_ICON_NAME: Lazy<&'static str> = Lazy::new(|| unsafe { pub static ELEMENT_METADATA_ICON_NAME: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_ICON_NAME) CStr::from_ptr(ffi::GST_ELEMENT_METADATA_ICON_NAME)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
pub static ELEMENT_METADATA_KLASS: Lazy<&'static str> = Lazy::new(|| unsafe { pub static ELEMENT_METADATA_KLASS: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_KLASS) CStr::from_ptr(ffi::GST_ELEMENT_METADATA_KLASS)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
pub static ELEMENT_METADATA_LONGNAME: Lazy<&'static str> = Lazy::new(|| unsafe { pub static ELEMENT_METADATA_LONGNAME: Lazy<&'static str> = Lazy::new(|| unsafe {
CStr::from_ptr(gst_sys::GST_ELEMENT_METADATA_LONGNAME) CStr::from_ptr(ffi::GST_ELEMENT_METADATA_LONGNAME)
.to_str() .to_str()
.unwrap() .unwrap()
}); });
@ -1400,16 +1387,16 @@ macro_rules! gst_element_info(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::prelude::*;
use glib::GString; use glib::GString;
use prelude::*;
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
#[test] #[test]
fn test_get_pads() { fn test_get_pads() {
::init().unwrap(); crate::init().unwrap();
let identity = ::ElementFactory::make("identity", None).unwrap(); let identity = crate::ElementFactory::make("identity", None).unwrap();
let mut pad_names = identity let mut pad_names = identity
.get_pads() .get_pads()
@ -1439,9 +1426,9 @@ mod tests {
#[test] #[test]
#[cfg(feature = "v1_14")] #[cfg(feature = "v1_14")]
fn test_foreach_pad() { fn test_foreach_pad() {
::init().unwrap(); crate::init().unwrap();
let identity = ::ElementFactory::make("identity", None).unwrap(); let identity = crate::ElementFactory::make("identity", None).unwrap();
let mut pad_names = Vec::new(); let mut pad_names = Vec::new();
identity.foreach_pad(|_element, pad| { identity.foreach_pad(|_element, pad| {
@ -1456,9 +1443,9 @@ mod tests {
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
#[test] #[test]
fn test_call_async() { fn test_call_async() {
::init().unwrap(); crate::init().unwrap();
let identity = ::ElementFactory::make("identity", None).unwrap(); let identity = crate::ElementFactory::make("identity", None).unwrap();
let (sender, receiver) = channel(); let (sender, receiver) = channel();
identity.call_async(move |_| { identity.call_async(move |_| {

View file

@ -6,14 +6,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::ClockReturn;
use crate::FlowReturn;
use crate::PadLinkReturn;
use crate::State;
use crate::StateChange;
use crate::StateChangeReturn;
use std::{cmp, ops}; use std::{cmp, ops};
use thiserror::Error; use thiserror::Error;
use ClockReturn;
use FlowReturn;
use PadLinkReturn;
use State;
use StateChange;
use StateChangeReturn;
use glib::translate::*; use glib::translate::*;
use glib::value::FromValue; use glib::value::FromValue;
@ -352,104 +352,104 @@ impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
} }
} }
impl PartialEq for ::TypeFindProbability { impl PartialEq for crate::TypeFindProbability {
fn eq(&self, other: &::TypeFindProbability) -> bool { fn eq(&self, other: &crate::TypeFindProbability) -> bool {
(self.to_glib() as u32).eq(&(other.to_glib() as u32)) (self.to_glib() as u32).eq(&(other.to_glib() as u32))
} }
} }
impl Eq for ::TypeFindProbability {} impl Eq for crate::TypeFindProbability {}
impl PartialOrd for ::TypeFindProbability { impl PartialOrd for crate::TypeFindProbability {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
(self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32)) (self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32))
} }
} }
impl Ord for ::TypeFindProbability { impl Ord for crate::TypeFindProbability {
fn cmp(&self, other: &Self) -> cmp::Ordering { fn cmp(&self, other: &Self) -> cmp::Ordering {
(self.to_glib() as u32).cmp(&(other.to_glib() as u32)) (self.to_glib() as u32).cmp(&(other.to_glib() as u32))
} }
} }
impl ops::Add<u32> for ::TypeFindProbability { impl ops::Add<u32> for crate::TypeFindProbability {
type Output = ::TypeFindProbability; type Output = crate::TypeFindProbability;
fn add(self, rhs: u32) -> ::TypeFindProbability { fn add(self, rhs: u32) -> crate::TypeFindProbability {
let res = (self.to_glib() as u32).saturating_add(rhs); let res = (self.to_glib() as u32).saturating_add(rhs);
from_glib(res as i32) from_glib(res as i32)
} }
} }
impl ops::AddAssign<u32> for ::TypeFindProbability { impl ops::AddAssign<u32> for crate::TypeFindProbability {
fn add_assign(&mut self, rhs: u32) { fn add_assign(&mut self, rhs: u32) {
let res = (self.to_glib() as u32).saturating_add(rhs); let res = (self.to_glib() as u32).saturating_add(rhs);
*self = from_glib(res as i32); *self = from_glib(res as i32);
} }
} }
impl ops::Sub<u32> for ::TypeFindProbability { impl ops::Sub<u32> for crate::TypeFindProbability {
type Output = ::TypeFindProbability; type Output = crate::TypeFindProbability;
fn sub(self, rhs: u32) -> ::TypeFindProbability { fn sub(self, rhs: u32) -> crate::TypeFindProbability {
let res = (self.to_glib() as u32).saturating_sub(rhs); let res = (self.to_glib() as u32).saturating_sub(rhs);
from_glib(res as i32) from_glib(res as i32)
} }
} }
impl ops::SubAssign<u32> for ::TypeFindProbability { impl ops::SubAssign<u32> for crate::TypeFindProbability {
fn sub_assign(&mut self, rhs: u32) { fn sub_assign(&mut self, rhs: u32) {
let res = (self.to_glib() as u32).saturating_sub(rhs); let res = (self.to_glib() as u32).saturating_sub(rhs);
*self = from_glib(res as i32); *self = from_glib(res as i32);
} }
} }
impl PartialEq for ::Rank { impl PartialEq for crate::Rank {
fn eq(&self, other: &::Rank) -> bool { fn eq(&self, other: &crate::Rank) -> bool {
(self.to_glib() as u32).eq(&(other.to_glib() as u32)) (self.to_glib() as u32).eq(&(other.to_glib() as u32))
} }
} }
impl Eq for ::Rank {} impl Eq for crate::Rank {}
impl PartialOrd for ::Rank { impl PartialOrd for crate::Rank {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
(self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32)) (self.to_glib() as u32).partial_cmp(&(other.to_glib() as u32))
} }
} }
impl Ord for ::Rank { impl Ord for crate::Rank {
fn cmp(&self, other: &Self) -> cmp::Ordering { fn cmp(&self, other: &Self) -> cmp::Ordering {
(self.to_glib() as u32).cmp(&(other.to_glib() as u32)) (self.to_glib() as u32).cmp(&(other.to_glib() as u32))
} }
} }
impl ops::Add<u32> for ::Rank { impl ops::Add<u32> for crate::Rank {
type Output = ::Rank; type Output = crate::Rank;
fn add(self, rhs: u32) -> ::Rank { fn add(self, rhs: u32) -> crate::Rank {
let res = (self.to_glib() as u32).saturating_add(rhs); let res = (self.to_glib() as u32).saturating_add(rhs);
from_glib(res as i32) from_glib(res as i32)
} }
} }
impl ops::AddAssign<u32> for ::Rank { impl ops::AddAssign<u32> for crate::Rank {
fn add_assign(&mut self, rhs: u32) { fn add_assign(&mut self, rhs: u32) {
let res = (self.to_glib() as u32).saturating_add(rhs); let res = (self.to_glib() as u32).saturating_add(rhs);
*self = from_glib(res as i32); *self = from_glib(res as i32);
} }
} }
impl ops::Sub<u32> for ::Rank { impl ops::Sub<u32> for crate::Rank {
type Output = ::Rank; type Output = crate::Rank;
fn sub(self, rhs: u32) -> ::Rank { fn sub(self, rhs: u32) -> crate::Rank {
let res = (self.to_glib() as u32).saturating_sub(rhs); let res = (self.to_glib() as u32).saturating_sub(rhs);
from_glib(res as i32) from_glib(res as i32)
} }
} }
impl ops::SubAssign<u32> for ::Rank { impl ops::SubAssign<u32> for crate::Rank {
fn sub_assign(&mut self, rhs: u32) { fn sub_assign(&mut self, rhs: u32) {
let res = (self.to_glib() as u32).saturating_sub(rhs); let res = (self.to_glib() as u32).saturating_sub(rhs);
*self = from_glib(res as i32); *self = from_glib(res as i32);
@ -512,58 +512,58 @@ pub enum MessageType {
#[doc(hidden)] #[doc(hidden)]
impl ToGlib for MessageType { impl ToGlib for MessageType {
type GlibType = gst_sys::GstMessageType; type GlibType = ffi::GstMessageType;
fn to_glib(&self) -> gst_sys::GstMessageType { fn to_glib(&self) -> ffi::GstMessageType {
match *self { match *self {
MessageType::Unknown => gst_sys::GST_MESSAGE_UNKNOWN, MessageType::Unknown => ffi::GST_MESSAGE_UNKNOWN,
MessageType::Eos => gst_sys::GST_MESSAGE_EOS, MessageType::Eos => ffi::GST_MESSAGE_EOS,
MessageType::Error => gst_sys::GST_MESSAGE_ERROR, MessageType::Error => ffi::GST_MESSAGE_ERROR,
MessageType::Warning => gst_sys::GST_MESSAGE_WARNING, MessageType::Warning => ffi::GST_MESSAGE_WARNING,
MessageType::Info => gst_sys::GST_MESSAGE_INFO, MessageType::Info => ffi::GST_MESSAGE_INFO,
MessageType::Tag => gst_sys::GST_MESSAGE_TAG, MessageType::Tag => ffi::GST_MESSAGE_TAG,
MessageType::Buffering => gst_sys::GST_MESSAGE_BUFFERING, MessageType::Buffering => ffi::GST_MESSAGE_BUFFERING,
MessageType::StateChanged => gst_sys::GST_MESSAGE_STATE_CHANGED, MessageType::StateChanged => ffi::GST_MESSAGE_STATE_CHANGED,
MessageType::StateDirty => gst_sys::GST_MESSAGE_STATE_DIRTY, MessageType::StateDirty => ffi::GST_MESSAGE_STATE_DIRTY,
MessageType::StepDone => gst_sys::GST_MESSAGE_STEP_DONE, MessageType::StepDone => ffi::GST_MESSAGE_STEP_DONE,
MessageType::ClockProvide => gst_sys::GST_MESSAGE_CLOCK_PROVIDE, MessageType::ClockProvide => ffi::GST_MESSAGE_CLOCK_PROVIDE,
MessageType::ClockLost => gst_sys::GST_MESSAGE_CLOCK_LOST, MessageType::ClockLost => ffi::GST_MESSAGE_CLOCK_LOST,
MessageType::NewClock => gst_sys::GST_MESSAGE_NEW_CLOCK, MessageType::NewClock => ffi::GST_MESSAGE_NEW_CLOCK,
MessageType::StructureChange => gst_sys::GST_MESSAGE_STRUCTURE_CHANGE, MessageType::StructureChange => ffi::GST_MESSAGE_STRUCTURE_CHANGE,
MessageType::StreamStatus => gst_sys::GST_MESSAGE_STREAM_STATUS, MessageType::StreamStatus => ffi::GST_MESSAGE_STREAM_STATUS,
MessageType::Application => gst_sys::GST_MESSAGE_APPLICATION, MessageType::Application => ffi::GST_MESSAGE_APPLICATION,
MessageType::Element => gst_sys::GST_MESSAGE_ELEMENT, MessageType::Element => ffi::GST_MESSAGE_ELEMENT,
MessageType::SegmentStart => gst_sys::GST_MESSAGE_SEGMENT_START, MessageType::SegmentStart => ffi::GST_MESSAGE_SEGMENT_START,
MessageType::SegmentDone => gst_sys::GST_MESSAGE_SEGMENT_DONE, MessageType::SegmentDone => ffi::GST_MESSAGE_SEGMENT_DONE,
MessageType::DurationChanged => gst_sys::GST_MESSAGE_DURATION_CHANGED, MessageType::DurationChanged => ffi::GST_MESSAGE_DURATION_CHANGED,
MessageType::Latency => gst_sys::GST_MESSAGE_LATENCY, MessageType::Latency => ffi::GST_MESSAGE_LATENCY,
MessageType::AsyncStart => gst_sys::GST_MESSAGE_ASYNC_START, MessageType::AsyncStart => ffi::GST_MESSAGE_ASYNC_START,
MessageType::AsyncDone => gst_sys::GST_MESSAGE_ASYNC_DONE, MessageType::AsyncDone => ffi::GST_MESSAGE_ASYNC_DONE,
MessageType::RequestState => gst_sys::GST_MESSAGE_REQUEST_STATE, MessageType::RequestState => ffi::GST_MESSAGE_REQUEST_STATE,
MessageType::StepStart => gst_sys::GST_MESSAGE_STEP_START, MessageType::StepStart => ffi::GST_MESSAGE_STEP_START,
MessageType::Qos => gst_sys::GST_MESSAGE_QOS, MessageType::Qos => ffi::GST_MESSAGE_QOS,
MessageType::Progress => gst_sys::GST_MESSAGE_PROGRESS, MessageType::Progress => ffi::GST_MESSAGE_PROGRESS,
MessageType::Toc => gst_sys::GST_MESSAGE_TOC, MessageType::Toc => ffi::GST_MESSAGE_TOC,
MessageType::ResetTime => gst_sys::GST_MESSAGE_RESET_TIME, MessageType::ResetTime => ffi::GST_MESSAGE_RESET_TIME,
MessageType::StreamStart => gst_sys::GST_MESSAGE_STREAM_START, MessageType::StreamStart => ffi::GST_MESSAGE_STREAM_START,
MessageType::NeedContext => gst_sys::GST_MESSAGE_NEED_CONTEXT, MessageType::NeedContext => ffi::GST_MESSAGE_NEED_CONTEXT,
MessageType::HaveContext => gst_sys::GST_MESSAGE_HAVE_CONTEXT, MessageType::HaveContext => ffi::GST_MESSAGE_HAVE_CONTEXT,
MessageType::Extended => gst_sys::GST_MESSAGE_EXTENDED, MessageType::Extended => ffi::GST_MESSAGE_EXTENDED,
MessageType::DeviceAdded => gst_sys::GST_MESSAGE_DEVICE_ADDED, MessageType::DeviceAdded => ffi::GST_MESSAGE_DEVICE_ADDED,
MessageType::DeviceRemoved => gst_sys::GST_MESSAGE_DEVICE_REMOVED, MessageType::DeviceRemoved => ffi::GST_MESSAGE_DEVICE_REMOVED,
MessageType::PropertyNotify => gst_sys::GST_MESSAGE_PROPERTY_NOTIFY, MessageType::PropertyNotify => ffi::GST_MESSAGE_PROPERTY_NOTIFY,
MessageType::StreamCollection => gst_sys::GST_MESSAGE_STREAM_COLLECTION, MessageType::StreamCollection => ffi::GST_MESSAGE_STREAM_COLLECTION,
MessageType::StreamsSelected => gst_sys::GST_MESSAGE_STREAMS_SELECTED, MessageType::StreamsSelected => ffi::GST_MESSAGE_STREAMS_SELECTED,
MessageType::Redirect => gst_sys::GST_MESSAGE_REDIRECT, MessageType::Redirect => ffi::GST_MESSAGE_REDIRECT,
MessageType::__Unknown(value) => value as u32, MessageType::__Unknown(value) => value as u32,
} }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl FromGlib<gst_sys::GstMessageType> for MessageType { impl FromGlib<ffi::GstMessageType> for MessageType {
#[allow(clippy::unreadable_literal)] #[allow(clippy::unreadable_literal)]
fn from_glib(value: gst_sys::GstMessageType) -> Self { fn from_glib(value: ffi::GstMessageType) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
match value { match value {
0 => MessageType::Unknown, 0 => MessageType::Unknown,
@ -612,7 +612,7 @@ impl FromGlib<gst_sys::GstMessageType> for MessageType {
impl StaticType for MessageType { impl StaticType for MessageType {
fn static_type() -> Type { fn static_type() -> Type {
unsafe { from_glib(gst_sys::gst_message_type_get_type()) } unsafe { from_glib(ffi::gst_message_type_get_type()) }
} }
} }
@ -624,13 +624,13 @@ impl<'a> FromValueOptional<'a> for MessageType {
impl<'a> FromValue<'a> for MessageType { impl<'a> FromValue<'a> for MessageType {
unsafe fn from_value(value: &Value) -> Self { unsafe fn from_value(value: &Value) -> Self {
from_glib(gobject_sys::g_value_get_flags(value.to_glib_none().0)) from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0))
} }
} }
impl SetValue for MessageType { impl SetValue for MessageType {
unsafe fn set_value(value: &mut Value, this: &Self) { unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_sys::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib()) glib::gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib())
} }
} }

View file

@ -8,7 +8,6 @@
use thiserror::Error; use thiserror::Error;
use glib;
use glib::IsA; use glib::IsA;
#[macro_export] #[macro_export]
@ -62,7 +61,7 @@ pub struct ErrorMessage {
} }
impl ErrorMessage { impl ErrorMessage {
pub fn new<T: ::MessageErrorDomain>( pub fn new<T: crate::MessageErrorDomain>(
error: &T, error: &T,
message: Option<&str>, message: Option<&str>,
debug: Option<&str>, debug: Option<&str>,
@ -102,14 +101,14 @@ macro_rules! gst_loggable_error(
#[macro_export] #[macro_export]
macro_rules! gst_result_from_gboolean( macro_rules! gst_result_from_gboolean(
// Plain strings // Plain strings
($gst_sys_bool:expr, $cat:expr, $msg:expr) => { ($ffi_bool:expr, $cat:expr, $msg:expr) => {
$crate::glib::glib_result_from_gboolean!($gst_sys_bool, $msg) $crate::glib::glib_result_from_gboolean!($ffi_bool, $msg)
.map_err(|bool_err| $crate::LoggableError::new($cat.clone(), bool_err)) .map_err(|bool_err| $crate::LoggableError::new($cat.clone(), bool_err))
}; };
// Format strings // Format strings
($gst_sys_bool:expr, $cat:expr, $($msg:tt)*) => { { ($ffi_bool:expr, $cat:expr, $($msg:tt)*) => { {
$crate::glib::glib_result_from_gboolean!($gst_sys_bool, $($msg)*) $crate::glib::glib_result_from_gboolean!($ffi_bool, $($msg)*)
.map_err(|bool_err| $crate::LoggableError::new($cat.clone(), bool_err)) .map_err(|bool_err| $crate::LoggableError::new($cat.clone(), bool_err))
}}; }};
); );
@ -117,12 +116,12 @@ macro_rules! gst_result_from_gboolean(
#[derive(Debug, Clone, Error)] #[derive(Debug, Clone, Error)]
#[error("Error {:?}: {:?} at {}:{}", .category.get_name(), .bool_error.message, .bool_error.filename, .bool_error.line)] #[error("Error {:?}: {:?} at {}:{}", .category.get_name(), .bool_error.message, .bool_error.filename, .bool_error.line)]
pub struct LoggableError { pub struct LoggableError {
category: ::DebugCategory, category: crate::DebugCategory,
bool_error: glib::BoolError, bool_error: glib::BoolError,
} }
impl LoggableError { impl LoggableError {
pub fn new(category: ::DebugCategory, bool_error: glib::BoolError) -> LoggableError { pub fn new(category: crate::DebugCategory, bool_error: glib::BoolError) -> LoggableError {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
LoggableError { LoggableError {
category, category,
@ -133,7 +132,7 @@ impl LoggableError {
pub fn log(&self) { pub fn log(&self) {
self.category.log( self.category.log(
None as Option<&glib::Object>, None as Option<&glib::Object>,
::DebugLevel::Error, crate::DebugLevel::Error,
self.bool_error.filename, self.bool_error.filename,
self.bool_error.function, self.bool_error.function,
self.bool_error.line, self.bool_error.line,
@ -144,7 +143,7 @@ impl LoggableError {
pub fn log_with_object<O: IsA<glib::Object>>(&self, obj: &O) { pub fn log_with_object<O: IsA<glib::Object>>(&self, obj: &O) {
self.category.log( self.category.log(
Some(obj), Some(obj),
::DebugLevel::Error, crate::DebugLevel::Error,
self.bool_error.filename, self.bool_error.filename,
self.bool_error.function, self.bool_error.function,
self.bool_error.line, self.bool_error.line,
@ -152,7 +151,7 @@ impl LoggableError {
); );
} }
pub fn category(&self) -> ::DebugCategory { pub fn category(&self) -> crate::DebugCategory {
self.category self.category
} }
} }
@ -161,7 +160,7 @@ impl From<glib::BoolError> for LoggableError {
fn from(bool_error: glib::BoolError) -> Self { fn from(bool_error: glib::BoolError) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
LoggableError { LoggableError {
category: *::CAT_RUST, category: *crate::CAT_RUST,
bool_error, bool_error,
} }
} }
@ -173,10 +172,10 @@ mod tests {
#[test] #[test]
fn error_message() { fn error_message() {
::init().unwrap(); crate::init().unwrap();
let e = ErrorMessage::new( let e = ErrorMessage::new(
&::CoreError::Failed, &crate::CoreError::Failed,
Some("message"), Some("message"),
Some("debug"), Some("debug"),
"filename", "filename",
@ -191,7 +190,7 @@ mod tests {
#[test] #[test]
fn logabble_error() { fn logabble_error() {
::init().unwrap(); crate::init().unwrap();
let e: LoggableError = glib::BoolError::new("msg", "filename", "function", 7).into(); let e: LoggableError = glib::BoolError::new("msg", "filename", "function", 7).into();
assert_eq!( assert_eq!(

File diff suppressed because it is too large Load diff

View file

@ -6,17 +6,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::ClockTime;
use crate::Format;
use muldiv::MulDiv; use muldiv::MulDiv;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::ops; use std::ops;
use thiserror::Error; use thiserror::Error;
use ClockTime;
use Format;
use std::cmp; use std::cmp;
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
#[cfg_attr(feature = "ser_de", derive(Serialize, Deserialize))] #[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub enum GenericFormattedValue { pub enum GenericFormattedValue {
Undefined(Undefined), Undefined(Undefined),
Default(Default), Default(Default),
@ -615,7 +615,7 @@ impl FormattedValue for Percent {
unsafe fn from_raw(format: Format, value: i64) -> Self { unsafe fn from_raw(format: Format, value: i64) -> Self {
debug_assert_eq!(format, Format::Percent); debug_assert_eq!(format, Format::Percent);
if value < 0 || value > gst_sys::GST_FORMAT_PERCENT_MAX { if value < 0 || value > ffi::GST_FORMAT_PERCENT_MAX {
Percent(None) Percent(None)
} else { } else {
Percent(Some(value as u32)) Percent(Some(value as u32))
@ -688,7 +688,7 @@ impl TryFrom<f64> for Percent {
Err(TryPercentFromFloatError(())) Err(TryPercentFromFloatError(()))
} else { } else {
Ok(Percent(Some( Ok(Percent(Some(
(v * gst_sys::GST_FORMAT_PERCENT_SCALE as f64).round() as u32, (v * ffi::GST_FORMAT_PERCENT_SCALE as f64).round() as u32,
))) )))
} }
} }
@ -703,7 +703,7 @@ impl TryFrom<f32> for Percent {
Err(TryPercentFromFloatError(())) Err(TryPercentFromFloatError(()))
} else { } else {
Ok(Percent(Some( Ok(Percent(Some(
(v * gst_sys::GST_FORMAT_PERCENT_SCALE as f32).round() as u32, (v * ffi::GST_FORMAT_PERCENT_SCALE as f32).round() as u32,
))) )))
} }
} }
@ -713,9 +713,9 @@ impl TryFrom<f32> for Percent {
mod tests { mod tests {
#[test] #[test]
fn test_clock_time() { fn test_clock_time() {
::init().unwrap(); crate::init().unwrap();
let t1 = ::SECOND; let t1 = crate::SECOND;
let t2 = 2 * t1; let t2 = 2 * t1;
let t3 = &t1 * 2; let t3 = &t1 * 2;
let mut t4 = t2 + t3; let mut t4 = t2 + t3;
@ -723,7 +723,7 @@ mod tests {
assert_eq!(t4.nanoseconds(), Some(5_000_000_000)); assert_eq!(t4.nanoseconds(), Some(5_000_000_000));
let t5 = t4 - 6 * ::SECOND; let t5 = t4 - 6 * crate::SECOND;
assert!(t5.is_none()); assert!(t5.is_none());
} }
} }

View file

@ -9,7 +9,7 @@
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use format::{Buffers, Bytes, Default, Percent, Undefined}; use crate::format::{Buffers, Bytes, Default, Percent, Undefined};
// Manual implementation for some types that would otherwise yield representations such as: // Manual implementation for some types that would otherwise yield representations such as:
// "Default((Some(42)))" // "Default((Some(42)))"
@ -63,18 +63,15 @@ impl<'de> Deserialize<'de> for Percent {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::format::{Buffers, Bytes, Default, Percent, Undefined};
extern crate serde_json; use crate::ClockTime;
use crate::Format;
use format::{Buffers, Bytes, Default, Percent, Undefined}; use crate::GenericFormattedValue;
use std::convert::TryFrom; use std::convert::TryFrom;
use ClockTime;
use Format;
use GenericFormattedValue;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default(); let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string(); pretty_config.new_line = "".to_string();
@ -136,7 +133,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
let value_ron = "Default(Some(42))"; let value_ron = "Default(Some(42))";
let value_de: GenericFormattedValue = ron::de::from_str(value_ron).unwrap(); let value_de: GenericFormattedValue = ron::de::from_str(value_ron).unwrap();
@ -157,7 +154,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
macro_rules! test_roundrip( macro_rules! test_roundrip(
($value:expr) => { ($value:expr) => {

View file

@ -6,18 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use auto::functions::parse_bin_from_description; use crate::auto::functions::parse_bin_from_description;
use glib;
use glib::translate::*; use glib::translate::*;
use glib::Cast; use glib::Cast;
use gst_sys;
use std::ptr; use std::ptr;
use Bin; use crate::Bin;
use Element; use crate::Element;
use Object; use crate::Object;
use ParseContext; use crate::ParseContext;
use ParseFlags; use crate::ParseFlags;
pub fn parse_bin_from_description_with_name( pub fn parse_bin_from_description_with_name(
bin_description: &str, bin_description: &str,
@ -29,7 +27,7 @@ pub fn parse_bin_from_description_with_name(
if !bin_name.is_empty() { if !bin_name.is_empty() {
let obj = bin.clone().upcast::<Object>(); let obj = bin.clone().upcast::<Object>();
unsafe { unsafe {
gst_sys::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0); ffi::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
} }
} }
Ok(bin) Ok(bin)
@ -44,7 +42,7 @@ pub fn parse_bin_from_description_full(
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = gst_sys::gst_parse_bin_from_description_full( let ret = ffi::gst_parse_bin_from_description_full(
bin_description.to_glib_none().0, bin_description.to_glib_none().0,
ghost_unlinked_pads.to_glib(), ghost_unlinked_pads.to_glib(),
context.to_glib_none_mut().0, context.to_glib_none_mut().0,
@ -72,7 +70,7 @@ pub fn parse_bin_from_description_with_name_full(
if !bin_name.is_empty() { if !bin_name.is_empty() {
let obj = bin.clone().upcast::<Object>(); let obj = bin.clone().upcast::<Object>();
unsafe { unsafe {
gst_sys::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0); ffi::gst_object_set_name(obj.to_glib_none().0, bin_name.to_glib_none().0);
} }
} }
Ok(bin) Ok(bin)
@ -86,7 +84,7 @@ pub fn parse_launch_full(
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = gst_sys::gst_parse_launch_full( let ret = ffi::gst_parse_launch_full(
pipeline_description.to_glib_none().0, pipeline_description.to_glib_none().0,
context.to_glib_none_mut().0, context.to_glib_none_mut().0,
flags.to_glib(), flags.to_glib(),
@ -108,7 +106,7 @@ pub fn parse_launchv_full(
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
let ret = gst_sys::gst_parse_launchv_full( let ret = ffi::gst_parse_launchv_full(
argv.to_glib_none().0, argv.to_glib_none().0,
context.to_glib_none_mut().0, context.to_glib_none_mut().0,
flags.to_glib(), flags.to_glib(),
@ -147,7 +145,7 @@ pub fn calculate_linear_regression(
let mut xbase = mem::MaybeUninit::uninit(); let mut xbase = mem::MaybeUninit::uninit();
let mut r_squared = mem::MaybeUninit::uninit(); let mut r_squared = mem::MaybeUninit::uninit();
let res = from_glib(gst_sys::gst_calculate_linear_regression( let res = from_glib(ffi::gst_calculate_linear_regression(
xy.as_ptr() as *const u64, xy.as_ptr() as *const u64,
temp.map(|temp| temp.as_mut_ptr() as *mut u64) temp.map(|temp| temp.as_mut_ptr() as *mut u64)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
@ -174,13 +172,13 @@ pub fn calculate_linear_regression(
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<::PluginAPIFlags> { pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<crate::PluginAPIFlags> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
use std::mem; use std::mem;
let mut flags = mem::MaybeUninit::uninit(); let mut flags = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_type_is_plugin_api( let ret = from_glib(ffi::gst_type_is_plugin_api(
type_.to_glib(), type_.to_glib(),
flags.as_mut_ptr(), flags.as_mut_ptr(),
)); ));
@ -196,12 +194,12 @@ pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<::PluginAPIFlags>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use prelude::*; use crate::prelude::*;
#[cfg(feature = "v1_12")] #[cfg(feature = "v1_12")]
#[test] #[test]
fn test_calculate_linear_regression() { fn test_calculate_linear_regression() {
::init().unwrap(); crate::init().unwrap();
let values = [(0, 0), (1, 1), (2, 2), (3, 3)]; let values = [(0, 0), (1, 1), (2, 2), (3, 3)];
@ -216,7 +214,7 @@ mod tests {
#[test] #[test]
fn test_parse_bin_from_description_with_name() { fn test_parse_bin_from_description_with_name() {
::init().unwrap(); crate::init().unwrap();
let bin = let bin =
parse_bin_from_description_with_name("fakesrc ! fakesink", false, "all_fake").unwrap(); parse_bin_from_description_with_name("fakesrc ! fakesink", false, "all_fake").unwrap();

View file

@ -6,22 +6,21 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::FlowError;
use crate::FlowSuccess;
use crate::GhostPad;
use crate::LoggableError;
use crate::Object;
use crate::Pad;
use crate::PadBuilder;
use crate::PadExt;
use crate::PadExtManual;
use crate::PadFlags;
use crate::PadGetRangeSuccess;
use crate::PadMode;
use crate::StaticPadTemplate;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use FlowError;
use FlowSuccess;
use GhostPad;
use LoggableError;
use Object;
use Pad;
use PadBuilder;
use PadExt;
use PadExtManual;
use PadFlags;
use PadGetRangeSuccess;
use PadMode;
use StaticPadTemplate;
impl GhostPad { impl GhostPad {
pub fn activate_mode_default<P: IsA<GhostPad>, Q: IsA<Object>>( pub fn activate_mode_default<P: IsA<GhostPad>, Q: IsA<Object>>(
@ -32,9 +31,9 @@ impl GhostPad {
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_ghost_pad_activate_mode_default( ffi::gst_ghost_pad_activate_mode_default(
pad.to_glib_none().0 as *mut gst_sys::GstPad, pad.to_glib_none().0 as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
mode.to_glib(), mode.to_glib(),
active.to_glib(), active.to_glib(),
@ -52,9 +51,9 @@ impl GhostPad {
) -> Result<(), glib::BoolError> { ) -> Result<(), glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_ghost_pad_internal_activate_mode_default( ffi::gst_ghost_pad_internal_activate_mode_default(
pad.to_glib_none().0 as *mut gst_sys::GstPad, pad.to_glib_none().0 as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
mode.to_glib(), mode.to_glib(),
active.to_glib(), active.to_glib(),
@ -67,12 +66,12 @@ impl GhostPad {
} }
} }
pub fn new(name: Option<&str>, direction: ::PadDirection) -> Self { pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder(name, direction).build() Self::builder(name, direction).build()
} }
pub fn builder(name: Option<&str>, direction: ::PadDirection) -> PadBuilder<Self> { pub fn builder(name: Option<&str>, direction: crate::PadDirection) -> PadBuilder<Self> {
skip_assert_initialized!(); skip_assert_initialized!();
PadBuilder::new(name, direction) PadBuilder::new(name, direction)
} }
@ -90,12 +89,15 @@ impl GhostPad {
PadBuilder::from_static_template(templ, name) PadBuilder::from_static_template(templ, name)
} }
pub fn from_template(templ: &::PadTemplate, name: Option<&str>) -> Self { pub fn from_template(templ: &crate::PadTemplate, name: Option<&str>) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
Self::builder_with_template(templ, name).build() Self::builder_with_template(templ, name).build()
} }
pub fn builder_with_template(templ: &::PadTemplate, name: Option<&str>) -> PadBuilder<Self> { pub fn builder_with_template(
templ: &crate::PadTemplate,
name: Option<&str>,
) -> PadBuilder<Self> {
skip_assert_initialized!(); skip_assert_initialized!();
PadBuilder::from_template(templ, name) PadBuilder::from_template(templ, name)
} }
@ -109,14 +111,14 @@ impl GhostPad {
} }
pub fn from_template_with_target<P: IsA<Pad>>( pub fn from_template_with_target<P: IsA<Pad>>(
templ: &::PadTemplate, templ: &crate::PadTemplate,
name: Option<&str>, name: Option<&str>,
target: &P, target: &P,
) -> Result<Self, glib::BoolError> { ) -> Result<Self, glib::BoolError> {
skip_assert_initialized!(); skip_assert_initialized!();
if target.get_direction() != templ.get_property_direction() { if target.get_direction() != templ.get_property_direction() {
return Err(glib_bool_error!( return Err(glib::glib_bool_error!(
"Template and target have different directions" "Template and target have different directions"
)); ));
} }
@ -128,14 +130,17 @@ impl GhostPad {
impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> { impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_activate_function<F>(self, func: F) -> Self pub fn proxy_pad_activate_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>) -> Result<(), LoggableError> + Send + Sync + 'static, F: Fn(&crate::ProxyPad, Option<&crate::Object>) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_activate_function(func); proxy.set_activate_function(func);
@ -146,17 +151,22 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_activatemode_function<F>(self, func: F) -> Self pub fn proxy_pad_activatemode_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, ::PadMode, bool) -> Result<(), LoggableError> F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::PadMode,
bool,
) -> Result<(), LoggableError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_activatemode_function(func); proxy.set_activatemode_function(func);
@ -167,17 +177,21 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_chain_function<F>(self, func: F) -> Self pub fn proxy_pad_chain_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, ::Buffer) -> Result<FlowSuccess, FlowError> F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::Buffer,
) -> Result<FlowSuccess, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_chain_function(func); proxy.set_chain_function(func);
@ -188,17 +202,21 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_chain_list_function<F>(self, func: F) -> Self pub fn proxy_pad_chain_list_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, ::BufferList) -> Result<FlowSuccess, FlowError> F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::BufferList,
) -> Result<FlowSuccess, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_chain_list_function(func); proxy.set_chain_list_function(func);
@ -209,14 +227,17 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_event_function<F>(self, func: F) -> Self pub fn proxy_pad_event_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, ::Event) -> bool + Send + Sync + 'static, F: Fn(&crate::ProxyPad, Option<&crate::Object>, crate::Event) -> bool
+ Send
+ Sync
+ 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_event_function(func); proxy.set_event_function(func);
@ -227,17 +248,21 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_event_full_function<F>(self, func: F) -> Self pub fn proxy_pad_event_full_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, ::Event) -> Result<FlowSuccess, FlowError> F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::Event,
) -> Result<FlowSuccess, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_event_full_function(func); proxy.set_event_full_function(func);
@ -249,22 +274,22 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_getrange_function<F>(self, func: F) -> Self pub fn proxy_pad_getrange_function<F>(self, func: F) -> Self
where where
F: Fn( F: Fn(
&::ProxyPad, &crate::ProxyPad,
Option<&::Object>, Option<&crate::Object>,
u64, u64,
Option<&mut ::BufferRef>, Option<&mut crate::BufferRef>,
u32, u32,
) -> Result<PadGetRangeSuccess, ::FlowError> ) -> Result<PadGetRangeSuccess, crate::FlowError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_getrange_function(func); proxy.set_getrange_function(func);
@ -275,14 +300,17 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_iterate_internal_links_function<F>(self, func: F) -> Self pub fn proxy_pad_iterate_internal_links_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>) -> ::Iterator<Pad> + Send + Sync + 'static, F: Fn(&crate::ProxyPad, Option<&crate::Object>) -> crate::Iterator<Pad>
+ Send
+ Sync
+ 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_iterate_internal_links_function(func); proxy.set_iterate_internal_links_function(func);
@ -293,17 +321,21 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_link_function<F>(self, func: F) -> Self pub fn proxy_pad_link_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError> F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
&Pad,
) -> Result<crate::PadLinkSuccess, crate::PadLinkError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_link_function(func); proxy.set_link_function(func);
@ -314,14 +346,17 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_query_function<F>(self, func: F) -> Self pub fn proxy_pad_query_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>, &mut ::QueryRef) -> bool + Send + Sync + 'static, F: Fn(&crate::ProxyPad, Option<&crate::Object>, &mut crate::QueryRef) -> bool
+ Send
+ Sync
+ 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_query_function(func); proxy.set_query_function(func);
@ -332,14 +367,14 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_unlink_function<F>(self, func: F) -> Self pub fn proxy_pad_unlink_function<F>(self, func: F) -> Self
where where
F: Fn(&::ProxyPad, Option<&::Object>) + Send + Sync + 'static, F: Fn(&crate::ProxyPad, Option<&crate::Object>) + Send + Sync + 'static,
{ {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_unlink_function(func); proxy.set_unlink_function(func);
@ -349,12 +384,12 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
} }
pub fn proxy_pad_flags(self, flags: PadFlags) -> Self { pub fn proxy_pad_flags(self, flags: PadFlags) -> Self {
use ProxyPadExt; use crate::ProxyPadExt;
unsafe { unsafe {
let proxy = self let proxy = self
.0 .0
.unsafe_cast_ref::<::ProxyPad>() .unsafe_cast_ref::<crate::ProxyPad>()
.get_internal() .get_internal()
.unwrap(); .unwrap();
proxy.set_pad_flags(flags); proxy.set_pad_flags(flags);
@ -364,7 +399,7 @@ impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
} }
pub fn build_with_target<P: IsA<Pad>>(self, target: &P) -> Result<T, glib::BoolError> { pub fn build_with_target<P: IsA<Pad>>(self, target: &P) -> Result<T, glib::BoolError> {
use GhostPadExt; use crate::GhostPadExt;
assert_eq!(self.0.get_direction(), target.get_direction()); assert_eq!(self.0.get_direction(), target.get_direction());

View file

@ -1,9 +1,6 @@
use glib;
use glib::translate::ToGlibPtr; use glib::translate::ToGlibPtr;
use glib::IsA; use glib::IsA;
use gst_sys;
pub trait GObjectExtManualGst: 'static { pub trait GObjectExtManualGst: 'static {
fn set_property_from_str(&self, name: &str, value: &str); fn set_property_from_str(&self, name: &str, value: &str);
} }
@ -11,7 +8,7 @@ pub trait GObjectExtManualGst: 'static {
impl<O: IsA<glib::Object>> GObjectExtManualGst for O { impl<O: IsA<glib::Object>> GObjectExtManualGst for O {
fn set_property_from_str(&self, name: &str, value: &str) { fn set_property_from_str(&self, name: &str, value: &str) {
unsafe { unsafe {
gst_sys::gst_util_set_object_arg( ffi::gst_util_set_object_arg(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
value.to_glib_none().0, value.to_glib_none().0,

View file

@ -6,15 +6,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib; use glib::ffi::{gconstpointer, gpointer};
use glib::translate::*; use glib::translate::*;
use glib::value::{FromValueOptional, ToValue}; use glib::value::{FromValueOptional, ToValue};
use glib::StaticType; use glib::StaticType;
use glib::Value; use glib::Value;
use glib_sys;
use glib_sys::{gconstpointer, gpointer};
use gobject_sys;
use gst_sys;
use std::ffi::CString; use std::ffi::CString;
use std::fmt; use std::fmt;
use std::iter; use std::iter;
@ -34,7 +30,7 @@ pub enum IteratorError {
// Implemented manually so that we can use generics for the item // Implemented manually so that we can use generics for the item
pub struct Iterator<T> { pub struct Iterator<T> {
iter: ptr::NonNull<gst_sys::GstIterator>, iter: ptr::NonNull<ffi::GstIterator>,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -42,7 +38,7 @@ impl<T> Iterator<T>
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstIterator { pub unsafe fn into_ptr(self) -> *mut ffi::GstIterator {
let s = mem::ManuallyDrop::new(self); let s = mem::ManuallyDrop::new(self);
let it = s.to_glib_none().0; let it = s.to_glib_none().0;
it as *mut _ it as *mut _
@ -52,25 +48,24 @@ where
pub fn next(&mut self) -> Result<Option<T>, IteratorError> { pub fn next(&mut self) -> Result<Option<T>, IteratorError> {
unsafe { unsafe {
let mut value = Value::uninitialized(); let mut value = Value::uninitialized();
let res = let res = ffi::gst_iterator_next(self.to_glib_none_mut().0, value.to_glib_none_mut().0);
gst_sys::gst_iterator_next(self.to_glib_none_mut().0, value.to_glib_none_mut().0);
#[allow(clippy::wildcard_in_or_patterns)] #[allow(clippy::wildcard_in_or_patterns)]
match res { match res {
gst_sys::GST_ITERATOR_OK => match value.get::<T>().expect("Iterator::next") { ffi::GST_ITERATOR_OK => match value.get::<T>().expect("Iterator::next") {
Some(value) => Ok(Some(value)), Some(value) => Ok(Some(value)),
None => Err(IteratorError::Error), None => Err(IteratorError::Error),
}, },
gst_sys::GST_ITERATOR_DONE => Ok(None), ffi::GST_ITERATOR_DONE => Ok(None),
gst_sys::GST_ITERATOR_RESYNC => Err(IteratorError::Resync), ffi::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
gst_sys::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error), ffi::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
} }
} }
} }
pub fn resync(&mut self) { pub fn resync(&mut self) {
unsafe { unsafe {
gst_sys::gst_iterator_resync(self.to_glib_none_mut().0); ffi::gst_iterator_resync(self.to_glib_none_mut().0);
} }
} }
@ -81,12 +76,12 @@ where
unsafe { unsafe {
let func_box: Box<dyn Fn(T) -> bool + Send + Sync + 'static> = Box::new(func); let func_box: Box<dyn Fn(T) -> bool + Send + Sync + 'static> = Box::new(func);
let mut closure_value = glib::Value::from_type(from_glib(filter_boxed_get_type::<T>())); let mut closure_value = glib::Value::from_type(from_glib(filter_boxed_get_type::<T>()));
gobject_sys::g_value_take_boxed( glib::gobject_ffi::g_value_take_boxed(
closure_value.to_glib_none_mut().0, closure_value.to_glib_none_mut().0,
Arc::into_raw(Arc::new(func_box)) as gpointer, Arc::into_raw(Arc::new(func_box)) as gpointer,
); );
from_glib_full(gst_sys::gst_iterator_filter( from_glib_full(ffi::gst_iterator_filter(
self.into_ptr(), self.into_ptr(),
Some(filter_trampoline::<T>), Some(filter_trampoline::<T>),
closure_value.to_glib_none().0, closure_value.to_glib_none().0,
@ -104,7 +99,7 @@ where
let mut func = func; let mut func = func;
let func_ptr = &mut func as *mut F as gpointer; let func_ptr = &mut func as *mut F as gpointer;
let res = from_glib(gst_sys::gst_iterator_find_custom( let res = from_glib(ffi::gst_iterator_find_custom(
self.to_glib_none_mut().0, self.to_glib_none_mut().0,
Some(find_trampoline::<T, F>), Some(find_trampoline::<T, F>),
elem.to_glib_none_mut().0, elem.to_glib_none_mut().0,
@ -126,7 +121,7 @@ where
let mut func = func; let mut func = func;
let func_ptr = &mut func as *mut F as gpointer; let func_ptr = &mut func as *mut F as gpointer;
let res = gst_sys::gst_iterator_foreach( let res = ffi::gst_iterator_foreach(
self.to_glib_none_mut().0, self.to_glib_none_mut().0,
Some(foreach_trampoline::<T, F>), Some(foreach_trampoline::<T, F>),
func_ptr, func_ptr,
@ -134,9 +129,9 @@ where
#[allow(clippy::wildcard_in_or_patterns)] #[allow(clippy::wildcard_in_or_patterns)]
match res { match res {
gst_sys::GST_ITERATOR_OK | gst_sys::GST_ITERATOR_DONE => Ok(()), ffi::GST_ITERATOR_OK | ffi::GST_ITERATOR_DONE => Ok(()),
gst_sys::GST_ITERATOR_RESYNC => Err(IteratorError::Resync), ffi::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
gst_sys::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error), ffi::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
} }
} }
} }
@ -151,12 +146,12 @@ where
let mut accum = Some(init); let mut accum = Some(init);
let mut ret = glib::Value::from_type(glib::Type::Pointer); let mut ret = glib::Value::from_type(glib::Type::Pointer);
gobject_sys::g_value_set_pointer( glib::gobject_ffi::g_value_set_pointer(
ret.to_glib_none_mut().0, ret.to_glib_none_mut().0,
&mut accum as *mut _ as gpointer, &mut accum as *mut _ as gpointer,
); );
let res = gst_sys::gst_iterator_fold( let res = ffi::gst_iterator_fold(
self.to_glib_none_mut().0, self.to_glib_none_mut().0,
Some(fold_trampoline::<T, U, F>), Some(fold_trampoline::<T, U, F>),
ret.to_glib_none_mut().0, ret.to_glib_none_mut().0,
@ -165,9 +160,9 @@ where
#[allow(clippy::wildcard_in_or_patterns)] #[allow(clippy::wildcard_in_or_patterns)]
match res { match res {
gst_sys::GST_ITERATOR_OK | gst_sys::GST_ITERATOR_DONE => Ok(accum.unwrap()), ffi::GST_ITERATOR_OK | ffi::GST_ITERATOR_DONE => Ok(accum.unwrap()),
gst_sys::GST_ITERATOR_RESYNC => Err(IteratorError::Resync), ffi::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
gst_sys::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error), ffi::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
} }
} }
} }
@ -182,7 +177,7 @@ where
static DUMMY_COOKIE: u32 = 0; static DUMMY_COOKIE: u32 = 0;
unsafe { unsafe {
let it = gst_sys::gst_iterator_new( let it = ffi::gst_iterator_new(
mem::size_of::<RsIterator<T, I>>() as u32, mem::size_of::<RsIterator<T, I>>() as u32,
T::static_type().to_glib(), T::static_type().to_glib(),
ptr::null_mut(), ptr::null_mut(),
@ -219,7 +214,7 @@ struct RsIterator<T, I: IteratorImpl<T>>
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
iter: gst_sys::GstIterator, iter: ffi::GstIterator,
imp: I, imp: I,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -233,8 +228,8 @@ where
} }
unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>( unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>(
it: *const gst_sys::GstIterator, it: *const ffi::GstIterator,
copy: *mut gst_sys::GstIterator, copy: *mut ffi::GstIterator,
) where ) where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
@ -244,7 +239,7 @@ unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>(
ptr::write(&mut (*copy).imp, (*it).imp.clone()); ptr::write(&mut (*copy).imp, (*it).imp.clone());
} }
unsafe extern "C" fn rs_iterator_free<T, I: IteratorImpl<T>>(it: *mut gst_sys::GstIterator) unsafe extern "C" fn rs_iterator_free<T, I: IteratorImpl<T>>(it: *mut ffi::GstIterator)
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
@ -253,9 +248,9 @@ where
} }
unsafe extern "C" fn rs_iterator_next<T, I: IteratorImpl<T>>( unsafe extern "C" fn rs_iterator_next<T, I: IteratorImpl<T>>(
it: *mut gst_sys::GstIterator, it: *mut ffi::GstIterator,
result: *mut gobject_sys::GValue, result: *mut glib::gobject_ffi::GValue,
) -> gst_sys::GstIteratorResult ) -> ffi::GstIteratorResult
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
@ -264,17 +259,17 @@ where
Some(Ok(value)) => { Some(Ok(value)) => {
let value = value.to_value(); let value = value.to_value();
ptr::write(result, value.into_raw()); ptr::write(result, value.into_raw());
gst_sys::GST_ITERATOR_OK ffi::GST_ITERATOR_OK
} }
None => gst_sys::GST_ITERATOR_DONE, None => ffi::GST_ITERATOR_DONE,
Some(Err(res)) => match res { Some(Err(res)) => match res {
IteratorError::Resync => gst_sys::GST_ITERATOR_RESYNC, IteratorError::Resync => ffi::GST_ITERATOR_RESYNC,
IteratorError::Error => gst_sys::GST_ITERATOR_ERROR, IteratorError::Error => ffi::GST_ITERATOR_ERROR,
}, },
} }
} }
unsafe extern "C" fn rs_iterator_resync<T, I: IteratorImpl<T>>(it: *mut gst_sys::GstIterator) unsafe extern "C" fn rs_iterator_resync<T, I: IteratorImpl<T>>(it: *mut ffi::GstIterator)
where where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static, for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{ {
@ -324,10 +319,10 @@ unsafe extern "C" fn filter_trampoline<T>(value: gconstpointer, func: gconstpoin
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
let value = value as *const gobject_sys::GValue; let value = value as *const glib::gobject_ffi::GValue;
let func = func as *const gobject_sys::GValue; let func = func as *const glib::gobject_ffi::GValue;
let func = gobject_sys::g_value_get_boxed(func); let func = glib::gobject_ffi::g_value_get_boxed(func);
let func = &*(func as *const &(dyn Fn(T) -> bool + Send + Sync + 'static)); let func = &*(func as *const &(dyn Fn(T) -> bool + Send + Sync + 'static));
let value = &*(value as *const glib::Value); let value = &*(value as *const glib::Value);
@ -357,12 +352,12 @@ unsafe extern "C" fn filter_boxed_unref<T: 'static>(boxed: gpointer) {
let _ = Arc::from_raw(boxed as *const Box<dyn Fn(T) -> bool + Send + Sync + 'static>); let _ = Arc::from_raw(boxed as *const Box<dyn Fn(T) -> bool + Send + Sync + 'static>);
} }
unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_sys::GType { unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib::ffi::GType {
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Mutex; use std::sync::Mutex;
static mut TYPES: Lazy<Mutex<HashMap<String, glib_sys::GType>>> = static mut TYPES: Lazy<Mutex<HashMap<String, glib::ffi::GType>>> =
Lazy::new(|| Mutex::new(HashMap::new())); Lazy::new(|| Mutex::new(HashMap::new()));
let mut types = TYPES.lock().unwrap(); let mut types = TYPES.lock().unwrap();
@ -380,8 +375,8 @@ unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_sy
let iter_type_name = let iter_type_name =
CString::new(format!("GstRsIteratorFilterBoxed-{}-{}", type_name, idx)) CString::new(format!("GstRsIteratorFilterBoxed-{}-{}", type_name, idx))
.unwrap(); .unwrap();
if gobject_sys::g_type_from_name(iter_type_name.as_ptr()) if glib::gobject_ffi::g_type_from_name(iter_type_name.as_ptr())
== gobject_sys::G_TYPE_INVALID == glib::gobject_ffi::G_TYPE_INVALID
{ {
break iter_type_name; break iter_type_name;
} }
@ -389,13 +384,13 @@ unsafe extern "C" fn filter_boxed_get_type<T: StaticType + 'static>() -> glib_sy
} }
}; };
let type_ = gobject_sys::g_boxed_type_register_static( let type_ = glib::gobject_ffi::g_boxed_type_register_static(
iter_type_name.as_ptr(), iter_type_name.as_ptr(),
Some(filter_boxed_ref::<T>), Some(filter_boxed_ref::<T>),
Some(filter_boxed_unref::<T>), Some(filter_boxed_unref::<T>),
); );
assert_ne!(type_, gobject_sys::G_TYPE_INVALID); assert_ne!(type_, glib::gobject_ffi::G_TYPE_INVALID);
type_ type_
}; };
@ -412,7 +407,7 @@ unsafe extern "C" fn find_trampoline<T, F: FnMut(T) -> bool>(
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
let value = value as *const gobject_sys::GValue; let value = value as *const glib::gobject_ffi::GValue;
let func = func as *mut F; let func = func as *mut F;
let value = &*(value as *const glib::Value); let value = &*(value as *const glib::Value);
@ -426,7 +421,7 @@ where
} }
unsafe extern "C" fn foreach_trampoline<T, F: FnMut(T)>( unsafe extern "C" fn foreach_trampoline<T, F: FnMut(T)>(
value: *const gobject_sys::GValue, value: *const glib::gobject_ffi::GValue,
func: gpointer, func: gpointer,
) where ) where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
@ -442,10 +437,10 @@ unsafe extern "C" fn foreach_trampoline<T, F: FnMut(T)>(
} }
unsafe extern "C" fn fold_trampoline<T, U, F: FnMut(U, T) -> Result<U, U>>( unsafe extern "C" fn fold_trampoline<T, U, F: FnMut(U, T) -> Result<U, U>>(
value: *const gobject_sys::GValue, value: *const glib::gobject_ffi::GValue,
ret: *mut gobject_sys::GValue, ret: *mut glib::gobject_ffi::GValue,
func: gpointer, func: gpointer,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
for<'a> T: FromValueOptional<'a> + 'static, for<'a> T: FromValueOptional<'a> + 'static,
{ {
@ -453,23 +448,23 @@ where
let value = &*(value as *const glib::Value); let value = &*(value as *const glib::Value);
let value = value.get::<T>().expect("Iterator fold_trampoline").unwrap(); let value = value.get::<T>().expect("Iterator fold_trampoline").unwrap();
let accum = &mut *(gobject_sys::g_value_get_pointer(ret) as *mut Option<U>); let accum = &mut *(glib::gobject_ffi::g_value_get_pointer(ret) as *mut Option<U>);
match (*func)(accum.take().unwrap(), value) { match (*func)(accum.take().unwrap(), value) {
Ok(next_accum) => { Ok(next_accum) => {
*accum = Some(next_accum); *accum = Some(next_accum);
glib_sys::GTRUE glib::ffi::GTRUE
} }
Err(next_accum) => { Err(next_accum) => {
*accum = Some(next_accum); *accum = Some(next_accum);
glib_sys::GFALSE glib::ffi::GFALSE
} }
} }
} }
impl<T: StaticType + 'static> Clone for Iterator<T> { impl<T: StaticType + 'static> Clone for Iterator<T> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { from_glib_full(gst_sys::gst_iterator_copy(self.to_glib_none().0)) } unsafe { from_glib_full(ffi::gst_iterator_copy(self.to_glib_none().0)) }
} }
} }
@ -484,7 +479,7 @@ impl<T> fmt::Debug for Iterator<T> {
impl<T> Drop for Iterator<T> { impl<T> Drop for Iterator<T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
gst_sys::gst_iterator_free(self.iter.as_ptr()); ffi::gst_iterator_free(self.iter.as_ptr());
} }
} }
} }
@ -503,26 +498,26 @@ where
impl<T> glib::types::StaticType for Iterator<T> { impl<T> glib::types::StaticType for Iterator<T> {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(gst_sys::gst_iterator_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_iterator_get_type()) }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a, T: StaticType> glib::value::FromValueOptional<'a> for Iterator<T> { impl<'a, T: StaticType> glib::value::FromValueOptional<'a> for Iterator<T> {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<Iterator<T>>::from_glib_none( Option::<Iterator<T>>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstIterator, value.to_glib_none().0,
) ) as *mut ffi::GstIterator)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: 'static> glib::value::SetValue for Iterator<T> { impl<T: 'static> glib::value::SetValue for Iterator<T> {
unsafe fn set_value(value: &mut glib::Value, this: &Self) { unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstIterator>::to_glib_none(this).0 glib::translate::ToGlibPtr::<*const ffi::GstIterator>::to_glib_none(this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
@ -530,76 +525,76 @@ impl<T: 'static> glib::value::SetValue for Iterator<T> {
#[doc(hidden)] #[doc(hidden)]
impl<T: 'static> glib::value::SetValueOptional for Iterator<T> { impl<T: 'static> glib::value::SetValueOptional for Iterator<T> {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstIterator>::to_glib_none(&this).0 glib::translate::ToGlibPtr::<*const ffi::GstIterator>::to_glib_none(&this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T> glib::translate::GlibPtrDefault for Iterator<T> { impl<T> glib::translate::GlibPtrDefault for Iterator<T> {
type GlibType = *mut gst_sys::GstIterator; type GlibType = *mut ffi::GstIterator;
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a, T: 'static> glib::translate::ToGlibPtr<'a, *const gst_sys::GstIterator> for Iterator<T> { impl<'a, T: 'static> glib::translate::ToGlibPtr<'a, *const ffi::GstIterator> for Iterator<T> {
type Storage = &'a Iterator<T>; type Storage = &'a Iterator<T>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const gst_sys::GstIterator, Self> { fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstIterator, Self> {
glib::translate::Stash(self.iter.as_ptr(), self) glib::translate::Stash(self.iter.as_ptr(), self)
} }
fn to_glib_full(&self) -> *const gst_sys::GstIterator { fn to_glib_full(&self) -> *const ffi::GstIterator {
unimplemented!() unimplemented!()
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a, T: 'static> glib::translate::ToGlibPtrMut<'a, *mut gst_sys::GstIterator> for Iterator<T> { impl<'a, T: 'static> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstIterator> for Iterator<T> {
type Storage = &'a mut Iterator<T>; type Storage = &'a mut Iterator<T>;
#[inline] #[inline]
fn to_glib_none_mut( fn to_glib_none_mut(
&'a mut self, &'a mut self,
) -> glib::translate::StashMut<'a, *mut gst_sys::GstIterator, Self> { ) -> glib::translate::StashMut<'a, *mut ffi::GstIterator, Self> {
glib::translate::StashMut(self.iter.as_ptr(), self) glib::translate::StashMut(self.iter.as_ptr(), self)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: StaticType> glib::translate::FromGlibPtrNone<*const gst_sys::GstIterator> for Iterator<T> { impl<T: StaticType> glib::translate::FromGlibPtrNone<*const ffi::GstIterator> for Iterator<T> {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *const gst_sys::GstIterator) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstIterator) -> Self {
assert_ne!( assert_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()), glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE glib::ffi::GFALSE
); );
from_glib_full(gst_sys::gst_iterator_copy(ptr)) from_glib_full(ffi::gst_iterator_copy(ptr))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: StaticType> glib::translate::FromGlibPtrNone<*mut gst_sys::GstIterator> for Iterator<T> { impl<T: StaticType> glib::translate::FromGlibPtrNone<*mut ffi::GstIterator> for Iterator<T> {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut gst_sys::GstIterator) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstIterator) -> Self {
assert_ne!( assert_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()), glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE glib::ffi::GFALSE
); );
from_glib_full(gst_sys::gst_iterator_copy(ptr)) from_glib_full(ffi::gst_iterator_copy(ptr))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: StaticType> glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstIterator> for Iterator<T> { impl<T: StaticType> glib::translate::FromGlibPtrBorrow<*mut ffi::GstIterator> for Iterator<T> {
#[inline] #[inline]
unsafe fn from_glib_borrow(ptr: *mut gst_sys::GstIterator) -> Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *mut ffi::GstIterator) -> Borrowed<Self> {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
assert_ne!( assert_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()), glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE glib::ffi::GFALSE
); );
Borrowed::new(Self { Borrowed::new(Self {
iter: ptr::NonNull::new_unchecked(ptr), iter: ptr::NonNull::new_unchecked(ptr),
@ -609,13 +604,13 @@ impl<T: StaticType> glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstIterator
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: StaticType> glib::translate::FromGlibPtrFull<*mut gst_sys::GstIterator> for Iterator<T> { impl<T: StaticType> glib::translate::FromGlibPtrFull<*mut ffi::GstIterator> for Iterator<T> {
#[inline] #[inline]
unsafe fn from_glib_full(ptr: *mut gst_sys::GstIterator) -> Self { unsafe fn from_glib_full(ptr: *mut ffi::GstIterator) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
assert_ne!( assert_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()), glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE glib::ffi::GFALSE
); );
Self { Self {
iter: ptr::NonNull::new_unchecked(ptr), iter: ptr::NonNull::new_unchecked(ptr),
@ -683,7 +678,7 @@ mod tests {
#[test] #[test]
fn test_vec() { fn test_vec() {
::init().unwrap(); crate::init().unwrap();
let vec = vec![1i32, 2, 3]; let vec = vec![1i32, 2, 3];
let mut it = Iterator::from_vec(vec); let mut it = Iterator::from_vec(vec);
@ -706,7 +701,7 @@ mod tests {
#[test] #[test]
fn test_filter() { fn test_filter() {
::init().unwrap(); crate::init().unwrap();
let vec = vec![1i32, 2, 3]; let vec = vec![1i32, 2, 3];
let mut it = Iterator::from_vec(vec).filter(|val| val % 2 == 1); let mut it = Iterator::from_vec(vec).filter(|val| val % 2 == 1);
@ -720,7 +715,7 @@ mod tests {
#[test] #[test]
fn test_find() { fn test_find() {
::init().unwrap(); crate::init().unwrap();
// Our find // Our find
let vec = vec![1i32, 2, 3]; let vec = vec![1i32, 2, 3];
@ -730,7 +725,7 @@ mod tests {
#[test] #[test]
fn test_foreach() { fn test_foreach() {
::init().unwrap(); crate::init().unwrap();
let vec = vec![1i32, 2, 3]; let vec = vec![1i32, 2, 3];
let mut sum = 0; let mut sum = 0;
@ -741,7 +736,7 @@ mod tests {
#[test] #[test]
fn test_fold() { fn test_fold() {
::init().unwrap(); crate::init().unwrap();
// Our fold // Our fold
let vec = vec![1i32, 2, 3]; let vec = vec![1i32, 2, 3];
@ -754,7 +749,7 @@ mod tests {
#[test] #[test]
fn test_std() { fn test_std() {
::init().unwrap(); crate::init().unwrap();
let mut it = Iterator::from_vec(vec![1i32, 2, 3]).into_iter(); let mut it = Iterator::from_vec(vec![1i32, 2, 3]).into_iter();
assert_eq!(it.next(), Some(Ok(1))); assert_eq!(it.next(), Some(Ok(1)));
@ -765,7 +760,7 @@ mod tests {
#[test] #[test]
fn test_into_iter() { fn test_into_iter() {
::init().unwrap(); crate::init().unwrap();
let mut v = vec![1i32, 2, 3].into_iter(); let mut v = vec![1i32, 2, 3].into_iter();
for x in Iterator::from_vec(vec![1i32, 2, 3]) { for x in Iterator::from_vec(vec![1i32, 2, 3]) {
@ -776,14 +771,14 @@ mod tests {
#[test] #[test]
fn test_std_resync_collect() { fn test_std_resync_collect() {
use prelude::*; use crate::prelude::*;
use std::collections::BTreeSet; use std::collections::BTreeSet;
::init().unwrap(); crate::init().unwrap();
let bin = ::Bin::new(None); let bin = crate::Bin::new(None);
let id1 = ::ElementFactory::make("identity", None).unwrap(); let id1 = crate::ElementFactory::make("identity", None).unwrap();
let id2 = ::ElementFactory::make("identity", None).unwrap(); let id2 = crate::ElementFactory::make("identity", None).unwrap();
bin.add(&id1).unwrap(); bin.add(&id1).unwrap();
@ -808,13 +803,13 @@ mod tests {
#[test] #[test]
fn test_std_resync_find() { fn test_std_resync_find() {
use prelude::*; use crate::prelude::*;
::init().unwrap(); crate::init().unwrap();
let bin = ::Bin::new(None); let bin = crate::Bin::new(None);
let id1 = ::ElementFactory::make("identity", None).unwrap(); let id1 = crate::ElementFactory::make("identity", None).unwrap();
let id2 = ::ElementFactory::make("identity", None).unwrap(); let id2 = crate::ElementFactory::make("identity", None).unwrap();
bin.add(&id1).unwrap(); bin.add(&id1).unwrap();

View file

@ -8,54 +8,19 @@
#![cfg_attr(feature = "dox", feature(doc_cfg))] #![cfg_attr(feature = "dox", feature(doc_cfg))]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate cfg_if;
extern crate libc;
extern crate once_cell;
extern crate thiserror;
// Re-exported for the subclass gst_plugin_define! macro // Re-exported for the subclass gst_plugin_define! macro
pub use ffi;
#[doc(hidden)] #[doc(hidden)]
pub extern crate glib_sys; pub use glib;
#[doc(hidden)] #[doc(hidden)]
pub extern crate gobject_sys; pub use paste;
#[doc(hidden)]
pub extern crate gstreamer_sys as gst_sys;
#[doc(hidden)]
pub extern crate paste;
#[macro_use]
#[doc(hidden)]
pub extern crate glib;
extern crate num_rational;
extern crate futures_channel;
extern crate futures_core;
extern crate futures_util;
extern crate muldiv;
extern crate pretty_hex;
#[cfg(feature = "ser_de")]
extern crate serde;
#[cfg(feature = "ser_de")]
extern crate serde_bytes;
#[cfg(feature = "ser_de")]
#[macro_use]
extern crate serde_derive;
#[cfg(test)]
extern crate futures_executor;
use glib::translate::{from_glib, from_glib_full}; use glib::translate::{from_glib, from_glib_full};
macro_rules! assert_initialized_main_thread { macro_rules! assert_initialized_main_thread {
() => { () => {
if unsafe { ::gst_sys::gst_is_initialized() } != ::glib_sys::GTRUE { if unsafe { ffi::gst_is_initialized() } != glib::ffi::GTRUE {
panic!("GStreamer has not been initialized. Call `gst::init` first."); panic!("GStreamer has not been initialized. Call `gst::init` first.");
} }
}; };
@ -70,39 +35,39 @@ macro_rules! skip_assert_initialized {
#[allow(clippy::match_same_arms)] #[allow(clippy::match_same_arms)]
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
mod auto; mod auto;
pub use auto::functions::*; pub use crate::auto::functions::*;
pub use auto::*; pub use crate::auto::*;
#[macro_use] #[macro_use]
mod log; mod log;
pub use log::*; pub use crate::log::*;
#[macro_use] #[macro_use]
mod error; mod error;
pub use error::*; pub use crate::error::*;
#[macro_use] #[macro_use]
pub mod miniobject; pub mod miniobject;
pub mod message; pub mod message;
pub use message::{Message, MessageErrorDomain, MessageRef, MessageView}; pub use crate::message::{Message, MessageErrorDomain, MessageRef, MessageView};
mod value; mod value;
pub use value::*; pub use crate::value::*;
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
#[macro_use] #[macro_use]
mod value_serde; mod value_serde;
pub mod structure; pub mod structure;
pub use structure::{Structure, StructureRef}; pub use crate::structure::{Structure, StructureRef};
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod structure_serde; mod structure_serde;
pub mod caps; pub mod caps;
pub use caps::{Caps, CapsRef}; pub use crate::caps::{Caps, CapsRef};
mod caps_features; mod caps_features;
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod caps_serde; mod caps_serde;
pub use caps_features::{ pub use crate::caps_features::{
CapsFeatures, CapsFeaturesRef, CAPS_FEATURES_MEMORY_SYSTEM_MEMORY, CapsFeatures, CapsFeaturesRef, CAPS_FEATURES_MEMORY_SYSTEM_MEMORY,
CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
}; };
@ -110,7 +75,7 @@ pub use caps_features::{
mod caps_features_serde; mod caps_features_serde;
pub mod tags; pub mod tags;
pub use tags::{ pub use crate::tags::{
tag_exists, tag_get_description, tag_get_flag, tag_get_nick, tag_get_type, Tag, TagList, tag_exists, tag_get_description, tag_get_flag, tag_get_nick, tag_get_type, Tag, TagList,
TagListRef, TagListRef,
}; };
@ -120,42 +85,42 @@ mod tags_serde;
pub mod meta; pub mod meta;
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub use meta::MetaSeqnum; pub use crate::meta::MetaSeqnum;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
pub use meta::ReferenceTimestampMeta; pub use crate::meta::ReferenceTimestampMeta;
pub use meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta}; pub use crate::meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta};
pub mod buffer; pub mod buffer;
pub use buffer::{ pub use crate::buffer::{
Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA, Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA,
}; };
mod buffer_cursor; mod buffer_cursor;
pub use buffer_cursor::{BufferCursor, BufferRefCursor}; pub use crate::buffer_cursor::{BufferCursor, BufferRefCursor};
pub mod memory; pub mod memory;
pub use memory::{MappedMemory, Memory, MemoryMap, MemoryRef}; pub use crate::memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod buffer_serde; mod buffer_serde;
pub mod sample; pub mod sample;
pub use sample::{Sample, SampleRef}; pub use crate::sample::{Sample, SampleRef};
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod sample_serde; mod sample_serde;
pub mod bufferlist; pub mod bufferlist;
pub use bufferlist::{BufferList, BufferListRef}; pub use crate::bufferlist::{BufferList, BufferListRef};
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod bufferlist_serde; mod bufferlist_serde;
pub mod query; pub mod query;
pub use query::{Query, QueryRef, QueryView}; pub use crate::query::{Query, QueryRef, QueryView};
pub mod event; pub mod event;
pub use event::{Event, EventRef, EventView, GroupId, Seqnum}; pub use crate::event::{Event, EventRef, EventView, GroupId, Seqnum};
pub mod context; pub mod context;
pub use context::{Context, ContextRef}; pub use crate::context::{Context, ContextRef};
mod static_caps; mod static_caps;
pub use static_caps::*; pub use crate::static_caps::*;
mod static_pad_template; mod static_pad_template;
pub use static_pad_template::*; pub use crate::static_pad_template::*;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
@ -170,9 +135,9 @@ mod element;
mod bin; mod bin;
mod allocator; mod allocator;
pub use allocator::AllocatorExtManual; pub use crate::allocator::AllocatorExtManual;
mod pipeline; mod pipeline;
pub use pipeline::GstPipelineExtManual; pub use crate::pipeline::GstPipelineExtManual;
mod allocation_params; mod allocation_params;
pub use self::allocation_params::AllocationParams; pub use self::allocation_params::AllocationParams;
@ -180,7 +145,7 @@ pub use self::allocation_params::AllocationParams;
// OS dependent Bus extensions (also import the other plateform mod for doc) // OS dependent Bus extensions (also import the other plateform mod for doc)
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
cfg_if! { cfg_if::cfg_if! {
if #[cfg(unix)] { if #[cfg(unix)] {
mod bus_unix; mod bus_unix;
#[cfg(feature = "dox")] #[cfg(feature = "dox")]
@ -203,31 +168,31 @@ mod date_time_serde;
mod device_monitor; mod device_monitor;
mod device_provider; mod device_provider;
mod enums; mod enums;
pub use enums::MessageType; pub use crate::enums::MessageType;
mod ghost_pad; mod ghost_pad;
mod gobject; mod gobject;
mod iterator; mod iterator;
mod object; mod object;
mod pad; mod pad;
pub use pad::PadBuilder; pub use crate::pad::PadBuilder;
mod control_binding; mod control_binding;
mod control_source; mod control_source;
mod parse_context; mod parse_context;
mod proxy_pad; mod proxy_pad;
pub use proxy_pad::ProxyPadExtManual; pub use crate::proxy_pad::ProxyPadExtManual;
mod tag_setter; mod tag_setter;
pub use bin::GstBinExtManual; pub use crate::bin::GstBinExtManual;
pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId}; pub use crate::element::{ElementExtManual, ElementMessageType, NotifyWatchId};
pub use element::{ pub use crate::element::{
ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI, ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI,
ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS, ELEMENT_METADATA_LONGNAME, ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS, ELEMENT_METADATA_LONGNAME,
}; };
pub use object::GstObjectExtManual; pub use crate::object::GstObjectExtManual;
// OS dependent Bus extensions (also import the other plateform trait for doc) // OS dependent Bus extensions (also import the other plateform trait for doc)
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
cfg_if! { cfg_if::cfg_if! {
if #[cfg(unix)] { if #[cfg(unix)] {
pub use bus_unix::UnixBusExtManual; pub use bus_unix::UnixBusExtManual;
#[cfg(feature = "dox")] #[cfg(feature = "dox")]
@ -240,23 +205,23 @@ cfg_if! {
} }
pub use self::iterator::{Iterator, IteratorError, IteratorImpl, StdIterator}; pub use self::iterator::{Iterator, IteratorError, IteratorImpl, StdIterator};
pub use child_proxy::ChildProxyExtManual; pub use crate::child_proxy::ChildProxyExtManual;
pub use clock_time::ClockTime; pub use crate::clock_time::ClockTime;
pub use device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId}; pub use crate::device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId};
pub use device_provider::DeviceProviderExtManual; pub use crate::device_provider::DeviceProviderExtManual;
pub use enums::{ pub use crate::enums::{
ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess, ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess,
StateChangeError, StateChangeSuccess, TagError, StateChangeError, StateChangeSuccess, TagError,
}; };
pub use gobject::GObjectExtManualGst; pub use crate::gobject::GObjectExtManualGst;
pub use pad::{PadExtManual, PadGetRangeSuccess, PadProbeData, PadProbeId, PadProbeInfo}; pub use crate::pad::{PadExtManual, PadGetRangeSuccess, PadProbeData, PadProbeId, PadProbeInfo};
pub use parse_context::ParseContext; pub use crate::parse_context::ParseContext;
mod plugin_feature; mod plugin_feature;
pub use plugin_feature::PluginFeatureExtManual; pub use crate::plugin_feature::PluginFeatureExtManual;
pub use tag_setter::TagSetterExtManual; pub use crate::tag_setter::TagSetterExtManual;
mod plugin; mod plugin;
pub use plugin::GstPluginExtManual; pub use crate::plugin::GstPluginExtManual;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
pub mod stream; pub mod stream;
@ -265,43 +230,45 @@ pub mod stream;
pub mod stream_collection; pub mod stream_collection;
mod typefind; mod typefind;
pub use typefind::*; pub use crate::typefind::*;
pub mod format; pub mod format;
pub use format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue}; pub use crate::format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue};
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod format_serde; mod format_serde;
mod segment; mod segment;
pub use segment::*; pub use crate::segment::*;
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod segment_serde; mod segment_serde;
pub mod toc; pub mod toc;
pub use toc::{Toc, TocEntry, TocEntryRef, TocRef}; pub use crate::toc::{Toc, TocEntry, TocEntryRef, TocRef};
#[cfg(feature = "ser_de")] #[cfg(feature = "ser_de")]
mod toc_serde; mod toc_serde;
mod clock; mod clock;
pub use clock::{AtomicClockReturn, ClockExtManual, ClockId, PeriodicClockId, SingleShotClockId}; pub use crate::clock::{
AtomicClockReturn, ClockExtManual, ClockId, PeriodicClockId, SingleShotClockId,
};
mod buffer_pool; mod buffer_pool;
pub use buffer_pool::*; pub use crate::buffer_pool::*;
mod pad_template; mod pad_template;
mod param_spec; mod param_spec;
pub use param_spec::*; pub use crate::param_spec::*;
pub mod functions; pub mod functions;
pub use functions::*; pub use crate::functions::*;
use std::ptr; use std::ptr;
pub fn init() -> Result<(), glib::Error> { pub fn init() -> Result<(), glib::Error> {
unsafe { unsafe {
let mut error = ptr::null_mut(); let mut error = ptr::null_mut();
if from_glib(gst_sys::gst_init_check( if from_glib(ffi::gst_init_check(
ptr::null_mut(), ptr::null_mut(),
ptr::null_mut(), ptr::null_mut(),
&mut error, &mut error,
@ -320,10 +287,10 @@ pub fn init() -> Result<(), glib::Error> {
/// This must only be called once during the lifetime of the process, once no GStreamer threads /// This must only be called once during the lifetime of the process, once no GStreamer threads
/// are running anymore and all GStreamer resources are released. /// are running anymore and all GStreamer resources are released.
pub unsafe fn deinit() { pub unsafe fn deinit() {
gst_sys::gst_deinit(); ffi::gst_deinit();
} }
pub const BUFFER_OFFSET_NONE: u64 = gst_sys::GST_BUFFER_OFFSET_NONE; pub const BUFFER_OFFSET_NONE: u64 = ffi::GST_BUFFER_OFFSET_NONE;
pub const CLOCK_TIME_NONE: ClockTime = ClockTime(None); pub const CLOCK_TIME_NONE: ClockTime = ClockTime(None);
pub const SECOND: ClockTime = ClockTime(Some(1_000_000_000)); pub const SECOND: ClockTime = ClockTime(Some(1_000_000_000));
@ -336,60 +303,60 @@ pub const MSECOND_VAL: u64 = 1_000_000;
pub const USECOND_VAL: u64 = 1_000; pub const USECOND_VAL: u64 = 1_000;
pub const NSECOND_VAL: u64 = 1; pub const NSECOND_VAL: u64 = 1;
pub const FORMAT_PERCENT_MAX: u32 = gst_sys::GST_FORMAT_PERCENT_MAX as u32; pub const FORMAT_PERCENT_MAX: u32 = ffi::GST_FORMAT_PERCENT_MAX as u32;
pub const FORMAT_PERCENT_SCALE: u32 = gst_sys::GST_FORMAT_PERCENT_SCALE as u32; pub const FORMAT_PERCENT_SCALE: u32 = ffi::GST_FORMAT_PERCENT_SCALE as u32;
// Re-export all the traits in a prelude module, so that applications // Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts // can always "use gst::prelude::*" without getting conflicts
pub mod prelude { pub mod prelude {
pub use glib::prelude::*; pub use glib::prelude::*;
pub use auto::traits::*; pub use crate::auto::traits::*;
pub use meta::MetaAPI; pub use crate::meta::MetaAPI;
pub use allocator::AllocatorExtManual; pub use crate::allocator::AllocatorExtManual;
pub use bin::GstBinExtManual; pub use crate::bin::GstBinExtManual;
pub use element::{ElementClassExt, ElementExtManual}; pub use crate::element::{ElementClassExt, ElementExtManual};
// OS dependent Bus extensions (also import the other plateform trait for doc) // OS dependent Bus extensions (also import the other plateform trait for doc)
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
cfg_if! { cfg_if::cfg_if! {
if #[cfg(unix)] { if #[cfg(unix)] {
pub use bus_unix::UnixBusExtManual; pub use crate::bus_unix::UnixBusExtManual;
#[cfg(feature = "dox")] #[cfg(feature = "dox")]
pub use bus_windows::WindowsBusExtManual; pub use crate::bus_windows::WindowsBusExtManual;
} else { } else {
pub use bus_windows::WindowsBusExtManual; pub use crate::bus_windows::WindowsBusExtManual;
#[cfg(feature = "dox")] #[cfg(feature = "dox")]
pub use bus_unix::UnixBusExtManual; pub use crate::bus_unix::UnixBusExtManual;
} }
} }
pub use buffer_pool::BufferPoolExtManual; pub use crate::buffer_pool::BufferPoolExtManual;
pub use child_proxy::ChildProxyExtManual; pub use crate::child_proxy::ChildProxyExtManual;
pub use clock::ClockExtManual; pub use crate::clock::ClockExtManual;
pub use device_monitor::DeviceMonitorExtManual; pub use crate::device_monitor::DeviceMonitorExtManual;
pub use device_provider::DeviceProviderExtManual; pub use crate::device_provider::DeviceProviderExtManual;
pub use gobject::GObjectExtManualGst; pub use crate::gobject::GObjectExtManualGst;
pub use message::MessageErrorDomain; pub use crate::message::MessageErrorDomain;
pub use object::GstObjectExtManual; pub use crate::object::GstObjectExtManual;
pub use pad::PadExtManual; pub use crate::pad::PadExtManual;
pub use param_spec::GstParamSpecExt; pub use crate::param_spec::GstParamSpecExt;
pub use pipeline::GstPipelineExtManual; pub use crate::pipeline::GstPipelineExtManual;
pub use plugin::GstPluginExtManual; pub use crate::plugin::GstPluginExtManual;
pub use plugin_feature::PluginFeatureExtManual; pub use crate::plugin_feature::PluginFeatureExtManual;
pub use proxy_pad::ProxyPadExtManual; pub use crate::proxy_pad::ProxyPadExtManual;
pub use tag_setter::TagSetterExtManual; pub use crate::tag_setter::TagSetterExtManual;
pub use typefind::TypeFindImpl; pub use crate::typefind::TypeFindImpl;
pub use value::GstValueExt; pub use crate::value::GstValueExt;
pub use tags::{CustomTag, Tag}; pub use crate::tags::{CustomTag, Tag};
pub use muldiv::MulDiv; pub use muldiv::MulDiv;
pub use format::{FormattedValue, SpecificFormattedValue}; pub use crate::format::{FormattedValue, SpecificFormattedValue};
} }
mod utils; mod utils;

View file

@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use DebugLevel; use crate::DebugLevel;
use libc::c_char; use libc::c_char;
use std::borrow::Cow; use std::borrow::Cow;
@ -16,15 +16,12 @@ use std::ptr;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use gobject_sys; use glib::ffi::gpointer;
use gst_sys;
use glib::translate::*; use glib::translate::*;
use glib::IsA; use glib::IsA;
use glib_sys::gpointer;
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
pub struct DebugMessage(ptr::NonNull<gst_sys::GstDebugMessage>); pub struct DebugMessage(ptr::NonNull<ffi::GstDebugMessage>);
impl fmt::Debug for DebugMessage { impl fmt::Debug for DebugMessage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -35,7 +32,7 @@ impl fmt::Debug for DebugMessage {
impl DebugMessage { impl DebugMessage {
pub fn get(&self) -> Option<Cow<str>> { pub fn get(&self) -> Option<Cow<str>> {
unsafe { unsafe {
let message = gst_sys::gst_debug_message_get(self.0.as_ptr()); let message = ffi::gst_debug_message_get(self.0.as_ptr());
if message.is_null() { if message.is_null() {
None None
@ -47,17 +44,21 @@ impl DebugMessage {
} }
#[derive(PartialEq, Eq, Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]
pub struct DebugCategory(ptr::NonNull<gst_sys::GstDebugCategory>); pub struct DebugCategory(ptr::NonNull<ffi::GstDebugCategory>);
impl DebugCategory { impl DebugCategory {
pub fn new(name: &str, color: ::DebugColorFlags, description: Option<&str>) -> DebugCategory { pub fn new(
name: &str,
color: crate::DebugColorFlags,
description: Option<&str>,
) -> DebugCategory {
skip_assert_initialized!(); skip_assert_initialized!();
extern "C" { extern "C" {
fn _gst_debug_category_new( fn _gst_debug_category_new(
name: *const c_char, name: *const c_char,
color: gst_sys::GstDebugColorFlags, color: ffi::GstDebugColorFlags,
description: *const c_char, description: *const c_char,
) -> *mut gst_sys::GstDebugCategory; ) -> *mut ffi::GstDebugCategory;
} }
// Gets the category if it exists already // Gets the category if it exists already
@ -76,7 +77,7 @@ impl DebugCategory {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
extern "C" { extern "C" {
fn _gst_debug_get_category(name: *const c_char) -> *mut gst_sys::GstDebugCategory; fn _gst_debug_get_category(name: *const c_char) -> *mut ffi::GstDebugCategory;
} }
let cat = _gst_debug_get_category(name.to_glib_none().0); let cat = _gst_debug_get_category(name.to_glib_none().0);
@ -89,25 +90,25 @@ impl DebugCategory {
} }
} }
pub fn get_threshold(self) -> ::DebugLevel { pub fn get_threshold(self) -> crate::DebugLevel {
from_glib(unsafe { gst_sys::gst_debug_category_get_threshold(self.0.as_ptr()) }) from_glib(unsafe { ffi::gst_debug_category_get_threshold(self.0.as_ptr()) })
} }
pub fn set_threshold(self, threshold: ::DebugLevel) { pub fn set_threshold(self, threshold: crate::DebugLevel) {
unsafe { gst_sys::gst_debug_category_set_threshold(self.0.as_ptr(), threshold.to_glib()) } unsafe { ffi::gst_debug_category_set_threshold(self.0.as_ptr(), threshold.to_glib()) }
} }
pub fn reset_threshold(self) { pub fn reset_threshold(self) {
unsafe { gst_sys::gst_debug_category_reset_threshold(self.0.as_ptr()) } unsafe { ffi::gst_debug_category_reset_threshold(self.0.as_ptr()) }
} }
pub fn get_color(self) -> ::DebugColorFlags { pub fn get_color(self) -> crate::DebugColorFlags {
unsafe { from_glib(gst_sys::gst_debug_category_get_color(self.0.as_ptr())) } unsafe { from_glib(ffi::gst_debug_category_get_color(self.0.as_ptr())) }
} }
pub fn get_name<'a>(self) -> &'a str { pub fn get_name<'a>(self) -> &'a str {
unsafe { unsafe {
CStr::from_ptr(gst_sys::gst_debug_category_get_name(self.0.as_ptr())) CStr::from_ptr(ffi::gst_debug_category_get_name(self.0.as_ptr()))
.to_str() .to_str()
.unwrap() .unwrap()
} }
@ -115,7 +116,7 @@ impl DebugCategory {
pub fn get_description<'a>(self) -> Option<&'a str> { pub fn get_description<'a>(self) -> Option<&'a str> {
unsafe { unsafe {
let ptr = gst_sys::gst_debug_category_get_description(self.0.as_ptr()); let ptr = ffi::gst_debug_category_get_description(self.0.as_ptr());
if ptr.is_null() { if ptr.is_null() {
None None
@ -129,7 +130,7 @@ impl DebugCategory {
pub fn log<O: IsA<glib::Object>>( pub fn log<O: IsA<glib::Object>>(
self, self,
obj: Option<&O>, obj: Option<&O>,
level: ::DebugLevel, level: crate::DebugLevel,
file: &str, file: &str,
module: &str, module: &str,
line: u32, line: u32,
@ -142,12 +143,12 @@ impl DebugCategory {
} }
let obj_ptr = match obj { let obj_ptr = match obj {
Some(obj) => obj.to_glib_none().0 as *mut gobject_sys::GObject, Some(obj) => obj.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
None => ptr::null_mut(), None => ptr::null_mut(),
}; };
unsafe { unsafe {
gst_sys::gst_debug_log( ffi::gst_debug_log(
self.0.as_ptr(), self.0.as_ptr(),
level.to_glib(), level.to_glib(),
file.to_glib_none().0, file.to_glib_none().0,
@ -174,7 +175,7 @@ impl fmt::Debug for DebugCategory {
pub static CAT_RUST: Lazy<DebugCategory> = Lazy::new(|| { pub static CAT_RUST: Lazy<DebugCategory> = Lazy::new(|| {
DebugCategory::new( DebugCategory::new(
"GST_RUST", "GST_RUST",
::DebugColorFlags::UNDERLINE, crate::DebugColorFlags::UNDERLINE,
Some("GStreamer's Rust binding core"), Some("GStreamer's Rust binding core"),
) )
}); });
@ -312,13 +313,13 @@ macro_rules! gst_log_with_level(
); );
unsafe extern "C" fn log_handler<T>( unsafe extern "C" fn log_handler<T>(
category: *mut gst_sys::GstDebugCategory, category: *mut ffi::GstDebugCategory,
level: gst_sys::GstDebugLevel, level: ffi::GstDebugLevel,
file: *const c_char, file: *const c_char,
function: *const c_char, function: *const c_char,
line: i32, line: i32,
object: *mut gobject_sys::GObject, object: *mut glib::gobject_ffi::GObject,
message: *mut gst_sys::GstDebugMessage, message: *mut ffi::GstDebugMessage,
user_data: gpointer, user_data: gpointer,
) where ) where
T: Fn(DebugCategory, DebugLevel, &str, &str, u32, Option<&LoggedObject>, &DebugMessage) T: Fn(DebugCategory, DebugLevel, &str, &str, u32, Option<&LoggedObject>, &DebugMessage)
@ -360,10 +361,10 @@ unsafe impl Send for DebugLogFunction {}
unsafe impl Sync for DebugLogFunction {} unsafe impl Sync for DebugLogFunction {}
#[derive(Debug)] #[derive(Debug)]
pub struct LoggedObject(ptr::NonNull<gobject_sys::GObject>); pub struct LoggedObject(ptr::NonNull<glib::gobject_ffi::GObject>);
impl LoggedObject { impl LoggedObject {
pub fn as_ptr(&self) -> *mut gobject_sys::GObject { pub fn as_ptr(&self) -> *mut glib::gobject_ffi::GObject {
self.0.as_ptr() self.0.as_ptr()
} }
} }
@ -373,16 +374,17 @@ impl fmt::Display for LoggedObject {
unsafe { unsafe {
let ptr = self.0.as_ptr(); let ptr = self.0.as_ptr();
let g_type_instance = &mut (*ptr).g_type_instance; let g_type_instance = &mut (*ptr).g_type_instance;
if gobject_sys::g_type_check_instance_is_fundamentally_a( if glib::gobject_ffi::g_type_check_instance_is_fundamentally_a(
g_type_instance, g_type_instance,
gobject_sys::g_object_get_type(), glib::gobject_ffi::g_object_get_type(),
) != glib_sys::GFALSE ) != glib::ffi::GFALSE
{ {
let type_ = (*g_type_instance.g_class).g_type; let type_ = (*g_type_instance.g_class).g_type;
if gobject_sys::g_type_is_a(type_, gst_sys::gst_pad_get_type()) != glib_sys::GFALSE if glib::gobject_ffi::g_type_is_a(type_, ffi::gst_pad_get_type())
!= glib::ffi::GFALSE
{ {
let name_ptr = (*(ptr as *mut gst_sys::GstObject)).name; let name_ptr = (*(ptr as *mut ffi::GstObject)).name;
let name = if name_ptr.is_null() { let name = if name_ptr.is_null() {
"<null>" "<null>"
} else { } else {
@ -391,11 +393,11 @@ impl fmt::Display for LoggedObject {
.unwrap_or("<invalid name>") .unwrap_or("<invalid name>")
}; };
let parent_ptr = (*(ptr as *mut gst_sys::GstObject)).parent; let parent_ptr = (*(ptr as *mut ffi::GstObject)).parent;
let parent_name = if parent_ptr.is_null() { let parent_name = if parent_ptr.is_null() {
"<null>" "<null>"
} else { } else {
let name_ptr = (*(parent_ptr as *mut gst_sys::GstObject)).name; let name_ptr = (*(parent_ptr as *mut ffi::GstObject)).name;
if name_ptr.is_null() { if name_ptr.is_null() {
"<null>" "<null>"
} else { } else {
@ -406,10 +408,10 @@ impl fmt::Display for LoggedObject {
}; };
write!(f, "{}:{}", parent_name, name) write!(f, "{}:{}", parent_name, name)
} else if gobject_sys::g_type_is_a(type_, gst_sys::gst_object_get_type()) } else if glib::gobject_ffi::g_type_is_a(type_, ffi::gst_object_get_type())
!= glib_sys::GFALSE != glib::ffi::GFALSE
{ {
let name_ptr = (*(ptr as *mut gst_sys::GstObject)).name; let name_ptr = (*(ptr as *mut ffi::GstObject)).name;
let name = if name_ptr.is_null() { let name = if name_ptr.is_null() {
"<null>" "<null>"
} else { } else {
@ -419,7 +421,7 @@ impl fmt::Display for LoggedObject {
}; };
write!(f, "{}", name) write!(f, "{}", name)
} else { } else {
let type_name = CStr::from_ptr(gobject_sys::g_type_name(type_)); let type_name = CStr::from_ptr(glib::gobject_ffi::g_type_name(type_));
write!( write!(
f, f,
"{}:{:?}", "{}:{:?}",
@ -445,7 +447,7 @@ where
unsafe { unsafe {
let user_data = Box::new(function); let user_data = Box::new(function);
let user_data_ptr = Box::into_raw(user_data) as gpointer; let user_data_ptr = Box::into_raw(user_data) as gpointer;
gst_sys::gst_debug_add_log_function( ffi::gst_debug_add_log_function(
Some(log_handler::<T>), Some(log_handler::<T>),
user_data_ptr, user_data_ptr,
Some(log_handler_data_free::<T>), Some(log_handler_data_free::<T>),
@ -457,14 +459,14 @@ where
pub fn debug_remove_default_log_function() { pub fn debug_remove_default_log_function() {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
gst_sys::gst_debug_remove_log_function(None); ffi::gst_debug_remove_log_function(None);
} }
} }
pub fn debug_remove_log_function(log_fn: DebugLogFunction) { pub fn debug_remove_log_function(log_fn: DebugLogFunction) {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let removed = gst_sys::gst_debug_remove_log_function_by_data(log_fn.0.as_ptr()); let removed = ffi::gst_debug_remove_log_function_by_data(log_fn.0.as_ptr());
assert_eq!(removed, 1); assert_eq!(removed, 1);
} }
} }
@ -477,7 +479,7 @@ mod tests {
#[test] #[test]
fn get_existing() { fn get_existing() {
::init().unwrap(); crate::init().unwrap();
let perf_cat = DebugCategory::get("GST_PERFORMANCE") let perf_cat = DebugCategory::get("GST_PERFORMANCE")
.expect("Unable to find `DebugCategory` with name \"GST_PERFORMANCE\""); .expect("Unable to find `DebugCategory` with name \"GST_PERFORMANCE\"");
@ -486,11 +488,11 @@ mod tests {
#[test] #[test]
fn new_and_log() { fn new_and_log() {
::init().unwrap(); crate::init().unwrap();
let cat = DebugCategory::new( let cat = DebugCategory::new(
"test-cat", "test-cat",
::DebugColorFlags::empty(), crate::DebugColorFlags::empty(),
Some("some debug category"), Some("some debug category"),
); );
@ -503,7 +505,7 @@ mod tests {
gst_trace!(cat, "meh"); gst_trace!(cat, "meh");
gst_memdump!(cat, "meh"); gst_memdump!(cat, "meh");
let obj = ::Bin::new(Some("meh")); let obj = crate::Bin::new(Some("meh"));
gst_error!(cat, obj: &obj, "meh"); gst_error!(cat, obj: &obj, "meh");
gst_warning!(cat, obj: &obj, "meh"); gst_warning!(cat, obj: &obj, "meh");
gst_fixme!(cat, obj: &obj, "meh"); gst_fixme!(cat, obj: &obj, "meh");
@ -516,15 +518,15 @@ mod tests {
#[test] #[test]
fn log_handler() { fn log_handler() {
::init().unwrap(); crate::init().unwrap();
let cat = DebugCategory::new( let cat = DebugCategory::new(
"test-cat-log", "test-cat-log",
::DebugColorFlags::empty(), crate::DebugColorFlags::empty(),
Some("some debug category"), Some("some debug category"),
); );
cat.set_threshold(DebugLevel::Info); cat.set_threshold(DebugLevel::Info);
let obj = ::Bin::new(Some("meh")); let obj = crate::Bin::new(Some("meh"));
let (sender, receiver) = mpsc::channel(); let (sender, receiver) = mpsc::channel();

View file

@ -13,28 +13,25 @@ use std::ops;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
use gst_sys;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlibPtr};
use AllocationParams; use crate::AllocationParams;
use Allocator; use crate::Allocator;
use MemoryFlags; use crate::MemoryFlags;
gst_define_mini_object_wrapper!(Memory, MemoryRef, gst_sys::GstMemory, || { gst_define_mini_object_wrapper!(Memory, MemoryRef, ffi::GstMemory, || {
gst_sys::gst_memory_get_type() ffi::gst_memory_get_type()
}); });
pub struct MemoryMap<'a, T> { pub struct MemoryMap<'a, T> {
memory: &'a MemoryRef, memory: &'a MemoryRef,
map_info: gst_sys::GstMapInfo, map_info: ffi::GstMapInfo,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
pub struct MappedMemory<T> { pub struct MappedMemory<T> {
memory: Option<Memory>, memory: Option<Memory>,
map_info: gst_sys::GstMapInfo, map_info: ffi::GstMapInfo,
phantom: PhantomData<T>, phantom: PhantomData<T>,
} }
@ -63,7 +60,7 @@ pub enum Readable {}
pub enum Writable {} pub enum Writable {}
impl Memory { impl Memory {
unsafe extern "C" fn drop_box<T>(vec: glib_sys::gpointer) { unsafe extern "C" fn drop_box<T>(vec: glib::ffi::gpointer) {
let slice: Box<T> = Box::from_raw(vec as *mut T); let slice: Box<T> = Box::from_raw(vec as *mut T);
drop(slice); drop(slice);
} }
@ -71,7 +68,7 @@ impl Memory {
pub fn with_size(size: usize) -> Self { pub fn with_size(size: usize) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_allocator_alloc( from_glib_full(ffi::gst_allocator_alloc(
ptr::null_mut(), ptr::null_mut(),
size, size,
ptr::null_mut(), ptr::null_mut(),
@ -82,7 +79,7 @@ impl Memory {
pub fn with_size_and_params(size: usize, params: &AllocationParams) -> Self { pub fn with_size_and_params(size: usize, params: &AllocationParams) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_allocator_alloc( from_glib_full(ffi::gst_allocator_alloc(
ptr::null_mut(), ptr::null_mut(),
size, size,
params.as_ptr() as *mut _, params.as_ptr() as *mut _,
@ -99,13 +96,13 @@ impl Memory {
(slice.len(), slice.as_ptr()) (slice.len(), slice.as_ptr())
}; };
let user_data = Box::into_raw(b); let user_data = Box::into_raw(b);
from_glib_full(gst_sys::gst_memory_new_wrapped( from_glib_full(ffi::gst_memory_new_wrapped(
gst_sys::GST_MEMORY_FLAG_READONLY, ffi::GST_MEMORY_FLAG_READONLY,
data as glib_sys::gpointer, data as glib::ffi::gpointer,
size, size,
0, 0,
size, size,
user_data as glib_sys::gpointer, user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>), Some(Self::drop_box::<T>),
)) ))
} }
@ -121,13 +118,13 @@ impl Memory {
(slice.len(), slice.as_mut_ptr()) (slice.len(), slice.as_mut_ptr())
}; };
let user_data = Box::into_raw(b); let user_data = Box::into_raw(b);
from_glib_full(gst_sys::gst_memory_new_wrapped( from_glib_full(ffi::gst_memory_new_wrapped(
0, 0,
data as glib_sys::gpointer, data as glib::ffi::gpointer,
size, size,
0, 0,
size, size,
user_data as glib_sys::gpointer, user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>), Some(Self::drop_box::<T>),
)) ))
} }
@ -136,10 +133,10 @@ impl Memory {
pub fn into_mapped_memory_readable(self) -> Result<MappedMemory<Readable>, Self> { pub fn into_mapped_memory_readable(self) -> Result<MappedMemory<Readable>, Self> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res: bool = from_glib(gst_sys::gst_memory_map( let res: bool = from_glib(ffi::gst_memory_map(
self.as_mut_ptr(), self.as_mut_ptr(),
map_info.as_mut_ptr(), map_info.as_mut_ptr(),
gst_sys::GST_MAP_READ, ffi::GST_MAP_READ,
)); ));
if res { if res {
Ok(MappedMemory { Ok(MappedMemory {
@ -156,10 +153,10 @@ impl Memory {
pub fn into_mapped_memory_writable(self) -> Result<MappedMemory<Writable>, Self> { pub fn into_mapped_memory_writable(self) -> Result<MappedMemory<Writable>, Self> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res: bool = from_glib(gst_sys::gst_memory_map( let res: bool = from_glib(ffi::gst_memory_map(
self.as_mut_ptr(), self.as_mut_ptr(),
map_info.as_mut_ptr(), map_info.as_mut_ptr(),
gst_sys::GST_MAP_READWRITE, ffi::GST_MAP_READWRITE,
)); ));
if res { if res {
Ok(MappedMemory { Ok(MappedMemory {
@ -216,7 +213,7 @@ impl MemoryRef {
}; };
assert!(offset + pos_sz < (self.get_maxsize() as isize)); assert!(offset + pos_sz < (self.get_maxsize() as isize));
unsafe { unsafe {
from_glib_full(gst_sys::gst_memory_copy( from_glib_full(ffi::gst_memory_copy(
self.as_mut_ptr(), self.as_mut_ptr(),
offset, offset,
match size { match size {
@ -230,7 +227,7 @@ impl MemoryRef {
pub fn is_span(&self, mem2: &MemoryRef) -> Option<usize> { pub fn is_span(&self, mem2: &MemoryRef) -> Option<usize> {
unsafe { unsafe {
let mut offset = mem::MaybeUninit::uninit(); let mut offset = mem::MaybeUninit::uninit();
let res = from_glib(gst_sys::gst_memory_is_span( let res = from_glib(ffi::gst_memory_is_span(
self.as_mut_ptr(), self.as_mut_ptr(),
mem2.as_mut_ptr(), mem2.as_mut_ptr(),
offset.as_mut_ptr(), offset.as_mut_ptr(),
@ -245,7 +242,7 @@ impl MemoryRef {
pub fn is_type(&self, mem_type: &str) -> bool { pub fn is_type(&self, mem_type: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_memory_is_type( from_glib(ffi::gst_memory_is_type(
self.as_mut_ptr(), self.as_mut_ptr(),
mem_type.to_glib_none().0, mem_type.to_glib_none().0,
)) ))
@ -255,19 +252,16 @@ impl MemoryRef {
pub fn map_readable(&self) -> Result<MemoryMap<Readable>, glib::BoolError> { pub fn map_readable(&self) -> Result<MemoryMap<Readable>, glib::BoolError> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_memory_map( let res =
self.as_mut_ptr(), ffi::gst_memory_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
map_info.as_mut_ptr(), if res == glib::ffi::GTRUE {
gst_sys::GST_MAP_READ,
);
if res == glib_sys::GTRUE {
Ok(MemoryMap { Ok(MemoryMap {
memory: self, memory: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } else {
Err(glib_bool_error!("Failed to map memory readable")) Err(glib::glib_bool_error!("Failed to map memory readable"))
} }
} }
} }
@ -275,19 +269,19 @@ impl MemoryRef {
pub fn map_writable(&mut self) -> Result<MemoryMap<Writable>, glib::BoolError> { pub fn map_writable(&mut self) -> Result<MemoryMap<Writable>, glib::BoolError> {
unsafe { unsafe {
let mut map_info = mem::MaybeUninit::zeroed(); let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_memory_map( let res = ffi::gst_memory_map(
self.as_mut_ptr(), self.as_mut_ptr(),
map_info.as_mut_ptr(), map_info.as_mut_ptr(),
gst_sys::GST_MAP_READWRITE, ffi::GST_MAP_READWRITE,
); );
if res == glib_sys::GTRUE { if res == glib::ffi::GTRUE {
Ok(MemoryMap { Ok(MemoryMap {
memory: self, memory: self,
map_info: map_info.assume_init(), map_info: map_info.assume_init(),
phantom: PhantomData, phantom: PhantomData,
}) })
} else { } else {
Err(glib_bool_error!("Failed to map memory writable")) Err(glib::glib_bool_error!("Failed to map memory writable"))
} }
} }
} }
@ -299,7 +293,7 @@ impl MemoryRef {
}; };
assert!(offset + pos_sz < (self.get_maxsize() as isize)); assert!(offset + pos_sz < (self.get_maxsize() as isize));
unsafe { unsafe {
from_glib_full(gst_sys::gst_memory_share( from_glib_full(ffi::gst_memory_share(
self.as_ptr() as *mut _, self.as_ptr() as *mut _,
offset, offset,
match size { match size {
@ -312,7 +306,7 @@ impl MemoryRef {
pub fn resize(&mut self, offset: isize, size: usize) { pub fn resize(&mut self, offset: isize, size: usize) {
assert!(offset + (size as isize) < (self.get_maxsize() as isize)); assert!(offset + (size as isize) < (self.get_maxsize() as isize));
unsafe { gst_sys::gst_memory_resize(self.as_mut_ptr(), offset, size) } unsafe { ffi::gst_memory_resize(self.as_mut_ptr(), offset, size) }
} }
pub fn dump(&self, size: Option<usize>) -> Dump { pub fn dump(&self, size: Option<usize>) -> Dump {
@ -385,7 +379,7 @@ impl<'a, T> Eq for MemoryMap<'a, T> {}
impl<'a, T> Drop for MemoryMap<'a, T> { impl<'a, T> Drop for MemoryMap<'a, T> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
gst_sys::gst_memory_unmap(self.memory.as_mut_ptr(), &mut self.map_info); ffi::gst_memory_unmap(self.memory.as_mut_ptr(), &mut self.map_info);
} }
} }
} }
@ -409,7 +403,7 @@ impl<T> MappedMemory<T> {
pub fn into_memory(mut self) -> Memory { pub fn into_memory(mut self) -> Memory {
let memory = self.memory.take().unwrap(); let memory = self.memory.take().unwrap();
unsafe { unsafe {
gst_sys::gst_memory_unmap(memory.as_mut_ptr(), &mut self.map_info); ffi::gst_memory_unmap(memory.as_mut_ptr(), &mut self.map_info);
} }
memory memory
@ -452,7 +446,7 @@ impl<T> Drop for MappedMemory<T> {
fn drop(&mut self) { fn drop(&mut self) {
if let Some(ref memory) = self.memory { if let Some(ref memory) = self.memory {
unsafe { unsafe {
gst_sys::gst_memory_unmap(memory.as_mut_ptr(), &mut self.map_info); ffi::gst_memory_unmap(memory.as_mut_ptr(), &mut self.map_info);
} }
} }
} }
@ -515,15 +509,15 @@ impl<'a> fmt::Debug for Dump<'a> {
mod tests { mod tests {
#[test] #[test]
fn test_dump() { fn test_dump() {
::init().unwrap(); crate::init().unwrap();
let mem = ::Memory::from_slice(vec![1, 2, 3, 4]); let mem = crate::Memory::from_slice(vec![1, 2, 3, 4]);
println!("{}", mem.dump(Some(mem.get_size()))); println!("{}", mem.dump(Some(mem.get_size())));
let mem = ::Memory::from_slice(vec![1, 2, 3, 4]); let mem = crate::Memory::from_slice(vec![1, 2, 3, 4]);
println!("{:?}", mem.dump(Some(2))); println!("{:?}", mem.dump(Some(2)));
let mem = ::Memory::from_slice(vec![0; 64]); let mem = crate::Memory::from_slice(vec![0; 64]);
dbg!(mem.dump(None)); dbg!(mem.dump(None));
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -10,25 +10,22 @@ use std::fmt;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops; use std::ops;
use Buffer; use crate::Buffer;
use BufferRef; use crate::BufferRef;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use Caps; use crate::Caps;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use CapsRef; use crate::CapsRef;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use ClockTime; use crate::ClockTime;
use glib;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use glib::translate::ToGlib; use glib::translate::ToGlib;
use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr}; use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr};
use glib_sys;
use gst_sys;
pub unsafe trait MetaAPI: Sync + Send + Sized { pub unsafe trait MetaAPI: Sync + Send + Sized {
type GstType; type GstType;
@ -42,7 +39,7 @@ pub unsafe trait MetaAPI: Sync + Send + Sized {
if meta_api != glib::Type::Invalid { if meta_api != glib::Type::Invalid {
assert_eq!( assert_eq!(
meta_api, meta_api,
from_glib((*(*(ptr as *const gst_sys::GstMeta)).info).api) from_glib((*(*(ptr as *const ffi::GstMeta)).info).api)
) )
} }
@ -62,7 +59,7 @@ pub unsafe trait MetaAPI: Sync + Send + Sized {
if meta_api != glib::Type::Invalid { if meta_api != glib::Type::Invalid {
assert_eq!( assert_eq!(
meta_api, meta_api,
from_glib((*(*(ptr as *const gst_sys::GstMeta)).info).api) from_glib((*(*(ptr as *const ffi::GstMeta)).info).api)
) )
} }
@ -149,7 +146,7 @@ impl<'a, T: MetaAPI, U> AsRef<MetaRef<'a, T>> for MetaRefMut<'a, T, U> {
impl<'a, T: MetaAPI> MetaRef<'a, T> { impl<'a, T: MetaAPI> MetaRef<'a, T> {
pub fn get_api(&self) -> glib::Type { pub fn get_api(&self) -> glib::Type {
unsafe { unsafe {
let meta = self.meta as *const _ as *const gst_sys::GstMeta; let meta = self.meta as *const _ as *const ffi::GstMeta;
let info = (*meta).info; let info = (*meta).info;
glib::Type::from_glib((*info).api) glib::Type::from_glib((*info).api)
} }
@ -159,8 +156,8 @@ impl<'a, T: MetaAPI> MetaRef<'a, T> {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn get_seqnum(&self) -> MetaSeqnum { pub fn get_seqnum(&self) -> MetaSeqnum {
unsafe { unsafe {
let meta = self.meta as *const _ as *const gst_sys::GstMeta; let meta = self.meta as *const _ as *const ffi::GstMeta;
MetaSeqnum(gst_sys::gst_meta_get_seqnum(meta)) MetaSeqnum(ffi::gst_meta_get_seqnum(meta))
} }
} }
@ -185,7 +182,7 @@ impl<'a> MetaRef<'a, Meta> {
impl<'a, T: MetaAPI, U> MetaRefMut<'a, T, U> { impl<'a, T: MetaAPI, U> MetaRefMut<'a, T, U> {
pub fn get_api(&self) -> glib::Type { pub fn get_api(&self) -> glib::Type {
unsafe { unsafe {
let meta = self.meta as *const _ as *const gst_sys::GstMeta; let meta = self.meta as *const _ as *const ffi::GstMeta;
let info = (*meta).info; let info = (*meta).info;
glib::Type::from_glib((*info).api) glib::Type::from_glib((*info).api)
} }
@ -195,8 +192,8 @@ impl<'a, T: MetaAPI, U> MetaRefMut<'a, T, U> {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn get_seqnum(&self) -> u64 { pub fn get_seqnum(&self) -> u64 {
unsafe { unsafe {
let meta = self.meta as *const _ as *const gst_sys::GstMeta; let meta = self.meta as *const _ as *const ffi::GstMeta;
gst_sys::gst_meta_get_seqnum(meta) ffi::gst_meta_get_seqnum(meta)
} }
} }
@ -212,11 +209,11 @@ impl<'a, T: MetaAPI, U> MetaRefMut<'a, T, U> {
impl<'a, T: MetaAPI> MetaRefMut<'a, T, Standalone> { impl<'a, T: MetaAPI> MetaRefMut<'a, T, Standalone> {
pub fn remove(mut self) { pub fn remove(mut self) {
unsafe { unsafe {
let res = gst_sys::gst_buffer_remove_meta( let res = ffi::gst_buffer_remove_meta(
self.buffer.as_mut_ptr(), self.buffer.as_mut_ptr(),
self.as_mut_ptr() as *mut gst_sys::GstMeta, self.as_mut_ptr() as *mut ffi::GstMeta,
); );
assert_ne!(res, glib_sys::GFALSE); assert_ne!(res, glib::ffi::GFALSE);
} }
} }
} }
@ -235,7 +232,7 @@ impl<'a, U> MetaRefMut<'a, Meta, U> {
} }
#[repr(transparent)] #[repr(transparent)]
pub struct Meta(gst_sys::GstMeta); pub struct Meta(ffi::GstMeta);
unsafe impl Send for Meta {} unsafe impl Send for Meta {}
unsafe impl Sync for Meta {} unsafe impl Sync for Meta {}
@ -247,7 +244,7 @@ impl Meta {
} }
unsafe impl MetaAPI for Meta { unsafe impl MetaAPI for Meta {
type GstType = gst_sys::GstMeta; type GstType = ffi::GstMeta;
fn get_meta_api() -> glib::Type { fn get_meta_api() -> glib::Type {
glib::Type::Invalid glib::Type::Invalid
@ -263,7 +260,7 @@ impl fmt::Debug for Meta {
} }
#[repr(transparent)] #[repr(transparent)]
pub struct ParentBufferMeta(gst_sys::GstParentBufferMeta); pub struct ParentBufferMeta(ffi::GstParentBufferMeta);
unsafe impl Send for ParentBufferMeta {} unsafe impl Send for ParentBufferMeta {}
unsafe impl Sync for ParentBufferMeta {} unsafe impl Sync for ParentBufferMeta {}
@ -272,7 +269,7 @@ impl ParentBufferMeta {
pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> { pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let meta = gst_sys::gst_buffer_add_parent_buffer_meta( let meta = ffi::gst_buffer_add_parent_buffer_meta(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
parent.to_glib_none().0, parent.to_glib_none().0,
); );
@ -291,10 +288,10 @@ impl ParentBufferMeta {
} }
unsafe impl MetaAPI for ParentBufferMeta { unsafe impl MetaAPI for ParentBufferMeta {
type GstType = gst_sys::GstParentBufferMeta; type GstType = ffi::GstParentBufferMeta;
fn get_meta_api() -> glib::Type { fn get_meta_api() -> glib::Type {
unsafe { from_glib(gst_sys::gst_parent_buffer_meta_api_get_type()) } unsafe { from_glib(ffi::gst_parent_buffer_meta_api_get_type()) }
} }
} }
@ -307,36 +304,35 @@ impl fmt::Debug for ParentBufferMeta {
} }
#[repr(transparent)] #[repr(transparent)]
pub struct ProtectionMeta(gst_sys::GstProtectionMeta); pub struct ProtectionMeta(ffi::GstProtectionMeta);
unsafe impl Send for ProtectionMeta {} unsafe impl Send for ProtectionMeta {}
unsafe impl Sync for ProtectionMeta {} unsafe impl Sync for ProtectionMeta {}
impl ProtectionMeta { impl ProtectionMeta {
pub fn add(buffer: &mut BufferRef, info: ::Structure) -> MetaRefMut<Self, Standalone> { pub fn add(buffer: &mut BufferRef, info: crate::Structure) -> MetaRefMut<Self, Standalone> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let meta = let meta = ffi::gst_buffer_add_protection_meta(buffer.as_mut_ptr(), info.into_ptr());
gst_sys::gst_buffer_add_protection_meta(buffer.as_mut_ptr(), info.into_ptr());
Self::from_mut_ptr(buffer, meta) Self::from_mut_ptr(buffer, meta)
} }
} }
pub fn get_info(&self) -> &::StructureRef { pub fn get_info(&self) -> &crate::StructureRef {
unsafe { ::StructureRef::from_glib_borrow(self.0.info) } unsafe { crate::StructureRef::from_glib_borrow(self.0.info) }
} }
pub fn get_info_mut(&mut self) -> &mut ::StructureRef { pub fn get_info_mut(&mut self) -> &mut crate::StructureRef {
unsafe { ::StructureRef::from_glib_borrow_mut(self.0.info) } unsafe { crate::StructureRef::from_glib_borrow_mut(self.0.info) }
} }
} }
unsafe impl MetaAPI for ProtectionMeta { unsafe impl MetaAPI for ProtectionMeta {
type GstType = gst_sys::GstProtectionMeta; type GstType = ffi::GstProtectionMeta;
fn get_meta_api() -> glib::Type { fn get_meta_api() -> glib::Type {
unsafe { from_glib(gst_sys::gst_protection_meta_api_get_type()) } unsafe { from_glib(ffi::gst_protection_meta_api_get_type()) }
} }
} }
@ -351,7 +347,7 @@ impl fmt::Debug for ProtectionMeta {
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
#[repr(transparent)] #[repr(transparent)]
pub struct ReferenceTimestampMeta(gst_sys::GstReferenceTimestampMeta); pub struct ReferenceTimestampMeta(ffi::GstReferenceTimestampMeta);
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
@ -371,7 +367,7 @@ impl ReferenceTimestampMeta {
) -> MetaRefMut<'a, Self, Standalone> { ) -> MetaRefMut<'a, Self, Standalone> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let meta = gst_sys::gst_buffer_add_reference_timestamp_meta( let meta = ffi::gst_buffer_add_reference_timestamp_meta(
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
reference.to_glib_none().0, reference.to_glib_none().0,
timestamp.to_glib(), timestamp.to_glib(),
@ -402,10 +398,10 @@ impl ReferenceTimestampMeta {
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
unsafe impl MetaAPI for ReferenceTimestampMeta { unsafe impl MetaAPI for ReferenceTimestampMeta {
type GstType = gst_sys::GstReferenceTimestampMeta; type GstType = ffi::GstReferenceTimestampMeta;
fn get_meta_api() -> glib::Type { fn get_meta_api() -> glib::Type {
unsafe { from_glib(gst_sys::gst_reference_timestamp_meta_api_get_type()) } unsafe { from_glib(ffi::gst_reference_timestamp_meta_api_get_type()) }
} }
} }
@ -427,10 +423,10 @@ mod tests {
#[test] #[test]
fn test_add_get_iterate_meta() { fn test_add_get_iterate_meta() {
::init().unwrap(); crate::init().unwrap();
let mut buffer = ::Buffer::new(); let mut buffer = crate::Buffer::new();
let parent = ::Buffer::new(); let parent = crate::Buffer::new();
{ {
let meta = ParentBufferMeta::add(buffer.get_mut().unwrap(), &parent); let meta = ParentBufferMeta::add(buffer.get_mut().unwrap(), &parent);
unsafe { unsafe {

View file

@ -8,47 +8,47 @@
#[macro_export] #[macro_export]
macro_rules! gst_define_mini_object_wrapper( macro_rules! gst_define_mini_object_wrapper(
($name:ident, $ref_name:ident, $gst_sys_name:path, $get_type:expr) => { ($name:ident, $ref_name:ident, $ffi_name:path, $get_type:expr) => {
pub struct $name { pub struct $name {
obj: ::std::ptr::NonNull<$ref_name>, obj: std::ptr::NonNull<$ref_name>,
} }
#[repr(transparent)] #[repr(transparent)]
pub struct $ref_name($gst_sys_name); pub struct $ref_name($ffi_name);
impl $name { impl $name {
pub unsafe fn from_glib_none(ptr: *const $gst_sys_name) -> Self { pub unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(!ptr.is_null()); assert!(!ptr.is_null());
$crate::gst_sys::gst_mini_object_ref(ptr as *mut $crate::gst_sys::GstMiniObject); $crate::ffi::gst_mini_object_ref(ptr as *mut $crate::ffi::GstMiniObject);
$name { $name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name), obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name as *mut $ref_name),
} }
} }
pub unsafe fn from_glib_full(ptr: *const $gst_sys_name) -> Self { pub unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(!ptr.is_null()); assert!(!ptr.is_null());
$name { $name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name), obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name as *mut $ref_name),
} }
} }
pub unsafe fn from_glib_borrow(ptr: *const $gst_sys_name) -> $crate::glib::translate::Borrowed<Self> { pub unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
skip_assert_initialized!(); skip_assert_initialized!();
assert!(!ptr.is_null()); assert!(!ptr.is_null());
$crate::glib::translate::Borrowed::new($name { $crate::glib::translate::Borrowed::new($name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name), obj: std::ptr::NonNull::new_unchecked(ptr as *mut $ffi_name as *mut $ref_name),
}) })
} }
pub unsafe fn replace_ptr(&mut self, ptr: *mut $gst_sys_name) { pub unsafe fn replace_ptr(&mut self, ptr: *mut $ffi_name) {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
self.obj = ::std::ptr::NonNull::new_unchecked(ptr as *mut $ref_name); self.obj = std::ptr::NonNull::new_unchecked(ptr as *mut $ref_name);
} }
pub fn make_mut(&mut self) -> &mut $ref_name { pub fn make_mut(&mut self) -> &mut $ref_name {
@ -57,10 +57,10 @@ macro_rules! gst_define_mini_object_wrapper(
return self.obj.as_mut(); return self.obj.as_mut();
} }
let ptr = $crate::gst_sys::gst_mini_object_make_writable( let ptr = $crate::ffi::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject
); );
self.replace_ptr(ptr as *mut $gst_sys_name); self.replace_ptr(ptr as *mut $ffi_name);
assert!(self.is_writable()); assert!(self.is_writable());
self.obj.as_mut() self.obj.as_mut()
@ -77,14 +77,14 @@ macro_rules! gst_define_mini_object_wrapper(
pub fn is_writable(&self) -> bool { pub fn is_writable(&self) -> bool {
unsafe { unsafe {
$crate::glib::translate::from_glib($crate::gst_sys::gst_mini_object_is_writable( $crate::glib::translate::from_glib($crate::ffi::gst_mini_object_is_writable(
self.as_ptr() as *const $crate::gst_sys::GstMiniObject self.as_ptr() as *const $crate::ffi::GstMiniObject
)) ))
} }
} }
pub unsafe fn into_ptr(self) -> *mut $gst_sys_name { pub unsafe fn into_ptr(self) -> *mut $ffi_name {
let s = ::std::mem::ManuallyDrop::new(self); let s = std::mem::ManuallyDrop::new(self);
s.as_mut_ptr() s.as_mut_ptr()
} }
} }
@ -98,12 +98,12 @@ macro_rules! gst_define_mini_object_wrapper(
impl Drop for $name { impl Drop for $name {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
$crate::gst_sys::gst_mini_object_unref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject); $crate::ffi::gst_mini_object_unref(self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject);
} }
} }
} }
impl ::std::ops::Deref for $name { impl std::ops::Deref for $name {
type Target = $ref_name; type Target = $ref_name;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@ -117,7 +117,7 @@ macro_rules! gst_define_mini_object_wrapper(
} }
} }
impl ::std::borrow::Borrow<$ref_name> for $name { impl std::borrow::Borrow<$ref_name> for $name {
fn borrow(&self) -> &$ref_name { fn borrow(&self) -> &$ref_name {
&*self &*self
} }
@ -129,71 +129,71 @@ macro_rules! gst_define_mini_object_wrapper(
} }
} }
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *const $gst_sys_name> for $name { impl<'a> $crate::glib::translate::ToGlibPtr<'a, *const $ffi_name> for $name {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *const $gst_sys_name, Self> { fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *const $ffi_name, Self> {
$crate::glib::translate::Stash(unsafe { self.as_ptr() }, self) $crate::glib::translate::Stash(unsafe { self.as_ptr() }, self)
} }
fn to_glib_full(&self) -> *const $gst_sys_name { fn to_glib_full(&self) -> *const $ffi_name {
unsafe { unsafe {
$crate::gst_sys::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject); $crate::ffi::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject);
self.as_ptr() self.as_ptr()
} }
} }
} }
impl<'a> $crate::glib::translate::ToGlibPtr<'a, *mut $gst_sys_name> for $name { impl<'a> $crate::glib::translate::ToGlibPtr<'a, *mut $ffi_name> for $name {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *mut $gst_sys_name, Self> { fn to_glib_none(&'a self) -> $crate::glib::translate::Stash<'a, *mut $ffi_name, Self> {
$crate::glib::translate::Stash(unsafe { self.as_mut_ptr() }, self) $crate::glib::translate::Stash(unsafe { self.as_mut_ptr() }, self)
} }
fn to_glib_full(&self) -> *mut $gst_sys_name { fn to_glib_full(&self) -> *mut $ffi_name {
unsafe { unsafe {
$crate::gst_sys::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject); $crate::ffi::gst_mini_object_ref(self.as_mut_ptr() as *mut $crate::ffi::GstMiniObject);
self.as_mut_ptr() self.as_mut_ptr()
} }
} }
} }
impl<'a> $crate::glib::translate::ToGlibPtrMut<'a, *mut $gst_sys_name> for $name { impl<'a> $crate::glib::translate::ToGlibPtrMut<'a, *mut $ffi_name> for $name {
type Storage = &'a mut Self; type Storage = &'a mut Self;
fn to_glib_none_mut(&'a mut self) -> $crate::glib::translate::StashMut<*mut $gst_sys_name, Self> { fn to_glib_none_mut(&'a mut self) -> $crate::glib::translate::StashMut<*mut $ffi_name, Self> {
self.make_mut(); self.make_mut();
$crate::glib::translate::StashMut(unsafe { self.as_mut_ptr() }, self) $crate::glib::translate::StashMut(unsafe { self.as_mut_ptr() }, self)
} }
} }
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *mut *mut $gst_sys_name> for $name { impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *mut *mut $ffi_name> for $name {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
type Storage = ( type Storage = (
Vec<$crate::glib::translate::Stash<'a, *mut $gst_sys_name, Self>>, Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, Self>>,
Option<Vec<*mut $gst_sys_name>>, Option<Vec<*mut $ffi_name>>,
); );
fn to_glib_none_from_slice(t: &'a [$name]) -> (*mut *mut $gst_sys_name, Self::Storage) { fn to_glib_none_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
skip_assert_initialized!(); skip_assert_initialized!();
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect(); let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).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(::std::ptr::null_mut() as *mut $gst_sys_name); v_ptr.push(std::ptr::null_mut() as *mut $ffi_name);
(v_ptr.as_ptr() as *mut *mut $gst_sys_name, (v, Some(v_ptr))) (v_ptr.as_ptr() as *mut *mut $ffi_name, (v, Some(v_ptr)))
} }
fn to_glib_container_from_slice(t: &'a [$name]) -> (*mut *mut $gst_sys_name, Self::Storage) { fn to_glib_container_from_slice(t: &'a [$name]) -> (*mut *mut $ffi_name, Self::Storage) {
skip_assert_initialized!(); skip_assert_initialized!();
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect(); let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect();
let v_ptr = unsafe { let v_ptr = unsafe {
let v_ptr = $crate::glib_sys::g_malloc0(::std::mem::size_of::<*mut $gst_sys_name>() * t.len() + 1) let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
as *mut *mut $gst_sys_name; as *mut *mut $ffi_name;
for (i, s) in v.iter().enumerate() { for (i, s) in v.iter().enumerate() {
::std::ptr::write(v_ptr.add(i), s.0); std::ptr::write(v_ptr.add(i), s.0);
} }
v_ptr v_ptr
@ -202,14 +202,14 @@ macro_rules! gst_define_mini_object_wrapper(
(v_ptr, (v, None)) (v_ptr, (v, None))
} }
fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $gst_sys_name { fn to_glib_full_from_slice(t: &[$name]) -> *mut *mut $ffi_name {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let v_ptr = $crate::glib_sys::g_malloc0(::std::mem::size_of::<*mut $gst_sys_name>() * t.len() + 1) let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
as *mut *mut $gst_sys_name; as *mut *mut $ffi_name;
for (i, s) in t.iter().enumerate() { 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 v_ptr
@ -217,152 +217,152 @@ macro_rules! gst_define_mini_object_wrapper(
} }
} }
impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *const *mut $gst_sys_name> impl<'a> $crate::glib::translate::ToGlibContainerFromSlice<'a, *const *mut $ffi_name>
for $name for $name
{ {
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
type Storage = ( type Storage = (
Vec<$crate::glib::translate::Stash<'a, *mut $gst_sys_name, $name>>, Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, $name>>,
Option<Vec<*mut $gst_sys_name>>, Option<Vec<*mut $ffi_name>>,
); );
fn to_glib_none_from_slice(t: &'a [$name]) -> (*const *mut $gst_sys_name, Self::Storage) { fn to_glib_none_from_slice(t: &'a [$name]) -> (*const *mut $ffi_name, Self::Storage) {
skip_assert_initialized!(); skip_assert_initialized!();
let (ptr, stash) = let (ptr, stash) =
$crate::glib::translate::ToGlibContainerFromSlice::<'a, *mut *mut $gst_sys_name>::to_glib_none_from_slice(t); $crate::glib::translate::ToGlibContainerFromSlice::<'a, *mut *mut $ffi_name>::to_glib_none_from_slice(t);
(ptr as *const *mut $gst_sys_name, stash) (ptr as *const *mut $ffi_name, stash)
} }
fn to_glib_container_from_slice(_: &'a [$name]) -> (*const *mut $gst_sys_name, Self::Storage) { fn to_glib_container_from_slice(_: &'a [$name]) -> (*const *mut $ffi_name, Self::Storage) {
skip_assert_initialized!(); skip_assert_initialized!();
// Can't have consumer free a *const pointer // Can't have consumer free a *const pointer
unimplemented!() unimplemented!()
} }
fn to_glib_full_from_slice(_: &[$name]) -> *const *mut $gst_sys_name { fn to_glib_full_from_slice(_: &[$name]) -> *const *mut $ffi_name {
skip_assert_initialized!(); skip_assert_initialized!();
// Can't have consumer free a *const pointer // Can't have consumer free a *const pointer
unimplemented!() unimplemented!()
} }
} }
impl $crate::glib::translate::FromGlibPtrNone<*const $gst_sys_name> for $name { impl $crate::glib::translate::FromGlibPtrNone<*const $ffi_name> for $name {
unsafe fn from_glib_none(ptr: *const $gst_sys_name) -> Self { unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
Self::from_glib_none(ptr) Self::from_glib_none(ptr)
} }
} }
impl $crate::glib::translate::FromGlibPtrNone<*mut $gst_sys_name> for $name { impl $crate::glib::translate::FromGlibPtrNone<*mut $ffi_name> for $name {
unsafe fn from_glib_none(ptr: *mut $gst_sys_name) -> Self { unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
Self::from_glib_none(ptr) Self::from_glib_none(ptr)
} }
} }
impl $crate::glib::translate::FromGlibPtrFull<*const $gst_sys_name> for $name { impl $crate::glib::translate::FromGlibPtrFull<*const $ffi_name> for $name {
unsafe fn from_glib_full(ptr: *const $gst_sys_name) -> Self { unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
Self::from_glib_full(ptr) Self::from_glib_full(ptr)
} }
} }
impl $crate::glib::translate::FromGlibPtrFull<*mut $gst_sys_name> for $name { impl $crate::glib::translate::FromGlibPtrFull<*mut $ffi_name> for $name {
unsafe fn from_glib_full(ptr: *mut $gst_sys_name) -> Self { unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
Self::from_glib_full(ptr) Self::from_glib_full(ptr)
} }
} }
impl $crate::glib::translate::FromGlibPtrBorrow<*const $gst_sys_name> for $name { impl $crate::glib::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
unsafe fn from_glib_borrow(ptr: *const $gst_sys_name) -> $crate::glib::translate::Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
Self::from_glib_borrow(ptr) Self::from_glib_borrow(ptr)
} }
} }
impl $crate::glib::translate::FromGlibPtrBorrow<*mut $gst_sys_name> for $name { impl $crate::glib::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name {
unsafe fn from_glib_borrow(ptr: *mut $gst_sys_name) -> $crate::glib::translate::Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
Self::from_glib_borrow(ptr) Self::from_glib_borrow(ptr)
} }
} }
impl $crate::glib::translate::FromGlibContainerAsVec<*mut $gst_sys_name, *mut *mut $gst_sys_name> impl $crate::glib::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name>
for $name for $name
{ {
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $gst_sys_name, num: usize) -> Vec<Self> { unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
if num == 0 || ptr.is_null() { if num == 0 || ptr.is_null() {
return Vec::new(); return Vec::new();
} }
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($crate::glib::translate::from_glib_none(::std::ptr::read(ptr.add(i)))); res.push($crate::glib::translate::from_glib_none(std::ptr::read(ptr.add(i))));
} }
res res
} }
unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut $gst_sys_name, num: usize) -> Vec<Self> { unsafe fn from_glib_container_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
let res = $crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num); let res = $crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, num);
$crate::glib_sys::g_free(ptr as *mut _); $crate::glib::ffi::g_free(ptr as *mut _);
res res
} }
unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut $gst_sys_name, num: usize) -> Vec<Self> { unsafe fn from_glib_full_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
if num == 0 || ptr.is_null() { if num == 0 || ptr.is_null() {
return Vec::new(); return Vec::new();
} }
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($crate::glib::translate::from_glib_full(::std::ptr::read(ptr.add(i)))); res.push($crate::glib::translate::from_glib_full(std::ptr::read(ptr.add(i))));
} }
$crate::glib_sys::g_free(ptr as *mut _); $crate::glib::ffi::g_free(ptr as *mut _);
res res
} }
} }
impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $gst_sys_name, *mut *mut $gst_sys_name> impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name>
for $name for $name
{ {
unsafe fn from_glib_none_as_vec(ptr: *mut *mut $gst_sys_name) -> Vec<Self> { unsafe fn from_glib_none_as_vec(ptr: *mut *mut $ffi_name) -> Vec<Self> {
$crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr)) $crate::glib::translate::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 $gst_sys_name) -> Vec<Self> { unsafe fn from_glib_container_as_vec(ptr: *mut *mut $ffi_name) -> Vec<Self> {
$crate::glib::translate::FromGlibContainerAsVec::from_glib_container_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr)) $crate::glib::translate::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 $gst_sys_name) -> Vec<Self> { unsafe fn from_glib_full_as_vec(ptr: *mut *mut $ffi_name) -> Vec<Self> {
$crate::glib::translate::FromGlibContainerAsVec::from_glib_full_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr)) $crate::glib::translate::FromGlibContainerAsVec::from_glib_full_num_as_vec(ptr, glib::translate::c_ptr_array_len(ptr))
} }
} }
impl $crate::glib::translate::FromGlibContainerAsVec<*mut $gst_sys_name, *const *mut $gst_sys_name> impl $crate::glib::translate::FromGlibContainerAsVec<*mut $ffi_name, *const *mut $ffi_name>
for $name for $name
{ {
unsafe fn from_glib_none_num_as_vec(ptr: *const *mut $gst_sys_name, num: usize) -> Vec<Self> { unsafe fn from_glib_none_num_as_vec(ptr: *const *mut $ffi_name, num: usize) -> Vec<Self> {
$crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr as *mut *mut _, num) $crate::glib::translate::FromGlibContainerAsVec::from_glib_none_num_as_vec(ptr as *mut *mut _, num)
} }
unsafe fn from_glib_container_num_as_vec(_: *const *mut $gst_sys_name, _: usize) -> Vec<Self> { unsafe fn from_glib_container_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec<Self> {
// Can't free a *const // Can't free a *const
unimplemented!() unimplemented!()
} }
unsafe fn from_glib_full_num_as_vec(_: *const *mut $gst_sys_name, _: usize) -> Vec<Self> { unsafe fn from_glib_full_num_as_vec(_: *const *mut $ffi_name, _: usize) -> Vec<Self> {
// Can't free a *const // Can't free a *const
unimplemented!() unimplemented!()
} }
} }
impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $gst_sys_name, *const *mut $gst_sys_name> for $name impl $crate::glib::translate::FromGlibPtrArrayContainerAsVec<*mut $ffi_name, *const *mut $ffi_name> for $name
{ {
unsafe fn from_glib_none_as_vec(ptr: *const *mut $gst_sys_name) -> Vec<Self> { unsafe fn from_glib_none_as_vec(ptr: *const *mut $ffi_name) -> Vec<Self> {
$crate::glib::translate::FromGlibPtrArrayContainerAsVec::from_glib_none_as_vec(ptr as *mut *mut _) $crate::glib::translate::FromGlibPtrArrayContainerAsVec::from_glib_none_as_vec(ptr as *mut *mut _)
} }
unsafe fn from_glib_container_as_vec(_: *const *mut $gst_sys_name) -> Vec<Self> { unsafe fn from_glib_container_as_vec(_: *const *mut $ffi_name) -> Vec<Self> {
// Can't free a *const // Can't free a *const
unimplemented!() unimplemented!()
} }
unsafe fn from_glib_full_as_vec(_: *const *mut $gst_sys_name) -> Vec<Self> { unsafe fn from_glib_full_as_vec(_: *const *mut $ffi_name) -> Vec<Self> {
// Can't free a *const // Can't free a *const
unimplemented!() unimplemented!()
} }
@ -372,59 +372,59 @@ 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> {
let ptr = $crate::gobject_sys::g_value_get_boxed($crate::glib::translate::ToGlibPtr::to_glib_none(v).0); let ptr = $crate::glib::gobject_ffi::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) $crate::glib::translate::from_glib_none(ptr as *const $ffi_name)
} }
} }
impl $crate::glib::value::SetValue for $name { impl $crate::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) {
$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); $crate::glib::gobject_ffi::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, s.as_ptr() as $crate::glib::ffi::gpointer);
} }
} }
impl $crate::glib::value::SetValueOptional for $name { impl $crate::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>) {
if let Some(s) = s { 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); $crate::glib::gobject_ffi::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, s.as_ptr() as $crate::glib::ffi::gpointer);
} else { } else {
$crate::gobject_sys::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, ::std::ptr::null_mut()); $crate::glib::gobject_ffi::g_value_set_boxed($crate::glib::translate::ToGlibPtrMut::to_glib_none_mut(v).0, std::ptr::null_mut());
} }
} }
} }
impl $crate::glib::translate::GlibPtrDefault for $name { impl $crate::glib::translate::GlibPtrDefault for $name {
type GlibType = *mut $gst_sys_name; type GlibType = *mut $ffi_name;
} }
impl $ref_name { impl $ref_name {
pub unsafe fn as_ptr(&self) -> *const $gst_sys_name { pub unsafe fn as_ptr(&self) -> *const $ffi_name {
self as *const Self as *const $gst_sys_name self as *const Self as *const $ffi_name
} }
pub unsafe fn as_mut_ptr(&self) -> *mut $gst_sys_name { pub unsafe fn as_mut_ptr(&self) -> *mut $ffi_name {
self as *const Self as *mut $gst_sys_name self as *const Self as *mut $ffi_name
} }
pub unsafe fn from_ptr<'a>(ptr: *const $gst_sys_name) -> &'a Self { pub unsafe fn from_ptr<'a>(ptr: *const $ffi_name) -> &'a Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
&*(ptr as *const Self) &*(ptr as *const Self)
} }
pub unsafe fn from_mut_ptr<'a>(ptr: *mut $gst_sys_name) -> &'a mut Self { pub unsafe fn from_mut_ptr<'a>(ptr: *mut $ffi_name) -> &'a mut Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
assert_ne!( assert_ne!(
$crate::gst_sys::gst_mini_object_is_writable(ptr as *mut $crate::gst_sys::GstMiniObject), $crate::ffi::gst_mini_object_is_writable(ptr as *mut $crate::ffi::GstMiniObject),
$crate::glib_sys::GFALSE $crate::glib::ffi::GFALSE
); );
&mut *(ptr as *mut Self) &mut *(ptr as *mut Self)
} }
pub fn copy(&self) -> $name { pub fn copy(&self) -> $name {
unsafe { unsafe {
$name::from_glib_full($crate::gst_sys::gst_mini_object_copy( $name::from_glib_full($crate::ffi::gst_mini_object_copy(
self.as_ptr() as *const $crate::gst_sys::GstMiniObject self.as_ptr() as *const $crate::ffi::GstMiniObject
) as *const $gst_sys_name) ) as *const $ffi_name)
} }
} }
} }
@ -436,14 +436,14 @@ macro_rules! gst_define_mini_object_wrapper(
} }
impl $crate::glib::translate::GlibPtrDefault for $ref_name { impl $crate::glib::translate::GlibPtrDefault for $ref_name {
type GlibType = *mut $gst_sys_name; type GlibType = *mut $ffi_name;
} }
impl<'a> $crate::glib::value::FromValueOptional<'a> impl<'a> $crate::glib::value::FromValueOptional<'a>
for &'a $ref_name for &'a $ref_name
{ {
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> { unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
let ptr = gobject_sys::g_value_get_boxed($crate::glib::translate::ToGlibPtr::to_glib_none(v).0); let ptr = glib::gobject_ffi::g_value_get_boxed($crate::glib::translate::ToGlibPtr::to_glib_none(v).0);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {

View file

@ -6,19 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::object::{Cast, ObjectExt}; use glib::object::{Cast, ObjectExt};
use glib::signal::SignalHandlerId; use glib::signal::SignalHandlerId;
use glib::translate::*; use glib::translate::*;
use glib::IsA; use glib::IsA;
use gobject_sys; use crate::ClockTime;
use crate::ObjectFlags;
use ClockTime;
use ObjectFlags;
pub trait GstObjectExtManual: 'static { pub trait GstObjectExtManual: 'static {
fn connect_deep_notify<F: Fn(&Self, &::Object, &glib::ParamSpec) + Send + Sync + 'static>( fn connect_deep_notify<F: Fn(&Self, &crate::Object, &glib::ParamSpec) + Send + Sync + 'static>(
&self, &self,
name: Option<&str>, name: Option<&str>,
f: F, f: F,
@ -39,8 +36,10 @@ pub trait GstObjectExtManual: 'static {
) -> Result<(), glib::error::BoolError>; ) -> Result<(), glib::error::BoolError>;
} }
impl<O: IsA<::Object>> GstObjectExtManual for O { impl<O: IsA<crate::Object>> GstObjectExtManual for O {
fn connect_deep_notify<F: Fn(&Self, &::Object, &glib::ParamSpec) + Send + Sync + 'static>( fn connect_deep_notify<
F: Fn(&Self, &crate::Object, &glib::ParamSpec) + Send + Sync + 'static,
>(
&self, &self,
name: Option<&str>, name: Option<&str>,
f: F, f: F,
@ -52,7 +51,7 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
}; };
let obj: Borrowed<glib::Object> = let obj: Borrowed<glib::Object> =
unsafe { from_glib_borrow(self.as_ptr() as *mut gobject_sys::GObject) }; unsafe { from_glib_borrow(self.as_ptr() as *mut glib::gobject_ffi::GObject) };
obj.connect(signal_name.as_str(), false, move |values| { obj.connect(signal_name.as_str(), false, move |values| {
// It would be nice to display the actual signal name in the panic messages below, // It would be nice to display the actual signal name in the panic messages below,
@ -60,20 +59,20 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
// which seems too much for the messages of development errors // which seems too much for the messages of development errors
let obj: O = unsafe { let obj: O = unsafe {
values[0] values[0]
.get::<::Object>() .get::<crate::Object>()
.unwrap_or_else(|err| { .unwrap_or_else(|err| {
panic!("Object signal \"deep-notify\": values[0]: {}", err) panic!("Object signal \"deep-notify\": values[0]: {}", err)
}) })
.expect("Object signal \"deep-notify\": values[0] not defined") .expect("Object signal \"deep-notify\": values[0] not defined")
.unsafe_cast() .unsafe_cast()
}; };
let prop_obj: ::Object = values[1] let prop_obj: crate::Object = values[1]
.get() .get()
.unwrap_or_else(|err| panic!("Object signal \"deep-notify\": values[1]: {}", err)) .unwrap_or_else(|err| panic!("Object signal \"deep-notify\": values[1]: {}", err))
.expect("Object signal \"deep-notify\": values[1] not defined"); .expect("Object signal \"deep-notify\": values[1] not defined");
let pspec = unsafe { let pspec = unsafe {
let pspec = gobject_sys::g_value_get_param(values[2].to_glib_none().0); let pspec = glib::gobject_ffi::g_value_get_param(values[2].to_glib_none().0);
from_glib_none(pspec) from_glib_none(pspec)
}; };
@ -86,24 +85,24 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
fn set_object_flags(&self, flags: ObjectFlags) { fn set_object_flags(&self, flags: ObjectFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib(); (*ptr).flags |= flags.to_glib();
} }
} }
fn unset_object_flags(&self, flags: ObjectFlags) { fn unset_object_flags(&self, flags: ObjectFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib(); (*ptr).flags &= !flags.to_glib();
} }
} }
fn get_object_flags(&self) -> ObjectFlags { fn get_object_flags(&self) -> ObjectFlags {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags) from_glib((*ptr).flags)
} }
} }
@ -117,14 +116,14 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
) -> Result<(), glib::error::BoolError> { ) -> Result<(), glib::error::BoolError> {
let n_values = values.len() as u32; let n_values = values.len() as u32;
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_object_get_g_value_array( ffi::gst_object_get_g_value_array(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
property_name.to_glib_none().0, property_name.to_glib_none().0,
timestamp.to_glib(), timestamp.to_glib(),
interval.to_glib(), interval.to_glib(),
n_values, n_values,
values.as_mut_ptr() as *mut gobject_sys::GValue, values.as_mut_ptr() as *mut glib::gobject_ffi::GValue,
), ),
"Failed to get value array" "Failed to get value array"
) )
@ -135,15 +134,15 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use prelude::*; use crate::prelude::*;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
#[test] #[test]
fn test_deep_notify() { fn test_deep_notify() {
::init().unwrap(); crate::init().unwrap();
let bin = ::Bin::new(None); let bin = crate::Bin::new(None);
let identity = ::ElementFactory::make("identity", Some("id")).unwrap(); let identity = crate::ElementFactory::make("identity", Some("id")).unwrap();
bin.add(&identity).unwrap(); bin.add(&identity).unwrap();
let notify = Arc::new(Mutex::new(None)); let notify = Arc::new(Mutex::new(None));
@ -155,7 +154,7 @@ mod tests {
identity.set_property("silent", &false).unwrap(); identity.set_property("silent", &false).unwrap();
assert_eq!( assert_eq!(
*notify.lock().unwrap(), *notify.lock().unwrap(),
Some((identity.upcast::<::Object>(), "silent")) Some((identity.upcast::<crate::Object>(), "silent"))
); );
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -6,20 +6,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::PadTemplate;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use crate::StaticPadTemplate;
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use glib::translate::*; use glib::translate::*;
use PadTemplate;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use StaticPadTemplate;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use glib;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use gst_sys;
impl PadTemplate { impl PadTemplate {
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
@ -31,12 +24,12 @@ impl PadTemplate {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
Option::<_>::from_glib_none( Option::<_>::from_glib_none(
gst_sys::gst_pad_template_new_from_static_pad_template_with_gtype( ffi::gst_pad_template_new_from_static_pad_template_with_gtype(
mut_override(pad_template.to_glib_none().0), mut_override(pad_template.to_glib_none().0),
pad_type.to_glib(), pad_type.to_glib(),
), ),
) )
.ok_or_else(|| glib_bool_error!("Failed to create PadTemplate")) .ok_or_else(|| glib::glib_bool_error!("Failed to create PadTemplate"))
} }
} }
} }

View file

@ -6,9 +6,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::translate::*; use glib::translate::*;
use gst_sys;
pub trait GstParamSpecExt { pub trait GstParamSpecExt {
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
@ -25,9 +23,9 @@ pub trait GstParamSpecExt {
name: &str, name: &str,
nick: &str, nick: &str,
blurb: &str, blurb: &str,
min: ::Fraction, min: crate::Fraction,
max: ::Fraction, max: crate::Fraction,
default: ::Fraction, default: crate::Fraction,
flags: glib::ParamFlags, flags: glib::ParamFlags,
) -> Self; ) -> Self;
} }
@ -44,7 +42,7 @@ impl GstParamSpecExt for glib::ParamSpec {
) -> glib::ParamSpec { ) -> glib::ParamSpec {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_param_spec_array( from_glib_full(ffi::gst_param_spec_array(
name.to_glib_none().0, name.to_glib_none().0,
nick.to_glib_none().0, nick.to_glib_none().0,
blurb.to_glib_none().0, blurb.to_glib_none().0,
@ -58,14 +56,14 @@ impl GstParamSpecExt for glib::ParamSpec {
name: &str, name: &str,
nick: &str, nick: &str,
blurb: &str, blurb: &str,
min: ::Fraction, min: crate::Fraction,
max: ::Fraction, max: crate::Fraction,
default: ::Fraction, default: crate::Fraction,
flags: glib::ParamFlags, flags: glib::ParamFlags,
) -> glib::ParamSpec { ) -> glib::ParamSpec {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_param_spec_fraction( from_glib_full(ffi::gst_param_spec_fraction(
name.to_glib_none().0, name.to_glib_none().0,
nick.to_glib_none().0, nick.to_glib_none().0,
blurb.to_glib_none().0, blurb.to_glib_none().0,
@ -83,12 +81,11 @@ impl GstParamSpecExt for glib::ParamSpec {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use glib; use crate::prelude::*;
use prelude::*;
#[test] #[test]
fn test_trait() { fn test_trait() {
::init().unwrap(); crate::init().unwrap();
let _pspec = glib::ParamSpec::fraction( let _pspec = glib::ParamSpec::fraction(
"foo", "foo",

View file

@ -7,21 +7,19 @@
// except according to those terms. // except according to those terms.
use glib::translate::*; use glib::translate::*;
use gobject_sys;
use gst_sys;
glib_wrapper! { glib::glib_wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ParseContext(Boxed<gst_sys::GstParseContext>); pub struct ParseContext(Boxed<ffi::GstParseContext>);
match fn { match fn {
copy => |ptr| { copy => |ptr| {
gobject_sys::g_boxed_copy(gst_sys::gst_parse_context_get_type(), ptr as *mut _) as *mut gst_sys::GstParseContext glib::gobject_ffi::g_boxed_copy(ffi::gst_parse_context_get_type(), ptr as *mut _) as *mut ffi::GstParseContext
}, },
free => |ptr| { free => |ptr| {
gobject_sys::g_boxed_free(gst_sys::gst_parse_context_get_type(), ptr as *mut _) glib::gobject_ffi::g_boxed_free(ffi::gst_parse_context_get_type(), ptr as *mut _)
}, },
get_type => || gst_sys::gst_parse_context_get_type(), get_type => || ffi::gst_parse_context_get_type(),
} }
} }
@ -30,12 +28,12 @@ unsafe impl Sync for ParseContext {}
impl ParseContext { impl ParseContext {
pub fn new() -> Self { pub fn new() -> Self {
unsafe { from_glib_full(gst_sys::gst_parse_context_new()) } unsafe { from_glib_full(ffi::gst_parse_context_new()) }
} }
pub fn get_missing_elements(&self) -> Vec<String> { pub fn get_missing_elements(&self) -> Vec<String> {
unsafe { unsafe {
FromGlibPtrContainer::from_glib_full(gst_sys::gst_parse_context_get_missing_elements( FromGlibPtrContainer::from_glib_full(ffi::gst_parse_context_get_missing_elements(
mut_override(self.to_glib_none().0), mut_override(self.to_glib_none().0),
)) ))
} }

View file

@ -9,7 +9,7 @@
use glib::translate::*; use glib::translate::*;
use glib::IsA; use glib::IsA;
use PipelineFlags; use crate::PipelineFlags;
pub trait GstPipelineExtManual: 'static { pub trait GstPipelineExtManual: 'static {
fn set_pipeline_flags(&self, flags: PipelineFlags); fn set_pipeline_flags(&self, flags: PipelineFlags);
@ -19,27 +19,27 @@ pub trait GstPipelineExtManual: 'static {
fn get_pipeline_flags(&self) -> PipelineFlags; fn get_pipeline_flags(&self) -> PipelineFlags;
} }
impl<O: IsA<::Pipeline>> GstPipelineExtManual for O { impl<O: IsA<crate::Pipeline>> GstPipelineExtManual for O {
fn set_pipeline_flags(&self, flags: PipelineFlags) { fn set_pipeline_flags(&self, flags: PipelineFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib(); (*ptr).flags |= flags.to_glib();
} }
} }
fn unset_pipeline_flags(&self, flags: PipelineFlags) { fn unset_pipeline_flags(&self, flags: PipelineFlags) {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib(); (*ptr).flags &= !flags.to_glib();
} }
} }
fn get_pipeline_flags(&self) -> PipelineFlags { fn get_pipeline_flags(&self) -> PipelineFlags {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags) from_glib((*ptr).flags)
} }
} }

View file

@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_sys; use crate::Plugin;
use Plugin; use crate::PluginFlags;
use PluginFlags; use crate::Structure;
use Structure; use crate::StructureRef;
use StructureRef;
use glib::translate::*; use glib::translate::*;
use glib::IsA; use glib::IsA;
@ -18,7 +17,7 @@ use glib::IsA;
impl Plugin { impl Plugin {
pub fn get_cache_data(&self) -> Option<&StructureRef> { pub fn get_cache_data(&self) -> Option<&StructureRef> {
unsafe { unsafe {
let cache_data = gst_sys::gst_plugin_get_cache_data(self.to_glib_none().0); let cache_data = ffi::gst_plugin_get_cache_data(self.to_glib_none().0);
if cache_data.is_null() { if cache_data.is_null() {
None None
} else { } else {
@ -29,7 +28,7 @@ impl Plugin {
pub fn set_cache_data(&self, cache_data: Structure) { pub fn set_cache_data(&self, cache_data: Structure) {
unsafe { unsafe {
gst_sys::gst_plugin_set_cache_data(self.to_glib_none().0, cache_data.into_ptr()); ffi::gst_plugin_set_cache_data(self.to_glib_none().0, cache_data.into_ptr());
} }
} }
} }
@ -40,16 +39,16 @@ pub trait GstPluginExtManual: 'static {
fn get_plugin_name(&self) -> glib::GString; fn get_plugin_name(&self) -> glib::GString;
} }
impl<O: IsA<::Plugin>> GstPluginExtManual for O { impl<O: IsA<crate::Plugin>> GstPluginExtManual for O {
fn get_plugin_flags(&self) -> PluginFlags { fn get_plugin_flags(&self) -> PluginFlags {
unsafe { unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock); let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags) from_glib((*ptr).flags)
} }
} }
fn get_plugin_name(&self) -> glib::GString { fn get_plugin_name(&self) -> glib::GString {
unsafe { from_glib_none(gst_sys::gst_plugin_get_name(self.as_ref().to_glib_none().0)) } unsafe { from_glib_none(ffi::gst_plugin_get_name(self.as_ref().to_glib_none().0)) }
} }
} }

View file

@ -6,8 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use PluginFeature; use crate::PluginFeature;
use Rank; use crate::Rank;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::{from_glib, ToGlib, ToGlibPtr}; use glib::translate::{from_glib, ToGlib, ToGlibPtr};
@ -20,17 +20,14 @@ pub trait PluginFeatureExtManual: 'static {
impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O { impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O {
fn get_rank(&self) -> Rank { fn get_rank(&self) -> Rank {
unsafe { unsafe {
let rank = gst_sys::gst_plugin_feature_get_rank(self.as_ref().to_glib_none().0); let rank = ffi::gst_plugin_feature_get_rank(self.as_ref().to_glib_none().0);
from_glib(rank as i32) from_glib(rank as i32)
} }
} }
fn set_rank(&self, rank: Rank) { fn set_rank(&self, rank: Rank) {
unsafe { unsafe {
gst_sys::gst_plugin_feature_set_rank( ffi::gst_plugin_feature_set_rank(self.as_ref().to_glib_none().0, rank.to_glib() as u32);
self.as_ref().to_glib_none().0,
rank.to_glib() as u32,
);
} }
} }
} }

View file

@ -6,26 +6,24 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::PromiseResult;
use crate::Structure;
use crate::StructureRef;
use glib::translate::*; use glib::translate::*;
use glib_sys;
use gst_sys;
use PromiseResult;
use Structure;
use StructureRef;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::pin::Pin; use std::pin::Pin;
use std::ptr; use std::ptr;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
glib_wrapper! { glib::glib_wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Promise(Shared<gst_sys::GstPromise>); pub struct Promise(Shared<ffi::GstPromise>);
match fn { match fn {
ref => |ptr| gst_sys::gst_mini_object_ref(ptr as *mut _), ref => |ptr| ffi::gst_mini_object_ref(ptr as *mut _),
unref => |ptr| gst_sys::gst_mini_object_unref(ptr as *mut _), unref => |ptr| ffi::gst_mini_object_unref(ptr as *mut _),
get_type => || gst_sys::gst_promise_get_type(), get_type => || ffi::gst_promise_get_type(),
} }
} }
@ -39,7 +37,7 @@ pub enum PromiseError {
impl Promise { impl Promise {
pub fn new() -> Promise { pub fn new() -> Promise {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_promise_new()) } unsafe { from_glib_full(ffi::gst_promise_new()) }
} }
pub fn with_change_func<F>(func: F) -> Promise pub fn with_change_func<F>(func: F) -> Promise
@ -52,8 +50,8 @@ impl Promise {
unsafe extern "C" fn trampoline< unsafe extern "C" fn trampoline<
F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static, F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static,
>( >(
promise: *mut gst_sys::GstPromise, promise: *mut ffi::GstPromise,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) { ) {
let user_data: &mut Option<F> = &mut *(user_data as *mut _); let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap(); let callback = user_data.take().unwrap();
@ -76,13 +74,13 @@ impl Promise {
unsafe extern "C" fn free_user_data< unsafe extern "C" fn free_user_data<
F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static, F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static,
>( >(
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) { ) {
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _); let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
} }
unsafe { unsafe {
from_glib_full(gst_sys::gst_promise_new_with_change_func( from_glib_full(ffi::gst_promise_new_with_change_func(
Some(trampoline::<F>), Some(trampoline::<F>),
Box::into_raw(user_data) as *mut _, Box::into_raw(user_data) as *mut _,
Some(free_user_data::<F>), Some(free_user_data::<F>),
@ -107,13 +105,13 @@ impl Promise {
pub fn expire(&self) { pub fn expire(&self) {
unsafe { unsafe {
gst_sys::gst_promise_expire(self.to_glib_none().0); ffi::gst_promise_expire(self.to_glib_none().0);
} }
} }
pub fn get_reply(&self) -> Option<&StructureRef> { pub fn get_reply(&self) -> Option<&StructureRef> {
unsafe { unsafe {
let s = gst_sys::gst_promise_get_reply(self.to_glib_none().0); let s = ffi::gst_promise_get_reply(self.to_glib_none().0);
if s.is_null() { if s.is_null() {
None None
} else { } else {
@ -124,13 +122,13 @@ impl Promise {
pub fn interrupt(&self) { pub fn interrupt(&self) {
unsafe { unsafe {
gst_sys::gst_promise_interrupt(self.to_glib_none().0); ffi::gst_promise_interrupt(self.to_glib_none().0);
} }
} }
pub fn reply(&self, s: Option<Structure>) { pub fn reply(&self, s: Option<Structure>) {
unsafe { unsafe {
gst_sys::gst_promise_reply( ffi::gst_promise_reply(
self.to_glib_none().0, self.to_glib_none().0,
s.map(|s| s.into_ptr()).unwrap_or(ptr::null_mut()), s.map(|s| s.into_ptr()).unwrap_or(ptr::null_mut()),
); );
@ -138,7 +136,7 @@ impl Promise {
} }
pub fn wait(&self) -> PromiseResult { pub fn wait(&self) -> PromiseResult {
unsafe { from_glib(gst_sys::gst_promise_wait(self.to_glib_none().0)) } unsafe { from_glib(ffi::gst_promise_wait(self.to_glib_none().0)) }
} }
} }
@ -167,7 +165,7 @@ impl<'a> std::future::Future for PromiseFuture<'a> {
Poll::Ready(Ok(())) => { Poll::Ready(Ok(())) => {
let res = match self.0.wait() { let res = match self.0.wait() {
PromiseResult::Replied => unsafe { PromiseResult::Replied => unsafe {
let s = gst_sys::gst_promise_get_reply(self.0.to_glib_none().0); let s = ffi::gst_promise_get_reply(self.0.to_glib_none().0);
if s.is_null() { if s.is_null() {
Ok(None) Ok(None)
} else { } else {
@ -196,7 +194,7 @@ mod tests {
#[test] #[test]
fn test_change_func() { fn test_change_func() {
::init().unwrap(); crate::init().unwrap();
let (sender, receiver) = channel(); let (sender, receiver) = channel();
let promise = Promise::with_change_func(move |res| { let promise = Promise::with_change_func(move |res| {

View file

@ -6,21 +6,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::Buffer;
use crate::BufferList;
use crate::FlowError;
use crate::FlowReturn;
use crate::FlowSuccess;
use crate::Object;
use crate::Pad;
use crate::ProxyPad;
use std::ptr; use std::ptr;
use Buffer;
use BufferList;
use FlowError;
use FlowReturn;
use FlowSuccess;
use Object;
use Pad;
use ProxyPad;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::{from_glib, from_glib_full, ToGlibPtr}; use glib::translate::{from_glib, from_glib_full, ToGlibPtr};
use gst_sys;
pub trait ProxyPadExtManual: 'static { pub trait ProxyPadExtManual: 'static {
fn chain_default<P: IsA<Object>>( fn chain_default<P: IsA<Object>>(
&self, &self,
@ -44,7 +42,7 @@ pub trait ProxyPadExtManual: 'static {
fn iterate_internal_links_default<P: IsA<Object>>( fn iterate_internal_links_default<P: IsA<Object>>(
&self, &self,
parent: Option<&P>, parent: Option<&P>,
) -> Option<::Iterator<Pad>>; ) -> Option<crate::Iterator<Pad>>;
} }
impl<O: IsA<ProxyPad>> ProxyPadExtManual for O { impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
@ -55,8 +53,8 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
) -> Result<FlowSuccess, FlowError> { ) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!(); skip_assert_initialized!();
let ret: FlowReturn = unsafe { let ret: FlowReturn = unsafe {
from_glib(gst_sys::gst_proxy_pad_chain_default( from_glib(ffi::gst_proxy_pad_chain_default(
self.as_ptr() as *mut gst_sys::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
@ -71,8 +69,8 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
) -> Result<FlowSuccess, FlowError> { ) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!(); skip_assert_initialized!();
let ret: FlowReturn = unsafe { let ret: FlowReturn = unsafe {
from_glib(gst_sys::gst_proxy_pad_chain_list_default( from_glib(ffi::gst_proxy_pad_chain_list_default(
self.as_ptr() as *mut gst_sys::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
@ -89,8 +87,8 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut buffer = ptr::null_mut(); let mut buffer = ptr::null_mut();
let ret: FlowReturn = from_glib(gst_sys::gst_proxy_pad_getrange_default( let ret: FlowReturn = from_glib(ffi::gst_proxy_pad_getrange_default(
self.as_ptr() as *mut gst_sys::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
offset, offset,
size, size,
@ -103,11 +101,11 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
fn iterate_internal_links_default<P: IsA<Object>>( fn iterate_internal_links_default<P: IsA<Object>>(
&self, &self,
parent: Option<&P>, parent: Option<&P>,
) -> Option<::Iterator<Pad>> { ) -> Option<crate::Iterator<Pad>> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
from_glib_full(gst_sys::gst_proxy_pad_iterate_internal_links_default( from_glib_full(ffi::gst_proxy_pad_iterate_internal_links_default(
self.as_ptr() as *mut gst_sys::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
)) ))
} }

File diff suppressed because it is too large Load diff

View file

@ -9,25 +9,22 @@
use std::fmt; use std::fmt;
use std::ptr; use std::ptr;
use gst_sys;
use glib;
use glib::translate::{from_glib_full, from_glib_none, mut_override, ToGlibPtr}; use glib::translate::{from_glib_full, from_glib_none, mut_override, ToGlibPtr};
use Buffer; use crate::Buffer;
use BufferList; use crate::BufferList;
use BufferListRef; use crate::BufferListRef;
use BufferRef; use crate::BufferRef;
use Caps; use crate::Caps;
use CapsRef; use crate::CapsRef;
use FormattedSegment; use crate::FormattedSegment;
use FormattedValue; use crate::FormattedValue;
use Segment; use crate::Segment;
use Structure; use crate::Structure;
use StructureRef; use crate::StructureRef;
gst_define_mini_object_wrapper!(Sample, SampleRef, gst_sys::GstSample, || { gst_define_mini_object_wrapper!(Sample, SampleRef, ffi::GstSample, || {
gst_sys::gst_sample_get_type() ffi::gst_sample_get_type()
}); });
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -83,7 +80,7 @@ impl<'a> SampleBuilder<'a> {
unsafe { unsafe {
let info = self.info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut()); let info = self.info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut());
let sample: Sample = from_glib_full(gst_sys::gst_sample_new( let sample: Sample = from_glib_full(ffi::gst_sample_new(
self.buffer.to_glib_none().0, self.buffer.to_glib_none().0,
self.caps.to_glib_none().0, self.caps.to_glib_none().0,
self.segment.to_glib_none().0, self.segment.to_glib_none().0,
@ -91,7 +88,7 @@ impl<'a> SampleBuilder<'a> {
)); ));
if let Some(buffer_list) = self.buffer_list { if let Some(buffer_list) = self.buffer_list {
gst_sys::gst_sample_set_buffer_list( ffi::gst_sample_set_buffer_list(
sample.to_glib_none().0, sample.to_glib_none().0,
buffer_list.to_glib_none().0, buffer_list.to_glib_none().0,
); );
@ -117,7 +114,7 @@ impl Sample {
impl SampleRef { impl SampleRef {
pub fn get_buffer(&self) -> Option<&BufferRef> { pub fn get_buffer(&self) -> Option<&BufferRef> {
unsafe { unsafe {
let ptr = gst_sys::gst_sample_get_buffer(self.as_mut_ptr()); let ptr = ffi::gst_sample_get_buffer(self.as_mut_ptr());
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -135,7 +132,7 @@ impl SampleRef {
pub fn get_buffer_list(&self) -> Option<&BufferListRef> { pub fn get_buffer_list(&self) -> Option<&BufferListRef> {
unsafe { unsafe {
let ptr = gst_sys::gst_sample_get_buffer_list(self.as_mut_ptr()); let ptr = ffi::gst_sample_get_buffer_list(self.as_mut_ptr());
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -153,7 +150,7 @@ impl SampleRef {
pub fn get_caps(&self) -> Option<&CapsRef> { pub fn get_caps(&self) -> Option<&CapsRef> {
unsafe { unsafe {
let ptr = gst_sys::gst_sample_get_caps(self.as_mut_ptr()); let ptr = ffi::gst_sample_get_caps(self.as_mut_ptr());
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -167,12 +164,12 @@ impl SampleRef {
} }
pub fn get_segment(&self) -> Option<Segment> { pub fn get_segment(&self) -> Option<Segment> {
unsafe { from_glib_none(gst_sys::gst_sample_get_segment(self.as_mut_ptr())) } unsafe { from_glib_none(ffi::gst_sample_get_segment(self.as_mut_ptr())) }
} }
pub fn get_info(&self) -> Option<&StructureRef> { pub fn get_info(&self) -> Option<&StructureRef> {
unsafe { unsafe {
let ptr = gst_sys::gst_sample_get_info(self.as_mut_ptr()); let ptr = ffi::gst_sample_get_info(self.as_mut_ptr());
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
@ -184,34 +181,32 @@ impl SampleRef {
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_buffer(&mut self, buffer: Option<&Buffer>) { pub fn set_buffer(&mut self, buffer: Option<&Buffer>) {
unsafe { gst_sys::gst_sample_set_buffer(self.as_mut_ptr(), buffer.to_glib_none().0) } unsafe { ffi::gst_sample_set_buffer(self.as_mut_ptr(), buffer.to_glib_none().0) }
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_buffer_list(&mut self, buffer_list: Option<&BufferList>) { pub fn set_buffer_list(&mut self, buffer_list: Option<&BufferList>) {
unsafe { unsafe { ffi::gst_sample_set_buffer_list(self.as_mut_ptr(), buffer_list.to_glib_none().0) }
gst_sys::gst_sample_set_buffer_list(self.as_mut_ptr(), buffer_list.to_glib_none().0)
}
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_caps(&mut self, caps: Option<&Caps>) { pub fn set_caps(&mut self, caps: Option<&Caps>) {
unsafe { gst_sys::gst_sample_set_caps(self.as_mut_ptr(), caps.to_glib_none().0) } unsafe { ffi::gst_sample_set_caps(self.as_mut_ptr(), caps.to_glib_none().0) }
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_segment(&mut self, segment: Option<&Segment>) { pub fn set_segment(&mut self, segment: Option<&Segment>) {
unsafe { gst_sys::gst_sample_set_segment(self.as_mut_ptr(), segment.to_glib_none().0) } unsafe { ffi::gst_sample_set_segment(self.as_mut_ptr(), segment.to_glib_none().0) }
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_info(&mut self, info: Option<Structure>) { pub fn set_info(&mut self, info: Option<Structure>) {
unsafe { unsafe {
gst_sys::gst_sample_set_info( ffi::gst_sample_set_info(
self.as_mut_ptr(), self.as_mut_ptr(),
info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut()), info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut()),
); );
@ -240,10 +235,10 @@ impl fmt::Debug for SampleRef {
mod tests { mod tests {
#[test] #[test]
fn test_sample_new_with_info() { fn test_sample_new_with_info() {
use Sample; use crate::Sample;
use Structure; use crate::Structure;
::init().unwrap(); crate::init().unwrap();
let info = Structure::builder("sample.info") let info = Structure::builder("sample.info")
.field("f3", &123i32) .field("f3", &123i32)

View file

@ -9,13 +9,13 @@
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use Buffer; use crate::Buffer;
use BufferList; use crate::BufferList;
use Caps; use crate::Caps;
use Sample; use crate::Sample;
use SampleRef; use crate::SampleRef;
use Segment; use crate::Segment;
use Structure; use crate::Structure;
impl<'a> Serialize for SampleRef { impl<'a> Serialize for SampleRef {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
@ -35,7 +35,7 @@ impl<'a> Serialize for Sample {
} }
} }
#[derive(Deserialize)] #[derive(serde::Deserialize)]
struct SampleDe { struct SampleDe {
buffer: Option<Buffer>, buffer: Option<Buffer>,
buffer_list: Option<BufferList>, buffer_list: Option<BufferList>,
@ -82,21 +82,19 @@ impl<'de> Deserialize<'de> for Sample {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::Buffer;
use crate::Caps;
use Buffer; use crate::ClockTime;
use Caps; use crate::Format;
use ClockTime; use crate::GenericFormattedValue;
use Format; use crate::Sample;
use GenericFormattedValue; use crate::Segment;
use Sample; use crate::SegmentFlags;
use Segment; use crate::Structure;
use SegmentFlags;
use Structure;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default(); let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string(); pretty_config.new_line = "".to_string();
@ -243,7 +241,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
let buffer_ron = r#" let buffer_ron = r#"
( (
@ -328,7 +326,7 @@ mod tests {
#[test] #[test]
fn test_roundrip() { fn test_roundrip() {
::init().unwrap(); crate::init().unwrap();
// Segment present // Segment present
let sample = { let sample = {

View file

@ -6,29 +6,25 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib; use crate::Format;
use crate::FormattedValue;
use crate::GenericFormattedValue;
use crate::SeekFlags;
use crate::SeekType;
use glib::translate::*; use glib::translate::*;
use glib_sys;
use gobject_sys;
use gst_sys;
use std::fmt; use std::fmt;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use Format;
use FormattedValue;
use GenericFormattedValue;
use SeekFlags;
use SeekType;
pub type Segment = FormattedSegment<GenericFormattedValue>; pub type Segment = FormattedSegment<GenericFormattedValue>;
#[repr(transparent)] #[repr(transparent)]
pub struct FormattedSegment<T: FormattedValue>(gst_sys::GstSegment, PhantomData<T>); pub struct FormattedSegment<T: FormattedValue>(ffi::GstSegment, PhantomData<T>);
impl Segment { impl Segment {
pub fn reset_with_format(&mut self, format: Format) { pub fn reset_with_format(&mut self, format: Format) {
unsafe { unsafe {
gst_sys::gst_segment_init(self.to_glib_none_mut().0, format.to_glib()); ffi::gst_segment_init(self.to_glib_none_mut().0, format.to_glib());
} }
} }
@ -78,7 +74,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let segment = unsafe { let segment = unsafe {
let mut segment = mem::MaybeUninit::zeroed(); let mut segment = mem::MaybeUninit::zeroed();
gst_sys::gst_segment_init(segment.as_mut_ptr(), T::get_default_format().to_glib()); ffi::gst_segment_init(segment.as_mut_ptr(), T::get_default_format().to_glib());
segment.assume_init() segment.assume_init()
}; };
FormattedSegment(segment, PhantomData) FormattedSegment(segment, PhantomData)
@ -96,7 +92,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
pub fn reset(&mut self) { pub fn reset(&mut self) {
unsafe { unsafe {
gst_sys::gst_segment_init(&mut self.0, T::get_default_format().to_glib()); ffi::gst_segment_init(&mut self.0, T::get_default_format().to_glib());
} }
} }
@ -112,7 +108,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
let mut clip_start = mem::MaybeUninit::uninit(); let mut clip_start = mem::MaybeUninit::uninit();
let mut clip_stop = mem::MaybeUninit::uninit(); let mut clip_stop = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_segment_clip( let ret = from_glib(ffi::gst_segment_clip(
&self.0, &self.0,
start.get_format().to_glib(), start.get_format().to_glib(),
start.to_raw_value() as u64, start.to_raw_value() as u64,
@ -152,7 +148,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
let mut update = mem::MaybeUninit::uninit(); let mut update = mem::MaybeUninit::uninit();
let ret = from_glib(gst_sys::gst_segment_do_seek( let ret = from_glib(ffi::gst_segment_do_seek(
&mut self.0, &mut self.0,
rate, rate,
self.get_format().to_glib(), self.get_format().to_glib(),
@ -173,8 +169,8 @@ impl<T: FormattedValue> FormattedSegment<T> {
pub fn offset_running_time(&mut self, offset: i64) -> Result<(), glib::BoolError> { pub fn offset_running_time(&mut self, offset: i64) -> Result<(), glib::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_segment_offset_running_time( ffi::gst_segment_offset_running_time(
&mut self.0, &mut self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
offset, offset,
@ -194,7 +190,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
T::from_raw( T::from_raw(
self.get_format(), self.get_format(),
gst_sys::gst_segment_position_from_running_time( ffi::gst_segment_position_from_running_time(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
running_time.to_raw_value() as u64, running_time.to_raw_value() as u64,
@ -212,7 +208,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
let mut position = mem::MaybeUninit::uninit(); let mut position = mem::MaybeUninit::uninit();
let ret = gst_sys::gst_segment_position_from_running_time_full( let ret = ffi::gst_segment_position_from_running_time_full(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
running_time.to_raw_value() as u64, running_time.to_raw_value() as u64,
@ -235,7 +231,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
T::from_raw( T::from_raw(
self.get_format(), self.get_format(),
gst_sys::gst_segment_position_from_stream_time( ffi::gst_segment_position_from_stream_time(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
stream_time.to_raw_value() as u64, stream_time.to_raw_value() as u64,
@ -253,7 +249,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
let mut position = mem::MaybeUninit::uninit(); let mut position = mem::MaybeUninit::uninit();
let ret = gst_sys::gst_segment_position_from_stream_time_full( let ret = ffi::gst_segment_position_from_stream_time_full(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
stream_time.to_raw_value() as u64, stream_time.to_raw_value() as u64,
@ -274,8 +270,8 @@ impl<T: FormattedValue> FormattedSegment<T> {
} }
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_sys::gst_segment_set_running_time( ffi::gst_segment_set_running_time(
&mut self.0, &mut self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
running_time.to_raw_value() as u64, running_time.to_raw_value() as u64,
@ -295,7 +291,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
T::from_raw( T::from_raw(
self.get_format(), self.get_format(),
gst_sys::gst_segment_to_running_time( ffi::gst_segment_to_running_time(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
position.to_raw_value() as u64, position.to_raw_value() as u64,
@ -313,7 +309,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
let mut running_time = mem::MaybeUninit::uninit(); let mut running_time = mem::MaybeUninit::uninit();
let ret = gst_sys::gst_segment_to_running_time_full( let ret = ffi::gst_segment_to_running_time_full(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
position.to_raw_value() as u64, position.to_raw_value() as u64,
@ -336,7 +332,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
T::from_raw( T::from_raw(
self.get_format(), self.get_format(),
gst_sys::gst_segment_to_stream_time( ffi::gst_segment_to_stream_time(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
position.to_raw_value() as u64, position.to_raw_value() as u64,
@ -354,7 +350,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe { unsafe {
let mut stream_time = mem::MaybeUninit::uninit(); let mut stream_time = mem::MaybeUninit::uninit();
let ret = gst_sys::gst_segment_to_stream_time_full( let ret = ffi::gst_segment_to_stream_time_full(
&self.0, &self.0,
self.get_format().to_glib(), self.get_format().to_glib(),
position.to_raw_value() as u64, position.to_raw_value() as u64,
@ -367,11 +363,11 @@ impl<T: FormattedValue> FormattedSegment<T> {
} }
} }
pub fn get_flags(&self) -> ::SegmentFlags { pub fn get_flags(&self) -> crate::SegmentFlags {
from_glib(self.0.flags) from_glib(self.0.flags)
} }
pub fn set_flags(&mut self, flags: ::SegmentFlags) { pub fn set_flags(&mut self, flags: crate::SegmentFlags) {
self.0.flags = flags.to_glib(); self.0.flags = flags.to_glib();
} }
@ -501,7 +497,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
impl<T: FormattedValue> PartialEq for FormattedSegment<T> { impl<T: FormattedValue> PartialEq for FormattedSegment<T> {
#[inline] #[inline]
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
unsafe { from_glib(gst_sys::gst_segment_is_equal(&self.0, &other.0)) } unsafe { from_glib(ffi::gst_segment_is_equal(&self.0, &other.0)) }
} }
} }
@ -533,7 +529,7 @@ impl<T: FormattedValue> fmt::Debug for FormattedSegment<T> {
.field("format", &Format::Undefined) .field("format", &Format::Undefined)
.finish(), .finish(),
Format::Time => { Format::Time => {
let segment = segment.downcast_ref::<::ClockTime>().unwrap(); let segment = segment.downcast_ref::<crate::ClockTime>().unwrap();
f.debug_struct("Segment") f.debug_struct("Segment")
.field("format", &Format::Time) .field("format", &Format::Time)
.field("start", &segment.get_start().to_string()) .field("start", &segment.get_start().to_string())
@ -574,26 +570,26 @@ impl<T: FormattedValue> Default for FormattedSegment<T> {
impl<T: FormattedValue> glib::types::StaticType for FormattedSegment<T> { impl<T: FormattedValue> glib::types::StaticType for FormattedSegment<T> {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(gst_sys::gst_segment_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_segment_get_type()) }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for Segment { impl<'a> glib::value::FromValueOptional<'a> for Segment {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<Segment>::from_glib_none( Option::<Segment>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstSegment value.to_glib_none().0,
) ) as *mut ffi::GstSegment)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> { impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> {
unsafe fn set_value(value: &mut glib::Value, this: &Self) { unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstSegment>::to_glib_none(this).0 glib::translate::ToGlibPtr::<*const ffi::GstSegment>::to_glib_none(this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
@ -601,78 +597,76 @@ impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> {
#[doc(hidden)] #[doc(hidden)]
impl<T: FormattedValue> glib::value::SetValueOptional for FormattedSegment<T> { impl<T: FormattedValue> glib::value::SetValueOptional for FormattedSegment<T> {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstSegment>::to_glib_none(&this).0 glib::translate::ToGlibPtr::<*const ffi::GstSegment>::to_glib_none(&this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<T: FormattedValue> glib::translate::GlibPtrDefault for FormattedSegment<T> { impl<T: FormattedValue> glib::translate::GlibPtrDefault for FormattedSegment<T> {
type GlibType = *mut gst_sys::GstSegment; type GlibType = *mut ffi::GstSegment;
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a, T: FormattedValue> glib::translate::ToGlibPtr<'a, *const gst_sys::GstSegment> impl<'a, T: FormattedValue> glib::translate::ToGlibPtr<'a, *const ffi::GstSegment>
for FormattedSegment<T> for FormattedSegment<T>
{ {
type Storage = &'a FormattedSegment<T>; type Storage = &'a FormattedSegment<T>;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const gst_sys::GstSegment, Self> { fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstSegment, Self> {
glib::translate::Stash(&self.0, self) glib::translate::Stash(&self.0, self)
} }
fn to_glib_full(&self) -> *const gst_sys::GstSegment { fn to_glib_full(&self) -> *const ffi::GstSegment {
unimplemented!() unimplemented!()
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a, T: FormattedValue> glib::translate::ToGlibPtrMut<'a, *mut gst_sys::GstSegment> impl<'a, T: FormattedValue> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstSegment>
for FormattedSegment<T> for FormattedSegment<T>
{ {
type Storage = &'a mut FormattedSegment<T>; type Storage = &'a mut FormattedSegment<T>;
#[inline] #[inline]
fn to_glib_none_mut( fn to_glib_none_mut(&'a mut self) -> glib::translate::StashMut<'a, *mut ffi::GstSegment, Self> {
&'a mut self,
) -> glib::translate::StashMut<'a, *mut gst_sys::GstSegment, Self> {
glib::translate::StashMut(&mut self.0, self) glib::translate::StashMut(&mut self.0, self)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const gst_sys::GstSegment> for Segment { impl glib::translate::FromGlibPtrNone<*const ffi::GstSegment> for Segment {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *const gst_sys::GstSegment) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstSegment) -> Self {
FormattedSegment(ptr::read(ptr), PhantomData) FormattedSegment(ptr::read(ptr), PhantomData)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstSegment> for Segment { impl glib::translate::FromGlibPtrNone<*mut ffi::GstSegment> for Segment {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut gst_sys::GstSegment) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstSegment) -> Self {
FormattedSegment(ptr::read(ptr), PhantomData) FormattedSegment(ptr::read(ptr), PhantomData)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstSegment> for Segment { impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstSegment> for Segment {
#[inline] #[inline]
unsafe fn from_glib_borrow(ptr: *mut gst_sys::GstSegment) -> Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *mut ffi::GstSegment) -> Borrowed<Self> {
Borrowed::new(FormattedSegment(ptr::read(ptr), PhantomData)) Borrowed::new(FormattedSegment(ptr::read(ptr), PhantomData))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstSegment> for Segment { impl glib::translate::FromGlibPtrFull<*mut ffi::GstSegment> for Segment {
#[inline] #[inline]
unsafe fn from_glib_full(ptr: *mut gst_sys::GstSegment) -> Self { unsafe fn from_glib_full(ptr: *mut ffi::GstSegment) -> Self {
let segment = from_glib_none(ptr); let segment = from_glib_none(ptr);
glib_sys::g_free(ptr as *mut _); glib::ffi::g_free(ptr as *mut _);
segment segment
} }
} }

View file

@ -10,15 +10,15 @@ use serde::de;
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
use Format; use crate::Format;
use FormattedSegment; use crate::FormattedSegment;
use FormattedValue; use crate::FormattedValue;
use GenericFormattedValue; use crate::GenericFormattedValue;
use Segment; use crate::Segment;
use SegmentFlags; use crate::SegmentFlags;
use SpecificFormattedValue; use crate::SpecificFormattedValue;
#[derive(Serialize, Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
struct FormattedSegmentSerde { struct FormattedSegmentSerde {
flags: SegmentFlags, flags: SegmentFlags,
rate: f64, rate: f64,
@ -114,17 +114,15 @@ impl<'de, T: FormattedValue + SpecificFormattedValue> Deserialize<'de> for Forma
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::ClockTime;
use crate::Format;
use ClockTime; use crate::GenericFormattedValue;
use Format; use crate::Segment;
use GenericFormattedValue; use crate::SegmentFlags;
use Segment;
use SegmentFlags;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut segment = Segment::new(); let mut segment = Segment::new();
segment.set_flags(SegmentFlags::RESET | SegmentFlags::SEGMENT); segment.set_flags(SegmentFlags::RESET | SegmentFlags::SEGMENT);
@ -168,7 +166,7 @@ mod tests {
#[test] #[test]
fn test_deserialize_segment() { fn test_deserialize_segment() {
::init().unwrap(); crate::init().unwrap();
let segment_ron = r#" let segment_ron = r#"
( (
@ -228,10 +226,10 @@ mod tests {
#[test] #[test]
fn test_deserialize_formatted() { fn test_deserialize_formatted() {
use format::Time; use crate::format::Time;
use FormattedSegment; use crate::FormattedSegment;
::init().unwrap(); crate::init().unwrap();
let segment_ron = r#" let segment_ron = r#"
( (
@ -270,7 +268,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let mut segment = Segment::new(); let mut segment = Segment::new();
segment.set_flags(SegmentFlags::RESET | SegmentFlags::SEGMENT); segment.set_flags(SegmentFlags::RESET | SegmentFlags::SEGMENT);

View file

@ -6,24 +6,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use Caps; use crate::Caps;
use glib_sys;
use gobject_sys;
use gst_sys;
use glib;
use glib::translate::*; use glib::translate::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::ptr; use std::ptr;
pub struct StaticCaps(ptr::NonNull<gst_sys::GstStaticCaps>); pub struct StaticCaps(ptr::NonNull<ffi::GstStaticCaps>);
impl StaticCaps { impl StaticCaps {
pub fn get(&self) -> Caps { pub fn get(&self) -> Caps {
unsafe { from_glib_full(gst_sys::gst_static_caps_get(self.0.as_ptr())) } unsafe { from_glib_full(ffi::gst_static_caps_get(self.0.as_ptr())) }
} }
} }
@ -42,26 +37,26 @@ impl fmt::Debug for StaticCaps {
impl glib::types::StaticType for StaticCaps { impl glib::types::StaticType for StaticCaps {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(gst_sys::gst_static_caps_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_static_caps_get_type()) }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for StaticCaps { impl<'a> glib::value::FromValueOptional<'a> for StaticCaps {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<StaticCaps>::from_glib_none( Option::<StaticCaps>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstStaticCaps value.to_glib_none().0,
) ) as *mut ffi::GstStaticCaps)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValue for StaticCaps { impl glib::value::SetValue for StaticCaps {
unsafe fn set_value(value: &mut glib::Value, this: &Self) { unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticCaps>::to_glib_none(this).0 glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
@ -69,63 +64,63 @@ impl glib::value::SetValue for StaticCaps {
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValueOptional for StaticCaps { impl glib::value::SetValueOptional for StaticCaps {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticCaps>::to_glib_none(&this).0 glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(&this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticCaps { impl glib::translate::GlibPtrDefault for StaticCaps {
type GlibType = *mut gst_sys::GstStaticCaps; type GlibType = *mut ffi::GstStaticCaps;
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const gst_sys::GstStaticCaps> for StaticCaps { impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticCaps> for StaticCaps {
type Storage = &'a StaticCaps; type Storage = &'a StaticCaps;
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const gst_sys::GstStaticCaps, Self> { fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstStaticCaps, Self> {
glib::translate::Stash(self.0.as_ptr(), self) glib::translate::Stash(self.0.as_ptr(), self)
} }
fn to_glib_full(&self) -> *const gst_sys::GstStaticCaps { fn to_glib_full(&self) -> *const ffi::GstStaticCaps {
unimplemented!() unimplemented!()
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const gst_sys::GstStaticCaps> for StaticCaps { impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *const gst_sys::GstStaticCaps) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstStaticCaps) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
StaticCaps(ptr::NonNull::new_unchecked(ptr as *mut _)) StaticCaps(ptr::NonNull::new_unchecked(ptr as *mut _))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstStaticCaps> for StaticCaps { impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut gst_sys::GstStaticCaps) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstStaticCaps) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
StaticCaps(ptr::NonNull::new_unchecked(ptr)) StaticCaps(ptr::NonNull::new_unchecked(ptr))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstStaticCaps> for StaticCaps { impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline] #[inline]
unsafe fn from_glib_borrow(ptr: *mut gst_sys::GstStaticCaps) -> Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticCaps) -> Borrowed<Self> {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Borrowed::new(StaticCaps(ptr::NonNull::new_unchecked(ptr))) Borrowed::new(StaticCaps(ptr::NonNull::new_unchecked(ptr)))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstStaticCaps> for StaticCaps { impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline] #[inline]
unsafe fn from_glib_full(_ptr: *mut gst_sys::GstStaticCaps) -> Self { unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticCaps) -> Self {
unimplemented!(); unimplemented!();
} }
} }

View file

@ -6,29 +6,24 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use Caps; use crate::Caps;
use PadTemplate; use crate::PadTemplate;
use glib_sys;
use gobject_sys;
use gst_sys;
use glib;
use glib::translate::*; use glib::translate::*;
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::ptr; use std::ptr;
pub struct StaticPadTemplate(ptr::NonNull<gst_sys::GstStaticPadTemplate>); pub struct StaticPadTemplate(ptr::NonNull<ffi::GstStaticPadTemplate>);
impl StaticPadTemplate { impl StaticPadTemplate {
pub fn get(&self) -> PadTemplate { pub fn get(&self) -> PadTemplate {
unsafe { from_glib_full(gst_sys::gst_static_pad_template_get(self.0.as_ptr())) } unsafe { from_glib_full(ffi::gst_static_pad_template_get(self.0.as_ptr())) }
} }
pub fn get_caps(&self) -> Caps { pub fn get_caps(&self) -> Caps {
unsafe { from_glib_full(gst_sys::gst_static_pad_template_get_caps(self.0.as_ptr())) } unsafe { from_glib_full(ffi::gst_static_pad_template_get_caps(self.0.as_ptr())) }
} }
pub fn name_template<'a>(&self) -> &'a str { pub fn name_template<'a>(&self) -> &'a str {
@ -39,11 +34,11 @@ impl StaticPadTemplate {
} }
} }
pub fn direction(&self) -> ::PadDirection { pub fn direction(&self) -> crate::PadDirection {
unsafe { from_glib(self.0.as_ref().direction) } unsafe { from_glib(self.0.as_ref().direction) }
} }
pub fn presence(&self) -> ::PadPresence { pub fn presence(&self) -> crate::PadPresence {
unsafe { from_glib(self.0.as_ref().presence) } unsafe { from_glib(self.0.as_ref().presence) }
} }
} }
@ -58,13 +53,13 @@ impl fmt::Debug for StaticPadTemplate {
CStr::from_ptr(self.0.as_ref().name_template).to_str() CStr::from_ptr(self.0.as_ref().name_template).to_str()
}) })
.field("direction", &unsafe { .field("direction", &unsafe {
from_glib::<_, ::PadDirection>(self.0.as_ref().direction) from_glib::<_, crate::PadDirection>(self.0.as_ref().direction)
}) })
.field("presence", &unsafe { .field("presence", &unsafe {
from_glib::<_, ::PadPresence>(self.0.as_ref().presence) from_glib::<_, crate::PadPresence>(self.0.as_ref().presence)
}) })
.field("static_caps", &unsafe { .field("static_caps", &unsafe {
from_glib_none::<_, ::StaticCaps>(&self.0.as_ref().static_caps as *const _) from_glib_none::<_, crate::StaticCaps>(&self.0.as_ref().static_caps as *const _)
}) })
.finish() .finish()
} }
@ -72,26 +67,26 @@ impl fmt::Debug for StaticPadTemplate {
impl glib::types::StaticType for StaticPadTemplate { impl glib::types::StaticType for StaticPadTemplate {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { glib::translate::from_glib(gst_sys::gst_static_pad_template_get_type()) } unsafe { glib::translate::from_glib(ffi::gst_static_pad_template_get_type()) }
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::value::FromValueOptional<'a> for StaticPadTemplate { impl<'a> glib::value::FromValueOptional<'a> for StaticPadTemplate {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> { unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<StaticPadTemplate>::from_glib_none(gobject_sys::g_value_get_boxed( Option::<StaticPadTemplate>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
value.to_glib_none().0, value.to_glib_none().0,
) as *mut gst_sys::GstStaticPadTemplate) ) as *mut ffi::GstStaticPadTemplate)
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValue for StaticPadTemplate { impl glib::value::SetValue for StaticPadTemplate {
unsafe fn set_value(value: &mut glib::Value, this: &Self) { unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticPadTemplate>::to_glib_none(this).0 glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(this).0
as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
@ -99,67 +94,65 @@ impl glib::value::SetValue for StaticPadTemplate {
#[doc(hidden)] #[doc(hidden)]
impl glib::value::SetValueOptional for StaticPadTemplate { impl glib::value::SetValueOptional for StaticPadTemplate {
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) { unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
gobject_sys::g_value_set_boxed( glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticPadTemplate>::to_glib_none(&this) glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(&this).0
.0 as glib_sys::gpointer, as glib::ffi::gpointer,
) )
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticPadTemplate { impl glib::translate::GlibPtrDefault for StaticPadTemplate {
type GlibType = *mut gst_sys::GstStaticPadTemplate; type GlibType = *mut ffi::GstStaticPadTemplate;
} }
#[doc(hidden)] #[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const gst_sys::GstStaticPadTemplate> impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate {
for StaticPadTemplate
{
type Storage = &'a StaticPadTemplate; type Storage = &'a StaticPadTemplate;
fn to_glib_none( fn to_glib_none(
&'a self, &'a self,
) -> glib::translate::Stash<'a, *const gst_sys::GstStaticPadTemplate, Self> { ) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, Self> {
glib::translate::Stash(self.0.as_ptr(), self) glib::translate::Stash(self.0.as_ptr(), self)
} }
fn to_glib_full(&self) -> *const gst_sys::GstStaticPadTemplate { fn to_glib_full(&self) -> *const ffi::GstStaticPadTemplate {
unimplemented!() unimplemented!()
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const gst_sys::GstStaticPadTemplate> for StaticPadTemplate { impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *const gst_sys::GstStaticPadTemplate) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstStaticPadTemplate) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
StaticPadTemplate(ptr::NonNull::new_unchecked(ptr as *mut _)) StaticPadTemplate(ptr::NonNull::new_unchecked(ptr as *mut _))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate { impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline] #[inline]
unsafe fn from_glib_none(ptr: *mut gst_sys::GstStaticPadTemplate) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstStaticPadTemplate) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)) StaticPadTemplate(ptr::NonNull::new_unchecked(ptr))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate { impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline] #[inline]
unsafe fn from_glib_borrow(ptr: *mut gst_sys::GstStaticPadTemplate) -> Borrowed<Self> { unsafe fn from_glib_borrow(ptr: *mut ffi::GstStaticPadTemplate) -> Borrowed<Self> {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Borrowed::new(StaticPadTemplate(ptr::NonNull::new_unchecked(ptr))) Borrowed::new(StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)))
} }
} }
#[doc(hidden)] #[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate { impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline] #[inline]
unsafe fn from_glib_full(_ptr: *mut gst_sys::GstStaticPadTemplate) -> Self { unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticPadTemplate) -> Self {
unimplemented!(); unimplemented!();
} }
} }

View file

@ -6,13 +6,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::Caps;
use crate::Stream;
use crate::StreamFlags;
use crate::StreamType;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use std::fmt; use std::fmt;
use Caps;
use Stream;
use StreamFlags;
use StreamType;
impl Stream { impl Stream {
pub fn new( pub fn new(
@ -25,10 +24,10 @@ impl Stream {
let stream_id = stream_id.to_glib_none(); let stream_id = stream_id.to_glib_none();
let caps = caps.to_glib_none(); let caps = caps.to_glib_none();
let (major, minor, _, _) = ::version(); let (major, minor, _, _) = crate::version();
if (major, minor) > (1, 12) { if (major, minor) > (1, 12) {
unsafe { unsafe {
from_glib_full(gst_sys::gst_stream_new( from_glib_full(ffi::gst_stream_new(
stream_id.0, stream_id.0,
caps.0, caps.0,
type_.to_glib(), type_.to_glib(),
@ -38,7 +37,7 @@ impl Stream {
} else { } else {
// Work-around for 1.14 switching from transfer-floating to transfer-full // Work-around for 1.14 switching from transfer-floating to transfer-full
unsafe { unsafe {
from_glib_none(gst_sys::gst_stream_new( from_glib_none(ffi::gst_stream_new(
stream_id.0, stream_id.0,
caps.0, caps.0,
type_.to_glib(), type_.to_glib(),

View file

@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::Stream;
use crate::StreamCollection;
use glib::translate::*; use glib::translate::*;
use gst_sys;
use std::fmt; use std::fmt;
use Stream;
use StreamCollection;
#[derive(Debug)] #[derive(Debug)]
pub struct Iter<'a> { pub struct Iter<'a> {
@ -74,10 +73,7 @@ pub struct StreamCollectionBuilder(StreamCollection);
impl StreamCollectionBuilder { impl StreamCollectionBuilder {
pub fn stream(self, stream: &Stream) -> Self { pub fn stream(self, stream: &Stream) -> Self {
unsafe { unsafe {
gst_sys::gst_stream_collection_add_stream( ffi::gst_stream_collection_add_stream((self.0).to_glib_none().0, stream.to_glib_full());
(self.0).to_glib_none().0,
stream.to_glib_full(),
);
} }
self self
@ -86,7 +82,7 @@ impl StreamCollectionBuilder {
pub fn streams<S: AsRef<Stream>>(self, streams: &[S]) -> Self { pub fn streams<S: AsRef<Stream>>(self, streams: &[S]) -> Self {
for stream in streams { for stream in streams {
unsafe { unsafe {
gst_sys::gst_stream_collection_add_stream( ffi::gst_stream_collection_add_stream(
(self.0).to_glib_none().0, (self.0).to_glib_none().0,
stream.as_ref().to_glib_full(), stream.as_ref().to_glib_full(),
); );
@ -105,12 +101,12 @@ impl StreamCollection {
pub fn builder(upstream_id: Option<&str>) -> StreamCollectionBuilder { pub fn builder(upstream_id: Option<&str>) -> StreamCollectionBuilder {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let upstream_id = upstream_id.to_glib_none(); let upstream_id = upstream_id.to_glib_none();
let (major, minor, _, _) = ::version(); let (major, minor, _, _) = crate::version();
let collection = if (major, minor) > (1, 12) { let collection = if (major, minor) > (1, 12) {
unsafe { from_glib_full(gst_sys::gst_stream_collection_new(upstream_id.0)) } unsafe { from_glib_full(ffi::gst_stream_collection_new(upstream_id.0)) }
} else { } else {
// Work-around for 1.14 switching from transfer-floating to transfer-full // Work-around for 1.14 switching from transfer-floating to transfer-full
unsafe { from_glib_none(gst_sys::gst_stream_collection_new(upstream_id.0)) } unsafe { from_glib_none(ffi::gst_stream_collection_new(upstream_id.0)) }
}; };
StreamCollectionBuilder(collection) StreamCollectionBuilder(collection)

View file

@ -16,17 +16,14 @@ use std::str;
use thiserror::Error; use thiserror::Error;
use Fraction; use crate::Fraction;
use glib; use glib::ffi::gpointer;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, Stash, StashMut, from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, Stash, StashMut,
ToGlib, ToGlibPtr, ToGlibPtrMut, ToGlib, ToGlibPtr, ToGlibPtrMut,
}; };
use glib::value::{FromValue, FromValueOptional, SendValue, ToSendValue}; use glib::value::{FromValue, FromValueOptional, SendValue, ToSendValue};
use glib_sys::gpointer;
use gobject_sys;
use gst_sys;
#[derive(Clone, Debug, Eq, PartialEq, Error)] #[derive(Clone, Debug, Eq, PartialEq, Error)]
pub enum GetError<'name> { pub enum GetError<'name> {
@ -68,7 +65,7 @@ impl Structure {
pub fn new_empty(name: &str) -> Structure { pub fn new_empty(name: &str) -> Structure {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let ptr = gst_sys::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef; let ptr = ffi::gst_structure_new_empty(name.to_glib_none().0) as *mut StructureRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr)) Structure(ptr::NonNull::new_unchecked(ptr))
} }
@ -85,9 +82,9 @@ impl Structure {
structure structure
} }
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstStructure { pub unsafe fn into_ptr(self) -> *mut ffi::GstStructure {
let s = mem::ManuallyDrop::new(self); let s = mem::ManuallyDrop::new(self);
s.0.as_ptr() as *mut StructureRef as *mut gst_sys::GstStructure s.0.as_ptr() as *mut StructureRef as *mut ffi::GstStructure
} }
#[allow(clippy::should_implement_trait)] #[allow(clippy::should_implement_trait)]
@ -100,7 +97,7 @@ impl Structure {
iter.into_iter().for_each(|(f, v)| unsafe { iter.into_iter().for_each(|(f, v)| unsafe {
let mut value = v.clone().into_raw(); let mut value = v.clone().into_raw();
gst_sys::gst_structure_take_value( ffi::gst_structure_take_value(
&mut structure.0.as_mut().0, &mut structure.0.as_mut().0,
f.to_glib_none().0, f.to_glib_none().0,
&mut value, &mut value,
@ -140,7 +137,7 @@ impl AsMut<StructureRef> for Structure {
impl Clone for Structure { impl Clone for Structure {
fn clone(&self) -> Self { fn clone(&self) -> Self {
unsafe { unsafe {
let ptr = gst_sys::gst_structure_copy(&self.0.as_ref().0) as *mut StructureRef; let ptr = ffi::gst_structure_copy(&self.0.as_ref().0) as *mut StructureRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr)) Structure(ptr::NonNull::new_unchecked(ptr))
} }
@ -149,7 +146,7 @@ impl Clone for Structure {
impl Drop for Structure { impl Drop for Structure {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { gst_sys::gst_structure_free(&mut self.0.as_mut().0) } unsafe { ffi::gst_structure_free(&mut self.0.as_mut().0) }
} }
} }
@ -187,9 +184,11 @@ impl str::FromStr for Structure {
fn from_str(s: &str) -> Result<Self, glib::BoolError> { fn from_str(s: &str) -> Result<Self, glib::BoolError> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
let structure = gst_sys::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut()); let structure = ffi::gst_structure_from_string(s.to_glib_none().0, ptr::null_mut());
if structure.is_null() { if structure.is_null() {
Err(glib_bool_error!("Failed to parse structure from string")) Err(glib::glib_bool_error!(
"Failed to parse structure from string"
))
} else { } else {
Ok(Structure(ptr::NonNull::new_unchecked( Ok(Structure(ptr::NonNull::new_unchecked(
structure as *mut StructureRef, structure as *mut StructureRef,
@ -216,7 +215,7 @@ impl ToOwned for StructureRef {
fn to_owned(&self) -> Structure { fn to_owned(&self) -> Structure {
unsafe { unsafe {
let ptr = gst_sys::gst_structure_copy(&self.0) as *mut StructureRef; let ptr = ffi::gst_structure_copy(&self.0) as *mut StructureRef;
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr)) Structure(ptr::NonNull::new_unchecked(ptr))
} }
@ -225,69 +224,69 @@ impl ToOwned for StructureRef {
impl glib::types::StaticType for Structure { impl glib::types::StaticType for Structure {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_structure_get_type()) } unsafe { from_glib(ffi::gst_structure_get_type()) }
} }
} }
impl<'a> ToGlibPtr<'a, *const gst_sys::GstStructure> for Structure { impl<'a> ToGlibPtr<'a, *const ffi::GstStructure> for Structure {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none(&'a self) -> Stash<'a, *const gst_sys::GstStructure, Self> { fn to_glib_none(&'a self) -> Stash<'a, *const ffi::GstStructure, Self> {
unsafe { Stash(&self.0.as_ref().0, self) } unsafe { Stash(&self.0.as_ref().0, self) }
} }
fn to_glib_full(&self) -> *const gst_sys::GstStructure { fn to_glib_full(&self) -> *const ffi::GstStructure {
unsafe { gst_sys::gst_structure_copy(&self.0.as_ref().0) } unsafe { ffi::gst_structure_copy(&self.0.as_ref().0) }
} }
} }
impl<'a> ToGlibPtr<'a, *mut gst_sys::GstStructure> for Structure { impl<'a> ToGlibPtr<'a, *mut ffi::GstStructure> for Structure {
type Storage = &'a Self; type Storage = &'a Self;
fn to_glib_none(&'a self) -> Stash<'a, *mut gst_sys::GstStructure, Self> { fn to_glib_none(&'a self) -> Stash<'a, *mut ffi::GstStructure, Self> {
unsafe { Stash(&self.0.as_ref().0 as *const _ as *mut _, self) } unsafe { Stash(&self.0.as_ref().0 as *const _ as *mut _, self) }
} }
fn to_glib_full(&self) -> *mut gst_sys::GstStructure { fn to_glib_full(&self) -> *mut ffi::GstStructure {
unsafe { gst_sys::gst_structure_copy(&self.0.as_ref().0) } unsafe { ffi::gst_structure_copy(&self.0.as_ref().0) }
} }
} }
impl<'a> ToGlibPtrMut<'a, *mut gst_sys::GstStructure> for Structure { impl<'a> ToGlibPtrMut<'a, *mut ffi::GstStructure> for Structure {
type Storage = &'a mut Self; type Storage = &'a mut Self;
fn to_glib_none_mut(&'a mut self) -> StashMut<*mut gst_sys::GstStructure, Self> { fn to_glib_none_mut(&'a mut self) -> StashMut<*mut ffi::GstStructure, Self> {
unsafe { StashMut(&mut self.0.as_mut().0, self) } unsafe { StashMut(&mut self.0.as_mut().0, self) }
} }
} }
impl FromGlibPtrNone<*const gst_sys::GstStructure> for Structure { impl FromGlibPtrNone<*const ffi::GstStructure> for Structure {
unsafe fn from_glib_none(ptr: *const gst_sys::GstStructure) -> Self { unsafe fn from_glib_none(ptr: *const ffi::GstStructure) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_structure_copy(ptr); let ptr = ffi::gst_structure_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef)) Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
} }
} }
impl FromGlibPtrNone<*mut gst_sys::GstStructure> for Structure { impl FromGlibPtrNone<*mut ffi::GstStructure> for Structure {
unsafe fn from_glib_none(ptr: *mut gst_sys::GstStructure) -> Self { unsafe fn from_glib_none(ptr: *mut ffi::GstStructure) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
let ptr = gst_sys::gst_structure_copy(ptr); let ptr = ffi::gst_structure_copy(ptr);
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef)) Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
} }
} }
impl FromGlibPtrFull<*const gst_sys::GstStructure> for Structure { impl FromGlibPtrFull<*const ffi::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *const gst_sys::GstStructure) -> Self { unsafe fn from_glib_full(ptr: *const ffi::GstStructure) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef)) Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
} }
} }
impl FromGlibPtrFull<*mut gst_sys::GstStructure> for Structure { impl FromGlibPtrFull<*mut ffi::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstStructure) -> Self { unsafe fn from_glib_full(ptr: *mut ffi::GstStructure) -> Self {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef)) Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
} }
@ -316,36 +315,34 @@ impl glib::value::SetValueOptional for Structure {
} }
impl GlibPtrDefault for Structure { impl GlibPtrDefault for Structure {
type GlibType = *mut gst_sys::GstStructure; type GlibType = *mut ffi::GstStructure;
} }
#[repr(transparent)] #[repr(transparent)]
pub struct StructureRef(gst_sys::GstStructure); pub struct StructureRef(ffi::GstStructure);
unsafe impl Send for StructureRef {} unsafe impl Send for StructureRef {}
unsafe impl Sync for StructureRef {} unsafe impl Sync for StructureRef {}
impl StructureRef { impl StructureRef {
pub unsafe fn from_glib_borrow<'a>(ptr: *const gst_sys::GstStructure) -> &'a StructureRef { pub unsafe fn from_glib_borrow<'a>(ptr: *const ffi::GstStructure) -> &'a StructureRef {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
&*(ptr as *mut StructureRef) &*(ptr as *mut StructureRef)
} }
pub unsafe fn from_glib_borrow_mut<'a>( pub unsafe fn from_glib_borrow_mut<'a>(ptr: *mut ffi::GstStructure) -> &'a mut StructureRef {
ptr: *mut gst_sys::GstStructure,
) -> &'a mut StructureRef {
assert!(!ptr.is_null()); assert!(!ptr.is_null());
&mut *(ptr as *mut StructureRef) &mut *(ptr as *mut StructureRef)
} }
pub unsafe fn as_ptr(&self) -> *const gst_sys::GstStructure { pub unsafe fn as_ptr(&self) -> *const ffi::GstStructure {
self as *const Self as *const gst_sys::GstStructure self as *const Self as *const ffi::GstStructure
} }
pub unsafe fn as_mut_ptr(&self) -> *mut gst_sys::GstStructure { pub unsafe fn as_mut_ptr(&self) -> *mut ffi::GstStructure {
self as *const Self as *mut gst_sys::GstStructure self as *const Self as *mut ffi::GstStructure
} }
pub fn get<'structure, 'name, T: FromValueOptional<'structure>>( pub fn get<'structure, 'name, T: FromValueOptional<'structure>>(
@ -385,7 +382,7 @@ impl StructureRef {
name: &'name str, name: &'name str,
) -> Result<&SendValue, GetError<'name>> { ) -> Result<&SendValue, GetError<'name>> {
unsafe { unsafe {
let value = gst_sys::gst_structure_get_value(&self.0, name.to_glib_none().0); let value = ffi::gst_structure_get_value(&self.0, name.to_glib_none().0);
if value.is_null() { if value.is_null() {
return Err(GetError::new_field_not_found(name)); return Err(GetError::new_field_not_found(name));
@ -403,25 +400,25 @@ impl StructureRef {
pub fn set_value(&mut self, name: &str, value: SendValue) { pub fn set_value(&mut self, name: &str, value: SendValue) {
unsafe { unsafe {
let mut value = value.into_raw(); let mut value = value.into_raw();
gst_sys::gst_structure_take_value(&mut self.0, name.to_glib_none().0, &mut value); ffi::gst_structure_take_value(&mut self.0, name.to_glib_none().0, &mut value);
} }
} }
pub fn get_name<'a>(&self) -> &'a str { pub fn get_name<'a>(&self) -> &'a str {
unsafe { unsafe {
CStr::from_ptr(gst_sys::gst_structure_get_name(&self.0)) CStr::from_ptr(ffi::gst_structure_get_name(&self.0))
.to_str() .to_str()
.unwrap() .unwrap()
} }
} }
pub fn set_name(&mut self, name: &str) { pub fn set_name(&mut self, name: &str) {
unsafe { gst_sys::gst_structure_set_name(&mut self.0, name.to_glib_none().0) } unsafe { ffi::gst_structure_set_name(&mut self.0, name.to_glib_none().0) }
} }
pub fn has_field(&self, field: &str) -> bool { pub fn has_field(&self, field: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_has_field( from_glib(ffi::gst_structure_has_field(
&self.0, &self.0,
field.to_glib_none().0, field.to_glib_none().0,
)) ))
@ -430,7 +427,7 @@ impl StructureRef {
pub fn has_field_with_type(&self, field: &str, type_: glib::Type) -> bool { pub fn has_field_with_type(&self, field: &str, type_: glib::Type) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_has_field_typed( from_glib(ffi::gst_structure_has_field_typed(
&self.0, &self.0,
field.to_glib_none().0, field.to_glib_none().0,
type_.to_glib(), type_.to_glib(),
@ -440,7 +437,7 @@ impl StructureRef {
pub fn remove_field(&mut self, field: &str) { pub fn remove_field(&mut self, field: &str) {
unsafe { unsafe {
gst_sys::gst_structure_remove_field(&mut self.0, field.to_glib_none().0); ffi::gst_structure_remove_field(&mut self.0, field.to_glib_none().0);
} }
} }
@ -452,7 +449,7 @@ impl StructureRef {
pub fn remove_all_fields(&mut self) { pub fn remove_all_fields(&mut self) {
unsafe { unsafe {
gst_sys::gst_structure_remove_all_fields(&mut self.0); ffi::gst_structure_remove_all_fields(&mut self.0);
} }
} }
@ -466,7 +463,7 @@ impl StructureRef {
pub fn get_nth_field_name<'a>(&self, idx: u32) -> Option<&'a str> { pub fn get_nth_field_name<'a>(&self, idx: u32) -> Option<&'a str> {
unsafe { unsafe {
let field_name = gst_sys::gst_structure_nth_field_name(&self.0, idx); let field_name = ffi::gst_structure_nth_field_name(&self.0, idx);
if field_name.is_null() { if field_name.is_null() {
return None; return None;
} }
@ -476,28 +473,28 @@ impl StructureRef {
} }
pub fn n_fields(&self) -> u32 { pub fn n_fields(&self) -> u32 {
unsafe { gst_sys::gst_structure_n_fields(&self.0) as u32 } unsafe { ffi::gst_structure_n_fields(&self.0) as u32 }
} }
pub fn can_intersect(&self, other: &StructureRef) -> bool { pub fn can_intersect(&self, other: &StructureRef) -> bool {
unsafe { from_glib(gst_sys::gst_structure_can_intersect(&self.0, &other.0)) } unsafe { from_glib(ffi::gst_structure_can_intersect(&self.0, &other.0)) }
} }
pub fn intersect(&self, other: &StructureRef) -> Option<Structure> { pub fn intersect(&self, other: &StructureRef) -> Option<Structure> {
unsafe { from_glib_full(gst_sys::gst_structure_intersect(&self.0, &other.0)) } unsafe { from_glib_full(ffi::gst_structure_intersect(&self.0, &other.0)) }
} }
pub fn is_subset(&self, superset: &StructureRef) -> bool { pub fn is_subset(&self, superset: &StructureRef) -> bool {
unsafe { from_glib(gst_sys::gst_structure_is_subset(&self.0, &superset.0)) } unsafe { from_glib(ffi::gst_structure_is_subset(&self.0, &superset.0)) }
} }
pub fn fixate(&mut self) { pub fn fixate(&mut self) {
unsafe { gst_sys::gst_structure_fixate(&mut self.0) } unsafe { ffi::gst_structure_fixate(&mut self.0) }
} }
pub fn fixate_field(&mut self, name: &str) -> bool { pub fn fixate_field(&mut self, name: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_fixate_field( from_glib(ffi::gst_structure_fixate_field(
&mut self.0, &mut self.0,
name.to_glib_none().0, name.to_glib_none().0,
)) ))
@ -506,7 +503,7 @@ impl StructureRef {
pub fn fixate_field_bool(&mut self, name: &str, target: bool) -> bool { pub fn fixate_field_bool(&mut self, name: &str, target: bool) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_fixate_field_boolean( from_glib(ffi::gst_structure_fixate_field_boolean(
&mut self.0, &mut self.0,
name.to_glib_none().0, name.to_glib_none().0,
target.to_glib(), target.to_glib(),
@ -516,7 +513,7 @@ impl StructureRef {
pub fn fixate_field_str(&mut self, name: &str, target: &str) -> bool { pub fn fixate_field_str(&mut self, name: &str, target: &str) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_fixate_field_string( from_glib(ffi::gst_structure_fixate_field_string(
&mut self.0, &mut self.0,
name.to_glib_none().0, name.to_glib_none().0,
target.to_glib_none().0, target.to_glib_none().0,
@ -526,7 +523,7 @@ impl StructureRef {
pub fn fixate_field_nearest_double(&mut self, name: &str, target: f64) -> bool { pub fn fixate_field_nearest_double(&mut self, name: &str, target: f64) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_fixate_field_nearest_double( from_glib(ffi::gst_structure_fixate_field_nearest_double(
&mut self.0, &mut self.0,
name.to_glib_none().0, name.to_glib_none().0,
target, target,
@ -543,7 +540,7 @@ impl StructureRef {
let target = target.into(); let target = target.into();
unsafe { unsafe {
from_glib(gst_sys::gst_structure_fixate_field_nearest_fraction( from_glib(ffi::gst_structure_fixate_field_nearest_fraction(
&mut self.0, &mut self.0,
name.to_glib_none().0, name.to_glib_none().0,
*target.numer(), *target.numer(),
@ -554,7 +551,7 @@ impl StructureRef {
pub fn fixate_field_nearest_int(&mut self, name: &str, target: i32) -> bool { pub fn fixate_field_nearest_int(&mut self, name: &str, target: i32) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_structure_fixate_field_nearest_int( from_glib(ffi::gst_structure_fixate_field_nearest_int(
&mut self.0, &mut self.0,
name.to_glib_none().0, name.to_glib_none().0,
target, target,
@ -565,7 +562,7 @@ impl StructureRef {
impl fmt::Display for StructureRef { impl fmt::Display for StructureRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = unsafe { glib::GString::from_glib_full(gst_sys::gst_structure_to_string(&self.0)) }; let s = unsafe { glib::GString::from_glib_full(ffi::gst_structure_to_string(&self.0)) };
f.write_str(&s) f.write_str(&s)
} }
} }
@ -578,7 +575,7 @@ impl fmt::Debug for StructureRef {
impl PartialEq for StructureRef { impl PartialEq for StructureRef {
fn eq(&self, other: &StructureRef) -> bool { fn eq(&self, other: &StructureRef) -> bool {
unsafe { from_glib(gst_sys::gst_structure_is_equal(&self.0, &other.0)) } unsafe { from_glib(ffi::gst_structure_is_equal(&self.0, &other.0)) }
} }
} }
@ -586,18 +583,18 @@ impl Eq for StructureRef {}
impl glib::types::StaticType for StructureRef { impl glib::types::StaticType for StructureRef {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_structure_get_type()) } unsafe { from_glib(ffi::gst_structure_get_type()) }
} }
} }
impl<'a> glib::value::FromValueOptional<'a> for &'a StructureRef { impl<'a> glib::value::FromValueOptional<'a> for &'a StructureRef {
unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> { unsafe fn from_value_optional(v: &'a glib::Value) -> Option<Self> {
let ptr = gobject_sys::g_value_get_boxed(v.to_glib_none().0); let ptr = glib::gobject_ffi::g_value_get_boxed(v.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
None None
} else { } else {
Some(StructureRef::from_glib_borrow( Some(StructureRef::from_glib_borrow(
ptr as *const gst_sys::GstStructure, ptr as *const ffi::GstStructure,
)) ))
} }
} }
@ -605,16 +602,16 @@ impl<'a> glib::value::FromValueOptional<'a> for &'a StructureRef {
impl glib::value::SetValue for StructureRef { impl glib::value::SetValue for StructureRef {
unsafe fn set_value(v: &mut glib::Value, s: &Self) { 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); glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} }
} }
impl glib::value::SetValueOptional for StructureRef { impl glib::value::SetValueOptional for StructureRef {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) { unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
if let Some(s) = s { if let Some(s) = s {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer); glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} else { } else {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut()); glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut());
} }
} }
} }
@ -759,7 +756,7 @@ mod tests {
fn new_set_get() { fn new_set_get() {
use glib::{value, Type}; use glib::{value, Type};
::init().unwrap(); crate::init().unwrap();
let mut s = Structure::new_empty("test"); let mut s = Structure::new_empty("test");
assert_eq!(s.get_name(), "test"); assert_eq!(s.get_name(), "test");
@ -816,7 +813,7 @@ mod tests {
#[test] #[test]
fn test_builder() { fn test_builder() {
::init().unwrap(); crate::init().unwrap();
let s = Structure::builder("test") let s = Structure::builder("test")
.field("f1", &"abc") .field("f1", &"abc")
@ -832,7 +829,7 @@ mod tests {
#[test] #[test]
fn test_string_conversion() { fn test_string_conversion() {
::init().unwrap(); crate::init().unwrap();
let a = "Test, f1=(string)abc, f2=(uint)123;"; let a = "Test, f1=(string)abc, f2=(uint)123;";
@ -845,7 +842,7 @@ mod tests {
#[test] #[test]
fn test_from_value_optional() { fn test_from_value_optional() {
::init().unwrap(); crate::init().unwrap();
let a = glib::value::Value::from(None::<&Structure>); let a = glib::value::Value::from(None::<&Structure>);
assert!(a.get::<Structure>().unwrap().is_none()); assert!(a.get::<Structure>().unwrap().is_none());
@ -855,7 +852,7 @@ mod tests {
#[test] #[test]
fn test_new_from_iter() { fn test_new_from_iter() {
::init().unwrap(); crate::init().unwrap();
let s = Structure::builder("test") let s = Structure::builder("test")
.field("f1", &"abc") .field("f1", &"abc")

View file

@ -6,7 +6,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::{Date, ToValue}; use glib::{Date, ToValue};
use serde::de; use serde::de;
@ -16,16 +15,16 @@ use serde::ser::{Serialize, SerializeSeq, SerializeTuple, Serializer};
use std::fmt; use std::fmt;
use Buffer; use crate::Buffer;
use DateTime; use crate::DateTime;
use Sample; use crate::Sample;
use date_time_serde; use crate::date_time_serde;
use value::*; use crate::value::*;
use value_serde::*; use crate::value_serde::*;
use Structure; use crate::Structure;
use StructureRef; use crate::StructureRef;
struct FieldSe<'a>(&'static str, &'a glib::SendValue); struct FieldSe<'a>(&'static str, &'a glib::SendValue);
impl<'a> Serialize for FieldSe<'a> { impl<'a> Serialize for FieldSe<'a> {
@ -169,18 +168,16 @@ impl<'de> Deserialize<'de> for Structure {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron;
use glib::{Date, DateMonth}; use glib::{Date, DateMonth};
use Array; use crate::Array;
use DateTime; use crate::DateTime;
use Fraction; use crate::Fraction;
use Structure; use crate::Structure;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let s = Structure::builder("test") let s = Structure::builder("test")
.field("f1", &"abc") .field("f1", &"abc")
@ -221,7 +218,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
::init().unwrap(); crate::init().unwrap();
let s_ron = r#" let s_ron = r#"
("test", [ ("test", [
@ -260,7 +257,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let s = Structure::builder("test") let s = Structure::builder("test")
.field("f1", &"abc") .field("f1", &"abc")

View file

@ -6,19 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gst_sys;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::*; use glib::translate::*;
use super::prelude::*; use super::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use Bin; use crate::Bin;
use Element; use crate::Element;
use LoggableError; use crate::LoggableError;
use Message; use crate::Message;
pub trait BinImpl: BinImplExt + ElementImpl { pub trait BinImpl: BinImplExt + ElementImpl {
fn add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> { fn add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> {
@ -50,16 +47,19 @@ impl<T: BinImpl> BinImplExt for T {
fn parent_add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> { fn parent_add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstBinClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
let f = (*parent_class).add_element.ok_or_else(|| { let f = (*parent_class).add_element.ok_or_else(|| {
gst_loggable_error!(::CAT_RUST, "Parent function `add_element` is not defined") gst_loggable_error!(
crate::CAT_RUST,
"Parent function `add_element` is not defined"
)
})?; })?;
gst_result_from_gboolean!( gst_result_from_gboolean!(
f( f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0, bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0,
element.to_glib_none().0 element.to_glib_none().0
), ),
::CAT_RUST, crate::CAT_RUST,
"Failed to add the element using the parent function" "Failed to add the element using the parent function"
) )
} }
@ -72,19 +72,19 @@ impl<T: BinImpl> BinImplExt for T {
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstBinClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
let f = (*parent_class).remove_element.ok_or_else(|| { let f = (*parent_class).remove_element.ok_or_else(|| {
gst_loggable_error!( gst_loggable_error!(
::CAT_RUST, crate::CAT_RUST,
"Parent function `remove_element` is not defined" "Parent function `remove_element` is not defined"
) )
})?; })?;
gst_result_from_gboolean!( gst_result_from_gboolean!(
f( f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0, bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0,
element.to_glib_none().0 element.to_glib_none().0
), ),
::CAT_RUST, crate::CAT_RUST,
"Failed to remove the element using the parent function" "Failed to remove the element using the parent function"
) )
} }
@ -93,10 +93,10 @@ impl<T: BinImpl> BinImplExt for T {
fn parent_handle_message(&self, bin: &Self::Type, message: Message) { fn parent_handle_message(&self, bin: &Self::Type, message: Message) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstBinClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
if let Some(ref f) = (*parent_class).handle_message { if let Some(ref f) = (*parent_class).handle_message {
f( f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0, bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0,
message.into_ptr(), message.into_ptr(),
); );
} }
@ -109,7 +109,7 @@ where
<T as ObjectSubclass>::Instance: PanicPoison, <T as ObjectSubclass>::Instance: PanicPoison,
{ {
fn override_vfuncs(klass: &mut glib::Class<Self>) { fn override_vfuncs(klass: &mut glib::Class<Self>) {
<::Element as IsSubclassable<T>>::override_vfuncs(klass); <crate::Element as IsSubclassable<T>>::override_vfuncs(klass);
let klass = klass.as_mut(); let klass = klass.as_mut();
klass.add_element = Some(bin_add_element::<T>); klass.add_element = Some(bin_add_element::<T>);
klass.remove_element = Some(bin_remove_element::<T>); klass.remove_element = Some(bin_remove_element::<T>);
@ -118,9 +118,9 @@ where
} }
unsafe extern "C" fn bin_add_element<T: BinImpl>( unsafe extern "C" fn bin_add_element<T: BinImpl>(
ptr: *mut gst_sys::GstBin, ptr: *mut ffi::GstBin,
element: *mut gst_sys::GstElement, element: *mut ffi::GstElement,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -141,9 +141,9 @@ where
} }
unsafe extern "C" fn bin_remove_element<T: BinImpl>( unsafe extern "C" fn bin_remove_element<T: BinImpl>(
ptr: *mut gst_sys::GstBin, ptr: *mut ffi::GstBin,
element: *mut gst_sys::GstElement, element: *mut ffi::GstElement,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -154,8 +154,10 @@ where
// If we get a floating reference passed simply return FALSE here. It can't be // If we get a floating reference passed simply return FALSE here. It can't be
// stored inside this bin, and if we continued to use it we would take ownership // stored inside this bin, and if we continued to use it we would take ownership
// of this floating reference. // of this floating reference.
if gobject_sys::g_object_is_floating(element as *mut gobject_sys::GObject) != glib_sys::GFALSE { if glib::gobject_ffi::g_object_is_floating(element as *mut glib::gobject_ffi::GObject)
return glib_sys::GFALSE; != glib::ffi::GFALSE
{
return glib::ffi::GFALSE;
} }
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
@ -171,8 +173,8 @@ where
} }
unsafe extern "C" fn bin_handle_message<T: BinImpl>( unsafe extern "C" fn bin_handle_message<T: BinImpl>(
ptr: *mut gst_sys::GstBin, ptr: *mut ffi::GstBin,
message: *mut gst_sys::GstMessage, message: *mut ffi::GstMessage,
) where ) where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {

View file

@ -6,25 +6,18 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gobject_sys;
use gst_sys;
use glib;
use glib::prelude::*; use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use libc; use crate::ChildProxy;
use ChildProxy;
pub trait ChildProxyImpl: ObjectImpl + Send + Sync { pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> { fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> {
unsafe { unsafe {
let type_ = gst_sys::gst_child_proxy_get_type(); let type_ = ffi::gst_child_proxy_get_type();
let iface = gobject_sys::g_type_default_interface_ref(type_) let iface = glib::gobject_ffi::g_type_default_interface_ref(type_)
as *mut gst_sys::GstChildProxyInterface; as *mut ffi::GstChildProxyInterface;
assert!(!iface.is_null()); assert!(!iface.is_null());
let ret = ((*iface).get_child_by_name.as_ref().unwrap())( let ret = ((*iface).get_child_by_name.as_ref().unwrap())(
@ -32,7 +25,7 @@ pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
name.to_glib_none().0, name.to_glib_none().0,
); );
gobject_sys::g_type_default_interface_unref(iface as glib_sys::gpointer); glib::gobject_ffi::g_type_default_interface_unref(iface as glib::ffi::gpointer);
from_glib_full(ret) from_glib_full(ret)
} }
@ -47,10 +40,10 @@ pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy { unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
unsafe extern "C" fn interface_init( unsafe extern "C" fn interface_init(
iface: glib_sys::gpointer, iface: glib::ffi::gpointer,
_iface_data: glib_sys::gpointer, _iface_data: glib::ffi::gpointer,
) { ) {
let child_proxy_iface = &mut *(iface as *mut gst_sys::GstChildProxyInterface); let child_proxy_iface = &mut *(iface as *mut ffi::GstChildProxyInterface);
child_proxy_iface.get_child_by_name = Some(child_proxy_get_child_by_name::<T>); child_proxy_iface.get_child_by_name = Some(child_proxy_get_child_by_name::<T>);
child_proxy_iface.get_child_by_index = Some(child_proxy_get_child_by_index::<T>); child_proxy_iface.get_child_by_index = Some(child_proxy_get_child_by_index::<T>);
@ -61,9 +54,9 @@ unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
} }
unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
child_proxy: *mut gst_sys::GstChildProxy, child_proxy: *mut ffi::GstChildProxy,
name: *const libc::c_char, name: *const libc::c_char,
) -> *mut gobject_sys::GObject { ) -> *mut glib::gobject_ffi::GObject {
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -75,9 +68,9 @@ unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
} }
unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
child_proxy: *mut gst_sys::GstChildProxy, child_proxy: *mut ffi::GstChildProxy,
index: u32, index: u32,
) -> *mut gobject_sys::GObject { ) -> *mut glib::gobject_ffi::GObject {
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -89,7 +82,7 @@ unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
} }
unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
child_proxy: *mut gst_sys::GstChildProxy, child_proxy: *mut ffi::GstChildProxy,
) -> u32 { ) -> u32 {
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -98,8 +91,8 @@ unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
} }
unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
child_proxy: *mut gst_sys::GstChildProxy, child_proxy: *mut ffi::GstChildProxy,
child: *mut gobject_sys::GObject, child: *mut glib::gobject_ffi::GObject,
name: *const libc::c_char, name: *const libc::c_char,
) { ) {
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);
@ -113,8 +106,8 @@ unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
} }
unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>( unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>(
child_proxy: *mut gst_sys::GstChildProxy, child_proxy: *mut ffi::GstChildProxy,
child: *mut gobject_sys::GObject, child: *mut glib::gobject_ffi::GObject,
name: *const libc::c_char, name: *const libc::c_char,
) { ) {
let instance = &*(child_proxy as *mut T::Instance); let instance = &*(child_proxy as *mut T::Instance);

View file

@ -6,20 +6,17 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_sys;
use glib;
use glib::prelude::*; use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use Clock; use crate::Clock;
use ClockError; use crate::ClockError;
use ClockId; use crate::ClockId;
use ClockReturn; use crate::ClockReturn;
use ClockSuccess; use crate::ClockSuccess;
use ClockTime; use crate::ClockTime;
use ClockTimeDiff; use crate::ClockTimeDiff;
pub trait ClockImpl: ClockImplExt + ObjectImpl + Send + Sync { pub trait ClockImpl: ClockImplExt + ObjectImpl + Send + Sync {
fn change_resolution( fn change_resolution(
@ -97,7 +94,7 @@ impl<T: ClockImpl> ClockImplExt for T {
) -> ClockTime { ) -> ClockTime {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstClockClass;
if let Some(func) = (*parent_class).change_resolution { if let Some(func) = (*parent_class).change_resolution {
from_glib(func( from_glib(func(
@ -114,7 +111,7 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_get_resolution(&self, clock: &Self::Type) -> ClockTime { fn parent_get_resolution(&self, clock: &Self::Type) -> ClockTime {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstClockClass;
from_glib( from_glib(
(*parent_class) (*parent_class)
@ -128,7 +125,7 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_get_internal_time(&self, clock: &Self::Type) -> ClockTime { fn parent_get_internal_time(&self, clock: &Self::Type) -> ClockTime {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstClockClass;
from_glib( from_glib(
(*parent_class) (*parent_class)
@ -146,7 +143,7 @@ impl<T: ClockImpl> ClockImplExt for T {
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) { ) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstClockClass;
let mut jitter = 0; let mut jitter = 0;
( (
@ -156,11 +153,11 @@ impl<T: ClockImpl> ClockImplExt for T {
.map(|f| { .map(|f| {
f( f(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
id.to_glib_none().0 as *mut gst_sys::GstClockEntry, id.to_glib_none().0 as *mut ffi::GstClockEntry,
&mut jitter, &mut jitter,
) )
}) })
.unwrap_or(gst_sys::GST_CLOCK_UNSUPPORTED), .unwrap_or(ffi::GST_CLOCK_UNSUPPORTED),
) )
.into_result(), .into_result(),
jitter, jitter,
@ -175,17 +172,17 @@ impl<T: ClockImpl> ClockImplExt for T {
) -> Result<ClockSuccess, ClockError> { ) -> Result<ClockSuccess, ClockError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstClockClass;
ClockReturn::from_glib( ClockReturn::from_glib(
(*parent_class) (*parent_class)
.wait_async .wait_async
.map(|f| { .map(|f| {
f( f(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
id.to_glib_none().0 as *mut gst_sys::GstClockEntry, id.to_glib_none().0 as *mut ffi::GstClockEntry,
) )
}) })
.unwrap_or(gst_sys::GST_CLOCK_UNSUPPORTED), .unwrap_or(ffi::GST_CLOCK_UNSUPPORTED),
) )
.into_result() .into_result()
} }
@ -194,11 +191,11 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId) { fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstClockClass;
if let Some(func) = (*parent_class).unschedule { if let Some(func) = (*parent_class).unschedule {
func( func(
clock.unsafe_cast_ref::<Clock>().to_glib_none().0, clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
id.to_glib_none().0 as *mut gst_sys::GstClockEntry, id.to_glib_none().0 as *mut ffi::GstClockEntry,
); );
} }
} }
@ -211,28 +208,28 @@ impl<T: ClockImpl> ClockImplExt for T {
{ {
let clock = self.get_instance(); let clock = self.get_instance();
cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "v1_16")] { if #[cfg(feature = "v1_16")] {
assert!(id.uses_clock(&clock)); assert!(id.uses_clock(&clock));
} else { } else {
unsafe { unsafe {
let ptr: *mut gst_sys::GstClockEntry = id.to_glib_none().0 as *mut _; let ptr: *mut ffi::GstClockEntry = id.to_glib_none().0 as *mut _;
assert_eq!((*ptr).clock, clock.as_ref().to_glib_none().0); assert_eq!((*ptr).clock, clock.as_ref().to_glib_none().0);
} }
} }
} }
unsafe { unsafe {
let ptr: *mut gst_sys::GstClockEntry = id.to_glib_none().0 as *mut _; let ptr: *mut ffi::GstClockEntry = id.to_glib_none().0 as *mut _;
if let Some(func) = (*ptr).func { if let Some(func) = (*ptr).func {
func( func(
clock.as_ref().to_glib_none().0, clock.as_ref().to_glib_none().0,
(*ptr).time, (*ptr).time,
ptr as gst_sys::GstClockID, ptr as ffi::GstClockID,
(*ptr).user_data, (*ptr).user_data,
); );
} }
if (*ptr).type_ == gst_sys::GST_CLOCK_ENTRY_PERIODIC { if (*ptr).type_ == ffi::GST_CLOCK_ENTRY_PERIODIC {
(*ptr).time += (*ptr).interval; (*ptr).time += (*ptr).interval;
} }
} }
@ -253,10 +250,10 @@ unsafe impl<T: ClockImpl> IsSubclassable<T> for Clock {
} }
unsafe extern "C" fn clock_change_resolution<T: ClockImpl>( unsafe extern "C" fn clock_change_resolution<T: ClockImpl>(
ptr: *mut gst_sys::GstClock, ptr: *mut ffi::GstClock,
old_resolution: gst_sys::GstClockTime, old_resolution: ffi::GstClockTime,
new_resolution: gst_sys::GstClockTime, new_resolution: ffi::GstClockTime,
) -> gst_sys::GstClockTime { ) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr); let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
@ -270,8 +267,8 @@ unsafe extern "C" fn clock_change_resolution<T: ClockImpl>(
} }
unsafe extern "C" fn clock_get_resolution<T: ClockImpl>( unsafe extern "C" fn clock_get_resolution<T: ClockImpl>(
ptr: *mut gst_sys::GstClock, ptr: *mut ffi::GstClock,
) -> gst_sys::GstClockTime { ) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr); let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
@ -280,8 +277,8 @@ unsafe extern "C" fn clock_get_resolution<T: ClockImpl>(
} }
unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>( unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>(
ptr: *mut gst_sys::GstClock, ptr: *mut ffi::GstClock,
) -> gst_sys::GstClockTime { ) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr); let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
@ -290,17 +287,17 @@ unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>(
} }
unsafe extern "C" fn clock_wait<T: ClockImpl>( unsafe extern "C" fn clock_wait<T: ClockImpl>(
ptr: *mut gst_sys::GstClock, ptr: *mut ffi::GstClock,
id: *mut gst_sys::GstClockEntry, id: *mut ffi::GstClockEntry,
jitter: *mut gst_sys::GstClockTimeDiff, jitter: *mut ffi::GstClockTimeDiff,
) -> gst_sys::GstClockReturn { ) -> ffi::GstClockReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr); let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
let (res, j) = imp.wait( let (res, j) = imp.wait(
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID), &from_glib_borrow(id as ffi::GstClockID),
); );
if !jitter.is_null() { if !jitter.is_null() {
*jitter = j; *jitter = j;
@ -310,23 +307,23 @@ unsafe extern "C" fn clock_wait<T: ClockImpl>(
} }
unsafe extern "C" fn clock_wait_async<T: ClockImpl>( unsafe extern "C" fn clock_wait_async<T: ClockImpl>(
ptr: *mut gst_sys::GstClock, ptr: *mut ffi::GstClock,
id: *mut gst_sys::GstClockEntry, id: *mut ffi::GstClockEntry,
) -> gst_sys::GstClockReturn { ) -> ffi::GstClockReturn {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr); let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
ClockReturn::from(imp.wait_async( ClockReturn::from(imp.wait_async(
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID), &from_glib_borrow(id as ffi::GstClockID),
)) ))
.to_glib() .to_glib()
} }
unsafe extern "C" fn clock_unschedule<T: ClockImpl>( unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
ptr: *mut gst_sys::GstClock, ptr: *mut ffi::GstClock,
id: *mut gst_sys::GstClockEntry, id: *mut ffi::GstClockEntry,
) { ) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -334,6 +331,6 @@ unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
imp.unschedule( imp.unschedule(
wrap.unsafe_cast_ref(), wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID), &from_glib_borrow(id as ffi::GstClockID),
); );
} }

View file

@ -6,16 +6,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gst_sys;
use glib::prelude::*; use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use Device; use crate::Device;
use Element; use crate::Element;
use LoggableError; use crate::LoggableError;
use std::ptr; use std::ptr;
@ -59,7 +56,7 @@ impl<T: DeviceImpl> DeviceImplExt for T {
) -> Result<Element, LoggableError> { ) -> Result<Element, LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceClass;
if let Some(f) = (*parent_class).create_element { if let Some(f) = (*parent_class).create_element {
let ptr = f( let ptr = f(
device.unsafe_cast_ref::<Device>().to_glib_none().0, device.unsafe_cast_ref::<Device>().to_glib_none().0,
@ -69,13 +66,13 @@ impl<T: DeviceImpl> DeviceImplExt for T {
// Don't steal floating reference here but pass it further to the caller // Don't steal floating reference here but pass it further to the caller
Option::<_>::from_glib_full(ptr).ok_or_else(|| { Option::<_>::from_glib_full(ptr).ok_or_else(|| {
gst_loggable_error!( gst_loggable_error!(
::CAT_RUST, crate::CAT_RUST,
"Failed to create element using the parent function" "Failed to create element using the parent function"
) )
}) })
} else { } else {
Err(gst_loggable_error!( Err(gst_loggable_error!(
::CAT_RUST, crate::CAT_RUST,
"Parent function `create_element` is not defined" "Parent function `create_element` is not defined"
)) ))
} }
@ -89,10 +86,10 @@ impl<T: DeviceImpl> DeviceImplExt for T {
) -> Result<(), LoggableError> { ) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceClass;
let f = (*parent_class).reconfigure_element.ok_or_else(|| { let f = (*parent_class).reconfigure_element.ok_or_else(|| {
gst_loggable_error!( gst_loggable_error!(
::CAT_RUST, crate::CAT_RUST,
"Parent function `reconfigure_element` is not defined" "Parent function `reconfigure_element` is not defined"
) )
})?; })?;
@ -101,7 +98,7 @@ impl<T: DeviceImpl> DeviceImplExt for T {
device.unsafe_cast_ref::<Device>().to_glib_none().0, device.unsafe_cast_ref::<Device>().to_glib_none().0,
element.to_glib_none().0 element.to_glib_none().0
), ),
::CAT_RUST, crate::CAT_RUST,
"Failed to reconfigure the element using the parent function" "Failed to reconfigure the element using the parent function"
) )
} }
@ -118,9 +115,9 @@ unsafe impl<T: DeviceImpl> IsSubclassable<T> for Device {
} }
unsafe extern "C" fn device_create_element<T: DeviceImpl>( unsafe extern "C" fn device_create_element<T: DeviceImpl>(
ptr: *mut gst_sys::GstDevice, ptr: *mut ffi::GstDevice,
name: *const libc::c_char, name: *const libc::c_char,
) -> *mut gst_sys::GstElement { ) -> *mut ffi::GstElement {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Device> = from_glib_borrow(ptr); let wrap: Borrowed<Device> = from_glib_borrow(ptr);
@ -138,7 +135,9 @@ unsafe extern "C" fn device_create_element<T: DeviceImpl>(
let element_ptr = element.to_glib_full(); let element_ptr = element.to_glib_full();
drop(element); drop(element);
// See https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/444 // See https://gitlab.freedesktop.org/gstreamer/gstreamer/issues/444
gobject_sys::g_object_force_floating(element_ptr as *mut gobject_sys::GObject); glib::gobject_ffi::g_object_force_floating(
element_ptr as *mut glib::gobject_ffi::GObject,
);
element_ptr element_ptr
} }
Err(err) => { Err(err) => {
@ -149,9 +148,9 @@ unsafe extern "C" fn device_create_element<T: DeviceImpl>(
} }
unsafe extern "C" fn device_reconfigure_element<T: DeviceImpl>( unsafe extern "C" fn device_reconfigure_element<T: DeviceImpl>(
ptr: *mut gst_sys::GstDevice, ptr: *mut ffi::GstDevice,
element: *mut gst_sys::GstElement, element: *mut ffi::GstElement,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Device> = from_glib_borrow(ptr); let wrap: Borrowed<Device> = from_glib_borrow(ptr);

View file

@ -6,16 +6,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gst_sys;
use glib::prelude::*; use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use Device; use crate::Device;
use DeviceProvider; use crate::DeviceProvider;
use LoggableError; use crate::LoggableError;
pub trait DeviceProviderImpl: DeviceProviderImplExt + ObjectImpl + Send + Sync { pub trait DeviceProviderImpl: DeviceProviderImplExt + ObjectImpl + Send + Sync {
fn probe(&self, device_provider: &Self::Type) -> Vec<Device> { fn probe(&self, device_provider: &Self::Type) -> Vec<Device> {
@ -43,8 +40,7 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
fn parent_probe(&self, device_provider: &Self::Type) -> Vec<Device> { fn parent_probe(&self, device_provider: &Self::Type) -> Vec<Device> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceProviderClass;
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
if let Some(f) = (*parent_class).probe { if let Some(f) = (*parent_class).probe {
FromGlibPtrContainer::from_glib_full(f(device_provider FromGlibPtrContainer::from_glib_full(f(device_provider
.unsafe_cast_ref::<DeviceProvider>() .unsafe_cast_ref::<DeviceProvider>()
@ -59,17 +55,16 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> { fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceProviderClass;
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
let f = (*parent_class).start.ok_or_else(|| { let f = (*parent_class).start.ok_or_else(|| {
gst_loggable_error!(::CAT_RUST, "Parent function `start` is not defined") gst_loggable_error!(crate::CAT_RUST, "Parent function `start` is not defined")
})?; })?;
gst_result_from_gboolean!( gst_result_from_gboolean!(
f(device_provider f(device_provider
.unsafe_cast_ref::<DeviceProvider>() .unsafe_cast_ref::<DeviceProvider>()
.to_glib_none() .to_glib_none()
.0), .0),
::CAT_RUST, crate::CAT_RUST,
"Failed to start the device provider using the parent function" "Failed to start the device provider using the parent function"
) )
} }
@ -78,8 +73,7 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
fn parent_stop(&self, device_provider: &Self::Type) { fn parent_stop(&self, device_provider: &Self::Type) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceProviderClass;
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
if let Some(f) = (*parent_class).stop { if let Some(f) = (*parent_class).stop {
f(device_provider f(device_provider
.unsafe_cast_ref::<DeviceProvider>() .unsafe_cast_ref::<DeviceProvider>()
@ -99,8 +93,8 @@ pub unsafe trait DeviceProviderClassSubclassExt: Sized + 'static {
author: &str, author: &str,
) { ) {
unsafe { unsafe {
gst_sys::gst_device_provider_class_set_metadata( ffi::gst_device_provider_class_set_metadata(
self as *mut Self as *mut gst_sys::GstDeviceProviderClass, self as *mut Self as *mut ffi::GstDeviceProviderClass,
long_name.to_glib_none().0, long_name.to_glib_none().0,
classification.to_glib_none().0, classification.to_glib_none().0,
description.to_glib_none().0, description.to_glib_none().0,
@ -111,8 +105,8 @@ pub unsafe trait DeviceProviderClassSubclassExt: Sized + 'static {
fn add_metadata(&mut self, key: &str, value: &str) { fn add_metadata(&mut self, key: &str, value: &str) {
unsafe { unsafe {
gst_sys::gst_device_provider_class_add_metadata( ffi::gst_device_provider_class_add_metadata(
self as *mut Self as *mut gst_sys::GstDeviceProviderClass, self as *mut Self as *mut ffi::GstDeviceProviderClass,
key.to_glib_none().0, key.to_glib_none().0,
value.to_glib_none().0, value.to_glib_none().0,
); );
@ -133,8 +127,8 @@ unsafe impl<T: DeviceProviderImpl> IsSubclassable<T> for DeviceProvider {
} }
unsafe extern "C" fn device_provider_probe<T: DeviceProviderImpl>( unsafe extern "C" fn device_provider_probe<T: DeviceProviderImpl>(
ptr: *mut gst_sys::GstDeviceProvider, ptr: *mut ffi::GstDeviceProvider,
) -> *mut glib_sys::GList { ) -> *mut glib::ffi::GList {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr); let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
@ -143,8 +137,8 @@ unsafe extern "C" fn device_provider_probe<T: DeviceProviderImpl>(
} }
unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>( unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
ptr: *mut gst_sys::GstDeviceProvider, ptr: *mut ffi::GstDeviceProvider,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr); let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
@ -159,9 +153,7 @@ unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
.to_glib() .to_glib()
} }
unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>( unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>(ptr: *mut ffi::GstDeviceProvider) {
ptr: *mut gst_sys::GstDeviceProvider,
) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr); let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);

View file

@ -6,26 +6,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use libc;
use glib_sys;
use gst_sys;
use super::prelude::*; use super::prelude::*;
use glib; use crate::prelude::*;
use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use prelude::*;
use Element; use crate::Element;
use Event; use crate::Event;
use PadTemplate; use crate::PadTemplate;
use QueryRef; use crate::QueryRef;
use StateChange; use crate::StateChange;
use StateChangeError; use crate::StateChangeError;
use StateChangeReturn; use crate::StateChangeReturn;
use StateChangeSuccess; use crate::StateChangeSuccess;
pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync { pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
fn change_state( fn change_state(
@ -39,14 +32,14 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
fn request_new_pad( fn request_new_pad(
&self, &self,
element: &Self::Type, element: &Self::Type,
templ: &::PadTemplate, templ: &crate::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&::Caps>, caps: Option<&crate::Caps>,
) -> Option<::Pad> { ) -> Option<crate::Pad> {
self.parent_request_new_pad(element, templ, name, caps) self.parent_request_new_pad(element, templ, name, caps)
} }
fn release_pad(&self, element: &Self::Type, pad: &::Pad) { fn release_pad(&self, element: &Self::Type, pad: &crate::Pad) {
self.parent_release_pad(element, pad) self.parent_release_pad(element, pad)
} }
@ -58,19 +51,19 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
self.parent_query(element, query) self.parent_query(element, query)
} }
fn set_context(&self, element: &Self::Type, context: &::Context) { fn set_context(&self, element: &Self::Type, context: &crate::Context) {
self.parent_set_context(element, context) self.parent_set_context(element, context)
} }
fn set_clock(&self, element: &Self::Type, clock: Option<&::Clock>) -> bool { fn set_clock(&self, element: &Self::Type, clock: Option<&crate::Clock>) -> bool {
self.parent_set_clock(element, clock) self.parent_set_clock(element, clock)
} }
fn provide_clock(&self, element: &Self::Type) -> Option<::Clock> { fn provide_clock(&self, element: &Self::Type) -> Option<crate::Clock> {
self.parent_provide_clock(element) self.parent_provide_clock(element)
} }
fn post_message(&self, element: &Self::Type, msg: ::Message) -> bool { fn post_message(&self, element: &Self::Type, msg: crate::Message) -> bool {
self.parent_post_message(element, msg) self.parent_post_message(element, msg)
} }
} }
@ -85,24 +78,24 @@ pub trait ElementImplExt: ObjectSubclass {
fn parent_request_new_pad( fn parent_request_new_pad(
&self, &self,
element: &Self::Type, element: &Self::Type,
templ: &::PadTemplate, templ: &crate::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&::Caps>, caps: Option<&crate::Caps>,
) -> Option<::Pad>; ) -> Option<crate::Pad>;
fn parent_release_pad(&self, element: &Self::Type, pad: &::Pad); fn parent_release_pad(&self, element: &Self::Type, pad: &crate::Pad);
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool; fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool;
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool; fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool;
fn parent_set_context(&self, element: &Self::Type, context: &::Context); fn parent_set_context(&self, element: &Self::Type, context: &crate::Context);
fn parent_set_clock(&self, element: &Self::Type, clock: Option<&::Clock>) -> bool; fn parent_set_clock(&self, element: &Self::Type, clock: Option<&crate::Clock>) -> bool;
fn parent_provide_clock(&self, element: &Self::Type) -> Option<::Clock>; fn parent_provide_clock(&self, element: &Self::Type) -> Option<crate::Clock>;
fn parent_post_message(&self, element: &Self::Type, msg: ::Message) -> bool; fn parent_post_message(&self, element: &Self::Type, msg: crate::Message) -> bool;
fn catch_panic<R, F: FnOnce(&Self) -> R, G: FnOnce() -> R, P: IsA<Element>>( fn catch_panic<R, F: FnOnce(&Self) -> R, G: FnOnce() -> R, P: IsA<Element>>(
&self, &self,
@ -112,7 +105,7 @@ pub trait ElementImplExt: ObjectSubclass {
) -> R; ) -> R;
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>( fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>(
parent: Option<&::Object>, parent: Option<&crate::Object>,
fallback: G, fallback: G,
f: F, f: F,
) -> R; ) -> R;
@ -129,7 +122,7 @@ where
) -> Result<StateChangeSuccess, StateChangeError> { ) -> Result<StateChangeSuccess, StateChangeError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
let f = (*parent_class) let f = (*parent_class)
.change_state .change_state
@ -145,13 +138,13 @@ where
fn parent_request_new_pad( fn parent_request_new_pad(
&self, &self,
element: &Self::Type, element: &Self::Type,
templ: &::PadTemplate, templ: &crate::PadTemplate,
name: Option<String>, name: Option<String>,
caps: Option<&::Caps>, caps: Option<&crate::Caps>,
) -> Option<::Pad> { ) -> Option<crate::Pad> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.request_new_pad .request_new_pad
@ -167,10 +160,10 @@ where
} }
} }
fn parent_release_pad(&self, element: &Self::Type, pad: &::Pad) { fn parent_release_pad(&self, element: &Self::Type, pad: &crate::Pad) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.release_pad .release_pad
@ -187,7 +180,7 @@ where
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool { fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.send_event .send_event
@ -204,7 +197,7 @@ where
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool { fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.query .query
@ -218,10 +211,10 @@ where
} }
} }
fn parent_set_context(&self, element: &Self::Type, context: &::Context) { fn parent_set_context(&self, element: &Self::Type, context: &crate::Context) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.set_context .set_context
@ -235,10 +228,10 @@ where
} }
} }
fn parent_set_clock(&self, element: &Self::Type, clock: Option<&::Clock>) -> bool { fn parent_set_clock(&self, element: &Self::Type, clock: Option<&crate::Clock>) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.set_clock .set_clock
@ -252,10 +245,10 @@ where
} }
} }
fn parent_provide_clock(&self, element: &Self::Type) -> Option<::Clock> { fn parent_provide_clock(&self, element: &Self::Type) -> Option<crate::Clock> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
(*parent_class) (*parent_class)
.provide_clock .provide_clock
@ -264,10 +257,10 @@ where
} }
} }
fn parent_post_message(&self, element: &Self::Type, msg: ::Message) -> bool { fn parent_post_message(&self, element: &Self::Type, msg: crate::Message) -> bool {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
if let Some(f) = (*parent_class).post_message { if let Some(f) = (*parent_class).post_message {
from_glib(f( from_glib(f(
@ -288,7 +281,7 @@ where
) -> R { ) -> R {
unsafe { unsafe {
assert!(element.get_type().is_a(&T::get_type())); assert!(element.get_type().is_a(&T::get_type()));
let ptr: *mut gst_sys::GstElement = element.as_ptr() as *mut _; let ptr: *mut ffi::GstElement = element.as_ptr() as *mut _;
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -297,14 +290,14 @@ where
} }
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>( fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>(
parent: Option<&::Object>, parent: Option<&crate::Object>,
fallback: G, fallback: G,
f: F, f: F,
) -> R { ) -> R {
unsafe { unsafe {
let wrap = parent.as_ref().unwrap().downcast_ref::<Element>().unwrap(); let wrap = parent.as_ref().unwrap().downcast_ref::<Element>().unwrap();
assert!(wrap.get_type().is_a(&T::get_type())); assert!(wrap.get_type().is_a(&T::get_type()));
let ptr: *mut gst_sys::GstElement = wrap.to_glib_none().0; let ptr: *mut ffi::GstElement = wrap.to_glib_none().0;
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -318,8 +311,8 @@ where
pub unsafe trait ElementClassSubclassExt: Sized + 'static { pub unsafe trait ElementClassSubclassExt: Sized + 'static {
fn add_pad_template(&mut self, pad_template: PadTemplate) { fn add_pad_template(&mut self, pad_template: PadTemplate) {
unsafe { unsafe {
gst_sys::gst_element_class_add_pad_template( ffi::gst_element_class_add_pad_template(
self as *mut Self as *mut gst_sys::GstElementClass, self as *mut Self as *mut ffi::GstElementClass,
pad_template.to_glib_none().0, pad_template.to_glib_none().0,
); );
} }
@ -333,8 +326,8 @@ pub unsafe trait ElementClassSubclassExt: Sized + 'static {
author: &str, author: &str,
) { ) {
unsafe { unsafe {
gst_sys::gst_element_class_set_metadata( ffi::gst_element_class_set_metadata(
self as *mut Self as *mut gst_sys::GstElementClass, self as *mut Self as *mut ffi::GstElementClass,
long_name.to_glib_none().0, long_name.to_glib_none().0,
classification.to_glib_none().0, classification.to_glib_none().0,
description.to_glib_none().0, description.to_glib_none().0,
@ -345,8 +338,8 @@ pub unsafe trait ElementClassSubclassExt: Sized + 'static {
fn add_metadata(&mut self, key: &str, value: &str) { fn add_metadata(&mut self, key: &str, value: &str) {
unsafe { unsafe {
gst_sys::gst_element_class_add_metadata( ffi::gst_element_class_add_metadata(
self as *mut Self as *mut gst_sys::GstElementClass, self as *mut Self as *mut ffi::GstElementClass,
key.to_glib_none().0, key.to_glib_none().0,
value.to_glib_none().0, value.to_glib_none().0,
); );
@ -376,9 +369,9 @@ where
} }
unsafe extern "C" fn element_change_state<T: ElementImpl>( unsafe extern "C" fn element_change_state<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
transition: gst_sys::GstStateChange, transition: ffi::GstStateChange,
) -> gst_sys::GstStateChangeReturn ) -> ffi::GstStateChangeReturn
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -403,11 +396,11 @@ where
} }
unsafe extern "C" fn element_request_new_pad<T: ElementImpl>( unsafe extern "C" fn element_request_new_pad<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
templ: *mut gst_sys::GstPadTemplate, templ: *mut ffi::GstPadTemplate,
name: *const libc::c_char, name: *const libc::c_char,
caps: *const gst_sys::GstCaps, caps: *const ffi::GstCaps,
) -> *mut gst_sys::GstPad ) -> *mut ffi::GstPad
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -415,7 +408,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Element> = from_glib_borrow(ptr); let wrap: Borrowed<Element> = from_glib_borrow(ptr);
let caps = Option::<::Caps>::from_glib_borrow(caps); let caps = Option::<crate::Caps>::from_glib_borrow(caps);
// XXX: This is effectively unsafe but the best we can do // XXX: This is effectively unsafe but the best we can do
// See https://bugzilla.gnome.org/show_bug.cgi?id=791193 // See https://bugzilla.gnome.org/show_bug.cgi?id=791193
@ -432,7 +425,9 @@ where
if let Some(ref pad) = pad { if let Some(ref pad) = pad {
assert_eq!( assert_eq!(
pad.get_parent().as_ref(), pad.get_parent().as_ref(),
Some(&*::Object::from_glib_borrow(ptr as *mut gst_sys::GstObject)) Some(&*crate::Object::from_glib_borrow(
ptr as *mut ffi::GstObject
))
); );
} }
@ -440,8 +435,8 @@ where
} }
unsafe extern "C" fn element_release_pad<T: ElementImpl>( unsafe extern "C" fn element_release_pad<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
pad: *mut gst_sys::GstPad, pad: *mut ffi::GstPad,
) where ) where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -451,7 +446,9 @@ unsafe extern "C" fn element_release_pad<T: ElementImpl>(
// If we get a floating reference passed simply return here. It can't be stored inside this // If we get a floating reference passed simply return here. It can't be stored inside this
// element, and if we continued to use it we would take ownership of this floating reference. // element, and if we continued to use it we would take ownership of this floating reference.
if gobject_sys::g_object_is_floating(pad as *mut gobject_sys::GObject) != glib_sys::GFALSE { if glib::gobject_ffi::g_object_is_floating(pad as *mut glib::gobject_ffi::GObject)
!= glib::ffi::GFALSE
{
return; return;
} }
@ -461,9 +458,9 @@ unsafe extern "C" fn element_release_pad<T: ElementImpl>(
} }
unsafe extern "C" fn element_send_event<T: ElementImpl>( unsafe extern "C" fn element_send_event<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
event: *mut gst_sys::GstEvent, event: *mut ffi::GstEvent,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -478,9 +475,9 @@ where
} }
unsafe extern "C" fn element_query<T: ElementImpl>( unsafe extern "C" fn element_query<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
query: *mut gst_sys::GstQuery, query: *mut ffi::GstQuery,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -496,8 +493,8 @@ where
} }
unsafe extern "C" fn element_set_context<T: ElementImpl>( unsafe extern "C" fn element_set_context<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
context: *mut gst_sys::GstContext, context: *mut ffi::GstContext,
) where ) where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -511,9 +508,9 @@ unsafe extern "C" fn element_set_context<T: ElementImpl>(
} }
unsafe extern "C" fn element_set_clock<T: ElementImpl>( unsafe extern "C" fn element_set_clock<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
clock: *mut gst_sys::GstClock, clock: *mut ffi::GstClock,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -521,7 +518,7 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Element> = from_glib_borrow(ptr); let wrap: Borrowed<Element> = from_glib_borrow(ptr);
let clock = Option::<::Clock>::from_glib_borrow(clock); let clock = Option::<crate::Clock>::from_glib_borrow(clock);
gst_panic_to_error!(&wrap, &instance.panicked(), false, { gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.set_clock(wrap.unsafe_cast_ref(), clock.as_ref().as_ref()) imp.set_clock(wrap.unsafe_cast_ref(), clock.as_ref().as_ref())
@ -530,8 +527,8 @@ where
} }
unsafe extern "C" fn element_provide_clock<T: ElementImpl>( unsafe extern "C" fn element_provide_clock<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
) -> *mut gst_sys::GstClock ) -> *mut ffi::GstClock
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -546,9 +543,9 @@ where
} }
unsafe extern "C" fn element_post_message<T: ElementImpl>( unsafe extern "C" fn element_post_message<T: ElementImpl>(
ptr: *mut gst_sys::GstElement, ptr: *mut ffi::GstElement,
msg: *mut gst_sys::GstMessage, msg: *mut ffi::GstMessage,
) -> glib_sys::gboolean ) -> glib::ffi::gboolean
where where
T::Instance: PanicPoison, T::Instance: PanicPoison,
{ {
@ -565,18 +562,17 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use glib;
use glib::subclass; use glib::subclass;
use std::sync::atomic; use std::sync::atomic;
use ElementFactory; use crate::ElementFactory;
pub mod imp { pub mod imp {
use super::*; use super::*;
pub struct TestElement { pub struct TestElement {
pub(super) srcpad: ::Pad, pub(super) srcpad: crate::Pad,
pub(super) sinkpad: ::Pad, pub(super) sinkpad: crate::Pad,
pub(super) n_buffers: atomic::AtomicU32, pub(super) n_buffers: atomic::AtomicU32,
pub(super) reached_playing: atomic::AtomicBool, pub(super) reached_playing: atomic::AtomicBool,
} }
@ -584,46 +580,46 @@ mod tests {
impl TestElement { impl TestElement {
fn sink_chain( fn sink_chain(
&self, &self,
_pad: &::Pad, _pad: &crate::Pad,
_element: &super::TestElement, _element: &super::TestElement,
buffer: ::Buffer, buffer: crate::Buffer,
) -> Result<::FlowSuccess, ::FlowError> { ) -> Result<crate::FlowSuccess, crate::FlowError> {
self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst); self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst);
self.srcpad.push(buffer) self.srcpad.push(buffer)
} }
fn sink_event( fn sink_event(
&self, &self,
_pad: &::Pad, _pad: &crate::Pad,
_element: &super::TestElement, _element: &super::TestElement,
event: ::Event, event: crate::Event,
) -> bool { ) -> bool {
self.srcpad.push_event(event) self.srcpad.push_event(event)
} }
fn sink_query( fn sink_query(
&self, &self,
_pad: &::Pad, _pad: &crate::Pad,
_element: &super::TestElement, _element: &super::TestElement,
query: &mut ::QueryRef, query: &mut crate::QueryRef,
) -> bool { ) -> bool {
self.srcpad.peer_query(query) self.srcpad.peer_query(query)
} }
fn src_event( fn src_event(
&self, &self,
_pad: &::Pad, _pad: &crate::Pad,
_element: &super::TestElement, _element: &super::TestElement,
event: ::Event, event: crate::Event,
) -> bool { ) -> bool {
self.sinkpad.push_event(event) self.sinkpad.push_event(event)
} }
fn src_query( fn src_query(
&self, &self,
_pad: &::Pad, _pad: &crate::Pad,
_element: &super::TestElement, _element: &super::TestElement,
query: &mut ::QueryRef, query: &mut crate::QueryRef,
) -> bool { ) -> bool {
self.sinkpad.peer_query(query) self.sinkpad.peer_query(query)
} }
@ -633,18 +629,18 @@ mod tests {
const NAME: &'static str = "TestElement"; const NAME: &'static str = "TestElement";
type Type = super::TestElement; type Type = super::TestElement;
type ParentType = Element; type ParentType = Element;
type Instance = ::subclass::ElementInstanceStruct<Self>; type Instance = crate::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>; type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!(); glib::glib_object_subclass!();
fn with_class(klass: &Self::Class) -> Self { fn with_class(klass: &Self::Class) -> Self {
let templ = klass.get_pad_template("sink").unwrap(); let templ = klass.get_pad_template("sink").unwrap();
let sinkpad = ::Pad::builder_with_template(&templ, Some("sink")) let sinkpad = crate::Pad::builder_with_template(&templ, Some("sink"))
.chain_function(|pad, parent, buffer| { .chain_function(|pad, parent, buffer| {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
|| Err(::FlowError::Error), || Err(crate::FlowError::Error),
|identity, element| identity.sink_chain(pad, element, buffer), |identity, element| identity.sink_chain(pad, element, buffer),
) )
}) })
@ -665,7 +661,7 @@ mod tests {
.build(); .build();
let templ = klass.get_pad_template("src").unwrap(); let templ = klass.get_pad_template("src").unwrap();
let srcpad = ::Pad::builder_with_template(&templ, Some("src")) let srcpad = crate::Pad::builder_with_template(&templ, Some("src"))
.event_function(|pad, parent, event| { .event_function(|pad, parent, event| {
TestElement::catch_panic_pad_function( TestElement::catch_panic_pad_function(
parent, parent,
@ -698,15 +694,23 @@ mod tests {
"Sebastian Dröge <sebastian@centricular.com>", "Sebastian Dröge <sebastian@centricular.com>",
); );
let caps = ::Caps::new_any(); let caps = crate::Caps::new_any();
let src_pad_template = let src_pad_template = crate::PadTemplate::new(
::PadTemplate::new("src", ::PadDirection::Src, ::PadPresence::Always, &caps) "src",
.unwrap(); crate::PadDirection::Src,
crate::PadPresence::Always,
&caps,
)
.unwrap();
klass.add_pad_template(src_pad_template); klass.add_pad_template(src_pad_template);
let sink_pad_template = let sink_pad_template = crate::PadTemplate::new(
::PadTemplate::new("sink", ::PadDirection::Sink, ::PadPresence::Always, &caps) "sink",
.unwrap(); crate::PadDirection::Sink,
crate::PadPresence::Always,
&caps,
)
.unwrap();
klass.add_pad_template(sink_pad_template); klass.add_pad_template(sink_pad_template);
} }
} }
@ -724,11 +728,11 @@ mod tests {
fn change_state( fn change_state(
&self, &self,
element: &Self::Type, element: &Self::Type,
transition: ::StateChange, transition: crate::StateChange,
) -> Result<::StateChangeSuccess, ::StateChangeError> { ) -> Result<crate::StateChangeSuccess, crate::StateChangeError> {
let res = self.parent_change_state(element, transition)?; let res = self.parent_change_state(element, transition)?;
if transition == ::StateChange::PausedToPlaying { if transition == crate::StateChange::PausedToPlaying {
self.reached_playing.store(true, atomic::Ordering::SeqCst); self.reached_playing.store(true, atomic::Ordering::SeqCst);
} }
@ -737,8 +741,8 @@ mod tests {
} }
} }
glib_wrapper! { glib::glib_wrapper! {
pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends Element, ::Object; pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends Element, crate::Object;
} }
unsafe impl Send for TestElement {} unsafe impl Send for TestElement {}
@ -755,18 +759,18 @@ mod tests {
#[test] #[test]
fn test_element_subclass() { fn test_element_subclass() {
::init().unwrap(); crate::init().unwrap();
let element = TestElement::new(Some("test")); let element = TestElement::new(Some("test"));
assert_eq!(element.get_name(), "test"); assert_eq!(element.get_name(), "test");
assert_eq!( assert_eq!(
element.get_metadata(&::ELEMENT_METADATA_LONGNAME), element.get_metadata(&crate::ELEMENT_METADATA_LONGNAME),
Some("Test Element") Some("Test Element")
); );
let pipeline = ::Pipeline::new(None); let pipeline = crate::Pipeline::new(None);
let src = ElementFactory::make("fakesrc", None).unwrap(); let src = ElementFactory::make("fakesrc", None).unwrap();
let sink = ElementFactory::make("fakesink", None).unwrap(); let sink = ElementFactory::make("fakesink", None).unwrap();
@ -777,13 +781,13 @@ mod tests {
.unwrap(); .unwrap();
Element::link_many(&[&src, &element.upcast_ref(), &sink]).unwrap(); Element::link_many(&[&src, &element.upcast_ref(), &sink]).unwrap();
pipeline.set_state(::State::Playing).unwrap(); pipeline.set_state(crate::State::Playing).unwrap();
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let eos = bus.timed_pop_filtered(::CLOCK_TIME_NONE, &[::MessageType::Eos]); let eos = bus.timed_pop_filtered(crate::CLOCK_TIME_NONE, &[crate::MessageType::Eos]);
assert!(eos.is_some()); assert!(eos.is_some());
pipeline.set_state(::State::Null).unwrap(); pipeline.set_state(crate::State::Null).unwrap();
let imp = imp::TestElement::from_instance(&element); let imp = imp::TestElement::from_instance(&element);
assert_eq!(imp.n_buffers.load(atomic::Ordering::SeqCst), 100); assert_eq!(imp.n_buffers.load(atomic::Ordering::SeqCst), 100);

View file

@ -8,8 +8,8 @@
use thiserror::Error; use thiserror::Error;
use ErrorMessage; use crate::ErrorMessage;
use FlowReturn; use crate::FlowReturn;
#[macro_export] #[macro_export]
macro_rules! gst_panic_to_error( macro_rules! gst_panic_to_error(

View file

@ -9,13 +9,13 @@
use super::prelude::*; use super::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use GhostPad; use crate::GhostPad;
pub trait GhostPadImpl: PadImpl {} pub trait GhostPadImpl: PadImpl {}
unsafe impl<T: GhostPadImpl> IsSubclassable<T> for GhostPad { unsafe impl<T: GhostPadImpl> IsSubclassable<T> for GhostPad {
fn override_vfuncs(klass: &mut glib::Class<Self>) { fn override_vfuncs(klass: &mut glib::Class<Self>) {
<::Pad as IsSubclassable<T>>::override_vfuncs(klass); <crate::Pad as IsSubclassable<T>>::override_vfuncs(klass);
let _klass = klass.as_mut(); let _klass = klass.as_mut();
// Nothing to do here // Nothing to do here
} }

View file

@ -62,7 +62,6 @@ pub mod prelude {
} }
use self::prelude::*; use self::prelude::*;
use glib;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
#[repr(C)] #[repr(C)]

View file

@ -6,14 +6,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_sys;
use glib;
use glib::prelude::*; use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use Pad; use crate::Pad;
pub trait PadImpl: PadImplExt + ObjectImpl + Send + Sync { pub trait PadImpl: PadImplExt + ObjectImpl + Send + Sync {
fn linked(&self, pad: &Self::Type, peer: &Pad) { fn linked(&self, pad: &Self::Type, peer: &Pad) {
@ -35,7 +32,7 @@ impl<T: PadImpl> PadImplExt for T {
fn parent_linked(&self, pad: &Self::Type, peer: &Pad) { fn parent_linked(&self, pad: &Self::Type, peer: &Pad) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstPadClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstPadClass;
(*parent_class) (*parent_class)
.linked .linked
@ -52,7 +49,7 @@ impl<T: PadImpl> PadImplExt for T {
fn parent_unlinked(&self, pad: &Self::Type, peer: &Pad) { fn parent_unlinked(&self, pad: &Self::Type, peer: &Pad) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstPadClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstPadClass;
(*parent_class) (*parent_class)
.unlinked .unlinked
@ -76,7 +73,7 @@ unsafe impl<T: PadImpl> IsSubclassable<T> for Pad {
} }
} }
unsafe extern "C" fn pad_linked<T: PadImpl>(ptr: *mut gst_sys::GstPad, peer: *mut gst_sys::GstPad) { unsafe extern "C" fn pad_linked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Pad> = from_glib_borrow(ptr); let wrap: Borrowed<Pad> = from_glib_borrow(ptr);
@ -84,10 +81,7 @@ unsafe extern "C" fn pad_linked<T: PadImpl>(ptr: *mut gst_sys::GstPad, peer: *mu
imp.linked(wrap.unsafe_cast_ref(), &from_glib_borrow(peer)) imp.linked(wrap.unsafe_cast_ref(), &from_glib_borrow(peer))
} }
unsafe extern "C" fn pad_unlinked<T: PadImpl>( unsafe extern "C" fn pad_unlinked<T: PadImpl>(ptr: *mut ffi::GstPad, peer: *mut ffi::GstPad) {
ptr: *mut gst_sys::GstPad,
peer: *mut gst_sys::GstPad,
) {
let instance = &*(ptr as *mut T::Instance); let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<Pad> = from_glib_borrow(ptr); let wrap: Borrowed<Pad> = from_glib_borrow(ptr);
@ -99,11 +93,10 @@ unsafe extern "C" fn pad_unlinked<T: PadImpl>(
mod tests { mod tests {
use super::*; use super::*;
use crate::prelude::*; use crate::prelude::*;
use glib;
use glib::subclass; use glib::subclass;
use std::sync::atomic; use std::sync::atomic;
use PadDirection; use crate::PadDirection;
pub mod imp { pub mod imp {
use super::*; use super::*;
@ -120,7 +113,7 @@ mod tests {
type Instance = subclass::simple::InstanceStruct<Self>; type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>; type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!(); glib::glib_object_subclass!();
fn new() -> Self { fn new() -> Self {
Self { Self {
@ -145,8 +138,8 @@ mod tests {
} }
} }
glib_wrapper! { glib::glib_wrapper! {
pub struct TestPad(ObjectSubclass<imp::TestPad>) @extends Pad, ::Object; pub struct TestPad(ObjectSubclass<imp::TestPad>) @extends Pad, crate::Object;
} }
unsafe impl Send for TestPad {} unsafe impl Send for TestPad {}
@ -166,7 +159,7 @@ mod tests {
#[test] #[test]
fn test_pad_subclass() { fn test_pad_subclass() {
::init().unwrap(); crate::init().unwrap();
let pad = TestPad::new("test", PadDirection::Src); let pad = TestPad::new("test", PadDirection::Src);

View file

@ -9,7 +9,7 @@
use super::prelude::*; use super::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use Pipeline; use crate::Pipeline;
pub trait PipelineImpl: BinImpl {} pub trait PipelineImpl: BinImpl {}
@ -18,7 +18,7 @@ where
<T as ObjectSubclass>::Instance: PanicPoison, <T as ObjectSubclass>::Instance: PanicPoison,
{ {
fn override_vfuncs(klass: &mut glib::Class<Self>) { fn override_vfuncs(klass: &mut glib::Class<Self>) {
<::Bin as IsSubclassable<T>>::override_vfuncs(klass); <crate::Bin as IsSubclassable<T>>::override_vfuncs(klass);
let _klass = klass.as_mut(); let _klass = klass.as_mut();
// Nothing to do here // Nothing to do here
} }

View file

@ -24,13 +24,13 @@ macro_rules! gst_plugin_define(
use $crate::glib::translate::{from_glib_borrow, ToGlib, from_glib}; use $crate::glib::translate::{from_glib_borrow, ToGlib, from_glib};
#[repr(transparent)] #[repr(transparent)]
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc); pub struct GstPluginDesc($crate::ffi::GstPluginDesc);
unsafe impl Send for GstPluginDesc {} unsafe impl Send for GstPluginDesc {}
unsafe impl Sync for GstPluginDesc {} unsafe impl Sync for GstPluginDesc {}
#[no_mangle] #[no_mangle]
#[allow(non_upper_case_globals)] #[allow(non_upper_case_globals)]
pub static gst_plugin_desc: GstPluginDesc = GstPluginDesc($crate::gst_sys::GstPluginDesc { pub static gst_plugin_desc: GstPluginDesc = GstPluginDesc($crate::ffi::GstPluginDesc {
major_version: $crate::subclass::MAJOR_VERSION, major_version: $crate::subclass::MAJOR_VERSION,
minor_version: $crate::subclass::MINOR_VERSION, minor_version: $crate::subclass::MINOR_VERSION,
name: concat!(stringify!($name), "\0") as *const str as *const _, name: concat!(stringify!($name), "\0") as *const str as *const _,
@ -42,13 +42,13 @@ macro_rules! gst_plugin_define(
package: concat!($package, "\0") as *const str as *const _, package: concat!($package, "\0") as *const str as *const _,
origin: concat!($origin, "\0") as *const str as *const _, origin: concat!($origin, "\0") as *const str as *const _,
release_datetime: concat!($release_datetime, "\0") as *const str as *const _, release_datetime: concat!($release_datetime, "\0") as *const str as *const _,
_gst_reserved: [0 as $crate::glib_sys::gpointer; 4], _gst_reserved: [0 as $crate::glib::ffi::gpointer; 4],
}); });
pub fn plugin_register_static() -> Result<(), $crate::glib::BoolError> { pub fn plugin_register_static() -> Result<(), $crate::glib::BoolError> {
unsafe { unsafe {
$crate::glib::glib_result_from_gboolean!( $crate::glib::glib_result_from_gboolean!(
$crate::gst_sys::gst_plugin_register_static( $crate::ffi::gst_plugin_register_static(
$crate::subclass::MAJOR_VERSION, $crate::subclass::MAJOR_VERSION,
$crate::subclass::MINOR_VERSION, $crate::subclass::MINOR_VERSION,
concat!(stringify!($name), "\0") as *const str as *const _, concat!(stringify!($name), "\0") as *const str as *const _,
@ -66,17 +66,17 @@ macro_rules! gst_plugin_define(
} }
#[allow(clippy::missing_safety_doc)] #[allow(clippy::missing_safety_doc)]
unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_sys::GstPlugin) -> $crate::glib_sys::gboolean { unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::ffi::GstPlugin) -> $crate::glib::ffi::gboolean {
use std::panic::{self, AssertUnwindSafe}; use std::panic::{self, AssertUnwindSafe};
let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)))); let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin))));
match panic_result { match panic_result {
Ok(register_result) => match register_result { Ok(register_result) => match register_result {
Ok(_) => $crate::glib_sys::GTRUE, Ok(_) => $crate::glib::ffi::GTRUE,
Err(err) => { Err(err) => {
let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap(); let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
$crate::gst_error!(cat, "Failed to register plugin: {}", err); $crate::gst_error!(cat, "Failed to register plugin: {}", err);
$crate::glib_sys::GFALSE $crate::glib::ffi::GFALSE
} }
} }
Err(err) => { Err(err) => {
@ -89,7 +89,7 @@ macro_rules! gst_plugin_define(
$crate::gst_error!(cat, "Failed to initialize plugin due to panic"); $crate::gst_error!(cat, "Failed to initialize plugin due to panic");
} }
$crate::glib_sys::GFALSE $crate::glib::ffi::GFALSE
} }
} }
} }

View file

@ -24,11 +24,11 @@ macro_rules! gst_plugin_define(
use $crate::glib::translate::{from_glib_borrow, ToGlib, from_glib}; use $crate::glib::translate::{from_glib_borrow, ToGlib, from_glib};
#[repr(transparent)] #[repr(transparent)]
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc); pub struct GstPluginDesc($crate::ffi::GstPluginDesc);
unsafe impl Send for GstPluginDesc {} unsafe impl Send for GstPluginDesc {}
unsafe impl Sync for GstPluginDesc {} unsafe impl Sync for GstPluginDesc {}
static GST_PLUGIN_DESC: GstPluginDesc = GstPluginDesc($crate::gst_sys::GstPluginDesc { static GST_PLUGIN_DESC: GstPluginDesc = GstPluginDesc($crate::ffi::GstPluginDesc {
major_version: $crate::subclass::MAJOR_VERSION, major_version: $crate::subclass::MAJOR_VERSION,
minor_version: $crate::subclass::MINOR_VERSION, minor_version: $crate::subclass::MINOR_VERSION,
name: concat!(stringify!($name), "\0") as *const str as *const _, name: concat!(stringify!($name), "\0") as *const str as *const _,
@ -40,13 +40,13 @@ macro_rules! gst_plugin_define(
package: concat!($package, "\0") as *const str as *const _, package: concat!($package, "\0") as *const str as *const _,
origin: concat!($origin, "\0") as *const str as *const _, origin: concat!($origin, "\0") as *const str as *const _,
release_datetime: concat!($release_datetime, "\0") as *const str as *const _, release_datetime: concat!($release_datetime, "\0") as *const str as *const _,
_gst_reserved: [0 as $crate::glib_sys::gpointer; 4], _gst_reserved: [0 as $crate::glib::ffi::gpointer; 4],
}); });
pub fn plugin_register_static() -> Result<(), $crate::glib::BoolError> { pub fn plugin_register_static() -> Result<(), $crate::glib::BoolError> {
unsafe { unsafe {
$crate::glib::glib_result_from_gboolean!( $crate::glib::glib_result_from_gboolean!(
$crate::gst_sys::gst_plugin_register_static( $crate::ffi::gst_plugin_register_static(
$crate::subclass::MAJOR_VERSION, $crate::subclass::MAJOR_VERSION,
$crate::subclass::MINOR_VERSION, $crate::subclass::MINOR_VERSION,
concat!(stringify!($name), "\0") as *const str as *const _, concat!(stringify!($name), "\0") as *const str as *const _,
@ -72,23 +72,23 @@ macro_rules! gst_plugin_define(
#[no_mangle] #[no_mangle]
#[allow(clippy::missing_safety_doc)] #[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn [<gst_plugin_ $name _get_desc>] () -> *const $crate::gst_sys::GstPluginDesc { pub unsafe extern "C" fn [<gst_plugin_ $name _get_desc>] () -> *const $crate::ffi::GstPluginDesc {
&GST_PLUGIN_DESC.0 &GST_PLUGIN_DESC.0
} }
} }
#[allow(clippy::missing_safety_doc)] #[allow(clippy::missing_safety_doc)]
unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::gst_sys::GstPlugin) -> $crate::glib_sys::gboolean { unsafe extern "C" fn plugin_init_trampoline(plugin: *mut $crate::ffi::GstPlugin) -> $crate::glib::ffi::gboolean {
use std::panic::{self, AssertUnwindSafe}; use std::panic::{self, AssertUnwindSafe};
let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin)))); let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin))));
match panic_result { match panic_result {
Ok(register_result) => match register_result { Ok(register_result) => match register_result {
Ok(_) => $crate::glib_sys::GTRUE, Ok(_) => $crate::glib::ffi::GTRUE,
Err(err) => { Err(err) => {
let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap(); let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
$crate::gst_error!(cat, "Failed to register plugin: {}", err); $crate::gst_error!(cat, "Failed to register plugin: {}", err);
$crate::glib_sys::GFALSE $crate::glib::ffi::GFALSE
} }
} }
Err(err) => { Err(err) => {
@ -101,7 +101,7 @@ macro_rules! gst_plugin_define(
$crate::gst_error!(cat, "Failed to initialize plugin due to panic"); $crate::gst_error!(cat, "Failed to initialize plugin due to panic");
} }
$crate::glib_sys::GFALSE $crate::glib::ffi::GFALSE
} }
} }
} }

View file

@ -6,18 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use Preset; use crate::Preset;
pub trait PresetImpl: super::element::ElementImpl {} pub trait PresetImpl: super::element::ElementImpl {}
unsafe impl<T: PresetImpl> IsImplementable<T> for Preset { unsafe impl<T: PresetImpl> IsImplementable<T> for Preset {
unsafe extern "C" fn interface_init( unsafe extern "C" fn interface_init(
_iface: glib_sys::gpointer, _iface: glib::ffi::gpointer,
_iface_data: glib_sys::gpointer, _iface_data: glib::ffi::gpointer,
) { ) {
} }
} }

View file

@ -9,13 +9,13 @@
use super::prelude::*; use super::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use SystemClock; use crate::SystemClock;
pub trait SystemClockImpl: ClockImpl {} pub trait SystemClockImpl: ClockImpl {}
unsafe impl<T: SystemClockImpl> IsSubclassable<T> for SystemClock { unsafe impl<T: SystemClockImpl> IsSubclassable<T> for SystemClock {
fn override_vfuncs(klass: &mut glib::Class<Self>) { fn override_vfuncs(klass: &mut glib::Class<Self>) {
<::Clock as IsSubclassable<T>>::override_vfuncs(klass); <crate::Clock as IsSubclassable<T>>::override_vfuncs(klass);
let _klass = klass.as_mut(); let _klass = klass.as_mut();
// Nothing to do here // Nothing to do here
} }

View file

@ -6,18 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use TagSetter; use crate::TagSetter;
pub trait TagSetterImpl: super::element::ElementImpl {} pub trait TagSetterImpl: super::element::ElementImpl {}
unsafe impl<T: TagSetterImpl> IsImplementable<T> for TagSetter { unsafe impl<T: TagSetterImpl> IsImplementable<T> for TagSetter {
unsafe extern "C" fn interface_init( unsafe extern "C" fn interface_init(
_iface: glib_sys::gpointer, _iface: glib::ffi::gpointer,
_iface_data: glib_sys::gpointer, _iface_data: glib::ffi::gpointer,
) { ) {
} }
} }

View file

@ -6,19 +6,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib_sys;
use gst_sys;
use glib;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::*; use glib::translate::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use libc; use crate::URIHandler;
use crate::URIType;
use URIHandler;
use URIType;
pub trait URIHandlerImpl: super::element::ElementImpl { pub trait URIHandlerImpl: super::element::ElementImpl {
fn get_uri(&self, element: &Self::Type) -> Option<String>; fn get_uri(&self, element: &Self::Type) -> Option<String>;
@ -29,10 +23,10 @@ pub trait URIHandlerImpl: super::element::ElementImpl {
unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler { unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
unsafe extern "C" fn interface_init( unsafe extern "C" fn interface_init(
iface: glib_sys::gpointer, iface: glib::ffi::gpointer,
_iface_data: glib_sys::gpointer, _iface_data: glib::ffi::gpointer,
) { ) {
let uri_handler_iface = &mut *(iface as *mut gst_sys::GstURIHandlerInterface); let uri_handler_iface = &mut *(iface as *mut ffi::GstURIHandlerInterface);
// Store the protocols in the interface data for later use // Store the protocols in the interface data for later use
let mut data = T::type_data(); let mut data = T::type_data();
@ -42,7 +36,7 @@ unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
if data.interface_data.is_null() { if data.interface_data.is_null() {
data.interface_data = Box::into_raw(Box::new(Vec::new())); data.interface_data = Box::into_raw(Box::new(Vec::new()));
} }
(*(data.interface_data as *mut Vec<(glib_sys::GType, glib_sys::gpointer)>)) (*(data.interface_data as *mut Vec<(glib::ffi::GType, glib::ffi::gpointer)>))
.push((URIHandler::static_type().to_glib(), protocols as *mut _)); .push((URIHandler::static_type().to_glib(), protocols as *mut _));
uri_handler_iface.get_type = Some(uri_handler_get_type::<T>); uri_handler_iface.get_type = Some(uri_handler_get_type::<T>);
@ -53,13 +47,13 @@ unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
} }
unsafe extern "C" fn uri_handler_get_type<T: URIHandlerImpl>( unsafe extern "C" fn uri_handler_get_type<T: URIHandlerImpl>(
_type_: glib_sys::GType, _type_: glib::ffi::GType,
) -> gst_sys::GstURIType { ) -> ffi::GstURIType {
<T as URIHandlerImpl>::get_uri_type().to_glib() <T as URIHandlerImpl>::get_uri_type().to_glib()
} }
unsafe extern "C" fn uri_handler_get_protocols<T: URIHandlerImpl>( unsafe extern "C" fn uri_handler_get_protocols<T: URIHandlerImpl>(
_type_: glib_sys::GType, _type_: glib::ffi::GType,
) -> *const *const libc::c_char { ) -> *const *const libc::c_char {
let data = <T as ObjectSubclass>::type_data(); let data = <T as ObjectSubclass>::type_data();
data.as_ref() data.as_ref()
@ -67,7 +61,7 @@ unsafe extern "C" fn uri_handler_get_protocols<T: URIHandlerImpl>(
} }
unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>( unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>(
uri_handler: *mut gst_sys::GstURIHandler, uri_handler: *mut ffi::GstURIHandler,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
let instance = &*(uri_handler as *mut T::Instance); let instance = &*(uri_handler as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();
@ -77,10 +71,10 @@ unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>(
} }
unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>( unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>(
uri_handler: *mut gst_sys::GstURIHandler, uri_handler: *mut ffi::GstURIHandler,
uri: *const libc::c_char, uri: *const libc::c_char,
err: *mut *mut glib_sys::GError, err: *mut *mut glib::ffi::GError,
) -> glib_sys::gboolean { ) -> glib::ffi::gboolean {
let instance = &*(uri_handler as *mut T::Instance); let instance = &*(uri_handler as *mut T::Instance);
let imp = instance.get_impl(); let imp = instance.get_impl();

View file

@ -6,13 +6,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::tags::*;
use crate::TagMergeMode;
use crate::TagSetter;
use glib::object::IsA; use glib::object::IsA;
use glib::translate::*; use glib::translate::*;
use glib::value::ToSendValue; use glib::value::ToSendValue;
use gst_sys;
use tags::*;
use TagMergeMode;
use TagSetter;
pub trait TagSetterExtManual: 'static { pub trait TagSetterExtManual: 'static {
fn add<'a, T: Tag<'a>>(&self, value: T::TagType, mode: TagMergeMode) fn add<'a, T: Tag<'a>>(&self, value: T::TagType, mode: TagMergeMode)
@ -28,7 +27,7 @@ impl<O: IsA<TagSetter>> TagSetterExtManual for O {
unsafe { unsafe {
let v = value.to_send_value(); let v = value.to_send_value();
gst_sys::gst_tag_setter_add_tag_value( ffi::gst_tag_setter_add_tag_value(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
mode.to_glib(), mode.to_glib(),
T::tag_name().to_glib_none().0, T::tag_name().to_glib_none().0,

View file

@ -13,19 +13,16 @@ use std::mem;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use glib;
use glib::translate::{ use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr, ToGlibPtrMut, from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr, ToGlibPtrMut,
}; };
use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue, Value}; use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue, Value};
use glib::StaticType; use glib::StaticType;
use gobject_sys;
use gst_sys;
use Sample; use crate::Sample;
use TagError; use crate::TagError;
use TagMergeMode; use crate::TagMergeMode;
use TagScope; use crate::TagScope;
pub trait Tag<'a> { pub trait Tag<'a> {
type TagType: FromValueOptional<'a> + SetValue + Send; type TagType: FromValueOptional<'a> + SetValue + Send;
@ -43,7 +40,7 @@ macro_rules! impl_tag(
} }
pub(crate) static $rust_tag: Lazy<&'static str> = Lazy::new(|| pub(crate) static $rust_tag: Lazy<&'static str> = Lazy::new(||
unsafe { CStr::from_ptr(gst_sys::$gst_tag).to_str().unwrap() }); unsafe { CStr::from_ptr(ffi::$gst_tag).to_str().unwrap() });
}; };
); );
@ -76,7 +73,12 @@ impl_tag!(
GST_TAG_ALBUM_ARTIST_SORTNAME GST_TAG_ALBUM_ARTIST_SORTNAME
); );
impl_tag!(Date, glib::Date, TAG_DATE, GST_TAG_DATE); impl_tag!(Date, glib::Date, TAG_DATE, GST_TAG_DATE);
impl_tag!(DateTime, ::auto::DateTime, TAG_DATE_TIME, GST_TAG_DATE_TIME); impl_tag!(
DateTime,
crate::auto::DateTime,
TAG_DATE_TIME,
GST_TAG_DATE_TIME
);
impl_tag!(Genre, &'a str, TAG_GENRE, GST_TAG_GENRE); impl_tag!(Genre, &'a str, TAG_GENRE, GST_TAG_GENRE);
impl_tag!(Comment, &'a str, TAG_COMMENT, GST_TAG_COMMENT); impl_tag!(Comment, &'a str, TAG_COMMENT, GST_TAG_COMMENT);
impl_tag!( impl_tag!(
@ -124,7 +126,7 @@ impl_tag!(Contact, &'a str, TAG_CONTACT, GST_TAG_CONTACT);
impl_tag!(License, &'a str, TAG_LICENSE, GST_TAG_LICENSE); impl_tag!(License, &'a str, TAG_LICENSE, GST_TAG_LICENSE);
impl_tag!(LicenseUri, &'a str, TAG_LICENSE_URI, GST_TAG_LICENSE_URI); impl_tag!(LicenseUri, &'a str, TAG_LICENSE_URI, GST_TAG_LICENSE_URI);
impl_tag!(Performer, &'a str, TAG_PERFORMER, GST_TAG_PERFORMER); impl_tag!(Performer, &'a str, TAG_PERFORMER, GST_TAG_PERFORMER);
impl_tag!(Duration, ::ClockTime, TAG_DURATION, GST_TAG_DURATION); impl_tag!(Duration, crate::ClockTime, TAG_DURATION, GST_TAG_DURATION);
impl_tag!(Codec, &'a str, TAG_CODEC, GST_TAG_CODEC); impl_tag!(Codec, &'a str, TAG_CODEC, GST_TAG_CODEC);
impl_tag!(VideoCodec, &'a str, TAG_VIDEO_CODEC, GST_TAG_VIDEO_CODEC); impl_tag!(VideoCodec, &'a str, TAG_VIDEO_CODEC, GST_TAG_VIDEO_CODEC);
impl_tag!(AudioCodec, &'a str, TAG_AUDIO_CODEC, GST_TAG_AUDIO_CODEC); impl_tag!(AudioCodec, &'a str, TAG_AUDIO_CODEC, GST_TAG_AUDIO_CODEC);
@ -339,14 +341,14 @@ impl_tag!(
); );
impl_tag!(PrivateData, Sample, TAG_PRIVATE_DATA, GST_TAG_PRIVATE_DATA); impl_tag!(PrivateData, Sample, TAG_PRIVATE_DATA, GST_TAG_PRIVATE_DATA);
gst_define_mini_object_wrapper!(TagList, TagListRef, gst_sys::GstTagList, || { gst_define_mini_object_wrapper!(TagList, TagListRef, ffi::GstTagList, || {
gst_sys::gst_tag_list_get_type() ffi::gst_tag_list_get_type()
}); });
impl TagList { impl TagList {
pub fn new() -> Self { pub fn new() -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_tag_list_new_empty()) } unsafe { from_glib_full(ffi::gst_tag_list_new_empty()) }
} }
} }
@ -387,12 +389,12 @@ impl TagListRef {
unsafe { unsafe {
let tag_name = tag_name.to_glib_none(); let tag_name = tag_name.to_glib_none();
let tag_type: glib::Type = from_glib(gst_sys::gst_tag_get_type(tag_name.0)); let tag_type: glib::Type = from_glib(ffi::gst_tag_get_type(tag_name.0));
if tag_type != value.type_() { if tag_type != value.type_() {
return Err(TagError::TypeMismatch); return Err(TagError::TypeMismatch);
} }
gst_sys::gst_tag_list_add_value( ffi::gst_tag_list_add_value(
self.as_mut_ptr(), self.as_mut_ptr(),
mode.to_glib(), mode.to_glib(),
tag_name.0, tag_name.0,
@ -415,7 +417,7 @@ impl TagListRef {
unsafe { unsafe {
let mut value: mem::MaybeUninit<SendValue> = mem::MaybeUninit::zeroed(); let mut value: mem::MaybeUninit<SendValue> = mem::MaybeUninit::zeroed();
let found: bool = from_glib(gst_sys::gst_tag_list_copy_value( let found: bool = from_glib(ffi::gst_tag_list_copy_value(
(*value.as_mut_ptr()).to_glib_none_mut().0, (*value.as_mut_ptr()).to_glib_none_mut().0,
self.as_ptr(), self.as_ptr(),
tag_name.to_glib_none().0, tag_name.to_glib_none().0,
@ -430,12 +432,12 @@ impl TagListRef {
} }
pub fn n_tags(&self) -> i32 { pub fn n_tags(&self) -> i32 {
unsafe { gst_sys::gst_tag_list_n_tags(self.as_ptr()) } unsafe { ffi::gst_tag_list_n_tags(self.as_ptr()) }
} }
pub fn nth_tag_name(&self, idx: u32) -> &str { pub fn nth_tag_name(&self, idx: u32) -> &str {
unsafe { unsafe {
CStr::from_ptr(gst_sys::gst_tag_list_nth_tag_name(self.as_ptr(), idx)) CStr::from_ptr(ffi::gst_tag_list_nth_tag_name(self.as_ptr(), idx))
.to_str() .to_str()
.unwrap() .unwrap()
} }
@ -448,11 +450,8 @@ impl TagListRef {
pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> { pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> {
unsafe { unsafe {
let value = gst_sys::gst_tag_list_get_value_index( let value =
self.as_ptr(), ffi::gst_tag_list_get_value_index(self.as_ptr(), tag_name.to_glib_none().0, idx);
tag_name.to_glib_none().0,
idx,
);
if value.is_null() { if value.is_null() {
return None; return None;
@ -467,7 +466,7 @@ impl TagListRef {
} }
pub fn get_size_by_name(&self, tag_name: &str) -> u32 { pub fn get_size_by_name(&self, tag_name: &str) -> u32 {
unsafe { gst_sys::gst_tag_list_get_tag_size(self.as_ptr(), tag_name.to_glib_none().0) } unsafe { ffi::gst_tag_list_get_tag_size(self.as_ptr(), tag_name.to_glib_none().0) }
} }
pub fn iter_tag<'a, T: Tag<'a>>(&'a self) -> TagIter<'a, T> { pub fn iter_tag<'a, T: Tag<'a>>(&'a self) -> TagIter<'a, T> {
@ -487,12 +486,12 @@ impl TagListRef {
} }
pub fn insert(&mut self, other: &TagListRef, mode: TagMergeMode) { pub fn insert(&mut self, other: &TagListRef, mode: TagMergeMode) {
unsafe { gst_sys::gst_tag_list_insert(self.as_mut_ptr(), other.as_ptr(), mode.to_glib()) } unsafe { ffi::gst_tag_list_insert(self.as_mut_ptr(), other.as_ptr(), mode.to_glib()) }
} }
pub fn merge(&self, other: &TagListRef, mode: TagMergeMode) -> TagList { pub fn merge(&self, other: &TagListRef, mode: TagMergeMode) -> TagList {
unsafe { unsafe {
from_glib_full(gst_sys::gst_tag_list_merge( from_glib_full(ffi::gst_tag_list_merge(
self.as_ptr(), self.as_ptr(),
other.as_ptr(), other.as_ptr(),
mode.to_glib(), mode.to_glib(),
@ -501,11 +500,11 @@ impl TagListRef {
} }
pub fn get_scope(&self) -> TagScope { pub fn get_scope(&self) -> TagScope {
unsafe { from_glib(gst_sys::gst_tag_list_get_scope(self.as_ptr())) } unsafe { from_glib(ffi::gst_tag_list_get_scope(self.as_ptr())) }
} }
pub fn set_scope(&mut self, scope: TagScope) { pub fn set_scope(&mut self, scope: TagScope) {
unsafe { gst_sys::gst_tag_list_set_scope(self.as_mut_ptr(), scope.to_glib()) } unsafe { ffi::gst_tag_list_set_scope(self.as_mut_ptr(), scope.to_glib()) }
} }
} }
@ -537,21 +536,15 @@ impl fmt::Debug for TagListRef {
impl fmt::Display for TagListRef { impl fmt::Display for TagListRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = unsafe { let s =
glib::GString::from_glib_full(gst_sys::gst_tag_list_to_string(self.as_ptr())) unsafe { glib::GString::from_glib_full(ffi::gst_tag_list_to_string(self.as_ptr())) };
};
f.write_str(&s) f.write_str(&s)
} }
} }
impl PartialEq for TagListRef { impl PartialEq for TagListRef {
fn eq(&self, other: &TagListRef) -> bool { fn eq(&self, other: &TagListRef) -> bool {
unsafe { unsafe { from_glib(ffi::gst_tag_list_is_equal(self.as_ptr(), other.as_ptr())) }
from_glib(gst_sys::gst_tag_list_is_equal(
self.as_ptr(),
other.as_ptr(),
))
}
} }
} }
@ -806,18 +799,18 @@ impl<'a> ExactSizeIterator for Iter<'a> {}
pub fn tag_exists(name: &str) -> bool { pub fn tag_exists(name: &str) -> bool {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { from_glib(gst_sys::gst_tag_exists(name.to_glib_none().0)) } unsafe { from_glib(ffi::gst_tag_exists(name.to_glib_none().0)) }
} }
pub fn tag_get_type(name: &str) -> glib::Type { pub fn tag_get_type(name: &str) -> glib::Type {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { from_glib(gst_sys::gst_tag_get_type(name.to_glib_none().0)) } unsafe { from_glib(ffi::gst_tag_get_type(name.to_glib_none().0)) }
} }
pub fn tag_get_nick<'b>(name: &str) -> Option<&'b str> { pub fn tag_get_nick<'b>(name: &str) -> Option<&'b str> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_tag_get_nick(name.to_glib_none().0); let ptr = ffi::gst_tag_get_nick(name.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
None None
@ -830,7 +823,7 @@ pub fn tag_get_nick<'b>(name: &str) -> Option<&'b str> {
pub fn tag_get_description<'b>(name: &str) -> Option<&'b str> { pub fn tag_get_description<'b>(name: &str) -> Option<&'b str> {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let ptr = gst_sys::gst_tag_get_description(name.to_glib_none().0); let ptr = ffi::gst_tag_get_description(name.to_glib_none().0);
if ptr.is_null() { if ptr.is_null() {
None None
@ -840,13 +833,13 @@ pub fn tag_get_description<'b>(name: &str) -> Option<&'b str> {
} }
} }
pub fn tag_get_flag(name: &str) -> ::TagFlag { pub fn tag_get_flag(name: &str) -> crate::TagFlag {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { from_glib(gst_sys::gst_tag_get_flag(name.to_glib_none().0)) } unsafe { from_glib(ffi::gst_tag_get_flag(name.to_glib_none().0)) }
} }
pub trait CustomTag<'a>: Tag<'a> { pub trait CustomTag<'a>: Tag<'a> {
const FLAG: ::TagFlag; const FLAG: crate::TagFlag;
const NICK: &'static str; const NICK: &'static str;
const DESCRIPTION: &'static str; const DESCRIPTION: &'static str;
@ -860,14 +853,14 @@ pub fn register<T: for<'a> CustomTag<'a>>() {
assert!(!tag_exists(T::tag_name())); assert!(!tag_exists(T::tag_name()));
unsafe extern "C" fn merge_func_trampoline<T: for<'a> CustomTag<'a>>( unsafe extern "C" fn merge_func_trampoline<T: for<'a> CustomTag<'a>>(
dest: *mut gobject_sys::GValue, dest: *mut glib::gobject_ffi::GValue,
src: *const gobject_sys::GValue, src: *const glib::gobject_ffi::GValue,
) { ) {
*dest = T::merge_func(&*(src as *const Value)).into_raw(); *dest = T::merge_func(&*(src as *const Value)).into_raw();
} }
unsafe { unsafe {
gst_sys::gst_tag_register( ffi::gst_tag_register(
T::tag_name().to_glib_none().0, T::tag_name().to_glib_none().0,
T::FLAG.to_glib(), T::FLAG.to_glib(),
T::TagType::static_type().to_glib(), T::TagType::static_type().to_glib(),
@ -880,26 +873,26 @@ pub fn register<T: for<'a> CustomTag<'a>>() {
pub fn merge_use_first(src: &Value) -> Value { pub fn merge_use_first(src: &Value) -> Value {
skip_assert_initialized!(); skip_assert_initialized!();
assert_eq!(src.type_(), ::List::static_type()); assert_eq!(src.type_(), crate::List::static_type());
unsafe { unsafe {
use glib::translate::Uninitialized; use glib::translate::Uninitialized;
let mut res = Value::uninitialized(); let mut res = Value::uninitialized();
gst_sys::gst_tag_merge_use_first(res.to_glib_none_mut().0, src.to_glib_none().0); ffi::gst_tag_merge_use_first(res.to_glib_none_mut().0, src.to_glib_none().0);
res res
} }
} }
pub fn merge_strings_with_comma(src: &Value) -> Value { pub fn merge_strings_with_comma(src: &Value) -> Value {
skip_assert_initialized!(); skip_assert_initialized!();
assert_eq!(src.type_(), ::List::static_type()); assert_eq!(src.type_(), crate::List::static_type());
unsafe { unsafe {
use glib::translate::Uninitialized; use glib::translate::Uninitialized;
let mut res = Value::uninitialized(); let mut res = Value::uninitialized();
gst_sys::gst_tag_merge_strings_with_comma(res.to_glib_none_mut().0, src.to_glib_none().0); ffi::gst_tag_merge_strings_with_comma(res.to_glib_none_mut().0, src.to_glib_none().0);
res res
} }
} }
@ -910,14 +903,14 @@ mod tests {
#[test] #[test]
fn test_add() { fn test_add() {
::init().unwrap(); crate::init().unwrap();
let mut tags = TagList::new(); let mut tags = TagList::new();
assert_eq!(tags.to_string(), "taglist;"); assert_eq!(tags.to_string(), "taglist;");
{ {
let tags = tags.get_mut().unwrap(); let tags = tags.get_mut().unwrap();
tags.add::<Title>(&"some title", TagMergeMode::Append); tags.add::<Title>(&"some title", TagMergeMode::Append);
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); tags.add::<Duration>(&(crate::SECOND * 120), TagMergeMode::Append);
} }
assert_eq!( assert_eq!(
tags.to_string(), tags.to_string(),
@ -927,31 +920,34 @@ mod tests {
#[test] #[test]
fn test_get() { fn test_get() {
::init().unwrap(); crate::init().unwrap();
let mut tags = TagList::new(); let mut tags = TagList::new();
assert_eq!(tags.to_string(), "taglist;"); assert_eq!(tags.to_string(), "taglist;");
{ {
let tags = tags.get_mut().unwrap(); let tags = tags.get_mut().unwrap();
tags.add::<Title>(&"some title", TagMergeMode::Append); tags.add::<Title>(&"some title", TagMergeMode::Append);
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); tags.add::<Duration>(&(crate::SECOND * 120), TagMergeMode::Append);
} }
assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title")); assert_eq!(tags.get::<Title>().unwrap().get(), Some("some title"));
assert_eq!(tags.get::<Duration>().unwrap().get_some(), (::SECOND * 120)); assert_eq!(
tags.get::<Duration>().unwrap().get_some(),
(crate::SECOND * 120)
);
assert_eq!( assert_eq!(
tags.get_index::<Title>(0).unwrap().get(), tags.get_index::<Title>(0).unwrap().get(),
Some("some title") Some("some title")
); );
assert_eq!( assert_eq!(
tags.get_index::<Duration>(0).unwrap().get_some(), tags.get_index::<Duration>(0).unwrap().get_some(),
(::SECOND * 120) (crate::SECOND * 120)
); );
} }
#[test] #[test]
fn test_scope() { fn test_scope() {
::init().unwrap(); crate::init().unwrap();
let mut tags = TagList::new(); let mut tags = TagList::new();
assert_eq!(tags.get_scope(), TagScope::Stream); assert_eq!(tags.get_scope(), TagScope::Stream);
@ -965,7 +961,7 @@ mod tests {
#[test] #[test]
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
fn test_generic() { fn test_generic() {
::init().unwrap(); crate::init().unwrap();
let mut tags = TagList::new(); let mut tags = TagList::new();
{ {
@ -977,7 +973,7 @@ mod tests {
.add_generic(&TAG_TITLE, &"second title", TagMergeMode::Append) .add_generic(&TAG_TITLE, &"second title", TagMergeMode::Append)
.is_ok()); .is_ok());
assert!(tags assert!(tags
.add_generic(&TAG_DURATION, &(::SECOND * 120), TagMergeMode::Append) .add_generic(&TAG_DURATION, &(crate::SECOND * 120), TagMergeMode::Append)
.is_ok()); .is_ok());
assert!(tags assert!(tags
.add_generic(&TAG_TITLE, &"third title", TagMergeMode::Append) .add_generic(&TAG_TITLE, &"third title", TagMergeMode::Append)
@ -1003,7 +999,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
tags.get_index_generic(&TAG_DURATION, 0).unwrap().get(), tags.get_index_generic(&TAG_DURATION, 0).unwrap().get(),
Ok(Some(::SECOND * 120)) Ok(Some(crate::SECOND * 120))
); );
assert_eq!( assert_eq!(
tags.get_index_generic(&TAG_TITLE, 2).unwrap().get(), tags.get_index_generic(&TAG_TITLE, 2).unwrap().get(),
@ -1049,7 +1045,7 @@ mod tests {
let (tag_name, mut tag_iter) = tag_list_iter.next().unwrap(); let (tag_name, mut tag_iter) = tag_list_iter.next().unwrap();
assert_eq!(tag_name, *TAG_DURATION); assert_eq!(tag_name, *TAG_DURATION);
let first_duration = tag_iter.next().unwrap(); let first_duration = tag_iter.next().unwrap();
assert_eq!(first_duration.get_some(), Ok(::SECOND * 120)); assert_eq!(first_duration.get_some(), Ok(crate::SECOND * 120));
assert!(tag_iter.next().is_none()); assert!(tag_iter.next().is_none());
// Iter // Iter
@ -1065,13 +1061,13 @@ mod tests {
let (tag_name, tag_value) = tag_list_iter.next().unwrap(); let (tag_name, tag_value) = tag_list_iter.next().unwrap();
assert_eq!(tag_name, *TAG_DURATION); assert_eq!(tag_name, *TAG_DURATION);
assert_eq!(tag_value.get_some(), Ok(::SECOND * 120)); assert_eq!(tag_value.get_some(), Ok(crate::SECOND * 120));
assert!(tag_iter.next().is_none()); assert!(tag_iter.next().is_none());
} }
#[test] #[test]
fn test_custom_tags() { fn test_custom_tags() {
::init().unwrap(); crate::init().unwrap();
enum MyCustomTag {}; enum MyCustomTag {};
@ -1083,7 +1079,7 @@ mod tests {
} }
impl<'a> CustomTag<'a> for MyCustomTag { impl<'a> CustomTag<'a> for MyCustomTag {
const FLAG: ::TagFlag = ::TagFlag::Meta; const FLAG: crate::TagFlag = crate::TagFlag::Meta;
const NICK: &'static str = "my custom tag"; const NICK: &'static str = "my custom tag";
const DESCRIPTION: &'static str = "My own custom tag type for testing"; const DESCRIPTION: &'static str = "My own custom tag type for testing";
@ -1131,7 +1127,7 @@ mod tests {
#[test] #[test]
fn test_display() { fn test_display() {
::init().unwrap(); crate::init().unwrap();
format!("{}", TagList::new()); format!("{}", TagList::new());
} }

View file

@ -6,10 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::translate::{from_glib, ToGlibPtr}; use glib::translate::{from_glib, ToGlibPtr};
use glib::{Date, SendValue, ToValue}; use glib::{Date, SendValue, ToValue};
use gst_sys;
use serde::de; use serde::de;
use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor}; use serde::de::{Deserialize, DeserializeSeed, Deserializer, SeqAccess, Visitor};
@ -21,13 +19,13 @@ use std::cmp;
use std::fmt; use std::fmt;
use std::rc::Rc; use std::rc::Rc;
use date_time_serde; use crate::date_time_serde;
use tags::{GenericTagIter, TagList, TagListRef}; use crate::tags::{GenericTagIter, TagList, TagListRef};
use value_serde::{DATE_OTHER_TYPE_ID, DATE_TIME_OTHER_TYPE_ID, SAMPLE_OTHER_TYPE_ID}; use crate::value_serde::{DATE_OTHER_TYPE_ID, DATE_TIME_OTHER_TYPE_ID, SAMPLE_OTHER_TYPE_ID};
use DateTime; use crate::DateTime;
use Sample; use crate::Sample;
use TagMergeMode; use crate::TagMergeMode;
use TagScope; use crate::TagScope;
macro_rules! ser_some_tag ( macro_rules! ser_some_tag (
($value:ident, $seq:ident, $t:ty) => ( ($value:ident, $seq:ident, $t:ty) => (
@ -183,7 +181,7 @@ impl<'de, 'a> Visitor<'de> for TagValuesVisitor<'a> {
fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<(), A::Error> { fn visit_seq<A: SeqAccess<'de>>(self, mut seq: A) -> Result<(), A::Error> {
let tag_type: glib::Type = unsafe { let tag_type: glib::Type = unsafe {
let tag_name = self.0.to_glib_none(); let tag_name = self.0.to_glib_none();
from_glib(gst_sys::gst_tag_get_type(tag_name.0)) from_glib(ffi::gst_tag_get_type(tag_name.0))
}; };
loop { loop {
@ -304,7 +302,7 @@ impl<'de> Deserialize<'de> for TagsDe {
} }
} }
#[derive(Deserialize)] #[derive(serde::Deserialize)]
struct TagListDe { struct TagListDe {
scope: TagScope, scope: TagScope,
tags: TagsDe, tags: TagsDe,
@ -329,17 +327,15 @@ impl<'de> Deserialize<'de> for TagList {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::tags::*;
use crate::Buffer;
use tags::*; use crate::Sample;
use Buffer; use crate::TagMergeMode;
use Sample; use crate::TagScope;
use TagMergeMode;
use TagScope;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut tags = TagList::new(); let mut tags = TagList::new();
assert_eq!(tags.to_string(), "taglist;"); assert_eq!(tags.to_string(), "taglist;");
@ -347,7 +343,7 @@ mod tests {
let tags = tags.get_mut().unwrap(); let tags = tags.get_mut().unwrap();
tags.add::<Title>(&"a title", TagMergeMode::Append); // String tags.add::<Title>(&"a title", TagMergeMode::Append); // String
tags.add::<Title>(&"another title", TagMergeMode::Append); // String tags.add::<Title>(&"another title", TagMergeMode::Append); // String
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); // u64 tags.add::<Duration>(&(crate::SECOND * 120), TagMergeMode::Append); // u64
tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32 tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32
tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64 tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64
tags.add::<Date>( tags.add::<Date>(
@ -355,7 +351,7 @@ mod tests {
TagMergeMode::Append, TagMergeMode::Append,
); );
tags.add::<DateTime>( tags.add::<DateTime>(
&::DateTime::new_ymd(2018, 5, 28).unwrap(), &crate::DateTime::new_ymd(2018, 5, 28).unwrap(),
TagMergeMode::Append, TagMergeMode::Append,
); );
@ -442,9 +438,7 @@ mod tests {
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
extern crate serde_json; crate::init().unwrap();
::init().unwrap();
let tag_list_ron = r#" let tag_list_ron = r#"
( (
@ -495,7 +489,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
tags.get_index::<Duration>(0).unwrap().get_some(), tags.get_index::<Duration>(0).unwrap().get_some(),
::SECOND * 120 crate::SECOND * 120
); );
assert_eq!(tags.get_index::<Bitrate>(0).unwrap().get_some(), 96_000); assert_eq!(tags.get_index::<Bitrate>(0).unwrap().get_some(), 96_000);
assert!( assert!(
@ -507,7 +501,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
tags.get_index::<DateTime>(0).unwrap().get().unwrap(), tags.get_index::<DateTime>(0).unwrap().get().unwrap(),
::DateTime::new_ymd(2018, 5, 28).unwrap() crate::DateTime::new_ymd(2018, 5, 28).unwrap()
); );
let sample = tags.get_index::<Image>(0).unwrap().get().unwrap(); let sample = tags.get_index::<Image>(0).unwrap().get().unwrap();
let buffer = sample.get_buffer().unwrap(); let buffer = sample.get_buffer().unwrap();
@ -548,7 +542,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
tags.get_index::<DateTime>(0).unwrap().get().unwrap(), tags.get_index::<DateTime>(0).unwrap().get().unwrap(),
::DateTime::new_ymd(2018, 5, 28).unwrap() crate::DateTime::new_ymd(2018, 5, 28).unwrap()
); );
let sample = tags.get_index::<Image>(0).unwrap().get().unwrap(); let sample = tags.get_index::<Image>(0).unwrap().get().unwrap();
let buffer = sample.get_buffer().unwrap(); let buffer = sample.get_buffer().unwrap();
@ -560,7 +554,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let mut tags = TagList::new(); let mut tags = TagList::new();
assert_eq!(tags.to_string(), "taglist;"); assert_eq!(tags.to_string(), "taglist;");
@ -569,7 +563,7 @@ mod tests {
tags.set_scope(TagScope::Global); tags.set_scope(TagScope::Global);
tags.add::<Title>(&"a title", TagMergeMode::Append); // String tags.add::<Title>(&"a title", TagMergeMode::Append); // String
tags.add::<Title>(&"another title", TagMergeMode::Append); // String tags.add::<Title>(&"another title", TagMergeMode::Append); // String
tags.add::<Duration>(&(::SECOND * 120), TagMergeMode::Append); // u64 tags.add::<Duration>(&(crate::SECOND * 120), TagMergeMode::Append); // u64
tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32 tags.add::<Bitrate>(&96_000, TagMergeMode::Append); // u32
tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64 tags.add::<TrackGain>(&1f64, TagMergeMode::Append); // f64
tags.add::<Date>( tags.add::<Date>(
@ -577,7 +571,7 @@ mod tests {
TagMergeMode::Append, TagMergeMode::Append,
); );
tags.add::<DateTime>( tags.add::<DateTime>(
&::DateTime::new_ymd(2018, 5, 28).unwrap(), &crate::DateTime::new_ymd(2018, 5, 28).unwrap(),
TagMergeMode::Append, TagMergeMode::Append,
); );
@ -625,7 +619,7 @@ mod tests {
); );
assert_eq!( assert_eq!(
tags.get_index::<DateTime>(0).unwrap().get().unwrap(), tags.get_index::<DateTime>(0).unwrap().get().unwrap(),
::DateTime::new_ymd(2018, 5, 28).unwrap() crate::DateTime::new_ymd(2018, 5, 28).unwrap()
); );
let sample = tags.get_index::<Image>(0).unwrap().get().unwrap(); let sample = tags.get_index::<Image>(0).unwrap().get().unwrap();
let buffer = sample.get_buffer().unwrap(); let buffer = sample.get_buffer().unwrap();

View file

@ -10,73 +10,63 @@ use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use gst_sys;
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 TagList; use crate::TagList;
use TagMergeMode; use crate::TagMergeMode;
use TocEntryType; use crate::TocEntryType;
use TocLoopType; use crate::TocLoopType;
use TocScope; use crate::TocScope;
gst_define_mini_object_wrapper!(Toc, TocRef, gst_sys::GstToc, || { gst_define_mini_object_wrapper!(Toc, TocRef, ffi::GstToc, || { ffi::gst_toc_get_type() });
gst_sys::gst_toc_get_type()
});
impl Toc { impl Toc {
pub fn new(scope: TocScope) -> Self { pub fn new(scope: TocScope) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { from_glib_full(gst_sys::gst_toc_new(scope.to_glib())) } unsafe { from_glib_full(ffi::gst_toc_new(scope.to_glib())) }
} }
} }
impl TocRef { impl TocRef {
pub fn get_scope(&self) -> TocScope { pub fn get_scope(&self) -> TocScope {
unsafe { from_glib(gst_sys::gst_toc_get_scope(self.as_ptr())) } unsafe { from_glib(ffi::gst_toc_get_scope(self.as_ptr())) }
} }
pub fn find_entry(&self, uid: &str) -> Option<TocEntry> { pub fn find_entry(&self, uid: &str) -> Option<TocEntry> {
unsafe { unsafe { from_glib_none(ffi::gst_toc_find_entry(self.as_ptr(), uid.to_glib_none().0)) }
from_glib_none(gst_sys::gst_toc_find_entry(
self.as_ptr(),
uid.to_glib_none().0,
))
}
} }
pub fn get_entries(&self) -> Vec<TocEntry> { pub fn get_entries(&self) -> Vec<TocEntry> {
unsafe { FromGlibPtrContainer::from_glib_none(gst_sys::gst_toc_get_entries(self.as_ptr())) } unsafe { FromGlibPtrContainer::from_glib_none(ffi::gst_toc_get_entries(self.as_ptr())) }
} }
pub fn append_entry(&mut self, entry: TocEntry) { pub fn append_entry(&mut self, entry: TocEntry) {
unsafe { unsafe {
gst_sys::gst_toc_append_entry(self.as_mut_ptr(), entry.into_ptr()); ffi::gst_toc_append_entry(self.as_mut_ptr(), entry.into_ptr());
} }
} }
pub fn get_tags(&self) -> Option<TagList> { pub fn get_tags(&self) -> Option<TagList> {
unsafe { from_glib_none(gst_sys::gst_toc_get_tags(self.as_ptr())) } unsafe { from_glib_none(ffi::gst_toc_get_tags(self.as_ptr())) }
} }
pub fn set_tags(&mut self, tag_list: TagList) { pub fn set_tags(&mut self, tag_list: TagList) {
unsafe { unsafe {
gst_sys::gst_toc_set_tags(self.as_mut_ptr(), tag_list.into_ptr()); ffi::gst_toc_set_tags(self.as_mut_ptr(), tag_list.into_ptr());
} }
} }
pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) { pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) {
unsafe { unsafe {
gst_sys::gst_toc_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib()); ffi::gst_toc_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib());
} }
} }
pub fn dump(&self) { pub fn dump(&self) {
unsafe { unsafe {
gst_sys::gst_toc_dump(self.as_mut_ptr()); ffi::gst_toc_dump(self.as_mut_ptr());
} }
} }
} }
@ -97,15 +87,15 @@ impl fmt::Debug for TocRef {
} }
} }
gst_define_mini_object_wrapper!(TocEntry, TocEntryRef, gst_sys::GstTocEntry, || { gst_define_mini_object_wrapper!(TocEntry, TocEntryRef, ffi::GstTocEntry, || {
gst_sys::gst_toc_entry_get_type() ffi::gst_toc_entry_get_type()
}); });
impl TocEntry { impl TocEntry {
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 {
from_glib_full(gst_sys::gst_toc_entry_new( from_glib_full(ffi::gst_toc_entry_new(
type_.to_glib(), type_.to_glib(),
uid.to_glib_none().0, uid.to_glib_none().0,
)) ))
@ -115,12 +105,12 @@ impl TocEntry {
impl TocEntryRef { impl TocEntryRef {
pub fn get_entry_type(&self) -> TocEntryType { pub fn get_entry_type(&self) -> TocEntryType {
unsafe { from_glib(gst_sys::gst_toc_entry_get_entry_type(self.as_ptr())) } unsafe { from_glib(ffi::gst_toc_entry_get_entry_type(self.as_ptr())) }
} }
pub fn get_uid(&self) -> &str { pub fn get_uid(&self) -> &str {
unsafe { unsafe {
CStr::from_ptr(gst_sys::gst_toc_entry_get_uid(self.as_ptr())) CStr::from_ptr(ffi::gst_toc_entry_get_uid(self.as_ptr()))
.to_str() .to_str()
.unwrap() .unwrap()
} }
@ -128,20 +118,18 @@ impl TocEntryRef {
pub fn append_sub_entry(&mut self, subentry: TocEntry) { pub fn append_sub_entry(&mut self, subentry: TocEntry) {
unsafe { unsafe {
gst_sys::gst_toc_entry_append_sub_entry(self.as_mut_ptr(), subentry.into_ptr()); ffi::gst_toc_entry_append_sub_entry(self.as_mut_ptr(), subentry.into_ptr());
} }
} }
pub fn get_sub_entries(&self) -> Vec<TocEntry> { pub fn get_sub_entries(&self) -> Vec<TocEntry> {
unsafe { unsafe {
FromGlibPtrContainer::from_glib_none(gst_sys::gst_toc_entry_get_sub_entries( FromGlibPtrContainer::from_glib_none(ffi::gst_toc_entry_get_sub_entries(self.as_ptr()))
self.as_ptr(),
))
} }
} }
pub fn get_parent(&self) -> Option<TocEntry> { pub fn get_parent(&self) -> Option<TocEntry> {
unsafe { from_glib_none(gst_sys::gst_toc_entry_get_parent(self.as_mut_ptr())) } unsafe { from_glib_none(ffi::gst_toc_entry_get_parent(self.as_mut_ptr())) }
} }
pub fn get_start_stop_times(&self) -> Option<(i64, i64)> { pub fn get_start_stop_times(&self) -> Option<(i64, i64)> {
@ -149,7 +137,7 @@ impl TocEntryRef {
let mut start = mem::MaybeUninit::uninit(); let mut start = mem::MaybeUninit::uninit();
let mut stop = mem::MaybeUninit::uninit(); let mut stop = mem::MaybeUninit::uninit();
if from_glib(gst_sys::gst_toc_entry_get_start_stop_times( if from_glib(ffi::gst_toc_entry_get_start_stop_times(
self.as_ptr(), self.as_ptr(),
start.as_mut_ptr(), start.as_mut_ptr(),
stop.as_mut_ptr(), stop.as_mut_ptr(),
@ -163,43 +151,39 @@ impl TocEntryRef {
pub fn set_start_stop_times(&mut self, start: i64, stop: i64) { pub fn set_start_stop_times(&mut self, start: i64, stop: i64) {
unsafe { unsafe {
gst_sys::gst_toc_entry_set_start_stop_times(self.as_mut_ptr(), start, stop); ffi::gst_toc_entry_set_start_stop_times(self.as_mut_ptr(), start, stop);
} }
} }
pub fn get_tags(&self) -> Option<TagList> { pub fn get_tags(&self) -> Option<TagList> {
unsafe { from_glib_none(gst_sys::gst_toc_entry_get_tags(self.as_ptr())) } unsafe { from_glib_none(ffi::gst_toc_entry_get_tags(self.as_ptr())) }
} }
pub fn set_tags(&mut self, tag_list: TagList) { pub fn set_tags(&mut self, tag_list: TagList) {
unsafe { unsafe {
gst_sys::gst_toc_entry_set_tags(self.as_mut_ptr(), tag_list.into_ptr()); ffi::gst_toc_entry_set_tags(self.as_mut_ptr(), tag_list.into_ptr());
} }
} }
pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) { pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) {
unsafe { unsafe {
gst_sys::gst_toc_entry_merge_tags( ffi::gst_toc_entry_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib());
self.as_mut_ptr(),
tag_list.as_mut_ptr(),
mode.to_glib(),
);
} }
} }
pub fn is_alternative(&self) -> bool { pub fn is_alternative(&self) -> bool {
unsafe { from_glib(gst_sys::gst_toc_entry_is_alternative(self.as_ptr())) } unsafe { from_glib(ffi::gst_toc_entry_is_alternative(self.as_ptr())) }
} }
pub fn is_sequence(&self) -> bool { pub fn is_sequence(&self) -> bool {
unsafe { from_glib(gst_sys::gst_toc_entry_is_sequence(self.as_ptr())) } unsafe { from_glib(ffi::gst_toc_entry_is_sequence(self.as_ptr())) }
} }
pub fn get_loop(&self) -> Option<(TocLoopType, i32)> { pub fn get_loop(&self) -> Option<(TocLoopType, i32)> {
unsafe { unsafe {
let mut loop_type = mem::MaybeUninit::uninit(); let mut loop_type = mem::MaybeUninit::uninit();
let mut repeat_count = mem::MaybeUninit::uninit(); let mut repeat_count = mem::MaybeUninit::uninit();
if from_glib(gst_sys::gst_toc_entry_get_loop( if from_glib(ffi::gst_toc_entry_get_loop(
self.as_ptr(), self.as_ptr(),
loop_type.as_mut_ptr(), loop_type.as_mut_ptr(),
repeat_count.as_mut_ptr(), repeat_count.as_mut_ptr(),
@ -216,7 +200,7 @@ impl TocEntryRef {
pub fn set_loop(&mut self, loop_type: TocLoopType, repeat_count: i32) { pub fn set_loop(&mut self, loop_type: TocLoopType, repeat_count: i32) {
unsafe { unsafe {
gst_sys::gst_toc_entry_set_loop(self.as_mut_ptr(), loop_type.to_glib(), repeat_count); ffi::gst_toc_entry_set_loop(self.as_mut_ptr(), loop_type.to_glib(), repeat_count);
} }
} }
} }
@ -248,7 +232,7 @@ mod tests {
#[test] #[test]
fn test_simple() { fn test_simple() {
::init().unwrap(); crate::init().unwrap();
// Top level toc entry // Top level toc entry
let mut toc_entry = TocEntry::new(TocEntryType::Chapter, "chapter"); let mut toc_entry = TocEntry::new(TocEntryType::Chapter, "chapter");

View file

@ -9,11 +9,11 @@
use serde::de::{Deserialize, Deserializer}; use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use toc::*; use crate::toc::*;
use TagList; use crate::TagList;
use TocEntryType; use crate::TocEntryType;
use TocLoopType; use crate::TocLoopType;
use TocScope; use crate::TocScope;
impl Serialize for TocRef { impl Serialize for TocRef {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
@ -50,7 +50,7 @@ impl Serialize for TocEntry {
} }
} }
#[derive(Deserialize)] #[derive(serde::Deserialize)]
struct TocDe { struct TocDe {
scope: TocScope, scope: TocScope,
tags: Option<TagList>, tags: Option<TagList>,
@ -82,7 +82,7 @@ impl<'de> Deserialize<'de> for Toc {
} }
} }
#[derive(Deserialize)] #[derive(serde::Deserialize)]
struct TocEntryDe { struct TocEntryDe {
entry_type: TocEntryType, entry_type: TocEntryType,
uid: String, uid: String,
@ -127,18 +127,16 @@ impl<'de> Deserialize<'de> for TocEntry {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::tags::Title;
use crate::toc::*;
use tags::Title; use crate::TagList;
use toc::*; use crate::TagMergeMode;
use TagList; use crate::TocEntryType;
use TagMergeMode; use crate::TocScope;
use TocEntryType;
use TocScope;
#[test] #[test]
fn test_serialize() { fn test_serialize() {
::init().unwrap(); crate::init().unwrap();
let mut toc = Toc::new(TocScope::Global); let mut toc = Toc::new(TocScope::Global);
{ {
@ -290,9 +288,9 @@ mod tests {
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
#[test] #[test]
fn test_deserialize() { fn test_deserialize() {
use tags::Title; use crate::tags::Title;
::init().unwrap(); crate::init().unwrap();
let toc_ron = r#" let toc_ron = r#"
( (
@ -425,7 +423,7 @@ mod tests {
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
#[test] #[test]
fn test_serde_roundtrip() { fn test_serde_roundtrip() {
::init().unwrap(); crate::init().unwrap();
let mut toc = Toc::new(TocScope::Global); let mut toc = Toc::new(TocScope::Global);
{ {

View file

@ -6,22 +6,19 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use gst_sys; use crate::Caps;
use Caps; use crate::Plugin;
use Plugin; use crate::Rank;
use Rank; use crate::TypeFindFactory;
use TypeFindFactory; use crate::TypeFindProbability;
use TypeFindProbability;
use glib;
use glib::translate::*; use glib::translate::*;
use glib_sys;
use std::ptr; use std::ptr;
use std::slice; use std::slice;
#[repr(transparent)] #[repr(transparent)]
#[derive(Debug)] #[derive(Debug)]
pub struct TypeFind(gst_sys::GstTypeFind); pub struct TypeFind(ffi::GstTypeFind);
pub trait TypeFindImpl { pub trait TypeFindImpl {
fn peek(&mut self, offset: i64, size: u32) -> Option<&[u8]>; fn peek(&mut self, offset: i64, size: u32) -> Option<&[u8]>;
@ -48,7 +45,7 @@ impl TypeFind {
let func: Box<F> = Box::new(func); let func: Box<F> = Box::new(func);
let func = Box::into_raw(func); let func = Box::into_raw(func);
let res = gst_sys::gst_type_find_register( let res = ffi::gst_type_find_register(
plugin.to_glib_none().0, plugin.to_glib_none().0,
name.to_glib_none().0, name.to_glib_none().0,
rank.to_glib() as u32, rank.to_glib() as u32,
@ -59,13 +56,13 @@ impl TypeFind {
Some(type_find_closure_drop::<F>), Some(type_find_closure_drop::<F>),
); );
glib_result_from_gboolean!(res, "Failed to register typefind factory") glib::glib_result_from_gboolean!(res, "Failed to register typefind factory")
} }
} }
pub fn peek(&mut self, offset: i64, size: u32) -> Option<&[u8]> { pub fn peek(&mut self, offset: i64, size: u32) -> Option<&[u8]> {
unsafe { unsafe {
let data = gst_sys::gst_type_find_peek(&mut self.0, offset, size); let data = ffi::gst_type_find_peek(&mut self.0, offset, size);
if data.is_null() { if data.is_null() {
None None
} else { } else {
@ -76,7 +73,7 @@ impl TypeFind {
pub fn suggest(&mut self, probability: TypeFindProbability, caps: &Caps) { pub fn suggest(&mut self, probability: TypeFindProbability, caps: &Caps) {
unsafe { unsafe {
gst_sys::gst_type_find_suggest( ffi::gst_type_find_suggest(
&mut self.0, &mut self.0,
probability.to_glib() as u32, probability.to_glib() as u32,
caps.to_glib_none().0, caps.to_glib_none().0,
@ -86,7 +83,7 @@ impl TypeFind {
pub fn get_length(&mut self) -> Option<u64> { pub fn get_length(&mut self) -> Option<u64> {
unsafe { unsafe {
let len = gst_sys::gst_type_find_get_length(&mut self.0); let len = ffi::gst_type_find_get_length(&mut self.0);
if len == 0 { if len == 0 {
None None
} else { } else {
@ -99,8 +96,8 @@ impl TypeFind {
impl TypeFindFactory { impl TypeFindFactory {
pub fn call_function(&self, find: &mut dyn TypeFindImpl) { pub fn call_function(&self, find: &mut dyn TypeFindImpl) {
unsafe { unsafe {
let find_ptr = &find as *const &mut dyn TypeFindImpl as glib_sys::gpointer; let find_ptr = &find as *const &mut dyn TypeFindImpl as glib::ffi::gpointer;
let mut find = gst_sys::GstTypeFind { let mut find = ffi::GstTypeFind {
peek: Some(type_find_peek), peek: Some(type_find_peek),
suggest: Some(type_find_suggest), suggest: Some(type_find_suggest),
data: find_ptr, data: find_ptr,
@ -108,26 +105,30 @@ impl TypeFindFactory {
_gst_reserved: [ptr::null_mut(); 4], _gst_reserved: [ptr::null_mut(); 4],
}; };
gst_sys::gst_type_find_factory_call_function(self.to_glib_none().0, &mut find) ffi::gst_type_find_factory_call_function(self.to_glib_none().0, &mut find)
} }
} }
} }
unsafe extern "C" fn type_find_trampoline<F: Fn(&mut TypeFind) + Send + Sync + 'static>( unsafe extern "C" fn type_find_trampoline<F: Fn(&mut TypeFind) + Send + Sync + 'static>(
find: *mut gst_sys::GstTypeFind, find: *mut ffi::GstTypeFind,
user_data: glib_sys::gpointer, user_data: glib::ffi::gpointer,
) { ) {
let func: &F = &*(user_data as *const F); let func: &F = &*(user_data as *const F);
func(&mut *(find as *mut TypeFind)); func(&mut *(find as *mut TypeFind));
} }
unsafe extern "C" fn type_find_closure_drop<F: Fn(&mut TypeFind) + Send + Sync + 'static>( unsafe extern "C" fn type_find_closure_drop<F: Fn(&mut TypeFind) + Send + Sync + 'static>(
data: glib_sys::gpointer, data: glib::ffi::gpointer,
) { ) {
Box::<F>::from_raw(data as *mut _); Box::<F>::from_raw(data as *mut _);
} }
unsafe extern "C" fn type_find_peek(data: glib_sys::gpointer, offset: i64, size: u32) -> *const u8 { unsafe extern "C" fn type_find_peek(
data: glib::ffi::gpointer,
offset: i64,
size: u32,
) -> *const u8 {
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl); let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
match find.peek(offset, size) { match find.peek(offset, size) {
None => ptr::null(), None => ptr::null(),
@ -136,15 +137,15 @@ unsafe extern "C" fn type_find_peek(data: glib_sys::gpointer, offset: i64, size:
} }
unsafe extern "C" fn type_find_suggest( unsafe extern "C" fn type_find_suggest(
data: glib_sys::gpointer, data: glib::ffi::gpointer,
probability: u32, probability: u32,
caps: *mut gst_sys::GstCaps, caps: *mut ffi::GstCaps,
) { ) {
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl); let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
find.suggest(from_glib(probability as i32), &from_glib_borrow(caps)); find.suggest(from_glib(probability as i32), &from_glib_borrow(caps));
} }
unsafe extern "C" fn type_find_get_length(data: glib_sys::gpointer) -> u64 { unsafe extern "C" fn type_find_get_length(data: glib::ffi::gpointer) -> u64 {
use std::u64; use std::u64;
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl); let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
@ -242,7 +243,7 @@ mod tests {
#[test] #[test]
fn test_typefind_call_function() { fn test_typefind_call_function() {
::init().unwrap(); crate::init().unwrap();
let xml_factory = TypeFindFactory::get_list() let xml_factory = TypeFindFactory::get_list()
.iter() .iter()
@ -272,12 +273,12 @@ mod tests {
#[test] #[test]
fn test_typefind_register() { fn test_typefind_register() {
::init().unwrap(); crate::init().unwrap();
TypeFind::register( TypeFind::register(
None, None,
"test_typefind", "test_typefind",
::Rank::Primary, crate::Rank::Primary,
None, None,
Some(&Caps::new_simple("test/test", &[])), Some(&Caps::new_simple("test/test", &[])),
|typefind| { |typefind| {

View file

@ -7,17 +7,16 @@
// except according to those terms. // except according to those terms.
use glib::translate::mut_override; use glib::translate::mut_override;
use glib_sys;
#[must_use = "if unused the Mutex will immediately unlock"] #[must_use = "if unused the Mutex will immediately unlock"]
pub struct MutexGuard<'a>(&'a glib_sys::GMutex); pub struct MutexGuard<'a>(&'a glib::ffi::GMutex);
impl<'a> MutexGuard<'a> { impl<'a> MutexGuard<'a> {
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
pub fn lock(mutex: &'a glib_sys::GMutex) -> Self { pub fn lock(mutex: &'a glib::ffi::GMutex) -> Self {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
glib_sys::g_mutex_lock(mut_override(mutex)); glib::ffi::g_mutex_lock(mut_override(mutex));
} }
MutexGuard(mutex) MutexGuard(mutex)
} }
@ -26,7 +25,7 @@ impl<'a> MutexGuard<'a> {
impl<'a> Drop for MutexGuard<'a> { impl<'a> Drop for MutexGuard<'a> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
glib_sys::g_mutex_unlock(mut_override(self.0)); glib::ffi::g_mutex_unlock(mut_override(self.0));
} }
} }
} }

View file

@ -13,13 +13,9 @@ use std::fmt;
use std::ops; use std::ops;
use std::slice; use std::slice;
use glib;
use glib::translate::{from_glib, FromGlibPtrFull, ToGlibPtr, ToGlibPtrMut, Uninitialized}; use glib::translate::{from_glib, FromGlibPtrFull, ToGlibPtr, ToGlibPtrMut, Uninitialized};
use glib::value::{FromValue, FromValueOptional, SetValue, ToSendValue, Value}; use glib::value::{FromValue, FromValueOptional, SetValue, ToSendValue, Value};
use glib_sys;
use gst_sys;
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Fraction(pub Rational32); pub struct Fraction(pub Rational32);
@ -248,14 +244,14 @@ impl From<Fraction> for Rational32 {
impl glib::types::StaticType for Fraction { impl glib::types::StaticType for Fraction {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_fraction_get_type()) } unsafe { from_glib(ffi::gst_fraction_get_type()) }
} }
} }
impl<'a> FromValue<'a> for Fraction { impl<'a> FromValue<'a> for Fraction {
unsafe fn from_value(v: &'a Value) -> Fraction { unsafe fn from_value(v: &'a Value) -> Fraction {
let n = gst_sys::gst_value_get_fraction_numerator(v.to_glib_none().0); let n = ffi::gst_value_get_fraction_numerator(v.to_glib_none().0);
let d = gst_sys::gst_value_get_fraction_denominator(v.to_glib_none().0); let d = ffi::gst_value_get_fraction_denominator(v.to_glib_none().0);
Fraction::new(n, d) Fraction::new(n, d)
} }
@ -269,12 +265,12 @@ impl<'a> FromValueOptional<'a> for Fraction {
impl SetValue for Fraction { impl SetValue for Fraction {
unsafe fn set_value(v: &mut Value, f: &Self) { unsafe fn set_value(v: &mut Value, f: &Self) {
gst_sys::gst_value_set_fraction(v.to_glib_none_mut().0, *f.numer(), *f.denom()); ffi::gst_value_set_fraction(v.to_glib_none_mut().0, *f.numer(), *f.denom());
} }
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "ser_de", derive(Serialize, Deserialize))] #[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub struct IntRange<T> { pub struct IntRange<T> {
min: T, min: T,
max: T, max: T,
@ -357,15 +353,15 @@ impl From<(i64, i64, i64)> for IntRange<i64> {
impl glib::types::StaticType for IntRange<i32> { impl glib::types::StaticType for IntRange<i32> {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_int_range_get_type()) } unsafe { from_glib(ffi::gst_int_range_get_type()) }
} }
} }
impl<'a> FromValue<'a> for IntRange<i32> { impl<'a> FromValue<'a> for IntRange<i32> {
unsafe fn from_value(v: &'a Value) -> Self { unsafe fn from_value(v: &'a Value) -> Self {
let min = gst_sys::gst_value_get_int_range_min(v.to_glib_none().0); let min = ffi::gst_value_get_int_range_min(v.to_glib_none().0);
let max = gst_sys::gst_value_get_int_range_max(v.to_glib_none().0); let max = ffi::gst_value_get_int_range_max(v.to_glib_none().0);
let step = gst_sys::gst_value_get_int_range_step(v.to_glib_none().0); let step = ffi::gst_value_get_int_range_step(v.to_glib_none().0);
Self::with_step(min, max, step) Self::with_step(min, max, step)
} }
@ -379,21 +375,21 @@ impl<'a> FromValueOptional<'a> for IntRange<i32> {
impl SetValue for IntRange<i32> { impl SetValue for IntRange<i32> {
unsafe fn set_value(v: &mut Value, r: &Self) { unsafe fn set_value(v: &mut Value, r: &Self) {
gst_sys::gst_value_set_int_range_step(v.to_glib_none_mut().0, r.min(), r.max(), r.step()); ffi::gst_value_set_int_range_step(v.to_glib_none_mut().0, r.min(), r.max(), r.step());
} }
} }
impl glib::types::StaticType for IntRange<i64> { impl glib::types::StaticType for IntRange<i64> {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_int64_range_get_type()) } unsafe { from_glib(ffi::gst_int64_range_get_type()) }
} }
} }
impl<'a> FromValue<'a> for IntRange<i64> { impl<'a> FromValue<'a> for IntRange<i64> {
unsafe fn from_value(v: &'a Value) -> Self { unsafe fn from_value(v: &'a Value) -> Self {
let min = gst_sys::gst_value_get_int64_range_min(v.to_glib_none().0); let min = ffi::gst_value_get_int64_range_min(v.to_glib_none().0);
let max = gst_sys::gst_value_get_int64_range_max(v.to_glib_none().0); let max = ffi::gst_value_get_int64_range_max(v.to_glib_none().0);
let step = gst_sys::gst_value_get_int64_range_step(v.to_glib_none().0); let step = ffi::gst_value_get_int64_range_step(v.to_glib_none().0);
Self::with_step(min, max, step) Self::with_step(min, max, step)
} }
@ -407,12 +403,12 @@ impl<'a> FromValueOptional<'a> for IntRange<i64> {
impl SetValue for IntRange<i64> { impl SetValue for IntRange<i64> {
unsafe fn set_value(v: &mut Value, r: &Self) { unsafe fn set_value(v: &mut Value, r: &Self) {
gst_sys::gst_value_set_int64_range_step(v.to_glib_none_mut().0, r.min(), r.max(), r.step()); ffi::gst_value_set_int64_range_step(v.to_glib_none_mut().0, r.min(), r.max(), r.step());
} }
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "ser_de", derive(Serialize, Deserialize))] #[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub struct FractionRange { pub struct FractionRange {
min: Fraction, min: Fraction,
max: Fraction, max: Fraction,
@ -449,19 +445,19 @@ impl From<(Fraction, Fraction)> for FractionRange {
impl glib::types::StaticType for FractionRange { impl glib::types::StaticType for FractionRange {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_fraction_range_get_type()) } unsafe { from_glib(ffi::gst_fraction_range_get_type()) }
} }
} }
impl<'a> FromValue<'a> for FractionRange { impl<'a> FromValue<'a> for FractionRange {
unsafe fn from_value(v: &'a Value) -> Self { unsafe fn from_value(v: &'a Value) -> Self {
let min = gst_sys::gst_value_get_fraction_range_min(v.to_glib_none().0); let min = ffi::gst_value_get_fraction_range_min(v.to_glib_none().0);
let max = gst_sys::gst_value_get_fraction_range_max(v.to_glib_none().0); let max = ffi::gst_value_get_fraction_range_max(v.to_glib_none().0);
let min_n = gst_sys::gst_value_get_fraction_numerator(min); let min_n = ffi::gst_value_get_fraction_numerator(min);
let min_d = gst_sys::gst_value_get_fraction_denominator(min); let min_d = ffi::gst_value_get_fraction_denominator(min);
let max_n = gst_sys::gst_value_get_fraction_numerator(max); let max_n = ffi::gst_value_get_fraction_numerator(max);
let max_d = gst_sys::gst_value_get_fraction_denominator(max); let max_d = ffi::gst_value_get_fraction_denominator(max);
Self::new((min_n, min_d), (max_n, max_d)) Self::new((min_n, min_d), (max_n, max_d))
} }
@ -475,7 +471,7 @@ impl<'a> FromValueOptional<'a> for FractionRange {
impl SetValue for FractionRange { impl SetValue for FractionRange {
unsafe fn set_value(v: &mut Value, r: &Self) { unsafe fn set_value(v: &mut Value, r: &Self) {
gst_sys::gst_value_set_fraction_range_full( ffi::gst_value_set_fraction_range_full(
v.to_glib_none_mut().0, v.to_glib_none_mut().0,
*r.min().numer(), *r.min().numer(),
*r.min().denom(), *r.min().denom(),
@ -486,7 +482,7 @@ impl SetValue for FractionRange {
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "ser_de", derive(Serialize, Deserialize))] #[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub struct Bitmask(pub u64); pub struct Bitmask(pub u64);
impl Bitmask { impl Bitmask {
@ -551,13 +547,13 @@ impl From<u64> for Bitmask {
impl glib::types::StaticType for Bitmask { impl glib::types::StaticType for Bitmask {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_bitmask_get_type()) } unsafe { from_glib(ffi::gst_bitmask_get_type()) }
} }
} }
impl<'a> FromValue<'a> for Bitmask { impl<'a> FromValue<'a> for Bitmask {
unsafe fn from_value(v: &'a Value) -> Self { unsafe fn from_value(v: &'a Value) -> Self {
let v = gst_sys::gst_value_get_bitmask(v.to_glib_none().0); let v = ffi::gst_value_get_bitmask(v.to_glib_none().0);
Self::new(v) Self::new(v)
} }
} }
@ -570,7 +566,7 @@ impl<'a> FromValueOptional<'a> for Bitmask {
impl SetValue for Bitmask { impl SetValue for Bitmask {
unsafe fn set_value(v: &mut Value, r: &Self) { unsafe fn set_value(v: &mut Value, r: &Self) {
gst_sys::gst_value_set_bitmask(v.to_glib_none_mut().0, r.0); ffi::gst_value_set_bitmask(v.to_glib_none_mut().0, r.0);
} }
} }
@ -625,7 +621,7 @@ impl<'a> From<&'a [glib::SendValue]> for Array<'a> {
impl<'a> FromValue<'a> for Array<'a> { impl<'a> FromValue<'a> for Array<'a> {
unsafe fn from_value(v: &'a Value) -> Self { unsafe fn from_value(v: &'a Value) -> Self {
let arr = (*v.to_glib_none().0).data[0].v_pointer as *const glib_sys::GArray; let arr = (*v.to_glib_none().0).data[0].v_pointer as *const glib::ffi::GArray;
if arr.is_null() { if arr.is_null() {
Array(Cow::Borrowed(&[])) Array(Cow::Borrowed(&[]))
} else { } else {
@ -647,14 +643,14 @@ impl<'a> FromValueOptional<'a> for Array<'a> {
impl<'a> SetValue for Array<'a> { impl<'a> SetValue for Array<'a> {
unsafe fn set_value(v: &mut Value, a: &Self) { unsafe fn set_value(v: &mut Value, a: &Self) {
for value in a.as_slice() { for value in a.as_slice() {
gst_sys::gst_value_array_append_value(v.to_glib_none_mut().0, value.to_glib_none().0); ffi::gst_value_array_append_value(v.to_glib_none_mut().0, value.to_glib_none().0);
} }
} }
} }
impl<'a> glib::types::StaticType for Array<'a> { impl<'a> glib::types::StaticType for Array<'a> {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_value_array_get_type()) } unsafe { from_glib(ffi::gst_value_array_get_type()) }
} }
} }
@ -709,7 +705,7 @@ impl<'a> From<&'a [glib::SendValue]> for List<'a> {
impl<'a> FromValue<'a> for List<'a> { impl<'a> FromValue<'a> for List<'a> {
unsafe fn from_value(v: &'a Value) -> Self { unsafe fn from_value(v: &'a Value) -> Self {
let arr = (*v.to_glib_none().0).data[0].v_pointer as *const glib_sys::GArray; let arr = (*v.to_glib_none().0).data[0].v_pointer as *const glib::ffi::GArray;
if arr.is_null() { if arr.is_null() {
List(Cow::Borrowed(&[])) List(Cow::Borrowed(&[]))
} else { } else {
@ -731,14 +727,14 @@ impl<'a> FromValueOptional<'a> for List<'a> {
impl<'a> SetValue for List<'a> { impl<'a> SetValue for List<'a> {
unsafe fn set_value(v: &mut Value, a: &Self) { unsafe fn set_value(v: &mut Value, a: &Self) {
for value in a.as_slice() { for value in a.as_slice() {
gst_sys::gst_value_list_append_value(v.to_glib_none_mut().0, value.to_glib_none().0); ffi::gst_value_list_append_value(v.to_glib_none_mut().0, value.to_glib_none().0);
} }
} }
} }
impl<'a> glib::types::StaticType for List<'a> { impl<'a> glib::types::StaticType for List<'a> {
fn static_type() -> glib::types::Type { fn static_type() -> glib::types::Type {
unsafe { from_glib(gst_sys::gst_value_list_get_type()) } unsafe { from_glib(ffi::gst_value_list_get_type()) }
} }
} }
@ -762,7 +758,7 @@ pub trait GstValueExt: Sized {
impl GstValueExt for glib::Value { impl GstValueExt for glib::Value {
fn can_compare(&self, other: &Self) -> bool { fn can_compare(&self, other: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_value_can_compare( from_glib(ffi::gst_value_can_compare(
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
)) ))
@ -771,12 +767,12 @@ impl GstValueExt for glib::Value {
fn compare(&self, other: &Self) -> Option<cmp::Ordering> { fn compare(&self, other: &Self) -> Option<cmp::Ordering> {
unsafe { unsafe {
let val = gst_sys::gst_value_compare(self.to_glib_none().0, other.to_glib_none().0); let val = ffi::gst_value_compare(self.to_glib_none().0, other.to_glib_none().0);
match val { match val {
gst_sys::GST_VALUE_LESS_THAN => Some(cmp::Ordering::Less), ffi::GST_VALUE_LESS_THAN => Some(cmp::Ordering::Less),
gst_sys::GST_VALUE_EQUAL => Some(cmp::Ordering::Equal), ffi::GST_VALUE_EQUAL => Some(cmp::Ordering::Equal),
gst_sys::GST_VALUE_GREATER_THAN => Some(cmp::Ordering::Greater), ffi::GST_VALUE_GREATER_THAN => Some(cmp::Ordering::Greater),
_ => None, _ => None,
} }
} }
@ -788,7 +784,7 @@ impl GstValueExt for glib::Value {
fn can_intersect(&self, other: &Self) -> bool { fn can_intersect(&self, other: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_value_can_intersect( from_glib(ffi::gst_value_can_intersect(
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
)) ))
@ -798,7 +794,7 @@ impl GstValueExt for glib::Value {
fn intersect(&self, other: &Self) -> Option<Self> { fn intersect(&self, other: &Self) -> Option<Self> {
unsafe { unsafe {
let mut value = glib::Value::uninitialized(); let mut value = glib::Value::uninitialized();
let ret: bool = from_glib(gst_sys::gst_value_intersect( let ret: bool = from_glib(ffi::gst_value_intersect(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
@ -813,7 +809,7 @@ impl GstValueExt for glib::Value {
fn can_subtract(&self, other: &Self) -> bool { fn can_subtract(&self, other: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_value_can_subtract( from_glib(ffi::gst_value_can_subtract(
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
)) ))
@ -823,7 +819,7 @@ impl GstValueExt for glib::Value {
fn subtract(&self, other: &Self) -> Option<Self> { fn subtract(&self, other: &Self) -> Option<Self> {
unsafe { unsafe {
let mut value = glib::Value::uninitialized(); let mut value = glib::Value::uninitialized();
let ret: bool = from_glib(gst_sys::gst_value_subtract( let ret: bool = from_glib(ffi::gst_value_subtract(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
@ -838,7 +834,7 @@ impl GstValueExt for glib::Value {
fn can_union(&self, other: &Self) -> bool { fn can_union(&self, other: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_value_can_union( from_glib(ffi::gst_value_can_union(
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
)) ))
@ -848,7 +844,7 @@ impl GstValueExt for glib::Value {
fn union(&self, other: &Self) -> Option<Self> { fn union(&self, other: &Self) -> Option<Self> {
unsafe { unsafe {
let mut value = glib::Value::uninitialized(); let mut value = glib::Value::uninitialized();
let ret: bool = from_glib(gst_sys::gst_value_union( let ret: bool = from_glib(ffi::gst_value_union(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
self.to_glib_none().0, self.to_glib_none().0,
other.to_glib_none().0, other.to_glib_none().0,
@ -864,7 +860,7 @@ impl GstValueExt for glib::Value {
fn fixate(&self) -> Option<Self> { fn fixate(&self) -> Option<Self> {
unsafe { unsafe {
let mut value = glib::Value::uninitialized(); let mut value = glib::Value::uninitialized();
let ret: bool = from_glib(gst_sys::gst_value_fixate( let ret: bool = from_glib(ffi::gst_value_fixate(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
self.to_glib_none().0, self.to_glib_none().0,
)); ));
@ -877,12 +873,12 @@ impl GstValueExt for glib::Value {
} }
fn is_fixed(&self) -> bool { fn is_fixed(&self) -> bool {
unsafe { from_glib(gst_sys::gst_value_is_fixed(self.to_glib_none().0)) } unsafe { from_glib(ffi::gst_value_is_fixed(self.to_glib_none().0)) }
} }
fn is_subset(&self, superset: &Self) -> bool { fn is_subset(&self, superset: &Self) -> bool {
unsafe { unsafe {
from_glib(gst_sys::gst_value_is_subset( from_glib(ffi::gst_value_is_subset(
self.to_glib_none().0, self.to_glib_none().0,
superset.to_glib_none().0, superset.to_glib_none().0,
)) ))
@ -891,8 +887,8 @@ impl GstValueExt for glib::Value {
fn serialize(&self) -> Result<glib::GString, glib::BoolError> { fn serialize(&self) -> Result<glib::GString, glib::BoolError> {
unsafe { unsafe {
Option::<_>::from_glib_full(gst_sys::gst_value_serialize(self.to_glib_none().0)) Option::<_>::from_glib_full(ffi::gst_value_serialize(self.to_glib_none().0))
.ok_or_else(|| glib_bool_error!("Failed to serialize value")) .ok_or_else(|| glib::glib_bool_error!("Failed to serialize value"))
} }
} }
@ -903,14 +899,14 @@ impl GstValueExt for glib::Value {
unsafe { unsafe {
let mut value = glib::Value::uninitialized(); let mut value = glib::Value::uninitialized();
let ret: bool = from_glib(gst_sys::gst_value_deserialize( let ret: bool = from_glib(ffi::gst_value_deserialize(
value.to_glib_none_mut().0, value.to_glib_none_mut().0,
s.to_glib_none().0, s.to_glib_none().0,
)); ));
if ret { if ret {
Ok(value) Ok(value)
} else { } else {
Err(glib_bool_error!("Failed to deserialize value")) Err(glib::glib_bool_error!("Failed to deserialize value"))
} }
} }
} }
@ -920,15 +916,15 @@ impl GstValueExt for glib::Value {
mod tests { mod tests {
#[test] #[test]
fn test_fraction() { fn test_fraction() {
::init().unwrap(); crate::init().unwrap();
let f1 = ::Fraction::new(1, 2); let f1 = crate::Fraction::new(1, 2);
let f2 = ::Fraction::new(2, 3); let f2 = crate::Fraction::new(2, 3);
let mut f3 = f1 * f2; let mut f3 = f1 * f2;
let f4 = f1 * f2; let f4 = f1 * f2;
f3 *= f2; f3 *= f2;
f3 *= f4; f3 *= f4;
assert_eq!(f3, ::Fraction::new(2, 27)); assert_eq!(f3, crate::Fraction::new(2, 27));
} }
} }

View file

@ -6,7 +6,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib;
use glib::{Date, StaticType, ToValue}; use glib::{Date, StaticType, ToValue};
use num_rational::Rational32; use num_rational::Rational32;
@ -20,12 +19,12 @@ use std::{fmt, mem};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use Buffer; use crate::Buffer;
use DateTime; use crate::DateTime;
use Sample; use crate::Sample;
use date_time_serde; use crate::date_time_serde;
use value::*; use crate::value::*;
fn get_other_type_id<T: StaticType>() -> usize { fn get_other_type_id<T: StaticType>() -> usize {
match T::static_type() { match T::static_type() {
@ -306,22 +305,19 @@ impl_de_send_value_collection!(List);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
extern crate ron; use crate::Array;
extern crate serde_json; use crate::Bitmask;
use crate::DateTime;
use Array; use crate::Fraction;
use Bitmask; use crate::FractionRange;
use DateTime; use crate::IntRange;
use Fraction; use crate::List;
use FractionRange;
use IntRange;
use List;
use glib::{Date, DateMonth}; use glib::{Date, DateMonth};
#[test] #[test]
fn test_serialize_simple() { fn test_serialize_simple() {
::init().unwrap(); crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default(); let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string(); pretty_config.new_line = "".to_string();
@ -364,10 +360,7 @@ mod tests {
#[test] #[test]
fn test_serialize_collections() { fn test_serialize_collections() {
use Fraction; crate::init().unwrap();
use List;
::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default(); let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string(); pretty_config.new_line = "".to_string();
@ -445,7 +438,7 @@ mod tests {
#[test] #[test]
fn test_deserialize_simple() { fn test_deserialize_simple() {
::init().unwrap(); crate::init().unwrap();
// Fraction // Fraction
let fraction_ron = "(1, 3)"; let fraction_ron = "(1, 3)";
@ -496,7 +489,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip_simple() { fn test_serde_roundtrip_simple() {
::init().unwrap(); crate::init().unwrap();
// Fraction // Fraction
let fraction = Fraction::new(1, 3); let fraction = Fraction::new(1, 3);
@ -537,7 +530,7 @@ mod tests {
#[allow(clippy::cognitive_complexity)] #[allow(clippy::cognitive_complexity)]
#[test] #[test]
fn test_deserialize_collections() { fn test_deserialize_collections() {
::init().unwrap(); crate::init().unwrap();
// Array // Array
let array_ron = r#"[ let array_ron = r#"[
@ -634,7 +627,7 @@ mod tests {
#[test] #[test]
fn test_serde_roundtrip_collection() { fn test_serde_roundtrip_collection() {
::init().unwrap(); crate::init().unwrap();
// Array // Array
let value_13 = Fraction::new(1, 3); let value_13 = Fraction::new(1, 3);