2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
use glib::prelude::*;
|
|
|
|
use glib::subclass::prelude::*;
|
2019-05-11 12:58:39 +00:00
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
|
2019-09-14 08:01:50 +00:00
|
|
|
use crate::prelude::*;
|
2020-11-22 09:53:17 +00:00
|
|
|
use crate::video_codec_state::{Readable, VideoCodecState};
|
|
|
|
use crate::VideoCodecFrame;
|
|
|
|
use crate::VideoDecoder;
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait VideoDecoderImpl: VideoDecoderImplExt + ElementImpl {
|
2020-11-14 16:22:46 +00:00
|
|
|
fn open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
self.parent_open(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
self.parent_close(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
self.parent_start(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
self.parent_stop(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-05-25 09:25:56 +00:00
|
|
|
self.parent_finish(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn drain(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-09-13 20:02:41 +00:00
|
|
|
self.parent_drain(element)
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:58:39 +00:00
|
|
|
fn set_format(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-12-23 11:07:05 +00:00
|
|
|
state: &VideoCodecState<'static, Readable>,
|
2019-05-11 12:58:39 +00:00
|
|
|
) -> Result<(), gst::LoggableError> {
|
|
|
|
self.parent_set_format(element, state)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame: &VideoCodecFrame,
|
|
|
|
adapter: &gst_base::Adapter,
|
|
|
|
at_eos: bool,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_parse(element, frame, adapter, at_eos)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_frame(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame: VideoCodecFrame,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_handle_frame(element, frame)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn flush(&self, element: &Self::Type) -> bool {
|
2019-05-11 12:58:39 +00:00
|
|
|
self.parent_flush(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> {
|
2019-09-13 19:58:53 +00:00
|
|
|
self.parent_negotiate(element)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps {
|
2019-09-13 19:58:53 +00:00
|
|
|
self.parent_get_caps(element, filter)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
self.parent_sink_event(element, event)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
self.parent_sink_query(element, query)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn src_event(&self, element: &Self::Type, event: gst::Event) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
self.parent_src_event(element, event)
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
self.parent_src_query(element, query)
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:58:39 +00:00
|
|
|
fn propose_allocation(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
query: &mut gst::QueryRef,
|
|
|
|
) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_propose_allocation(element, query)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn decide_allocation(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
query: &mut gst::QueryRef,
|
|
|
|
) -> Result<(), gst::ErrorMessage> {
|
|
|
|
self.parent_decide_allocation(element, query)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
pub trait VideoDecoderImplExt: ObjectSubclass {
|
|
|
|
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage>;
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError>;
|
2019-05-25 09:25:56 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_drain(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError>;
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2019-05-11 12:58:39 +00:00
|
|
|
fn parent_set_format(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-12-23 11:07:05 +00:00
|
|
|
state: &VideoCodecState<'static, Readable>,
|
2019-05-11 12:58:39 +00:00
|
|
|
) -> Result<(), gst::LoggableError>;
|
|
|
|
|
|
|
|
fn parent_parse(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame: &VideoCodecFrame,
|
|
|
|
adapter: &gst_base::Adapter,
|
|
|
|
at_eos: bool,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
|
|
|
fn parent_handle_frame(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame: VideoCodecFrame,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_flush(&self, element: &Self::Type) -> bool;
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError>;
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps;
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool;
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool;
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool;
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool;
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2019-05-11 12:58:39 +00:00
|
|
|
fn parent_propose_allocation(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
query: &mut gst::QueryRef,
|
|
|
|
) -> Result<(), gst::ErrorMessage>;
|
|
|
|
|
|
|
|
fn parent_decide_allocation(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
query: &mut gst::QueryRef,
|
|
|
|
) -> Result<(), gst::ErrorMessage>;
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_open(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.open
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
if from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
{
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `open` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_close(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.close
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
if from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
{
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `close` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_start(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.start
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
if from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
{
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `start` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_stop(&self, element: &Self::Type) -> Result<(), gst::ErrorMessage> {
|
2019-05-11 12:58:39 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.stop
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
if from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
{
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `stop` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_finish(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-05-25 09:25:56 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-25 09:25:56 +00:00
|
|
|
(*parent_class)
|
|
|
|
.finish
|
2020-11-14 16:22:46 +00:00
|
|
|
.map(|f| {
|
|
|
|
gst::FlowReturn::from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
})
|
2019-05-25 09:25:56 +00:00
|
|
|
.unwrap_or(gst::FlowReturn::Ok)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_drain(&self, element: &Self::Type) -> Result<gst::FlowSuccess, gst::FlowError> {
|
2019-09-13 20:02:41 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 20:02:41 +00:00
|
|
|
(*parent_class)
|
|
|
|
.drain
|
2020-11-14 16:22:46 +00:00
|
|
|
.map(|f| {
|
|
|
|
gst::FlowReturn::from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
})
|
2019-09-13 20:02:41 +00:00
|
|
|
.unwrap_or(gst::FlowReturn::Ok)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:58:39 +00:00
|
|
|
fn parent_set_format(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-12-23 11:07:05 +00:00
|
|
|
state: &VideoCodecState<'static, Readable>,
|
2019-05-11 12:58:39 +00:00
|
|
|
) -> Result<(), gst::LoggableError> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.set_format
|
|
|
|
.map(|f| {
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::result_from_gboolean!(
|
2020-11-14 16:22:46 +00:00
|
|
|
f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
state.as_mut_ptr()
|
|
|
|
),
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CAT_RUST,
|
|
|
|
"parent function `set_format` failed"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_parse(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame: &VideoCodecFrame,
|
|
|
|
adapter: &gst_base::Adapter,
|
|
|
|
at_eos: bool,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.parse
|
|
|
|
.map(|f| {
|
|
|
|
gst::FlowReturn::from_glib(f(
|
2020-11-14 16:22:46 +00:00
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame.to_glib_none().0,
|
|
|
|
adapter.to_glib_none().0,
|
|
|
|
at_eos.to_glib(),
|
|
|
|
))
|
|
|
|
})
|
|
|
|
.unwrap_or(gst::FlowReturn::Ok)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_handle_frame(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
frame: VideoCodecFrame,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.handle_frame
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
gst::FlowReturn::from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
frame.to_glib_none().0,
|
|
|
|
))
|
2019-05-11 12:58:39 +00:00
|
|
|
})
|
|
|
|
.unwrap_or(gst::FlowReturn::Error)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_flush(&self, element: &Self::Type) -> bool {
|
2019-05-11 12:58:39 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.flush
|
2020-11-14 16:22:46 +00:00
|
|
|
.map(|f| {
|
|
|
|
from_glib(f(element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.to_glib_none()
|
|
|
|
.0))
|
|
|
|
})
|
2019-05-11 12:58:39 +00:00
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_negotiate(&self, element: &Self::Type) -> Result<(), gst::LoggableError> {
|
2019-09-13 19:58:53 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 19:58:53 +00:00
|
|
|
(*parent_class)
|
|
|
|
.negotiate
|
|
|
|
.map(|f| {
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::result_from_gboolean!(
|
2020-11-14 16:22:46 +00:00
|
|
|
f(element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0),
|
2019-09-13 19:58:53 +00:00
|
|
|
gst::CAT_RUST,
|
|
|
|
"Parent function `negotiate` failed"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_get_caps(&self, element: &Self::Type, filter: Option<&gst::Caps>) -> gst::Caps {
|
2019-09-13 19:58:53 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 19:58:53 +00:00
|
|
|
(*parent_class)
|
|
|
|
.getcaps
|
2020-11-14 16:22:46 +00:00
|
|
|
.map(|f| {
|
|
|
|
from_glib_full(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
filter.to_glib_none().0,
|
|
|
|
))
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
element
|
|
|
|
.unsafe_cast_ref::<VideoDecoder>()
|
|
|
|
.proxy_getcaps(None, filter)
|
|
|
|
})
|
2019-09-13 19:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_sink_event(&self, element: &Self::Type, event: gst::Event) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 19:58:53 +00:00
|
|
|
let f = (*parent_class)
|
|
|
|
.sink_event
|
|
|
|
.expect("Missing parent function `sink_event`");
|
2020-11-14 16:22:46 +00:00
|
|
|
from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2019-09-13 19:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_sink_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 19:58:53 +00:00
|
|
|
let f = (*parent_class)
|
|
|
|
.sink_query
|
|
|
|
.expect("Missing parent function `sink_query`");
|
2020-11-14 16:22:46 +00:00
|
|
|
from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2019-09-13 19:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_src_event(&self, element: &Self::Type, event: gst::Event) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 19:58:53 +00:00
|
|
|
let f = (*parent_class)
|
|
|
|
.src_event
|
|
|
|
.expect("Missing parent function `src_event`");
|
2020-11-14 16:22:46 +00:00
|
|
|
from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
event.into_ptr(),
|
|
|
|
))
|
2019-09-13 19:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 16:22:46 +00:00
|
|
|
fn parent_src_query(&self, element: &Self::Type, query: &mut gst::QueryRef) -> bool {
|
2019-09-13 19:58:53 +00:00
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-09-13 19:58:53 +00:00
|
|
|
let f = (*parent_class)
|
|
|
|
.src_query
|
|
|
|
.expect("Missing parent function `src_query`");
|
2020-11-14 16:22:46 +00:00
|
|
|
from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
query.as_mut_ptr(),
|
|
|
|
))
|
2019-09-13 19:58:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 12:58:39 +00:00
|
|
|
fn parent_propose_allocation(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
query: &mut gst::QueryRef,
|
|
|
|
) -> Result<(), gst::ErrorMessage> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.propose_allocation
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
if from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
query.as_mut_ptr(),
|
|
|
|
)) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `propose_allocation` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parent_decide_allocation(
|
|
|
|
&self,
|
2020-11-14 16:22:46 +00:00
|
|
|
element: &Self::Type,
|
2019-05-11 12:58:39 +00:00
|
|
|
query: &mut gst::QueryRef,
|
|
|
|
) -> Result<(), gst::ErrorMessage> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-11-22 09:53:17 +00:00
|
|
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstVideoDecoderClass;
|
2019-05-11 12:58:39 +00:00
|
|
|
(*parent_class)
|
|
|
|
.decide_allocation
|
|
|
|
.map(|f| {
|
2020-11-14 16:22:46 +00:00
|
|
|
if from_glib(f(
|
|
|
|
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
|
|
|
|
query.as_mut_ptr(),
|
|
|
|
)) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
2020-12-20 15:09:22 +00:00
|
|
|
Err(gst::error_msg!(
|
2019-05-11 12:58:39 +00:00
|
|
|
gst::CoreError::StateChange,
|
|
|
|
["Parent function `decide_allocation` failed"]
|
|
|
|
))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(Ok(()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-05 13:18:19 +00:00
|
|
|
unsafe impl<T: VideoDecoderImpl> IsSubclassable<T> for VideoDecoder
|
2019-05-11 12:58:39 +00:00
|
|
|
where
|
|
|
|
<T as ObjectSubclass>::Instance: PanicPoison,
|
|
|
|
{
|
2020-11-05 16:48:17 +00:00
|
|
|
fn override_vfuncs(klass: &mut glib::Class<Self>) {
|
2020-11-05 13:18:19 +00:00
|
|
|
<gst::Element as IsSubclassable<T>>::override_vfuncs(klass);
|
2020-11-05 17:07:31 +00:00
|
|
|
let klass = klass.as_mut();
|
|
|
|
klass.open = Some(video_decoder_open::<T>);
|
|
|
|
klass.close = Some(video_decoder_close::<T>);
|
|
|
|
klass.start = Some(video_decoder_start::<T>);
|
|
|
|
klass.stop = Some(video_decoder_stop::<T>);
|
|
|
|
klass.finish = Some(video_decoder_finish::<T>);
|
|
|
|
klass.drain = Some(video_decoder_drain::<T>);
|
|
|
|
klass.set_format = Some(video_decoder_set_format::<T>);
|
|
|
|
klass.parse = Some(video_decoder_parse::<T>);
|
|
|
|
klass.handle_frame = Some(video_decoder_handle_frame::<T>);
|
|
|
|
klass.flush = Some(video_decoder_flush::<T>);
|
|
|
|
klass.negotiate = Some(video_decoder_negotiate::<T>);
|
|
|
|
klass.getcaps = Some(video_decoder_getcaps::<T>);
|
|
|
|
klass.sink_event = Some(video_decoder_sink_event::<T>);
|
|
|
|
klass.src_event = Some(video_decoder_src_event::<T>);
|
|
|
|
klass.sink_query = Some(video_decoder_sink_query::<T>);
|
|
|
|
klass.src_query = Some(video_decoder_src_query::<T>);
|
|
|
|
klass.propose_allocation = Some(video_decoder_propose_allocation::<T>);
|
|
|
|
klass.decide_allocation = Some(video_decoder_decide_allocation::<T>);
|
2019-05-11 12:58:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_open<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.open(wrap.unsafe_cast_ref()) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_close<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.close(wrap.unsafe_cast_ref()) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_start<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.start(wrap.unsafe_cast_ref()) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_stop<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.stop(wrap.unsafe_cast_ref()) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_finish<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> gst::ffi::GstFlowReturn
|
2019-05-25 09:25:56 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-25 09:25:56 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.finish(wrap.unsafe_cast_ref()).into()
|
2019-05-25 09:25:56 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_drain<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> gst::ffi::GstFlowReturn
|
2019-09-13 20:02:41 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 20:02:41 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.drain(wrap.unsafe_cast_ref()).into()
|
2019-09-13 20:02:41 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_set_format<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
state: *mut ffi::GstVideoCodecState,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_codec_state_ref(state);
|
2019-07-11 15:50:37 +00:00
|
|
|
let wrap_state = VideoCodecState::<Readable>::new(state);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.set_format(wrap.unsafe_cast_ref(), &wrap_state) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-04-05 14:52:56 +00:00
|
|
|
err.log_with_object(&*wrap);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_parse<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
frame: *mut ffi::GstVideoCodecFrame,
|
|
|
|
adapter: *mut gst_base::ffi::GstAdapter,
|
|
|
|
at_eos: glib::ffi::gboolean,
|
|
|
|
) -> gst::ffi::GstFlowReturn
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2020-11-22 09:53:17 +00:00
|
|
|
ffi::gst_video_codec_frame_ref(frame);
|
2020-04-05 14:52:56 +00:00
|
|
|
let wrap_frame = VideoCodecFrame::new(frame, &*wrap);
|
|
|
|
let wrap_adapter: Borrowed<gst_base::Adapter> = from_glib_borrow(adapter);
|
2019-05-11 12:58:39 +00:00
|
|
|
let at_eos: bool = from_glib(at_eos);
|
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.parse(wrap.unsafe_cast_ref(), &wrap_frame, &wrap_adapter, at_eos)
|
|
|
|
.into()
|
2019-05-11 12:58:39 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_handle_frame<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
frame: *mut ffi::GstVideoCodecFrame,
|
|
|
|
) -> gst::ffi::GstFlowReturn
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
|
|
|
let wrap_frame = VideoCodecFrame::new(frame, &*wrap);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.handle_frame(wrap.unsafe_cast_ref(), wrap_frame).into()
|
2019-05-11 12:58:39 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_flush<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
VideoDecoderImpl::flush(imp, wrap.unsafe_cast_ref())
|
2019-05-11 12:58:39 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_negotiate<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-09-13 19:58:53 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.negotiate(wrap.unsafe_cast_ref()) {
|
2019-09-13 19:58:53 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-04-05 14:52:56 +00:00
|
|
|
err.log_with_object(&*wrap);
|
2019-09-13 19:58:53 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_getcaps<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
filter: *mut gst::ffi::GstCaps,
|
|
|
|
) -> *mut gst::ffi::GstCaps
|
2019-09-13 19:58:53 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), gst::Caps::new_empty(), {
|
2019-09-13 19:58:53 +00:00
|
|
|
VideoDecoderImpl::get_caps(
|
|
|
|
imp,
|
2020-11-14 16:22:46 +00:00
|
|
|
wrap.unsafe_cast_ref(),
|
2020-04-05 14:52:56 +00:00
|
|
|
Option::<gst::Caps>::from_glib_borrow(filter)
|
|
|
|
.as_ref()
|
|
|
|
.as_ref(),
|
2019-09-13 19:58:53 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.to_glib_full()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_sink_event<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
event: *mut gst::ffi::GstEvent,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-09-13 19:58:53 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.sink_event(wrap.unsafe_cast_ref(), from_glib_full(event))
|
2019-09-13 19:58:53 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_sink_query<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
query: *mut gst::ffi::GstQuery,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-09-13 19:58:53 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.sink_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query))
|
2019-09-13 19:58:53 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_src_event<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
event: *mut gst::ffi::GstEvent,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-09-13 19:58:53 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.src_event(wrap.unsafe_cast_ref(), from_glib_full(event))
|
2019-09-13 19:58:53 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_src_query<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
query: *mut gst::ffi::GstQuery,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-09-13 19:58:53 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-09-13 19:58:53 +00:00
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
imp.src_query(wrap.unsafe_cast_ref(), gst::QueryRef::from_mut_ptr(query))
|
2019-09-13 19:58:53 +00:00
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_propose_allocation<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
query: *mut gst::ffi::GstQuery,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
let query = gst::QueryRef::from_mut_ptr(query);
|
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.propose_allocation(wrap.unsafe_cast_ref(), query) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_decoder_decide_allocation<T: VideoDecoderImpl>(
|
2020-11-22 09:53:17 +00:00
|
|
|
ptr: *mut ffi::GstVideoDecoder,
|
|
|
|
query: *mut gst::ffi::GstQuery,
|
|
|
|
) -> glib::ffi::gboolean
|
2019-05-11 12:58:39 +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<VideoDecoder> = from_glib_borrow(ptr);
|
2019-05-11 12:58:39 +00:00
|
|
|
let query = gst::QueryRef::from_mut_ptr(query);
|
|
|
|
|
2020-12-20 15:09:22 +00:00
|
|
|
gst::panic_to_error!(&wrap, &instance.panicked(), false, {
|
2020-11-14 16:22:46 +00:00
|
|
|
match imp.decide_allocation(wrap.unsafe_cast_ref(), query) {
|
2019-05-11 12:58:39 +00:00
|
|
|
Ok(()) => true,
|
|
|
|
Err(err) => {
|
2020-06-30 20:51:15 +00:00
|
|
|
wrap.post_error_message(err);
|
2019-05-11 12:58:39 +00:00
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|