From 01b16fe6c0a55cb40cfb87113fe2d165c91078e0 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 25 Dec 2020 00:17:39 +0100 Subject: [PATCH] gst-player: add PlayerVideoRenderer subclassing support --- gstreamer-player/src/lib.rs | 2 ++ gstreamer-player/src/subclass/mod.rs | 7 ++++ .../src/subclass/player_video_renderer.rs | 36 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 gstreamer-player/src/subclass/mod.rs create mode 100644 gstreamer-player/src/subclass/player_video_renderer.rs diff --git a/gstreamer-player/src/lib.rs b/gstreamer-player/src/lib.rs index 510b693aa..a7a89b47d 100644 --- a/gstreamer-player/src/lib.rs +++ b/gstreamer-player/src/lib.rs @@ -23,6 +23,8 @@ macro_rules! assert_initialized_main_thread { mod auto; pub use crate::auto::*; +pub mod subclass; + mod config; mod player; pub use crate::config::*; diff --git a/gstreamer-player/src/subclass/mod.rs b/gstreamer-player/src/subclass/mod.rs new file mode 100644 index 000000000..fc3098edd --- /dev/null +++ b/gstreamer-player/src/subclass/mod.rs @@ -0,0 +1,7 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +mod player_video_renderer; + +pub mod prelude { + pub use super::player_video_renderer::PlayerVideoRendererImpl; +} diff --git a/gstreamer-player/src/subclass/player_video_renderer.rs b/gstreamer-player/src/subclass/player_video_renderer.rs new file mode 100644 index 000000000..af4217cd8 --- /dev/null +++ b/gstreamer-player/src/subclass/player_video_renderer.rs @@ -0,0 +1,36 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::{Player, PlayerVideoRenderer}; + +use glib::subclass::prelude::*; +use glib::translate::*; +use glib::Cast; + +pub trait PlayerVideoRendererImpl: ObjectImpl { + fn create_video_sink(&self, video_renderer: &Self::Type, player: &Player) -> gst::Element; +} + +unsafe impl IsImplementable for PlayerVideoRenderer { + unsafe extern "C" fn interface_init( + iface: glib::ffi::gpointer, + _iface_data: glib::ffi::gpointer, + ) { + let video_renderer_iface = &mut *(iface as *mut ffi::GstPlayerVideoRendererInterface); + + video_renderer_iface.create_video_sink = Some(video_renderer_create_video_sink::); + } +} + +unsafe extern "C" fn video_renderer_create_video_sink( + video_renderer: *mut ffi::GstPlayerVideoRenderer, + player: *mut ffi::GstPlayer, +) -> *mut gst::ffi::GstElement { + let instance = &*(video_renderer as *mut T::Instance); + let imp = instance.get_impl(); + + imp.create_video_sink( + from_glib_borrow::<_, PlayerVideoRenderer>(video_renderer).unsafe_cast_ref(), + &Player::from_glib_borrow(player), + ) + .to_glib_full() +}