From 40fd1c4751f46ae3630965095329a7832548d304 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Thu, 13 Jul 2023 11:25:08 +0200 Subject: [PATCH 1/4] debug log config path --- debian/postinst | 2 +- ffplayout-engine/src/input/playlist.rs | 2 +- ffplayout-engine/src/main.rs | 5 +++++ lib/src/utils/config.rs | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/debian/postinst b/debian/postinst index 7c744de7..df00d9a2 100644 --- a/debian/postinst +++ b/debian/postinst @@ -8,7 +8,7 @@ if [ -f /run/.containerenv ] || [ -f /run/.dockerenv ] || [ -f /.dockerenv ] || fi if [ ! $(id -u $sysUser 2>/dev/null || echo -1) -ge 0 ]; then - adduser --system $sysUser + adduser --system --create-home $sysUser > /dev/null || adduser --system --home "/home/$sysUser" $sysUser fi if [ ! -d "/usr/share/ffplayout/db" ]; then diff --git a/ffplayout-engine/src/input/playlist.rs b/ffplayout-engine/src/input/playlist.rs index 5b90b14d..e296acc1 100644 --- a/ffplayout-engine/src/input/playlist.rs +++ b/ffplayout-engine/src/input/playlist.rs @@ -82,7 +82,7 @@ impl CurrentProgram { let json = read_json(&self.config, None, self.is_terminated.clone(), seek, 0.0); if let Some(file) = &json.current_file { - info!("Read Playlist: {}", file); + info!("Read Playlist: {file}"); } self.json_path = json.current_file; diff --git a/ffplayout-engine/src/main.rs b/ffplayout-engine/src/main.rs index 4548f15f..cfeae085 100644 --- a/ffplayout-engine/src/main.rs +++ b/ffplayout-engine/src/main.rs @@ -200,6 +200,11 @@ fn main() { status_file(&config.general.stat_file, &playout_stat); + debug!( + "Use config: {}", + config.general.config_path + ); + match config.out.mode { // write files/playlist to HLS m3u8 playlist HLS => write_hls(&config, play_control, playout_stat, proc_control), diff --git a/lib/src/utils/config.rs b/lib/src/utils/config.rs index 3b55668e..a2d1bbcb 100644 --- a/lib/src/utils/config.rs +++ b/lib/src/utils/config.rs @@ -146,6 +146,9 @@ pub struct General { pub help_text: String, pub stop_threshold: f64, + #[serde(default, skip_serializing, skip_deserializing)] + pub config_path: String, + #[serde(default)] pub stat_file: String, @@ -342,6 +345,8 @@ impl PlayoutConfig { serde_yaml::from_reader(f).expect("Could not read config file."); config.general.generate = None; + config.general.config_path = config_path.to_string_lossy().to_string(); + config.general.stat_file = home_dir() .unwrap_or_else(env::temp_dir) .join(if config.general.stat_file.is_empty() { From ac90dcb157784a3b98990140f5535622a6689e65 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 14 Jul 2023 13:42:20 +0200 Subject: [PATCH 2/4] check if json rpc port is in use --- Cargo.lock | 116 +++++++++++++++++------------------ debian/postinst | 8 +-- ffplayout-engine/src/main.rs | 9 ++- lib/src/utils/mod.rs | 27 ++++---- 4 files changed, 84 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc2acce2..6dddabb5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -219,7 +219,7 @@ dependencies = [ "serde_urlencoded", "smallvec", "socket2", - "time 0.3.22", + "time 0.3.23", "url", ] @@ -324,9 +324,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "android-tzdata" @@ -433,9 +433,9 @@ dependencies = [ [[package]] name = "async-channel" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf46fee83e5ccffc220104713af3292ff9bc7c64c7de289f66dae8e38d826833" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" dependencies = [ "concurrent-queue", "event-listener", @@ -541,7 +541,7 @@ checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -775,7 +775,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -801,9 +801,9 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6340df57935414636969091153f35f68d9f00bbc8fb4a9c6054706c213e6c6bc" +checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" [[package]] name = "convert_case" @@ -818,7 +818,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" dependencies = [ "percent-encoding", - "time 0.3.22", + "time 0.3.23", "version_check", ] @@ -912,12 +912,12 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.4.0" +version = "5.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc" +checksum = "6943ae99c34386c84a470c499d3414f66502a41340aa895406e0d2e4a207b91d" dependencies = [ "cfg-if", - "hashbrown 0.12.3", + "hashbrown 0.14.0", "lock_api", "once_cell", "parking_lot_core", @@ -1001,9 +1001,9 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" @@ -1136,7 +1136,7 @@ dependencies = [ "serde_yaml", "shlex", "simplelog", - "time 0.3.22", + "time 0.3.23", "walkdir", "winapi", ] @@ -1325,7 +1325,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -1688,12 +1688,12 @@ checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "is-terminal" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", - "rustix 0.38.3", + "rustix 0.38.4", "windows-sys 0.48.0", ] @@ -2130,7 +2130,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -2254,7 +2254,7 @@ checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -2320,9 +2320,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -2392,9 +2392,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89089e897c013b3deb627116ae56a6955a72b8bed395c9526af31c9fe528b484" +checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575" dependencies = [ "aho-corasick", "memchr", @@ -2404,9 +2404,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa250384981ea14565685dea16a9ccc4d1c541a13f82b9c168572264d1df8c56" +checksum = "39354c10dd07468c2e73926b23bb9c2caca74c5501e38a35da70406f1d923310" dependencies = [ "aho-corasick", "memchr", @@ -2415,9 +2415,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab07dc67230e4a4718e70fd5c20055a4334b121f1f9db8fe63ef39ce9b8c846" +checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" [[package]] name = "relative-path" @@ -2542,9 +2542,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.3" +version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac5ffa1efe7548069688cd7028f32591853cd7b5b756d41bcffd2353e4fc75b4" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" dependencies = [ "bitflags 2.3.3", "errno", @@ -2624,29 +2624,29 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.166" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01b7404f9d441d3ad40e6a636a7782c377d2abdbe4fa2440e2edcc2f4f10db8" +checksum = "30e27d1e4fd7659406c492fd6cfaf2066ba8773de45ca75e855590f856dc34a9" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.166" +version = "1.0.171" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd83d6dde2b6b2d466e14d9d1acce8816dedee94f735eac6395808b3483c6d6" +checksum = "389894603bd18c46fa56231694f8d827779c0951a667087194cf9de94ed24682" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] name = "serde_json" -version = "1.0.100" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" +checksum = "b5062a995d481b2308b6064e9af76011f2921c35f97b0468811ed9f6cd91dfed" dependencies = [ "itoa", "ryu", @@ -2700,7 +2700,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -2759,7 +2759,7 @@ dependencies = [ "num-bigint", "num-traits", "thiserror", - "time 0.3.22", + "time 0.3.23", ] [[package]] @@ -2771,7 +2771,7 @@ dependencies = [ "log", "paris", "termcolor", - "time 0.3.22", + "time 0.3.23", ] [[package]] @@ -3064,9 +3064,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.23" +version = "2.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "15e3fc8c0c74267e2df136e5e5fb656a464158aa57624053375eb9c8c6e25ae2" dependencies = [ "proc-macro2", "quote", @@ -3117,28 +3117,28 @@ dependencies = [ "serial_test", "shlex", "simplelog", - "time 0.3.22", + "time 0.3.23", "walkdir", ] [[package]] name = "thiserror" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c16a64ba9387ef3fdae4f9c1a7f07a0997fce91985c0336f1ddc1822b3b37802" +checksum = "a35fc5b8971143ca348fa6df4f024d4d55264f3468c71ad1c2f365b0a4d58c42" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.41" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59" +checksum = "463fe12d7993d3b327787537ce8dd4dfa058de32fc2b195ef3cde03dc4771e8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -3154,9 +3154,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd" +checksum = "59e399c068f43a5d116fedaf73b203fa4f9c519f17e2b34f63221d3792f81446" dependencies = [ "itoa", "libc", @@ -3174,9 +3174,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "96ba15a897f3c86766b757e5ac7221554c6750054d74d5b28844fce5fb36a6c4" dependencies = [ "time-core", ] @@ -3236,7 +3236,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -3301,7 +3301,7 @@ checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", ] [[package]] @@ -3481,7 +3481,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", "wasm-bindgen-shared", ] @@ -3515,7 +3515,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.23", + "syn 2.0.25", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/debian/postinst b/debian/postinst index df00d9a2..78617737 100644 --- a/debian/postinst +++ b/debian/postinst @@ -20,9 +20,9 @@ if [ ! -d "/usr/share/ffplayout/db" ]; then /usr/bin/ffpapi -i -d "${IP}:8787" - chown -R ${sysUser}. "/usr/share/ffplayout" - chown -R ${sysUser}. "/var/lib/ffplayout" - chown -R ${sysUser}. "/etc/ffplayout" + chown -R ${sysUser}: "/usr/share/ffplayout" + chown -R ${sysUser}: "/var/lib/ffplayout" + chown -R ${sysUser}: "/etc/ffplayout" ln -s "/var/lib/ffplayout/tv-media" "/usr/share/ffplayout/public/" fi @@ -30,5 +30,5 @@ fi if [ ! -d "/var/log/ffplayout" ]; then mkdir "/var/log/ffplayout" - chown ${sysUser}. "/var/log/ffplayout" + chown ${sysUser}: "/var/log/ffplayout" fi diff --git a/ffplayout-engine/src/main.rs b/ffplayout-engine/src/main.rs index cfeae085..5060c0ed 100644 --- a/ffplayout-engine/src/main.rs +++ b/ffplayout-engine/src/main.rs @@ -20,8 +20,8 @@ use ffplayout::{ use ffplayout_lib::utils::{ generate_playlist, get_date, import::import_file, init_logging, is_remote, send_mail, - validate_ffmpeg, validate_playlist, JsonPlaylist, OutputMode::*, PlayerControl, PlayoutStatus, - ProcessControl, + test_tcp_port, validate_ffmpeg, validate_playlist, JsonPlaylist, OutputMode::*, PlayerControl, + PlayoutStatus, ProcessControl, }; #[cfg(debug_assertions)] @@ -195,6 +195,11 @@ fn main() { if config.rpc_server.enable { // If RPC server is enable we also fire up a JSON RPC server. + + if !test_tcp_port(&config.rpc_server.address) { + exit(1) + } + thread::spawn(move || run_server(config_clone, play_ctl, play_stat, proc_ctl2)); } diff --git a/lib/src/utils/mod.rs b/lib/src/utils/mod.rs index bae97d55..7d34c284 100644 --- a/lib/src/utils/mod.rs +++ b/lib/src/utils/mod.rs @@ -825,21 +825,24 @@ pub fn free_tcp_socket(exclude_socket: String) -> Option { /// check if tcp port is free pub fn test_tcp_port(url: &str) -> bool { - let raw_addr = url.split('/').collect::>(); + let re = Regex::new(r"^[\w]+\://").unwrap(); + let mut addr = url.to_string(); - if raw_addr.len() > 1 { - if let Some(socket) = raw_addr[2].split_once(':') { - if TcpListener::bind(( - socket.0, - socket.1.to_string().parse::().unwrap_or_default(), - )) - .is_ok() - { - return true; - } - }; + if re.is_match(url) { + addr = re.replace(url, "").to_string(); } + if let Some(socket) = addr.split_once(':') { + if TcpListener::bind(( + socket.0, + socket.1.to_string().parse::().unwrap_or_default(), + )) + .is_ok() + { + return true; + } + }; + error!("Address {url} already in use!"); false From 50204ce3815d52214a426ed3e93178117ad3be2c Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 14 Jul 2023 13:46:30 +0200 Subject: [PATCH 3/4] watch channel change on player page, #351 --- ffplayout-frontend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffplayout-frontend b/ffplayout-frontend index 6d356e0c..eef6310a 160000 --- a/ffplayout-frontend +++ b/ffplayout-frontend @@ -1 +1 @@ -Subproject commit 6d356e0cd72c1cfffba9ef0b7ae976ee8df7ea21 +Subproject commit eef6310a8d489a9cd1af70e5b29a1caa8cbadb0a From acfe223301fd3d70cc358159dff122fc149bc32e Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 14 Jul 2023 13:59:24 +0200 Subject: [PATCH 4/4] rename hls output, fix #351 --- ffplayout-api/src/utils/channels.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ffplayout-api/src/utils/channels.rs b/ffplayout-api/src/utils/channels.rs index 19a223e1..55a061c6 100644 --- a/ffplayout-api/src/utils/channels.rs +++ b/ffplayout-api/src/utils/channels.rs @@ -48,6 +48,12 @@ pub async fn create_channel( .to_string_lossy() .to_string(); + config.out.output_param = config + .out + .output_param + .replace("stream.m3u8", &format!("stream{channel_num}.m3u8")) + .replace("stream-%d.ts", &format!("stream{channel_num}-%d.ts")); + let file = fs::File::create(&target_channel.config_path)?; serde_yaml::to_writer(file, &config).unwrap();