simplify recalculate_begin

This commit is contained in:
jb-alvarado 2024-03-23 23:10:14 +01:00
parent 5ed54ed77d
commit 1284d03571

View File

@ -14,8 +14,8 @@ use ffplayout_lib::utils::{
controller::PlayerControl, controller::PlayerControl,
gen_dummy, get_delta, is_close, is_remote, gen_dummy, get_delta, is_close, is_remote,
json_serializer::{read_json, set_defaults}, json_serializer::{read_json, set_defaults},
loop_filler, loop_image, modified_time, sec_to_time, seek_and_length, time_in_seconds, loop_filler, loop_image, modified_time, seek_and_length, time_in_seconds, JsonPlaylist, Media,
JsonPlaylist, Media, MediaProbe, PlayoutConfig, PlayoutStatus, IMAGE_FORMAT, MediaProbe, PlayoutConfig, PlayoutStatus, IMAGE_FORMAT,
}; };
/// Struct for current playlist. /// Struct for current playlist.
@ -229,7 +229,10 @@ impl CurrentProgram {
drop(shift); drop(shift);
if self.config.playlist.infinit && self.json_playlist.length.unwrap() < 86400.0 { if self.config.playlist.infinit
&& self.json_playlist.length.unwrap() < 86400.0
&& time_sec > self.json_playlist.length.unwrap() + self.start_sec
{
self.recalculate_begin(true) self.recalculate_begin(true)
} }
@ -241,14 +244,6 @@ impl CurrentProgram {
.iter() .iter()
.enumerate() .enumerate()
{ {
if i == 0 {
println!(
"first start {}, current time {}",
sec_to_time(item.begin.unwrap()),
sec_to_time(time_sec)
);
}
if item.begin.unwrap() + item.out - item.seek > time_sec { if item.begin.unwrap() + item.out - item.seek > time_sec {
self.playout_stat.list_init.store(false, Ordering::SeqCst); self.playout_stat.list_init.store(false, Ordering::SeqCst);
self.player_control.current_index.store(i, Ordering::SeqCst); self.player_control.current_index.store(i, Ordering::SeqCst);
@ -307,7 +302,6 @@ impl CurrentProgram {
fn fill_end(&mut self, total_delta: f64) { fn fill_end(&mut self, total_delta: f64) {
// Fill end from playlist // Fill end from playlist
let index = self.player_control.current_index.load(Ordering::SeqCst); let index = self.player_control.current_index.load(Ordering::SeqCst);
let mut media = Media::new(index, "", false); let mut media = Media::new(index, "", false);
media.begin = Some(time_in_seconds()); media.begin = Some(time_in_seconds());
@ -344,11 +338,7 @@ impl CurrentProgram {
let mut time_sec = time_in_seconds(); let mut time_sec = time_in_seconds();
if extend { if extend {
// TODO: fix this when playlist length is under 24 hours time_sec = self.start_sec + self.json_playlist.length.unwrap();
let time_elapsed = time_sec - self.start_sec;
let extra_time = time_elapsed % self.json_playlist.length.unwrap();
time_sec = self.start_sec + extra_time + 86400.0;
} }
self.json_playlist.start_sec = Some(time_sec); self.json_playlist.start_sec = Some(time_sec);