gstreamer-player: Update manual code to 2018 edition

This commit is contained in:
Sebastian Dröge 2020-11-22 12:32:04 +02:00
parent 0b1dd5ecfc
commit ddad791418
9 changed files with 60 additions and 103 deletions

View file

@ -11,29 +11,27 @@ homepage = "https://gstreamer.freedesktop.org"
documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer_player/" documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer_player/"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"] keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs" build = "build.rs"
edition = "2018"
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
libc = "0.2" libc = "0.2"
glib-sys = { git = "https://github.com/gtk-rs/gtk-rs" } ffi = { package = "gstreamer-player-sys", path = "../gstreamer-player/sys" }
gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer-sys = { path = "../gstreamer/sys", features = ["v1_12"] }
gstreamer-player-sys = { path = "../gstreamer-player/sys" }
glib = { git = "https://github.com/gtk-rs/gtk-rs" } glib = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer = { path = "../gstreamer", features = ["v1_12"] } gst = { package = "gstreamer", path = "../gstreamer", features = ["v1_12"] }
gstreamer-video = { path = "../gstreamer-video", features = ["v1_12"] } gst-video = { package = "gstreamer-video", path = "../gstreamer-video", features = ["v1_12"] }
[build-dependencies] [build-dependencies]
gstreamer-rs-lgpl-docs = { path = "../docs", optional = true } gstreamer-rs-lgpl-docs = { path = "../docs", optional = true }
[features] [features]
default = [] default = []
v1_14 = ["gstreamer/v1_14", "gstreamer-video/v1_14", "gstreamer-player-sys/v1_14"] v1_14 = ["gst/v1_14", "gst-video/v1_14", "ffi/v1_14"]
v1_16 = ["gstreamer/v1_16", "gstreamer-video/v1_16", "gstreamer-player-sys/v1_16", "v1_14"] v1_16 = ["gst/v1_16", "gst-video/v1_16", "ffi/v1_16", "v1_14"]
v1_18 = ["gstreamer/v1_18", "gstreamer-video/v1_18", "gstreamer-player-sys/v1_18", "v1_16"] v1_18 = ["gst/v1_18", "gst-video/v1_18", "ffi/v1_18", "v1_16"]
embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"] embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"] purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
dox = ["v1_18", "gstreamer-player-sys/dox", "glib/dox", "gstreamer/dox", "gstreamer-video/dox"] dox = ["v1_18", "ffi/dox", "glib/dox", "gst/dox", "gst-video/dox"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["dox", "embed-lgpl-docs"] features = ["dox", "embed-lgpl-docs"]

View file

@ -2,6 +2,6 @@
// from gir-files (https://github.com/gtk-rs/gir-files) // from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT // DO NOT EDIT
use gst_player_sys; use ffi;
use glib::translate::*; use glib::translate::*;

View file

@ -7,9 +7,6 @@
// except according to those terms. // except according to those terms.
use glib::translate::*; use glib::translate::*;
use gst;
use gst_player_sys;
use gst_sys;
use std::mem; use std::mem;
use std::ops; use std::ops;
@ -46,15 +43,13 @@ impl AsMut<gst::StructureRef> for PlayerConfig {
impl PlayerConfig { impl PlayerConfig {
pub fn get_position_update_interval(&self) -> u32 { pub fn get_position_update_interval(&self) -> u32 {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe { ffi::gst_player_config_get_position_update_interval(self.0.to_glib_none().0) }
gst_player_sys::gst_player_config_get_position_update_interval(self.0.to_glib_none().0)
}
} }
pub fn get_seek_accurate(&self) -> bool { pub fn get_seek_accurate(&self) -> bool {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib(gst_player_sys::gst_player_config_get_seek_accurate( from_glib(ffi::gst_player_config_get_seek_accurate(
self.0.to_glib_none().0, self.0.to_glib_none().0,
)) ))
} }
@ -63,7 +58,7 @@ impl PlayerConfig {
pub fn get_user_agent(&self) -> Option<String> { pub fn get_user_agent(&self) -> Option<String> {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full(gst_player_sys::gst_player_config_get_user_agent( from_glib_full(ffi::gst_player_config_get_user_agent(
self.0.to_glib_none().0, self.0.to_glib_none().0,
)) ))
} }
@ -72,7 +67,7 @@ impl PlayerConfig {
pub fn set_position_update_interval(&mut self, interval: u32) { pub fn set_position_update_interval(&mut self, interval: u32) {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
gst_player_sys::gst_player_config_set_position_update_interval( ffi::gst_player_config_set_position_update_interval(
self.0.to_glib_none_mut().0, self.0.to_glib_none_mut().0,
interval, interval,
); );
@ -89,21 +84,21 @@ impl PlayerConfig {
pub fn set_user_agent(&mut self, agent: &str) { pub fn set_user_agent(&mut self, agent: &str) {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
gst_player_sys::gst_player_config_set_user_agent( ffi::gst_player_config_set_user_agent(
self.0.to_glib_none_mut().0, self.0.to_glib_none_mut().0,
agent.to_glib_none().0, agent.to_glib_none().0,
); );
} }
} }
pub unsafe fn into_ptr(self) -> *mut gst_sys::GstStructure { pub unsafe fn into_ptr(self) -> *mut gst::ffi::GstStructure {
let mut s = mem::ManuallyDrop::new(self); let mut s = mem::ManuallyDrop::new(self);
s.0.to_glib_none_mut().0 s.0.to_glib_none_mut().0
} }
} }
impl FromGlibPtrFull<*mut gst_sys::GstStructure> for PlayerConfig { impl FromGlibPtrFull<*mut gst::ffi::GstStructure> for PlayerConfig {
unsafe fn from_glib_full(ptr: *mut gst_sys::GstStructure) -> Self { unsafe fn from_glib_full(ptr: *mut gst::ffi::GstStructure) -> Self {
PlayerConfig(from_glib_full(ptr)) PlayerConfig(from_glib_full(ptr))
} }
} }

View file

@ -8,17 +8,7 @@
#![cfg_attr(feature = "dox", feature(doc_cfg))] #![cfg_attr(feature = "dox", feature(doc_cfg))]
extern crate libc; pub use ffi;
extern crate glib_sys;
extern crate gobject_sys;
extern crate gstreamer as gst;
extern crate gstreamer_player_sys as gst_player_sys;
extern crate gstreamer_sys as gst_sys;
extern crate gstreamer_video as gst_video;
#[macro_use]
extern crate glib;
macro_rules! skip_assert_initialized { macro_rules! skip_assert_initialized {
() => {}; () => {};
@ -35,11 +25,11 @@ macro_rules! assert_initialized_main_thread {
#[allow(clippy::cast_ptr_alignment)] #[allow(clippy::cast_ptr_alignment)]
#[allow(unused_imports)] #[allow(unused_imports)]
mod auto; mod auto;
pub use auto::*; pub use crate::auto::*;
mod config; mod config;
mod player; mod player;
pub use config::*; pub use crate::config::*;
mod player_video_info; mod player_video_info;
@ -53,5 +43,5 @@ pub mod prelude {
pub use glib::prelude::*; pub use glib::prelude::*;
pub use gst::prelude::*; pub use gst::prelude::*;
pub use auto::traits::*; pub use crate::auto::traits::*;
} }

View file

@ -6,19 +6,15 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib; use crate::Player;
use crate::PlayerSignalDispatcher;
use crate::PlayerVideoRenderer;
use glib::object::ObjectType; use glib::object::ObjectType;
use glib::signal::connect_raw; use glib::signal::connect_raw;
use glib::signal::SignalHandlerId; use glib::signal::SignalHandlerId;
use glib::translate::*; use glib::translate::*;
use glib_sys;
use gst;
use gst_player_sys;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem::transmute; use std::mem::transmute;
use Player;
use PlayerSignalDispatcher;
use PlayerVideoRenderer;
impl Player { impl Player {
pub fn new( pub fn new(
@ -31,32 +27,22 @@ impl Player {
let (major, minor, _, _) = gst::version(); let (major, minor, _, _) = gst::version();
if (major, minor) > (1, 12) { if (major, minor) > (1, 12) {
unsafe { unsafe { from_glib_full(ffi::gst_player_new(video_renderer, signal_dispatcher)) }
from_glib_full(gst_player_sys::gst_player_new(
video_renderer,
signal_dispatcher,
))
}
} else { } else {
// Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 in // Workaround for bad floating reference handling in 1.12. This issue was fixed for 1.13 in
// https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/gst-libs/gst/player/gstplayer.c?id=634cd87c76f58b5e1383715bafd5614db825c7d1 // https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/gst-libs/gst/player/gstplayer.c?id=634cd87c76f58b5e1383715bafd5614db825c7d1
unsafe { unsafe { from_glib_none(ffi::gst_player_new(video_renderer, signal_dispatcher)) }
from_glib_none(gst_player_sys::gst_player_new(
video_renderer,
signal_dispatcher,
))
}
} }
} }
pub fn get_config(&self) -> ::PlayerConfig { pub fn get_config(&self) -> crate::PlayerConfig {
unsafe { from_glib_full(gst_player_sys::gst_player_get_config(self.to_glib_none().0)) } unsafe { from_glib_full(ffi::gst_player_get_config(self.to_glib_none().0)) }
} }
pub fn set_config(&self, config: ::PlayerConfig) -> Result<(), glib::error::BoolError> { pub fn set_config(&self, config: crate::PlayerConfig) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!( glib::glib_result_from_gboolean!(
gst_player_sys::gst_player_set_config(self.to_glib_none().0, config.into_ptr()), ffi::gst_player_set_config(self.to_glib_none().0, config.into_ptr()),
"Failed to set config", "Failed to set config",
) )
} }
@ -120,9 +106,9 @@ impl Player {
unsafe extern "C" fn duration_changed_trampoline< unsafe extern "C" fn duration_changed_trampoline<
F: Fn(&Player, gst::ClockTime) + Send + 'static, F: Fn(&Player, gst::ClockTime) + Send + 'static,
>( >(
this: *mut gst_player_sys::GstPlayer, this: *mut ffi::GstPlayer,
object: u64, object: u64,
f: glib_sys::gpointer, f: glib::ffi::gpointer,
) { ) {
let f: &F = &*(f as *const F); let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), gst::ClockTime(Some(object))) f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
@ -131,18 +117,18 @@ unsafe extern "C" fn duration_changed_trampoline<
unsafe extern "C" fn position_updated_trampoline< unsafe extern "C" fn position_updated_trampoline<
F: Fn(&Player, gst::ClockTime) + Send + 'static, F: Fn(&Player, gst::ClockTime) + Send + 'static,
>( >(
this: *mut gst_player_sys::GstPlayer, this: *mut ffi::GstPlayer,
object: u64, object: u64,
f: glib_sys::gpointer, f: glib::ffi::gpointer,
) { ) {
let f: &F = &*(f as *const F); let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), gst::ClockTime(Some(object))) f(&from_glib_borrow(this), gst::ClockTime(Some(object)))
} }
unsafe extern "C" fn seek_done_trampoline<F: Fn(&Player, gst::ClockTime) + Send + 'static>( unsafe extern "C" fn seek_done_trampoline<F: Fn(&Player, gst::ClockTime) + Send + 'static>(
this: *mut gst_player_sys::GstPlayer, this: *mut ffi::GstPlayer,
object: u64, object: u64,
f: glib_sys::gpointer, f: glib::ffi::gpointer,
) { ) {
let f: &F = &*(f as *const F); let f: &F = &*(f as *const F);
f(&from_glib_borrow(this), gst::ClockTime(Some(object))) f(&from_glib_borrow(this), gst::ClockTime(Some(object)))

View file

@ -6,10 +6,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use glib; use crate::PlayerGMainContextSignalDispatcher;
use glib::translate::*; use glib::translate::*;
use gst_player_sys;
use PlayerGMainContextSignalDispatcher;
impl PlayerGMainContextSignalDispatcher { impl PlayerGMainContextSignalDispatcher {
pub fn new( pub fn new(
@ -18,11 +16,10 @@ impl PlayerGMainContextSignalDispatcher {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let application_context = application_context.to_glib_none(); let application_context = application_context.to_glib_none();
unsafe { unsafe {
from_glib_full( from_glib_full(ffi::gst_player_g_main_context_signal_dispatcher_new(
gst_player_sys::gst_player_g_main_context_signal_dispatcher_new(
application_context.0, application_context.0,
) as *mut gst_player_sys::GstPlayerGMainContextSignalDispatcher,
) )
as *mut ffi::GstPlayerGMainContextSignalDispatcher)
} }
} }
} }

View file

@ -6,18 +6,16 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::PlayerVideoInfo;
use glib::translate::*; use glib::translate::*;
use gst;
use gst_player_sys;
use std::mem; use std::mem;
use PlayerVideoInfo;
impl PlayerVideoInfo { impl PlayerVideoInfo {
pub fn get_framerate(&self) -> gst::Fraction { pub fn get_framerate(&self) -> gst::Fraction {
unsafe { unsafe {
let mut fps_n = mem::MaybeUninit::uninit(); let mut fps_n = mem::MaybeUninit::uninit();
let mut fps_d = mem::MaybeUninit::uninit(); let mut fps_d = mem::MaybeUninit::uninit();
gst_player_sys::gst_player_video_info_get_framerate( ffi::gst_player_video_info_get_framerate(
self.to_glib_none().0, self.to_glib_none().0,
fps_n.as_mut_ptr(), fps_n.as_mut_ptr(),
fps_d.as_mut_ptr(), fps_d.as_mut_ptr(),
@ -30,7 +28,7 @@ impl PlayerVideoInfo {
unsafe { unsafe {
let mut par_n = mem::MaybeUninit::uninit(); let mut par_n = mem::MaybeUninit::uninit();
let mut par_d = mem::MaybeUninit::uninit(); let mut par_d = mem::MaybeUninit::uninit();
gst_player_sys::gst_player_video_info_get_pixel_aspect_ratio( ffi::gst_player_video_info_get_pixel_aspect_ratio(
self.to_glib_none().0, self.to_glib_none().0,
par_n.as_mut_ptr(), par_n.as_mut_ptr(),
par_d.as_mut_ptr(), par_d.as_mut_ptr(),

View file

@ -6,11 +6,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use crate::PlayerVideoOverlayVideoRenderer;
use glib::translate::*; use glib::translate::*;
use glib::IsA; use glib::IsA;
use gst;
use gst_player_sys;
use PlayerVideoOverlayVideoRenderer;
use std::ptr; use std::ptr;
@ -20,9 +18,9 @@ impl PlayerVideoOverlayVideoRenderer {
pub unsafe fn new(window_handle: uintptr_t) -> PlayerVideoOverlayVideoRenderer { pub unsafe fn new(window_handle: uintptr_t) -> PlayerVideoOverlayVideoRenderer {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
from_glib_full(gst_player_sys::gst_player_video_overlay_video_renderer_new( from_glib_full(
window_handle as *mut _, ffi::gst_player_video_overlay_video_renderer_new(window_handle as *mut _) as *mut _,
) as *mut _) )
} }
pub unsafe fn with_handle_and_sink<P: IsA<gst::Element>>( pub unsafe fn with_handle_and_sink<P: IsA<gst::Element>>(
@ -31,35 +29,30 @@ impl PlayerVideoOverlayVideoRenderer {
) -> PlayerVideoOverlayVideoRenderer { ) -> PlayerVideoOverlayVideoRenderer {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
from_glib_full( from_glib_full(ffi::gst_player_video_overlay_video_renderer_new_with_sink(
gst_player_sys::gst_player_video_overlay_video_renderer_new_with_sink(
window_handle as *mut _, window_handle as *mut _,
video_sink.as_ref().to_glib_none().0, video_sink.as_ref().to_glib_none().0,
) as *mut _, ) as *mut _)
)
} }
pub fn with_sink<P: IsA<gst::Element>>(video_sink: &P) -> PlayerVideoOverlayVideoRenderer { pub fn with_sink<P: IsA<gst::Element>>(video_sink: &P) -> PlayerVideoOverlayVideoRenderer {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
unsafe { unsafe {
from_glib_full( from_glib_full(ffi::gst_player_video_overlay_video_renderer_new_with_sink(
gst_player_sys::gst_player_video_overlay_video_renderer_new_with_sink(
ptr::null_mut(), ptr::null_mut(),
video_sink.as_ref().to_glib_none().0, video_sink.as_ref().to_glib_none().0,
) as *mut _, ) as *mut _)
)
} }
} }
pub unsafe fn get_window_handle(&self) -> uintptr_t { pub unsafe fn get_window_handle(&self) -> uintptr_t {
gst_player_sys::gst_player_video_overlay_video_renderer_get_window_handle( ffi::gst_player_video_overlay_video_renderer_get_window_handle(self.to_glib_none().0)
self.to_glib_none().0, as uintptr_t
) as uintptr_t
} }
pub unsafe fn set_window_handle(&self, window_handle: uintptr_t) { pub unsafe fn set_window_handle(&self, window_handle: uintptr_t) {
gst_player_sys::gst_player_video_overlay_video_renderer_set_window_handle( ffi::gst_player_video_overlay_video_renderer_set_window_handle(
self.to_glib_none().0, self.to_glib_none().0,
window_handle as *mut _, window_handle as *mut _,
) )

View file

@ -9,7 +9,7 @@
use glib::translate::*; use glib::translate::*;
use std::ffi::CStr; use std::ffi::CStr;
use PlayerVisualization; use crate::PlayerVisualization;
impl PlayerVisualization { impl PlayerVisualization {
pub fn name(&self) -> &str { pub fn name(&self) -> &str {