mirror of
https://github.com/v0l/zap-stream-core.git
synced 2025-06-20 13:40:33 +00:00
chore: cleanup HLS output when dropped
This commit is contained in:
@ -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<Item = (&'a VariantStream, &'a Encoder)>,
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<PathBuf> {
|
||||
) -> 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
|
||||
|
Reference in New Issue
Block a user