Add tracing

This commit is contained in:
Vladimir Romashchenko 2024-08-06 19:11:57 -04:00
parent 3b24aa6b3c
commit 9b42458774
No known key found for this signature in database
GPG key ID: E5B7EA4A9E1D48F4
3 changed files with 6 additions and 3 deletions

1
Cargo.lock generated
View file

@ -1429,6 +1429,7 @@ dependencies = [
"iced_native", "iced_native",
"iced_wgpu", "iced_wgpu",
"thiserror", "thiserror",
"tracing",
"url", "url",
] ]

View file

@ -23,6 +23,7 @@ gstreamer = "0.22"
gstreamer-app = "0.22" # appsink gstreamer-app = "0.22" # appsink
gstreamer-base = "0.22" # basesrc gstreamer-base = "0.22" # basesrc
glib = "0.19" # gobject traits and error type glib = "0.19" # gobject traits and error type
tracing = "0.1" # structured logging
thiserror = "1" thiserror = "1"
url = "2" # media uri url = "2" # media uri

View file

@ -7,6 +7,7 @@ use iced::{
use iced_wgpu::primitive::pipeline::Renderer as PrimitiveRenderer; use iced_wgpu::primitive::pipeline::Renderer as PrimitiveRenderer;
use std::{marker::PhantomData, sync::atomic::Ordering}; use std::{marker::PhantomData, sync::atomic::Ordering};
use std::{sync::Arc, time::Duration}; use std::{sync::Arc, time::Duration};
use tracing::error;
/// Video player widget which displays the current frame of a [`Video`](crate::Video). /// Video player widget which displays the current frame of a [`Video`](crate::Video).
pub struct VideoPlayer<'a, Message, Theme = iced::Theme, Renderer = iced::Renderer> pub struct VideoPlayer<'a, Message, Theme = iced::Theme, Renderer = iced::Renderer>
@ -121,6 +122,7 @@ where
); );
} }
#[tracing::instrument(skip_all, fields(event = ?event))]
fn on_event( fn on_event(
&mut self, &mut self,
_state: &mut widget::Tree, _state: &mut widget::Tree,
@ -147,10 +149,9 @@ where
for msg in inner.bus.iter() { for msg in inner.bus.iter() {
match msg.view() { match msg.view() {
gst::MessageView::Error(err) => { gst::MessageView::Error(err) => {
error!("bus returned an error: {err}");
if let Some(ref on_error) = self.on_error { if let Some(ref on_error) = self.on_error {
shell.publish(on_error(&err.error())) shell.publish(on_error(&err.error()))
} else {
panic!("{:#?}", err)
}; };
} }
gst::MessageView::Eos(_eos) => { gst::MessageView::Eos(_eos) => {
@ -170,7 +171,7 @@ where
// Don't run eos_pause if restart_stream is true; fixes "pausing" after restarting a stream // Don't run eos_pause if restart_stream is true; fixes "pausing" after restarting a stream
if restart_stream { if restart_stream {
if let Err(err) = inner.restart_stream() { if let Err(err) = inner.restart_stream() {
eprintln!("cannot restart stream (can't seek): {:#?}", err); error!("cannot restart stream (can't seek): {err:#?}")
} }
} else if eos_pause { } else if eos_pause {
inner.is_eos = true; inner.is_eos = true;