gstreamer/element: Let post_message() and post_error_message() take ownership of the message

This is more in line with the C API and simplifies callers in Rust.
This commit is contained in:
Sebastian Dröge 2020-06-30 23:51:15 +03:00
parent 71b83b7c84
commit 9cc99b27e0
14 changed files with 65 additions and 62 deletions

View file

@ -512,6 +512,11 @@ manual_traits = ["ElementExtManual"]
# manual implementation also works for earlier versions # manual implementation also works for earlier versions
ignore = true ignore = true
[[object.function]]
name = "post_message"
# takes ownership of message
ignore = true
[[object.function]] [[object.function]]
name = "add_pad" name = "add_pad"
[object.function.return] [object.function.return]

View file

@ -554,7 +554,7 @@ where
match imp.open(&wrap) { match imp.open(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -577,7 +577,7 @@ where
match imp.close(&wrap) { match imp.close(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -600,7 +600,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -623,7 +623,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -890,7 +890,7 @@ where
match imp.propose_allocation(&wrap, query) { match imp.propose_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -915,7 +915,7 @@ where
match imp.decide_allocation(&wrap, query) { match imp.decide_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -502,7 +502,7 @@ where
match imp.open(&wrap) { match imp.open(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -525,7 +525,7 @@ where
match imp.close(&wrap) { match imp.close(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -548,7 +548,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -571,7 +571,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -807,7 +807,7 @@ where
match imp.propose_allocation(&wrap, query) { match imp.propose_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -832,7 +832,7 @@ where
match imp.decide_allocation(&wrap, query) { match imp.decide_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -888,7 +888,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -911,7 +911,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -247,7 +247,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -270,7 +270,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -295,7 +295,7 @@ where
match imp.set_sink_caps(&wrap, &caps) { match imp.set_sink_caps(&wrap, &caps) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -421,7 +421,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -444,7 +444,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -644,7 +644,7 @@ where
match imp.unlock(&wrap) { match imp.unlock(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -667,7 +667,7 @@ where
match imp.unlock_stop(&wrap) { match imp.unlock_stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -614,7 +614,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -637,7 +637,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -1006,7 +1006,7 @@ where
match imp.unlock(&wrap) { match imp.unlock(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -1029,7 +1029,7 @@ where
match imp.unlock_stop(&wrap) { match imp.unlock_stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -923,7 +923,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -946,7 +946,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -544,7 +544,7 @@ where
match imp.open(&wrap) { match imp.open(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -567,7 +567,7 @@ where
match imp.close(&wrap) { match imp.close(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -590,7 +590,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -613,7 +613,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -877,7 +877,7 @@ where
match imp.propose_allocation(&wrap, query) { match imp.propose_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -902,7 +902,7 @@ where
match imp.decide_allocation(&wrap, query) { match imp.decide_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -478,7 +478,7 @@ where
match imp.open(&wrap) { match imp.open(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -501,7 +501,7 @@ where
match imp.close(&wrap) { match imp.close(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -524,7 +524,7 @@ where
match imp.start(&wrap) { match imp.start(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -547,7 +547,7 @@ where
match imp.stop(&wrap) { match imp.stop(&wrap) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -770,7 +770,7 @@ where
match imp.propose_allocation(&wrap, query) { match imp.propose_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }
@ -795,7 +795,7 @@ where
match imp.decide_allocation(&wrap, query) { match imp.decide_allocation(&wrap, query) {
Ok(()) => true, Ok(()) => true,
Err(err) => { Err(err) => {
wrap.post_error_message(&err); wrap.post_error_message(err);
false false
} }
} }

View file

@ -19,7 +19,6 @@ use Clock;
use ClockTime; use ClockTime;
use Context; use Context;
use ElementFactory; use ElementFactory;
use Message;
use Object; use Object;
use Pad; use Pad;
use PadLinkCheck; use PadLinkCheck;
@ -151,8 +150,6 @@ pub trait ElementExt: 'static {
fn no_more_pads(&self); fn no_more_pads(&self);
fn post_message(&self, message: &Message) -> Result<(), glib::error::BoolError>;
fn provide_clock(&self) -> Option<Clock>; fn provide_clock(&self) -> Option<Clock>;
fn release_request_pad<P: IsA<Pad>>(&self, pad: &P); fn release_request_pad<P: IsA<Pad>>(&self, pad: &P);
@ -524,18 +521,6 @@ impl<O: IsA<Element>> ElementExt for O {
} }
} }
fn post_message(&self, message: &Message) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_element_post_message(
self.as_ref().to_glib_none().0,
message.to_glib_full()
),
"Failed to post message"
)
}
}
fn provide_clock(&self) -> Option<Clock> { fn provide_clock(&self) -> Option<Clock> {
unsafe { unsafe {
from_glib_full(gst_sys::gst_element_provide_clock( from_glib_full(gst_sys::gst_element_provide_clock(

View file

@ -189,7 +189,8 @@ pub trait ElementExtManual: 'static {
structure: ::Structure, structure: ::Structure,
); );
fn post_error_message(&self, msg: &::ErrorMessage); fn post_message(&self, message: ::Message) -> Result<(), glib::error::BoolError>;
fn post_error_message(&self, msg: ::ErrorMessage);
fn iterate_pads(&self) -> ::Iterator<Pad>; fn iterate_pads(&self) -> ::Iterator<Pad>;
fn iterate_sink_pads(&self) -> ::Iterator<Pad>; fn iterate_sink_pads(&self) -> ::Iterator<Pad>;
@ -454,7 +455,19 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn post_error_message(&self, msg: &::ErrorMessage) { fn post_message(&self, message: ::Message) -> Result<(), glib::error::BoolError> {
unsafe {
glib_result_from_gboolean!(
gst_sys::gst_element_post_message(
self.as_ref().to_glib_none().0,
message.into_ptr()
),
"Failed to post message"
)
}
}
fn post_error_message(&self, msg: ::ErrorMessage) {
let ::ErrorMessage { let ::ErrorMessage {
error_domain, error_domain,
error_code, error_code,
@ -463,7 +476,7 @@ impl<O: IsA<Element>> ElementExtManual for O {
filename, filename,
function, function,
line, line,
} = *msg; } = msg;
unsafe { unsafe {
gst_sys::gst_element_message_full( gst_sys::gst_element_message_full(

View file

@ -21,7 +21,7 @@ macro_rules! gst_panic_to_error(
#[allow(clippy::unused_unit)] #[allow(clippy::unused_unit)]
{ {
if $panicked.load(Ordering::Relaxed) { if $panicked.load(Ordering::Relaxed) {
$element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked"])); $element.post_error_message(gst_error_msg!($crate::LibraryError::Failed, ["Panicked"]));
$ret $ret
} else { } else {
let result = panic::catch_unwind(AssertUnwindSafe(|| $code)); let result = panic::catch_unwind(AssertUnwindSafe(|| $code));
@ -31,11 +31,11 @@ macro_rules! gst_panic_to_error(
Err(err) => { Err(err) => {
$panicked.store(true, Ordering::Relaxed); $panicked.store(true, Ordering::Relaxed);
if let Some(cause) = err.downcast_ref::<&str>() { if let Some(cause) = err.downcast_ref::<&str>() {
$element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); $element.post_error_message(gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause]));
} else if let Some(cause) = err.downcast_ref::<String>() { } else if let Some(cause) = err.downcast_ref::<String>() {
$element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause])); $element.post_error_message(gst_error_msg!($crate::LibraryError::Failed, ["Panicked: {}", cause]));
} else { } else {
$element.post_error_message(&gst_error_msg!($crate::LibraryError::Failed, ["Panicked"])); $element.post_error_message(gst_error_msg!($crate::LibraryError::Failed, ["Panicked"]));
} }
$ret $ret
} }

View file

@ -303,7 +303,7 @@ mod tutorial5 {
// We are possibly in a GStreamer working thread, so we notify the main // We are possibly in a GStreamer working thread, so we notify the main
// thread of this event through a message in the bus // thread of this event through a message in the bus
fn post_app_message(playbin: &gst::Element) { fn post_app_message(playbin: &gst::Element) {
let _ = playbin.post_message(&gst::message::Application::new(gst::Structure::new_empty( let _ = playbin.post_message(gst::message::Application::new(gst::Structure::new_empty(
"tags-changed", "tags-changed",
))); )));
} }