add test
This commit is contained in:
parent
4f58eb0785
commit
9e95fb2bb0
@ -19,20 +19,10 @@ use walkdir::WalkDir;
|
||||
use super::{folder::FolderSource, PlayerControl};
|
||||
use crate::utils::{
|
||||
folder::fill_filler_list, gen_dummy, get_date_range, include_file_extension,
|
||||
json_serializer::JsonPlaylist, time_to_sec, Media, PlayoutConfig, Template,
|
||||
json_serializer::JsonPlaylist, sum_durations, time_to_sec, Media, PlayoutConfig, Template,
|
||||
};
|
||||
|
||||
fn sum_durations(clip_list: &Vec<Media>) -> f64 {
|
||||
let mut list_duration = 0.0;
|
||||
|
||||
for item in clip_list {
|
||||
list_duration += item.out
|
||||
}
|
||||
|
||||
list_duration
|
||||
}
|
||||
|
||||
fn random_list(clip_list: Vec<Media>, total_length: f64) -> Vec<Media> {
|
||||
pub fn random_list(clip_list: Vec<Media>, total_length: f64) -> Vec<Media> {
|
||||
let mut max_attempts = 10000;
|
||||
let mut randomized_clip_list: Vec<Media> = vec![];
|
||||
let mut target_duration = 0.0;
|
||||
@ -65,7 +55,7 @@ fn random_list(clip_list: Vec<Media>, total_length: f64) -> Vec<Media> {
|
||||
randomized_clip_list
|
||||
}
|
||||
|
||||
fn ordered_list(clip_list: Vec<Media>, total_length: f64) -> Vec<Media> {
|
||||
pub fn ordered_list(clip_list: Vec<Media>, total_length: f64) -> Vec<Media> {
|
||||
let mut index = 0;
|
||||
let mut skip_count = 0;
|
||||
let mut ordered_clip_list: Vec<Media> = vec![];
|
||||
@ -96,7 +86,7 @@ fn ordered_list(clip_list: Vec<Media>, total_length: f64) -> Vec<Media> {
|
||||
ordered_clip_list
|
||||
}
|
||||
|
||||
fn filler_list(config: &PlayoutConfig, total_length: f64) -> Vec<Media> {
|
||||
pub fn filler_list(config: &PlayoutConfig, total_length: f64) -> Vec<Media> {
|
||||
let filler_list = fill_filler_list(config, None);
|
||||
let mut index = 0;
|
||||
let mut filler_clip_list: Vec<Media> = vec![];
|
||||
|
@ -24,7 +24,7 @@ use simplelog::*;
|
||||
pub mod config;
|
||||
pub mod controller;
|
||||
pub mod folder;
|
||||
mod generator;
|
||||
pub mod generator;
|
||||
pub mod import;
|
||||
pub mod json_serializer;
|
||||
mod json_validate;
|
||||
@ -148,14 +148,15 @@ impl Media {
|
||||
pub fn add_probe(&mut self) {
|
||||
if self.probe.is_none() {
|
||||
let probe = MediaProbe::new(&self.source);
|
||||
self.probe = Some(probe.clone());
|
||||
|
||||
if let Some(dur) = probe
|
||||
.format
|
||||
.clone()
|
||||
.and_then(|f| f.duration)
|
||||
.map(|d| d.parse().unwrap())
|
||||
.filter(|d| !is_close(*d, self.duration, 0.5))
|
||||
{
|
||||
self.probe = Some(probe);
|
||||
self.duration = dur;
|
||||
|
||||
if self.out == 0.0 {
|
||||
@ -409,6 +410,17 @@ pub fn is_close(a: f64, b: f64, to: f64) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// add duration from all media clips
|
||||
pub fn sum_durations(clip_list: &Vec<Media>) -> f64 {
|
||||
let mut list_duration = 0.0;
|
||||
|
||||
for item in clip_list {
|
||||
list_duration += item.out
|
||||
}
|
||||
|
||||
list_duration
|
||||
}
|
||||
|
||||
/// Get delta between clip start and current time. This value we need to check,
|
||||
/// if we still in sync.
|
||||
///
|
||||
|
@ -41,3 +41,7 @@ path = "src/engine_playlist.rs"
|
||||
[[test]]
|
||||
name = "engine_cmd"
|
||||
path = "src/engine_cmd.rs"
|
||||
|
||||
[[test]]
|
||||
name = "engine_generator"
|
||||
path = "src/engine_generator.rs"
|
||||
|
23
tests/src/engine_generator.rs
Normal file
23
tests/src/engine_generator.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use ffplayout_lib::utils::{generator::ordered_list, sum_durations, Media};
|
||||
|
||||
#[test]
|
||||
fn test_ordered_list() {
|
||||
let clip_list = vec![
|
||||
Media::new(0, "./assets/with_audio.mp4", true), // 30 seconds
|
||||
Media::new(0, "./assets/dual_audio.mp4", true), // 30 seconds
|
||||
Media::new(0, "./assets/av_sync.mp4", true), // 30 seconds
|
||||
Media::new(0, "./assets/ad.mp4", true), // 25 seconds
|
||||
];
|
||||
|
||||
let result = ordered_list(clip_list.clone(), 85.0);
|
||||
|
||||
assert_eq!(result.len(), 3);
|
||||
assert_eq!(result[2].duration, 25.0);
|
||||
assert_eq!(sum_durations(&result), 85.0);
|
||||
|
||||
let result = ordered_list(clip_list, 120.0);
|
||||
|
||||
assert_eq!(result.len(), 4);
|
||||
assert_eq!(result[2].duration, 30.0);
|
||||
assert_eq!(sum_durations(&result), 115.0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user