mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-22 16:16:37 +00:00
Minor cleanup in various places
This commit is contained in:
parent
9d5ae8ed14
commit
8d0fa62275
5 changed files with 44 additions and 95 deletions
|
@ -730,7 +730,7 @@ impl Harness {
|
|||
None
|
||||
} else {
|
||||
Some(Ref(
|
||||
Some(Harness(
|
||||
mem::ManuallyDrop::new(Harness(
|
||||
ptr::NonNull::new_unchecked(sink_harness),
|
||||
PhantomData,
|
||||
)),
|
||||
|
@ -747,7 +747,7 @@ impl Harness {
|
|||
None
|
||||
} else {
|
||||
Some(Ref(
|
||||
Some(Harness(
|
||||
mem::ManuallyDrop::new(Harness(
|
||||
ptr::NonNull::new_unchecked(src_harness),
|
||||
PhantomData,
|
||||
)),
|
||||
|
@ -764,7 +764,7 @@ impl Harness {
|
|||
None
|
||||
} else {
|
||||
Some(RefMut(
|
||||
Some(Harness(
|
||||
mem::ManuallyDrop::new(Harness(
|
||||
ptr::NonNull::new_unchecked(sink_harness),
|
||||
PhantomData,
|
||||
)),
|
||||
|
@ -781,7 +781,7 @@ impl Harness {
|
|||
None
|
||||
} else {
|
||||
Some(RefMut(
|
||||
Some(Harness(
|
||||
mem::ManuallyDrop::new(Harness(
|
||||
ptr::NonNull::new_unchecked(src_harness),
|
||||
PhantomData,
|
||||
)),
|
||||
|
@ -793,44 +793,30 @@ impl Harness {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Ref<'a>(Option<Harness>, PhantomData<&'a Harness>);
|
||||
pub struct Ref<'a>(mem::ManuallyDrop<Harness>, PhantomData<&'a Harness>);
|
||||
|
||||
impl<'a> ops::Deref for Ref<'a> {
|
||||
type Target = Harness;
|
||||
|
||||
fn deref(&self) -> &Harness {
|
||||
self.0.as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for Ref<'a> {
|
||||
fn drop(&mut self) {
|
||||
// We only really borrow
|
||||
mem::forget(self.0.take())
|
||||
&*self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RefMut<'a>(Option<Harness>, PhantomData<&'a mut Harness>);
|
||||
pub struct RefMut<'a>(mem::ManuallyDrop<Harness>, PhantomData<&'a mut Harness>);
|
||||
|
||||
impl<'a> ops::Deref for RefMut<'a> {
|
||||
type Target = Harness;
|
||||
|
||||
fn deref(&self) -> &Harness {
|
||||
self.0.as_ref().unwrap()
|
||||
&*self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> ops::DerefMut for RefMut<'a> {
|
||||
fn deref_mut(&mut self) -> &mut Harness {
|
||||
self.0.as_mut().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for RefMut<'a> {
|
||||
fn drop(&mut self) {
|
||||
// We only really borrow
|
||||
mem::forget(self.0.take())
|
||||
&mut *self.0
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1435,11 +1435,8 @@ impl<'a> NavigationBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_navigation(structure.to_glib_none().0);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_navigation(structure.into_ptr())
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1553,14 +1550,8 @@ impl<'a> CustomUpstreamBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_custom(
|
||||
gst_sys::GST_EVENT_CUSTOM_UPSTREAM,
|
||||
structure.to_glib_none().0,
|
||||
);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_custom(gst_sys::GST_EVENT_CUSTOM_UPSTREAM, structure.into_ptr())
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1578,14 +1569,8 @@ impl<'a> CustomDownstreamBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_custom(
|
||||
gst_sys::GST_EVENT_CUSTOM_DOWNSTREAM,
|
||||
structure.to_glib_none().0,
|
||||
);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_custom(gst_sys::GST_EVENT_CUSTOM_DOWNSTREAM, structure.into_ptr())
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1603,14 +1588,11 @@ impl<'a> CustomDownstreamOobBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_custom(
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_custom(
|
||||
gst_sys::GST_EVENT_CUSTOM_DOWNSTREAM_OOB,
|
||||
structure.to_glib_none().0,
|
||||
);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
structure.into_ptr(),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1628,14 +1610,11 @@ impl<'a> CustomDownstreamStickyBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_custom(
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_custom(
|
||||
gst_sys::GST_EVENT_CUSTOM_DOWNSTREAM_STICKY,
|
||||
structure.to_glib_none().0,
|
||||
);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
structure.into_ptr(),
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1653,14 +1632,8 @@ impl<'a> CustomBothBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_custom(
|
||||
gst_sys::GST_EVENT_CUSTOM_BOTH,
|
||||
structure.to_glib_none().0,
|
||||
);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_custom(gst_sys::GST_EVENT_CUSTOM_BOTH, structure.into_ptr())
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1678,14 +1651,8 @@ impl<'a> CustomBothOobBuilder<'a> {
|
|||
}
|
||||
|
||||
event_builder_generic_impl!(|s: &mut Self| {
|
||||
let structure = s.structure.take();
|
||||
let ev = gst_sys::gst_event_new_custom(
|
||||
gst_sys::GST_EVENT_CUSTOM_BOTH_OOB,
|
||||
structure.to_glib_none().0,
|
||||
);
|
||||
mem::forget(structure);
|
||||
|
||||
ev
|
||||
let structure = s.structure.take().unwrap();
|
||||
gst_sys::gst_event_new_custom(gst_sys::GST_EVENT_CUSTOM_BOTH_OOB, structure.into_ptr())
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,12 @@ impl<T> Iterator<T>
|
|||
where
|
||||
for<'a> T: FromValueOptional<'a> + 'static,
|
||||
{
|
||||
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstIterator {
|
||||
let it = self.to_glib_none().0;
|
||||
mem::forget(self);
|
||||
it as *mut _
|
||||
}
|
||||
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn next(&mut self) -> Result<Option<T>, IteratorError> {
|
||||
unsafe {
|
||||
|
@ -72,9 +78,6 @@ where
|
|||
F: Fn(T) -> bool + Send + Sync + 'static,
|
||||
{
|
||||
unsafe {
|
||||
let it = self.to_glib_none().0;
|
||||
mem::forget(self);
|
||||
|
||||
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(
|
||||
|
@ -83,7 +86,7 @@ where
|
|||
);
|
||||
|
||||
from_glib_full(gst_sys::gst_iterator_filter(
|
||||
it as *mut _,
|
||||
self.into_ptr(),
|
||||
Some(filter_trampoline::<T>),
|
||||
closure_value.to_glib_none().0,
|
||||
))
|
||||
|
@ -189,7 +192,7 @@ where
|
|||
|
||||
{
|
||||
let it = it as *mut RsIterator<T, I>;
|
||||
(*it).imp = Some(imp);
|
||||
ptr::write(&mut (*it).imp, imp);
|
||||
}
|
||||
|
||||
from_glib_full(it)
|
||||
|
@ -212,7 +215,7 @@ where
|
|||
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
|
||||
{
|
||||
iter: gst_sys::GstIterator,
|
||||
imp: Option<I>,
|
||||
imp: I,
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
||||
|
@ -241,7 +244,7 @@ where
|
|||
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
|
||||
{
|
||||
let it = it as *mut RsIterator<T, I>;
|
||||
let _ = (*it).imp.take();
|
||||
ptr::drop_in_place(&mut (*it).imp);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn rs_iterator_next<T, I: IteratorImpl<T>>(
|
||||
|
@ -252,11 +255,10 @@ where
|
|||
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
|
||||
{
|
||||
let it = it as *mut RsIterator<T, I>;
|
||||
match (*it).imp.as_mut().map(|imp| imp.next()).unwrap() {
|
||||
match (*it).imp.next() {
|
||||
Some(Ok(value)) => {
|
||||
let value = value.to_value();
|
||||
ptr::write(result, ptr::read(value.to_glib_none().0));
|
||||
mem::forget(value);
|
||||
ptr::write(result, value.into_raw());
|
||||
gst_sys::GST_ITERATOR_OK
|
||||
}
|
||||
None => gst_sys::GST_ITERATOR_DONE,
|
||||
|
@ -272,7 +274,7 @@ where
|
|||
for<'a> T: FromValueOptional<'a> + StaticType + ToValue + Send + 'static,
|
||||
{
|
||||
let it = it as *mut RsIterator<T, I>;
|
||||
(*it).imp.as_mut().map(|imp| imp.resync()).unwrap();
|
||||
(*it).imp.resync();
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
@ -1316,10 +1316,8 @@ where
|
|||
&Pad::from_glib_borrow(pad).unsafe_cast(),
|
||||
Option::<::Object>::from_glib_borrow(parent).as_ref(),
|
||||
);
|
||||
let ptr = ret.to_glib_none().0;
|
||||
mem::forget(ret);
|
||||
|
||||
ptr as *mut _
|
||||
ret.into_ptr()
|
||||
}
|
||||
|
||||
unsafe extern "C" fn trampoline_link_function<
|
||||
|
|
|
@ -420,14 +420,10 @@ impl StructureRef {
|
|||
self.set_value(name, value);
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, name: &str, mut value: SendValue) {
|
||||
pub fn set_value(&mut self, name: &str, value: SendValue) {
|
||||
unsafe {
|
||||
gst_sys::gst_structure_take_value(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
value.to_glib_none_mut().0,
|
||||
);
|
||||
mem::forget(value);
|
||||
let mut value = value.into_raw();
|
||||
gst_sys::gst_structure_take_value(&mut self.0, name.to_glib_none().0, &mut value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue