From 130cc9d63b0ae66eddd8342d1c65780956c9e045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 19 Oct 2022 17:57:16 +0300 Subject: [PATCH] element: Implement linking functions manually for better error reporting Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/318 --- gstreamer/Gir.toml | 22 ++--- gstreamer/src/auto/element.rs | 127 -------------------------- gstreamer/src/element.rs | 167 +++++++++++++++++++++++++++++++++- 3 files changed, 175 insertions(+), 141 deletions(-) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index ba1a009d1..22c807016 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -1038,13 +1038,13 @@ manual_traits = ["ElementExtManual"] # but gir considers these methods on `ElementExtManual` in the docs. [[object.function]] name = "link_many" - ignore = true + manual = true [[object.function]] name = "unlink_many" - ignore = true + manual = true [[object.function]] name = "register" - ignore = true + manual = true [[object.function]] name = "call_async" @@ -1094,38 +1094,34 @@ manual_traits = ["ElementExtManual"] [object.function.return] bool_return_is_error = "Failed to remove pad" + # Manual implementations with better error reporting [[object.function]] name = "link" - [object.function.return] - bool_return_is_error = "Failed to link elements" + manual = true [[object.function]] name = "link_filtered" + manual = true [[object.function.parameter]] name = "filter" # Can use `link` instead nullable = false - [object.function.return] - bool_return_is_error = "Failed to link elements" [[object.function]] name = "link_pads" - [object.function.return] - bool_return_is_error = "Failed to link pads" + manual = true [[object.function]] name = "link_pads_filtered" + manual = true [[object.function.parameter]] name = "filter" # Can use `link` instead nullable = false - [object.function.return] - bool_return_is_error = "Failed to link pads" [[object.function]] name = "link_pads_full" - [object.function.return] - bool_return_is_error = "Failed to link pads" + manual = true [[object.function]] name = "set_clock" diff --git a/gstreamer/src/auto/element.rs b/gstreamer/src/auto/element.rs index e517a3ae1..72b78bbfd 100644 --- a/gstreamer/src/auto/element.rs +++ b/gstreamer/src/auto/element.rs @@ -11,7 +11,6 @@ use crate::Context; use crate::ElementFactory; use crate::Object; use crate::Pad; -use crate::PadLinkCheck; use crate::PadTemplate; use crate::State; use crate::StateChange; @@ -147,42 +146,6 @@ pub trait ElementExt: 'static { #[doc(alias = "gst_element_is_locked_state")] fn is_locked_state(&self) -> bool; - #[doc(alias = "gst_element_link")] - fn link(&self, dest: &impl IsA) -> Result<(), glib::error::BoolError>; - - #[doc(alias = "gst_element_link_filtered")] - fn link_filtered( - &self, - dest: &impl IsA, - filter: &Caps, - ) -> Result<(), glib::error::BoolError>; - - #[doc(alias = "gst_element_link_pads")] - fn link_pads( - &self, - srcpadname: Option<&str>, - dest: &impl IsA, - destpadname: Option<&str>, - ) -> Result<(), glib::error::BoolError>; - - #[doc(alias = "gst_element_link_pads_filtered")] - fn link_pads_filtered( - &self, - srcpadname: Option<&str>, - dest: &impl IsA, - destpadname: Option<&str>, - filter: &Caps, - ) -> Result<(), glib::error::BoolError>; - - #[doc(alias = "gst_element_link_pads_full")] - fn link_pads_full( - &self, - srcpadname: Option<&str>, - dest: &impl IsA, - destpadname: Option<&str>, - flags: PadLinkCheck, - ) -> Result<(), glib::error::BoolError>; - #[doc(alias = "gst_element_lost_state")] fn lost_state(&self); @@ -475,96 +438,6 @@ impl> ElementExt for O { } } - fn link(&self, dest: &impl IsA) -> Result<(), glib::error::BoolError> { - unsafe { - glib::result_from_gboolean!( - ffi::gst_element_link( - self.as_ref().to_glib_none().0, - dest.as_ref().to_glib_none().0 - ), - "Failed to link elements" - ) - } - } - - fn link_filtered( - &self, - dest: &impl IsA, - filter: &Caps, - ) -> Result<(), glib::error::BoolError> { - unsafe { - glib::result_from_gboolean!( - ffi::gst_element_link_filtered( - self.as_ref().to_glib_none().0, - dest.as_ref().to_glib_none().0, - filter.to_glib_none().0 - ), - "Failed to link elements" - ) - } - } - - fn link_pads( - &self, - srcpadname: Option<&str>, - dest: &impl IsA, - destpadname: Option<&str>, - ) -> Result<(), glib::error::BoolError> { - unsafe { - glib::result_from_gboolean!( - ffi::gst_element_link_pads( - self.as_ref().to_glib_none().0, - srcpadname.to_glib_none().0, - dest.as_ref().to_glib_none().0, - destpadname.to_glib_none().0 - ), - "Failed to link pads" - ) - } - } - - fn link_pads_filtered( - &self, - srcpadname: Option<&str>, - dest: &impl IsA, - destpadname: Option<&str>, - filter: &Caps, - ) -> Result<(), glib::error::BoolError> { - unsafe { - glib::result_from_gboolean!( - ffi::gst_element_link_pads_filtered( - self.as_ref().to_glib_none().0, - srcpadname.to_glib_none().0, - dest.as_ref().to_glib_none().0, - destpadname.to_glib_none().0, - filter.to_glib_none().0 - ), - "Failed to link pads" - ) - } - } - - fn link_pads_full( - &self, - srcpadname: Option<&str>, - dest: &impl IsA, - destpadname: Option<&str>, - flags: PadLinkCheck, - ) -> Result<(), glib::error::BoolError> { - unsafe { - glib::result_from_gboolean!( - ffi::gst_element_link_pads_full( - self.as_ref().to_glib_none().0, - srcpadname.to_glib_none().0, - dest.as_ref().to_glib_none().0, - destpadname.to_glib_none().0, - flags.into_glib() - ), - "Failed to link pads" - ) - } - } - fn lost_state(&self) { unsafe { ffi::gst_element_lost_state(self.as_ref().to_glib_none().0); diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index 2f439732e..62a8a5a7f 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -39,7 +39,9 @@ impl Element { e[0].as_ref().to_glib_none().0, e[1].as_ref().to_glib_none().0, ), - "Failed to link elements" + "Failed to link elements '{}' and '{}'", + e[0].as_ref().name(), + e[1].as_ref().name(), )?; } } @@ -268,6 +270,42 @@ pub trait ElementExtManual: 'static { #[doc(alias = "get_request_pad")] #[doc(alias = "gst_element_request_pad_simple")] fn request_pad_simple(&self, name: &str) -> Option; + + #[doc(alias = "gst_element_link")] + fn link(&self, dest: &impl IsA) -> Result<(), glib::error::BoolError>; + + #[doc(alias = "gst_element_link_filtered")] + fn link_filtered( + &self, + dest: &impl IsA, + filter: &crate::Caps, + ) -> Result<(), glib::error::BoolError>; + + #[doc(alias = "gst_element_link_pads")] + fn link_pads( + &self, + srcpadname: Option<&str>, + dest: &impl IsA, + destpadname: Option<&str>, + ) -> Result<(), glib::error::BoolError>; + + #[doc(alias = "gst_element_link_pads_filtered")] + fn link_pads_filtered( + &self, + srcpadname: Option<&str>, + dest: &impl IsA, + destpadname: Option<&str>, + filter: &crate::Caps, + ) -> Result<(), glib::error::BoolError>; + + #[doc(alias = "gst_element_link_pads_full")] + fn link_pads_full( + &self, + srcpadname: Option<&str>, + dest: &impl IsA, + destpadname: Option<&str>, + flags: crate::PadLinkCheck, + ) -> Result<(), glib::error::BoolError>; } impl> ElementExtManual for O { @@ -793,6 +831,133 @@ impl> ElementExtManual for O { } } } + + fn link(&self, dest: &impl IsA) -> Result<(), glib::error::BoolError> { + unsafe { + glib::result_from_gboolean!( + ffi::gst_element_link( + self.as_ref().to_glib_none().0, + dest.as_ref().to_glib_none().0 + ), + "Failed to link elements '{}' and '{}'", + self.as_ref().name(), + dest.as_ref().name(), + ) + } + } + + fn link_filtered( + &self, + dest: &impl IsA, + filter: &crate::Caps, + ) -> Result<(), glib::error::BoolError> { + unsafe { + glib::result_from_gboolean!( + ffi::gst_element_link_filtered( + self.as_ref().to_glib_none().0, + dest.as_ref().to_glib_none().0, + filter.to_glib_none().0 + ), + "Failed to link elements '{}' and '{}' with filter '{:?}'", + self.as_ref().name(), + dest.as_ref().name(), + filter, + ) + } + } + + fn link_pads( + &self, + srcpadname: Option<&str>, + dest: &impl IsA, + destpadname: Option<&str>, + ) -> Result<(), glib::error::BoolError> { + unsafe { + glib::result_from_gboolean!( + ffi::gst_element_link_pads( + self.as_ref().to_glib_none().0, + srcpadname.to_glib_none().0, + dest.as_ref().to_glib_none().0, + destpadname.to_glib_none().0 + ), + "Failed to link pads '{}' and '{}'", + if let Some(srcpadname) = srcpadname { + format!("{}:{}", self.as_ref().name(), srcpadname) + } else { + format!("{}:*", self.as_ref().name()) + }, + if let Some(destpadname) = destpadname { + format!("{}:{}", dest.as_ref().name(), destpadname) + } else { + format!("{}:*", dest.as_ref().name()) + }, + ) + } + } + + fn link_pads_filtered( + &self, + srcpadname: Option<&str>, + dest: &impl IsA, + destpadname: Option<&str>, + filter: &crate::Caps, + ) -> Result<(), glib::error::BoolError> { + unsafe { + glib::result_from_gboolean!( + ffi::gst_element_link_pads_filtered( + self.as_ref().to_glib_none().0, + srcpadname.to_glib_none().0, + dest.as_ref().to_glib_none().0, + destpadname.to_glib_none().0, + filter.to_glib_none().0 + ), + "Failed to link pads '{}' and '{}' with filter '{:?}'", + if let Some(srcpadname) = srcpadname { + format!("{}:{}", self.as_ref().name(), srcpadname) + } else { + format!("{}:*", self.as_ref().name()) + }, + if let Some(destpadname) = destpadname { + format!("{}:{}", dest.as_ref().name(), destpadname) + } else { + format!("{}:*", dest.as_ref().name()) + }, + filter, + ) + } + } + + fn link_pads_full( + &self, + srcpadname: Option<&str>, + dest: &impl IsA, + destpadname: Option<&str>, + flags: crate::PadLinkCheck, + ) -> Result<(), glib::error::BoolError> { + unsafe { + glib::result_from_gboolean!( + ffi::gst_element_link_pads_full( + self.as_ref().to_glib_none().0, + srcpadname.to_glib_none().0, + dest.as_ref().to_glib_none().0, + destpadname.to_glib_none().0, + flags.into_glib() + ), + "Failed to link pads '{}' and '{}' with flags '{:?}'", + if let Some(srcpadname) = srcpadname { + format!("{}:{}", self.as_ref().name(), srcpadname) + } else { + format!("{}:*", self.as_ref().name()) + }, + if let Some(destpadname) = destpadname { + format!("{}:{}", dest.as_ref().name(), destpadname) + } else { + format!("{}:*", dest.as_ref().name()) + }, + flags, + ) + } + } } pub unsafe trait ElementClassExt {