gst-player: add PlayerVideoRenderer subclassing support

This commit is contained in:
Bilal Elmoussaoui 2020-12-25 00:17:39 +01:00
parent ec2a287842
commit 01b16fe6c0
3 changed files with 45 additions and 0 deletions

View file

@ -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::*;

View file

@ -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;
}

View file

@ -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<T: PlayerVideoRendererImpl> IsImplementable<T> 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::<T>);
}
}
unsafe extern "C" fn video_renderer_create_video_sink<T: PlayerVideoRendererImpl>(
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()
}