2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2020-11-14 16:01:13 +00:00
|
|
|
use glib::prelude::*;
|
2018-11-20 21:23:31 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
|
|
|
|
use std::ptr;
|
|
|
|
|
2020-11-21 17:59:22 +00:00
|
|
|
use crate::BaseSink;
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl {
|
2022-10-08 18:50:06 +00:00
|
|
|
fn start(&self) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_start()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn stop(&self) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_stop()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn render(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_render(buffer)
|
2019-12-18 11:07:42 +00:00
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn prepare(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_prepare(buffer)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn render_list(&self, list: &gst::BufferList) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_render_list(list)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn prepare_list(&self, list: &gst::BufferList) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_prepare_list(list)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn query(&self, query: &mut gst::QueryRef) -> bool {
|
|
|
|
BaseSinkImplExt::parent_query(self, query)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn event(&self, event: gst::Event) -> bool {
|
|
|
|
self.parent_event(event)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
|
|
|
|
self.parent_caps(filter)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
|
|
|
|
self.parent_set_caps(caps)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn fixate(&self, caps: gst::Caps) -> gst::Caps {
|
|
|
|
self.parent_fixate(caps)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn unlock(&self) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_unlock()
|
2019-02-02 16:11:30 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_unlock_stop()
|
2019-02-02 16:11:30 +00:00
|
|
|
}
|
2021-10-16 10:53:57 +00:00
|
|
|
|
|
|
|
fn propose_allocation(
|
|
|
|
&self,
|
2022-01-18 09:57:22 +00:00
|
|
|
query: &mut gst::query::Allocation,
|
2021-12-06 16:41:39 +00:00
|
|
|
) -> Result<(), gst::LoggableError> {
|
2022-10-08 18:50:06 +00:00
|
|
|
self.parent_propose_allocation(query)
|
2021-10-16 10:53:57 +00:00
|
|
|
}
|
2019-02-12 14:23:30 +00:00
|
|
|
}
|
2019-02-02 16:11:30 +00:00
|
|
|
|
2020-11-14 16:01:13 +00:00
|
|
|
pub trait BaseSinkImplExt: ObjectSubclass {
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_start(&self) -> Result<(), gst::ErrorMessage>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_stop(&self) -> Result<(), gst::ErrorMessage>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_render(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_prepare(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
|
|
|
fn parent_render_list(
|
|
|
|
&self,
|
2019-05-23 11:28:09 +00:00
|
|
|
list: &gst::BufferList,
|
2019-02-12 14:23:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
|
|
|
fn parent_prepare_list(
|
|
|
|
&self,
|
2019-05-23 11:28:09 +00:00
|
|
|
list: &gst::BufferList,
|
2019-02-12 14:23:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_query(&self, query: &mut gst::QueryRef) -> bool;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_event(&self, event: gst::Event) -> bool;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_fixate(&self, caps: gst::Caps) -> gst::Caps;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_unlock(&self) -> Result<(), gst::ErrorMessage>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_unlock_stop(&self) -> Result<(), gst::ErrorMessage>;
|
2021-10-16 10:53:57 +00:00
|
|
|
|
|
|
|
fn parent_propose_allocation(
|
|
|
|
&self,
|
2022-01-18 09:57:22 +00:00
|
|
|
query: &mut gst::query::Allocation,
|
2021-12-06 16:41:39 +00:00
|
|
|
) -> Result<(), gst::LoggableError>;
|
2019-02-12 14:23:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
impl<T: BaseSinkImpl> BaseSinkImplExt for T {
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_start(&self) -> Result<(), gst::ErrorMessage> {
|
2019-02-02 16:11:30 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.start
|
|
|
|
.map(|f| {
|
2022-10-23 19:59:23 +00:00
|
|
|
if from_glib(f(self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0)) {
|
2019-02-02 16:11:30 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-02-02 16:11:30 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `start` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_stop(&self) -> Result<(), gst::ErrorMessage> {
|
2019-02-02 16:11:30 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.stop
|
|
|
|
.map(|f| {
|
2022-10-23 19:59:23 +00:00
|
|
|
if from_glib(f(self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0)) {
|
2019-02-02 16:11:30 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-02-02 16:11:30 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `stop` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_render(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-02-02 16:11:30 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.render
|
|
|
|
.map(|f| {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
buffer.to_glib_none().0,
|
|
|
|
))
|
2019-02-02 16:11:30 +00:00
|
|
|
})
|
2021-04-28 12:34:56 +00:00
|
|
|
.unwrap_or(Ok(gst::FlowSuccess::Ok))
|
2019-02-02 16:11:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_prepare(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-02-02 16:11:30 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.prepare
|
2020-11-14 16:01:13 +00:00
|
|
|
.map(|f| {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
buffer.to_glib_none().0,
|
|
|
|
))
|
|
|
|
})
|
2021-04-28 12:34:56 +00:00
|
|
|
.unwrap_or(Ok(gst::FlowSuccess::Ok))
|
2019-02-02 16:11:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_render_list(
|
|
|
|
&self,
|
2019-05-23 11:28:09 +00:00
|
|
|
list: &gst::BufferList,
|
2019-02-02 16:11:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.render_list
|
|
|
|
.map(|f| {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
list.to_glib_none().0,
|
|
|
|
))
|
2019-02-02 16:11:30 +00:00
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
for buffer in list.iter() {
|
2022-10-08 18:50:06 +00:00
|
|
|
self.render(&from_glib_borrow(buffer.as_ptr()))?;
|
2019-02-02 16:11:30 +00:00
|
|
|
}
|
|
|
|
Ok(gst::FlowSuccess::Ok)
|
|
|
|
})
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 16:11:30 +00:00
|
|
|
fn parent_prepare_list(
|
|
|
|
&self,
|
2019-05-23 11:28:09 +00:00
|
|
|
list: &gst::BufferList,
|
2019-02-02 16:11:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.prepare_list
|
|
|
|
.map(|f| {
|
2021-05-13 12:54:41 +00:00
|
|
|
try_from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
list.to_glib_none().0,
|
|
|
|
))
|
2019-02-02 16:11:30 +00:00
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
for buffer in list.iter() {
|
2022-10-08 18:50:06 +00:00
|
|
|
self.prepare(&from_glib_borrow(buffer.as_ptr()))?;
|
2019-02-02 16:11:30 +00:00
|
|
|
}
|
|
|
|
Ok(gst::FlowSuccess::Ok)
|
|
|
|
})
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_query(&self, query: &mut gst::QueryRef) -> bool {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
(*parent_class)
|
|
|
|
.query
|
2020-11-14 16:01:13 +00:00
|
|
|
.map(|f| {
|
|
|
|
from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
|
|
|
})
|
2018-11-20 21:23:31 +00:00
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_event(&self, event: gst::Event) -> bool {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
(*parent_class)
|
|
|
|
.event
|
2020-11-14 16:01:13 +00:00
|
|
|
.map(|f| {
|
|
|
|
from_glib(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
event.into_glib_ptr(),
|
2020-11-14 16:01:13 +00:00
|
|
|
))
|
|
|
|
})
|
2019-02-01 14:07:42 +00:00
|
|
|
.unwrap_or(true)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_caps(&self, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
(*parent_class)
|
|
|
|
.get_caps
|
2020-11-14 16:01:13 +00:00
|
|
|
.map(|f| {
|
|
|
|
from_glib_full(f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
filter.to_glib_none().0,
|
|
|
|
))
|
|
|
|
})
|
2018-11-20 21:23:31 +00:00
|
|
|
.unwrap_or(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_set_caps(&self, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-01 14:07:42 +00:00
|
|
|
(*parent_class)
|
|
|
|
.set_caps
|
|
|
|
.map(|f| {
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::result_from_gboolean!(
|
2020-11-14 16:01:13 +00:00
|
|
|
f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2020-11-14 16:01:13 +00:00
|
|
|
caps.to_glib_none().0
|
|
|
|
),
|
2019-02-01 14:07:42 +00:00
|
|
|
gst::CAT_RUST,
|
|
|
|
"Parent function `set_caps` failed"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_fixate(&self, caps: gst::Caps) -> gst::Caps {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
match (*parent_class).fixate {
|
2020-11-14 16:01:13 +00:00
|
|
|
Some(fixate) => from_glib_full(fixate(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2022-05-06 19:41:15 +00:00
|
|
|
caps.into_glib_ptr(),
|
2020-11-14 16:01:13 +00:00
|
|
|
)),
|
2018-11-20 21:23:31 +00:00
|
|
|
None => caps,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-02 16:11:30 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_unlock(&self) -> Result<(), gst::ErrorMessage> {
|
2019-02-02 16:11:30 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.unlock
|
|
|
|
.map(|f| {
|
2022-10-23 19:59:23 +00:00
|
|
|
if from_glib(f(self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0)) {
|
2019-02-02 16:11:30 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-02-02 16:11:30 +00:00
|
|
|
gst::CoreError::Failed,
|
|
|
|
["Parent function `unlock` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
fn parent_unlock_stop(&self) -> Result<(), gst::ErrorMessage> {
|
2019-02-02 16:11:30 +00:00
|
|
|
unsafe {
|
2021-04-29 20:06:41 +00:00
|
|
|
let data = Self::type_data();
|
2021-04-11 19:39:50 +00:00
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.unlock_stop
|
|
|
|
.map(|f| {
|
2022-10-23 19:59:23 +00:00
|
|
|
if from_glib(f(self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0)) {
|
2019-02-02 16:11:30 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-02-02 16:11:30 +00:00
|
|
|
gst::CoreError::Failed,
|
|
|
|
["Parent function `unlock_stop` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
2021-10-16 10:53:57 +00:00
|
|
|
|
|
|
|
fn parent_propose_allocation(
|
|
|
|
&self,
|
2022-01-18 09:57:22 +00:00
|
|
|
query: &mut gst::query::Allocation,
|
2021-12-06 16:41:39 +00:00
|
|
|
) -> Result<(), gst::LoggableError> {
|
2021-10-16 10:53:57 +00:00
|
|
|
unsafe {
|
|
|
|
let data = Self::type_data();
|
|
|
|
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSinkClass;
|
|
|
|
(*parent_class)
|
|
|
|
.propose_allocation
|
|
|
|
.map(|f| {
|
2021-12-06 16:41:39 +00:00
|
|
|
gst::result_from_gboolean!(
|
|
|
|
f(
|
2022-10-23 19:59:23 +00:00
|
|
|
self.obj().unsafe_cast_ref::<BaseSink>().to_glib_none().0,
|
2021-12-06 16:41:39 +00:00
|
|
|
query.as_mut_ptr(),
|
|
|
|
),
|
|
|
|
gst::CAT_RUST,
|
|
|
|
"Parent function `propose_allocation` failed",
|
|
|
|
)
|
2021-10-16 10:53:57 +00:00
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-09 13:37:05 +00:00
|
|
|
unsafe impl<T: BaseSinkImpl> IsSubclassable<T> for BaseSink {
|
2021-03-08 10:06:56 +00:00
|
|
|
fn class_init(klass: &mut glib::Class<Self>) {
|
2021-08-24 05:55:37 +00:00
|
|
|
Self::parent_class_init::<T>(klass);
|
2020-11-05 17:07:31 +00:00
|
|
|
let klass = klass.as_mut();
|
|
|
|
klass.start = Some(base_sink_start::<T>);
|
|
|
|
klass.stop = Some(base_sink_stop::<T>);
|
|
|
|
klass.render = Some(base_sink_render::<T>);
|
|
|
|
klass.render_list = Some(base_sink_render_list::<T>);
|
|
|
|
klass.prepare = Some(base_sink_prepare::<T>);
|
|
|
|
klass.prepare_list = Some(base_sink_prepare_list::<T>);
|
|
|
|
klass.query = Some(base_sink_query::<T>);
|
|
|
|
klass.event = Some(base_sink_event::<T>);
|
|
|
|
klass.get_caps = Some(base_sink_get_caps::<T>);
|
|
|
|
klass.set_caps = Some(base_sink_set_caps::<T>);
|
|
|
|
klass.fixate = Some(base_sink_fixate::<T>);
|
|
|
|
klass.unlock = Some(base_sink_unlock::<T>);
|
|
|
|
klass.unlock_stop = Some(base_sink_unlock_stop::<T>);
|
2021-10-16 10:53:57 +00:00
|
|
|
klass.propose_allocation = Some(base_sink_propose_allocation::<T>);
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_start<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, {
|
|
|
|
match imp.start() {
|
2019-01-26 14:22:06 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_stop<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, {
|
|
|
|
match imp.stop() {
|
2019-01-26 14:22:06 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_render<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
buffer: *mut gst::ffi::GstBuffer,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> gst::ffi::GstFlowReturn {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2019-05-23 11:28:09 +00:00
|
|
|
let buffer = from_glib_borrow(buffer);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.render(&buffer).into() }).into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_prepare<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
buffer: *mut gst::ffi::GstBuffer,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> gst::ffi::GstFlowReturn {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2019-05-23 11:28:09 +00:00
|
|
|
let buffer = from_glib_borrow(buffer);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, gst::FlowReturn::Error, { imp.prepare(&buffer).into() }).into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_render_list<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
list: *mut gst::ffi::GstBufferList,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> gst::ffi::GstFlowReturn {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2019-05-23 11:28:09 +00:00
|
|
|
let list = from_glib_borrow(list);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, gst::FlowReturn::Error, {
|
|
|
|
imp.render_list(&list).into()
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_prepare_list<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
list: *mut gst::ffi::GstBufferList,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> gst::ffi::GstFlowReturn {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2019-05-23 11:28:09 +00:00
|
|
|
let list = from_glib_borrow(list);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, gst::FlowReturn::Error, {
|
|
|
|
imp.prepare_list(&list).into()
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_query<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
query_ptr: *mut gst::ffi::GstQuery,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
let query = gst::QueryRef::from_mut_ptr(query_ptr);
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, { BaseSinkImpl::query(imp, query) }).into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_event<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
event_ptr: *mut gst::ffi::GstEvent,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, { imp.event(from_glib_full(event_ptr)) }).into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_get_caps<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
filter: *mut gst::ffi::GstCaps,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> *mut gst::ffi::GstCaps {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2019-05-23 11:28:09 +00:00
|
|
|
let filter = Option::<gst::Caps>::from_glib_borrow(filter);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, None, { imp.caps(filter.as_ref().as_ref()) })
|
|
|
|
.map(|caps| caps.into_glib_ptr())
|
|
|
|
.unwrap_or(ptr::null_mut())
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_set_caps<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
caps: *mut gst::ffi::GstCaps,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2019-05-23 11:28:09 +00:00
|
|
|
let caps = from_glib_borrow(caps);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, {
|
|
|
|
match imp.set_caps(&caps) {
|
2019-01-26 13:54:48 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2022-10-08 18:50:06 +00:00
|
|
|
err.log_with_imp(imp);
|
2019-01-26 13:54:48 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_fixate<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
caps: *mut gst::ffi::GstCaps,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> *mut gst::ffi::GstCaps {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
let caps = from_glib_full(caps);
|
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, gst::Caps::new_empty(), { imp.fixate(caps) }).into_glib_ptr()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_unlock<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, {
|
|
|
|
match imp.unlock() {
|
2019-01-26 14:22:06 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_unlock_stop<T: BaseSinkImpl>(
|
2020-11-21 17:59:22 +00:00
|
|
|
ptr: *mut ffi::GstBaseSink,
|
2021-03-09 13:37:05 +00:00
|
|
|
) -> glib::ffi::gboolean {
|
2018-11-20 21:23:31 +00:00
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, {
|
|
|
|
match imp.unlock_stop() {
|
2019-01-26 14:22:06 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2022-10-08 18:50:06 +00:00
|
|
|
imp.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
2021-04-27 15:15:46 +00:00
|
|
|
.into_glib()
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
2021-10-16 10:53:57 +00:00
|
|
|
|
|
|
|
unsafe extern "C" fn base_sink_propose_allocation<T: BaseSinkImpl>(
|
|
|
|
ptr: *mut ffi::GstBaseSink,
|
|
|
|
query: *mut gst::ffi::GstQuery,
|
|
|
|
) -> glib::ffi::gboolean {
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
2021-12-28 15:50:06 +00:00
|
|
|
let imp = instance.imp();
|
2021-10-16 11:12:50 +00:00
|
|
|
let query = match gst::QueryRef::from_mut_ptr(query).view_mut() {
|
2022-01-18 09:57:22 +00:00
|
|
|
gst::QueryViewMut::Allocation(allocation) => allocation,
|
2021-10-16 11:12:50 +00:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2021-10-16 10:53:57 +00:00
|
|
|
|
2022-10-08 18:50:06 +00:00
|
|
|
gst::panic_to_error!(imp, false, {
|
|
|
|
match imp.propose_allocation(query) {
|
2021-10-16 10:53:57 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2022-10-08 18:50:06 +00:00
|
|
|
err.log_with_imp(imp);
|
2021-10-16 10:53:57 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.into_glib()
|
|
|
|
}
|