add probe in validation thread
This commit is contained in:
parent
c6329c470a
commit
0330ad6168
@ -5,7 +5,6 @@ use std::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use serde_json::json;
|
||||
@ -13,8 +12,8 @@ use simplelog::*;
|
||||
|
||||
use ffplayout_lib::utils::{
|
||||
controller::PlayerControl, gen_dummy, get_delta, get_sec, is_close, is_remote,
|
||||
json_serializer::read_json, loop_filler, loop_image, modified_time, seek_and_length,
|
||||
validate_next, Media, MediaProbe, PlayoutConfig, PlayoutStatus, DUMMY_LEN, IMAGE_FORMAT,
|
||||
json_serializer::read_json, loop_filler, loop_image, modified_time, seek_and_length, Media,
|
||||
MediaProbe, PlayoutConfig, PlayoutStatus, DUMMY_LEN, IMAGE_FORMAT,
|
||||
};
|
||||
|
||||
/// Struct for current playlist.
|
||||
@ -41,7 +40,14 @@ impl CurrentProgram {
|
||||
is_terminated: Arc<AtomicBool>,
|
||||
player_control: &PlayerControl,
|
||||
) -> Self {
|
||||
let json = read_json(config, None, is_terminated.clone(), true, false);
|
||||
let json = read_json(
|
||||
config,
|
||||
player_control,
|
||||
None,
|
||||
is_terminated.clone(),
|
||||
true,
|
||||
false,
|
||||
);
|
||||
|
||||
if let Some(file) = &json.current_file {
|
||||
info!("Read Playlist: <b><magenta>{}</></b>", file);
|
||||
@ -79,7 +85,14 @@ impl CurrentProgram {
|
||||
fn check_update(&mut self, seek: bool) {
|
||||
if self.json_path.is_none() {
|
||||
// If the playlist was missing, we check here to see if it came back.
|
||||
let json = read_json(&self.config, None, self.is_terminated.clone(), seek, false);
|
||||
let json = read_json(
|
||||
&self.config,
|
||||
&self.player_control,
|
||||
None,
|
||||
self.is_terminated.clone(),
|
||||
seek,
|
||||
false,
|
||||
);
|
||||
|
||||
if let Some(file) = &json.current_file {
|
||||
info!("Read Playlist: <b><magenta>{file}</></b>");
|
||||
@ -103,6 +116,7 @@ impl CurrentProgram {
|
||||
|
||||
let json = read_json(
|
||||
&self.config,
|
||||
&self.player_control,
|
||||
self.json_path.clone(),
|
||||
self.is_terminated.clone(),
|
||||
false,
|
||||
@ -167,7 +181,14 @@ impl CurrentProgram {
|
||||
trace!("get next day");
|
||||
next = true;
|
||||
|
||||
let json = read_json(&self.config, None, self.is_terminated.clone(), false, true);
|
||||
let json = read_json(
|
||||
&self.config,
|
||||
&self.player_control,
|
||||
None,
|
||||
self.is_terminated.clone(),
|
||||
false,
|
||||
true,
|
||||
);
|
||||
|
||||
if let Some(file) = &json.current_file {
|
||||
info!("Read next Playlist: <b><magenta>{}</></b>", file);
|
||||
@ -580,13 +601,10 @@ pub fn gen_source(
|
||||
|
||||
trace!("Clip out: {duration}, duration: {}", node.duration);
|
||||
|
||||
let node_begin = node.begin;
|
||||
let player_ctl = player_control.clone();
|
||||
|
||||
thread::spawn(move || validate_next(player_ctl, node_begin));
|
||||
|
||||
if node.probe.is_none() {
|
||||
node.add_probe(true);
|
||||
} else {
|
||||
trace!("Node has a probe...")
|
||||
}
|
||||
|
||||
// separate if condition, because of node.add_probe() in last condition
|
||||
|
@ -159,6 +159,7 @@ fn main() -> Result<(), ProcError> {
|
||||
}
|
||||
|
||||
if args.validate {
|
||||
let play_ctl3 = play_control.clone();
|
||||
let mut playlist_path = config.playlist.path.clone();
|
||||
let start_sec = config.playlist.start_sec.unwrap();
|
||||
let date = get_date(false, start_sec, false);
|
||||
@ -179,7 +180,12 @@ fn main() -> Result<(), ProcError> {
|
||||
|
||||
let playlist: JsonPlaylist = serde_json::from_reader(f)?;
|
||||
|
||||
validate_playlist(playlist, Arc::new(AtomicBool::new(false)), config);
|
||||
validate_playlist(
|
||||
config,
|
||||
play_ctl3,
|
||||
playlist,
|
||||
Arc::new(AtomicBool::new(false)),
|
||||
);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use simplelog::*;
|
||||
|
||||
use crate::utils::{
|
||||
controller::ProcessUnit::*, get_date, is_remote, modified_time, time_from_header,
|
||||
validate_playlist, Media, PlayoutConfig, DUMMY_LEN,
|
||||
validate_playlist, Media, PlayerControl, PlayoutConfig, DUMMY_LEN,
|
||||
};
|
||||
|
||||
/// This is our main playlist object, it holds all necessary information for the current day.
|
||||
@ -141,12 +141,14 @@ fn loop_playlist(
|
||||
/// which we need to process.
|
||||
pub fn read_json(
|
||||
config: &PlayoutConfig,
|
||||
player_control: &PlayerControl,
|
||||
path: Option<String>,
|
||||
is_terminated: Arc<AtomicBool>,
|
||||
seek: bool,
|
||||
get_next: bool,
|
||||
) -> JsonPlaylist {
|
||||
let config_clone = config.clone();
|
||||
let control_clone = player_control.clone();
|
||||
let mut playlist_path = config.playlist.path.clone();
|
||||
let start_sec = config.playlist.start_sec.unwrap();
|
||||
let date = get_date(seek, start_sec, get_next);
|
||||
@ -185,7 +187,7 @@ pub fn read_json(
|
||||
let list_clone = playlist.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
validate_playlist(list_clone, is_terminated, config_clone)
|
||||
validate_playlist(config_clone, control_clone, list_clone, is_terminated)
|
||||
});
|
||||
|
||||
match config.playlist.infinit {
|
||||
@ -218,7 +220,9 @@ pub fn read_json(
|
||||
|
||||
let list_clone = playlist.clone();
|
||||
|
||||
thread::spawn(move || validate_playlist(list_clone, is_terminated, config_clone));
|
||||
thread::spawn(move || {
|
||||
validate_playlist(config_clone, control_clone, list_clone, is_terminated)
|
||||
});
|
||||
|
||||
match config.playlist.infinit {
|
||||
true => return loop_playlist(config, current_file, playlist),
|
||||
|
@ -14,7 +14,7 @@ use simplelog::*;
|
||||
use crate::filter::FilterType::Audio;
|
||||
use crate::utils::{
|
||||
errors::ProcError, loop_image, sec_to_time, seek_and_length, vec_strings, JsonPlaylist, Media,
|
||||
OutputMode::Null, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
|
||||
OutputMode::Null, PlayerControl, PlayoutConfig, FFMPEG_IGNORE_ERRORS, IMAGE_FORMAT,
|
||||
};
|
||||
|
||||
/// Validate a single media file.
|
||||
@ -144,9 +144,10 @@ fn check_media(
|
||||
///
|
||||
/// This function we run in a thread, to don't block the main function.
|
||||
pub fn validate_playlist(
|
||||
mut config: PlayoutConfig,
|
||||
player_control: PlayerControl,
|
||||
mut playlist: JsonPlaylist,
|
||||
is_terminated: Arc<AtomicBool>,
|
||||
mut config: PlayoutConfig,
|
||||
) {
|
||||
let date = playlist.date;
|
||||
|
||||
@ -170,7 +171,11 @@ pub fn validate_playlist(
|
||||
|
||||
let pos = index + 1;
|
||||
|
||||
item.add_probe(false);
|
||||
if item.audio.is_empty() {
|
||||
item.add_probe(false);
|
||||
} else {
|
||||
item.add_probe(true);
|
||||
}
|
||||
|
||||
if item.probe.is_some() {
|
||||
if let Err(e) = check_media(item.clone(), pos, begin, &config) {
|
||||
@ -181,6 +186,16 @@ pub fn validate_playlist(
|
||||
sec_to_time(begin),
|
||||
item.source
|
||||
)
|
||||
} else if let Ok(mut list) = player_control.current_list.lock() {
|
||||
list.iter_mut().for_each(|o| {
|
||||
if o.source == item.source {
|
||||
o.probe = item.probe.clone();
|
||||
}
|
||||
if o.audio == item.audio && item.probe_audio.is_some() {
|
||||
o.probe_audio = item.probe_audio.clone();
|
||||
o.duration_audio = item.duration_audio;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
|
@ -598,18 +598,6 @@ pub fn is_remote(path: &str) -> bool {
|
||||
Regex::new(r"^https?://.*").unwrap().is_match(path)
|
||||
}
|
||||
|
||||
/// Validate next input
|
||||
///
|
||||
/// Check if next input is valid, and probe it.
|
||||
pub fn validate_next(player_control: PlayerControl, node_begin: Option<f64>) {
|
||||
let mut list = player_control.current_list.lock().unwrap();
|
||||
if let Some(index) = list.iter().position(|r| r.begin == node_begin) {
|
||||
if let Some(next_item) = list.get_mut(index + 1) {
|
||||
next_item.add_probe(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if file can include or has to exclude.
|
||||
/// For example when a file is on given HLS output path, it should exclude.
|
||||
/// Or when the file extension is set under storage config it can be include.
|
||||
|
Loading…
x
Reference in New Issue
Block a user