2019-02-01 14:07:42 +00:00
|
|
|
// Copyright (C) 2017-2019 Sebastian Dröge <sebastian@centricular.com>
|
2018-11-20 21:23:31 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
use glib_sys;
|
|
|
|
use gst_base_sys;
|
|
|
|
use gst_sys;
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
use glib::subclass::prelude::*;
|
2018-11-20 21:23:31 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use gst;
|
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
|
|
|
|
use std::ptr;
|
|
|
|
|
|
|
|
use BaseSink;
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait BaseSinkImpl: BaseSinkImplExt + ElementImpl {
|
2019-02-02 16:11:30 +00:00
|
|
|
fn start(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_start(element)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-02 16:11:30 +00:00
|
|
|
fn stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_stop(element)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn render(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer: &gst::Buffer,
|
2019-12-18 11:07:42 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_render(element, buffer)
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn prepare(
|
|
|
|
&self,
|
2019-02-02 16:11:30 +00:00
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer: &gst::Buffer,
|
2019-01-08 16:13:37 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-02-02 16:11:30 +00:00
|
|
|
self.parent_prepare(element, buffer)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn render_list(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
list: &gst::BufferList,
|
2019-01-08 16:13:37 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-02-02 16:11:30 +00:00
|
|
|
self.parent_render_list(element, list)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2019-01-08 16:13:37 +00:00
|
|
|
fn prepare_list(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
list: &gst::BufferList,
|
2019-01-08 16:13:37 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-02-02 16:11:30 +00:00
|
|
|
self.parent_prepare_list(element, list)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool {
|
2019-02-12 14:23:30 +00:00
|
|
|
BaseSinkImplExt::parent_query(self, element, query)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn event(&self, element: &BaseSink, event: gst::Event) -> bool {
|
|
|
|
self.parent_event(element, event)
|
|
|
|
}
|
|
|
|
|
2019-05-23 11:28:09 +00:00
|
|
|
fn get_caps(&self, element: &BaseSink, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
|
2018-11-20 21:23:31 +00:00
|
|
|
self.parent_get_caps(element, filter)
|
|
|
|
}
|
|
|
|
|
2019-05-23 11:28:09 +00:00
|
|
|
fn set_caps(&self, element: &BaseSink, caps: &gst::Caps) -> Result<(), gst::LoggableError> {
|
2018-11-20 21:23:31 +00:00
|
|
|
self.parent_set_caps(element, caps)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fixate(&self, element: &BaseSink, caps: gst::Caps) -> gst::Caps {
|
|
|
|
self.parent_fixate(element, caps)
|
|
|
|
}
|
|
|
|
|
2019-02-02 16:11:30 +00:00
|
|
|
fn unlock(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_unlock(element)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unlock_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_unlock_stop(element)
|
|
|
|
}
|
2019-02-12 14:23:30 +00:00
|
|
|
}
|
2019-02-02 16:11:30 +00:00
|
|
|
|
2019-02-12 14:23:30 +00:00
|
|
|
pub trait BaseSinkImplExt {
|
|
|
|
fn parent_start(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>;
|
|
|
|
|
|
|
|
fn parent_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>;
|
|
|
|
|
|
|
|
fn parent_render(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer: &gst::Buffer,
|
2019-02-12 14:23:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
|
|
|
fn parent_prepare(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer: &gst::Buffer,
|
2019-02-12 14:23:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
|
|
|
fn parent_render_list(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
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,
|
|
|
|
element: &BaseSink,
|
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_query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool;
|
|
|
|
|
|
|
|
fn parent_event(&self, element: &BaseSink, event: gst::Event) -> bool;
|
|
|
|
|
2019-05-23 11:28:09 +00:00
|
|
|
fn parent_get_caps(&self, element: &BaseSink, filter: Option<&gst::Caps>) -> Option<gst::Caps>;
|
2019-02-12 14:23:30 +00:00
|
|
|
|
|
|
|
fn parent_set_caps(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
caps: &gst::Caps,
|
2019-02-12 14:23:30 +00:00
|
|
|
) -> Result<(), gst::LoggableError>;
|
|
|
|
|
|
|
|
fn parent_fixate(&self, element: &BaseSink, caps: gst::Caps) -> gst::Caps;
|
|
|
|
|
|
|
|
fn parent_unlock(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>;
|
|
|
|
|
|
|
|
fn parent_unlock_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage>;
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
impl<T: BaseSinkImpl> BaseSinkImplExt for T {
|
2019-02-02 16:11:30 +00:00
|
|
|
fn parent_start(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.start
|
|
|
|
.map(|f| {
|
|
|
|
if from_glib(f(element.to_glib_none().0)) {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(gst_error_msg!(
|
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `start` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.stop
|
|
|
|
.map(|f| {
|
|
|
|
if from_glib(f(element.to_glib_none().0)) {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(gst_error_msg!(
|
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `stop` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_render(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer: &gst::Buffer,
|
2019-02-02 16:11:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.render
|
|
|
|
.map(|f| {
|
2019-05-23 11:28:09 +00:00
|
|
|
gst::FlowReturn::from_glib(f(element.to_glib_none().0, buffer.to_glib_none().0))
|
2019-02-02 16:11:30 +00:00
|
|
|
})
|
|
|
|
.unwrap_or(gst::FlowReturn::Ok)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_prepare(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
buffer: &gst::Buffer,
|
2019-02-02 16:11:30 +00:00
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.prepare
|
2019-05-23 11:28:09 +00:00
|
|
|
.map(|f| from_glib(f(element.to_glib_none().0, buffer.to_glib_none().0)))
|
2019-02-02 16:11:30 +00:00
|
|
|
.unwrap_or(gst::FlowReturn::Ok)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_render_list(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
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 {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.render_list
|
|
|
|
.map(|f| {
|
2019-05-23 11:28:09 +00:00
|
|
|
gst::FlowReturn::from_glib(f(element.to_glib_none().0, list.to_glib_none().0))
|
2019-02-02 16:11:30 +00:00
|
|
|
.into_result()
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
for buffer in list.iter() {
|
2019-05-23 11:28:09 +00:00
|
|
|
self.render(element, &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,
|
|
|
|
element: &BaseSink,
|
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 {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.prepare_list
|
|
|
|
.map(|f| {
|
2019-05-23 11:28:09 +00:00
|
|
|
gst::FlowReturn::from_glib(f(element.to_glib_none().0, list.to_glib_none().0))
|
2019-02-02 16:11:30 +00:00
|
|
|
.into_result()
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
for buffer in list.iter() {
|
2019-05-23 11:28:09 +00:00
|
|
|
self.prepare(element, &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
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
(*parent_class)
|
|
|
|
.query
|
|
|
|
.map(|f| from_glib(f(element.to_glib_none().0, query.as_mut_ptr())))
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_event(&self, element: &BaseSink, event: gst::Event) -> bool {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
(*parent_class)
|
|
|
|
.event
|
|
|
|
.map(|f| from_glib(f(element.to_glib_none().0, event.into_ptr())))
|
2019-02-01 14:07:42 +00:00
|
|
|
.unwrap_or(true)
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 11:28:09 +00:00
|
|
|
fn parent_get_caps(&self, element: &BaseSink, filter: Option<&gst::Caps>) -> Option<gst::Caps> {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
(*parent_class)
|
|
|
|
.get_caps
|
2019-05-23 11:28:09 +00:00
|
|
|
.map(|f| from_glib_full(f(element.to_glib_none().0, filter.to_glib_none().0)))
|
2018-11-20 21:23:31 +00:00
|
|
|
.unwrap_or(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 13:54:48 +00:00
|
|
|
fn parent_set_caps(
|
|
|
|
&self,
|
|
|
|
element: &BaseSink,
|
2019-05-23 11:28:09 +00:00
|
|
|
caps: &gst::Caps,
|
2019-01-26 13:54:48 +00:00
|
|
|
) -> Result<(), gst::LoggableError> {
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-01 14:07:42 +00:00
|
|
|
(*parent_class)
|
|
|
|
.set_caps
|
|
|
|
.map(|f| {
|
|
|
|
gst_result_from_gboolean!(
|
2019-05-23 11:28:09 +00:00
|
|
|
f(element.to_glib_none().0, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_fixate(&self, element: &BaseSink, caps: gst::Caps) -> gst::Caps {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
match (*parent_class).fixate {
|
|
|
|
Some(fixate) => from_glib_full(fixate(element.to_glib_none().0, caps.into_ptr())),
|
|
|
|
None => caps,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-02 16:11:30 +00:00
|
|
|
|
|
|
|
fn parent_unlock(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.unlock
|
|
|
|
.map(|f| {
|
|
|
|
if from_glib(f(element.to_glib_none().0)) {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(gst_error_msg!(
|
|
|
|
gst::CoreError::Failed,
|
|
|
|
["Parent function `unlock` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_unlock_stop(&self, element: &BaseSink) -> Result<(), gst::ErrorMessage> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2019-03-19 07:58:20 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_base_sys::GstBaseSinkClass;
|
2019-02-02 16:11:30 +00:00
|
|
|
(*parent_class)
|
|
|
|
.unlock_stop
|
|
|
|
.map(|f| {
|
|
|
|
if from_glib(f(element.to_glib_none().0)) {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(gst_error_msg!(
|
|
|
|
gst::CoreError::Failed,
|
|
|
|
["Parent function `unlock_stop` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 13:18:19 +00:00
|
|
|
unsafe impl<T: BaseSinkImpl> IsSubclassable<T> for BaseSink
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
<T as ObjectSubclass>::Instance: PanicPoison,
|
|
|
|
{
|
2020-11-05 13:18:19 +00:00
|
|
|
fn override_vfuncs(klass: &mut glib::object::Class<Self>) {
|
|
|
|
<gst::Element as IsSubclassable<T>>::override_vfuncs(klass);
|
2018-11-20 21:23:31 +00:00
|
|
|
unsafe {
|
2020-11-05 13:18:19 +00:00
|
|
|
let klass = &mut *(klass.as_mut() as *mut gst_base_sys::GstBaseSinkClass);
|
2018-11-20 21:23:31 +00:00
|
|
|
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>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_start<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2019-01-26 14:22:06 +00:00
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
|
|
|
match imp.start(&wrap) {
|
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_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>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2019-01-26 14:22:06 +00:00
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
|
|
|
match imp.stop(&wrap) {
|
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_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>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
buffer: *mut gst_sys::GstBuffer,
|
|
|
|
) -> gst_sys::GstFlowReturn
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2019-05-23 11:28:09 +00:00
|
|
|
let buffer = from_glib_borrow(buffer);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2019-05-23 11:28:09 +00:00
|
|
|
imp.render(&wrap, &buffer).into()
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_prepare<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
buffer: *mut gst_sys::GstBuffer,
|
|
|
|
) -> gst_sys::GstFlowReturn
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2019-05-23 11:28:09 +00:00
|
|
|
let buffer = from_glib_borrow(buffer);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2019-05-23 11:28:09 +00:00
|
|
|
imp.prepare(&wrap, &buffer).into()
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_render_list<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
list: *mut gst_sys::GstBufferList,
|
|
|
|
) -> gst_sys::GstFlowReturn
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2019-05-23 11:28:09 +00:00
|
|
|
let list = from_glib_borrow(list);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2019-05-23 11:28:09 +00:00
|
|
|
imp.render_list(&wrap, &list).into()
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_prepare_list<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
list: *mut gst_sys::GstBufferList,
|
|
|
|
) -> gst_sys::GstFlowReturn
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2019-05-23 11:28:09 +00:00
|
|
|
let list = from_glib_borrow(list);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2019-05-23 11:28:09 +00:00
|
|
|
imp.prepare_list(&wrap, &list).into()
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_query<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
query_ptr: *mut gst_sys::GstQuery,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
let query = gst::QueryRef::from_mut_ptr(query_ptr);
|
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
|
|
|
BaseSinkImpl::query(imp, &wrap, query)
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_event<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
event_ptr: *mut gst_sys::GstEvent,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
|
|
|
imp.event(&wrap, from_glib_full(event_ptr))
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_get_caps<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
filter: *mut gst_sys::GstCaps,
|
|
|
|
) -> *mut gst_sys::GstCaps
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
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
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), None, {
|
2020-04-05 14:52:56 +00:00
|
|
|
imp.get_caps(&wrap, filter.as_ref().as_ref())
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.map(|caps| caps.into_ptr())
|
|
|
|
.unwrap_or(ptr::null_mut())
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_set_caps<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
caps: *mut gst_sys::GstCaps,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2019-05-23 11:28:09 +00:00
|
|
|
let caps = from_glib_borrow(caps);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
2019-05-23 11:28:09 +00:00
|
|
|
match imp.set_caps(&wrap, &caps) {
|
2019-01-26 13:54:48 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-04-05 14:52:56 +00:00
|
|
|
err.log_with_object(&*wrap);
|
2019-01-26 13:54:48 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_fixate<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
caps: *mut gst_sys::GstCaps,
|
|
|
|
) -> *mut gst_sys::GstCaps
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
let caps = from_glib_full(caps);
|
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::Caps::new_empty(), {
|
|
|
|
imp.fixate(&wrap, caps)
|
|
|
|
})
|
|
|
|
.into_ptr()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn base_sink_unlock<T: BaseSinkImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
2019-01-26 14:22:06 +00:00
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
|
|
|
match imp.unlock(&wrap) {
|
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_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>(
|
2019-03-19 07:58:20 +00:00
|
|
|
ptr: *mut gst_base_sys::GstBaseSink,
|
|
|
|
) -> glib_sys::gboolean
|
2018-11-20 21:23:31 +00:00
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap: Borrowed<BaseSink> = from_glib_borrow(ptr);
|
2018-11-20 21:23:31 +00:00
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
2019-01-26 14:22:06 +00:00
|
|
|
match imp.unlock_stop(&wrap) {
|
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-01-26 14:22:06 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 21:23:31 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|