2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-08-07 14:35:57 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use std::{boxed::Box as Box_, mem::transmute};
|
|
|
|
|
|
|
|
use glib::{
|
|
|
|
object::ObjectType,
|
|
|
|
signal::{connect_raw, SignalHandlerId},
|
|
|
|
translate::*,
|
|
|
|
};
|
|
|
|
|
2020-11-22 10:32:04 +00:00
|
|
|
use crate::Player;
|
2017-08-07 14:35:57 +00:00
|
|
|
|
|
|
|
impl Player {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_config")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_player_get_config")]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn config(&self) -> crate::PlayerConfig {
|
2020-11-22 10:32:04 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_player_get_config(self.to_glib_none().0)) }
|
2017-12-16 09:18:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_player_set_config")]
|
2020-11-22 10:32:04 +00:00
|
|
|
pub fn set_config(&self, config: crate::PlayerConfig) -> Result<(), glib::error::BoolError> {
|
2017-08-07 14:35:57 +00:00
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2022-05-06 19:41:15 +00:00
|
|
|
ffi::gst_player_set_config(self.to_glib_none().0, config.into_glib_ptr()),
|
2017-12-16 09:18:00 +00:00
|
|
|
"Failed to set config",
|
|
|
|
)
|
2017-08-07 14:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-10 10:13:17 +00:00
|
|
|
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn connect_duration_changed<F: Fn(&Player, Option<gst::ClockTime>) + Send + 'static>(
|
2017-12-16 09:18:00 +00:00
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2017-12-10 10:13:17 +00:00
|
|
|
unsafe {
|
2019-01-29 16:22:05 +00:00
|
|
|
let f: Box_<F> = Box_::new(f);
|
2019-01-16 11:32:58 +00:00
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"duration-changed\0".as_ptr() as *const _,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
|
|
duration_changed_trampoline::<F> as *const (),
|
|
|
|
)),
|
2019-01-29 16:22:05 +00:00
|
|
|
Box_::into_raw(f),
|
2017-12-16 09:18:00 +00:00
|
|
|
)
|
2017-12-10 10:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn connect_position_updated<F: Fn(&Player, Option<gst::ClockTime>) + Send + 'static>(
|
2017-12-16 09:18:00 +00:00
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2017-12-10 10:13:17 +00:00
|
|
|
unsafe {
|
2019-01-29 16:22:05 +00:00
|
|
|
let f: Box_<F> = Box_::new(f);
|
2019-01-16 11:32:58 +00:00
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"position-updated\0".as_ptr() as *const _,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
|
|
position_updated_trampoline::<F> as *const (),
|
|
|
|
)),
|
2019-01-29 16:22:05 +00:00
|
|
|
Box_::into_raw(f),
|
2017-12-16 09:18:00 +00:00
|
|
|
)
|
2017-12-10 10:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 09:18:00 +00:00
|
|
|
pub fn connect_seek_done<F: Fn(&Player, gst::ClockTime) + Send + 'static>(
|
|
|
|
&self,
|
|
|
|
f: F,
|
|
|
|
) -> SignalHandlerId {
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::cast_ptr_alignment)]
|
2017-12-10 10:13:17 +00:00
|
|
|
unsafe {
|
2019-01-29 16:22:05 +00:00
|
|
|
let f: Box_<F> = Box_::new(f);
|
2019-01-16 11:32:58 +00:00
|
|
|
connect_raw(
|
|
|
|
self.as_ptr() as *mut _,
|
|
|
|
b"seek-done\0".as_ptr() as *const _,
|
2020-04-13 16:18:57 +00:00
|
|
|
Some(transmute::<_, unsafe extern "C" fn()>(
|
|
|
|
seek_done_trampoline::<F> as *const (),
|
|
|
|
)),
|
2019-01-29 16:22:05 +00:00
|
|
|
Box_::into_raw(f),
|
2017-12-16 09:18:00 +00:00
|
|
|
)
|
2017-12-10 10:13:17 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-21 09:38:45 +00:00
|
|
|
|
|
|
|
#[doc(alias = "gst_player_get_video_snapshot")]
|
|
|
|
#[doc(alias = "get_video_snapshot")]
|
|
|
|
pub fn video_snapshot(
|
|
|
|
&self,
|
|
|
|
format: crate::PlayerSnapshotFormat,
|
|
|
|
config: Option<&gst::StructureRef>,
|
|
|
|
) -> Option<gst::Sample> {
|
|
|
|
unsafe {
|
|
|
|
from_glib_full(ffi::gst_player_get_video_snapshot(
|
|
|
|
self.to_glib_none().0,
|
|
|
|
format.into_glib(),
|
|
|
|
mut_override(config.map(|c| c.as_ptr()).unwrap_or(std::ptr::null())),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2017-12-10 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
2023-03-09 12:20:29 +00:00
|
|
|
impl Default for Player {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new(
|
|
|
|
None::<crate::PlayerVideoRenderer>,
|
|
|
|
None::<crate::PlayerSignalDispatcher>,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 16:22:05 +00:00
|
|
|
unsafe extern "C" fn duration_changed_trampoline<
|
2021-04-28 22:29:13 +00:00
|
|
|
F: Fn(&Player, Option<gst::ClockTime>) + Send + 'static,
|
2019-01-29 16:22:05 +00:00
|
|
|
>(
|
2020-11-22 10:32:04 +00:00
|
|
|
this: *mut ffi::GstPlayer,
|
2017-12-16 09:18:00 +00:00
|
|
|
object: u64,
|
2020-11-22 10:32:04 +00:00
|
|
|
f: glib::ffi::gpointer,
|
2017-12-16 09:18:00 +00:00
|
|
|
) {
|
2019-02-21 17:30:36 +00:00
|
|
|
let f: &F = &*(f as *const F);
|
2021-04-28 22:29:13 +00:00
|
|
|
f(&from_glib_borrow(this), FromGlib::from_glib(object))
|
2017-12-10 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 16:22:05 +00:00
|
|
|
unsafe extern "C" fn position_updated_trampoline<
|
2021-04-28 22:29:13 +00:00
|
|
|
F: Fn(&Player, Option<gst::ClockTime>) + Send + 'static,
|
2019-01-29 16:22:05 +00:00
|
|
|
>(
|
2020-11-22 10:32:04 +00:00
|
|
|
this: *mut ffi::GstPlayer,
|
2017-12-16 09:18:00 +00:00
|
|
|
object: u64,
|
2020-11-22 10:32:04 +00:00
|
|
|
f: glib::ffi::gpointer,
|
2017-12-16 09:18:00 +00:00
|
|
|
) {
|
2019-02-21 17:30:36 +00:00
|
|
|
let f: &F = &*(f as *const F);
|
2021-04-28 22:29:13 +00:00
|
|
|
f(&from_glib_borrow(this), FromGlib::from_glib(object))
|
2017-12-10 10:13:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 16:22:05 +00:00
|
|
|
unsafe extern "C" fn seek_done_trampoline<F: Fn(&Player, gst::ClockTime) + Send + 'static>(
|
2020-11-22 10:32:04 +00:00
|
|
|
this: *mut ffi::GstPlayer,
|
2017-12-16 09:18:00 +00:00
|
|
|
object: u64,
|
2020-11-22 10:32:04 +00:00
|
|
|
f: glib::ffi::gpointer,
|
2017-12-16 09:18:00 +00:00
|
|
|
) {
|
2019-02-21 17:30:36 +00:00
|
|
|
let f: &F = &*(f as *const F);
|
2021-04-28 22:29:13 +00:00
|
|
|
f(
|
|
|
|
&from_glib_borrow(this),
|
|
|
|
try_from_glib(object).expect("undefined seek position"),
|
|
|
|
)
|
2017-08-07 14:35:57 +00:00
|
|
|
}
|