player: feed the app with gst logs

Get the debug callback to retrieve the gst logs
and display it in the debug tab.
This commit is contained in:
Stéphane Cerveau 2023-11-28 21:20:31 +01:00
parent 9c03de5d00
commit 8c6cda2e92
4 changed files with 49 additions and 4 deletions

View file

@ -61,6 +61,28 @@ impl PlayerWeak {
} }
} }
fn gst_log_handler(
category: gst::DebugCategory,
level: gst::DebugLevel,
file: &glib::GStr,
function: &glib::GStr,
line: u32,
_obj: Option<&gst::LoggedObject>,
message: &gst::DebugMessage,
) {
let log_message = format!(
"{}\t{}\t{}:{}:{}\t{}",
level,
category.name(),
line,
file.as_str(),
function.as_str(),
message.get().unwrap().as_str()
);
GPS_GST_LOG!("{}", log_message);
}
#[derive(Debug)] #[derive(Debug)]
pub struct PlayerInner { pub struct PlayerInner {
app: RefCell<Option<GPSApp>>, app: RefCell<Option<GPSApp>>,
@ -79,7 +101,7 @@ impl Player {
n_video_sink: Cell::new(0), n_video_sink: Cell::new(0),
bus_watch_guard: RefCell::new(None), bus_watch_guard: RefCell::new(None),
})); }));
gst::debug_add_log_function(gst_log_handler);
Ok(pipeline) Ok(pipeline)
} }
@ -105,7 +127,7 @@ impl Player {
} else { } else {
ElementInfo::element_update_rank("gtk4paintablesink", gst::Rank::Marginal); ElementInfo::element_update_rank("gtk4paintablesink", gst::Rank::Marginal);
} }
gst::debug_set_threshold_from_string(settings::Settings::gst_log_level().as_str(), true);
// Create pipeline from the description // Create pipeline from the description
let pipeline = gst::parse_launch(description)?; let pipeline = gst::parse_launch(description)?;
let pipeline = pipeline.downcast::<gst::Pipeline>(); let pipeline = pipeline.downcast::<gst::Pipeline>();
@ -282,7 +304,9 @@ impl Player {
fn on_pipeline_message(&self, msg: &gst::MessageRef) { fn on_pipeline_message(&self, msg: &gst::MessageRef) {
use gst::MessageView; use gst::MessageView;
GPS_MSG!("{:?}", msg.structure()); if let Some(message) = msg.structure() {
GPS_MSG_LOG!("{:?}", message);
}
match msg.view() { match msg.view() {
MessageView::Eos(_) => { MessageView::Eos(_) => {
GPS_INFO!("EOS received"); GPS_INFO!("EOS received");

View file

@ -92,7 +92,7 @@ macro_rules! GPS_DEBUG (
); );
#[macro_export] #[macro_export]
macro_rules! GPS_MSG ( macro_rules! GPS_MSG_LOG (
() => ($crate::print!("\n")); () => ($crate::print!("\n"));
($($arg:tt)*) => ({ ($($arg:tt)*) => ({
logger::pring_msg_logger(logger::LogType::Message, format_args!($($arg)*).to_string()); logger::pring_msg_logger(logger::LogType::Message, format_args!($($arg)*).to_string());

View file

@ -70,6 +70,16 @@ impl Settings {
path path
} }
pub fn gst_log_level() -> String {
let settings = Settings::load_settings();
let binding = "0".to_string();
let level = settings
.preferences
.get("gst_log_level")
.unwrap_or(&binding);
level.clone()
}
pub fn set_recent_pipeline_description(pipeline: &str) { pub fn set_recent_pipeline_description(pipeline: &str) {
let mut settings = Settings::load_settings(); let mut settings = Settings::load_settings();
settings.recent_pipeline = pipeline.to_string(); settings.recent_pipeline = pipeline.to_string();

View file

@ -82,5 +82,16 @@ pub fn display_settings(app: &GPSApp) {
dialog.close(); dialog.close();
}); });
let widget = gtk::Entry::new();
widget.set_text(settings::Settings::gst_log_level().as_str());
widget.connect_changed(glib::clone!(@weak widget => move |c| {
let mut settings = settings::Settings::load_settings();
settings.preferences.insert("gst_log_level".to_string(), c.text().to_string());
settings::Settings::save_settings(&settings);
}));
let widget = widget
.dynamic_cast::<gtk::Widget>()
.expect("Should be a widget");
add_settings_widget(&grid, "GST Log level", &widget, 2);
dialog.show(); dialog.show();
} }