Merge pull request #220 from jb-alvarado/master

add ignore, use ProcessUnit for error logging, simplify code
This commit is contained in:
jb-alvarado 2022-10-25 15:13:54 +02:00 committed by GitHub
commit 613cfd3467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 47 deletions

View File

@ -9,37 +9,27 @@ use crossbeam_channel::Sender;
use simplelog::*; use simplelog::*;
use ffplayout_lib::utils::{ use ffplayout_lib::utils::{
controller::ProcessUnit::*, format_log_line, test_tcp_port, Media, PlayoutConfig, controller::ProcessUnit::*, test_tcp_port, Media, PlayoutConfig, ProcessControl,
ProcessControl,
}; };
use ffplayout_lib::vec_strings; use ffplayout_lib::vec_strings;
pub fn log_line(line: String, level: &str) { pub fn log_line(line: String, level: &str) {
if line.contains("[info]") && level.to_lowercase() == "info" { if line.contains("[info]") && level.to_lowercase() == "info" {
info!( info!("<bright black>[Server]</> {}", line.replace("[info] ", ""))
"<bright black>[Server]</> {}",
format_log_line(line, "info")
)
} else if line.contains("[warning]") } else if line.contains("[warning]")
&& (level.to_lowercase() == "warning" || level.to_lowercase() == "info") && (level.to_lowercase() == "warning" || level.to_lowercase() == "info")
{ {
warn!( warn!(
"<bright black>[Server]</> {}", "<bright black>[Server]</> {}",
format_log_line(line, "warning") line.replace("[warning] ", "")
) )
} else if line.contains("[error]") } else if line.contains("[error]")
&& !line.contains("Input/output error") && !line.contains("Input/output error")
&& !line.contains("Broken pipe") && !line.contains("Broken pipe")
{ {
error!( error!("<bright black>[Server]</> {}", line.replace("[error] ", ""));
"<bright black>[Server]</> {}",
format_log_line(line, "error")
);
} else if line.contains("[fatal]") { } else if line.contains("[fatal]") {
error!( error!("<bright black>[Server]</> {}", line.replace("[fatal] ", ""))
"<bright black>[Server]</> {}",
format_log_line(line, "fatal")
)
} }
} }
@ -56,10 +46,7 @@ fn server_monitor(
error!("{e}"); error!("{e}");
}; };
warn!( warn!("<bright black>[Server]</> {}", line.replace("[error] ", ""));
"<bright black>[Server]</> {}",
format_log_line(line.clone(), "error")
);
} }
if line.contains("Address already in use") { if line.contains("Address already in use") {

View File

@ -202,7 +202,7 @@ pub fn write_hls(
let enc_err = BufReader::new(enc_proc.stderr.take().unwrap()); let enc_err = BufReader::new(enc_proc.stderr.take().unwrap());
*proc_control.encoder_term.lock().unwrap() = Some(enc_proc); *proc_control.encoder_term.lock().unwrap() = Some(enc_proc);
if let Err(e) = stderr_reader(enc_err, "Writer", proc_control.clone()) { if let Err(e) = stderr_reader(enc_err, Encoder, proc_control.clone()) {
error!("{e:?}") error!("{e:?}")
}; };

View File

@ -18,8 +18,8 @@ pub use hls::write_hls;
use crate::input::{ingest_server, source_generator}; use crate::input::{ingest_server, source_generator};
use ffplayout_lib::utils::{ use ffplayout_lib::utils::{
sec_to_time, stderr_reader, Decoder, OutputMode::*, PlayerControl, PlayoutConfig, sec_to_time, stderr_reader, OutputMode::*, PlayerControl, PlayoutConfig, PlayoutStatus,
PlayoutStatus, ProcessControl, ProcessControl, ProcessUnit::*,
}; };
use ffplayout_lib::vec_strings; use ffplayout_lib::vec_strings;
@ -68,7 +68,7 @@ pub fn player(
let enc_p_ctl = proc_control.clone(); let enc_p_ctl = proc_control.clone();
// spawn a thread to log ffmpeg output error messages // spawn a thread to log ffmpeg output error messages
let error_encoder_thread = thread::spawn(move || stderr_reader(enc_err, "Encoder", enc_p_ctl)); let error_encoder_thread = thread::spawn(move || stderr_reader(enc_err, Encoder, enc_p_ctl));
let proc_control_c = proc_control.clone(); let proc_control_c = proc_control.clone();
let mut ingest_receiver = None; let mut ingest_receiver = None;
@ -137,7 +137,7 @@ pub fn player(
let dec_p_ctl = proc_control.clone(); let dec_p_ctl = proc_control.clone();
let error_decoder_thread = let error_decoder_thread =
thread::spawn(move || stderr_reader(dec_err, "Decoder", dec_p_ctl)); thread::spawn(move || stderr_reader(dec_err, Decoder, dec_p_ctl));
loop { loop {
// when server is running, read from channel // when server is running, read from channel

View File

@ -19,8 +19,9 @@ pub const IMAGE_FORMAT: [&str; 21] = [
]; ];
// Some well known errors can be safely ignore // Some well known errors can be safely ignore
pub const FFMPEG_IGNORE_ERRORS: [&str; 4] = [ pub const FFMPEG_IGNORE_ERRORS: [&str; 5] = [
"ac-tex damaged", "ac-tex damaged",
"end mismatch left",
"Referenced QT chapter track not found", "Referenced QT chapter track not found",
"skipped MB in I-frame at", "skipped MB in I-frame at",
"Warning MVs not available", "Warning MVs not available",

View File

@ -10,8 +10,8 @@ use std::{
use simplelog::*; use simplelog::*;
use crate::utils::{ use crate::utils::{
format_log_line, loop_image, sec_to_time, seek_and_length, valid_source, vec_strings, loop_image, sec_to_time, seek_and_length, valid_source, vec_strings, JsonPlaylist, Media,
JsonPlaylist, Media, OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT, OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
}; };
/// check if ffmpeg can read the file and apply filter to it. /// check if ffmpeg can read the file and apply filter to it.
@ -82,19 +82,13 @@ fn check_media(
for line in enc_err.lines() { for line in enc_err.lines() {
let line = line?; let line = line?;
if !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i)) { if !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i))
if line.contains("[error]") { && (line.contains("[error]") || line.contains("[fatal]"))
let log_line = format_log_line(line, "error"); {
let log_line = line.replace("[error] ", "").replace("[fatal] ", "");
if !error_list.contains(&log_line) { if !error_list.contains(&log_line) {
error_list.push(log_line); error_list.push(log_line);
}
} else if line.contains("[fatal]") {
let log_line = format_log_line(line, "fatal");
if !error_list.contains(&log_line) {
error_list.push(log_line);
}
} }
} }
} }

View File

@ -630,15 +630,11 @@ pub fn include_file(config: PlayoutConfig, file_path: &Path) -> bool {
include include
} }
pub fn format_log_line(line: String, level: &str) -> String {
line.replace(&format!("[{level: >5}] "), "")
}
/// Read ffmpeg stderr decoder and encoder instance /// Read ffmpeg stderr decoder and encoder instance
/// and log the output. /// and log the output.
pub fn stderr_reader( pub fn stderr_reader(
buffer: BufReader<ChildStderr>, buffer: BufReader<ChildStderr>,
suffix: &str, suffix: ProcessUnit,
mut proc_control: ProcessControl, mut proc_control: ProcessControl,
) -> Result<(), Error> { ) -> Result<(), Error> {
for line in buffer.lines() { for line in buffer.lines() {
@ -647,19 +643,19 @@ pub fn stderr_reader(
if line.contains("[info]") { if line.contains("[info]") {
info!( info!(
"<bright black>[{suffix}]</> {}", "<bright black>[{suffix}]</> {}",
format_log_line(line, "info") line.replace("[info] ", "")
) )
} else if line.contains("[warning]") { } else if line.contains("[warning]") {
warn!( warn!(
"<bright black>[{suffix}]</> {}", "<bright black>[{suffix}]</> {}",
format_log_line(line, "warning") line.replace("[warning] ", "")
) )
} else if (line.contains("[error]") || line.contains("[fatal]")) } else if (line.contains("[error]") || line.contains("[fatal]"))
&& !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i)) && !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i))
{ {
error!( error!(
"<bright black>[{suffix}]</> {}", "<bright black>[{suffix}]</> {}",
line.replace("[error]", "").replace("[fatal]", "") line.replace("[error] ", "").replace("[fatal] ", "")
); );
if line.contains("Invalid argument") if line.contains("Invalid argument")