gstreamer-app: Update manual code to 2018 edition

This commit is contained in:
Sebastian Dröge 2020-11-21 20:06:11 +02:00
parent e7843d68d0
commit 5a70dd1756
4 changed files with 62 additions and 105 deletions

View file

@ -11,19 +11,17 @@ homepage = "https://gstreamer.freedesktop.org"
documentation = "https://gstreamer.pages.freedesktop.org/gstreamer-rs/gstreamer_app/"
keywords = ["gstreamer", "multimedia", "audio", "video", "gnome"]
build = "build.rs"
edition = "2018"
[dependencies]
futures-core = "0.3"
futures-sink = "0.3"
bitflags = "1.0"
libc = "0.2"
glib-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gobject-sys = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer-sys = { path = "../gstreamer/sys", features = ["v1_8"] }
gstreamer-app-sys = { path = "../gstreamer-app/sys", features = ["v1_8"] }
ffi = { package = "gstreamer-app-sys", path = "../gstreamer-app/sys", features = ["v1_8"] }
glib = { git = "https://github.com/gtk-rs/gtk-rs" }
gstreamer = { path = "../gstreamer" }
gstreamer-base = { path = "../gstreamer-base" }
gst = { package = "gstreamer", path = "../gstreamer" }
gst-base = { package = "gstreamer-base", path = "../gstreamer-base" }
once_cell = "1.0"
[build-dependencies]
@ -35,14 +33,14 @@ futures-executor = "0.3"
[features]
default = []
v1_10 = ["gstreamer/v1_10", "gstreamer-base/v1_10", "gstreamer-app-sys/v1_10"]
v1_12 = ["gstreamer/v1_12", "gstreamer-base/v1_12", "gstreamer-app-sys/v1_12", "v1_10"]
v1_14 = ["gstreamer/v1_14", "gstreamer-base/v1_14", "gstreamer-app-sys/v1_14", "v1_12"]
v1_16 = ["gstreamer/v1_16", "gstreamer-base/v1_16", "gstreamer-app-sys/v1_16", "v1_14"]
v1_18 = ["gstreamer/v1_18", "gstreamer-base/v1_18", "gstreamer-app-sys/v1_18", "v1_16"]
v1_10 = ["gst/v1_10", "gst-base/v1_10", "ffi/v1_10"]
v1_12 = ["gst/v1_12", "gst-base/v1_12", "ffi/v1_12", "v1_10"]
v1_14 = ["gst/v1_14", "gst-base/v1_14", "ffi/v1_14", "v1_12"]
v1_16 = ["gst/v1_16", "gst-base/v1_16", "ffi/v1_16", "v1_14"]
v1_18 = ["gst/v1_18", "gst-base/v1_18", "ffi/v1_18", "v1_16"]
embed-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
purge-lgpl-docs = ["gstreamer-rs-lgpl-docs"]
dox = ["v1_18", "gstreamer-app-sys/dox", "glib/dox", "gstreamer/dox", "gstreamer-base/dox"]
dox = ["v1_18", "ffi/dox", "glib/dox", "gst/dox", "gst-base/dox"]
[package.metadata.docs.rs]
features = ["dox", "embed-lgpl-docs"]

View file

@ -6,22 +6,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use crate::AppSink;
use glib::ffi::gpointer;
use glib::object::ObjectType;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib_sys::gpointer;
use gst;
use gst::gst_element_error;
use gst_app_sys;
use gst_sys;
use std::boxed::Box as Box_;
use std::cell::RefCell;
use std::mem::transmute;
use std::panic;
use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering};
use AppSink;
#[cfg(any(feature = "v1_10"))]
use {
@ -48,7 +44,7 @@ pub struct AppSinkCallbacks {
>,
>,
panicked: AtomicBool,
callbacks: gst_app_sys::GstAppSinkCallbacks,
callbacks: ffi::GstAppSinkCallbacks,
}
unsafe impl Send for AppSinkCallbacks {}
@ -122,7 +118,7 @@ impl AppSinkCallbacksBuilder {
new_preroll: self.new_preroll,
new_sample: self.new_sample,
panicked: AtomicBool::new(false),
callbacks: gst_app_sys::GstAppSinkCallbacks {
callbacks: ffi::GstAppSinkCallbacks {
eos: if have_eos { Some(trampoline_eos) } else { None },
new_preroll: if have_new_preroll {
Some(trampoline_new_preroll)
@ -148,21 +144,21 @@ impl AppSinkCallbacksBuilder {
fn post_panic_error_message(element: &AppSink, err: &dyn std::any::Any) {
skip_assert_initialized!();
if let Some(cause) = err.downcast_ref::<&str>() {
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
} else if let Some(cause) = err.downcast_ref::<String>() {
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
} else {
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
}
}
unsafe extern "C" fn trampoline_eos(appsink: *mut gst_app_sys::GstAppSink, callbacks: gpointer) {
unsafe extern "C" fn trampoline_eos(appsink: *mut ffi::GstAppSink, callbacks: gpointer) {
let callbacks = &*(callbacks as *const AppSinkCallbacks);
let element: Borrowed<AppSink> = from_glib_borrow(appsink);
if callbacks.panicked.load(Ordering::Relaxed) {
let element: Borrowed<AppSink> = from_glib_borrow(appsink);
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
return;
}
@ -181,15 +177,15 @@ unsafe extern "C" fn trampoline_eos(appsink: *mut gst_app_sys::GstAppSink, callb
}
unsafe extern "C" fn trampoline_new_preroll(
appsink: *mut gst_app_sys::GstAppSink,
appsink: *mut ffi::GstAppSink,
callbacks: gpointer,
) -> gst_sys::GstFlowReturn {
) -> gst::ffi::GstFlowReturn {
let callbacks = &*(callbacks as *const AppSinkCallbacks);
let element: Borrowed<AppSink> = from_glib_borrow(appsink);
if callbacks.panicked.load(Ordering::Relaxed) {
let element: Borrowed<AppSink> = from_glib_borrow(appsink);
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
return gst::FlowReturn::Error.to_glib();
}
@ -214,15 +210,15 @@ unsafe extern "C" fn trampoline_new_preroll(
}
unsafe extern "C" fn trampoline_new_sample(
appsink: *mut gst_app_sys::GstAppSink,
appsink: *mut ffi::GstAppSink,
callbacks: gpointer,
) -> gst_sys::GstFlowReturn {
) -> gst::ffi::GstFlowReturn {
let callbacks = &*(callbacks as *const AppSinkCallbacks);
let element: Borrowed<AppSink> = from_glib_borrow(appsink);
if callbacks.panicked.load(Ordering::Relaxed) {
let element: Borrowed<AppSink> = from_glib_borrow(appsink);
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
return gst::FlowReturn::Error.to_glib();
}
@ -262,20 +258,20 @@ impl AppSink {
// This is not thread-safe before 1.16.3, see
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
if gst::version() < (1, 16, 3, 0) {
if !gobject_sys::g_object_get_qdata(sink as *mut _, SET_ONCE_QUARK.to_glib())
if !glib::gobject_ffi::g_object_get_qdata(sink as *mut _, SET_ONCE_QUARK.to_glib())
.is_null()
{
panic!("AppSink callbacks can only be set once");
}
gobject_sys::g_object_set_qdata(
glib::gobject_ffi::g_object_set_qdata(
sink as *mut _,
SET_ONCE_QUARK.to_glib(),
1 as *mut _,
);
}
gst_app_sys::gst_app_sink_set_callbacks(
ffi::gst_app_sink_set_callbacks(
sink,
mut_override(&callbacks.callbacks),
Box::into_raw(Box::new(callbacks)) as *mut _,
@ -331,9 +327,9 @@ impl AppSink {
unsafe extern "C" fn new_sample_trampoline<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
>(
this: *mut gst_app_sys::GstAppSink,
f: glib_sys::gpointer,
) -> gst_sys::GstFlowReturn {
this: *mut ffi::GstAppSink,
f: glib::ffi::gpointer,
) -> gst::ffi::GstFlowReturn {
let f: &F = &*(f as *const F);
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
ret.to_glib()
@ -342,9 +338,9 @@ unsafe extern "C" fn new_sample_trampoline<
unsafe extern "C" fn new_preroll_trampoline<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
>(
this: *mut gst_app_sys::GstAppSink,
f: glib_sys::gpointer,
) -> gst_sys::GstFlowReturn {
this: *mut ffi::GstAppSink,
f: glib::ffi::gpointer,
) -> gst::ffi::GstFlowReturn {
let f: &F = &*(f as *const F);
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
ret.to_glib()

View file

@ -7,13 +7,11 @@
// except according to those terms.
use futures_sink::Sink;
use glib::ffi::{gboolean, gpointer};
use glib::prelude::*;
use glib::translate::*;
use glib_sys::{gboolean, gpointer};
use gst;
use gst::gst_element_error;
use gst_app_sys;
use crate::AppSrc;
use std::cell::RefCell;
use std::mem;
use std::panic;
@ -22,7 +20,6 @@ use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll, Waker};
use AppSrc;
#[allow(clippy::type_complexity)]
pub struct AppSrcCallbacks {
@ -30,7 +27,7 @@ pub struct AppSrcCallbacks {
enough_data: Option<Box<dyn Fn(&AppSrc) + Send + Sync + 'static>>,
seek_data: Option<Box<dyn Fn(&AppSrc, u64) -> bool + Send + Sync + 'static>>,
panicked: AtomicBool,
callbacks: gst_app_sys::GstAppSrcCallbacks,
callbacks: ffi::GstAppSrcCallbacks,
}
unsafe impl Send for AppSrcCallbacks {}
@ -90,7 +87,7 @@ impl AppSrcCallbacksBuilder {
enough_data: self.enough_data,
seek_data: self.seek_data,
panicked: AtomicBool::new(false),
callbacks: gst_app_sys::GstAppSrcCallbacks {
callbacks: ffi::GstAppSrcCallbacks {
need_data: if have_need_data {
Some(trampoline_need_data)
} else {
@ -120,16 +117,16 @@ impl AppSrcCallbacksBuilder {
fn post_panic_error_message(element: &AppSrc, err: &dyn std::any::Any) {
skip_assert_initialized!();
if let Some(cause) = err.downcast_ref::<&str>() {
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
} else if let Some(cause) = err.downcast_ref::<String>() {
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked: {}", cause]);
} else {
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
}
}
unsafe extern "C" fn trampoline_need_data(
appsrc: *mut gst_app_sys::GstAppSrc,
appsrc: *mut ffi::GstAppSrc,
length: u32,
callbacks: gpointer,
) {
@ -138,7 +135,7 @@ unsafe extern "C" fn trampoline_need_data(
if callbacks.panicked.load(Ordering::Relaxed) {
let element: Borrowed<AppSrc> = from_glib_borrow(appsrc);
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
return;
}
@ -156,16 +153,13 @@ unsafe extern "C" fn trampoline_need_data(
}
}
unsafe extern "C" fn trampoline_enough_data(
appsrc: *mut gst_app_sys::GstAppSrc,
callbacks: gpointer,
) {
unsafe extern "C" fn trampoline_enough_data(appsrc: *mut ffi::GstAppSrc, callbacks: gpointer) {
let callbacks = &*(callbacks as *const AppSrcCallbacks);
let element: Borrowed<AppSrc> = from_glib_borrow(appsrc);
if callbacks.panicked.load(Ordering::Relaxed) {
let element: Borrowed<AppSrc> = from_glib_borrow(appsrc);
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
return;
}
@ -182,7 +176,7 @@ unsafe extern "C" fn trampoline_enough_data(
}
unsafe extern "C" fn trampoline_seek_data(
appsrc: *mut gst_app_sys::GstAppSrc,
appsrc: *mut ffi::GstAppSrc,
offset: u64,
callbacks: gpointer,
) -> gboolean {
@ -191,7 +185,7 @@ unsafe extern "C" fn trampoline_seek_data(
if callbacks.panicked.load(Ordering::Relaxed) {
let element: Borrowed<AppSrc> = from_glib_borrow(appsrc);
gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
gst::gst_element_error!(&element, gst::LibraryError::Failed, ["Panicked"]);
return false.to_glib();
}
@ -220,17 +214,14 @@ unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
impl AppSrc {
pub fn end_of_stream(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(gst_app_sys::gst_app_src_end_of_stream(
self.to_glib_none().0,
))
};
let ret: gst::FlowReturn =
unsafe { from_glib(ffi::gst_app_src_end_of_stream(self.to_glib_none().0)) };
ret.into_result()
}
pub fn push_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(gst_app_sys::gst_app_src_push_buffer(
from_glib(ffi::gst_app_src_push_buffer(
self.to_glib_none().0,
buffer.into_ptr(),
))
@ -245,7 +236,7 @@ impl AppSrc {
list: gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(gst_app_sys::gst_app_src_push_buffer_list(
from_glib(ffi::gst_app_src_push_buffer_list(
self.to_glib_none().0,
list.into_ptr(),
))
@ -255,7 +246,7 @@ impl AppSrc {
pub fn push_sample(&self, sample: &gst::Sample) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(gst_app_sys::gst_app_src_push_sample(
from_glib(ffi::gst_app_src_push_sample(
self.to_glib_none().0,
sample.to_glib_none().0,
))
@ -273,20 +264,20 @@ impl AppSrc {
// This is not thread-safe before 1.16.3, see
// https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570
if gst::version() < (1, 16, 3, 0) {
if !gobject_sys::g_object_get_qdata(src as *mut _, SET_ONCE_QUARK.to_glib())
if !glib::gobject_ffi::g_object_get_qdata(src as *mut _, SET_ONCE_QUARK.to_glib())
.is_null()
{
panic!("AppSrc callbacks can only be set once");
}
gobject_sys::g_object_set_qdata(
glib::gobject_ffi::g_object_set_qdata(
src as *mut _,
SET_ONCE_QUARK.to_glib(),
1 as *mut _,
);
}
gst_app_sys::gst_app_src_set_callbacks(
ffi::gst_app_src_set_callbacks(
src,
mut_override(&callbacks.callbacks),
Box::into_raw(Box::new(callbacks)) as *mut _,
@ -297,11 +288,7 @@ impl AppSrc {
pub fn set_latency(&self, min: gst::ClockTime, max: gst::ClockTime) {
unsafe {
gst_app_sys::gst_app_src_set_latency(
self.to_glib_none().0,
min.to_glib(),
max.to_glib(),
);
ffi::gst_app_src_set_latency(self.to_glib_none().0, min.to_glib(), max.to_glib());
}
}
@ -309,11 +296,7 @@ impl AppSrc {
unsafe {
let mut min = mem::MaybeUninit::uninit();
let mut max = mem::MaybeUninit::uninit();
gst_app_sys::gst_app_src_get_latency(
self.to_glib_none().0,
min.as_mut_ptr(),
max.as_mut_ptr(),
);
ffi::gst_app_src_get_latency(self.to_glib_none().0, min.as_mut_ptr(), max.as_mut_ptr());
(from_glib(min.assume_init()), from_glib(max.assume_init()))
}
}

View file

@ -8,27 +8,7 @@
#![cfg_attr(feature = "dox", feature(doc_cfg))]
extern crate libc;
extern crate futures_core;
extern crate futures_sink;
extern crate glib_sys;
extern crate gobject_sys;
extern crate gstreamer as gst;
extern crate gstreamer_app_sys as gst_app_sys;
extern crate gstreamer_base as gst_base;
extern crate gstreamer_sys as gst_sys;
extern crate once_cell;
#[macro_use]
extern crate glib;
#[cfg(test)]
extern crate futures_util;
#[cfg(test)]
extern crate futures_executor;
pub use ffi;
macro_rules! skip_assert_initialized {
() => {};
@ -38,13 +18,13 @@ macro_rules! skip_assert_initialized {
#[allow(clippy::too_many_arguments)]
#[allow(clippy::match_same_arms)]
mod auto;
pub use auto::*;
pub use crate::auto::*;
pub mod app_sink;
pub use app_sink::AppSinkCallbacks;
pub use crate::app_sink::AppSinkCallbacks;
pub mod app_src;
pub use app_src::AppSrcCallbacks;
pub use crate::app_src::AppSrcCallbacks;
// Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts
@ -52,5 +32,5 @@ pub mod prelude {
pub use glib::prelude::*;
pub use gst::prelude::*;
pub use auto::traits::*;
pub use crate::auto::traits::*;
}