video: Add bindings for VideoSink

This commit is contained in:
François Laignel 2020-06-12 16:05:46 +02:00
parent 4b553c3ae7
commit 04875f3bff
6 changed files with 211 additions and 2 deletions

View file

@ -64,6 +64,7 @@ manual = [
"Gst.FlowReturn", "Gst.FlowReturn",
"Gst.TagList", "Gst.TagList",
"Gst.TagMergeMode", "Gst.TagMergeMode",
"GstBase.BaseSink",
"GstBase.BaseTransform", "GstBase.BaseTransform",
"GstVideo.VideoCodecState", "GstVideo.VideoCodecState",
"GstVideo.VideoCodecFrame", "GstVideo.VideoCodecFrame",
@ -248,3 +249,12 @@ status = "generate"
[[object.derive]] [[object.derive]]
name = "Debug, Eq, PartialEq, Hash" name = "Debug, Eq, PartialEq, Hash"
[[object]]
name = "GstVideo.VideoSink"
status = "generate"
[[object.function]]
name = "center_rect"
# Implemented in video_rectangle
ignore = true

View file

@ -20,6 +20,10 @@ mod video_overlay;
pub use self::video_overlay::VideoOverlayExt; pub use self::video_overlay::VideoOverlayExt;
pub use self::video_overlay::{VideoOverlay, NONE_VIDEO_OVERLAY}; pub use self::video_overlay::{VideoOverlay, NONE_VIDEO_OVERLAY};
mod video_sink;
pub use self::video_sink::VideoSinkExt;
pub use self::video_sink::{VideoSink, VideoSinkClass, NONE_VIDEO_SINK};
mod enums; mod enums;
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
pub use self::enums::VideoAFDSpec; pub use self::enums::VideoAFDSpec;
@ -63,4 +67,5 @@ pub mod traits {
pub use super::VideoDecoderExt; pub use super::VideoDecoderExt;
pub use super::VideoEncoderExt; pub use super::VideoEncoderExt;
pub use super::VideoOverlayExt; pub use super::VideoOverlayExt;
pub use super::VideoSinkExt;
} }

View file

@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 882e09b) Generated by gir (https://github.com/gtk-rs/gir @ 882e09b)
from gir-files (https://github.com/gtk-rs/gir-files @ 38361831) from gir-files (https://github.com/gtk-rs/gir-files @ 1a54d3bc)

View file

@ -0,0 +1,99 @@
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use gst;
use gst_base;
use gst_video_sys;
use std::boxed::Box as Box_;
use std::mem::transmute;
glib_wrapper! {
pub struct VideoSink(Object<gst_video_sys::GstVideoSink, gst_video_sys::GstVideoSinkClass, VideoSinkClass>) @extends gst_base::BaseSink, gst::Element, gst::Object;
match fn {
get_type => || gst_video_sys::gst_video_sink_get_type(),
}
}
unsafe impl Send for VideoSink {}
unsafe impl Sync for VideoSink {}
pub const NONE_VIDEO_SINK: Option<&VideoSink> = None;
pub trait VideoSinkExt: 'static {
fn get_property_show_preroll_frame(&self) -> bool;
fn set_property_show_preroll_frame(&self, show_preroll_frame: bool);
fn connect_property_show_preroll_frame_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId;
}
impl<O: IsA<VideoSink>> VideoSinkExt for O {
fn get_property_show_preroll_frame(&self) -> bool {
unsafe {
let mut value = Value::from_type(<bool as StaticType>::static_type());
gobject_sys::g_object_get_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"show-preroll-frame\0".as_ptr() as *const _,
value.to_glib_none_mut().0,
);
value
.get()
.expect("Return Value for property `show-preroll-frame` getter")
.unwrap()
}
}
fn set_property_show_preroll_frame(&self, show_preroll_frame: bool) {
unsafe {
gobject_sys::g_object_set_property(
self.to_glib_none().0 as *mut gobject_sys::GObject,
b"show-preroll-frame\0".as_ptr() as *const _,
Value::from(&show_preroll_frame).to_glib_none().0,
);
}
}
fn connect_property_show_preroll_frame_notify<F: Fn(&Self) + Send + Sync + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_show_preroll_frame_trampoline<
P,
F: Fn(&P) + Send + Sync + 'static,
>(
this: *mut gst_video_sys::GstVideoSink,
_param_spec: glib_sys::gpointer,
f: glib_sys::gpointer,
) where
P: IsA<VideoSink>,
{
let f: &F = &*(f as *const F);
f(&VideoSink::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::show-preroll-frame\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
notify_show_preroll_frame_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}

View file

@ -9,8 +9,10 @@
mod video_decoder; mod video_decoder;
mod video_encoder; mod video_encoder;
mod video_sink;
pub mod prelude { pub mod prelude {
pub use super::video_decoder::{VideoDecoderImpl, VideoDecoderImplExt}; pub use super::video_decoder::{VideoDecoderImpl, VideoDecoderImplExt};
pub use super::video_encoder::{VideoEncoderImpl, VideoEncoderImplExt}; pub use super::video_encoder::{VideoEncoderImpl, VideoEncoderImplExt};
pub use super::video_sink::{VideoSinkImpl, VideoSinkImplExt};
} }

View file

@ -0,0 +1,93 @@
// 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;
pub trait VideoSinkImpl:
VideoSinkImplExt + BaseSinkImpl + ElementImpl + Send + Sync + 'static
{
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>;
}
impl<T: VideoSinkImpl + ObjectImpl> VideoSinkImplExt for T {
fn parent_show_frame(
&self,
element: &VideoSink,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe {
let data = self.get_type_data();
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()
}
}
}
unsafe impl<T: ObjectSubclass + VideoSinkImpl> IsSubclassable<T> for VideoSinkClass
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>);
}
}
}
unsafe extern "C" fn video_sink_show_frame<T: ObjectSubclass>(
ptr: *mut gst_video_sys::GstVideoSink,
buffer: *mut gst_sys::GstBuffer,
) -> gst_sys::GstFlowReturn
where
T: VideoSinkImpl,
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()
}