diff --git a/crates/core/src/mux/hls/mod.rs b/crates/core/src/mux/hls/mod.rs index 5941f58..96c5b0d 100644 --- a/crates/core/src/mux/hls/mod.rs +++ b/crates/core/src/mux/hls/mod.rs @@ -5,9 +5,9 @@ use anyhow::Result; use ffmpeg_rs_raw::ffmpeg_sys_the_third::AVPacket; use ffmpeg_rs_raw::Encoder; use itertools::Itertools; -use log::trace; +use log::{trace, warn}; use std::fmt::Display; -use std::fs::File; +use std::fs::{remove_dir_all, File}; use std::path::PathBuf; use uuid::Uuid; @@ -72,6 +72,8 @@ pub struct HlsMuxer { } impl HlsMuxer { + const MASTER_PLAYLIST: &'static str = "live.m3u8"; + pub fn new<'a>( out_dir: PathBuf, encoders: impl Iterator, @@ -106,7 +108,7 @@ impl HlsMuxer { .map(|v| v.to_playlist_variant()) .collect(); - let mut f_out = File::create(self.out_dir.join("live.m3u8"))?; + let mut f_out = File::create(self.out_dir.join(Self::MASTER_PLAYLIST))?; pl.write_to(&mut f_out)?; Ok(()) } @@ -134,3 +136,11 @@ impl HlsMuxer { Ok(EgressResult::None) } } + +impl Drop for HlsMuxer { + fn drop(&mut self) { + if let Err(e) = remove_dir_all(&self.out_dir) { + warn!("Failed to clean up hls dir: {} {}", self.out_dir.display(), e); + } + } +} diff --git a/crates/core/src/test_hls_timing.rs b/crates/core/src/test_hls_timing.rs index a1094a0..6c6fac9 100644 --- a/crates/core/src/test_hls_timing.rs +++ b/crates/core/src/test_hls_timing.rs @@ -116,8 +116,8 @@ impl HlsTimingTester { // Generate test stream let stream_id = Uuid::new_v4(); let out_dir = output_dir.join(stream_id.to_string()); - let hls_dir = - self.generate_test_stream(&out_dir, &stream_id, duration_seconds, segment_type)?; + let (_muxer, hls_dir) = + self.generate_test_stream(&out_dir, duration_seconds, segment_type)?; // Test the generated stream match self.test_stream_timing_internal(&hls_dir) { @@ -151,10 +151,9 @@ impl HlsTimingTester { fn generate_test_stream( &self, output_dir: &Path, - stream_id: &Uuid, duration_seconds: f32, segment_type: SegmentType, - ) -> Result { + ) -> Result<(HlsMuxer, PathBuf)> { const VIDEO_FPS: f32 = 30.0; const VIDEO_WIDTH: u16 = 1280; const VIDEO_HEIGHT: u16 = 720; @@ -341,7 +340,7 @@ impl HlsTimingTester { video_frames_generated as f32 / VIDEO_FPS ); - Ok(output_dir.join("stream_0")) + Ok((hls_muxer, output_dir.join("stream_0"))) } /// Test HLS timing for a specific stream directory