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/"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs"
edition = "2018"
[dependencies]
bitflags = "1.0"
cfg-if = "1.0"
libc = "0.2"
glib-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer-sys = { path = "../gstreamer/sys", features = ["v1_8"] }
ffi = { package = "gstreamer-sys", path = "../gstreamer/sys", features = ["v1_8"] }
glib = { git = "https://github.com/gtk-rs/gtk-rs" }
num-rational = { version = "0.3", default-features = false, features = [] }
once_cell = "1.0"
@ -43,14 +42,14 @@ futures-executor = "0.3.1"
[features]
default = []
v1_10 = ["gstreamer-sys/v1_10"]
v1_12 = ["gstreamer-sys/v1_12", "v1_10"]
v1_14 = ["gstreamer-sys/v1_14", "v1_12"]
v1_16 = ["gstreamer-sys/v1_16", "v1_14"]
v1_18 = ["gstreamer-sys/v1_18", "v1_16"]
v1_10 = ["ffi/v1_10"]
v1_12 = ["ffi/v1_12", "v1_10"]
v1_14 = ["ffi/v1_14", "v1_12"]
v1_16 = ["ffi/v1_16", "v1_14"]
v1_18 = ["ffi/v1_18", "v1_16"]
embed-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"]
[package.metadata.docs.rs]

View file

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

View file

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

View file

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

View file

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

View file

@ -15,35 +15,32 @@ use std::slice;
use std::u64;
use std::usize;
use meta::*;
use BufferCursor;
use BufferFlags;
use BufferRefCursor;
use ClockTime;
use Memory;
use MemoryRef;
use crate::meta::*;
use crate::BufferCursor;
use crate::BufferFlags;
use crate::BufferRefCursor;
use crate::ClockTime;
use crate::Memory;
use crate::MemoryRef;
use glib;
use glib::translate::{from_glib, from_glib_full, FromGlib, FromGlibPtrFull, ToGlib};
use glib_sys;
use gst_sys;
pub enum Readable {}
pub enum Writable {}
gst_define_mini_object_wrapper!(Buffer, BufferRef, gst_sys::GstBuffer, || {
gst_sys::gst_buffer_get_type()
gst_define_mini_object_wrapper!(Buffer, BufferRef, ffi::GstBuffer, || {
ffi::gst_buffer_get_type()
});
pub struct BufferMap<'a, T> {
buffer: &'a BufferRef,
map_info: gst_sys::GstMapInfo,
map_info: ffi::GstMapInfo,
phantom: PhantomData<T>,
}
pub struct MappedBuffer<T> {
buffer: Option<Buffer>,
map_info: gst_sys::GstMapInfo,
map_info: ffi::GstMapInfo,
phantom: PhantomData<T>,
}
@ -51,23 +48,23 @@ impl Buffer {
pub fn new() -> Self {
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> {
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_full(gst_sys::gst_buffer_new_allocate(
Option::<_>::from_glib_full(ffi::gst_buffer_new_allocate(
ptr::null_mut(),
size,
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);
drop(slice);
}
@ -82,13 +79,13 @@ impl Buffer {
(slice.len(), slice.as_mut_ptr())
};
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,
data as glib_sys::gpointer,
data as glib::ffi::gpointer,
size,
0,
size,
user_data as glib_sys::gpointer,
user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>),
))
}
@ -104,13 +101,13 @@ impl Buffer {
(slice.len(), slice.as_ptr())
};
let user_data = Box::into_raw(b);
from_glib_full(gst_sys::gst_buffer_new_wrapped_full(
gst_sys::GST_MEMORY_FLAG_READONLY,
data as glib_sys::gpointer,
from_glib_full(ffi::gst_buffer_new_wrapped_full(
ffi::GST_MEMORY_FLAG_READONLY,
data as glib::ffi::gpointer,
size,
0,
size,
user_data as glib_sys::gpointer,
user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>),
))
}
@ -119,10 +116,10 @@ impl Buffer {
pub fn into_mapped_buffer_readable(self) -> Result<MappedBuffer<Readable>, Self> {
unsafe {
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(),
map_info.as_mut_ptr(),
gst_sys::GST_MAP_READ,
ffi::GST_MAP_READ,
));
if res {
Ok(MappedBuffer {
@ -139,10 +136,10 @@ impl Buffer {
pub fn into_mapped_buffer_writable(self) -> Result<MappedBuffer<Writable>, Self> {
unsafe {
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(),
map_info.as_mut_ptr(),
gst_sys::GST_MAP_READWRITE,
ffi::GST_MAP_READWRITE,
));
if res {
Ok(MappedBuffer {
@ -167,7 +164,7 @@ impl Buffer {
pub fn append(&mut self, other: Self) {
skip_assert_initialized!();
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);
}
}
@ -183,19 +180,16 @@ impl BufferRef {
pub fn map_readable(&self) -> Result<BufferMap<Readable>, glib::BoolError> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_buffer_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),
gst_sys::GST_MAP_READ,
);
if res == glib_sys::GTRUE {
let res =
ffi::gst_buffer_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
if res == glib::ffi::GTRUE {
Ok(BufferMap {
buffer: self,
map_info: map_info.assume_init(),
phantom: PhantomData,
})
} 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> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_buffer_map(
let res = ffi::gst_buffer_map(
self.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 {
buffer: self,
map_info: map_info.assume_init(),
phantom: PhantomData,
})
} else {
Err(glib_bool_error!("Failed to map buffer writable"))
Err(glib::glib_bool_error!("Failed to map buffer writable"))
}
}
}
pub fn copy_region(
&self,
flags: ::BufferCopyFlags,
flags: crate::BufferCopyFlags,
offset: usize,
size: Option<usize>,
) -> Result<Buffer, glib::BoolError> {
let size_real = size.unwrap_or(usize::MAX);
unsafe {
Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_region(
Option::<_>::from_glib_full(ffi::gst_buffer_copy_region(
self.as_mut_ptr(),
flags.to_glib(),
offset,
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(
&self,
dest: &mut BufferRef,
flags: ::BufferCopyFlags,
flags: crate::BufferCopyFlags,
offset: usize,
size: Option<usize>,
) -> Result<(), glib::BoolError> {
let size_real = size.unwrap_or(usize::MAX);
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_buffer_copy_into(
glib::glib_result_from_gboolean!(
ffi::gst_buffer_copy_into(
dest.as_mut_ptr(),
self.as_mut_ptr(),
flags.to_glib(),
@ -268,10 +262,10 @@ impl BufferRef {
let copied = unsafe {
let src = slice.as_ptr();
gst_sys::gst_buffer_fill(
ffi::gst_buffer_fill(
self.as_mut_ptr(),
offset,
src as glib_sys::gconstpointer,
src as glib::ffi::gconstpointer,
size,
)
};
@ -291,7 +285,7 @@ impl BufferRef {
let copied = unsafe {
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 {
@ -303,19 +297,19 @@ impl BufferRef {
pub fn copy_deep(&self) -> Result<Buffer, glib::BoolError> {
unsafe {
Option::<_>::from_glib_full(gst_sys::gst_buffer_copy_deep(self.as_ptr()))
.ok_or_else(|| glib_bool_error!("Failed to deep copy buffer"))
Option::<_>::from_glib_full(ffi::gst_buffer_copy_deep(self.as_ptr()))
.ok_or_else(|| glib::glib_bool_error!("Failed to deep copy buffer"))
}
}
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 {
unsafe {
let mut maxsize = mem::MaybeUninit::uninit();
gst_sys::gst_buffer_get_sizes_range(
ffi::gst_buffer_get_sizes_range(
self.as_mut_ptr(),
0,
-1,
@ -331,7 +325,7 @@ impl BufferRef {
assert!(self.get_maxsize() >= size);
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>> {
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() {
None
} 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 {
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() {
None
} else {
@ -428,10 +422,10 @@ impl BufferRef {
pub fn foreach_meta<F: FnMut(MetaRef<Meta>) -> bool>(&self, func: F) -> bool {
unsafe extern "C" fn trampoline<F: FnMut(MetaRef<Meta>) -> bool>(
buffer: *mut gst_sys::GstBuffer,
meta: *mut *mut gst_sys::GstMeta,
user_data: glib_sys::gpointer,
) -> glib_sys::gboolean {
buffer: *mut ffi::GstBuffer,
meta: *mut *mut ffi::GstMeta,
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F;
let res = (*func)(Meta::from_ptr(BufferRef::from_ptr(buffer), *meta));
@ -441,7 +435,7 @@ impl BufferRef {
unsafe {
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 _,
Some(trampoline::<F>),
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,
func: F,
) -> bool {
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,
meta: *mut *mut gst_sys::GstMeta,
user_data: glib_sys::gpointer,
) -> glib_sys::gboolean {
buffer: *mut ffi::GstBuffer,
meta: *mut *mut ffi::GstMeta,
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F;
let res = (*func)(Meta::from_mut_ptr(BufferRef::from_mut_ptr(buffer), *meta));
@ -475,7 +471,7 @@ impl BufferRef {
unsafe {
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 _,
Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _,
@ -484,7 +480,7 @@ impl BufferRef {
}
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)> {
@ -493,7 +489,7 @@ impl BufferRef {
let mut length = 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(),
offset,
size.unwrap_or(usize::MAX),
@ -512,7 +508,7 @@ impl BufferRef {
pub fn get_all_memory(&self) -> Option<Memory> {
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() {
None
} else {
@ -522,7 +518,7 @@ impl BufferRef {
}
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> {
@ -530,7 +526,7 @@ impl BufferRef {
None
} else {
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() {
None
} else {
@ -543,7 +539,7 @@ impl BufferRef {
pub fn get_memory_range(&self, idx: u32, length: Option<u32>) -> Option<Memory> {
assert!(idx + length.unwrap_or(0) < self.n_memory());
unsafe {
let res = gst_sys::gst_buffer_get_memory_range(
let res = ffi::gst_buffer_get_memory_range(
self.as_mut_ptr(),
idx,
match length {
@ -561,7 +557,7 @@ impl BufferRef {
pub fn insert_memory(&mut self, idx: Option<u32>, mem: Memory) {
unsafe {
gst_sys::gst_buffer_insert_memory(
ffi::gst_buffer_insert_memory(
self.as_mut_ptr(),
match idx {
Some(val) => val as i32,
@ -573,16 +569,12 @@ impl BufferRef {
}
pub fn is_all_memory_writable(&self) -> bool {
unsafe {
from_glib(gst_sys::gst_buffer_is_all_memory_writable(
self.as_mut_ptr(),
))
}
unsafe { from_glib(ffi::gst_buffer_is_all_memory_writable(self.as_mut_ptr())) }
}
pub fn is_memory_range_writable(&self, idx: u32, length: Option<u16>) -> bool {
unsafe {
from_glib(gst_sys::gst_buffer_is_memory_range_writable(
from_glib(ffi::gst_buffer_is_memory_range_writable(
self.as_mut_ptr(),
idx,
match length {
@ -594,22 +586,22 @@ impl BufferRef {
}
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 {
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> {
assert!(idx < self.n_memory());
unsafe {
let mem = gst_sys::gst_buffer_peek_memory(self.as_mut_ptr(), idx);
if gst_sys::gst_mini_object_is_writable(mem as *mut _) == glib_sys::GFALSE {
Err(glib_bool_error!("Memory not writable"))
let mem = ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx);
if ffi::gst_mini_object_is_writable(mem as *mut _) == glib::ffi::GFALSE {
Err(glib::glib_bool_error!("Memory not writable"))
} 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(),
idx,
)))
@ -618,22 +610,22 @@ impl BufferRef {
}
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) {
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) {
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>) {
assert!(idx + length.unwrap_or(0) < self.n_memory());
unsafe {
gst_sys::gst_buffer_remove_memory_range(
ffi::gst_buffer_remove_memory_range(
self.as_mut_ptr(),
idx,
match length {
@ -645,18 +637,18 @@ impl BufferRef {
}
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) {
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) {
assert!(idx + length.unwrap_or(0) < self.n_memory());
unsafe {
gst_sys::gst_buffer_replace_memory_range(
ffi::gst_buffer_replace_memory_range(
self.as_mut_ptr(),
idx,
match length {
@ -674,7 +666,7 @@ impl BufferRef {
pub fn iter_memories_mut(&mut self) -> Result<IterMut, glib::BoolError> {
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 {
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) => {
pub struct $name<'a, T: MetaAPI + 'a> {
buffer: $typ,
state: glib_sys::gpointer,
state: glib::ffi::gpointer,
meta_api: glib::Type,
items: PhantomData<$mtyp>,
}
@ -737,7 +729,7 @@ macro_rules! define_meta_iter(
fn next(&mut self) -> Option<Self::Item> {
loop {
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() {
return None;
@ -758,14 +750,14 @@ define_meta_iter!(
MetaIter,
&'a BufferRef,
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)
);
define_meta_iter!(
MetaIterMut,
&'a mut BufferRef,
MetaRefMut<'a, T, ::meta::Iterated>,
|buffer: *mut gst_sys::GstBuffer| BufferRef::from_mut_ptr(buffer),
MetaRefMut<'a, T, crate::meta::Iterated>,
|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)
);
@ -852,11 +844,11 @@ define_iter!(
&'a BufferRef,
&'a MemoryRef,
|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() {
None
} 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 MemoryRef,
|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() {
None
} 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(
"metas",
&DebugIter(RefCell::new(
self.iter_meta::<::Meta>().map(|m| m.get_api()),
self.iter_meta::<crate::Meta>().map(|m| m.get_api()),
)),
)
.finish()
@ -1012,7 +1004,7 @@ impl<'a, T> Eq for BufferMap<'a, T> {}
impl<'a, T> Drop for BufferMap<'a, T> {
fn drop(&mut self) {
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 {
let buffer = self.buffer.take().unwrap();
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
@ -1079,7 +1071,7 @@ impl<T> Drop for MappedBuffer<T> {
fn drop(&mut self) {
if let Some(ref buffer) = self.buffer {
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> Sync for MappedBuffer<T> {}
pub const BUFFER_COPY_METADATA: ::BufferCopyFlags =
::BufferCopyFlags::from_bits_truncate(gst_sys::GST_BUFFER_COPY_METADATA);
pub const BUFFER_COPY_ALL: ::BufferCopyFlags =
::BufferCopyFlags::from_bits_truncate(gst_sys::GST_BUFFER_COPY_ALL);
pub const BUFFER_COPY_METADATA: crate::BufferCopyFlags =
crate::BufferCopyFlags::from_bits_truncate(ffi::GST_BUFFER_COPY_METADATA);
pub const BUFFER_COPY_ALL: crate::BufferCopyFlags =
crate::BufferCopyFlags::from_bits_truncate(ffi::GST_BUFFER_COPY_ALL);
#[cfg(test)]
mod tests {
@ -1115,7 +1107,7 @@ mod tests {
#[test]
fn test_fields() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::new();
@ -1136,7 +1128,7 @@ mod tests {
#[test]
fn test_writability() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
@ -1184,16 +1176,16 @@ mod tests {
#[test]
#[allow(clippy::cognitive_complexity)]
fn test_memories() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::new();
{
let buffer = buffer.get_mut().unwrap();
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::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; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 10]));
}
assert!(buffer.is_all_memory_writable());
@ -1295,78 +1287,84 @@ mod tests {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
#[test]
fn test_meta_foreach() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::new();
{
let buffer = buffer.get_mut().unwrap();
::ReferenceTimestampMeta::add(
crate::ReferenceTimestampMeta::add(
buffer,
&::Caps::builder("foo/bar").build(),
::ClockTime::from(0),
::CLOCK_TIME_NONE,
&crate::Caps::builder("foo/bar").build(),
crate::ClockTime::from(0),
crate::CLOCK_TIME_NONE,
);
::ReferenceTimestampMeta::add(
crate::ReferenceTimestampMeta::add(
buffer,
&::Caps::builder("foo/bar").build(),
::SECOND,
::CLOCK_TIME_NONE,
&crate::Caps::builder("foo/bar").build(),
crate::SECOND,
crate::CLOCK_TIME_NONE,
);
}
let mut res = vec![];
buffer.foreach_meta(|meta| {
let meta = meta.downcast_ref::<::ReferenceTimestampMeta>().unwrap();
let meta = meta
.downcast_ref::<crate::ReferenceTimestampMeta>()
.unwrap();
res.push(meta.get_timestamp());
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_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
#[test]
fn test_meta_foreach_mut() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::new();
{
let buffer = buffer.get_mut().unwrap();
::ReferenceTimestampMeta::add(
crate::ReferenceTimestampMeta::add(
buffer,
&::Caps::builder("foo/bar").build(),
::ClockTime::from(0),
::CLOCK_TIME_NONE,
&crate::Caps::builder("foo/bar").build(),
crate::ClockTime::from(0),
crate::CLOCK_TIME_NONE,
);
::ReferenceTimestampMeta::add(
crate::ReferenceTimestampMeta::add(
buffer,
&::Caps::builder("foo/bar").build(),
::SECOND,
::CLOCK_TIME_NONE,
&crate::Caps::builder("foo/bar").build(),
crate::SECOND,
crate::CLOCK_TIME_NONE,
);
}
let mut res = vec![];
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());
if meta.get_timestamp() == ::SECOND {
if meta.get_timestamp() == crate::SECOND {
Ok(false)
} else {
Ok(true)
}
});
assert_eq!(&[::ClockTime::from(0), ::SECOND][..], &res[..]);
assert_eq!(&[crate::ClockTime::from(0), crate::SECOND][..], &res[..]);
let mut res = vec![];
buffer.foreach_meta(|meta| {
let meta = meta.downcast_ref::<::ReferenceTimestampMeta>().unwrap();
let meta = meta
.downcast_ref::<crate::ReferenceTimestampMeta>()
.unwrap();
res.push(meta.get_timestamp());
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::usize;
use Buffer;
use BufferRef;
use crate::Buffer;
use crate::BufferRef;
use glib;
use glib_sys;
use gst_sys;
use buffer::{Readable, Writable};
use crate::buffer::{Readable, Writable};
pub struct BufferCursor<T> {
buffer: Option<Buffer>,
@ -30,7 +26,7 @@ pub struct BufferCursor<T> {
cur_mem_idx: u32,
cur_offset: u64,
cur_mem_offset: usize,
map_info: gst_sys::GstMapInfo,
map_info: ffi::GstMapInfo,
phantom: PhantomData<T>,
}
@ -41,7 +37,7 @@ pub struct BufferRefCursor<T> {
cur_mem_idx: u32,
cur_offset: u64,
cur_mem_offset: usize,
map_info: gst_sys::GstMapInfo,
map_info: ffi::GstMapInfo,
}
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() {
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();
}
}
@ -124,14 +120,14 @@ macro_rules! define_read_write_fn_impl(
unsafe {
// Work around lifetime annotation issues with closures
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(),
$self.cur_mem_idx,
);
assert!(!memory.is_null());
if gst_sys::gst_memory_map(memory, &mut $self.map_info, $map_flags)
== glib_sys::GFALSE
if ffi::gst_memory_map(memory, &mut $self.map_info, $map_flags)
== glib::ffi::GFALSE
{
return Err(io::Error::new(
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 $self.cur_mem_offset == $self.map_info.size {
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.cur_mem_idx += 1;
@ -182,8 +178,8 @@ macro_rules! define_read_impl(
data,
&mut [u8],
$get_buffer_ref,
gst_sys::GST_MAP_READ,
|map_info: &gst_sys::GstMapInfo, off, data: &mut [u8], to_copy| unsafe {
ffi::GST_MAP_READ,
|map_info: &ffi::GstMapInfo, off, data: &mut [u8], to_copy| unsafe {
ptr::copy_nonoverlapping(
(map_info.data as *const u8).add(off),
data.as_mut_ptr(),
@ -204,8 +200,8 @@ macro_rules! define_write_impl(
data,
&[u8],
$get_buffer_ref,
gst_sys::GST_MAP_WRITE,
|map_info: &gst_sys::GstMapInfo, off, data: &[u8], to_copy| unsafe {
ffi::GST_MAP_WRITE,
|map_info: &ffi::GstMapInfo, off, data: &[u8], to_copy| unsafe {
ptr::copy_nonoverlapping(
data.as_ptr(),
(map_info.data as *mut u8).add(off),
@ -219,7 +215,7 @@ macro_rules! define_write_impl(
fn flush(&mut self) -> Result<(), io::Error> {
if !self.map_info.memory.is_null() {
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();
}
}
@ -247,7 +243,7 @@ impl<T> Drop for BufferCursor<T> {
fn drop(&mut self) {
if !self.map_info.memory.is_null() {
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> {
skip_assert_initialized!();
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;
@ -346,7 +342,7 @@ impl<T> Drop for BufferRefCursor<T> {
fn drop(&mut self) {
if !self.map_info.memory.is_null() {
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> {
skip_assert_initialized!();
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;
@ -440,16 +436,16 @@ mod tests {
fn test_buffer_cursor() {
use std::io::{self, Read, Seek, Write};
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::new();
{
let buffer = buffer.get_mut().unwrap();
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::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; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 10]));
}
assert!(buffer.is_all_memory_writable());
@ -532,16 +528,16 @@ mod tests {
fn test_buffer_cursor_ref() {
use std::io::{self, Read, Seek, Write};
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::new();
{
let buffer = buffer.get_mut().unwrap();
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(::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; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 5]));
buffer.append_memory(crate::Memory::from_mut_slice(vec![0; 10]));
}
assert!(buffer.is_all_memory_writable());

View file

@ -6,17 +6,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use AllocationParams;
use Allocator;
use BufferPool;
use Structure;
use crate::AllocationParams;
use crate::Allocator;
use crate::BufferPool;
use crate::Structure;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr, ToGlibPtrMut};
use glib::IsA;
use gst_sys;
use std::mem;
use std::ops;
use std::ptr;
@ -25,27 +22,27 @@ use std::ptr;
pub struct BufferPoolConfig(Structure);
impl ops::Deref for BufferPoolConfig {
type Target = ::StructureRef;
type Target = crate::StructureRef;
fn deref(&self) -> &::StructureRef {
fn deref(&self) -> &crate::StructureRef {
self.0.deref()
}
}
impl ops::DerefMut for BufferPoolConfig {
fn deref_mut(&mut self) -> &mut ::StructureRef {
fn deref_mut(&mut self) -> &mut crate::StructureRef {
self.0.deref_mut()
}
}
impl AsRef<::StructureRef> for BufferPoolConfig {
fn as_ref(&self) -> &::StructureRef {
impl AsRef<crate::StructureRef> for BufferPoolConfig {
fn as_ref(&self) -> &crate::StructureRef {
self.0.as_ref()
}
}
impl AsMut<::StructureRef> for BufferPoolConfig {
fn as_mut(&mut self) -> &mut ::StructureRef {
impl AsMut<crate::StructureRef> for BufferPoolConfig {
fn as_mut(&mut self) -> &mut crate::StructureRef {
self.0.as_mut()
}
}
@ -53,7 +50,7 @@ impl AsMut<::StructureRef> for BufferPoolConfig {
impl BufferPoolConfig {
pub fn add_option(&mut self, option: &str) {
unsafe {
gst_sys::gst_buffer_pool_config_add_option(
ffi::gst_buffer_pool_config_add_option(
self.0.to_glib_none_mut().0,
option.to_glib_none().0,
);
@ -62,7 +59,7 @@ impl BufferPoolConfig {
pub fn has_option(&self, option: &str) -> bool {
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,
option.to_glib_none().0,
))
@ -71,11 +68,11 @@ impl BufferPoolConfig {
pub fn get_options(&self) -> Vec<String> {
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);
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,
i as u32,
)));
@ -87,13 +84,13 @@ impl BufferPoolConfig {
pub fn set_params(
&mut self,
caps: Option<&::Caps>,
caps: Option<&crate::Caps>,
size: u32,
min_buffers: u32,
max_buffers: u32,
) {
unsafe {
gst_sys::gst_buffer_pool_config_set_params(
ffi::gst_buffer_pool_config_set_params(
self.0.to_glib_none_mut().0,
caps.to_glib_none().0,
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 {
let mut caps = ptr::null_mut();
let mut size = mem::MaybeUninit::uninit();
let mut min_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,
&mut caps,
size.as_mut_ptr(),
@ -132,14 +129,14 @@ impl BufferPoolConfig {
pub fn validate_params(
&self,
caps: Option<&::Caps>,
caps: Option<&crate::Caps>,
size: u32,
min_buffers: u32,
max_buffers: u32,
) -> Result<(), glib::BoolError> {
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_buffer_pool_config_validate_params(
glib::glib_result_from_gboolean!(
ffi::gst_buffer_pool_config_validate_params(
self.0.to_glib_none().0,
caps.to_glib_none().0,
size,
@ -155,7 +152,7 @@ impl BufferPoolConfig {
unsafe {
let mut allocator = ptr::null_mut();
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,
&mut allocator,
params.as_mut_ptr(),
@ -171,7 +168,7 @@ impl BufferPoolConfig {
pub fn set_allocator(&self, allocator: Option<&Allocator>, params: Option<&AllocationParams>) {
assert!(allocator.is_some() || params.is_some());
unsafe {
gst_sys::gst_buffer_pool_config_set_allocator(
ffi::gst_buffer_pool_config_set_allocator(
self.0.to_glib_none().0,
allocator.to_glib_none().0,
match params {
@ -185,16 +182,16 @@ impl BufferPoolConfig {
}
#[derive(Debug)]
pub struct BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams);
pub struct BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams);
unsafe impl Send for BufferPoolAcquireParams {}
unsafe impl Sync for BufferPoolAcquireParams {}
impl BufferPoolAcquireParams {
pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self {
pub fn with_flags(flags: crate::BufferPoolAcquireFlags) -> Self {
skip_assert_initialized!();
BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams {
format: gst_sys::GST_FORMAT_UNDEFINED,
BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
format: ffi::GST_FORMAT_UNDEFINED,
start: -1,
stop: -1,
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,
stop: T,
flags: ::BufferPoolAcquireFlags,
flags: crate::BufferPoolAcquireFlags,
) -> Self {
skip_assert_initialized!();
unsafe {
BufferPoolAcquireParams(gst_sys::GstBufferPoolAcquireParams {
BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
format: start.get_format().to_glib(),
start: start.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)
}
pub fn format(&self) -> ::Format {
pub fn format(&self) -> crate::Format {
from_glib(self.0.format)
}
pub fn start(&self) -> ::GenericFormattedValue {
::GenericFormattedValue::new(from_glib(self.0.format), self.0.start)
pub fn start(&self) -> crate::GenericFormattedValue {
crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.start)
}
pub fn stop(&self) -> ::GenericFormattedValue {
::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop)
pub fn stop(&self) -> crate::GenericFormattedValue {
crate::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop)
}
}
@ -247,23 +244,23 @@ impl PartialEq for BufferPoolAcquireParams {
impl Eq for BufferPoolAcquireParams {}
#[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;
fn to_glib_none(
&'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)
}
}
#[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;
fn to_glib_none_mut(
&'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)
}
}
@ -271,12 +268,12 @@ impl<'a> ToGlibPtrMut<'a, *mut gst_sys::GstBufferPoolAcquireParams> for BufferPo
impl BufferPool {
pub fn new() -> BufferPool {
assert_initialized_main_thread!();
let (major, minor, _, _) = ::version();
let (major, minor, _, _) = crate::version();
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 {
// 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(
&self,
params: Option<&BufferPoolAcquireParams>,
) -> Result<::Buffer, ::FlowError>;
fn release_buffer(&self, buffer: ::Buffer);
) -> Result<crate::Buffer, crate::FlowError>;
fn release_buffer(&self, buffer: crate::Buffer);
}
impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
fn get_config(&self) -> BufferPoolConfig {
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))
}
}
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_buffer_pool_set_config(
glib::glib_result_from_gboolean!(
ffi::gst_buffer_pool_set_config(
self.as_ref().to_glib_none().0,
config.0.into_ptr()
),
@ -323,7 +320,7 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
fn is_flushing(&self) -> bool {
unsafe {
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)
}
@ -332,12 +329,12 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
fn acquire_buffer(
&self,
params: Option<&BufferPoolAcquireParams>,
) -> Result<::Buffer, ::FlowError> {
) -> Result<crate::Buffer, crate::FlowError> {
let params_ptr = params.to_glib_none().0 as *mut _;
unsafe {
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,
&mut buffer,
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 {
gst_sys::gst_buffer_pool_release_buffer(
self.as_ref().to_glib_none().0,
buffer.into_ptr(),
);
ffi::gst_buffer_pool_release_buffer(self.as_ref().to_glib_none().0, buffer.into_ptr());
}
}
}
@ -360,20 +354,21 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
#[cfg(test)]
mod tests {
use super::*;
use prelude::*;
use crate::prelude::*;
#[test]
fn test_pool() {
::init().unwrap();
crate::init().unwrap();
let pool = ::BufferPool::new();
let pool = crate::BufferPool::new();
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_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 buf2 = pool.acquire_buffer(Some(&params)).unwrap();

View file

@ -11,10 +11,10 @@ use serde::ser;
use serde::ser::{Serialize, SerializeStruct, Serializer};
use serde_bytes::{ByteBuf, Bytes};
use Buffer;
use BufferFlags;
use BufferRef;
use ClockTime;
use crate::Buffer;
use crate::BufferFlags;
use crate::BufferRef;
use crate::ClockTime;
// TODO: try `Either<ByteBuf, Bytes>` to merge the base reprensentations for ser and de
// while avoiding unneeded copy
@ -44,7 +44,7 @@ impl<'a> Serialize for Buffer {
}
}
#[derive(Deserialize)]
#[derive(serde::Deserialize)]
struct BufferDe {
pts: ClockTime,
dts: ClockTime,
@ -81,15 +81,12 @@ impl<'de> Deserialize<'de> for Buffer {
#[cfg(test)]
mod tests {
extern crate ron;
extern crate serde_json;
use Buffer;
use BufferFlags;
use crate::Buffer;
use crate::BufferFlags;
#[test]
fn test_serialize() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = Buffer::from_slice(vec![1, 2, 3, 4]);
{
@ -143,7 +140,7 @@ mod tests {
#[test]
fn test_deserialize() {
::init().unwrap();
crate::init().unwrap();
let buffer_ron = r#"
(
@ -196,7 +193,7 @@ mod tests {
#[test]
fn test_serde_roundtrip() {
::init().unwrap();
crate::init().unwrap();
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
// except according to those terms.
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib};
use gst_sys;
use std::fmt;
use std::ptr;
use Buffer;
use BufferRef;
use crate::Buffer;
use crate::BufferRef;
gst_define_mini_object_wrapper!(BufferList, BufferListRef, gst_sys::GstBufferList, || {
gst_sys::gst_buffer_list_get_type()
gst_define_mini_object_wrapper!(BufferList, BufferListRef, ffi::GstBufferList, || {
ffi::gst_buffer_list_get_type()
});
impl BufferList {
pub fn new() -> Self {
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 {
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 {
pub fn insert(&mut self, idx: i32, buffer: Buffer) {
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 {
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) {
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> {
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() {
None
} else {
@ -63,7 +61,7 @@ impl BufferListRef {
pub fn get_owned(&self, idx: u32) -> Option<Buffer> {
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)
}
}
@ -72,7 +70,7 @@ impl BufferListRef {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
pub fn get_writable(&mut self, idx: u32) -> Option<&mut BufferRef> {
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() {
None
} else {
@ -82,13 +80,13 @@ impl BufferListRef {
}
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_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
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 {
@ -105,10 +103,10 @@ impl BufferListRef {
pub fn foreach<F: FnMut(&BufferRef, u32) -> bool>(&self, func: F) -> bool {
unsafe extern "C" fn trampoline<F: FnMut(&BufferRef, u32) -> bool>(
buffer: *mut *mut gst_sys::GstBuffer,
buffer: *mut *mut ffi::GstBuffer,
idx: u32,
user_data: glib_sys::gpointer,
) -> glib_sys::gboolean {
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F;
let res = (*func)(BufferRef::from_ptr(*buffer), idx);
@ -118,7 +116,7 @@ impl BufferListRef {
unsafe {
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 _,
Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _,
@ -133,10 +131,10 @@ impl BufferListRef {
unsafe extern "C" fn trampoline<
F: FnMut(Buffer, u32) -> Result<Option<Buffer>, Option<Buffer>>,
>(
buffer: *mut *mut gst_sys::GstBuffer,
buffer: *mut *mut ffi::GstBuffer,
idx: u32,
user_data: glib_sys::gpointer,
) -> glib_sys::gboolean {
user_data: glib::ffi::gpointer,
) -> glib::ffi::gboolean {
let func = user_data as *const _ as usize as *mut F;
let res = (*func)(Buffer::from_glib_full(*buffer), idx);
@ -147,11 +145,11 @@ impl BufferListRef {
}
Ok(Some(b)) => {
*buffer = b.into_ptr();
glib_sys::GTRUE
glib::ffi::GTRUE
}
Err(Some(b)) => {
*buffer = b.into_ptr();
glib_sys::GFALSE
glib::ffi::GFALSE
}
}
}
@ -159,7 +157,7 @@ impl BufferListRef {
unsafe {
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 _,
Some(trampoline::<F>),
func_ptr as *const _ as usize as *mut _,
@ -186,7 +184,7 @@ impl fmt::Debug for BufferListRef {
let (pts, dts) = self
.get(0)
.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")
.field("ptr", unsafe { &self.as_ptr() })
@ -272,17 +270,17 @@ mod tests {
#[test]
fn test_foreach() {
::init().unwrap();
crate::init().unwrap();
let mut buffer_list = BufferList::new();
{
let buffer_list = buffer_list.get_mut().unwrap();
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);
let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(::SECOND);
buffer.get_mut().unwrap().set_pts(crate::SECOND);
buffer_list.add(buffer);
}
@ -293,26 +291,26 @@ mod tests {
true
});
assert_eq!(res, &[(::ClockTime::from(0), 0), (::SECOND, 1)]);
assert_eq!(res, &[(crate::ClockTime::from(0), 0), (crate::SECOND, 1)]);
}
#[test]
fn test_foreach_mut() {
::init().unwrap();
crate::init().unwrap();
let mut buffer_list = BufferList::new();
{
let buffer_list = buffer_list.get_mut().unwrap();
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);
let mut buffer = Buffer::new();
buffer.get_mut().unwrap().set_pts(::SECOND);
buffer.get_mut().unwrap().set_pts(crate::SECOND);
buffer_list.add(buffer);
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);
}
@ -320,20 +318,24 @@ mod tests {
buffer_list.get_mut().unwrap().foreach_mut(|buffer, 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))
} else if buffer.get_pts() == ::SECOND {
} else if buffer.get_pts() == crate::SECOND {
Ok(None)
} else {
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))
}
});
assert_eq!(
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![];
@ -343,6 +345,9 @@ mod tests {
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 Buffer;
use BufferList;
use BufferListRef;
use crate::Buffer;
use crate::BufferList;
use crate::BufferListRef;
impl Serialize for BufferListRef {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
@ -67,15 +67,13 @@ impl<'de> Deserialize<'de> for BufferList {
#[cfg(test)]
mod tests {
extern crate ron;
use BufferList;
use crate::BufferList;
#[test]
fn test_serialize() {
use Buffer;
use crate::Buffer;
::init().unwrap();
crate::init().unwrap();
let mut buffer_list = BufferList::new();
{
@ -140,7 +138,7 @@ mod tests {
#[test]
fn test_deserialize() {
::init().unwrap();
crate::init().unwrap();
let buffer_list_ron = r#"
[
@ -189,9 +187,9 @@ mod tests {
#[test]
fn test_serde_roundtrip() {
use Buffer;
use crate::Buffer;
::init().unwrap();
crate::init().unwrap();
let mut buffer_list = BufferList::new();
{

View file

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

View file

@ -7,9 +7,8 @@
// except according to those terms.
#[macro_use]
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(unix)] {
use gst_sys;
use glib::translate::ToGlibPtr;
use std::mem;
@ -35,7 +34,7 @@ impl UnixBusExtManual for Bus {
#[cfg(unix)]
unsafe {
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();
pollfd.fd
}

View file

@ -7,9 +7,8 @@
// except according to those terms.
#[macro_use]
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(windows)] {
use gst_sys;
use glib::translate::ToGlibPtr;
use std::mem;
@ -35,7 +34,7 @@ impl WindowsBusExtManual for Bus {
#[cfg(windows)]
unsafe {
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();
pollfd.fd as *mut _
}

View file

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

View file

@ -16,14 +16,11 @@ use std::str;
use once_cell::sync::Lazy;
use glib;
use glib::ffi::gpointer;
use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, Stash, StashMut,
ToGlibPtr, ToGlibPtrMut,
};
use glib_sys::gpointer;
use gobject_sys;
use gst_sys;
pub struct CapsFeatures(ptr::NonNull<CapsFeaturesRef>);
unsafe impl Send for CapsFeatures {}
@ -45,7 +42,7 @@ impl CapsFeatures {
assert_initialized_main_thread!();
unsafe {
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!();
unsafe {
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);
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 {
fn clone(&self) -> Self {
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());
CapsFeatures(ptr::NonNull::new_unchecked(ptr))
}
@ -103,7 +100,7 @@ impl Clone for CapsFeatures {
impl Drop for CapsFeatures {
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> {
assert_initialized_main_thread!();
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() {
return Err(glib_bool_error!(
return Err(glib::glib_bool_error!(
"Failed to parse caps features from string"
));
}
@ -157,69 +154,69 @@ impl BorrowMut<CapsFeaturesRef> for CapsFeatures {
impl glib::types::StaticType for CapsFeatures {
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;
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) }
}
fn to_glib_full(&self) -> *const gst_sys::GstCapsFeatures {
unsafe { gst_sys::gst_caps_features_copy(&self.0.as_ref().0) }
fn to_glib_full(&self) -> *const ffi::GstCapsFeatures {
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;
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) }
}
fn to_glib_full(&self) -> *mut gst_sys::GstCapsFeatures {
unsafe { gst_sys::gst_caps_features_copy(&self.0.as_ref().0) }
fn to_glib_full(&self) -> *mut ffi::GstCapsFeatures {
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;
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) }
}
}
impl FromGlibPtrNone<*const gst_sys::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_none(ptr: *const gst_sys::GstCapsFeatures) -> Self {
impl FromGlibPtrNone<*const ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_none(ptr: *const ffi::GstCapsFeatures) -> Self {
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());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
}
}
impl FromGlibPtrNone<*mut gst_sys::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_none(ptr: *mut gst_sys::GstCapsFeatures) -> Self {
impl FromGlibPtrNone<*mut ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_none(ptr: *mut ffi::GstCapsFeatures) -> Self {
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());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
}
}
impl FromGlibPtrFull<*const gst_sys::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *const gst_sys::GstCapsFeatures) -> Self {
impl FromGlibPtrFull<*const ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *const ffi::GstCapsFeatures) -> Self {
assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
}
}
impl FromGlibPtrFull<*mut gst_sys::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstCapsFeatures) -> Self {
impl FromGlibPtrFull<*mut ffi::GstCapsFeatures> for CapsFeatures {
unsafe fn from_glib_full(ptr: *mut ffi::GstCapsFeatures) -> Self {
assert!(!ptr.is_null());
CapsFeatures(ptr::NonNull::new_unchecked(ptr as *mut CapsFeaturesRef))
}
@ -248,35 +245,33 @@ impl glib::value::SetValueOptional for CapsFeatures {
}
impl GlibPtrDefault for CapsFeatures {
type GlibType = *mut gst_sys::GstCapsFeatures;
type GlibType = *mut ffi::GstCapsFeatures;
}
#[repr(transparent)]
pub struct CapsFeaturesRef(gst_sys::GstCapsFeatures);
pub struct CapsFeaturesRef(ffi::GstCapsFeatures);
impl CapsFeaturesRef {
pub unsafe fn from_glib_borrow<'a>(
ptr: *const gst_sys::GstCapsFeatures,
) -> &'a CapsFeaturesRef {
pub unsafe fn from_glib_borrow<'a>(ptr: *const ffi::GstCapsFeatures) -> &'a CapsFeaturesRef {
assert!(!ptr.is_null());
&*(ptr as *mut CapsFeaturesRef)
}
pub unsafe fn from_glib_borrow_mut<'a>(
ptr: *mut gst_sys::GstCapsFeatures,
ptr: *mut ffi::GstCapsFeatures,
) -> &'a mut CapsFeaturesRef {
assert!(!ptr.is_null());
&mut *(ptr as *mut CapsFeaturesRef)
}
pub unsafe fn as_ptr(&self) -> *const gst_sys::GstCapsFeatures {
self as *const Self as *const gst_sys::GstCapsFeatures
pub unsafe fn as_ptr(&self) -> *const ffi::GstCapsFeatures {
self as *const Self as *const ffi::GstCapsFeatures
}
pub unsafe fn as_mut_ptr(&self) -> *mut gst_sys::GstCapsFeatures {
self as *const Self as *mut gst_sys::GstCapsFeatures
pub unsafe fn as_mut_ptr(&self) -> *mut ffi::GstCapsFeatures {
self as *const Self as *mut ffi::GstCapsFeatures
}
pub fn is_empty(&self) -> bool {
@ -284,12 +279,12 @@ impl CapsFeaturesRef {
}
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 {
unsafe {
from_glib(gst_sys::gst_caps_features_contains(
from_glib(ffi::gst_caps_features_contains(
self.as_ptr(),
feature.to_glib_none().0,
))
@ -297,7 +292,7 @@ impl CapsFeaturesRef {
}
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> {
@ -306,7 +301,7 @@ impl CapsFeaturesRef {
}
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() {
return None;
}
@ -316,11 +311,11 @@ impl CapsFeaturesRef {
}
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) {
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 {
@ -330,7 +325,7 @@ impl CapsFeaturesRef {
// This is not an equivalence relation with regards to ANY. Everything is equal to ANY
pub fn is_equal(&self, other: &CapsFeaturesRef) -> bool {
unsafe {
from_glib(gst_sys::gst_caps_features_is_equal(
from_glib(ffi::gst_caps_features_is_equal(
self.as_ptr(),
other.as_ptr(),
))
@ -340,18 +335,18 @@ impl CapsFeaturesRef {
impl glib::types::StaticType for CapsFeaturesRef {
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 {
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() {
None
} else {
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 {
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 {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
if let Some(s) = s {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} else {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut());
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 {
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() {
return None;
}
@ -434,7 +429,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
unsafe {
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() {
return None;
}
@ -457,7 +452,7 @@ impl fmt::Debug for CapsFeaturesRef {
impl fmt::Display for CapsFeaturesRef {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
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)
}
@ -467,9 +462,7 @@ impl ToOwned for CapsFeaturesRef {
type Owned = CapsFeatures;
fn to_owned(&self) -> CapsFeatures {
unsafe {
from_glib_full(gst_sys::gst_caps_features_copy(self.as_ptr() as *const _) as *mut _)
}
unsafe { from_glib_full(ffi::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 {}
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()
.unwrap()
});
@ -490,7 +483,7 @@ mod tests {
#[test]
fn test_from_value_optional() {
::init().unwrap();
crate::init().unwrap();
let a = glib::value::Value::from(None::<&CapsFeatures>);
assert!(a.get::<CapsFeatures>().unwrap().is_none());

View file

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

View file

@ -12,12 +12,12 @@ use serde::ser::{Serialize, SerializeSeq, SerializeTuple, Serializer};
use std::fmt;
use Caps;
use CapsFeatures;
use CapsFeaturesRef;
use CapsRef;
use Structure;
use StructureRef;
use crate::Caps;
use crate::CapsFeatures;
use crate::CapsFeaturesRef;
use crate::CapsRef;
use crate::Structure;
use crate::StructureRef;
enum CapsVariantKinds {
Any,
@ -57,7 +57,7 @@ impl<'a> Serialize for CapsForIterSe<'a> {
let mut seq = serializer.serialize_seq(Some(size))?;
for (structure, features) in iter {
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
} else {
@ -229,16 +229,14 @@ impl<'de> Deserialize<'de> for Caps {
#[cfg(test)]
mod tests {
extern crate ron;
use Array;
use Caps;
use CapsFeatures;
use Fraction;
use crate::Array;
use crate::Caps;
use crate::CapsFeatures;
use crate::Fraction;
#[test]
fn test_serialize() {
::init().unwrap();
crate::init().unwrap();
let caps = Caps::builder("foo/bar")
.field("int", &12)
@ -349,9 +347,9 @@ mod tests {
#[test]
fn test_deserialize() {
use Structure;
use crate::Structure;
::init().unwrap();
crate::init().unwrap();
let caps_ron = "Any";
let caps: Caps = ron::de::from_str(caps_ron).unwrap();
@ -468,7 +466,7 @@ mod tests {
#[test]
fn test_serde_roundtrip() {
::init().unwrap();
crate::init().unwrap();
let caps = Caps::new_any();
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
// except according to those terms.
use glib;
use crate::ChildProxy;
use glib::object::IsA;
use glib::translate::*;
use gst_sys;
use std::ptr;
use ChildProxy;
pub trait ChildProxyExtManual: 'static {
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 {
fn get_child_property(&self, name: &str) -> Option<glib::Value> {
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,
name.to_glib_none().0,
ptr::null_mut(),
@ -36,7 +34,7 @@ impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
}
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,
name.to_glib_none().0,
value.to_glib_none_mut().0,
@ -51,18 +49,18 @@ impl<O: IsA<ChildProxy>> ChildProxyExtManual for O {
value: &dyn glib::ToValue,
) -> Result<(), glib::BoolError> {
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,
name.to_glib_none().0,
ptr::null_mut(),
ptr::null_mut(),
));
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();
gst_sys::gst_child_proxy_set_property(
ffi::gst_child_proxy_set_property(
self.as_ref().to_glib_none().0,
name.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
// 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_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
use glib::prelude::*;
use glib::translate::*;
use glib::IsA;
use glib_sys::{gboolean, gpointer};
use gst_sys;
use libc::c_void;
use std::cmp;
use std::convert;
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 std::marker::Unpin;
@ -33,40 +31,37 @@ use std::pin::Pin;
use std::sync::atomic;
use std::sync::atomic::AtomicI32;
glib_wrapper! {
glib::glib_wrapper! {
#[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub struct ClockId(Shared<c_void>);
match fn {
ref => |ptr| gst_sys::gst_clock_id_ref(ptr),
unref => |ptr| gst_sys::gst_clock_id_unref(ptr),
ref => |ptr| ffi::gst_clock_id_ref(ptr),
unref => |ptr| ffi::gst_clock_id_unref(ptr),
}
}
impl ClockId {
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) {
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) {
unsafe {
let mut jitter = 0;
let res: ClockReturn = from_glib(gst_sys::gst_clock_id_wait(
self.to_glib_none().0,
&mut jitter,
));
let res: ClockReturn =
from_glib(ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter));
(res.into_result(), jitter)
}
}
pub fn compare_by_time(&self, other: &Self) -> cmp::Ordering {
unsafe {
let res =
gst_sys::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0);
let res = ffi::gst_clock_id_compare_func(self.to_glib_none().0, other.to_glib_none().0);
res.cmp(&0)
}
}
@ -74,14 +69,14 @@ impl ClockId {
#[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
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_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn uses_clock<P: IsA<Clock>>(&self, clock: &P) -> bool {
unsafe {
from_glib(gst_sys::gst_clock_id_uses_clock(
from_glib(ffi::gst_clock_id_uses_clock(
self.to_glib_none().0,
clock.as_ref().as_ptr(),
))
@ -90,14 +85,14 @@ impl ClockId {
pub fn get_type(&self) -> ClockEntryType {
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_)
}
}
pub fn get_status(&self) -> &AtomicClockReturn {
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)
}
}
@ -128,7 +123,7 @@ impl convert::TryFrom<ClockId> for SingleShotClockId {
skip_assert_initialized!();
match id.get_type() {
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,
{
unsafe extern "C" fn trampoline<F: FnOnce(&Clock, ClockTime, &ClockId) + Send + 'static>(
clock: *mut gst_sys::GstClock,
time: gst_sys::GstClockTime,
clock: *mut ffi::GstClock,
time: ffi::GstClockTime,
id: gpointer,
func: gpointer,
) -> gboolean {
@ -157,7 +152,7 @@ impl SingleShotClockId {
&from_glib_borrow(id),
);
glib_sys::GTRUE
glib::ffi::GTRUE
}
unsafe extern "C" fn destroy_notify<
@ -171,7 +166,7 @@ impl SingleShotClockId {
let func: Box<Option<F>> = Box::new(Some(func));
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,
Some(trampoline::<F>),
Box::into_raw(func) as gpointer,
@ -236,7 +231,7 @@ impl convert::TryFrom<ClockId> for PeriodicClockId {
skip_assert_initialized!();
match id.get_type() {
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 {
pub fn get_interval(&self) -> ClockTime {
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)
}
}
@ -258,8 +253,8 @@ impl PeriodicClockId {
F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static,
{
unsafe extern "C" fn trampoline<F: Fn(&Clock, ClockTime, &ClockId) + Send + 'static>(
clock: *mut gst_sys::GstClock,
time: gst_sys::GstClockTime,
clock: *mut ffi::GstClock,
time: ffi::GstClockTime,
id: gpointer,
func: gpointer,
) -> gboolean {
@ -269,7 +264,7 @@ impl PeriodicClockId {
from_glib(time),
&from_glib_borrow(id),
);
glib_sys::GTRUE
glib::ffi::GTRUE
}
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 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,
Some(trampoline::<F>),
Box::into_raw(func) as gpointer,
@ -351,7 +346,7 @@ impl Clock {
) -> ClockTime {
skip_assert_initialized!();
unsafe {
from_glib(gst_sys::gst_clock_adjust_with_calibration(
from_glib(ffi::gst_clock_adjust_with_calibration(
ptr::null_mut(),
internal_target.to_glib(),
cinternal.to_glib(),
@ -371,7 +366,7 @@ impl Clock {
) -> ClockTime {
skip_assert_initialized!();
unsafe {
from_glib(gst_sys::gst_clock_unadjust_with_calibration(
from_glib(ffi::gst_clock_unadjust_with_calibration(
ptr::null_mut(),
external_target.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 {
assert!(start_time.is_some());
assert!(interval.is_some());
assert_ne!(interval, ::ClockTime::from(0));
assert_ne!(interval, crate::ClockTime::from(0));
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,
start_time.to_glib(),
interval.to_glib(),
@ -431,7 +426,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
) -> Result<(), glib::BoolError> {
skip_assert_initialized!();
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,
id.to_glib_none().0,
start_time.to_glib(),
@ -440,7 +435,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
if res {
Ok(())
} 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());
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,
time.to_glib(),
)))
@ -462,7 +457,7 @@ impl<O: IsA<Clock>> ClockExtManual for O {
time: ClockTime,
) -> Result<(), glib::BoolError> {
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,
id.to_glib_none().0,
time.to_glib(),
@ -470,31 +465,33 @@ impl<O: IsA<Clock>> ClockExtManual for O {
if res {
Ok(())
} 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) {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib();
}
}
fn unset_clock_flags(&self, flags: ClockFlags) {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib();
}
}
fn get_clock_flags(&self) -> ClockFlags {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags)
}
}
@ -508,11 +505,11 @@ mod tests {
#[test]
fn test_wait() {
::init().unwrap();
crate::init().unwrap();
let clock = SystemClock::obtain();
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();
assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early));
@ -520,13 +517,13 @@ mod tests {
#[test]
fn test_wait_async() {
::init().unwrap();
crate::init().unwrap();
let (sender, receiver) = channel();
let clock = SystemClock::obtain();
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 |_, _, _| {
sender.send(()).unwrap();
});
@ -538,11 +535,11 @@ mod tests {
#[test]
fn test_wait_periodic() {
::init().unwrap();
crate::init().unwrap();
let clock = SystemClock::obtain();
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();
assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early));
@ -553,13 +550,13 @@ mod tests {
#[test]
fn test_wait_async_periodic() {
::init().unwrap();
crate::init().unwrap();
let (sender, receiver) = channel();
let clock = SystemClock::obtain();
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 _ = sender.send(());
});

View file

@ -6,9 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use glib;
use glib::translate::*;
use gst_sys;
use std::time::Duration;
use std::{cmp, convert, fmt};
@ -17,27 +15,27 @@ pub struct ClockTime(pub Option<u64>);
impl ClockTime {
pub fn hours(&self) -> Option<u64> {
(*self / ::SECOND / 60 / 60).0
(*self / crate::SECOND / 60 / 60).0
}
pub fn minutes(&self) -> Option<u64> {
(*self / ::SECOND / 60).0
(*self / crate::SECOND / 60).0
}
pub fn seconds(&self) -> Option<u64> {
(*self / ::SECOND).0
(*self / crate::SECOND).0
}
pub fn mseconds(&self) -> Option<u64> {
(*self / ::MSECOND).0
(*self / crate::MSECOND).0
}
pub fn useconds(&self) -> Option<u64> {
(*self / ::USECOND).0
(*self / crate::USECOND).0
}
pub fn nseconds(&self) -> Option<u64> {
(*self / ::NSECOND).0
(*self / crate::NSECOND).0
}
pub fn nanoseconds(&self) -> Option<u64> {
@ -46,22 +44,22 @@ impl ClockTime {
pub fn from_seconds(seconds: u64) -> ClockTime {
skip_assert_initialized!();
seconds * ::SECOND
seconds * crate::SECOND
}
pub fn from_mseconds(mseconds: u64) -> ClockTime {
skip_assert_initialized!();
mseconds * ::MSECOND
mseconds * crate::MSECOND
}
pub fn from_useconds(useconds: u64) -> ClockTime {
skip_assert_initialized!();
useconds * ::USECOND
useconds * crate::USECOND
}
pub fn from_nseconds(nseconds: u64) -> ClockTime {
skip_assert_initialized!();
nseconds * ::NSECOND
nseconds * crate::NSECOND
}
}
@ -182,22 +180,22 @@ impl fmt::Display for ClockTime {
#[doc(hidden)]
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 {
None => gst_sys::GST_CLOCK_TIME_NONE,
None => ffi::GST_CLOCK_TIME_NONE,
Some(v) => v,
}
}
}
#[doc(hidden)]
impl FromGlib<gst_sys::GstClockTime> for ClockTime {
fn from_glib(value: gst_sys::GstClockTime) -> Self {
impl FromGlib<ffi::GstClockTime> for ClockTime {
fn from_glib(value: ffi::GstClockTime) -> Self {
skip_assert_initialized!();
match value {
gst_sys::GST_CLOCK_TIME_NONE => ClockTime(None),
ffi::GST_CLOCK_TIME_NONE => ClockTime(None),
value => ClockTime(Some(value)),
}
}
@ -239,7 +237,7 @@ impl From<Duration> for ClockTime {
let nanos = d.as_nanos();
if nanos > std::u64::MAX as u128 {
::CLOCK_TIME_NONE
crate::CLOCK_TIME_NONE
} else {
ClockTime::from_nseconds(nanos as u64)
}
@ -254,7 +252,7 @@ impl convert::TryFrom<ClockTime> for Duration {
t.nanoseconds()
.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 ClockTime;
use crate::ClockTime;
impl<'a> Serialize for ClockTime {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
@ -52,14 +52,11 @@ impl<'de> Deserialize<'de> for ClockTime {
#[cfg(test)]
mod tests {
extern crate ron;
extern crate serde_json;
use ClockTime;
use crate::ClockTime;
#[test]
fn test_serialize() {
::init().unwrap();
crate::init().unwrap();
// Some
let clocktime = ClockTime::from_nseconds(42_123_456_789);
@ -85,7 +82,7 @@ mod tests {
#[test]
fn test_deserialize() {
::init().unwrap();
crate::init().unwrap();
// Some
let clocktime_ron = "Some(42123456789)";
@ -114,7 +111,7 @@ mod tests {
#[test]
fn test_serde_roundtrip() {
::init().unwrap();
crate::init().unwrap();
// Some
let clocktime = ClockTime::from_nseconds(42_123_456_789);

View file

@ -9,22 +9,19 @@
use std::ffi::CStr;
use std::fmt;
use gst_sys;
use glib;
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_sys::gst_context_get_type()
gst_define_mini_object_wrapper!(Context, ContextRef, ffi::GstContext, || {
ffi::gst_context_get_type()
});
impl Context {
pub fn new(context_type: &str, persistent: bool) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_sys::gst_context_new(
from_glib_full(ffi::gst_context_new(
context_type.to_glib_none().0,
persistent.to_glib(),
))
@ -35,14 +32,14 @@ impl Context {
impl ContextRef {
pub fn get_context_type(&self) -> &str {
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()
}
}
pub fn has_context_type(&self, context_type: &str) -> bool {
unsafe {
from_glib(gst_sys::gst_context_has_context_type(
from_glib(ffi::gst_context_has_context_type(
self.as_mut_ptr(),
context_type.to_glib_none().0,
))
@ -50,18 +47,16 @@ impl ContextRef {
}
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 {
unsafe {
StructureRef::from_glib_borrow(gst_sys::gst_context_get_structure(self.as_mut_ptr()))
}
unsafe { StructureRef::from_glib_borrow(ffi::gst_context_get_structure(self.as_mut_ptr())) }
}
pub fn get_mut_structure(&mut self) -> &mut StructureRef {
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(),
))
}

View file

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

View file

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

View file

@ -10,7 +10,7 @@ use std::cmp;
use std::convert;
use std::fmt;
use DateTime;
use crate::DateTime;
impl DateTime {
pub fn to_utc(&self) -> Result<DateTime, glib::BoolError> {
@ -28,7 +28,7 @@ impl DateTime {
self.to_g_date_time()
.and_then(|d| {
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))
} else {
@ -48,7 +48,7 @@ impl DateTime {
.and_then(|d| d.to_g_date_time())
.and_then(|d| {
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::new(
@ -273,7 +273,7 @@ mod tests {
#[allow(clippy::cognitive_complexity)]
#[test]
fn test_to_utc() {
::init().unwrap();
crate::init().unwrap();
// Hour offset
let utc_date_time = DateTime::new(2f32, 2019, 8, 20, 20, 9, 42.123_456f64)
@ -324,7 +324,7 @@ mod tests {
#[test]
fn test_partial_ord() {
::init().unwrap();
crate::init().unwrap();
// Different years
assert!(
@ -429,7 +429,7 @@ mod tests {
#[test]
fn test_eq() {
::init().unwrap();
crate::init().unwrap();
assert_eq!(
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::StaticType;
use crate::DateTime;
use serde::de::{Deserialize, Deserializer, Error};
use serde::ser;
use serde::ser::{Serialize, Serializer};
use DateTime;
#[derive(Serialize, Deserialize)]
#[derive(serde::Serialize, serde::Deserialize)]
enum DateTimeVariants {
Y(i32),
YM(i32, i32),
@ -115,18 +115,18 @@ impl TryFrom<DateTimeVariants> for Date {
DateTimeVariants::YMD(y, m, d) => {
let month = glib::DateMonth::from_glib(m);
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(
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,
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\")"
)),
}
@ -171,14 +171,11 @@ impl<'de> Deserialize<'de> for DateTime {
#[cfg(test)]
mod tests {
extern crate ron;
extern crate serde_json;
use DateTime;
use crate::DateTime;
#[test]
fn test_serialize() {
::init().unwrap();
crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string();
@ -215,7 +212,7 @@ mod tests {
#[test]
fn test_deserialize() {
::init().unwrap();
crate::init().unwrap();
let datetime_ron = "YMDhmsTz(2018, 5, 28, 16, 6, 42.123456, 2)";
let datetime_de: DateTime = ron::de::from_str(datetime_ron).unwrap();
@ -253,7 +250,7 @@ mod tests {
#[test]
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_ser = ron::ser::to_string(&datetime).unwrap();

View file

@ -6,26 +6,23 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use Caps;
use DeviceMonitor;
use crate::Caps;
use crate::DeviceMonitor;
use glib;
use glib::object::IsA;
use glib::translate::*;
use gst_sys;
use std::num::NonZeroU32;
impl DeviceMonitor {
pub fn new() -> DeviceMonitor {
assert_initialized_main_thread!();
let (major, minor, _, _) = ::version();
let (major, minor, _, _) = crate::version();
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 {
// 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>,
) -> Option<DeviceMonitorFilterId> {
let id = unsafe {
gst_sys::gst_device_monitor_add_filter(
ffi::gst_device_monitor_add_filter(
self.as_ref().to_glib_none().0,
classes.to_glib_none().0,
caps.to_glib_none().0,
@ -92,8 +89,8 @@ impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {
filter_id: DeviceMonitorFilterId,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_device_monitor_remove_filter(
glib::glib_result_from_gboolean!(
ffi::gst_device_monitor_remove_filter(
self.as_ref().to_glib_none().0,
filter_id.to_glib()
),

View file

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

View file

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

View file

@ -6,14 +6,14 @@
// option. This file may not be copied, modified, or distributed
// 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 thiserror::Error;
use ClockReturn;
use FlowReturn;
use PadLinkReturn;
use State;
use StateChange;
use StateChangeReturn;
use glib::translate::*;
use glib::value::FromValue;
@ -352,104 +352,104 @@ impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
}
}
impl PartialEq for ::TypeFindProbability {
fn eq(&self, other: &::TypeFindProbability) -> bool {
impl PartialEq for crate::TypeFindProbability {
fn eq(&self, other: &crate::TypeFindProbability) -> bool {
(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> {
(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 {
(self.to_glib() as u32).cmp(&(other.to_glib() as u32))
}
}
impl ops::Add<u32> for ::TypeFindProbability {
type Output = ::TypeFindProbability;
impl ops::Add<u32> for crate::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);
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) {
let res = (self.to_glib() as u32).saturating_add(rhs);
*self = from_glib(res as i32);
}
}
impl ops::Sub<u32> for ::TypeFindProbability {
type Output = ::TypeFindProbability;
impl ops::Sub<u32> for crate::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);
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) {
let res = (self.to_glib() as u32).saturating_sub(rhs);
*self = from_glib(res as i32);
}
}
impl PartialEq for ::Rank {
fn eq(&self, other: &::Rank) -> bool {
impl PartialEq for crate::Rank {
fn eq(&self, other: &crate::Rank) -> bool {
(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> {
(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 {
(self.to_glib() as u32).cmp(&(other.to_glib() as u32))
}
}
impl ops::Add<u32> for ::Rank {
type Output = ::Rank;
impl ops::Add<u32> for crate::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);
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) {
let res = (self.to_glib() as u32).saturating_add(rhs);
*self = from_glib(res as i32);
}
}
impl ops::Sub<u32> for ::Rank {
type Output = ::Rank;
impl ops::Sub<u32> for crate::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);
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) {
let res = (self.to_glib() as u32).saturating_sub(rhs);
*self = from_glib(res as i32);
@ -512,58 +512,58 @@ pub enum MessageType {
#[doc(hidden)]
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 {
MessageType::Unknown => gst_sys::GST_MESSAGE_UNKNOWN,
MessageType::Eos => gst_sys::GST_MESSAGE_EOS,
MessageType::Error => gst_sys::GST_MESSAGE_ERROR,
MessageType::Warning => gst_sys::GST_MESSAGE_WARNING,
MessageType::Info => gst_sys::GST_MESSAGE_INFO,
MessageType::Tag => gst_sys::GST_MESSAGE_TAG,
MessageType::Buffering => gst_sys::GST_MESSAGE_BUFFERING,
MessageType::StateChanged => gst_sys::GST_MESSAGE_STATE_CHANGED,
MessageType::StateDirty => gst_sys::GST_MESSAGE_STATE_DIRTY,
MessageType::StepDone => gst_sys::GST_MESSAGE_STEP_DONE,
MessageType::ClockProvide => gst_sys::GST_MESSAGE_CLOCK_PROVIDE,
MessageType::ClockLost => gst_sys::GST_MESSAGE_CLOCK_LOST,
MessageType::NewClock => gst_sys::GST_MESSAGE_NEW_CLOCK,
MessageType::StructureChange => gst_sys::GST_MESSAGE_STRUCTURE_CHANGE,
MessageType::StreamStatus => gst_sys::GST_MESSAGE_STREAM_STATUS,
MessageType::Application => gst_sys::GST_MESSAGE_APPLICATION,
MessageType::Element => gst_sys::GST_MESSAGE_ELEMENT,
MessageType::SegmentStart => gst_sys::GST_MESSAGE_SEGMENT_START,
MessageType::SegmentDone => gst_sys::GST_MESSAGE_SEGMENT_DONE,
MessageType::DurationChanged => gst_sys::GST_MESSAGE_DURATION_CHANGED,
MessageType::Latency => gst_sys::GST_MESSAGE_LATENCY,
MessageType::AsyncStart => gst_sys::GST_MESSAGE_ASYNC_START,
MessageType::AsyncDone => gst_sys::GST_MESSAGE_ASYNC_DONE,
MessageType::RequestState => gst_sys::GST_MESSAGE_REQUEST_STATE,
MessageType::StepStart => gst_sys::GST_MESSAGE_STEP_START,
MessageType::Qos => gst_sys::GST_MESSAGE_QOS,
MessageType::Progress => gst_sys::GST_MESSAGE_PROGRESS,
MessageType::Toc => gst_sys::GST_MESSAGE_TOC,
MessageType::ResetTime => gst_sys::GST_MESSAGE_RESET_TIME,
MessageType::StreamStart => gst_sys::GST_MESSAGE_STREAM_START,
MessageType::NeedContext => gst_sys::GST_MESSAGE_NEED_CONTEXT,
MessageType::HaveContext => gst_sys::GST_MESSAGE_HAVE_CONTEXT,
MessageType::Extended => gst_sys::GST_MESSAGE_EXTENDED,
MessageType::DeviceAdded => gst_sys::GST_MESSAGE_DEVICE_ADDED,
MessageType::DeviceRemoved => gst_sys::GST_MESSAGE_DEVICE_REMOVED,
MessageType::PropertyNotify => gst_sys::GST_MESSAGE_PROPERTY_NOTIFY,
MessageType::StreamCollection => gst_sys::GST_MESSAGE_STREAM_COLLECTION,
MessageType::StreamsSelected => gst_sys::GST_MESSAGE_STREAMS_SELECTED,
MessageType::Redirect => gst_sys::GST_MESSAGE_REDIRECT,
MessageType::Unknown => ffi::GST_MESSAGE_UNKNOWN,
MessageType::Eos => ffi::GST_MESSAGE_EOS,
MessageType::Error => ffi::GST_MESSAGE_ERROR,
MessageType::Warning => ffi::GST_MESSAGE_WARNING,
MessageType::Info => ffi::GST_MESSAGE_INFO,
MessageType::Tag => ffi::GST_MESSAGE_TAG,
MessageType::Buffering => ffi::GST_MESSAGE_BUFFERING,
MessageType::StateChanged => ffi::GST_MESSAGE_STATE_CHANGED,
MessageType::StateDirty => ffi::GST_MESSAGE_STATE_DIRTY,
MessageType::StepDone => ffi::GST_MESSAGE_STEP_DONE,
MessageType::ClockProvide => ffi::GST_MESSAGE_CLOCK_PROVIDE,
MessageType::ClockLost => ffi::GST_MESSAGE_CLOCK_LOST,
MessageType::NewClock => ffi::GST_MESSAGE_NEW_CLOCK,
MessageType::StructureChange => ffi::GST_MESSAGE_STRUCTURE_CHANGE,
MessageType::StreamStatus => ffi::GST_MESSAGE_STREAM_STATUS,
MessageType::Application => ffi::GST_MESSAGE_APPLICATION,
MessageType::Element => ffi::GST_MESSAGE_ELEMENT,
MessageType::SegmentStart => ffi::GST_MESSAGE_SEGMENT_START,
MessageType::SegmentDone => ffi::GST_MESSAGE_SEGMENT_DONE,
MessageType::DurationChanged => ffi::GST_MESSAGE_DURATION_CHANGED,
MessageType::Latency => ffi::GST_MESSAGE_LATENCY,
MessageType::AsyncStart => ffi::GST_MESSAGE_ASYNC_START,
MessageType::AsyncDone => ffi::GST_MESSAGE_ASYNC_DONE,
MessageType::RequestState => ffi::GST_MESSAGE_REQUEST_STATE,
MessageType::StepStart => ffi::GST_MESSAGE_STEP_START,
MessageType::Qos => ffi::GST_MESSAGE_QOS,
MessageType::Progress => ffi::GST_MESSAGE_PROGRESS,
MessageType::Toc => ffi::GST_MESSAGE_TOC,
MessageType::ResetTime => ffi::GST_MESSAGE_RESET_TIME,
MessageType::StreamStart => ffi::GST_MESSAGE_STREAM_START,
MessageType::NeedContext => ffi::GST_MESSAGE_NEED_CONTEXT,
MessageType::HaveContext => ffi::GST_MESSAGE_HAVE_CONTEXT,
MessageType::Extended => ffi::GST_MESSAGE_EXTENDED,
MessageType::DeviceAdded => ffi::GST_MESSAGE_DEVICE_ADDED,
MessageType::DeviceRemoved => ffi::GST_MESSAGE_DEVICE_REMOVED,
MessageType::PropertyNotify => ffi::GST_MESSAGE_PROPERTY_NOTIFY,
MessageType::StreamCollection => ffi::GST_MESSAGE_STREAM_COLLECTION,
MessageType::StreamsSelected => ffi::GST_MESSAGE_STREAMS_SELECTED,
MessageType::Redirect => ffi::GST_MESSAGE_REDIRECT,
MessageType::__Unknown(value) => value as u32,
}
}
}
#[doc(hidden)]
impl FromGlib<gst_sys::GstMessageType> for MessageType {
impl FromGlib<ffi::GstMessageType> for MessageType {
#[allow(clippy::unreadable_literal)]
fn from_glib(value: gst_sys::GstMessageType) -> Self {
fn from_glib(value: ffi::GstMessageType) -> Self {
skip_assert_initialized!();
match value {
0 => MessageType::Unknown,
@ -612,7 +612,7 @@ impl FromGlib<gst_sys::GstMessageType> for MessageType {
impl StaticType for MessageType {
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 {
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 {
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 glib;
use glib::IsA;
#[macro_export]
@ -62,7 +61,7 @@ pub struct ErrorMessage {
}
impl ErrorMessage {
pub fn new<T: ::MessageErrorDomain>(
pub fn new<T: crate::MessageErrorDomain>(
error: &T,
message: Option<&str>,
debug: Option<&str>,
@ -102,14 +101,14 @@ macro_rules! gst_loggable_error(
#[macro_export]
macro_rules! gst_result_from_gboolean(
// Plain strings
($gst_sys_bool:expr, $cat:expr, $msg:expr) => {
$crate::glib::glib_result_from_gboolean!($gst_sys_bool, $msg)
($ffi_bool:expr, $cat:expr, $msg:expr) => {
$crate::glib::glib_result_from_gboolean!($ffi_bool, $msg)
.map_err(|bool_err| $crate::LoggableError::new($cat.clone(), bool_err))
};
// Format strings
($gst_sys_bool:expr, $cat:expr, $($msg:tt)*) => { {
$crate::glib::glib_result_from_gboolean!($gst_sys_bool, $($msg)*)
($ffi_bool:expr, $cat:expr, $($msg:tt)*) => { {
$crate::glib::glib_result_from_gboolean!($ffi_bool, $($msg)*)
.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)]
#[error("Error {:?}: {:?} at {}:{}", .category.get_name(), .bool_error.message, .bool_error.filename, .bool_error.line)]
pub struct LoggableError {
category: ::DebugCategory,
category: crate::DebugCategory,
bool_error: glib::BoolError,
}
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!();
LoggableError {
category,
@ -133,7 +132,7 @@ impl LoggableError {
pub fn log(&self) {
self.category.log(
None as Option<&glib::Object>,
::DebugLevel::Error,
crate::DebugLevel::Error,
self.bool_error.filename,
self.bool_error.function,
self.bool_error.line,
@ -144,7 +143,7 @@ impl LoggableError {
pub fn log_with_object<O: IsA<glib::Object>>(&self, obj: &O) {
self.category.log(
Some(obj),
::DebugLevel::Error,
crate::DebugLevel::Error,
self.bool_error.filename,
self.bool_error.function,
self.bool_error.line,
@ -152,7 +151,7 @@ impl LoggableError {
);
}
pub fn category(&self) -> ::DebugCategory {
pub fn category(&self) -> crate::DebugCategory {
self.category
}
}
@ -161,7 +160,7 @@ impl From<glib::BoolError> for LoggableError {
fn from(bool_error: glib::BoolError) -> Self {
skip_assert_initialized!();
LoggableError {
category: *::CAT_RUST,
category: *crate::CAT_RUST,
bool_error,
}
}
@ -173,10 +172,10 @@ mod tests {
#[test]
fn error_message() {
::init().unwrap();
crate::init().unwrap();
let e = ErrorMessage::new(
&::CoreError::Failed,
&crate::CoreError::Failed,
Some("message"),
Some("debug"),
"filename",
@ -191,7 +190,7 @@ mod tests {
#[test]
fn logabble_error() {
::init().unwrap();
crate::init().unwrap();
let e: LoggableError = glib::BoolError::new("msg", "filename", "function", 7).into();
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
// except according to those terms.
use crate::ClockTime;
use crate::Format;
use muldiv::MulDiv;
use std::convert::TryFrom;
use std::ops;
use thiserror::Error;
use ClockTime;
use Format;
use std::cmp;
#[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 {
Undefined(Undefined),
Default(Default),
@ -615,7 +615,7 @@ impl FormattedValue for Percent {
unsafe fn from_raw(format: Format, value: i64) -> Self {
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)
} else {
Percent(Some(value as u32))
@ -688,7 +688,7 @@ impl TryFrom<f64> for Percent {
Err(TryPercentFromFloatError(()))
} else {
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(()))
} else {
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 {
#[test]
fn test_clock_time() {
::init().unwrap();
crate::init().unwrap();
let t1 = ::SECOND;
let t1 = crate::SECOND;
let t2 = 2 * t1;
let t3 = &t1 * 2;
let mut t4 = t2 + t3;
@ -723,7 +723,7 @@ mod tests {
assert_eq!(t4.nanoseconds(), Some(5_000_000_000));
let t5 = t4 - 6 * ::SECOND;
let t5 = t4 - 6 * crate::SECOND;
assert!(t5.is_none());
}
}

View file

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

View file

@ -6,18 +6,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use auto::functions::parse_bin_from_description;
use glib;
use crate::auto::functions::parse_bin_from_description;
use glib::translate::*;
use glib::Cast;
use gst_sys;
use std::ptr;
use Bin;
use Element;
use Object;
use ParseContext;
use ParseFlags;
use crate::Bin;
use crate::Element;
use crate::Object;
use crate::ParseContext;
use crate::ParseFlags;
pub fn parse_bin_from_description_with_name(
bin_description: &str,
@ -29,7 +27,7 @@ pub fn parse_bin_from_description_with_name(
if !bin_name.is_empty() {
let obj = bin.clone().upcast::<Object>();
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)
@ -44,7 +42,7 @@ pub fn parse_bin_from_description_full(
assert_initialized_main_thread!();
unsafe {
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,
ghost_unlinked_pads.to_glib(),
context.to_glib_none_mut().0,
@ -72,7 +70,7 @@ pub fn parse_bin_from_description_with_name_full(
if !bin_name.is_empty() {
let obj = bin.clone().upcast::<Object>();
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)
@ -86,7 +84,7 @@ pub fn parse_launch_full(
assert_initialized_main_thread!();
unsafe {
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,
context.to_glib_none_mut().0,
flags.to_glib(),
@ -108,7 +106,7 @@ pub fn parse_launchv_full(
assert_initialized_main_thread!();
unsafe {
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,
context.to_glib_none_mut().0,
flags.to_glib(),
@ -147,7 +145,7 @@ pub fn calculate_linear_regression(
let mut xbase = 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,
temp.map(|temp| temp.as_mut_ptr() as *mut u64)
.unwrap_or(ptr::null_mut()),
@ -174,13 +172,13 @@ pub fn calculate_linear_regression(
#[cfg(any(feature = "v1_18", feature = "dox"))]
#[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!();
unsafe {
use std::mem;
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(),
flags.as_mut_ptr(),
));
@ -196,12 +194,12 @@ pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<::PluginAPIFlags>
#[cfg(test)]
mod tests {
use super::*;
use prelude::*;
use crate::prelude::*;
#[cfg(feature = "v1_12")]
#[test]
fn test_calculate_linear_regression() {
::init().unwrap();
crate::init().unwrap();
let values = [(0, 0), (1, 1), (2, 2), (3, 3)];
@ -216,7 +214,7 @@ mod tests {
#[test]
fn test_parse_bin_from_description_with_name() {
::init().unwrap();
crate::init().unwrap();
let bin =
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
// 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::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 {
pub fn activate_mode_default<P: IsA<GhostPad>, Q: IsA<Object>>(
@ -32,9 +31,9 @@ impl GhostPad {
) -> Result<(), glib::BoolError> {
skip_assert_initialized!();
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_ghost_pad_activate_mode_default(
pad.to_glib_none().0 as *mut gst_sys::GstPad,
glib::glib_result_from_gboolean!(
ffi::gst_ghost_pad_activate_mode_default(
pad.to_glib_none().0 as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0,
mode.to_glib(),
active.to_glib(),
@ -52,9 +51,9 @@ impl GhostPad {
) -> Result<(), glib::BoolError> {
skip_assert_initialized!();
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_ghost_pad_internal_activate_mode_default(
pad.to_glib_none().0 as *mut gst_sys::GstPad,
glib::glib_result_from_gboolean!(
ffi::gst_ghost_pad_internal_activate_mode_default(
pad.to_glib_none().0 as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0,
mode.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!();
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!();
PadBuilder::new(name, direction)
}
@ -90,12 +89,15 @@ impl GhostPad {
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!();
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!();
PadBuilder::from_template(templ, name)
}
@ -109,14 +111,14 @@ impl GhostPad {
}
pub fn from_template_with_target<P: IsA<Pad>>(
templ: &::PadTemplate,
templ: &crate::PadTemplate,
name: Option<&str>,
target: &P,
) -> Result<Self, glib::BoolError> {
skip_assert_initialized!();
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"
));
}
@ -128,14 +130,17 @@ impl GhostPad {
impl<T: IsA<GhostPad> + IsA<Pad>> PadBuilder<T> {
pub fn proxy_pad_activate_function<F>(self, func: F) -> Self
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 {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
where
F: Fn(&::ProxyPad, Option<&::Object>, ::PadMode, bool) -> Result<(), LoggableError>
F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::PadMode,
bool,
) -> Result<(), LoggableError>
+ Send
+ Sync
+ 'static,
{
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
where
F: Fn(&::ProxyPad, Option<&::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::Buffer,
) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
where
F: Fn(&::ProxyPad, Option<&::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::BufferList,
) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
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 {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
where
F: Fn(&::ProxyPad, Option<&::Object>, ::Event) -> Result<FlowSuccess, FlowError>
F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
crate::Event,
) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
where
F: Fn(
&::ProxyPad,
Option<&::Object>,
&crate::ProxyPad,
Option<&crate::Object>,
u64,
Option<&mut ::BufferRef>,
Option<&mut crate::BufferRef>,
u32,
) -> Result<PadGetRangeSuccess, ::FlowError>
) -> Result<PadGetRangeSuccess, crate::FlowError>
+ Send
+ Sync
+ 'static,
{
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
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 {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
where
F: Fn(&::ProxyPad, Option<&::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
F: Fn(
&crate::ProxyPad,
Option<&crate::Object>,
&Pad,
) -> Result<crate::PadLinkSuccess, crate::PadLinkError>
+ Send
+ Sync
+ 'static,
{
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
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 {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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
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 {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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 {
use ProxyPadExt;
use crate::ProxyPadExt;
unsafe {
let proxy = self
.0
.unsafe_cast_ref::<::ProxyPad>()
.unsafe_cast_ref::<crate::ProxyPad>()
.get_internal()
.unwrap();
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> {
use GhostPadExt;
use crate::GhostPadExt;
assert_eq!(self.0.get_direction(), target.get_direction());

View file

@ -1,9 +1,6 @@
use glib;
use glib::translate::ToGlibPtr;
use glib::IsA;
use gst_sys;
pub trait GObjectExtManualGst: 'static {
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 {
fn set_property_from_str(&self, name: &str, value: &str) {
unsafe {
gst_sys::gst_util_set_object_arg(
ffi::gst_util_set_object_arg(
self.as_ref().to_glib_none().0,
name.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
// except according to those terms.
use glib;
use glib::ffi::{gconstpointer, gpointer};
use glib::translate::*;
use glib::value::{FromValueOptional, ToValue};
use glib::StaticType;
use glib::Value;
use glib_sys;
use glib_sys::{gconstpointer, gpointer};
use gobject_sys;
use gst_sys;
use std::ffi::CString;
use std::fmt;
use std::iter;
@ -34,7 +30,7 @@ pub enum IteratorError {
// Implemented manually so that we can use generics for the item
pub struct Iterator<T> {
iter: ptr::NonNull<gst_sys::GstIterator>,
iter: ptr::NonNull<ffi::GstIterator>,
phantom: PhantomData<T>,
}
@ -42,7 +38,7 @@ impl<T> Iterator<T>
where
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 it = s.to_glib_none().0;
it as *mut _
@ -52,25 +48,24 @@ where
pub fn next(&mut self) -> Result<Option<T>, IteratorError> {
unsafe {
let mut value = Value::uninitialized();
let res =
gst_sys::gst_iterator_next(self.to_glib_none_mut().0, value.to_glib_none_mut().0);
let res = ffi::gst_iterator_next(self.to_glib_none_mut().0, value.to_glib_none_mut().0);
#[allow(clippy::wildcard_in_or_patterns)]
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)),
None => Err(IteratorError::Error),
},
gst_sys::GST_ITERATOR_DONE => Ok(None),
gst_sys::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
gst_sys::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
ffi::GST_ITERATOR_DONE => Ok(None),
ffi::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
ffi::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
}
}
}
pub fn resync(&mut self) {
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 {
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>()));
gobject_sys::g_value_take_boxed(
glib::gobject_ffi::g_value_take_boxed(
closure_value.to_glib_none_mut().0,
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(),
Some(filter_trampoline::<T>),
closure_value.to_glib_none().0,
@ -104,7 +99,7 @@ where
let mut func = func;
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,
Some(find_trampoline::<T, F>),
elem.to_glib_none_mut().0,
@ -126,7 +121,7 @@ where
let mut func = func;
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,
Some(foreach_trampoline::<T, F>),
func_ptr,
@ -134,9 +129,9 @@ where
#[allow(clippy::wildcard_in_or_patterns)]
match res {
gst_sys::GST_ITERATOR_OK | gst_sys::GST_ITERATOR_DONE => Ok(()),
gst_sys::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
gst_sys::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
ffi::GST_ITERATOR_OK | ffi::GST_ITERATOR_DONE => Ok(()),
ffi::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
ffi::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
}
}
}
@ -151,12 +146,12 @@ where
let mut accum = Some(init);
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,
&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,
Some(fold_trampoline::<T, U, F>),
ret.to_glib_none_mut().0,
@ -165,9 +160,9 @@ where
#[allow(clippy::wildcard_in_or_patterns)]
match res {
gst_sys::GST_ITERATOR_OK | gst_sys::GST_ITERATOR_DONE => Ok(accum.unwrap()),
gst_sys::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
gst_sys::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
ffi::GST_ITERATOR_OK | ffi::GST_ITERATOR_DONE => Ok(accum.unwrap()),
ffi::GST_ITERATOR_RESYNC => Err(IteratorError::Resync),
ffi::GST_ITERATOR_ERROR | _ => Err(IteratorError::Error),
}
}
}
@ -182,7 +177,7 @@ where
static DUMMY_COOKIE: u32 = 0;
unsafe {
let it = gst_sys::gst_iterator_new(
let it = ffi::gst_iterator_new(
mem::size_of::<RsIterator<T, I>>() as u32,
T::static_type().to_glib(),
ptr::null_mut(),
@ -219,7 +214,7 @@ struct RsIterator<T, I: IteratorImpl<T>>
where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{
iter: gst_sys::GstIterator,
iter: ffi::GstIterator,
imp: I,
phantom: PhantomData<T>,
}
@ -233,8 +228,8 @@ where
}
unsafe extern "C" fn rs_iterator_copy<T, I: IteratorImpl<T>>(
it: *const gst_sys::GstIterator,
copy: *mut gst_sys::GstIterator,
it: *const ffi::GstIterator,
copy: *mut ffi::GstIterator,
) where
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());
}
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
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>>(
it: *mut gst_sys::GstIterator,
result: *mut gobject_sys::GValue,
) -> gst_sys::GstIteratorResult
it: *mut ffi::GstIterator,
result: *mut glib::gobject_ffi::GValue,
) -> ffi::GstIteratorResult
where
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
{
@ -264,17 +259,17 @@ where
Some(Ok(value)) => {
let value = value.to_value();
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 {
IteratorError::Resync => gst_sys::GST_ITERATOR_RESYNC,
IteratorError::Error => gst_sys::GST_ITERATOR_ERROR,
IteratorError::Resync => ffi::GST_ITERATOR_RESYNC,
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
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
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 = gobject_sys::g_value_get_boxed(func);
let func = func as *const glib::gobject_ffi::GValue;
let func = glib::gobject_ffi::g_value_get_boxed(func);
let func = &*(func as *const &(dyn Fn(T) -> bool + Send + Sync + 'static));
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>);
}
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 std::collections::HashMap;
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()));
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 =
CString::new(format!("GstRsIteratorFilterBoxed-{}-{}", type_name, idx))
.unwrap();
if gobject_sys::g_type_from_name(iter_type_name.as_ptr())
== gobject_sys::G_TYPE_INVALID
if glib::gobject_ffi::g_type_from_name(iter_type_name.as_ptr())
== glib::gobject_ffi::G_TYPE_INVALID
{
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(),
Some(filter_boxed_ref::<T>),
Some(filter_boxed_unref::<T>),
);
assert_ne!(type_, gobject_sys::G_TYPE_INVALID);
assert_ne!(type_, glib::gobject_ffi::G_TYPE_INVALID);
type_
};
@ -412,7 +407,7 @@ unsafe extern "C" fn find_trampoline<T, F: FnMut(T) -> bool>(
where
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 value = &*(value as *const glib::Value);
@ -426,7 +421,7 @@ where
}
unsafe extern "C" fn foreach_trampoline<T, F: FnMut(T)>(
value: *const gobject_sys::GValue,
value: *const glib::gobject_ffi::GValue,
func: gpointer,
) where
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>>(
value: *const gobject_sys::GValue,
ret: *mut gobject_sys::GValue,
value: *const glib::gobject_ffi::GValue,
ret: *mut glib::gobject_ffi::GValue,
func: gpointer,
) -> glib_sys::gboolean
) -> glib::ffi::gboolean
where
for<'a> T: FromValueOptional<'a> + 'static,
{
@ -453,23 +448,23 @@ where
let value = &*(value as *const glib::Value);
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) {
Ok(next_accum) => {
*accum = Some(next_accum);
glib_sys::GTRUE
glib::ffi::GTRUE
}
Err(next_accum) => {
*accum = Some(next_accum);
glib_sys::GFALSE
glib::ffi::GFALSE
}
}
}
impl<T: StaticType + 'static> Clone for Iterator<T> {
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> {
fn drop(&mut self) {
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> {
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)]
impl<'a, T: StaticType> glib::value::FromValueOptional<'a> for Iterator<T> {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<Iterator<T>>::from_glib_none(
gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstIterator,
)
Option::<Iterator<T>>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
value.to_glib_none().0,
) as *mut ffi::GstIterator)
}
}
#[doc(hidden)]
impl<T: 'static> glib::value::SetValue for Iterator<T> {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstIterator>::to_glib_none(this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstIterator>::to_glib_none(this).0
as glib::ffi::gpointer,
)
}
}
@ -530,76 +525,76 @@ impl<T: 'static> glib::value::SetValue for Iterator<T> {
#[doc(hidden)]
impl<T: 'static> glib::value::SetValueOptional for Iterator<T> {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstIterator>::to_glib_none(&this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstIterator>::to_glib_none(&this).0
as glib::ffi::gpointer,
)
}
}
#[doc(hidden)]
impl<T> glib::translate::GlibPtrDefault for Iterator<T> {
type GlibType = *mut gst_sys::GstIterator;
type GlibType = *mut ffi::GstIterator;
}
#[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>;
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)
}
fn to_glib_full(&self) -> *const gst_sys::GstIterator {
fn to_glib_full(&self) -> *const ffi::GstIterator {
unimplemented!()
}
}
#[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>;
#[inline]
fn to_glib_none_mut(
&'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)
}
}
#[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]
unsafe fn from_glib_none(ptr: *const gst_sys::GstIterator) -> Self {
unsafe fn from_glib_none(ptr: *const ffi::GstIterator) -> Self {
assert_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE
glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib::ffi::GFALSE
);
from_glib_full(gst_sys::gst_iterator_copy(ptr))
from_glib_full(ffi::gst_iterator_copy(ptr))
}
}
#[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]
unsafe fn from_glib_none(ptr: *mut gst_sys::GstIterator) -> Self {
unsafe fn from_glib_none(ptr: *mut ffi::GstIterator) -> Self {
assert_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE
glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib::ffi::GFALSE
);
from_glib_full(gst_sys::gst_iterator_copy(ptr))
from_glib_full(ffi::gst_iterator_copy(ptr))
}
}
#[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]
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_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE
glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib::ffi::GFALSE
);
Borrowed::new(Self {
iter: ptr::NonNull::new_unchecked(ptr),
@ -609,13 +604,13 @@ impl<T: StaticType> glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstIterator
}
#[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]
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_ne!(
gobject_sys::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib_sys::GFALSE
glib::gobject_ffi::g_type_is_a((*ptr).type_, T::static_type().to_glib()),
glib::ffi::GFALSE
);
Self {
iter: ptr::NonNull::new_unchecked(ptr),
@ -683,7 +678,7 @@ mod tests {
#[test]
fn test_vec() {
::init().unwrap();
crate::init().unwrap();
let vec = vec![1i32, 2, 3];
let mut it = Iterator::from_vec(vec);
@ -706,7 +701,7 @@ mod tests {
#[test]
fn test_filter() {
::init().unwrap();
crate::init().unwrap();
let vec = vec![1i32, 2, 3];
let mut it = Iterator::from_vec(vec).filter(|val| val % 2 == 1);
@ -720,7 +715,7 @@ mod tests {
#[test]
fn test_find() {
::init().unwrap();
crate::init().unwrap();
// Our find
let vec = vec![1i32, 2, 3];
@ -730,7 +725,7 @@ mod tests {
#[test]
fn test_foreach() {
::init().unwrap();
crate::init().unwrap();
let vec = vec![1i32, 2, 3];
let mut sum = 0;
@ -741,7 +736,7 @@ mod tests {
#[test]
fn test_fold() {
::init().unwrap();
crate::init().unwrap();
// Our fold
let vec = vec![1i32, 2, 3];
@ -754,7 +749,7 @@ mod tests {
#[test]
fn test_std() {
::init().unwrap();
crate::init().unwrap();
let mut it = Iterator::from_vec(vec![1i32, 2, 3]).into_iter();
assert_eq!(it.next(), Some(Ok(1)));
@ -765,7 +760,7 @@ mod tests {
#[test]
fn test_into_iter() {
::init().unwrap();
crate::init().unwrap();
let mut v = vec![1i32, 2, 3].into_iter();
for x in Iterator::from_vec(vec![1i32, 2, 3]) {
@ -776,14 +771,14 @@ mod tests {
#[test]
fn test_std_resync_collect() {
use prelude::*;
use crate::prelude::*;
use std::collections::BTreeSet;
::init().unwrap();
crate::init().unwrap();
let bin = ::Bin::new(None);
let id1 = ::ElementFactory::make("identity", None).unwrap();
let id2 = ::ElementFactory::make("identity", None).unwrap();
let bin = crate::Bin::new(None);
let id1 = crate::ElementFactory::make("identity", None).unwrap();
let id2 = crate::ElementFactory::make("identity", None).unwrap();
bin.add(&id1).unwrap();
@ -808,13 +803,13 @@ mod tests {
#[test]
fn test_std_resync_find() {
use prelude::*;
use crate::prelude::*;
::init().unwrap();
crate::init().unwrap();
let bin = ::Bin::new(None);
let id1 = ::ElementFactory::make("identity", None).unwrap();
let id2 = ::ElementFactory::make("identity", None).unwrap();
let bin = crate::Bin::new(None);
let id1 = crate::ElementFactory::make("identity", None).unwrap();
let id2 = crate::ElementFactory::make("identity", None).unwrap();
bin.add(&id1).unwrap();

View file

@ -8,54 +8,19 @@
#![cfg_attr(feature = "dox", feature(doc_cfg))]
#![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
pub use ffi;
#[doc(hidden)]
pub extern crate glib_sys;
pub use glib;
#[doc(hidden)]
pub extern crate gobject_sys;
#[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;
pub use paste;
use glib::translate::{from_glib, from_glib_full};
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.");
}
};
@ -70,39 +35,39 @@ macro_rules! skip_assert_initialized {
#[allow(clippy::match_same_arms)]
#[allow(clippy::type_complexity)]
mod auto;
pub use auto::functions::*;
pub use auto::*;
pub use crate::auto::functions::*;
pub use crate::auto::*;
#[macro_use]
mod log;
pub use log::*;
pub use crate::log::*;
#[macro_use]
mod error;
pub use error::*;
pub use crate::error::*;
#[macro_use]
pub mod miniobject;
pub mod message;
pub use message::{Message, MessageErrorDomain, MessageRef, MessageView};
pub use crate::message::{Message, MessageErrorDomain, MessageRef, MessageView};
mod value;
pub use value::*;
pub use crate::value::*;
#[cfg(feature = "ser_de")]
#[macro_use]
mod value_serde;
pub mod structure;
pub use structure::{Structure, StructureRef};
pub use crate::structure::{Structure, StructureRef};
#[cfg(feature = "ser_de")]
mod structure_serde;
pub mod caps;
pub use caps::{Caps, CapsRef};
pub use crate::caps::{Caps, CapsRef};
mod caps_features;
#[cfg(feature = "ser_de")]
mod caps_serde;
pub use caps_features::{
pub use crate::caps_features::{
CapsFeatures, CapsFeaturesRef, CAPS_FEATURES_MEMORY_SYSTEM_MEMORY,
CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
};
@ -110,7 +75,7 @@ pub use caps_features::{
mod caps_features_serde;
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,
TagListRef,
};
@ -120,42 +85,42 @@ mod tags_serde;
pub mod meta;
#[cfg(any(feature = "v1_16", feature = "dox"))]
#[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_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
pub use meta::ReferenceTimestampMeta;
pub use meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta};
pub use crate::meta::ReferenceTimestampMeta;
pub use crate::meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta};
pub mod buffer;
pub use buffer::{
pub use crate::buffer::{
Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA,
};
mod buffer_cursor;
pub use buffer_cursor::{BufferCursor, BufferRefCursor};
pub use crate::buffer_cursor::{BufferCursor, BufferRefCursor};
pub mod memory;
pub use memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
pub use crate::memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
#[cfg(feature = "ser_de")]
mod buffer_serde;
pub mod sample;
pub use sample::{Sample, SampleRef};
pub use crate::sample::{Sample, SampleRef};
#[cfg(feature = "ser_de")]
mod sample_serde;
pub mod bufferlist;
pub use bufferlist::{BufferList, BufferListRef};
pub use crate::bufferlist::{BufferList, BufferListRef};
#[cfg(feature = "ser_de")]
mod bufferlist_serde;
pub mod query;
pub use query::{Query, QueryRef, QueryView};
pub use crate::query::{Query, QueryRef, QueryView};
pub mod event;
pub use event::{Event, EventRef, EventView, GroupId, Seqnum};
pub use crate::event::{Event, EventRef, EventView, GroupId, Seqnum};
pub mod context;
pub use context::{Context, ContextRef};
pub use crate::context::{Context, ContextRef};
mod static_caps;
pub use static_caps::*;
pub use crate::static_caps::*;
mod static_pad_template;
pub use static_pad_template::*;
pub use crate::static_pad_template::*;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
@ -170,9 +135,9 @@ mod element;
mod bin;
mod allocator;
pub use allocator::AllocatorExtManual;
pub use crate::allocator::AllocatorExtManual;
mod pipeline;
pub use pipeline::GstPipelineExtManual;
pub use crate::pipeline::GstPipelineExtManual;
mod allocation_params;
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)
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(unix)] {
mod bus_unix;
#[cfg(feature = "dox")]
@ -203,31 +168,31 @@ mod date_time_serde;
mod device_monitor;
mod device_provider;
mod enums;
pub use enums::MessageType;
pub use crate::enums::MessageType;
mod ghost_pad;
mod gobject;
mod iterator;
mod object;
mod pad;
pub use pad::PadBuilder;
pub use crate::pad::PadBuilder;
mod control_binding;
mod control_source;
mod parse_context;
mod proxy_pad;
pub use proxy_pad::ProxyPadExtManual;
pub use crate::proxy_pad::ProxyPadExtManual;
mod tag_setter;
pub use bin::GstBinExtManual;
pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId};
pub use element::{
pub use crate::bin::GstBinExtManual;
pub use crate::element::{ElementExtManual, ElementMessageType, NotifyWatchId};
pub use crate::element::{
ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI,
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)
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(unix)] {
pub use bus_unix::UnixBusExtManual;
#[cfg(feature = "dox")]
@ -240,23 +205,23 @@ cfg_if! {
}
pub use self::iterator::{Iterator, IteratorError, IteratorImpl, StdIterator};
pub use child_proxy::ChildProxyExtManual;
pub use clock_time::ClockTime;
pub use device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId};
pub use device_provider::DeviceProviderExtManual;
pub use enums::{
pub use crate::child_proxy::ChildProxyExtManual;
pub use crate::clock_time::ClockTime;
pub use crate::device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId};
pub use crate::device_provider::DeviceProviderExtManual;
pub use crate::enums::{
ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess,
StateChangeError, StateChangeSuccess, TagError,
};
pub use gobject::GObjectExtManualGst;
pub use pad::{PadExtManual, PadGetRangeSuccess, PadProbeData, PadProbeId, PadProbeInfo};
pub use parse_context::ParseContext;
pub use crate::gobject::GObjectExtManualGst;
pub use crate::pad::{PadExtManual, PadGetRangeSuccess, PadProbeData, PadProbeId, PadProbeInfo};
pub use crate::parse_context::ParseContext;
mod plugin_feature;
pub use plugin_feature::PluginFeatureExtManual;
pub use tag_setter::TagSetterExtManual;
pub use crate::plugin_feature::PluginFeatureExtManual;
pub use crate::tag_setter::TagSetterExtManual;
mod plugin;
pub use plugin::GstPluginExtManual;
pub use crate::plugin::GstPluginExtManual;
#[cfg(any(feature = "v1_10", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))]
pub mod stream;
@ -265,43 +230,45 @@ pub mod stream;
pub mod stream_collection;
mod typefind;
pub use typefind::*;
pub use crate::typefind::*;
pub mod format;
pub use format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue};
pub use crate::format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue};
#[cfg(feature = "ser_de")]
mod format_serde;
mod segment;
pub use segment::*;
pub use crate::segment::*;
#[cfg(feature = "ser_de")]
mod segment_serde;
pub mod toc;
pub use toc::{Toc, TocEntry, TocEntryRef, TocRef};
pub use crate::toc::{Toc, TocEntry, TocEntryRef, TocRef};
#[cfg(feature = "ser_de")]
mod toc_serde;
mod clock;
pub use clock::{AtomicClockReturn, ClockExtManual, ClockId, PeriodicClockId, SingleShotClockId};
pub use crate::clock::{
AtomicClockReturn, ClockExtManual, ClockId, PeriodicClockId, SingleShotClockId,
};
mod buffer_pool;
pub use buffer_pool::*;
pub use crate::buffer_pool::*;
mod pad_template;
mod param_spec;
pub use param_spec::*;
pub use crate::param_spec::*;
pub mod functions;
pub use functions::*;
pub use crate::functions::*;
use std::ptr;
pub fn init() -> Result<(), glib::Error> {
unsafe {
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(),
&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
/// are running anymore and all GStreamer resources are released.
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 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 NSECOND_VAL: u64 = 1;
pub const FORMAT_PERCENT_MAX: u32 = gst_sys::GST_FORMAT_PERCENT_MAX as u32;
pub const FORMAT_PERCENT_SCALE: u32 = gst_sys::GST_FORMAT_PERCENT_SCALE as u32;
pub const FORMAT_PERCENT_MAX: u32 = ffi::GST_FORMAT_PERCENT_MAX 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
// can always "use gst::prelude::*" without getting conflicts
pub mod 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 bin::GstBinExtManual;
pub use element::{ElementClassExt, ElementExtManual};
pub use crate::allocator::AllocatorExtManual;
pub use crate::bin::GstBinExtManual;
pub use crate::element::{ElementClassExt, ElementExtManual};
// OS dependent Bus extensions (also import the other plateform trait for doc)
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(unix)] {
pub use bus_unix::UnixBusExtManual;
pub use crate::bus_unix::UnixBusExtManual;
#[cfg(feature = "dox")]
pub use bus_windows::WindowsBusExtManual;
pub use crate::bus_windows::WindowsBusExtManual;
} else {
pub use bus_windows::WindowsBusExtManual;
pub use crate::bus_windows::WindowsBusExtManual;
#[cfg(feature = "dox")]
pub use bus_unix::UnixBusExtManual;
pub use crate::bus_unix::UnixBusExtManual;
}
}
pub use buffer_pool::BufferPoolExtManual;
pub use child_proxy::ChildProxyExtManual;
pub use clock::ClockExtManual;
pub use device_monitor::DeviceMonitorExtManual;
pub use device_provider::DeviceProviderExtManual;
pub use gobject::GObjectExtManualGst;
pub use message::MessageErrorDomain;
pub use object::GstObjectExtManual;
pub use pad::PadExtManual;
pub use param_spec::GstParamSpecExt;
pub use pipeline::GstPipelineExtManual;
pub use plugin::GstPluginExtManual;
pub use plugin_feature::PluginFeatureExtManual;
pub use proxy_pad::ProxyPadExtManual;
pub use tag_setter::TagSetterExtManual;
pub use typefind::TypeFindImpl;
pub use value::GstValueExt;
pub use crate::buffer_pool::BufferPoolExtManual;
pub use crate::child_proxy::ChildProxyExtManual;
pub use crate::clock::ClockExtManual;
pub use crate::device_monitor::DeviceMonitorExtManual;
pub use crate::device_provider::DeviceProviderExtManual;
pub use crate::gobject::GObjectExtManualGst;
pub use crate::message::MessageErrorDomain;
pub use crate::object::GstObjectExtManual;
pub use crate::pad::PadExtManual;
pub use crate::param_spec::GstParamSpecExt;
pub use crate::pipeline::GstPipelineExtManual;
pub use crate::plugin::GstPluginExtManual;
pub use crate::plugin_feature::PluginFeatureExtManual;
pub use crate::proxy_pad::ProxyPadExtManual;
pub use crate::tag_setter::TagSetterExtManual;
pub use crate::typefind::TypeFindImpl;
pub use crate::value::GstValueExt;
pub use tags::{CustomTag, Tag};
pub use crate::tags::{CustomTag, Tag};
pub use muldiv::MulDiv;
pub use format::{FormattedValue, SpecificFormattedValue};
pub use crate::format::{FormattedValue, SpecificFormattedValue};
}
mod utils;

View file

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

View file

@ -13,28 +13,25 @@ use std::ops;
use std::ptr;
use std::slice;
use gst_sys;
use glib;
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlibPtr};
use AllocationParams;
use Allocator;
use MemoryFlags;
use crate::AllocationParams;
use crate::Allocator;
use crate::MemoryFlags;
gst_define_mini_object_wrapper!(Memory, MemoryRef, gst_sys::GstMemory, || {
gst_sys::gst_memory_get_type()
gst_define_mini_object_wrapper!(Memory, MemoryRef, ffi::GstMemory, || {
ffi::gst_memory_get_type()
});
pub struct MemoryMap<'a, T> {
memory: &'a MemoryRef,
map_info: gst_sys::GstMapInfo,
map_info: ffi::GstMapInfo,
phantom: PhantomData<T>,
}
pub struct MappedMemory<T> {
memory: Option<Memory>,
map_info: gst_sys::GstMapInfo,
map_info: ffi::GstMapInfo,
phantom: PhantomData<T>,
}
@ -63,7 +60,7 @@ pub enum Readable {}
pub enum Writable {}
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);
drop(slice);
}
@ -71,7 +68,7 @@ impl Memory {
pub fn with_size(size: usize) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_sys::gst_allocator_alloc(
from_glib_full(ffi::gst_allocator_alloc(
ptr::null_mut(),
size,
ptr::null_mut(),
@ -82,7 +79,7 @@ impl Memory {
pub fn with_size_and_params(size: usize, params: &AllocationParams) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_sys::gst_allocator_alloc(
from_glib_full(ffi::gst_allocator_alloc(
ptr::null_mut(),
size,
params.as_ptr() as *mut _,
@ -99,13 +96,13 @@ impl Memory {
(slice.len(), slice.as_ptr())
};
let user_data = Box::into_raw(b);
from_glib_full(gst_sys::gst_memory_new_wrapped(
gst_sys::GST_MEMORY_FLAG_READONLY,
data as glib_sys::gpointer,
from_glib_full(ffi::gst_memory_new_wrapped(
ffi::GST_MEMORY_FLAG_READONLY,
data as glib::ffi::gpointer,
size,
0,
size,
user_data as glib_sys::gpointer,
user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>),
))
}
@ -121,13 +118,13 @@ impl Memory {
(slice.len(), slice.as_mut_ptr())
};
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,
data as glib_sys::gpointer,
data as glib::ffi::gpointer,
size,
0,
size,
user_data as glib_sys::gpointer,
user_data as glib::ffi::gpointer,
Some(Self::drop_box::<T>),
))
}
@ -136,10 +133,10 @@ impl Memory {
pub fn into_mapped_memory_readable(self) -> Result<MappedMemory<Readable>, Self> {
unsafe {
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(),
map_info.as_mut_ptr(),
gst_sys::GST_MAP_READ,
ffi::GST_MAP_READ,
));
if res {
Ok(MappedMemory {
@ -156,10 +153,10 @@ impl Memory {
pub fn into_mapped_memory_writable(self) -> Result<MappedMemory<Writable>, Self> {
unsafe {
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(),
map_info.as_mut_ptr(),
gst_sys::GST_MAP_READWRITE,
ffi::GST_MAP_READWRITE,
));
if res {
Ok(MappedMemory {
@ -216,7 +213,7 @@ impl MemoryRef {
};
assert!(offset + pos_sz < (self.get_maxsize() as isize));
unsafe {
from_glib_full(gst_sys::gst_memory_copy(
from_glib_full(ffi::gst_memory_copy(
self.as_mut_ptr(),
offset,
match size {
@ -230,7 +227,7 @@ impl MemoryRef {
pub fn is_span(&self, mem2: &MemoryRef) -> Option<usize> {
unsafe {
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(),
mem2.as_mut_ptr(),
offset.as_mut_ptr(),
@ -245,7 +242,7 @@ impl MemoryRef {
pub fn is_type(&self, mem_type: &str) -> bool {
unsafe {
from_glib(gst_sys::gst_memory_is_type(
from_glib(ffi::gst_memory_is_type(
self.as_mut_ptr(),
mem_type.to_glib_none().0,
))
@ -255,19 +252,16 @@ impl MemoryRef {
pub fn map_readable(&self) -> Result<MemoryMap<Readable>, glib::BoolError> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_memory_map(
self.as_mut_ptr(),
map_info.as_mut_ptr(),
gst_sys::GST_MAP_READ,
);
if res == glib_sys::GTRUE {
let res =
ffi::gst_memory_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
if res == glib::ffi::GTRUE {
Ok(MemoryMap {
memory: self,
map_info: map_info.assume_init(),
phantom: PhantomData,
})
} 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> {
unsafe {
let mut map_info = mem::MaybeUninit::zeroed();
let res = gst_sys::gst_memory_map(
let res = ffi::gst_memory_map(
self.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 {
memory: self,
map_info: map_info.assume_init(),
phantom: PhantomData,
})
} 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));
unsafe {
from_glib_full(gst_sys::gst_memory_share(
from_glib_full(ffi::gst_memory_share(
self.as_ptr() as *mut _,
offset,
match size {
@ -312,7 +306,7 @@ impl MemoryRef {
pub fn resize(&mut self, offset: isize, size: usize) {
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 {
@ -385,7 +379,7 @@ impl<'a, T> Eq for MemoryMap<'a, T> {}
impl<'a, T> Drop for MemoryMap<'a, T> {
fn drop(&mut self) {
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 {
let memory = self.memory.take().unwrap();
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
@ -452,7 +446,7 @@ impl<T> Drop for MappedMemory<T> {
fn drop(&mut self) {
if let Some(ref memory) = self.memory {
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 {
#[test]
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())));
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)));
let mem = ::Memory::from_slice(vec![0; 64]);
let mem = crate::Memory::from_slice(vec![0; 64]);
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::ops;
use Buffer;
use BufferRef;
use crate::Buffer;
use crate::BufferRef;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use Caps;
use crate::Caps;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use CapsRef;
use crate::CapsRef;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use ClockTime;
use crate::ClockTime;
use glib;
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
use glib::translate::ToGlib;
use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr};
use glib_sys;
use gst_sys;
pub unsafe trait MetaAPI: Sync + Send + Sized {
type GstType;
@ -42,7 +39,7 @@ pub unsafe trait MetaAPI: Sync + Send + Sized {
if meta_api != glib::Type::Invalid {
assert_eq!(
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 {
assert_eq!(
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> {
pub fn get_api(&self) -> glib::Type {
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;
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")))]
pub fn get_seqnum(&self) -> MetaSeqnum {
unsafe {
let meta = self.meta as *const _ as *const gst_sys::GstMeta;
MetaSeqnum(gst_sys::gst_meta_get_seqnum(meta))
let meta = self.meta as *const _ as *const ffi::GstMeta;
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> {
pub fn get_api(&self) -> glib::Type {
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;
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")))]
pub fn get_seqnum(&self) -> u64 {
unsafe {
let meta = self.meta as *const _ as *const gst_sys::GstMeta;
gst_sys::gst_meta_get_seqnum(meta)
let meta = self.meta as *const _ as *const ffi::GstMeta;
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> {
pub fn remove(mut self) {
unsafe {
let res = gst_sys::gst_buffer_remove_meta(
let res = ffi::gst_buffer_remove_meta(
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)]
pub struct Meta(gst_sys::GstMeta);
pub struct Meta(ffi::GstMeta);
unsafe impl Send for Meta {}
unsafe impl Sync for Meta {}
@ -247,7 +244,7 @@ impl Meta {
}
unsafe impl MetaAPI for Meta {
type GstType = gst_sys::GstMeta;
type GstType = ffi::GstMeta;
fn get_meta_api() -> glib::Type {
glib::Type::Invalid
@ -263,7 +260,7 @@ impl fmt::Debug for Meta {
}
#[repr(transparent)]
pub struct ParentBufferMeta(gst_sys::GstParentBufferMeta);
pub struct ParentBufferMeta(ffi::GstParentBufferMeta);
unsafe impl Send 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> {
skip_assert_initialized!();
unsafe {
let meta = gst_sys::gst_buffer_add_parent_buffer_meta(
let meta = ffi::gst_buffer_add_parent_buffer_meta(
buffer.as_mut_ptr(),
parent.to_glib_none().0,
);
@ -291,10 +288,10 @@ impl ParentBufferMeta {
}
unsafe impl MetaAPI for ParentBufferMeta {
type GstType = gst_sys::GstParentBufferMeta;
type GstType = ffi::GstParentBufferMeta;
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)]
pub struct ProtectionMeta(gst_sys::GstProtectionMeta);
pub struct ProtectionMeta(ffi::GstProtectionMeta);
unsafe impl Send for ProtectionMeta {}
unsafe impl Sync for 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!();
unsafe {
let meta =
gst_sys::gst_buffer_add_protection_meta(buffer.as_mut_ptr(), info.into_ptr());
let meta = ffi::gst_buffer_add_protection_meta(buffer.as_mut_ptr(), info.into_ptr());
Self::from_mut_ptr(buffer, meta)
}
}
pub fn get_info(&self) -> &::StructureRef {
unsafe { ::StructureRef::from_glib_borrow(self.0.info) }
pub fn get_info(&self) -> &crate::StructureRef {
unsafe { crate::StructureRef::from_glib_borrow(self.0.info) }
}
pub fn get_info_mut(&mut self) -> &mut ::StructureRef {
unsafe { ::StructureRef::from_glib_borrow_mut(self.0.info) }
pub fn get_info_mut(&mut self) -> &mut crate::StructureRef {
unsafe { crate::StructureRef::from_glib_borrow_mut(self.0.info) }
}
}
unsafe impl MetaAPI for ProtectionMeta {
type GstType = gst_sys::GstProtectionMeta;
type GstType = ffi::GstProtectionMeta;
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_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
#[repr(transparent)]
pub struct ReferenceTimestampMeta(gst_sys::GstReferenceTimestampMeta);
pub struct ReferenceTimestampMeta(ffi::GstReferenceTimestampMeta);
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
@ -371,7 +367,7 @@ impl ReferenceTimestampMeta {
) -> MetaRefMut<'a, Self, Standalone> {
skip_assert_initialized!();
unsafe {
let meta = gst_sys::gst_buffer_add_reference_timestamp_meta(
let meta = ffi::gst_buffer_add_reference_timestamp_meta(
buffer.as_mut_ptr(),
reference.to_glib_none().0,
timestamp.to_glib(),
@ -402,10 +398,10 @@ impl ReferenceTimestampMeta {
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
unsafe impl MetaAPI for ReferenceTimestampMeta {
type GstType = gst_sys::GstReferenceTimestampMeta;
type GstType = ffi::GstReferenceTimestampMeta;
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]
fn test_add_get_iterate_meta() {
::init().unwrap();
crate::init().unwrap();
let mut buffer = ::Buffer::new();
let parent = ::Buffer::new();
let mut buffer = crate::Buffer::new();
let parent = crate::Buffer::new();
{
let meta = ParentBufferMeta::add(buffer.get_mut().unwrap(), &parent);
unsafe {

View file

@ -8,47 +8,47 @@
#[macro_export]
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 {
obj: ::std::ptr::NonNull<$ref_name>,
obj: std::ptr::NonNull<$ref_name>,
}
#[repr(transparent)]
pub struct $ref_name($gst_sys_name);
pub struct $ref_name($ffi_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!();
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 {
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!();
assert!(!ptr.is_null());
$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!();
assert!(!ptr.is_null());
$crate::glib::translate::Borrowed::new($name {
obj: ::std::ptr::NonNull::new_unchecked(ptr as *mut $gst_sys_name as *mut $ref_name),
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());
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 {
@ -57,10 +57,10 @@ macro_rules! gst_define_mini_object_wrapper(
return self.obj.as_mut();
}
let ptr = $crate::gst_sys::gst_mini_object_make_writable(
self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject
let ptr = $crate::ffi::gst_mini_object_make_writable(
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());
self.obj.as_mut()
@ -77,14 +77,14 @@ macro_rules! gst_define_mini_object_wrapper(
pub fn is_writable(&self) -> bool {
unsafe {
$crate::glib::translate::from_glib($crate::gst_sys::gst_mini_object_is_writable(
self.as_ptr() as *const $crate::gst_sys::GstMiniObject
$crate::glib::translate::from_glib($crate::ffi::gst_mini_object_is_writable(
self.as_ptr() as *const $crate::ffi::GstMiniObject
))
}
}
pub unsafe fn into_ptr(self) -> *mut $gst_sys_name {
let s = ::std::mem::ManuallyDrop::new(self);
pub unsafe fn into_ptr(self) -> *mut $ffi_name {
let s = std::mem::ManuallyDrop::new(self);
s.as_mut_ptr()
}
}
@ -98,12 +98,12 @@ macro_rules! gst_define_mini_object_wrapper(
impl Drop for $name {
fn drop(&mut self) {
unsafe {
$crate::gst_sys::gst_mini_object_unref(self.as_mut_ptr() as *mut $crate::gst_sys::GstMiniObject);
$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;
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 {
&*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;
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)
}
fn to_glib_full(&self) -> *const $gst_sys_name {
fn to_glib_full(&self) -> *const $ffi_name {
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()
}
}
}
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;
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)
}
fn to_glib_full(&self) -> *mut $gst_sys_name {
fn to_glib_full(&self) -> *mut $ffi_name {
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()
}
}
}
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;
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();
$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)]
type Storage = (
Vec<$crate::glib::translate::Stash<'a, *mut $gst_sys_name, Self>>,
Option<Vec<*mut $gst_sys_name>>,
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, Self>>,
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!();
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();
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!();
let v: Vec<_> = t.iter().map(|s| $crate::glib::translate::ToGlibPtr::to_glib_none(s)).collect();
let v_ptr = unsafe {
let v_ptr = $crate::glib_sys::g_malloc0(::std::mem::size_of::<*mut $gst_sys_name>() * t.len() + 1)
as *mut *mut $gst_sys_name;
let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
as *mut *mut $ffi_name;
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
@ -202,14 +202,14 @@ macro_rules! gst_define_mini_object_wrapper(
(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!();
unsafe {
let v_ptr = $crate::glib_sys::g_malloc0(::std::mem::size_of::<*mut $gst_sys_name>() * t.len() + 1)
as *mut *mut $gst_sys_name;
let v_ptr = $crate::glib::ffi::g_malloc0(std::mem::size_of::<*mut $ffi_name>() * t.len() + 1)
as *mut *mut $ffi_name;
for (i, s) in t.iter().enumerate() {
::std::ptr::write(v_ptr.add(i), $crate::glib::translate::ToGlibPtr::to_glib_full(s));
std::ptr::write(v_ptr.add(i), $crate::glib::translate::ToGlibPtr::to_glib_full(s));
}
v_ptr
@ -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
{
#[allow(clippy::type_complexity)]
type Storage = (
Vec<$crate::glib::translate::Stash<'a, *mut $gst_sys_name, $name>>,
Option<Vec<*mut $gst_sys_name>>,
Vec<$crate::glib::translate::Stash<'a, *mut $ffi_name, $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!();
let (ptr, stash) =
$crate::glib::translate::ToGlibContainerFromSlice::<'a, *mut *mut $gst_sys_name>::to_glib_none_from_slice(t);
(ptr as *const *mut $gst_sys_name, stash)
$crate::glib::translate::ToGlibContainerFromSlice::<'a, *mut *mut $ffi_name>::to_glib_none_from_slice(t);
(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!();
// Can't have consumer free a *const pointer
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!();
// Can't have consumer free a *const pointer
unimplemented!()
}
}
impl $crate::glib::translate::FromGlibPtrNone<*const $gst_sys_name> for $name {
unsafe fn from_glib_none(ptr: *const $gst_sys_name) -> Self {
impl $crate::glib::translate::FromGlibPtrNone<*const $ffi_name> for $name {
unsafe fn from_glib_none(ptr: *const $ffi_name) -> Self {
Self::from_glib_none(ptr)
}
}
impl $crate::glib::translate::FromGlibPtrNone<*mut $gst_sys_name> for $name {
unsafe fn from_glib_none(ptr: *mut $gst_sys_name) -> Self {
impl $crate::glib::translate::FromGlibPtrNone<*mut $ffi_name> for $name {
unsafe fn from_glib_none(ptr: *mut $ffi_name) -> Self {
Self::from_glib_none(ptr)
}
}
impl $crate::glib::translate::FromGlibPtrFull<*const $gst_sys_name> for $name {
unsafe fn from_glib_full(ptr: *const $gst_sys_name) -> Self {
impl $crate::glib::translate::FromGlibPtrFull<*const $ffi_name> for $name {
unsafe fn from_glib_full(ptr: *const $ffi_name) -> Self {
Self::from_glib_full(ptr)
}
}
impl $crate::glib::translate::FromGlibPtrFull<*mut $gst_sys_name> for $name {
unsafe fn from_glib_full(ptr: *mut $gst_sys_name) -> Self {
impl $crate::glib::translate::FromGlibPtrFull<*mut $ffi_name> for $name {
unsafe fn from_glib_full(ptr: *mut $ffi_name) -> Self {
Self::from_glib_full(ptr)
}
}
impl $crate::glib::translate::FromGlibPtrBorrow<*const $gst_sys_name> for $name {
unsafe fn from_glib_borrow(ptr: *const $gst_sys_name) -> $crate::glib::translate::Borrowed<Self> {
impl $crate::glib::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
Self::from_glib_borrow(ptr)
}
}
impl $crate::glib::translate::FromGlibPtrBorrow<*mut $gst_sys_name> for $name {
unsafe fn from_glib_borrow(ptr: *mut $gst_sys_name) -> $crate::glib::translate::Borrowed<Self> {
impl $crate::glib::translate::FromGlibPtrBorrow<*mut $ffi_name> for $name {
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> $crate::glib::translate::Borrowed<Self> {
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
{
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() {
return Vec::new();
}
let mut res = Vec::with_capacity(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
}
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);
$crate::glib_sys::g_free(ptr as *mut _);
$crate::glib::ffi::g_free(ptr as *mut _);
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() {
return Vec::new();
}
let mut res = Vec::with_capacity(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
}
}
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
{
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))
}
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))
}
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))
}
}
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
{
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)
}
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
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
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 _)
}
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
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
unimplemented!()
}
@ -372,59 +372,59 @@ macro_rules! gst_define_mini_object_wrapper(
for $name
{
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);
$crate::glib::translate::from_glib_none(ptr as *const $gst_sys_name)
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 $ffi_name)
}
}
impl $crate::glib::value::SetValue for $name {
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 {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
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 {
$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 {
type GlibType = *mut $gst_sys_name;
type GlibType = *mut $ffi_name;
}
impl $ref_name {
pub unsafe fn as_ptr(&self) -> *const $gst_sys_name {
self as *const Self as *const $gst_sys_name
pub unsafe fn as_ptr(&self) -> *const $ffi_name {
self as *const Self as *const $ffi_name
}
pub unsafe fn as_mut_ptr(&self) -> *mut $gst_sys_name {
self as *const Self as *mut $gst_sys_name
pub unsafe fn as_mut_ptr(&self) -> *mut $ffi_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());
&*(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_ne!(
$crate::gst_sys::gst_mini_object_is_writable(ptr as *mut $crate::gst_sys::GstMiniObject),
$crate::glib_sys::GFALSE
$crate::ffi::gst_mini_object_is_writable(ptr as *mut $crate::ffi::GstMiniObject),
$crate::glib::ffi::GFALSE
);
&mut *(ptr as *mut Self)
}
pub fn copy(&self) -> $name {
unsafe {
$name::from_glib_full($crate::gst_sys::gst_mini_object_copy(
self.as_ptr() as *const $crate::gst_sys::GstMiniObject
) as *const $gst_sys_name)
$name::from_glib_full($crate::ffi::gst_mini_object_copy(
self.as_ptr() as *const $crate::ffi::GstMiniObject
) as *const $ffi_name)
}
}
}
@ -436,14 +436,14 @@ macro_rules! gst_define_mini_object_wrapper(
}
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>
for &'a $ref_name
{
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() {
None
} else {

View file

@ -6,19 +6,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use glib;
use glib::object::{Cast, ObjectExt};
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::IsA;
use gobject_sys;
use ClockTime;
use ObjectFlags;
use crate::ClockTime;
use crate::ObjectFlags;
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,
name: Option<&str>,
f: F,
@ -39,8 +36,10 @@ pub trait GstObjectExtManual: 'static {
) -> Result<(), glib::error::BoolError>;
}
impl<O: IsA<::Object>> GstObjectExtManual for O {
fn connect_deep_notify<F: Fn(&Self, &::Object, &glib::ParamSpec) + Send + Sync + 'static>(
impl<O: IsA<crate::Object>> GstObjectExtManual for O {
fn connect_deep_notify<
F: Fn(&Self, &crate::Object, &glib::ParamSpec) + Send + Sync + 'static,
>(
&self,
name: Option<&str>,
f: F,
@ -52,7 +51,7 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
};
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| {
// 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
let obj: O = unsafe {
values[0]
.get::<::Object>()
.get::<crate::Object>()
.unwrap_or_else(|err| {
panic!("Object signal \"deep-notify\": values[0]: {}", err)
})
.expect("Object signal \"deep-notify\": values[0] not defined")
.unsafe_cast()
};
let prop_obj: ::Object = values[1]
let prop_obj: crate::Object = values[1]
.get()
.unwrap_or_else(|err| panic!("Object signal \"deep-notify\": values[1]: {}", err))
.expect("Object signal \"deep-notify\": values[1] not defined");
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)
};
@ -86,24 +85,24 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
fn set_object_flags(&self, flags: ObjectFlags) {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags |= flags.to_glib();
}
}
fn unset_object_flags(&self, flags: ObjectFlags) {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
(*ptr).flags &= !flags.to_glib();
}
}
fn get_object_flags(&self) -> ObjectFlags {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags)
}
}
@ -117,14 +116,14 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
) -> Result<(), glib::error::BoolError> {
let n_values = values.len() as u32;
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_object_get_g_value_array(
glib::glib_result_from_gboolean!(
ffi::gst_object_get_g_value_array(
self.as_ref().to_glib_none().0,
property_name.to_glib_none().0,
timestamp.to_glib(),
interval.to_glib(),
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"
)
@ -135,15 +134,15 @@ impl<O: IsA<::Object>> GstObjectExtManual for O {
#[cfg(test)]
mod tests {
use super::*;
use prelude::*;
use crate::prelude::*;
use std::sync::{Arc, Mutex};
#[test]
fn test_deep_notify() {
::init().unwrap();
crate::init().unwrap();
let bin = ::Bin::new(None);
let identity = ::ElementFactory::make("identity", Some("id")).unwrap();
let bin = crate::Bin::new(None);
let identity = crate::ElementFactory::make("identity", Some("id")).unwrap();
bin.add(&identity).unwrap();
let notify = Arc::new(Mutex::new(None));
@ -155,7 +154,7 @@ mod tests {
identity.set_property("silent", &false).unwrap();
assert_eq!(
*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
// 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_attr(feature = "dox", doc(cfg(feature = "v1_14")))]
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 {
#[cfg(any(feature = "v1_14", feature = "dox"))]
@ -31,12 +24,12 @@ impl PadTemplate {
assert_initialized_main_thread!();
unsafe {
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),
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
// except according to those terms.
use glib;
use glib::translate::*;
use gst_sys;
pub trait GstParamSpecExt {
#[cfg(any(feature = "v1_14", feature = "dox"))]
@ -25,9 +23,9 @@ pub trait GstParamSpecExt {
name: &str,
nick: &str,
blurb: &str,
min: ::Fraction,
max: ::Fraction,
default: ::Fraction,
min: crate::Fraction,
max: crate::Fraction,
default: crate::Fraction,
flags: glib::ParamFlags,
) -> Self;
}
@ -44,7 +42,7 @@ impl GstParamSpecExt for glib::ParamSpec {
) -> glib::ParamSpec {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_sys::gst_param_spec_array(
from_glib_full(ffi::gst_param_spec_array(
name.to_glib_none().0,
nick.to_glib_none().0,
blurb.to_glib_none().0,
@ -58,14 +56,14 @@ impl GstParamSpecExt for glib::ParamSpec {
name: &str,
nick: &str,
blurb: &str,
min: ::Fraction,
max: ::Fraction,
default: ::Fraction,
min: crate::Fraction,
max: crate::Fraction,
default: crate::Fraction,
flags: glib::ParamFlags,
) -> glib::ParamSpec {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_sys::gst_param_spec_fraction(
from_glib_full(ffi::gst_param_spec_fraction(
name.to_glib_none().0,
nick.to_glib_none().0,
blurb.to_glib_none().0,
@ -83,12 +81,11 @@ impl GstParamSpecExt for glib::ParamSpec {
#[cfg(test)]
mod tests {
use glib;
use prelude::*;
use crate::prelude::*;
#[test]
fn test_trait() {
::init().unwrap();
crate::init().unwrap();
let _pspec = glib::ParamSpec::fraction(
"foo",

View file

@ -7,21 +7,19 @@
// except according to those terms.
use glib::translate::*;
use gobject_sys;
use gst_sys;
glib_wrapper! {
glib::glib_wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ParseContext(Boxed<gst_sys::GstParseContext>);
pub struct ParseContext(Boxed<ffi::GstParseContext>);
match fn {
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| {
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 {
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> {
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),
))
}

View file

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

View file

@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use gst_sys;
use Plugin;
use PluginFlags;
use Structure;
use StructureRef;
use crate::Plugin;
use crate::PluginFlags;
use crate::Structure;
use crate::StructureRef;
use glib::translate::*;
use glib::IsA;
@ -18,7 +17,7 @@ use glib::IsA;
impl Plugin {
pub fn get_cache_data(&self) -> Option<&StructureRef> {
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() {
None
} else {
@ -29,7 +28,7 @@ impl Plugin {
pub fn set_cache_data(&self, cache_data: Structure) {
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;
}
impl<O: IsA<::Plugin>> GstPluginExtManual for O {
impl<O: IsA<crate::Plugin>> GstPluginExtManual for O {
fn get_plugin_flags(&self) -> PluginFlags {
unsafe {
let ptr: *mut gst_sys::GstObject = self.as_ptr() as *mut _;
let _guard = ::utils::MutexGuard::lock(&(*ptr).lock);
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = crate::utils::MutexGuard::lock(&(*ptr).lock);
from_glib((*ptr).flags)
}
}
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
// except according to those terms.
use PluginFeature;
use Rank;
use crate::PluginFeature;
use crate::Rank;
use glib::object::IsA;
use glib::translate::{from_glib, ToGlib, ToGlibPtr};
@ -20,17 +20,14 @@ pub trait PluginFeatureExtManual: 'static {
impl<O: IsA<PluginFeature>> PluginFeatureExtManual for O {
fn get_rank(&self) -> Rank {
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)
}
}
fn set_rank(&self, rank: Rank) {
unsafe {
gst_sys::gst_plugin_feature_set_rank(
self.as_ref().to_glib_none().0,
rank.to_glib() as u32,
);
ffi::gst_plugin_feature_set_rank(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
// except according to those terms.
use crate::PromiseResult;
use crate::Structure;
use crate::StructureRef;
use glib::translate::*;
use glib_sys;
use gst_sys;
use PromiseResult;
use Structure;
use StructureRef;
use std::marker::PhantomData;
use std::pin::Pin;
use std::ptr;
use std::task::{Context, Poll};
glib_wrapper! {
glib::glib_wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Promise(Shared<gst_sys::GstPromise>);
pub struct Promise(Shared<ffi::GstPromise>);
match fn {
ref => |ptr| gst_sys::gst_mini_object_ref(ptr as *mut _),
unref => |ptr| gst_sys::gst_mini_object_unref(ptr as *mut _),
get_type => || gst_sys::gst_promise_get_type(),
ref => |ptr| ffi::gst_mini_object_ref(ptr as *mut _),
unref => |ptr| ffi::gst_mini_object_unref(ptr as *mut _),
get_type => || ffi::gst_promise_get_type(),
}
}
@ -39,7 +37,7 @@ pub enum PromiseError {
impl Promise {
pub fn new() -> Promise {
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
@ -52,8 +50,8 @@ impl Promise {
unsafe extern "C" fn trampoline<
F: FnOnce(Result<Option<&StructureRef>, PromiseError>) + Send + 'static,
>(
promise: *mut gst_sys::GstPromise,
user_data: glib_sys::gpointer,
promise: *mut ffi::GstPromise,
user_data: glib::ffi::gpointer,
) {
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap();
@ -76,13 +74,13 @@ impl Promise {
unsafe extern "C" fn free_user_data<
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 _);
}
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>),
Box::into_raw(user_data) as *mut _,
Some(free_user_data::<F>),
@ -107,13 +105,13 @@ impl Promise {
pub fn expire(&self) {
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> {
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() {
None
} else {
@ -124,13 +122,13 @@ impl Promise {
pub fn interrupt(&self) {
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>) {
unsafe {
gst_sys::gst_promise_reply(
ffi::gst_promise_reply(
self.to_glib_none().0,
s.map(|s| s.into_ptr()).unwrap_or(ptr::null_mut()),
);
@ -138,7 +136,7 @@ impl Promise {
}
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(())) => {
let res = match self.0.wait() {
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() {
Ok(None)
} else {
@ -196,7 +194,7 @@ mod tests {
#[test]
fn test_change_func() {
::init().unwrap();
crate::init().unwrap();
let (sender, receiver) = channel();
let promise = Promise::with_change_func(move |res| {

View file

@ -6,21 +6,19 @@
// option. This file may not be copied, modified, or distributed
// 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 Buffer;
use BufferList;
use FlowError;
use FlowReturn;
use FlowSuccess;
use Object;
use Pad;
use ProxyPad;
use glib::object::IsA;
use glib::translate::{from_glib, from_glib_full, ToGlibPtr};
use gst_sys;
pub trait ProxyPadExtManual: 'static {
fn chain_default<P: IsA<Object>>(
&self,
@ -44,7 +42,7 @@ pub trait ProxyPadExtManual: 'static {
fn iterate_internal_links_default<P: IsA<Object>>(
&self,
parent: Option<&P>,
) -> Option<::Iterator<Pad>>;
) -> Option<crate::Iterator<Pad>>;
}
impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
@ -55,8 +53,8 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!();
let ret: FlowReturn = unsafe {
from_glib(gst_sys::gst_proxy_pad_chain_default(
self.as_ptr() as *mut gst_sys::GstPad,
from_glib(ffi::gst_proxy_pad_chain_default(
self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0,
buffer.into_ptr(),
))
@ -71,8 +69,8 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!();
let ret: FlowReturn = unsafe {
from_glib(gst_sys::gst_proxy_pad_chain_list_default(
self.as_ptr() as *mut gst_sys::GstPad,
from_glib(ffi::gst_proxy_pad_chain_list_default(
self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0,
list.into_ptr(),
))
@ -89,8 +87,8 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
skip_assert_initialized!();
unsafe {
let mut buffer = ptr::null_mut();
let ret: FlowReturn = from_glib(gst_sys::gst_proxy_pad_getrange_default(
self.as_ptr() as *mut gst_sys::GstPad,
let ret: FlowReturn = from_glib(ffi::gst_proxy_pad_getrange_default(
self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0,
offset,
size,
@ -103,11 +101,11 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
fn iterate_internal_links_default<P: IsA<Object>>(
&self,
parent: Option<&P>,
) -> Option<::Iterator<Pad>> {
) -> Option<crate::Iterator<Pad>> {
skip_assert_initialized!();
unsafe {
from_glib_full(gst_sys::gst_proxy_pad_iterate_internal_links_default(
self.as_ptr() as *mut gst_sys::GstPad,
from_glib_full(ffi::gst_proxy_pad_iterate_internal_links_default(
self.as_ptr() as *mut ffi::GstPad,
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::ptr;
use gst_sys;
use glib;
use glib::translate::{from_glib_full, from_glib_none, mut_override, ToGlibPtr};
use Buffer;
use BufferList;
use BufferListRef;
use BufferRef;
use Caps;
use CapsRef;
use FormattedSegment;
use FormattedValue;
use Segment;
use Structure;
use StructureRef;
use crate::Buffer;
use crate::BufferList;
use crate::BufferListRef;
use crate::BufferRef;
use crate::Caps;
use crate::CapsRef;
use crate::FormattedSegment;
use crate::FormattedValue;
use crate::Segment;
use crate::Structure;
use crate::StructureRef;
gst_define_mini_object_wrapper!(Sample, SampleRef, gst_sys::GstSample, || {
gst_sys::gst_sample_get_type()
gst_define_mini_object_wrapper!(Sample, SampleRef, ffi::GstSample, || {
ffi::gst_sample_get_type()
});
#[derive(Debug, Clone)]
@ -83,7 +80,7 @@ impl<'a> SampleBuilder<'a> {
unsafe {
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.caps.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 {
gst_sys::gst_sample_set_buffer_list(
ffi::gst_sample_set_buffer_list(
sample.to_glib_none().0,
buffer_list.to_glib_none().0,
);
@ -117,7 +114,7 @@ impl Sample {
impl SampleRef {
pub fn get_buffer(&self) -> Option<&BufferRef> {
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() {
None
} else {
@ -135,7 +132,7 @@ impl SampleRef {
pub fn get_buffer_list(&self) -> Option<&BufferListRef> {
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() {
None
} else {
@ -153,7 +150,7 @@ impl SampleRef {
pub fn get_caps(&self) -> Option<&CapsRef> {
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() {
None
} else {
@ -167,12 +164,12 @@ impl SampleRef {
}
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> {
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() {
None
} else {
@ -184,34 +181,32 @@ impl SampleRef {
#[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
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_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_buffer_list(&mut self, buffer_list: Option<&BufferList>) {
unsafe {
gst_sys::gst_sample_set_buffer_list(self.as_mut_ptr(), buffer_list.to_glib_none().0)
}
unsafe { ffi::gst_sample_set_buffer_list(self.as_mut_ptr(), buffer_list.to_glib_none().0) }
}
#[cfg(any(feature = "v1_16", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
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_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
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_attr(feature = "dox", doc(cfg(feature = "v1_16")))]
pub fn set_info(&mut self, info: Option<Structure>) {
unsafe {
gst_sys::gst_sample_set_info(
ffi::gst_sample_set_info(
self.as_mut_ptr(),
info.map(|i| i.into_ptr()).unwrap_or(ptr::null_mut()),
);
@ -240,10 +235,10 @@ impl fmt::Debug for SampleRef {
mod tests {
#[test]
fn test_sample_new_with_info() {
use Sample;
use Structure;
use crate::Sample;
use crate::Structure;
::init().unwrap();
crate::init().unwrap();
let info = Structure::builder("sample.info")
.field("f3", &123i32)

View file

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

View file

@ -6,29 +6,25 @@
// option. This file may not be copied, modified, or distributed
// 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_sys;
use gobject_sys;
use gst_sys;
use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::ptr;
use Format;
use FormattedValue;
use GenericFormattedValue;
use SeekFlags;
use SeekType;
pub type Segment = FormattedSegment<GenericFormattedValue>;
#[repr(transparent)]
pub struct FormattedSegment<T: FormattedValue>(gst_sys::GstSegment, PhantomData<T>);
pub struct FormattedSegment<T: FormattedValue>(ffi::GstSegment, PhantomData<T>);
impl Segment {
pub fn reset_with_format(&mut self, format: Format) {
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!();
let segment = unsafe {
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()
};
FormattedSegment(segment, PhantomData)
@ -96,7 +92,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
pub fn reset(&mut self) {
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 {
let mut clip_start = 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,
start.get_format().to_glib(),
start.to_raw_value() as u64,
@ -152,7 +148,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
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,
rate,
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> {
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_segment_offset_running_time(
glib::glib_result_from_gboolean!(
ffi::gst_segment_offset_running_time(
&mut self.0,
self.get_format().to_glib(),
offset,
@ -194,7 +190,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
T::from_raw(
self.get_format(),
gst_sys::gst_segment_position_from_running_time(
ffi::gst_segment_position_from_running_time(
&self.0,
self.get_format().to_glib(),
running_time.to_raw_value() as u64,
@ -212,7 +208,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
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.get_format().to_glib(),
running_time.to_raw_value() as u64,
@ -235,7 +231,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
T::from_raw(
self.get_format(),
gst_sys::gst_segment_position_from_stream_time(
ffi::gst_segment_position_from_stream_time(
&self.0,
self.get_format().to_glib(),
stream_time.to_raw_value() as u64,
@ -253,7 +249,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
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.get_format().to_glib(),
stream_time.to_raw_value() as u64,
@ -274,8 +270,8 @@ impl<T: FormattedValue> FormattedSegment<T> {
}
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_segment_set_running_time(
glib::glib_result_from_gboolean!(
ffi::gst_segment_set_running_time(
&mut self.0,
self.get_format().to_glib(),
running_time.to_raw_value() as u64,
@ -295,7 +291,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
T::from_raw(
self.get_format(),
gst_sys::gst_segment_to_running_time(
ffi::gst_segment_to_running_time(
&self.0,
self.get_format().to_glib(),
position.to_raw_value() as u64,
@ -313,7 +309,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
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.get_format().to_glib(),
position.to_raw_value() as u64,
@ -336,7 +332,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
T::from_raw(
self.get_format(),
gst_sys::gst_segment_to_stream_time(
ffi::gst_segment_to_stream_time(
&self.0,
self.get_format().to_glib(),
position.to_raw_value() as u64,
@ -354,7 +350,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
unsafe {
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.get_format().to_glib(),
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)
}
pub fn set_flags(&mut self, flags: ::SegmentFlags) {
pub fn set_flags(&mut self, flags: crate::SegmentFlags) {
self.0.flags = flags.to_glib();
}
@ -501,7 +497,7 @@ impl<T: FormattedValue> FormattedSegment<T> {
impl<T: FormattedValue> PartialEq for FormattedSegment<T> {
#[inline]
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)
.finish(),
Format::Time => {
let segment = segment.downcast_ref::<::ClockTime>().unwrap();
let segment = segment.downcast_ref::<crate::ClockTime>().unwrap();
f.debug_struct("Segment")
.field("format", &Format::Time)
.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> {
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)]
impl<'a> glib::value::FromValueOptional<'a> for Segment {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<Segment>::from_glib_none(
gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstSegment
)
Option::<Segment>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
value.to_glib_none().0,
) as *mut ffi::GstSegment)
}
}
#[doc(hidden)]
impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstSegment>::to_glib_none(this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstSegment>::to_glib_none(this).0
as glib::ffi::gpointer,
)
}
}
@ -601,78 +597,76 @@ impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> {
#[doc(hidden)]
impl<T: FormattedValue> glib::value::SetValueOptional for FormattedSegment<T> {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstSegment>::to_glib_none(&this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstSegment>::to_glib_none(&this).0
as glib::ffi::gpointer,
)
}
}
#[doc(hidden)]
impl<T: FormattedValue> glib::translate::GlibPtrDefault for FormattedSegment<T> {
type GlibType = *mut gst_sys::GstSegment;
type GlibType = *mut ffi::GstSegment;
}
#[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>
{
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)
}
fn to_glib_full(&self) -> *const gst_sys::GstSegment {
fn to_glib_full(&self) -> *const ffi::GstSegment {
unimplemented!()
}
}
#[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>
{
type Storage = &'a mut FormattedSegment<T>;
#[inline]
fn to_glib_none_mut(
&'a mut self,
) -> glib::translate::StashMut<'a, *mut gst_sys::GstSegment, Self> {
fn to_glib_none_mut(&'a mut self) -> glib::translate::StashMut<'a, *mut ffi::GstSegment, Self> {
glib::translate::StashMut(&mut self.0, self)
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const gst_sys::GstSegment> for Segment {
impl glib::translate::FromGlibPtrNone<*const ffi::GstSegment> for Segment {
#[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)
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstSegment> for Segment {
impl glib::translate::FromGlibPtrNone<*mut ffi::GstSegment> for Segment {
#[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)
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstSegment> for Segment {
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstSegment> for Segment {
#[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))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstSegment> for Segment {
impl glib::translate::FromGlibPtrFull<*mut ffi::GstSegment> for Segment {
#[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);
glib_sys::g_free(ptr as *mut _);
glib::ffi::g_free(ptr as *mut _);
segment
}
}

View file

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

View file

@ -6,24 +6,19 @@
// option. This file may not be copied, modified, or distributed
// 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 std::ffi::CStr;
use std::fmt;
use std::ptr;
pub struct StaticCaps(ptr::NonNull<gst_sys::GstStaticCaps>);
pub struct StaticCaps(ptr::NonNull<ffi::GstStaticCaps>);
impl StaticCaps {
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 {
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)]
impl<'a> glib::value::FromValueOptional<'a> for StaticCaps {
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
Option::<StaticCaps>::from_glib_none(
gobject_sys::g_value_get_boxed(value.to_glib_none().0) as *mut gst_sys::GstStaticCaps
)
Option::<StaticCaps>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
value.to_glib_none().0,
) as *mut ffi::GstStaticCaps)
}
}
#[doc(hidden)]
impl glib::value::SetValue for StaticCaps {
unsafe fn set_value(value: &mut glib::Value, this: &Self) {
gobject_sys::g_value_set_boxed(
glib::gobject_ffi::g_value_set_boxed(
value.to_glib_none_mut().0,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticCaps>::to_glib_none(this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(this).0
as glib::ffi::gpointer,
)
}
}
@ -69,63 +64,63 @@ impl glib::value::SetValue for StaticCaps {
#[doc(hidden)]
impl glib::value::SetValueOptional for StaticCaps {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticCaps>::to_glib_none(&this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstStaticCaps>::to_glib_none(&this).0
as glib::ffi::gpointer,
)
}
}
#[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticCaps {
type GlibType = *mut gst_sys::GstStaticCaps;
type GlibType = *mut ffi::GstStaticCaps;
}
#[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;
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)
}
fn to_glib_full(&self) -> *const gst_sys::GstStaticCaps {
fn to_glib_full(&self) -> *const ffi::GstStaticCaps {
unimplemented!()
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const gst_sys::GstStaticCaps> for StaticCaps {
impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticCaps> for StaticCaps {
#[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());
StaticCaps(ptr::NonNull::new_unchecked(ptr as *mut _))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstStaticCaps> for StaticCaps {
impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticCaps> for StaticCaps {
#[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());
StaticCaps(ptr::NonNull::new_unchecked(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstStaticCaps> for StaticCaps {
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticCaps> for StaticCaps {
#[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());
Borrowed::new(StaticCaps(ptr::NonNull::new_unchecked(ptr)))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstStaticCaps> for StaticCaps {
impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticCaps> for StaticCaps {
#[inline]
unsafe fn from_glib_full(_ptr: *mut gst_sys::GstStaticCaps) -> Self {
unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticCaps) -> Self {
unimplemented!();
}
}

View file

@ -6,29 +6,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use Caps;
use PadTemplate;
use crate::Caps;
use crate::PadTemplate;
use glib_sys;
use gobject_sys;
use gst_sys;
use glib;
use glib::translate::*;
use std::ffi::CStr;
use std::fmt;
use std::ptr;
pub struct StaticPadTemplate(ptr::NonNull<gst_sys::GstStaticPadTemplate>);
pub struct StaticPadTemplate(ptr::NonNull<ffi::GstStaticPadTemplate>);
impl StaticPadTemplate {
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 {
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 {
@ -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) }
}
pub fn presence(&self) -> ::PadPresence {
pub fn presence(&self) -> crate::PadPresence {
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()
})
.field("direction", &unsafe {
from_glib::<_, ::PadDirection>(self.0.as_ref().direction)
from_glib::<_, crate::PadDirection>(self.0.as_ref().direction)
})
.field("presence", &unsafe {
from_glib::<_, ::PadPresence>(self.0.as_ref().presence)
from_glib::<_, crate::PadPresence>(self.0.as_ref().presence)
})
.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()
}
@ -72,26 +67,26 @@ impl fmt::Debug for StaticPadTemplate {
impl glib::types::StaticType for StaticPadTemplate {
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)]
impl<'a> glib::value::FromValueOptional<'a> for StaticPadTemplate {
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,
) as *mut gst_sys::GstStaticPadTemplate)
) as *mut ffi::GstStaticPadTemplate)
}
}
#[doc(hidden)]
impl glib::value::SetValue for StaticPadTemplate {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticPadTemplate>::to_glib_none(this).0
as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(this).0
as glib::ffi::gpointer,
)
}
}
@ -99,67 +94,65 @@ impl glib::value::SetValue for StaticPadTemplate {
#[doc(hidden)]
impl glib::value::SetValueOptional for StaticPadTemplate {
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,
glib::translate::ToGlibPtr::<*const gst_sys::GstStaticPadTemplate>::to_glib_none(&this)
.0 as glib_sys::gpointer,
glib::translate::ToGlibPtr::<*const ffi::GstStaticPadTemplate>::to_glib_none(&this).0
as glib::ffi::gpointer,
)
}
}
#[doc(hidden)]
impl glib::translate::GlibPtrDefault for StaticPadTemplate {
type GlibType = *mut gst_sys::GstStaticPadTemplate;
type GlibType = *mut ffi::GstStaticPadTemplate;
}
#[doc(hidden)]
impl<'a> glib::translate::ToGlibPtr<'a, *const gst_sys::GstStaticPadTemplate>
for StaticPadTemplate
{
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstStaticPadTemplate> for StaticPadTemplate {
type Storage = &'a StaticPadTemplate;
fn to_glib_none(
&'a self,
) -> glib::translate::Stash<'a, *const gst_sys::GstStaticPadTemplate, Self> {
) -> glib::translate::Stash<'a, *const ffi::GstStaticPadTemplate, 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!()
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*const gst_sys::GstStaticPadTemplate> for StaticPadTemplate {
impl glib::translate::FromGlibPtrNone<*const ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[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());
StaticPadTemplate(ptr::NonNull::new_unchecked(ptr as *mut _))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrNone<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate {
impl glib::translate::FromGlibPtrNone<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[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());
StaticPadTemplate(ptr::NonNull::new_unchecked(ptr))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrBorrow<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate {
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[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());
Borrowed::new(StaticPadTemplate(ptr::NonNull::new_unchecked(ptr)))
}
}
#[doc(hidden)]
impl glib::translate::FromGlibPtrFull<*mut gst_sys::GstStaticPadTemplate> for StaticPadTemplate {
impl glib::translate::FromGlibPtrFull<*mut ffi::GstStaticPadTemplate> for StaticPadTemplate {
#[inline]
unsafe fn from_glib_full(_ptr: *mut gst_sys::GstStaticPadTemplate) -> Self {
unsafe fn from_glib_full(_ptr: *mut ffi::GstStaticPadTemplate) -> Self {
unimplemented!();
}
}

View file

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

View file

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

View file

@ -16,17 +16,14 @@ use std::str;
use thiserror::Error;
use Fraction;
use crate::Fraction;
use glib;
use glib::ffi::gpointer;
use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, FromGlibPtrNone, GlibPtrDefault, Stash, StashMut,
ToGlib, ToGlibPtr, ToGlibPtrMut,
};
use glib::value::{FromValue, FromValueOptional, SendValue, ToSendValue};
use glib_sys::gpointer;
use gobject_sys;
use gst_sys;
#[derive(Clone, Debug, Eq, PartialEq, Error)]
pub enum GetError<'name> {
@ -68,7 +65,7 @@ impl Structure {
pub fn new_empty(name: &str) -> Structure {
assert_initialized_main_thread!();
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());
Structure(ptr::NonNull::new_unchecked(ptr))
}
@ -85,9 +82,9 @@ impl 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);
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)]
@ -100,7 +97,7 @@ impl Structure {
iter.into_iter().for_each(|(f, v)| unsafe {
let mut value = v.clone().into_raw();
gst_sys::gst_structure_take_value(
ffi::gst_structure_take_value(
&mut structure.0.as_mut().0,
f.to_glib_none().0,
&mut value,
@ -140,7 +137,7 @@ impl AsMut<StructureRef> for Structure {
impl Clone for Structure {
fn clone(&self) -> Self {
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());
Structure(ptr::NonNull::new_unchecked(ptr))
}
@ -149,7 +146,7 @@ impl Clone for Structure {
impl Drop for Structure {
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> {
assert_initialized_main_thread!();
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() {
Err(glib_bool_error!("Failed to parse structure from string"))
Err(glib::glib_bool_error!(
"Failed to parse structure from string"
))
} else {
Ok(Structure(ptr::NonNull::new_unchecked(
structure as *mut StructureRef,
@ -216,7 +215,7 @@ impl ToOwned for StructureRef {
fn to_owned(&self) -> Structure {
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());
Structure(ptr::NonNull::new_unchecked(ptr))
}
@ -225,69 +224,69 @@ impl ToOwned for StructureRef {
impl glib::types::StaticType for Structure {
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;
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) }
}
fn to_glib_full(&self) -> *const gst_sys::GstStructure {
unsafe { gst_sys::gst_structure_copy(&self.0.as_ref().0) }
fn to_glib_full(&self) -> *const ffi::GstStructure {
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;
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) }
}
fn to_glib_full(&self) -> *mut gst_sys::GstStructure {
unsafe { gst_sys::gst_structure_copy(&self.0.as_ref().0) }
fn to_glib_full(&self) -> *mut ffi::GstStructure {
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;
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) }
}
}
impl FromGlibPtrNone<*const gst_sys::GstStructure> for Structure {
unsafe fn from_glib_none(ptr: *const gst_sys::GstStructure) -> Self {
impl FromGlibPtrNone<*const ffi::GstStructure> for Structure {
unsafe fn from_glib_none(ptr: *const ffi::GstStructure) -> Self {
assert!(!ptr.is_null());
let ptr = gst_sys::gst_structure_copy(ptr);
let ptr = ffi::gst_structure_copy(ptr);
assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
}
}
impl FromGlibPtrNone<*mut gst_sys::GstStructure> for Structure {
unsafe fn from_glib_none(ptr: *mut gst_sys::GstStructure) -> Self {
impl FromGlibPtrNone<*mut ffi::GstStructure> for Structure {
unsafe fn from_glib_none(ptr: *mut ffi::GstStructure) -> Self {
assert!(!ptr.is_null());
let ptr = gst_sys::gst_structure_copy(ptr);
let ptr = ffi::gst_structure_copy(ptr);
assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
}
}
impl FromGlibPtrFull<*const gst_sys::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *const gst_sys::GstStructure) -> Self {
impl FromGlibPtrFull<*const ffi::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *const ffi::GstStructure) -> Self {
assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
}
}
impl FromGlibPtrFull<*mut gst_sys::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstStructure) -> Self {
impl FromGlibPtrFull<*mut ffi::GstStructure> for Structure {
unsafe fn from_glib_full(ptr: *mut ffi::GstStructure) -> Self {
assert!(!ptr.is_null());
Structure(ptr::NonNull::new_unchecked(ptr as *mut StructureRef))
}
@ -316,36 +315,34 @@ impl glib::value::SetValueOptional for Structure {
}
impl GlibPtrDefault for Structure {
type GlibType = *mut gst_sys::GstStructure;
type GlibType = *mut ffi::GstStructure;
}
#[repr(transparent)]
pub struct StructureRef(gst_sys::GstStructure);
pub struct StructureRef(ffi::GstStructure);
unsafe impl Send for StructureRef {}
unsafe impl Sync for 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());
&*(ptr as *mut StructureRef)
}
pub unsafe fn from_glib_borrow_mut<'a>(
ptr: *mut gst_sys::GstStructure,
) -> &'a mut StructureRef {
pub unsafe fn from_glib_borrow_mut<'a>(ptr: *mut ffi::GstStructure) -> &'a mut StructureRef {
assert!(!ptr.is_null());
&mut *(ptr as *mut StructureRef)
}
pub unsafe fn as_ptr(&self) -> *const gst_sys::GstStructure {
self as *const Self as *const gst_sys::GstStructure
pub unsafe fn as_ptr(&self) -> *const ffi::GstStructure {
self as *const Self as *const ffi::GstStructure
}
pub unsafe fn as_mut_ptr(&self) -> *mut gst_sys::GstStructure {
self as *const Self as *mut gst_sys::GstStructure
pub unsafe fn as_mut_ptr(&self) -> *mut ffi::GstStructure {
self as *const Self as *mut ffi::GstStructure
}
pub fn get<'structure, 'name, T: FromValueOptional<'structure>>(
@ -385,7 +382,7 @@ impl StructureRef {
name: &'name str,
) -> Result<&SendValue, GetError<'name>> {
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() {
return Err(GetError::new_field_not_found(name));
@ -403,25 +400,25 @@ impl StructureRef {
pub fn set_value(&mut self, name: &str, value: SendValue) {
unsafe {
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 {
unsafe {
CStr::from_ptr(gst_sys::gst_structure_get_name(&self.0))
CStr::from_ptr(ffi::gst_structure_get_name(&self.0))
.to_str()
.unwrap()
}
}
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 {
unsafe {
from_glib(gst_sys::gst_structure_has_field(
from_glib(ffi::gst_structure_has_field(
&self.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 {
unsafe {
from_glib(gst_sys::gst_structure_has_field_typed(
from_glib(ffi::gst_structure_has_field_typed(
&self.0,
field.to_glib_none().0,
type_.to_glib(),
@ -440,7 +437,7 @@ impl StructureRef {
pub fn remove_field(&mut self, field: &str) {
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) {
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> {
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() {
return None;
}
@ -476,28 +473,28 @@ impl StructureRef {
}
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 {
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> {
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 {
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) {
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 {
unsafe {
from_glib(gst_sys::gst_structure_fixate_field(
from_glib(ffi::gst_structure_fixate_field(
&mut self.0,
name.to_glib_none().0,
))
@ -506,7 +503,7 @@ impl StructureRef {
pub fn fixate_field_bool(&mut self, name: &str, target: bool) -> bool {
unsafe {
from_glib(gst_sys::gst_structure_fixate_field_boolean(
from_glib(ffi::gst_structure_fixate_field_boolean(
&mut self.0,
name.to_glib_none().0,
target.to_glib(),
@ -516,7 +513,7 @@ impl StructureRef {
pub fn fixate_field_str(&mut self, name: &str, target: &str) -> bool {
unsafe {
from_glib(gst_sys::gst_structure_fixate_field_string(
from_glib(ffi::gst_structure_fixate_field_string(
&mut self.0,
name.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 {
unsafe {
from_glib(gst_sys::gst_structure_fixate_field_nearest_double(
from_glib(ffi::gst_structure_fixate_field_nearest_double(
&mut self.0,
name.to_glib_none().0,
target,
@ -543,7 +540,7 @@ impl StructureRef {
let target = target.into();
unsafe {
from_glib(gst_sys::gst_structure_fixate_field_nearest_fraction(
from_glib(ffi::gst_structure_fixate_field_nearest_fraction(
&mut self.0,
name.to_glib_none().0,
*target.numer(),
@ -554,7 +551,7 @@ impl StructureRef {
pub fn fixate_field_nearest_int(&mut self, name: &str, target: i32) -> bool {
unsafe {
from_glib(gst_sys::gst_structure_fixate_field_nearest_int(
from_glib(ffi::gst_structure_fixate_field_nearest_int(
&mut self.0,
name.to_glib_none().0,
target,
@ -565,7 +562,7 @@ impl StructureRef {
impl fmt::Display for StructureRef {
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)
}
}
@ -578,7 +575,7 @@ impl fmt::Debug for StructureRef {
impl PartialEq for StructureRef {
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 {
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 {
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() {
None
} else {
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 {
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 {
unsafe fn set_value_optional(v: &mut glib::Value, s: Option<&Self>) {
if let Some(s) = s {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
glib::gobject_ffi::g_value_set_boxed(v.to_glib_none_mut().0, s.as_ptr() as gpointer);
} else {
gobject_sys::g_value_set_boxed(v.to_glib_none_mut().0, ptr::null_mut());
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() {
use glib::{value, Type};
::init().unwrap();
crate::init().unwrap();
let mut s = Structure::new_empty("test");
assert_eq!(s.get_name(), "test");
@ -816,7 +813,7 @@ mod tests {
#[test]
fn test_builder() {
::init().unwrap();
crate::init().unwrap();
let s = Structure::builder("test")
.field("f1", &"abc")
@ -832,7 +829,7 @@ mod tests {
#[test]
fn test_string_conversion() {
::init().unwrap();
crate::init().unwrap();
let a = "Test, f1=(string)abc, f2=(uint)123;";
@ -845,7 +842,7 @@ mod tests {
#[test]
fn test_from_value_optional() {
::init().unwrap();
crate::init().unwrap();
let a = glib::value::Value::from(None::<&Structure>);
assert!(a.get::<Structure>().unwrap().is_none());
@ -855,7 +852,7 @@ mod tests {
#[test]
fn test_new_from_iter() {
::init().unwrap();
crate::init().unwrap();
let s = Structure::builder("test")
.field("f1", &"abc")

View file

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

View file

@ -6,19 +6,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use glib_sys;
use gst_sys;
use glib::prelude::*;
use glib::translate::*;
use super::prelude::*;
use glib::subclass::prelude::*;
use Bin;
use Element;
use LoggableError;
use Message;
use crate::Bin;
use crate::Element;
use crate::LoggableError;
use crate::Message;
pub trait BinImpl: BinImplExt + ElementImpl {
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> {
unsafe {
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(|| {
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!(
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
),
::CAT_RUST,
crate::CAT_RUST,
"Failed to add the element using the parent function"
)
}
@ -72,19 +72,19 @@ impl<T: BinImpl> BinImplExt for T {
) -> Result<(), LoggableError> {
unsafe {
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(|| {
gst_loggable_error!(
::CAT_RUST,
crate::CAT_RUST,
"Parent function `remove_element` is not defined"
)
})?;
gst_result_from_gboolean!(
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
),
::CAT_RUST,
crate::CAT_RUST,
"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) {
unsafe {
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 {
f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0,
bin.unsafe_cast_ref::<crate::Bin>().to_glib_none().0,
message.into_ptr(),
);
}
@ -109,7 +109,7 @@ where
<T as ObjectSubclass>::Instance: PanicPoison,
{
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();
klass.add_element = Some(bin_add_element::<T>);
klass.remove_element = Some(bin_remove_element::<T>);
@ -118,9 +118,9 @@ where
}
unsafe extern "C" fn bin_add_element<T: BinImpl>(
ptr: *mut gst_sys::GstBin,
element: *mut gst_sys::GstElement,
) -> glib_sys::gboolean
ptr: *mut ffi::GstBin,
element: *mut ffi::GstElement,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
@ -141,9 +141,9 @@ where
}
unsafe extern "C" fn bin_remove_element<T: BinImpl>(
ptr: *mut gst_sys::GstBin,
element: *mut gst_sys::GstElement,
) -> glib_sys::gboolean
ptr: *mut ffi::GstBin,
element: *mut ffi::GstElement,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
@ -154,8 +154,10 @@ where
// 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
// of this floating reference.
if gobject_sys::g_object_is_floating(element as *mut gobject_sys::GObject) != glib_sys::GFALSE {
return glib_sys::GFALSE;
if glib::gobject_ffi::g_object_is_floating(element as *mut glib::gobject_ffi::GObject)
!= glib::ffi::GFALSE
{
return glib::ffi::GFALSE;
}
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
@ -171,8 +173,8 @@ where
}
unsafe extern "C" fn bin_handle_message<T: BinImpl>(
ptr: *mut gst_sys::GstBin,
message: *mut gst_sys::GstMessage,
ptr: *mut ffi::GstBin,
message: *mut ffi::GstMessage,
) where
T::Instance: PanicPoison,
{

View file

@ -6,25 +6,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use glib_sys;
use gobject_sys;
use gst_sys;
use glib;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use libc;
use ChildProxy;
use crate::ChildProxy;
pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> {
unsafe {
let type_ = gst_sys::gst_child_proxy_get_type();
let iface = gobject_sys::g_type_default_interface_ref(type_)
as *mut gst_sys::GstChildProxyInterface;
let type_ = ffi::gst_child_proxy_get_type();
let iface = glib::gobject_ffi::g_type_default_interface_ref(type_)
as *mut ffi::GstChildProxyInterface;
assert!(!iface.is_null());
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,
);
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)
}
@ -47,10 +40,10 @@ pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
unsafe extern "C" fn interface_init(
iface: glib_sys::gpointer,
_iface_data: glib_sys::gpointer,
iface: glib::ffi::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_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>(
child_proxy: *mut gst_sys::GstChildProxy,
child_proxy: *mut ffi::GstChildProxy,
name: *const libc::c_char,
) -> *mut gobject_sys::GObject {
) -> *mut glib::gobject_ffi::GObject {
let instance = &*(child_proxy as *mut T::Instance);
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>(
child_proxy: *mut gst_sys::GstChildProxy,
child_proxy: *mut ffi::GstChildProxy,
index: u32,
) -> *mut gobject_sys::GObject {
) -> *mut glib::gobject_ffi::GObject {
let instance = &*(child_proxy as *mut T::Instance);
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>(
child_proxy: *mut gst_sys::GstChildProxy,
child_proxy: *mut ffi::GstChildProxy,
) -> u32 {
let instance = &*(child_proxy as *mut T::Instance);
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>(
child_proxy: *mut gst_sys::GstChildProxy,
child: *mut gobject_sys::GObject,
child_proxy: *mut ffi::GstChildProxy,
child: *mut glib::gobject_ffi::GObject,
name: *const libc::c_char,
) {
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>(
child_proxy: *mut gst_sys::GstChildProxy,
child: *mut gobject_sys::GObject,
child_proxy: *mut ffi::GstChildProxy,
child: *mut glib::gobject_ffi::GObject,
name: *const libc::c_char,
) {
let instance = &*(child_proxy as *mut T::Instance);

View file

@ -6,20 +6,17 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use gst_sys;
use glib;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use Clock;
use ClockError;
use ClockId;
use ClockReturn;
use ClockSuccess;
use ClockTime;
use ClockTimeDiff;
use crate::Clock;
use crate::ClockError;
use crate::ClockId;
use crate::ClockReturn;
use crate::ClockSuccess;
use crate::ClockTime;
use crate::ClockTimeDiff;
pub trait ClockImpl: ClockImplExt + ObjectImpl + Send + Sync {
fn change_resolution(
@ -97,7 +94,7 @@ impl<T: ClockImpl> ClockImplExt for T {
) -> ClockTime {
unsafe {
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 {
from_glib(func(
@ -114,7 +111,7 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_get_resolution(&self, clock: &Self::Type) -> ClockTime {
unsafe {
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(
(*parent_class)
@ -128,7 +125,7 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_get_internal_time(&self, clock: &Self::Type) -> ClockTime {
unsafe {
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(
(*parent_class)
@ -146,7 +143,7 @@ impl<T: ClockImpl> ClockImplExt for T {
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe {
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;
(
@ -156,11 +153,11 @@ impl<T: ClockImpl> ClockImplExt for T {
.map(|f| {
f(
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,
)
})
.unwrap_or(gst_sys::GST_CLOCK_UNSUPPORTED),
.unwrap_or(ffi::GST_CLOCK_UNSUPPORTED),
)
.into_result(),
jitter,
@ -175,17 +172,17 @@ impl<T: ClockImpl> ClockImplExt for T {
) -> Result<ClockSuccess, ClockError> {
unsafe {
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(
(*parent_class)
.wait_async
.map(|f| {
f(
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()
}
@ -194,11 +191,11 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId) {
unsafe {
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 {
func(
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();
cfg_if! {
cfg_if::cfg_if! {
if #[cfg(feature = "v1_16")] {
assert!(id.uses_clock(&clock));
} else {
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);
}
}
}
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 {
func(
clock.as_ref().to_glib_none().0,
(*ptr).time,
ptr as gst_sys::GstClockID,
ptr as ffi::GstClockID,
(*ptr).user_data,
);
}
if (*ptr).type_ == gst_sys::GST_CLOCK_ENTRY_PERIODIC {
if (*ptr).type_ == ffi::GST_CLOCK_ENTRY_PERIODIC {
(*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>(
ptr: *mut gst_sys::GstClock,
old_resolution: gst_sys::GstClockTime,
new_resolution: gst_sys::GstClockTime,
) -> gst_sys::GstClockTime {
ptr: *mut ffi::GstClock,
old_resolution: ffi::GstClockTime,
new_resolution: ffi::GstClockTime,
) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
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>(
ptr: *mut gst_sys::GstClock,
) -> gst_sys::GstClockTime {
ptr: *mut ffi::GstClock,
) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
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>(
ptr: *mut gst_sys::GstClock,
) -> gst_sys::GstClockTime {
ptr: *mut ffi::GstClock,
) -> ffi::GstClockTime {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
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>(
ptr: *mut gst_sys::GstClock,
id: *mut gst_sys::GstClockEntry,
jitter: *mut gst_sys::GstClockTimeDiff,
) -> gst_sys::GstClockReturn {
ptr: *mut ffi::GstClock,
id: *mut ffi::GstClockEntry,
jitter: *mut ffi::GstClockTimeDiff,
) -> ffi::GstClockReturn {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
let (res, j) = imp.wait(
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID),
&from_glib_borrow(id as ffi::GstClockID),
);
if !jitter.is_null() {
*jitter = j;
@ -310,23 +307,23 @@ unsafe extern "C" fn clock_wait<T: ClockImpl>(
}
unsafe extern "C" fn clock_wait_async<T: ClockImpl>(
ptr: *mut gst_sys::GstClock,
id: *mut gst_sys::GstClockEntry,
) -> gst_sys::GstClockReturn {
ptr: *mut ffi::GstClock,
id: *mut ffi::GstClockEntry,
) -> ffi::GstClockReturn {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
ClockReturn::from(imp.wait_async(
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID),
&from_glib_borrow(id as ffi::GstClockID),
))
.to_glib()
}
unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
ptr: *mut gst_sys::GstClock,
id: *mut gst_sys::GstClockEntry,
ptr: *mut ffi::GstClock,
id: *mut ffi::GstClockEntry,
) {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
@ -334,6 +331,6 @@ unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
imp.unschedule(
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
// except according to those terms.
use glib_sys;
use gst_sys;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use Device;
use Element;
use LoggableError;
use crate::Device;
use crate::Element;
use crate::LoggableError;
use std::ptr;
@ -59,7 +56,7 @@ impl<T: DeviceImpl> DeviceImplExt for T {
) -> Result<Element, LoggableError> {
unsafe {
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 {
let ptr = f(
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
Option::<_>::from_glib_full(ptr).ok_or_else(|| {
gst_loggable_error!(
::CAT_RUST,
crate::CAT_RUST,
"Failed to create element using the parent function"
)
})
} else {
Err(gst_loggable_error!(
::CAT_RUST,
crate::CAT_RUST,
"Parent function `create_element` is not defined"
))
}
@ -89,10 +86,10 @@ impl<T: DeviceImpl> DeviceImplExt for T {
) -> Result<(), LoggableError> {
unsafe {
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(|| {
gst_loggable_error!(
::CAT_RUST,
crate::CAT_RUST,
"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,
element.to_glib_none().0
),
::CAT_RUST,
crate::CAT_RUST,
"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>(
ptr: *mut gst_sys::GstDevice,
ptr: *mut ffi::GstDevice,
name: *const libc::c_char,
) -> *mut gst_sys::GstElement {
) -> *mut ffi::GstElement {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
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();
drop(element);
// 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
}
Err(err) => {
@ -149,9 +148,9 @@ unsafe extern "C" fn device_create_element<T: DeviceImpl>(
}
unsafe extern "C" fn device_reconfigure_element<T: DeviceImpl>(
ptr: *mut gst_sys::GstDevice,
element: *mut gst_sys::GstElement,
) -> glib_sys::gboolean {
ptr: *mut ffi::GstDevice,
element: *mut ffi::GstElement,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<Device> = from_glib_borrow(ptr);

View file

@ -6,16 +6,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use glib_sys;
use gst_sys;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use Device;
use DeviceProvider;
use LoggableError;
use crate::Device;
use crate::DeviceProvider;
use crate::LoggableError;
pub trait DeviceProviderImpl: DeviceProviderImplExt + ObjectImpl + Send + Sync {
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> {
unsafe {
let data = T::type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceProviderClass;
if let Some(f) = (*parent_class).probe {
FromGlibPtrContainer::from_glib_full(f(device_provider
.unsafe_cast_ref::<DeviceProvider>()
@ -59,17 +55,16 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> {
unsafe {
let data = T::type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceProviderClass;
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!(
f(device_provider
.unsafe_cast_ref::<DeviceProvider>()
.to_glib_none()
.0),
::CAT_RUST,
crate::CAT_RUST,
"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) {
unsafe {
let data = T::type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstDeviceProviderClass;
if let Some(f) = (*parent_class).stop {
f(device_provider
.unsafe_cast_ref::<DeviceProvider>()
@ -99,8 +93,8 @@ pub unsafe trait DeviceProviderClassSubclassExt: Sized + 'static {
author: &str,
) {
unsafe {
gst_sys::gst_device_provider_class_set_metadata(
self as *mut Self as *mut gst_sys::GstDeviceProviderClass,
ffi::gst_device_provider_class_set_metadata(
self as *mut Self as *mut ffi::GstDeviceProviderClass,
long_name.to_glib_none().0,
classification.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) {
unsafe {
gst_sys::gst_device_provider_class_add_metadata(
self as *mut Self as *mut gst_sys::GstDeviceProviderClass,
ffi::gst_device_provider_class_add_metadata(
self as *mut Self as *mut ffi::GstDeviceProviderClass,
key.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>(
ptr: *mut gst_sys::GstDeviceProvider,
) -> *mut glib_sys::GList {
ptr: *mut ffi::GstDeviceProvider,
) -> *mut glib::ffi::GList {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
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>(
ptr: *mut gst_sys::GstDeviceProvider,
) -> glib_sys::gboolean {
ptr: *mut ffi::GstDeviceProvider,
) -> glib::ffi::gboolean {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
@ -159,9 +153,7 @@ unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
.to_glib()
}
unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>(
ptr: *mut gst_sys::GstDeviceProvider,
) {
unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>(ptr: *mut ffi::GstDeviceProvider) {
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);

View file

@ -6,26 +6,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use libc;
use glib_sys;
use gst_sys;
use super::prelude::*;
use glib;
use glib::prelude::*;
use crate::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use prelude::*;
use Element;
use Event;
use PadTemplate;
use QueryRef;
use StateChange;
use StateChangeError;
use StateChangeReturn;
use StateChangeSuccess;
use crate::Element;
use crate::Event;
use crate::PadTemplate;
use crate::QueryRef;
use crate::StateChange;
use crate::StateChangeError;
use crate::StateChangeReturn;
use crate::StateChangeSuccess;
pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
fn change_state(
@ -39,14 +32,14 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
fn request_new_pad(
&self,
element: &Self::Type,
templ: &::PadTemplate,
templ: &crate::PadTemplate,
name: Option<String>,
caps: Option<&::Caps>,
) -> Option<::Pad> {
caps: Option<&crate::Caps>,
) -> Option<crate::Pad> {
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)
}
@ -58,19 +51,19 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
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)
}
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)
}
fn provide_clock(&self, element: &Self::Type) -> Option<::Clock> {
fn provide_clock(&self, element: &Self::Type) -> Option<crate::Clock> {
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)
}
}
@ -85,24 +78,24 @@ pub trait ElementImplExt: ObjectSubclass {
fn parent_request_new_pad(
&self,
element: &Self::Type,
templ: &::PadTemplate,
templ: &crate::PadTemplate,
name: Option<String>,
caps: Option<&::Caps>,
) -> Option<::Pad>;
caps: Option<&crate::Caps>,
) -> 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_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>>(
&self,
@ -112,7 +105,7 @@ pub trait ElementImplExt: ObjectSubclass {
) -> 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,
f: F,
) -> R;
@ -129,7 +122,7 @@ where
) -> Result<StateChangeSuccess, StateChangeError> {
unsafe {
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)
.change_state
@ -145,13 +138,13 @@ where
fn parent_request_new_pad(
&self,
element: &Self::Type,
templ: &::PadTemplate,
templ: &crate::PadTemplate,
name: Option<String>,
caps: Option<&::Caps>,
) -> Option<::Pad> {
caps: Option<&crate::Caps>,
) -> Option<crate::Pad> {
unsafe {
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)
.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 {
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)
.release_pad
@ -187,7 +180,7 @@ where
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool {
unsafe {
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)
.send_event
@ -204,7 +197,7 @@ where
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool {
unsafe {
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)
.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 {
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)
.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 {
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)
.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 {
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)
.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 {
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 {
from_glib(f(
@ -288,7 +281,7 @@ where
) -> R {
unsafe {
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 imp = instance.get_impl();
@ -297,14 +290,14 @@ where
}
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>(
parent: Option<&::Object>,
parent: Option<&crate::Object>,
fallback: G,
f: F,
) -> R {
unsafe {
let wrap = parent.as_ref().unwrap().downcast_ref::<Element>().unwrap();
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 imp = instance.get_impl();
@ -318,8 +311,8 @@ where
pub unsafe trait ElementClassSubclassExt: Sized + 'static {
fn add_pad_template(&mut self, pad_template: PadTemplate) {
unsafe {
gst_sys::gst_element_class_add_pad_template(
self as *mut Self as *mut gst_sys::GstElementClass,
ffi::gst_element_class_add_pad_template(
self as *mut Self as *mut ffi::GstElementClass,
pad_template.to_glib_none().0,
);
}
@ -333,8 +326,8 @@ pub unsafe trait ElementClassSubclassExt: Sized + 'static {
author: &str,
) {
unsafe {
gst_sys::gst_element_class_set_metadata(
self as *mut Self as *mut gst_sys::GstElementClass,
ffi::gst_element_class_set_metadata(
self as *mut Self as *mut ffi::GstElementClass,
long_name.to_glib_none().0,
classification.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) {
unsafe {
gst_sys::gst_element_class_add_metadata(
self as *mut Self as *mut gst_sys::GstElementClass,
ffi::gst_element_class_add_metadata(
self as *mut Self as *mut ffi::GstElementClass,
key.to_glib_none().0,
value.to_glib_none().0,
);
@ -376,9 +369,9 @@ where
}
unsafe extern "C" fn element_change_state<T: ElementImpl>(
ptr: *mut gst_sys::GstElement,
transition: gst_sys::GstStateChange,
) -> gst_sys::GstStateChangeReturn
ptr: *mut ffi::GstElement,
transition: ffi::GstStateChange,
) -> ffi::GstStateChangeReturn
where
T::Instance: PanicPoison,
{
@ -403,11 +396,11 @@ where
}
unsafe extern "C" fn element_request_new_pad<T: ElementImpl>(
ptr: *mut gst_sys::GstElement,
templ: *mut gst_sys::GstPadTemplate,
ptr: *mut ffi::GstElement,
templ: *mut ffi::GstPadTemplate,
name: *const libc::c_char,
caps: *const gst_sys::GstCaps,
) -> *mut gst_sys::GstPad
caps: *const ffi::GstCaps,
) -> *mut ffi::GstPad
where
T::Instance: PanicPoison,
{
@ -415,7 +408,7 @@ where
let imp = instance.get_impl();
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
// See https://bugzilla.gnome.org/show_bug.cgi?id=791193
@ -432,7 +425,9 @@ where
if let Some(ref pad) = pad {
assert_eq!(
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>(
ptr: *mut gst_sys::GstElement,
pad: *mut gst_sys::GstPad,
ptr: *mut ffi::GstElement,
pad: *mut ffi::GstPad,
) where
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
// 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;
}
@ -461,9 +458,9 @@ unsafe extern "C" fn element_release_pad<T: ElementImpl>(
}
unsafe extern "C" fn element_send_event<T: ElementImpl>(
ptr: *mut gst_sys::GstElement,
event: *mut gst_sys::GstEvent,
) -> glib_sys::gboolean
ptr: *mut ffi::GstElement,
event: *mut ffi::GstEvent,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
@ -478,9 +475,9 @@ where
}
unsafe extern "C" fn element_query<T: ElementImpl>(
ptr: *mut gst_sys::GstElement,
query: *mut gst_sys::GstQuery,
) -> glib_sys::gboolean
ptr: *mut ffi::GstElement,
query: *mut ffi::GstQuery,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
@ -496,8 +493,8 @@ where
}
unsafe extern "C" fn element_set_context<T: ElementImpl>(
ptr: *mut gst_sys::GstElement,
context: *mut gst_sys::GstContext,
ptr: *mut ffi::GstElement,
context: *mut ffi::GstContext,
) where
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>(
ptr: *mut gst_sys::GstElement,
clock: *mut gst_sys::GstClock,
) -> glib_sys::gboolean
ptr: *mut ffi::GstElement,
clock: *mut ffi::GstClock,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
@ -521,7 +518,7 @@ where
let imp = instance.get_impl();
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, {
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>(
ptr: *mut gst_sys::GstElement,
) -> *mut gst_sys::GstClock
ptr: *mut ffi::GstElement,
) -> *mut ffi::GstClock
where
T::Instance: PanicPoison,
{
@ -546,9 +543,9 @@ where
}
unsafe extern "C" fn element_post_message<T: ElementImpl>(
ptr: *mut gst_sys::GstElement,
msg: *mut gst_sys::GstMessage,
) -> glib_sys::gboolean
ptr: *mut ffi::GstElement,
msg: *mut ffi::GstMessage,
) -> glib::ffi::gboolean
where
T::Instance: PanicPoison,
{
@ -565,18 +562,17 @@ where
#[cfg(test)]
mod tests {
use super::*;
use glib;
use glib::subclass;
use std::sync::atomic;
use ElementFactory;
use crate::ElementFactory;
pub mod imp {
use super::*;
pub struct TestElement {
pub(super) srcpad: ::Pad,
pub(super) sinkpad: ::Pad,
pub(super) srcpad: crate::Pad,
pub(super) sinkpad: crate::Pad,
pub(super) n_buffers: atomic::AtomicU32,
pub(super) reached_playing: atomic::AtomicBool,
}
@ -584,46 +580,46 @@ mod tests {
impl TestElement {
fn sink_chain(
&self,
_pad: &::Pad,
_pad: &crate::Pad,
_element: &super::TestElement,
buffer: ::Buffer,
) -> Result<::FlowSuccess, ::FlowError> {
buffer: crate::Buffer,
) -> Result<crate::FlowSuccess, crate::FlowError> {
self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst);
self.srcpad.push(buffer)
}
fn sink_event(
&self,
_pad: &::Pad,
_pad: &crate::Pad,
_element: &super::TestElement,
event: ::Event,
event: crate::Event,
) -> bool {
self.srcpad.push_event(event)
}
fn sink_query(
&self,
_pad: &::Pad,
_pad: &crate::Pad,
_element: &super::TestElement,
query: &mut ::QueryRef,
query: &mut crate::QueryRef,
) -> bool {
self.srcpad.peer_query(query)
}
fn src_event(
&self,
_pad: &::Pad,
_pad: &crate::Pad,
_element: &super::TestElement,
event: ::Event,
event: crate::Event,
) -> bool {
self.sinkpad.push_event(event)
}
fn src_query(
&self,
_pad: &::Pad,
_pad: &crate::Pad,
_element: &super::TestElement,
query: &mut ::QueryRef,
query: &mut crate::QueryRef,
) -> bool {
self.sinkpad.peer_query(query)
}
@ -633,18 +629,18 @@ mod tests {
const NAME: &'static str = "TestElement";
type Type = super::TestElement;
type ParentType = Element;
type Instance = ::subclass::ElementInstanceStruct<Self>;
type Instance = crate::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!();
glib::glib_object_subclass!();
fn with_class(klass: &Self::Class) -> Self {
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| {
TestElement::catch_panic_pad_function(
parent,
|| Err(::FlowError::Error),
|| Err(crate::FlowError::Error),
|identity, element| identity.sink_chain(pad, element, buffer),
)
})
@ -665,7 +661,7 @@ mod tests {
.build();
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| {
TestElement::catch_panic_pad_function(
parent,
@ -698,15 +694,23 @@ mod tests {
"Sebastian Dröge <sebastian@centricular.com>",
);
let caps = ::Caps::new_any();
let src_pad_template =
::PadTemplate::new("src", ::PadDirection::Src, ::PadPresence::Always, &caps)
.unwrap();
let caps = crate::Caps::new_any();
let src_pad_template = crate::PadTemplate::new(
"src",
crate::PadDirection::Src,
crate::PadPresence::Always,
&caps,
)
.unwrap();
klass.add_pad_template(src_pad_template);
let sink_pad_template =
::PadTemplate::new("sink", ::PadDirection::Sink, ::PadPresence::Always, &caps)
.unwrap();
let sink_pad_template = crate::PadTemplate::new(
"sink",
crate::PadDirection::Sink,
crate::PadPresence::Always,
&caps,
)
.unwrap();
klass.add_pad_template(sink_pad_template);
}
}
@ -724,11 +728,11 @@ mod tests {
fn change_state(
&self,
element: &Self::Type,
transition: ::StateChange,
) -> Result<::StateChangeSuccess, ::StateChangeError> {
transition: crate::StateChange,
) -> Result<crate::StateChangeSuccess, crate::StateChangeError> {
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);
}
@ -737,8 +741,8 @@ mod tests {
}
}
glib_wrapper! {
pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends Element, ::Object;
glib::glib_wrapper! {
pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends Element, crate::Object;
}
unsafe impl Send for TestElement {}
@ -755,18 +759,18 @@ mod tests {
#[test]
fn test_element_subclass() {
::init().unwrap();
crate::init().unwrap();
let element = TestElement::new(Some("test"));
assert_eq!(element.get_name(), "test");
assert_eq!(
element.get_metadata(&::ELEMENT_METADATA_LONGNAME),
element.get_metadata(&crate::ELEMENT_METADATA_LONGNAME),
Some("Test Element")
);
let pipeline = ::Pipeline::new(None);
let pipeline = crate::Pipeline::new(None);
let src = ElementFactory::make("fakesrc", None).unwrap();
let sink = ElementFactory::make("fakesink", None).unwrap();
@ -777,13 +781,13 @@ mod tests {
.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 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());
pipeline.set_state(::State::Null).unwrap();
pipeline.set_state(crate::State::Null).unwrap();
let imp = imp::TestElement::from_instance(&element);
assert_eq!(imp.n_buffers.load(atomic::Ordering::SeqCst), 100);

View file

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

View file

@ -9,13 +9,13 @@
use super::prelude::*;
use glib::subclass::prelude::*;
use GhostPad;
use crate::GhostPad;
pub trait GhostPadImpl: PadImpl {}
unsafe impl<T: GhostPadImpl> IsSubclassable<T> for GhostPad {
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();
// Nothing to do here
}

View file

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

View file

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

View file

@ -9,7 +9,7 @@
use super::prelude::*;
use glib::subclass::prelude::*;
use Pipeline;
use crate::Pipeline;
pub trait PipelineImpl: BinImpl {}
@ -18,7 +18,7 @@ where
<T as ObjectSubclass>::Instance: PanicPoison,
{
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();
// 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};
#[repr(transparent)]
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc);
pub struct GstPluginDesc($crate::ffi::GstPluginDesc);
unsafe impl Send for GstPluginDesc {}
unsafe impl Sync for GstPluginDesc {}
#[no_mangle]
#[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,
minor_version: $crate::subclass::MINOR_VERSION,
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 _,
origin: concat!($origin, "\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> {
unsafe {
$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::MINOR_VERSION,
concat!(stringify!($name), "\0") as *const str as *const _,
@ -66,17 +66,17 @@ macro_rules! gst_plugin_define(
}
#[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};
let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin))));
match panic_result {
Ok(register_result) => match register_result {
Ok(_) => $crate::glib_sys::GTRUE,
Ok(_) => $crate::glib::ffi::GTRUE,
Err(err) => {
let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
$crate::gst_error!(cat, "Failed to register plugin: {}", err);
$crate::glib_sys::GFALSE
$crate::glib::ffi::GFALSE
}
}
Err(err) => {
@ -89,7 +89,7 @@ macro_rules! gst_plugin_define(
$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};
#[repr(transparent)]
pub struct GstPluginDesc($crate::gst_sys::GstPluginDesc);
pub struct GstPluginDesc($crate::ffi::GstPluginDesc);
unsafe impl Send 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,
minor_version: $crate::subclass::MINOR_VERSION,
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 _,
origin: concat!($origin, "\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> {
unsafe {
$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::MINOR_VERSION,
concat!(stringify!($name), "\0") as *const str as *const _,
@ -72,23 +72,23 @@ macro_rules! gst_plugin_define(
#[no_mangle]
#[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
}
}
#[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};
let panic_result = panic::catch_unwind(AssertUnwindSafe(|| super::$plugin_init(&from_glib_borrow(plugin))));
match panic_result {
Ok(register_result) => match register_result {
Ok(_) => $crate::glib_sys::GTRUE,
Ok(_) => $crate::glib::ffi::GTRUE,
Err(err) => {
let cat = $crate::DebugCategory::get("GST_PLUGIN_LOADING").unwrap();
$crate::gst_error!(cat, "Failed to register plugin: {}", err);
$crate::glib_sys::GFALSE
$crate::glib::ffi::GFALSE
}
}
Err(err) => {
@ -101,7 +101,7 @@ macro_rules! gst_plugin_define(
$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
// except according to those terms.
use glib_sys;
use glib::subclass::prelude::*;
use Preset;
use crate::Preset;
pub trait PresetImpl: super::element::ElementImpl {}
unsafe impl<T: PresetImpl> IsImplementable<T> for Preset {
unsafe extern "C" fn interface_init(
_iface: glib_sys::gpointer,
_iface_data: glib_sys::gpointer,
_iface: glib::ffi::gpointer,
_iface_data: glib::ffi::gpointer,
) {
}
}

View file

@ -9,13 +9,13 @@
use super::prelude::*;
use glib::subclass::prelude::*;
use SystemClock;
use crate::SystemClock;
pub trait SystemClockImpl: ClockImpl {}
unsafe impl<T: SystemClockImpl> IsSubclassable<T> for SystemClock {
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();
// Nothing to do here
}

View file

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

View file

@ -6,19 +6,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use glib_sys;
use gst_sys;
use glib;
use glib::prelude::*;
use glib::translate::*;
use glib::subclass::prelude::*;
use libc;
use URIHandler;
use URIType;
use crate::URIHandler;
use crate::URIType;
pub trait URIHandlerImpl: super::element::ElementImpl {
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 extern "C" fn interface_init(
iface: glib_sys::gpointer,
_iface_data: glib_sys::gpointer,
iface: glib::ffi::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
let mut data = T::type_data();
@ -42,7 +36,7 @@ unsafe impl<T: URIHandlerImpl> IsImplementable<T> for URIHandler {
if data.interface_data.is_null() {
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 _));
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>(
_type_: glib_sys::GType,
) -> gst_sys::GstURIType {
_type_: glib::ffi::GType,
) -> ffi::GstURIType {
<T as URIHandlerImpl>::get_uri_type().to_glib()
}
unsafe extern "C" fn uri_handler_get_protocols<T: URIHandlerImpl>(
_type_: glib_sys::GType,
_type_: glib::ffi::GType,
) -> *const *const libc::c_char {
let data = <T as ObjectSubclass>::type_data();
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>(
uri_handler: *mut gst_sys::GstURIHandler,
uri_handler: *mut ffi::GstURIHandler,
) -> *mut libc::c_char {
let instance = &*(uri_handler as *mut T::Instance);
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>(
uri_handler: *mut gst_sys::GstURIHandler,
uri_handler: *mut ffi::GstURIHandler,
uri: *const libc::c_char,
err: *mut *mut glib_sys::GError,
) -> glib_sys::gboolean {
err: *mut *mut glib::ffi::GError,
) -> glib::ffi::gboolean {
let instance = &*(uri_handler as *mut T::Instance);
let imp = instance.get_impl();

View file

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

View file

@ -13,19 +13,16 @@ use std::mem;
use once_cell::sync::Lazy;
use glib;
use glib::translate::{
from_glib, from_glib_full, FromGlibPtrFull, ToGlib, ToGlibPtr, ToGlibPtrMut,
};
use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue, Value};
use glib::StaticType;
use gobject_sys;
use gst_sys;
use Sample;
use TagError;
use TagMergeMode;
use TagScope;
use crate::Sample;
use crate::TagError;
use crate::TagMergeMode;
use crate::TagScope;
pub trait Tag<'a> {
type TagType: FromValueOptional<'a> + SetValue + Send;
@ -43,7 +40,7 @@ macro_rules! impl_tag(
}
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
);
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!(Comment, &'a str, TAG_COMMENT, GST_TAG_COMMENT);
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!(LicenseUri, &'a str, TAG_LICENSE_URI, GST_TAG_LICENSE_URI);
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!(VideoCodec, &'a str, TAG_VIDEO_CODEC, GST_TAG_VIDEO_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);
gst_define_mini_object_wrapper!(TagList, TagListRef, gst_sys::GstTagList, || {
gst_sys::gst_tag_list_get_type()
gst_define_mini_object_wrapper!(TagList, TagListRef, ffi::GstTagList, || {
ffi::gst_tag_list_get_type()
});
impl TagList {
pub fn new() -> Self {
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 {
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_() {
return Err(TagError::TypeMismatch);
}
gst_sys::gst_tag_list_add_value(
ffi::gst_tag_list_add_value(
self.as_mut_ptr(),
mode.to_glib(),
tag_name.0,
@ -415,7 +417,7 @@ impl TagListRef {
unsafe {
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,
self.as_ptr(),
tag_name.to_glib_none().0,
@ -430,12 +432,12 @@ impl TagListRef {
}
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 {
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()
.unwrap()
}
@ -448,11 +450,8 @@ impl TagListRef {
pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> {
unsafe {
let value = gst_sys::gst_tag_list_get_value_index(
self.as_ptr(),
tag_name.to_glib_none().0,
idx,
);
let value =
ffi::gst_tag_list_get_value_index(self.as_ptr(), tag_name.to_glib_none().0, idx);
if value.is_null() {
return None;
@ -467,7 +466,7 @@ impl TagListRef {
}
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> {
@ -487,12 +486,12 @@ impl TagListRef {
}
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 {
unsafe {
from_glib_full(gst_sys::gst_tag_list_merge(
from_glib_full(ffi::gst_tag_list_merge(
self.as_ptr(),
other.as_ptr(),
mode.to_glib(),
@ -501,11 +500,11 @@ impl TagListRef {
}
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) {
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 {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = unsafe {
glib::GString::from_glib_full(gst_sys::gst_tag_list_to_string(self.as_ptr()))
};
let s =
unsafe { glib::GString::from_glib_full(ffi::gst_tag_list_to_string(self.as_ptr())) };
f.write_str(&s)
}
}
impl PartialEq for TagListRef {
fn eq(&self, other: &TagListRef) -> bool {
unsafe {
from_glib(gst_sys::gst_tag_list_is_equal(
self.as_ptr(),
other.as_ptr(),
))
}
unsafe { from_glib(ffi::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 {
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 {
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> {
skip_assert_initialized!();
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() {
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> {
skip_assert_initialized!();
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() {
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!();
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> {
const FLAG: ::TagFlag;
const FLAG: crate::TagFlag;
const NICK: &'static str;
const DESCRIPTION: &'static str;
@ -860,14 +853,14 @@ pub fn register<T: for<'a> CustomTag<'a>>() {
assert!(!tag_exists(T::tag_name()));
unsafe extern "C" fn merge_func_trampoline<T: for<'a> CustomTag<'a>>(
dest: *mut gobject_sys::GValue,
src: *const gobject_sys::GValue,
dest: *mut glib::gobject_ffi::GValue,
src: *const glib::gobject_ffi::GValue,
) {
*dest = T::merge_func(&*(src as *const Value)).into_raw();
}
unsafe {
gst_sys::gst_tag_register(
ffi::gst_tag_register(
T::tag_name().to_glib_none().0,
T::FLAG.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 {
skip_assert_initialized!();
assert_eq!(src.type_(), ::List::static_type());
assert_eq!(src.type_(), crate::List::static_type());
unsafe {
use glib::translate::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
}
}
pub fn merge_strings_with_comma(src: &Value) -> Value {
skip_assert_initialized!();
assert_eq!(src.type_(), ::List::static_type());
assert_eq!(src.type_(), crate::List::static_type());
unsafe {
use glib::translate::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
}
}
@ -910,14 +903,14 @@ mod tests {
#[test]
fn test_add() {
::init().unwrap();
crate::init().unwrap();
let mut tags = TagList::new();
assert_eq!(tags.to_string(), "taglist;");
{
let tags = tags.get_mut().unwrap();
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.to_string(),
@ -927,31 +920,34 @@ mod tests {
#[test]
fn test_get() {
::init().unwrap();
crate::init().unwrap();
let mut tags = TagList::new();
assert_eq!(tags.to_string(), "taglist;");
{
let tags = tags.get_mut().unwrap();
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::<Duration>().unwrap().get_some(), (::SECOND * 120));
assert_eq!(
tags.get::<Duration>().unwrap().get_some(),
(crate::SECOND * 120)
);
assert_eq!(
tags.get_index::<Title>(0).unwrap().get(),
Some("some title")
);
assert_eq!(
tags.get_index::<Duration>(0).unwrap().get_some(),
(::SECOND * 120)
(crate::SECOND * 120)
);
}
#[test]
fn test_scope() {
::init().unwrap();
crate::init().unwrap();
let mut tags = TagList::new();
assert_eq!(tags.get_scope(), TagScope::Stream);
@ -965,7 +961,7 @@ mod tests {
#[test]
#[allow(clippy::cognitive_complexity)]
fn test_generic() {
::init().unwrap();
crate::init().unwrap();
let mut tags = TagList::new();
{
@ -977,7 +973,7 @@ mod tests {
.add_generic(&TAG_TITLE, &"second title", TagMergeMode::Append)
.is_ok());
assert!(tags
.add_generic(&TAG_DURATION, &(::SECOND * 120), TagMergeMode::Append)
.add_generic(&TAG_DURATION, &(crate::SECOND * 120), TagMergeMode::Append)
.is_ok());
assert!(tags
.add_generic(&TAG_TITLE, &"third title", TagMergeMode::Append)
@ -1003,7 +999,7 @@ mod tests {
);
assert_eq!(
tags.get_index_generic(&TAG_DURATION, 0).unwrap().get(),
Ok(Some(::SECOND * 120))
Ok(Some(crate::SECOND * 120))
);
assert_eq!(
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();
assert_eq!(tag_name, *TAG_DURATION);
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());
// Iter
@ -1065,13 +1061,13 @@ mod tests {
let (tag_name, tag_value) = tag_list_iter.next().unwrap();
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());
}
#[test]
fn test_custom_tags() {
::init().unwrap();
crate::init().unwrap();
enum MyCustomTag {};
@ -1083,7 +1079,7 @@ mod tests {
}
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 DESCRIPTION: &'static str = "My own custom tag type for testing";
@ -1131,7 +1127,7 @@ mod tests {
#[test]
fn test_display() {
::init().unwrap();
crate::init().unwrap();
format!("{}", TagList::new());
}

View file

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

View file

@ -10,73 +10,63 @@ use std::ffi::CStr;
use std::fmt;
use std::mem;
use gst_sys;
use glib;
use glib::translate::{
from_glib, from_glib_full, from_glib_none, FromGlibPtrContainer, ToGlib, ToGlibPtr,
};
use TagList;
use TagMergeMode;
use TocEntryType;
use TocLoopType;
use TocScope;
use crate::TagList;
use crate::TagMergeMode;
use crate::TocEntryType;
use crate::TocLoopType;
use crate::TocScope;
gst_define_mini_object_wrapper!(Toc, TocRef, gst_sys::GstToc, || {
gst_sys::gst_toc_get_type()
});
gst_define_mini_object_wrapper!(Toc, TocRef, ffi::GstToc, || { ffi::gst_toc_get_type() });
impl Toc {
pub fn new(scope: TocScope) -> Self {
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 {
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> {
unsafe {
from_glib_none(gst_sys::gst_toc_find_entry(
self.as_ptr(),
uid.to_glib_none().0,
))
}
unsafe { from_glib_none(ffi::gst_toc_find_entry(self.as_ptr(), uid.to_glib_none().0)) }
}
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) {
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> {
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) {
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) {
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) {
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_sys::gst_toc_entry_get_type()
gst_define_mini_object_wrapper!(TocEntry, TocEntryRef, ffi::GstTocEntry, || {
ffi::gst_toc_entry_get_type()
});
impl TocEntry {
pub fn new(type_: TocEntryType, uid: &str) -> Self {
assert_initialized_main_thread!();
unsafe {
from_glib_full(gst_sys::gst_toc_entry_new(
from_glib_full(ffi::gst_toc_entry_new(
type_.to_glib(),
uid.to_glib_none().0,
))
@ -115,12 +105,12 @@ impl TocEntry {
impl TocEntryRef {
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 {
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()
.unwrap()
}
@ -128,20 +118,18 @@ impl TocEntryRef {
pub fn append_sub_entry(&mut self, subentry: TocEntry) {
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> {
unsafe {
FromGlibPtrContainer::from_glib_none(gst_sys::gst_toc_entry_get_sub_entries(
self.as_ptr(),
))
FromGlibPtrContainer::from_glib_none(ffi::gst_toc_entry_get_sub_entries(self.as_ptr()))
}
}
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)> {
@ -149,7 +137,7 @@ impl TocEntryRef {
let mut start = 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(),
start.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) {
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> {
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) {
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) {
unsafe {
gst_sys::gst_toc_entry_merge_tags(
self.as_mut_ptr(),
tag_list.as_mut_ptr(),
mode.to_glib(),
);
ffi::gst_toc_entry_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.to_glib());
}
}
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 {
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)> {
unsafe {
let mut loop_type = 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(),
loop_type.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) {
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]
fn test_simple() {
::init().unwrap();
crate::init().unwrap();
// Top level toc entry
let mut toc_entry = TocEntry::new(TocEntryType::Chapter, "chapter");

View file

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

View file

@ -6,22 +6,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use gst_sys;
use Caps;
use Plugin;
use Rank;
use TypeFindFactory;
use TypeFindProbability;
use crate::Caps;
use crate::Plugin;
use crate::Rank;
use crate::TypeFindFactory;
use crate::TypeFindProbability;
use glib;
use glib::translate::*;
use glib_sys;
use std::ptr;
use std::slice;
#[repr(transparent)]
#[derive(Debug)]
pub struct TypeFind(gst_sys::GstTypeFind);
pub struct TypeFind(ffi::GstTypeFind);
pub trait TypeFindImpl {
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::into_raw(func);
let res = gst_sys::gst_type_find_register(
let res = ffi::gst_type_find_register(
plugin.to_glib_none().0,
name.to_glib_none().0,
rank.to_glib() as u32,
@ -59,13 +56,13 @@ impl TypeFind {
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]> {
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() {
None
} else {
@ -76,7 +73,7 @@ impl TypeFind {
pub fn suggest(&mut self, probability: TypeFindProbability, caps: &Caps) {
unsafe {
gst_sys::gst_type_find_suggest(
ffi::gst_type_find_suggest(
&mut self.0,
probability.to_glib() as u32,
caps.to_glib_none().0,
@ -86,7 +83,7 @@ impl TypeFind {
pub fn get_length(&mut self) -> Option<u64> {
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 {
None
} else {
@ -99,8 +96,8 @@ impl TypeFind {
impl TypeFindFactory {
pub fn call_function(&self, find: &mut dyn TypeFindImpl) {
unsafe {
let find_ptr = &find as *const &mut dyn TypeFindImpl as glib_sys::gpointer;
let mut find = gst_sys::GstTypeFind {
let find_ptr = &find as *const &mut dyn TypeFindImpl as glib::ffi::gpointer;
let mut find = ffi::GstTypeFind {
peek: Some(type_find_peek),
suggest: Some(type_find_suggest),
data: find_ptr,
@ -108,26 +105,30 @@ impl TypeFindFactory {
_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>(
find: *mut gst_sys::GstTypeFind,
user_data: glib_sys::gpointer,
find: *mut ffi::GstTypeFind,
user_data: glib::ffi::gpointer,
) {
let func: &F = &*(user_data as *const F);
func(&mut *(find as *mut TypeFind));
}
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 _);
}
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);
match find.peek(offset, size) {
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(
data: glib_sys::gpointer,
data: glib::ffi::gpointer,
probability: u32,
caps: *mut gst_sys::GstCaps,
caps: *mut ffi::GstCaps,
) {
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
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;
let find: &mut &mut dyn TypeFindImpl = &mut *(data as *mut &mut dyn TypeFindImpl);
@ -242,7 +243,7 @@ mod tests {
#[test]
fn test_typefind_call_function() {
::init().unwrap();
crate::init().unwrap();
let xml_factory = TypeFindFactory::get_list()
.iter()
@ -272,12 +273,12 @@ mod tests {
#[test]
fn test_typefind_register() {
::init().unwrap();
crate::init().unwrap();
TypeFind::register(
None,
"test_typefind",
::Rank::Primary,
crate::Rank::Primary,
None,
Some(&Caps::new_simple("test/test", &[])),
|typefind| {

View file

@ -7,17 +7,16 @@
// except according to those terms.
use glib::translate::mut_override;
use glib_sys;
#[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> {
#[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!();
unsafe {
glib_sys::g_mutex_lock(mut_override(mutex));
glib::ffi::g_mutex_lock(mut_override(mutex));
}
MutexGuard(mutex)
}
@ -26,7 +25,7 @@ impl<'a> MutexGuard<'a> {
impl<'a> Drop for MutexGuard<'a> {
fn drop(&mut self) {
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::slice;
use glib;
use glib::translate::{from_glib, FromGlibPtrFull, ToGlibPtr, ToGlibPtrMut, Uninitialized};
use glib::value::{FromValue, FromValueOptional, SetValue, ToSendValue, Value};
use glib_sys;
use gst_sys;
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Fraction(pub Rational32);
@ -248,14 +244,14 @@ impl From<Fraction> for Rational32 {
impl glib::types::StaticType for Fraction {
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 {
unsafe fn from_value(v: &'a Value) -> Fraction {
let n = gst_sys::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 n = ffi::gst_value_get_fraction_numerator(v.to_glib_none().0);
let d = ffi::gst_value_get_fraction_denominator(v.to_glib_none().0);
Fraction::new(n, d)
}
@ -269,12 +265,12 @@ impl<'a> FromValueOptional<'a> for Fraction {
impl SetValue for Fraction {
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)]
#[cfg_attr(feature = "ser_de", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub struct IntRange<T> {
min: T,
max: T,
@ -357,15 +353,15 @@ impl From<(i64, i64, i64)> for IntRange<i64> {
impl glib::types::StaticType for IntRange<i32> {
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> {
unsafe fn from_value(v: &'a Value) -> Self {
let min = gst_sys::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 step = gst_sys::gst_value_get_int_range_step(v.to_glib_none().0);
let min = ffi::gst_value_get_int_range_min(v.to_glib_none().0);
let max = ffi::gst_value_get_int_range_max(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)
}
@ -379,21 +375,21 @@ impl<'a> FromValueOptional<'a> for IntRange<i32> {
impl SetValue for IntRange<i32> {
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> {
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> {
unsafe fn from_value(v: &'a Value) -> Self {
let min = gst_sys::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 step = gst_sys::gst_value_get_int64_range_step(v.to_glib_none().0);
let min = ffi::gst_value_get_int64_range_min(v.to_glib_none().0);
let max = ffi::gst_value_get_int64_range_max(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)
}
@ -407,12 +403,12 @@ impl<'a> FromValueOptional<'a> for IntRange<i64> {
impl SetValue for IntRange<i64> {
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)]
#[cfg_attr(feature = "ser_de", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub struct FractionRange {
min: Fraction,
max: Fraction,
@ -449,19 +445,19 @@ impl From<(Fraction, Fraction)> for FractionRange {
impl glib::types::StaticType for FractionRange {
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 {
unsafe fn from_value(v: &'a Value) -> Self {
let min = gst_sys::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 min = ffi::gst_value_get_fraction_range_min(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_d = gst_sys::gst_value_get_fraction_denominator(min);
let max_n = gst_sys::gst_value_get_fraction_numerator(max);
let max_d = gst_sys::gst_value_get_fraction_denominator(max);
let min_n = ffi::gst_value_get_fraction_numerator(min);
let min_d = ffi::gst_value_get_fraction_denominator(min);
let max_n = ffi::gst_value_get_fraction_numerator(max);
let max_d = ffi::gst_value_get_fraction_denominator(max);
Self::new((min_n, min_d), (max_n, max_d))
}
@ -475,7 +471,7 @@ impl<'a> FromValueOptional<'a> for FractionRange {
impl SetValue for FractionRange {
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,
*r.min().numer(),
*r.min().denom(),
@ -486,7 +482,7 @@ impl SetValue for FractionRange {
}
#[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);
impl Bitmask {
@ -551,13 +547,13 @@ impl From<u64> for Bitmask {
impl glib::types::StaticType for Bitmask {
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 {
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)
}
}
@ -570,7 +566,7 @@ impl<'a> FromValueOptional<'a> for Bitmask {
impl SetValue for Bitmask {
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> {
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() {
Array(Cow::Borrowed(&[]))
} else {
@ -647,14 +643,14 @@ impl<'a> FromValueOptional<'a> for Array<'a> {
impl<'a> SetValue for Array<'a> {
unsafe fn set_value(v: &mut Value, a: &Self) {
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> {
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> {
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() {
List(Cow::Borrowed(&[]))
} else {
@ -731,14 +727,14 @@ impl<'a> FromValueOptional<'a> for List<'a> {
impl<'a> SetValue for List<'a> {
unsafe fn set_value(v: &mut Value, a: &Self) {
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> {
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 {
fn can_compare(&self, other: &Self) -> bool {
unsafe {
from_glib(gst_sys::gst_value_can_compare(
from_glib(ffi::gst_value_can_compare(
self.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> {
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 {
gst_sys::GST_VALUE_LESS_THAN => Some(cmp::Ordering::Less),
gst_sys::GST_VALUE_EQUAL => Some(cmp::Ordering::Equal),
gst_sys::GST_VALUE_GREATER_THAN => Some(cmp::Ordering::Greater),
ffi::GST_VALUE_LESS_THAN => Some(cmp::Ordering::Less),
ffi::GST_VALUE_EQUAL => Some(cmp::Ordering::Equal),
ffi::GST_VALUE_GREATER_THAN => Some(cmp::Ordering::Greater),
_ => None,
}
}
@ -788,7 +784,7 @@ impl GstValueExt for glib::Value {
fn can_intersect(&self, other: &Self) -> bool {
unsafe {
from_glib(gst_sys::gst_value_can_intersect(
from_glib(ffi::gst_value_can_intersect(
self.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> {
unsafe {
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,
self.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 {
unsafe {
from_glib(gst_sys::gst_value_can_subtract(
from_glib(ffi::gst_value_can_subtract(
self.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> {
unsafe {
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,
self.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 {
unsafe {
from_glib(gst_sys::gst_value_can_union(
from_glib(ffi::gst_value_can_union(
self.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> {
unsafe {
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,
self.to_glib_none().0,
other.to_glib_none().0,
@ -864,7 +860,7 @@ impl GstValueExt for glib::Value {
fn fixate(&self) -> Option<Self> {
unsafe {
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,
self.to_glib_none().0,
));
@ -877,12 +873,12 @@ impl GstValueExt for glib::Value {
}
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 {
unsafe {
from_glib(gst_sys::gst_value_is_subset(
from_glib(ffi::gst_value_is_subset(
self.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> {
unsafe {
Option::<_>::from_glib_full(gst_sys::gst_value_serialize(self.to_glib_none().0))
.ok_or_else(|| glib_bool_error!("Failed to serialize value"))
Option::<_>::from_glib_full(ffi::gst_value_serialize(self.to_glib_none().0))
.ok_or_else(|| glib::glib_bool_error!("Failed to serialize value"))
}
}
@ -903,14 +899,14 @@ impl GstValueExt for glib::Value {
unsafe {
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,
s.to_glib_none().0,
));
if ret {
Ok(value)
} 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 {
#[test]
fn test_fraction() {
::init().unwrap();
crate::init().unwrap();
let f1 = ::Fraction::new(1, 2);
let f2 = ::Fraction::new(2, 3);
let f1 = crate::Fraction::new(1, 2);
let f2 = crate::Fraction::new(2, 3);
let mut f3 = f1 * f2;
let f4 = f1 * f2;
f3 *= f2;
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
// except according to those terms.
use glib;
use glib::{Date, StaticType, ToValue};
use num_rational::Rational32;
@ -20,12 +19,12 @@ use std::{fmt, mem};
use once_cell::sync::Lazy;
use Buffer;
use DateTime;
use Sample;
use crate::Buffer;
use crate::DateTime;
use crate::Sample;
use date_time_serde;
use value::*;
use crate::date_time_serde;
use crate::value::*;
fn get_other_type_id<T: StaticType>() -> usize {
match T::static_type() {
@ -306,22 +305,19 @@ impl_de_send_value_collection!(List);
#[cfg(test)]
mod tests {
extern crate ron;
extern crate serde_json;
use Array;
use Bitmask;
use DateTime;
use Fraction;
use FractionRange;
use IntRange;
use List;
use crate::Array;
use crate::Bitmask;
use crate::DateTime;
use crate::Fraction;
use crate::FractionRange;
use crate::IntRange;
use crate::List;
use glib::{Date, DateMonth};
#[test]
fn test_serialize_simple() {
::init().unwrap();
crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string();
@ -364,10 +360,7 @@ mod tests {
#[test]
fn test_serialize_collections() {
use Fraction;
use List;
::init().unwrap();
crate::init().unwrap();
let mut pretty_config = ron::ser::PrettyConfig::default();
pretty_config.new_line = "".to_string();
@ -445,7 +438,7 @@ mod tests {
#[test]
fn test_deserialize_simple() {
::init().unwrap();
crate::init().unwrap();
// Fraction
let fraction_ron = "(1, 3)";
@ -496,7 +489,7 @@ mod tests {
#[test]
fn test_serde_roundtrip_simple() {
::init().unwrap();
crate::init().unwrap();
// Fraction
let fraction = Fraction::new(1, 3);
@ -537,7 +530,7 @@ mod tests {
#[allow(clippy::cognitive_complexity)]
#[test]
fn test_deserialize_collections() {
::init().unwrap();
crate::init().unwrap();
// Array
let array_ron = r#"[
@ -634,7 +627,7 @@ mod tests {
#[test]
fn test_serde_roundtrip_collection() {
::init().unwrap();
crate::init().unwrap();
// Array
let value_13 = Fraction::new(1, 3);