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

View File

@ -18,8 +18,8 @@ pub use hls::write_hls;
use crate::input::{ingest_server, source_generator};
use ffplayout_lib::utils::{
sec_to_time, stderr_reader, Decoder, OutputMode::*, PlayerControl, PlayoutConfig,
PlayoutStatus, ProcessControl,
sec_to_time, stderr_reader, OutputMode::*, PlayerControl, PlayoutConfig, PlayoutStatus,
ProcessControl, ProcessUnit::*,
};
use ffplayout_lib::vec_strings;
@ -68,7 +68,7 @@ pub fn player(
let enc_p_ctl = proc_control.clone();
// 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 mut ingest_receiver = None;
@ -137,7 +137,7 @@ pub fn player(
let dec_p_ctl = proc_control.clone();
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 {
// 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
pub const FFMPEG_IGNORE_ERRORS: [&str; 4] = [
pub const FFMPEG_IGNORE_ERRORS: [&str; 5] = [
"ac-tex damaged",
"end mismatch left",
"Referenced QT chapter track not found",
"skipped MB in I-frame at",
"Warning MVs not available",

View File

@ -10,8 +10,8 @@ use std::{
use simplelog::*;
use crate::utils::{
format_log_line, loop_image, sec_to_time, seek_and_length, valid_source, vec_strings,
JsonPlaylist, Media, OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
loop_image, sec_to_time, seek_and_length, valid_source, vec_strings, JsonPlaylist, Media,
OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
};
/// 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() {
let line = line?;
if !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i)) {
if line.contains("[error]") {
let log_line = format_log_line(line, "error");
if !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i))
&& (line.contains("[error]") || line.contains("[fatal]"))
{
let log_line = line.replace("[error] ", "").replace("[fatal] ", "");
if !error_list.contains(&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);
}
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
}
pub fn format_log_line(line: String, level: &str) -> String {
line.replace(&format!("[{level: >5}] "), "")
}
/// Read ffmpeg stderr decoder and encoder instance
/// and log the output.
pub fn stderr_reader(
buffer: BufReader<ChildStderr>,
suffix: &str,
suffix: ProcessUnit,
mut proc_control: ProcessControl,
) -> Result<(), Error> {
for line in buffer.lines() {
@ -647,19 +643,19 @@ pub fn stderr_reader(
if line.contains("[info]") {
info!(
"<bright black>[{suffix}]</> {}",
format_log_line(line, "info")
line.replace("[info] ", "")
)
} else if line.contains("[warning]") {
warn!(
"<bright black>[{suffix}]</> {}",
format_log_line(line, "warning")
line.replace("[warning] ", "")
)
} else if (line.contains("[error]") || line.contains("[fatal]"))
&& !FFMPEG_IGNORE_ERRORS.iter().any(|i| line.contains(*i))
{
error!(
"<bright black>[{suffix}]</> {}",
line.replace("[error]", "").replace("[fatal]", "")
line.replace("[error] ", "").replace("[fatal] ", "")
);
if line.contains("Invalid argument")