integrate option infinit for playlist

This commit is contained in:
jb-alvarado 2022-06-26 23:23:14 +02:00
parent a28abb3b4c
commit c90fc62a38
5 changed files with 68 additions and 6 deletions

2
Cargo.lock generated
View File

@ -1055,7 +1055,7 @@ dependencies = [
[[package]] [[package]]
name = "ffplayout-lib" name = "ffplayout-lib"
version = "0.10.0" version = "0.10.1"
dependencies = [ dependencies = [
"chrono 0.4.19 (git+https://github.com/chronotope/chrono.git)", "chrono 0.4.19 (git+https://github.com/chronotope/chrono.git)",
"crossbeam-channel 0.5.5", "crossbeam-channel 0.5.5",

View File

@ -348,7 +348,8 @@ impl Iterator for CurrentProgram {
let (_, total_delta) = let (_, total_delta) =
get_delta(&self.config, &self.config.playlist.start_sec.unwrap()); get_delta(&self.config, &self.config.playlist.start_sec.unwrap());
if last_playlist == self.json_path if !self.config.playlist.infinit
&& last_playlist == self.json_path
&& total_delta.abs() > self.config.general.stop_threshold && total_delta.abs() > self.config.general.stop_threshold
{ {
// Test if playlist is to early finish, // Test if playlist is to early finish,

View File

@ -4,7 +4,7 @@ description = "Library for ffplayout"
license = "GPL-3.0" license = "GPL-3.0"
authors = ["Jonathan Baecker jonbae77@gmail.com"] authors = ["Jonathan Baecker jonbae77@gmail.com"]
readme = "README.md" readme = "README.md"
version = "0.10.0" version = "0.10.1"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -17,6 +17,7 @@ pub const DUMMY_LEN: f64 = 60.0;
/// This is our main playlist object, it holds all necessary information for the current day. /// This is our main playlist object, it holds all necessary information for the current day.
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct JsonPlaylist { pub struct JsonPlaylist {
#[serde(default = "default_channel")]
pub channel: String, pub channel: String,
pub date: String, pub date: String,
@ -57,6 +58,10 @@ impl PartialEq for JsonPlaylist {
impl Eq for JsonPlaylist {} impl Eq for JsonPlaylist {}
fn default_channel() -> String {
"Channel 1".to_string()
}
fn set_defaults( fn set_defaults(
mut playlist: JsonPlaylist, mut playlist: JsonPlaylist,
current_file: String, current_file: String,
@ -80,6 +85,54 @@ fn set_defaults(
playlist playlist
} }
fn loop_playlist(
config: &PlayoutConfig,
current_file: String,
mut playlist: JsonPlaylist,
) -> JsonPlaylist {
let start_sec = config.playlist.start_sec.unwrap();
let mut begin = start_sec;
let length = config.playlist.length_sec.unwrap();
let mut program_list = vec![];
let mut index = 0;
playlist.current_file = Some(current_file);
playlist.start_sec = Some(start_sec);
'program_looper: loop {
for item in playlist.program.iter() {
let media = Media {
index: Some(index),
begin: Some(begin),
seek: item.seek,
out: item.out,
duration: item.duration,
category: item.category.clone(),
source: item.source.clone(),
cmd: item.cmd.clone(),
probe: item.probe.clone(),
process: Some(true),
last_ad: Some(false),
next_ad: Some(false),
filter: Some(vec![]),
};
if begin < start_sec + length {
program_list.push(media);
} else {
break 'program_looper;
}
begin += item.out - item.seek;
index += 1;
}
}
playlist.program = program_list;
playlist
}
/// Read json playlist file, fills JsonPlaylist struct and set some extra values, /// Read json playlist file, fills JsonPlaylist struct and set some extra values,
/// which we need to process. /// which we need to process.
pub fn read_json( pub fn read_json(
@ -131,7 +184,11 @@ pub fn read_json(
validate_playlist(list_clone, is_terminated, config_clone) validate_playlist(list_clone, is_terminated, config_clone)
}); });
return set_defaults(playlist, current_file, start_sec); if config.playlist.infinit {
return loop_playlist(config, current_file, playlist);
} else {
return set_defaults(playlist, current_file, start_sec);
}
} }
} }
} }
@ -149,7 +206,11 @@ pub fn read_json(
thread::spawn(move || validate_playlist(list_clone, is_terminated, config_clone)); thread::spawn(move || validate_playlist(list_clone, is_terminated, config_clone));
return set_defaults(playlist, current_file, start_sec); if config.playlist.infinit {
return loop_playlist(config, current_file, playlist);
} else {
return set_defaults(playlist, current_file, start_sec);
}
} }
error!("Playlist <b><magenta>{current_file}</></b> not exist!"); error!("Playlist <b><magenta>{current_file}</></b> not exist!");

View File

@ -53,7 +53,7 @@ pub fn validate_playlist(
begin += item.out - item.seek; begin += item.out - item.seek;
} }
if length > begin + 1.0 { if !config.playlist.infinit && length > begin + 1.0 {
error!( error!(
"Playlist from <yellow>{date}</> not long enough, <yellow>{}</> needed!", "Playlist from <yellow>{date}</> not long enough, <yellow>{}</> needed!",
sec_to_time(length - begin), sec_to_time(length - begin),