gstreamer: Allow borrowing Segments from Values without copying

This commit is contained in:
Sebastian Dröge 2022-06-27 22:19:42 +03:00
parent c9d07219c8
commit 20ac231146
3 changed files with 19 additions and 2 deletions

View file

@ -245,7 +245,7 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
let f: &F = &*(f as *const F);
f(
Aggregator::from_glib_borrow(this).unsafe_cast_ref(),
&gst::Segment::from_glib_borrow(segment),
gst::Segment::from_ptr(segment),
from_glib(pts),
from_glib(dts),
from_glib(duration),

View file

@ -173,7 +173,7 @@ impl SampleRef {
if ptr.is_null() {
None
} else {
Some(&*(ptr as *const crate::Segment))
Some(crate::Segment::from_ptr(ptr))
}
}
}

View file

@ -18,6 +18,11 @@ pub type Segment = FormattedSegment<GenericFormattedValue>;
pub struct FormattedSegment<T: FormattedValueIntrinsic>(ffi::GstSegment, PhantomData<T>);
impl Segment {
pub unsafe fn from_ptr<'a>(ptr: *const ffi::GstSegment) -> &'a Segment {
assert!(!ptr.is_null());
&*(ptr as *const Self)
}
pub fn reset_with_format(&mut self, format: Format) {
unsafe {
ffi::gst_segment_init(self.to_glib_none_mut().0, format.into_glib());
@ -649,6 +654,18 @@ unsafe impl<'a> glib::value::FromValue<'a> for Segment {
}
}
#[doc(hidden)]
unsafe impl<'a> glib::value::FromValue<'a> for &'a Segment {
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
unsafe fn from_value(value: &'a glib::Value) -> Self {
skip_assert_initialized!();
Segment::from_ptr(
glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0) as *const ffi::GstSegment
)
}
}
#[doc(hidden)]
impl<T: FormattedValueIntrinsic> glib::value::ToValue for FormattedSegment<T> {
fn to_value(&self) -> glib::Value {