From c7529d3d5bd2ef153bf4d1c18c3462afeb8d6456 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 14 Jun 2024 12:47:08 +0200 Subject: [PATCH] fix deadlock, on playlist generation, fix playlist init --- ffplayout/src/main.rs | 2 +- ffplayout/src/player/controller.rs | 1 + ffplayout/src/player/input/playlist.rs | 12 ++++-- ffplayout/src/player/utils/folder.rs | 5 +++ ffplayout/src/utils/args_parse.rs | 2 +- ffplayout/src/utils/config.rs | 8 +++- ffplayout/src/utils/generator.rs | 2 +- ffplayout/src/utils/logging.rs | 55 +++++++++++++++++++------- 8 files changed, 66 insertions(+), 21 deletions(-) diff --git a/ffplayout/src/main.rs b/ffplayout/src/main.rs index d55f028d..5da867eb 100644 --- a/ffplayout/src/main.rs +++ b/ffplayout/src/main.rs @@ -255,7 +255,7 @@ async fn main() -> std::io::Result<()> { Ok(()) } else { - error!("Run ffplayout with listen parameter!"); + error!("Run ffplayout with parameters! Run ffplayout -h for more information."); Ok(()) } diff --git a/ffplayout/src/player/controller.rs b/ffplayout/src/player/controller.rs index 877b5663..ce3c77e7 100644 --- a/ffplayout/src/player/controller.rs +++ b/ffplayout/src/player/controller.rs @@ -76,6 +76,7 @@ impl ChannelManager { is_alive: Arc::new(AtomicBool::new(false)), channel: Arc::new(Mutex::new(channel)), config: Arc::new(Mutex::new(config)), + list_init: Arc::new(AtomicBool::new(true)), current_media: Arc::new(Mutex::new(None)), current_list: Arc::new(Mutex::new(vec![Media::new(0, "", false)])), filler_list: Arc::new(Mutex::new(vec![])), diff --git a/ffplayout/src/player/input/playlist.rs b/ffplayout/src/player/input/playlist.rs index 05a5af88..56545120 100644 --- a/ffplayout/src/player/input/playlist.rs +++ b/ffplayout/src/player/input/playlist.rs @@ -150,7 +150,7 @@ impl CurrentProgram { } trace!( - "delta: {delta} | total_delta: {total_delta}, index: {node_index} \nnext_start: {next_start} | end_sec: {} | source {}", + "delta: {delta} | total_delta: {total_delta}, index: {node_index} \n next_start: {next_start} | end_sec: {} | source {}", self.end_sec, self.current_node.source ); @@ -501,8 +501,14 @@ fn timed_source( let mut new_node = node.clone(); new_node.process = Some(false); - trace!("Node begin: {}", node.begin.unwrap()); - trace!("timed source is last: {last}"); + trace!( + "Node - begin: {} | source: {}", + node.begin.unwrap(), + node.source + ); + trace!( + "timed source is last: {last} | current_date: {current_date} | last_date: {last_date:?} | time_shift: {time_shift}" + ); if config.playlist.length.contains(':') { if Some(current_date) == last_date && time_shift != 0.0 { diff --git a/ffplayout/src/player/utils/folder.rs b/ffplayout/src/player/utils/folder.rs index 1b4085de..ed5aa94a 100644 --- a/ffplayout/src/player/utils/folder.rs +++ b/ffplayout/src/player/utils/folder.rs @@ -28,6 +28,11 @@ impl FolderSource { let mut media_list = vec![]; let mut index: usize = 0; + debug!( + "generate: {:?}, paths: {:?}", + config.general.generate, config.storage.paths + ); + if config.general.generate.is_some() && !config.storage.paths.is_empty() { for path in &config.storage.paths { path_list.push(path) diff --git a/ffplayout/src/utils/args_parse.rs b/ffplayout/src/utils/args_parse.rs index 3b45ae27..6f69eacd 100644 --- a/ffplayout/src/utils/args_parse.rs +++ b/ffplayout/src/utils/args_parse.rs @@ -17,7 +17,7 @@ use crate::ARGS; #[derive(Parser, Debug, Clone)] #[clap(version, - about = "REST API for ffplayout", + about = "ffplayout - 24/7 broadcasting solution", long_about = None)] pub struct Args { #[clap( diff --git a/ffplayout/src/utils/config.rs b/ffplayout/src/utils/config.rs index 0c25bb16..3dcd8a41 100644 --- a/ffplayout/src/utils/config.rs +++ b/ffplayout/src/utils/config.rs @@ -176,6 +176,7 @@ pub struct Global { pub playlist_path: PathBuf, pub storage_path: PathBuf, pub logging_path: PathBuf, + pub shared_storage: bool, } impl Global { @@ -185,6 +186,7 @@ impl Global { playlist_path: PathBuf::from(config.playlist_path.clone()), storage_path: PathBuf::from(config.storage_path.clone()), logging_path: PathBuf::from(config.logging_path.clone()), + shared_storage: config.shared_storage, } } } @@ -551,7 +553,7 @@ impl PlayoutConfig { .await .expect("Can't read advanced config"); - let global = Global::new(&global); + let mut global = Global::new(&global); let advanced = AdvancedConfig::new(adv_config); let general = General::new(&config); let mail = Mail::new(&config); @@ -564,6 +566,10 @@ impl PlayoutConfig { let task = Task::new(&config); let mut output = Output::new(&config); + if !global.shared_storage { + global.storage_path = global.storage_path.join(channel.to_string()); + } + let (filler_path, _, _) = norm_abs_path(&global.storage_path, &config.storage_filler) .expect("Can't get filler path"); diff --git a/ffplayout/src/utils/generator.rs b/ffplayout/src/utils/generator.rs index a6c13cd9..2c7ebf4d 100644 --- a/ffplayout/src/utils/generator.rs +++ b/ffplayout/src/utils/generator.rs @@ -200,7 +200,7 @@ pub fn generate_from_template( /// Generate playlists pub fn playlist_generator(manager: &ChannelManager) -> Result, Error> { - let config = manager.config.lock().unwrap(); + let config = manager.config.lock().unwrap().clone(); let channel_name = manager.channel.lock().unwrap().name.clone(); let total_length = match config.playlist.length_sec { diff --git a/ffplayout/src/utils/logging.rs b/ffplayout/src/utils/logging.rs index 0efd2be7..6820ba17 100644 --- a/ffplayout/src/utils/logging.rs +++ b/ffplayout/src/utils/logging.rs @@ -233,19 +233,38 @@ impl MailQueue { } fn console_formatter(w: &mut dyn Write, _now: &mut DeferredNow, record: &Record) -> io::Result<()> { - let level = match record.level() { - Level::Debug => "[DEBUG]", - Level::Error => "[ERROR]", - Level::Info => "[ INFO]", - Level::Trace => "[TRACE]", - Level::Warn => "[ WARN]", - }; - - write!( - w, - "{}", - colorize_string(format!("{level} {}", record.args())) - ) + match record.level() { + Level::Debug => write!( + w, + "{}", + colorize_string(format!("[DEBUG] {}", record.args())) + ), + Level::Error => write!( + w, + "{}", + colorize_string(format!("[ERROR] {}", record.args())) + ), + Level::Info => write!( + w, + "{}", + colorize_string(format!("[ INFO] {}", record.args())) + ), + Level::Trace => write!( + w, + "{}", + colorize_string(format!( + "[TRACE] {}{} {}", + record.file().unwrap_or_default(), + record.line().unwrap_or_default(), + record.args() + )) + ), + Level::Warn => write!( + w, + "{}", + colorize_string(format!("[ WARN] {}", record.args())) + ), + } } fn file_formatter( @@ -411,14 +430,22 @@ pub fn init_logging(mail_queues: Arc>>>>) -> io:: let mut builder = LogSpecification::builder(); builder .default(log_level) + .module("actix", LevelFilter::Error) .module("actix_files", LevelFilter::Error) + .module("actix_web", LevelFilter::Error) + .module("actix_web_service", LevelFilter::Error) .module("hyper", LevelFilter::Error) + .module("flexi_logger", LevelFilter::Error) .module("libc", LevelFilter::Error) + .module("log", LevelFilter::Error) + .module("mio", LevelFilter::Error) .module("neli", LevelFilter::Error) .module("reqwest", LevelFilter::Error) + .module("rpc", LevelFilter::Error) .module("rustls", LevelFilter::Error) .module("serial_test", LevelFilter::Error) - .module("sqlx", LevelFilter::Error); + .module("sqlx", LevelFilter::Error) + .module("tokio", LevelFilter::Error); Logger::with(builder.build()) .format(console_formatter)