Run everything through rustfmt again

This commit is contained in:
Sebastian Dröge 2018-05-01 17:16:12 +03:00
parent d74995ee7e
commit 8bc3f12061
18 changed files with 148 additions and 160 deletions

View file

@ -8,9 +8,9 @@
use std::ptr;
use glib;
use glib_ffi;
use gobject_ffi;
use glib;
#[macro_export]
macro_rules! callback_guard {

View file

@ -70,10 +70,10 @@ pub trait ImplTypeStatic<T: ObjectType>: Send + Sync + 'static {
pub struct ClassInitToken(());
pub struct TypeInitToken(());
pub trait ObjectType: FromGlibPtrBorrow<*mut <Self as ObjectType>::InstanceStructType>
where Self: Sized + 'static,
Self::InstanceStructType: Instance<Self>
where
Self: Sized + 'static,
Self::InstanceStructType: Instance<Self>,
{
const NAME: &'static str;
type InstanceStructType: Instance<Self> + 'static;
@ -81,7 +81,6 @@ where Self: Sized + 'static,
type GlibClassType;
type ImplType: ObjectImpl<Self>;
fn glib_type() -> glib::Type;
fn class_init(token: &ClassInitToken, klass: &mut ClassStruct<Self>);
@ -96,12 +95,11 @@ where Self: Sized + 'static,
unsafe fn get_instance(&self) -> *mut Self::InstanceStructType;
fn get_impl(&self) -> &Self::ImplType{
fn get_impl(&self) -> &Self::ImplType {
unsafe { (*self.get_instance()).get_impl() }
}
unsafe fn get_class(&self) -> *const ClassStruct<Self>{
unsafe fn get_class(&self) -> *const ClassStruct<Self> {
(*self.get_instance()).get_class()
}
}
@ -115,29 +113,24 @@ macro_rules! object_type_fns(
}
);
pub trait Instance<T: ObjectType>
{
pub trait Instance<T: ObjectType> {
fn parent(&self) -> &T::GlibType;
fn get_impl(&self) -> &T::ImplType;
unsafe fn set_impl(&mut self, imp:ptr::NonNull<T::ImplType>);
unsafe fn set_impl(&mut self, imp: ptr::NonNull<T::ImplType>);
unsafe fn get_class(&self) -> *const ClassStruct<T>;
}
#[repr(C)]
pub struct InstanceStruct<T: ObjectType>
{
pub struct InstanceStruct<T: ObjectType> {
_parent: T::GlibType,
_imp: ptr::NonNull<T::ImplType>,
}
impl<T: ObjectType> Instance<T> for InstanceStruct<T>
{
fn parent(&self) -> &T::GlibType{
impl<T: ObjectType> Instance<T> for InstanceStruct<T> {
fn parent(&self) -> &T::GlibType {
&self._parent
}
@ -145,7 +138,7 @@ impl<T: ObjectType> Instance<T> for InstanceStruct<T>
unsafe { self._imp.as_ref() }
}
unsafe fn set_impl(&mut self, imp:ptr::NonNull<T::ImplType>){
unsafe fn set_impl(&mut self, imp: ptr::NonNull<T::ImplType>) {
self._imp = imp;
}
@ -308,8 +301,7 @@ unsafe impl<T: ObjectType> ObjectClass for ClassStruct<T> {}
unsafe extern "C" fn class_init<T: ObjectType>(
klass: glib_ffi::gpointer,
_klass_data: glib_ffi::gpointer,
)
{
) {
callback_guard!();
{
let gobject_klass = &mut *(klass as *mut gobject_ffi::GObjectClass);
@ -349,8 +341,7 @@ unsafe extern "C" fn get_property<T: ObjectType>(
id: u32,
value: *mut gobject_ffi::GValue,
_pspec: *mut gobject_ffi::GParamSpec,
)
{
) {
callback_guard!();
floating_reference_guard!(obj);
match T::get_property(&from_glib_borrow(obj as *mut T::InstanceStructType), id - 1) {
@ -368,8 +359,7 @@ unsafe extern "C" fn set_property<T: ObjectType>(
id: u32,
value: *mut gobject_ffi::GValue,
_pspec: *mut gobject_ffi::GParamSpec,
)
{
) {
callback_guard!();
floating_reference_guard!(obj);
T::set_property(
@ -381,8 +371,7 @@ unsafe extern "C" fn set_property<T: ObjectType>(
static mut TYPES: *mut Mutex<BTreeMap<TypeId, glib::Type>> = 0 as *mut _;
pub unsafe fn get_type<T: ObjectType>() -> glib_ffi::GType
{
pub unsafe fn get_type<T: ObjectType>() -> glib_ffi::GType {
use std::sync::{Once, ONCE_INIT};
static ONCE: Once = ONCE_INIT;
@ -495,8 +484,7 @@ unsafe extern "C" fn sub_set_property<T: ObjectType>(
unsafe extern "C" fn sub_init<T: ObjectType>(
obj: *mut gobject_ffi::GTypeInstance,
_klass: glib_ffi::gpointer,
)
{
) {
callback_guard!();
floating_reference_guard!(obj);
let instance = &mut *(obj as *mut T::InstanceStructType);
@ -507,8 +495,7 @@ unsafe extern "C" fn sub_init<T: ObjectType>(
instance.set_impl(ptr::NonNull::new_unchecked(Box::into_raw(Box::new(imp))));
}
pub fn register_type<T: ObjectType, I: ImplTypeStatic<T>>(imp: I) -> glib::Type
{
pub fn register_type<T: ObjectType, I: ImplTypeStatic<T>>(imp: I) -> glib::Type {
unsafe {
let parent_type = get_type::<T>();
let type_name = format!("{}-{}", T::NAME, imp.get_name());

View file

@ -17,7 +17,7 @@ use gst_plugin::object::*;
use gst_plugin::properties::*;
use std::sync::Mutex;
use std::{cmp, iter, i32, u64};
use std::{cmp, i32, iter, u64};
use byte_slice_cast::*;

View file

@ -12,9 +12,9 @@ use url::Url;
use std::io::Write;
use gst_plugin_simple::UriValidator;
use gst_plugin_simple::error::*;
use gst_plugin_simple::sink::*;
use gst_plugin_simple::UriValidator;
use gst;
@ -93,7 +93,7 @@ impl SinkImpl for FileSink {
[
"Could not open file for writing '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string()
err.to_string(),
]
))
}));

View file

@ -11,9 +11,9 @@ use std::io::{Read, Seek, SeekFrom};
use std::u64;
use url::Url;
use gst_plugin_simple::UriValidator;
use gst_plugin_simple::error::*;
use gst_plugin_simple::source::*;
use gst_plugin_simple::UriValidator;
use gst;
@ -104,7 +104,7 @@ impl SourceImpl for FileSrc {
[
"Could not open file for reading '{}': {}",
location.to_str().unwrap_or("Non-UTF8 path"),
err.to_string()
err.to_string(),
]
))
}));

View file

@ -346,12 +346,10 @@ impl VideoFormat {
if let Some(par) = self.pixel_aspect_ratio {
if *par.numer() != 0 && par.numer() != par.denom() {
caps.as_mut().map(|c| {
c.get_mut().unwrap().set_simple(&[
(
c.get_mut().unwrap().set_simple(&[(
"pixel-aspect-ratio",
&gst::Fraction::new(*par.numer(), *par.denom()),
),
])
)])
});
}
}
@ -359,9 +357,10 @@ impl VideoFormat {
if let Some(fps) = self.framerate {
if *fps.numer() != 0 {
caps.as_mut().map(|c| {
c.get_mut().unwrap().set_simple(&[
("framerate", &gst::Fraction::new(*fps.numer(), *fps.denom())),
])
c.get_mut().unwrap().set_simple(&[(
"framerate",
&gst::Fraction::new(*fps.numer(), *fps.denom()),
)])
});
}
}

View file

@ -13,9 +13,9 @@ use std::io::Read;
use std::u64;
use url::Url;
use gst_plugin_simple::UriValidator;
use gst_plugin_simple::error::*;
use gst_plugin_simple::source::*;
use gst_plugin_simple::UriValidator;
use gst;

View file

@ -41,15 +41,13 @@ struct Sink {
imp: Mutex<Box<SinkImpl>>,
}
static PROPERTIES: [Property; 1] = [
Property::String(
static PROPERTIES: [Property; 1] = [Property::String(
"uri",
"URI",
"URI to read from",
None,
PropertyMutability::ReadWrite,
),
];
)];
impl Sink {
fn new(sink: &BaseSink, sink_info: &SinkInfo) -> Self {

View file

@ -59,15 +59,13 @@ struct Source {
push_only: bool,
}
static PROPERTIES: [Property; 1] = [
Property::String(
static PROPERTIES: [Property; 1] = [Property::String(
"uri",
"URI",
"URI to read from",
None,
PropertyMutability::ReadWrite,
),
];
)];
impl Source {
fn new(source: &BaseSrc, source_info: &SourceInfo) -> Self {

View file

@ -919,7 +919,7 @@ impl ToggleRecord {
gst::StreamError::Format,
[
"Only Time segments supported, got {:?}",
segment.get_format()
segment.get_format(),
]
);
return false;
@ -933,7 +933,7 @@ impl ToggleRecord {
gst::StreamError::Format,
[
"Only rate==1.0 segments supported, got {:?}",
segment.get_rate()
segment.get_rate(),
]
);
return false;

View file

@ -27,7 +27,7 @@ use object::*;
pub trait BaseSinkImpl<T: BaseSinkBase>:
AnyImpl + ObjectImpl<T> + ElementImpl<T> + Send + Sync + 'static
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn start(&self, _element: &T) -> bool {
true
@ -165,7 +165,7 @@ pub unsafe trait BaseSinkBase:
pub unsafe trait BaseSinkClassExt<T: BaseSinkBase>
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn override_vfuncs(&mut self, _: &ClassInitToken) {
unsafe {
@ -311,7 +311,7 @@ unsafe extern "C" fn base_sink_start<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -327,7 +327,7 @@ unsafe extern "C" fn base_sink_stop<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -344,7 +344,7 @@ unsafe extern "C" fn base_sink_render<T: BaseSinkBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -364,7 +364,7 @@ unsafe extern "C" fn base_sink_prepare<T: BaseSinkBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -384,7 +384,7 @@ unsafe extern "C" fn base_sink_render_list<T: BaseSinkBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -404,7 +404,7 @@ unsafe extern "C" fn base_sink_prepare_list<T: BaseSinkBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -424,7 +424,7 @@ unsafe extern "C" fn base_sink_query<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -444,7 +444,7 @@ unsafe extern "C" fn base_sink_event<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -463,7 +463,7 @@ unsafe extern "C" fn base_sink_get_caps<T: BaseSinkBase>(
) -> *mut gst_ffi::GstCaps
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -488,7 +488,7 @@ unsafe extern "C" fn base_sink_set_caps<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -508,7 +508,7 @@ unsafe extern "C" fn base_sink_fixate<T: BaseSinkBase>(
) -> *mut gst_ffi::GstCaps
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -527,7 +527,7 @@ unsafe extern "C" fn base_sink_unlock<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -543,7 +543,7 @@ unsafe extern "C" fn base_sink_unlock_stop<T: BaseSinkBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSinkImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -551,5 +551,7 @@ where
let wrap: T = from_glib_borrow(ptr as *mut T::InstanceStructType);
let imp = element.get_impl();
panic_to_error!(&wrap, &element.panicked(), false, { imp.unlock_stop(&wrap) }).to_glib()
panic_to_error!(&wrap, &element.panicked(), false, {
imp.unlock_stop(&wrap)
}).to_glib()
}

View file

@ -27,7 +27,7 @@ use object::*;
pub trait BaseSrcImpl<T: BaseSrcBase>:
AnyImpl + ObjectImpl<T> + ElementImpl<T> + Send + Sync + 'static
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn start(&self, _element: &T) -> bool {
true
@ -214,7 +214,7 @@ pub unsafe trait BaseSrcBase:
pub unsafe trait BaseSrcClassExt<T: BaseSrcBase>
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn override_vfuncs(&mut self, _: &ClassInitToken) {
unsafe {
@ -382,7 +382,7 @@ unsafe extern "C" fn base_src_start<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -398,7 +398,7 @@ unsafe extern "C" fn base_src_stop<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -414,7 +414,7 @@ unsafe extern "C" fn base_src_is_seekable<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -422,7 +422,9 @@ where
let wrap: T = from_glib_borrow(ptr as *mut T::InstanceStructType);
let imp = element.get_impl();
panic_to_error!(&wrap, &element.panicked(), false, { imp.is_seekable(&wrap) }).to_glib()
panic_to_error!(&wrap, &element.panicked(), false, {
imp.is_seekable(&wrap)
}).to_glib()
}
unsafe extern "C" fn base_src_get_size<T: BaseSrcBase>(
@ -431,7 +433,7 @@ unsafe extern "C" fn base_src_get_size<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -458,7 +460,7 @@ unsafe extern "C" fn base_src_fill<T: BaseSrcBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -480,7 +482,7 @@ unsafe extern "C" fn base_src_create<T: BaseSrcBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -508,7 +510,7 @@ unsafe extern "C" fn base_src_do_seek<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -527,7 +529,7 @@ unsafe extern "C" fn base_src_query<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -547,7 +549,7 @@ unsafe extern "C" fn base_src_event<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -566,7 +568,7 @@ unsafe extern "C" fn base_src_get_caps<T: BaseSrcBase>(
) -> *mut gst_ffi::GstCaps
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -590,7 +592,7 @@ unsafe extern "C" fn base_src_negotiate<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -607,7 +609,7 @@ unsafe extern "C" fn base_src_set_caps<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -627,7 +629,7 @@ unsafe extern "C" fn base_src_fixate<T: BaseSrcBase>(
) -> *mut gst_ffi::GstCaps
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -646,7 +648,7 @@ unsafe extern "C" fn base_src_unlock<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -662,7 +664,7 @@ unsafe extern "C" fn base_src_unlock_stop<T: BaseSrcBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseSrcImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -670,5 +672,7 @@ where
let wrap: T = from_glib_borrow(ptr as *mut T::InstanceStructType);
let imp = element.get_impl();
panic_to_error!(&wrap, &element.panicked(), false, { imp.unlock_stop(&wrap) }).to_glib()
panic_to_error!(&wrap, &element.panicked(), false, {
imp.unlock_stop(&wrap)
}).to_glib()
}

View file

@ -27,7 +27,7 @@ use object::*;
pub trait BaseTransformImpl<T: BaseTransformBase>:
AnyImpl + ObjectImpl<T> + ElementImpl<T> + Send + Sync + 'static
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn start(&self, _element: &T) -> bool {
true
@ -115,7 +115,7 @@ any_impl!(BaseTransformBase, BaseTransformImpl, PanicPoison);
pub unsafe trait BaseTransformBase:
IsA<gst::Element> + IsA<gst_base::BaseTransform> + ObjectType
where
Self::InstanceStructType: PanicPoison
Self::InstanceStructType: PanicPoison,
{
fn parent_transform_caps(
&self,
@ -264,7 +264,7 @@ pub enum BaseTransformMode {
pub unsafe trait BaseTransformClassExt<T: BaseTransformBase>
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn configure(
&mut self,
@ -325,7 +325,7 @@ glib_wrapper! {
unsafe impl<T: IsA<gst::Element> + IsA<gst_base::BaseTransform> + ObjectType> BaseTransformBase
for T
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
}
pub type BaseTransformClass = ClassStruct<BaseTransform>;
@ -444,7 +444,7 @@ unsafe extern "C" fn base_transform_start<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -460,7 +460,7 @@ unsafe extern "C" fn base_transform_stop<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -479,7 +479,7 @@ unsafe extern "C" fn base_transform_transform_caps<T: BaseTransformBase>(
) -> *mut gst_ffi::GstCaps
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -511,7 +511,7 @@ unsafe extern "C" fn base_transform_fixate_caps<T: BaseTransformBase>(
) -> *mut gst_ffi::GstCaps
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -536,7 +536,7 @@ unsafe extern "C" fn base_transform_set_caps<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -556,7 +556,7 @@ unsafe extern "C" fn base_transform_accept_caps<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -576,7 +576,7 @@ unsafe extern "C" fn base_transform_query<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -604,7 +604,7 @@ unsafe extern "C" fn base_transform_transform_size<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -636,7 +636,7 @@ unsafe extern "C" fn base_transform_get_unit_size<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -661,7 +661,7 @@ unsafe extern "C" fn base_transform_sink_event<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -680,7 +680,7 @@ unsafe extern "C" fn base_transform_src_event<T: BaseTransformBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -700,7 +700,7 @@ unsafe extern "C" fn base_transform_transform<T: BaseTransformBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -723,7 +723,7 @@ unsafe extern "C" fn base_transform_transform_ip<T: BaseTransformBase>(
) -> gst_ffi::GstFlowReturn
where
T::ImplType: BaseTransformImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);

View file

@ -25,7 +25,7 @@ use object::*;
pub trait BinImpl<T: BinBase>:
AnyImpl + ObjectImpl<T> + ElementImpl<T> + Send + Sync + 'static
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn add_element(&self, bin: &T, element: &gst::Element) -> bool {
bin.parent_add_element(element)
@ -79,8 +79,7 @@ pub unsafe trait BinBase: IsA<gst::Element> + IsA<gst::Bin> + ObjectType {
pub unsafe trait BinClassExt<T: BinBase>
where
T::ImplType: BinImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn override_vfuncs(&mut self, _: &ClassInitToken) {
unsafe {
@ -167,7 +166,7 @@ unsafe extern "C" fn bin_add_element<T: BinBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BinImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -186,7 +185,7 @@ unsafe extern "C" fn bin_remove_element<T: BinBase>(
) -> glib_ffi::gboolean
where
T::ImplType: BinImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -204,7 +203,7 @@ unsafe extern "C" fn bin_handle_message<T: BinBase>(
message: *mut gst_ffi::GstMessage,
) where
T::ImplType: BinImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);

View file

@ -26,7 +26,7 @@ use object::*;
pub trait ElementImpl<T: ElementBase>: ObjectImpl<T> + AnyImpl + Send + Sync + 'static
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn change_state(&self, element: &T, transition: gst::StateChange) -> gst::StateChangeReturn {
element.parent_change_state(transition)
@ -68,7 +68,7 @@ pub trait ElementImplExt<T> {
impl<S: ElementImpl<T>, T: ObjectType + glib::IsA<gst::Element> + glib::IsA<gst::Object>>
ElementImplExt<T> for S
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn catch_panic_pad_function<R, F: FnOnce(&Self, &T) -> R, G: FnOnce() -> R>(
parent: &Option<gst::Object>,
@ -88,7 +88,7 @@ any_impl!(ElementBase, ElementImpl, PanicPoison);
pub unsafe trait ElementBase: IsA<gst::Element> + ObjectType
where
Self::InstanceStructType: PanicPoison
Self::InstanceStructType: PanicPoison,
{
fn parent_change_state(&self, transition: gst::StateChange) -> gst::StateChangeReturn {
unsafe {
@ -134,8 +134,7 @@ where
}
}
fn catch_panic<T, F: FnOnce(&Self) -> T, G: FnOnce() -> T>(&self, fallback: G, f: F) -> T
{
fn catch_panic<T, F: FnOnce(&Self) -> T, G: FnOnce() -> T>(&self, fallback: G, f: F) -> T {
let panicked = unsafe { &(*self.get_instance()).panicked() };
panic_to_error!(self, panicked, fallback(), { f(self) })
}
@ -144,7 +143,7 @@ where
pub unsafe trait ElementClassExt<T: ElementBase>
where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn add_pad_template(&mut self, pad_template: gst::PadTemplate) {
unsafe {
@ -173,8 +172,7 @@ where
}
}
fn override_vfuncs(&mut self, _: &ClassInitToken)
{
fn override_vfuncs(&mut self, _: &ClassInitToken) {
unsafe {
let klass = &mut *(self as *const Self as *mut gst_ffi::GstElementClass);
klass.change_state = Some(element_change_state::<T>);
@ -198,7 +196,10 @@ glib_wrapper! {
}
unsafe impl<T: IsA<gst::Element> + ObjectType> ElementBase for T
where Self::InstanceStructType: PanicPoison{}
where
Self::InstanceStructType: PanicPoison,
{
}
pub type ElementClass = ClassStruct<Element>;
@ -256,8 +257,7 @@ macro_rules! box_element_impl(
box_element_impl!(ElementImpl);
impl ObjectType for Element
{
impl ObjectType for Element {
const NAME: &'static str = "RsElement";
type GlibType = gst_ffi::GstElement;
type GlibClassType = gst_ffi::GstElementClass;
@ -281,7 +281,7 @@ unsafe extern "C" fn element_change_state<T: ElementBase>(
) -> gst_ffi::GstStateChangeReturn
where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -312,7 +312,7 @@ unsafe extern "C" fn element_request_new_pad<T: ElementBase>(
) -> *mut gst_ffi::GstPad
where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -347,9 +347,9 @@ where
unsafe extern "C" fn element_release_pad<T: ElementBase>(
ptr: *mut gst_ffi::GstElement,
pad: *mut gst_ffi::GstPad,
)where
) where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -368,7 +368,7 @@ unsafe extern "C" fn element_send_event<T: ElementBase>(
) -> glib_ffi::gboolean
where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -387,7 +387,7 @@ unsafe extern "C" fn element_query<T: ElementBase>(
) -> glib_ffi::gboolean
where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);
@ -396,15 +396,17 @@ where
let imp = element.get_impl();
let query = gst::QueryRef::from_mut_ptr(query);
panic_to_error!(&wrap, &element.panicked(), false, { imp.query(&wrap, query) }).to_glib()
panic_to_error!(&wrap, &element.panicked(), false, {
imp.query(&wrap, query)
}).to_glib()
}
unsafe extern "C" fn element_set_context<T: ElementBase>(
ptr: *mut gst_ffi::GstElement,
context: *mut gst_ffi::GstContext,
)where
) where
T::ImplType: ElementImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
callback_guard!();
floating_reference_guard!(ptr);

View file

@ -25,10 +25,16 @@ extern crate gstreamer_base as gst_base;
#[macro_use]
extern crate gobject_subclass;
#[macro_use]
#[macro_use]
#[macro_use]
#[macro_use]
pub use gobject_subclass::anyimpl;
pub use gobject_subclass::properties;
#[macro_use]
#[macro_use]
#[macro_use]
#[macro_use]
pub use gobject_subclass::guard;

View file

@ -3,24 +3,20 @@ use std::sync::atomic::AtomicBool;
pub use gobject_subclass::object::*;
#[repr(C)]
pub struct ElementInstanceStruct<T: ObjectType>
{
pub struct ElementInstanceStruct<T: ObjectType> {
_parent: T::GlibType,
_imp: ptr::NonNull<T::ImplType>,
_panicked: AtomicBool,
}
pub trait PanicPoison{
pub trait PanicPoison {
fn panicked(&self) -> &AtomicBool;
}
impl<T: ObjectType> Instance<T> for ElementInstanceStruct<T>
{
fn parent(&self) -> &T::GlibType{
impl<T: ObjectType> Instance<T> for ElementInstanceStruct<T> {
fn parent(&self) -> &T::GlibType {
&self._parent
}
@ -28,7 +24,7 @@ impl<T: ObjectType> Instance<T> for ElementInstanceStruct<T>
unsafe { self._imp.as_ref() }
}
unsafe fn set_impl(&mut self, imp:ptr::NonNull<T::ImplType>){
unsafe fn set_impl(&mut self, imp: ptr::NonNull<T::ImplType>) {
self._imp = imp;
}
@ -37,11 +33,8 @@ impl<T: ObjectType> Instance<T> for ElementInstanceStruct<T>
}
}
impl<T: ObjectType> PanicPoison for ElementInstanceStruct<T>
{
fn panicked(&self) -> &AtomicBool{
impl<T: ObjectType> PanicPoison for ElementInstanceStruct<T> {
fn panicked(&self) -> &AtomicBool {
&self._panicked
}
}

View file

@ -26,7 +26,7 @@ use object::*;
pub trait PipelineImpl<T: PipelineBase>:
AnyImpl + ObjectImpl<T> + ElementImpl<T> + BinImpl<T> + Send + Sync + 'static
where
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
}
@ -40,7 +40,7 @@ pub unsafe trait PipelineBase:
pub unsafe trait PipelineClassExt<T: PipelineBase>
where
T::ImplType: PipelineImpl<T>,
T::InstanceStructType: PanicPoison
T::InstanceStructType: PanicPoison,
{
fn override_vfuncs(&mut self, _: &ClassInitToken) {}
}