2020-06-12 14:05:46 +00:00
|
|
|
// Copyright (C) 2020 François Laignel <fengalin@free.fr>
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
use gst_sys;
|
|
|
|
use gst_video_sys;
|
|
|
|
|
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use glib::subclass::prelude::*;
|
|
|
|
use gst;
|
|
|
|
use gst::subclass::prelude::*;
|
|
|
|
use gst_base::subclass::prelude::*;
|
|
|
|
|
|
|
|
use VideoSink;
|
|
|
|
use VideoSinkClass;
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait VideoSinkImpl: VideoSinkImplExt + BaseSinkImpl + ElementImpl {
|
2020-06-12 14:05:46 +00:00
|
|
|
fn show_frame(
|
|
|
|
&self,
|
|
|
|
element: &VideoSink,
|
|
|
|
buffer: &gst::Buffer,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
self.parent_show_frame(element, buffer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait VideoSinkImplExt {
|
|
|
|
fn parent_show_frame(
|
|
|
|
&self,
|
|
|
|
element: &VideoSink,
|
|
|
|
buffer: &gst::Buffer,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError>;
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
impl<T: VideoSinkImpl> VideoSinkImplExt for T {
|
2020-06-12 14:05:46 +00:00
|
|
|
fn parent_show_frame(
|
|
|
|
&self,
|
|
|
|
element: &VideoSink,
|
|
|
|
buffer: &gst::Buffer,
|
|
|
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
|
|
|
unsafe {
|
2020-07-25 08:02:04 +00:00
|
|
|
let data = T::type_data();
|
2020-06-12 14:05:46 +00:00
|
|
|
let parent_class =
|
|
|
|
data.as_ref().get_parent_class() as *mut gst_video_sys::GstVideoSinkClass;
|
|
|
|
(*parent_class)
|
|
|
|
.show_frame
|
|
|
|
.map(|f| {
|
|
|
|
gst::FlowReturn::from_glib(f(element.to_glib_none().0, buffer.to_glib_none().0))
|
|
|
|
})
|
|
|
|
.unwrap_or(gst::FlowReturn::Error)
|
|
|
|
.into_result()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe impl<T: VideoSinkImpl> IsSubclassable<T> for VideoSinkClass
|
2020-06-12 14:05:46 +00:00
|
|
|
where
|
|
|
|
<T as ObjectSubclass>::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
fn override_vfuncs(&mut self) {
|
|
|
|
<gst_base::BaseSinkClass as IsSubclassable<T>>::override_vfuncs(self);
|
|
|
|
unsafe {
|
|
|
|
let klass = &mut *(self as *mut Self as *mut gst_video_sys::GstVideoSinkClass);
|
|
|
|
klass.show_frame = Some(video_sink_show_frame::<T>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn video_sink_show_frame<T: VideoSinkImpl>(
|
2020-06-12 14:05:46 +00:00
|
|
|
ptr: *mut gst_video_sys::GstVideoSink,
|
|
|
|
buffer: *mut gst_sys::GstBuffer,
|
|
|
|
) -> gst_sys::GstFlowReturn
|
|
|
|
where
|
|
|
|
T::Instance: PanicPoison,
|
|
|
|
{
|
|
|
|
let instance = &*(ptr as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
let wrap: Borrowed<VideoSink> = from_glib_borrow(ptr);
|
|
|
|
let buffer = from_glib_borrow(buffer);
|
|
|
|
|
|
|
|
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
|
|
|
|
imp.show_frame(&wrap, &buffer).into()
|
|
|
|
})
|
|
|
|
.to_glib()
|
|
|
|
}
|