gstreamer: Return glib::GString for the error/warning/info message debug string

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1184>
This commit is contained in:
Sebastian Dröge 2023-01-05 17:28:48 +02:00
parent ba1d8c5ce6
commit 277d63601c
15 changed files with 81 additions and 118 deletions

View file

@ -23,10 +23,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn create_pipeline() -> Result<gst::Pipeline, Error> { fn create_pipeline() -> Result<gst::Pipeline, Error> {
@ -135,11 +134,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -20,10 +20,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
const WIDTH: usize = 320; const WIDTH: usize = 320;
@ -151,11 +150,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -44,10 +44,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
#[derive(Clone, Debug, glib::Boxed)] #[derive(Clone, Debug, glib::Boxed)]
@ -234,11 +233,10 @@ fn example_main() -> Result<(), Error> {
_ => Err(ErrorMessage { _ => Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()), .into()),
}?; }?;

View file

@ -28,10 +28,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
#[derive(Clone, Debug, glib::Boxed)] #[derive(Clone, Debug, glib::Boxed)]
@ -251,11 +250,10 @@ fn example_main() -> Result<(), Error> {
_ => Err(ErrorMessage { _ => Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()), .into()),
}?; }?;

View file

@ -20,7 +20,6 @@ use std::{
}; };
use anyhow::Error; use anyhow::Error;
use derive_more::{Display, Error};
use futures::StreamExt; use futures::StreamExt;
use gst::{element_error, prelude::*}; use gst::{element_error, prelude::*};
use memmap2::MmapMut; use memmap2::MmapMut;
@ -29,15 +28,6 @@ use uds::UnixStreamExt;
#[path = "../examples-common.rs"] #[path = "../examples-common.rs"]
mod examples_common; mod examples_common;
#[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage {
src: String,
error: String,
debug: Option<String>,
source: glib::Error,
}
fn create_receiver_pipeline( fn create_receiver_pipeline(
video_info: &gst_video::VideoInfo, video_info: &gst_video::VideoInfo,
receiver: UnixStream, receiver: UnixStream,

View file

@ -24,10 +24,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
struct DrawingContext { struct DrawingContext {
@ -275,11 +274,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -27,10 +27,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
struct DrawingContext { struct DrawingContext {
@ -219,11 +218,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -23,10 +23,9 @@ struct UsageError(#[error(not(source))] String);
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> { fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> {
@ -243,11 +242,10 @@ fn example_main() -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -19,10 +19,9 @@ struct UsageError(#[error(not(source))] String);
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> { fn static_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst::Pad, Error> {
@ -169,11 +168,10 @@ fn example_main() -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -231,10 +231,9 @@ mod fir_filter {
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn create_pipeline() -> Result<gst::Pipeline, Error> { fn create_pipeline() -> Result<gst::Pipeline, Error> {
@ -303,11 +302,10 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -32,10 +32,9 @@ struct MissingElement(#[error(not(source))] String);
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn example_main() -> Result<(), Error> { fn example_main() -> Result<(), Error> {
@ -90,14 +89,12 @@ fn example_main() -> Result<(), Error> {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
return Err(ErrorMessage { return Err(ErrorMessage {
src: err src: msg
.src() .src()
.map(|s| s.path_string()) .map(|s| s.path_string())
.unwrap_or_else(|| "None".into()) .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
.to_string(), error: err.error(),
error: err.error().to_string(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -17,10 +17,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn create_pipeline(uri: String, out_path: std::path::PathBuf) -> Result<gst::Pipeline, Error> { fn create_pipeline(uri: String, out_path: std::path::PathBuf) -> Result<gst::Pipeline, Error> {
@ -202,11 +201,10 @@ fn main_loop(pipeline: gst::Pipeline, position: u64) -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -29,10 +29,9 @@ mod examples_common;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
fn example_main() -> Result<(), Error> { fn example_main() -> Result<(), Error> {
@ -140,11 +139,10 @@ fn example_main() -> Result<(), Error> {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -14,10 +14,9 @@ use gst_gl::prelude::*;
#[derive(Debug, Display, Error)] #[derive(Debug, Display, Error)]
#[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)] #[display(fmt = "Received error from {}: {} (debug: {:?})", src, error, debug)]
struct ErrorMessage { struct ErrorMessage {
src: String, src: glib::GString,
error: String, error: glib::Error,
debug: Option<String>, debug: Option<glib::GString>,
source: glib::Error,
} }
#[rustfmt::skip] #[rustfmt::skip]
@ -587,11 +586,10 @@ impl App {
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
.src() .src()
.map(|s| String::from(s.path_string())) .map(|s| s.path_string())
.unwrap_or_else(|| String::from("None")), .unwrap_or_else(|| glib::GString::from("UNKNOWN")),
error: err.error().to_string(), error: err.error(),
debug: err.debug(), debug: err.debug(),
source: err.error(),
} }
.into()); .into());
} }

View file

@ -339,7 +339,7 @@ impl Error {
#[doc(alias = "get_debug")] #[doc(alias = "get_debug")]
#[doc(alias = "gst_message_parse_error")] #[doc(alias = "gst_message_parse_error")]
pub fn debug(&self) -> Option<String> { pub fn debug(&self) -> Option<glib::GString> {
unsafe { unsafe {
let mut debug = ptr::null_mut(); let mut debug = ptr::null_mut();
@ -409,7 +409,7 @@ impl Warning {
#[doc(alias = "get_debug")] #[doc(alias = "get_debug")]
#[doc(alias = "gst_message_parse_warning")] #[doc(alias = "gst_message_parse_warning")]
pub fn debug(&self) -> Option<String> { pub fn debug(&self) -> Option<glib::GString> {
unsafe { unsafe {
let mut debug = ptr::null_mut(); let mut debug = ptr::null_mut();
@ -479,7 +479,7 @@ impl Info {
#[doc(alias = "get_debug")] #[doc(alias = "get_debug")]
#[doc(alias = "gst_message_parse_info")] #[doc(alias = "gst_message_parse_info")]
pub fn debug(&self) -> Option<String> { pub fn debug(&self) -> Option<glib::GString> {
unsafe { unsafe {
let mut debug = ptr::null_mut(); let mut debug = ptr::null_mut();