From 14f485d0b1185738f41d7b516ccf6ad5d81f59bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 28 Jun 2022 23:17:58 +0300 Subject: [PATCH] bus: Take ownership of the message in post() --- gstreamer/Gir.toml | 4 ++-- gstreamer/src/auto/bus.rs | 10 ---------- gstreamer/src/bus.rs | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 489e9e1e6..7c1a35dc0 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -608,8 +608,8 @@ final_type = true [[object.function]] name = "post" - [object.function.return] - bool_return_is_error = "Failed to post message" + # transfer ownership of the message + manual = true [[object]] name = "Gst.Caps" diff --git a/gstreamer/src/auto/bus.rs b/gstreamer/src/auto/bus.rs index 75430e4de..63d5a3a98 100644 --- a/gstreamer/src/auto/bus.rs +++ b/gstreamer/src/auto/bus.rs @@ -76,16 +76,6 @@ impl Bus { unsafe { from_glib_full(ffi::gst_bus_pop(self.to_glib_none().0)) } } - #[doc(alias = "gst_bus_post")] - pub fn post(&self, message: &Message) -> Result<(), glib::error::BoolError> { - unsafe { - glib::result_from_gboolean!( - ffi::gst_bus_post(self.to_glib_none().0, message.to_glib_full()), - "Failed to post message" - ) - } - } - #[doc(alias = "gst_bus_remove_signal_watch")] pub fn remove_signal_watch(&self) { unsafe { diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index c4b1033f0..8fa46f48e 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -302,6 +302,16 @@ impl Bus { future::ready(message_types.contains(&message_type)) }) } + + #[doc(alias = "gst_bus_post")] + pub fn post(&self, message: crate::Message) -> Result<(), glib::error::BoolError> { + unsafe { + glib::result_from_gboolean!( + ffi::gst_bus_post(self.to_glib_none().0, message.into_glib_ptr()), + "Failed to post message" + ) + } + } } #[derive(Debug)] @@ -382,7 +392,7 @@ mod tests { BusSyncReply::Pass }); - bus.post(&crate::message::Eos::new()).unwrap(); + bus.post(crate::message::Eos::new()).unwrap(); let msgs = msgs.lock().unwrap(); assert_eq!(msgs.len(), 1); @@ -400,7 +410,7 @@ mod tests { let bus_stream = bus.stream(); let eos_message = crate::message::Eos::new(); - bus.post(&eos_message).unwrap(); + bus.post(eos_message).unwrap(); let bus_future = bus_stream.into_future(); let (message, _) = futures_executor::block_on(bus_future);