mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
gstreamer-base: Add basesrc alloc() vfunc
This commit is contained in:
parent
68332e854e
commit
13411b7461
1 changed files with 77 additions and 0 deletions
|
@ -64,6 +64,15 @@ pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl + Send + Sync + 'static {
|
||||||
self.parent_fill(element, offset, length, buffer)
|
self.parent_fill(element, offset, length, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn alloc(
|
||||||
|
&self,
|
||||||
|
element: &BaseSrc,
|
||||||
|
offset: u64,
|
||||||
|
length: u32,
|
||||||
|
) -> Result<gst::Buffer, gst::FlowError> {
|
||||||
|
self.parent_alloc(element, offset, length)
|
||||||
|
}
|
||||||
|
|
||||||
fn create(
|
fn create(
|
||||||
&self,
|
&self,
|
||||||
element: &BaseSrc,
|
element: &BaseSrc,
|
||||||
|
@ -134,6 +143,13 @@ pub trait BaseSrcImplExt {
|
||||||
buffer: &mut gst::BufferRef,
|
buffer: &mut gst::BufferRef,
|
||||||
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
||||||
|
|
||||||
|
fn parent_alloc(
|
||||||
|
&self,
|
||||||
|
element: &BaseSrc,
|
||||||
|
offset: u64,
|
||||||
|
length: u32,
|
||||||
|
) -> Result<gst::Buffer, gst::FlowError>;
|
||||||
|
|
||||||
fn parent_create(
|
fn parent_create(
|
||||||
&self,
|
&self,
|
||||||
element: &BaseSrc,
|
element: &BaseSrc,
|
||||||
|
@ -294,6 +310,37 @@ impl<T: BaseSrcImpl + ObjectImpl> BaseSrcImplExt for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parent_alloc(
|
||||||
|
&self,
|
||||||
|
element: &BaseSrc,
|
||||||
|
offset: u64,
|
||||||
|
length: u32,
|
||||||
|
) -> Result<gst::Buffer, gst::FlowError> {
|
||||||
|
unsafe {
|
||||||
|
let data = self.get_type_data();
|
||||||
|
let parent_class =
|
||||||
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSrcClass;
|
||||||
|
(*parent_class)
|
||||||
|
.alloc
|
||||||
|
.map(|f| {
|
||||||
|
let mut buffer_ptr: *mut gst_sys::GstBuffer = ptr::null_mut();
|
||||||
|
|
||||||
|
// FIXME: Wrong signature in -sys bindings
|
||||||
|
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
|
||||||
|
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst_sys::GstBuffer;
|
||||||
|
|
||||||
|
let res = gst::FlowReturn::from_glib(f(
|
||||||
|
element.to_glib_none().0,
|
||||||
|
offset,
|
||||||
|
length,
|
||||||
|
buffer_ref,
|
||||||
|
));
|
||||||
|
res.into_result_value(|| from_glib_full(buffer_ref))
|
||||||
|
})
|
||||||
|
.unwrap_or(Err(gst::FlowError::NotSupported))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parent_create(
|
fn parent_create(
|
||||||
&self,
|
&self,
|
||||||
element: &BaseSrc,
|
element: &BaseSrc,
|
||||||
|
@ -538,6 +585,7 @@ where
|
||||||
klass.get_size = Some(base_src_get_size::<T>);
|
klass.get_size = Some(base_src_get_size::<T>);
|
||||||
klass.get_times = Some(base_src_get_times::<T>);
|
klass.get_times = Some(base_src_get_times::<T>);
|
||||||
klass.fill = Some(base_src_fill::<T>);
|
klass.fill = Some(base_src_fill::<T>);
|
||||||
|
klass.alloc = Some(base_src_alloc::<T>);
|
||||||
klass.create = Some(base_src_create::<T>);
|
klass.create = Some(base_src_create::<T>);
|
||||||
klass.do_seek = Some(base_src_do_seek::<T>);
|
klass.do_seek = Some(base_src_do_seek::<T>);
|
||||||
klass.query = Some(base_src_query::<T>);
|
klass.query = Some(base_src_query::<T>);
|
||||||
|
@ -684,6 +732,35 @@ where
|
||||||
.to_glib()
|
.to_glib()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn base_src_alloc<T: ObjectSubclass>(
|
||||||
|
ptr: *mut gst_base_sys::GstBaseSrc,
|
||||||
|
offset: u64,
|
||||||
|
length: u32,
|
||||||
|
buffer_ptr: *mut gst_sys::GstBuffer,
|
||||||
|
) -> gst_sys::GstFlowReturn
|
||||||
|
where
|
||||||
|
T: BaseSrcImpl,
|
||||||
|
T::Instance: PanicPoison,
|
||||||
|
{
|
||||||
|
let instance = &*(ptr as *mut T::Instance);
|
||||||
|
let imp = instance.get_impl();
|
||||||
|
let wrap: BaseSrc = from_glib_borrow(ptr);
|
||||||
|
// FIXME: Wrong signature in -sys bindings
|
||||||
|
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
|
||||||
|
let buffer_ptr = buffer_ptr as *mut *mut gst_sys::GstBuffer;
|
||||||
|
|
||||||
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
||||||
|
match imp.alloc(&wrap, offset, length) {
|
||||||
|
Ok(buffer) => {
|
||||||
|
*buffer_ptr = buffer.into_ptr();
|
||||||
|
gst::FlowReturn::Ok
|
||||||
|
}
|
||||||
|
Err(err) => gst::FlowReturn::from(err),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.to_glib()
|
||||||
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn base_src_create<T: ObjectSubclass>(
|
unsafe extern "C" fn base_src_create<T: ObjectSubclass>(
|
||||||
ptr: *mut gst_base_sys::GstBaseSrc,
|
ptr: *mut gst_base_sys::GstBaseSrc,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
|
|
Loading…
Reference in a new issue