From fd1c6347c193329041ffd6ed01f91d386baf636a Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Mon, 16 Oct 2023 15:26:29 +0500 Subject: [PATCH] boilerplate for hls handling --- src/main.rs | 2 +- src/muxer/hls/handler.rs | 7 +++++++ src/muxer/hls/mod.rs | 10 ++++++++++ src/muxer/hls/mp4/mod.rs | 0 src/muxer/mod.rs | 25 ++++++------------------- src/util/mod.rs | 6 ++++++ 6 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 src/muxer/hls/handler.rs create mode 100644 src/muxer/hls/mod.rs create mode 100644 src/muxer/hls/mp4/mod.rs diff --git a/src/main.rs b/src/main.rs index 7389440..2d9d0e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ fn init() -> Result<[mpsc::Receiver>; 4 let (v_out, a_out, metadata, demux_err_recv) = demux::spawn()?; let (raw_v_out, raw_a_out, decode_err_recv) = decode::spawn(v_out, a_out, metadata.clone())?; let (enc_v_out, enc_a_out, encode_err_recv) = encode::spawn(raw_v_out, raw_a_out, metadata.clone(), util::VideoCodec::AV1, util::AudioCodec::OPUS)?; - let muxer_err_recv = muxer::spawn(enc_v_out, enc_a_out, metadata.clone())?; + let muxer_err_recv = muxer::spawn(enc_v_out, enc_a_out, metadata.clone(), util::HLSArgs{segment_time: 4, segment_prepend: String::from("/vid/tmp/"), max_segments: 4})?; return Ok([demux_err_recv, decode_err_recv, encode_err_recv, muxer_err_recv]); } diff --git a/src/muxer/hls/handler.rs b/src/muxer/hls/handler.rs new file mode 100644 index 0000000..337f968 --- /dev/null +++ b/src/muxer/hls/handler.rs @@ -0,0 +1,7 @@ +pub struct HLSHandler; + +impl HLSHandler { + pub fn data_loop(&mut self) { + todo!(); + } +} diff --git a/src/muxer/hls/mod.rs b/src/muxer/hls/mod.rs new file mode 100644 index 0000000..a75d565 --- /dev/null +++ b/src/muxer/hls/mod.rs @@ -0,0 +1,10 @@ +mod handler; + +use std::sync::{Arc, mpsc}; +use std::error::Error; + +use crate::util; + +pub fn spawn(v: mpsc::Receiver, a: mpsc::Receiver, metadata: Arc, err_in: mpsc::Sender>, hls_args: util::HLSArgs) -> Result> { + todo!(); +} diff --git a/src/muxer/hls/mp4/mod.rs b/src/muxer/hls/mp4/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/muxer/mod.rs b/src/muxer/mod.rs index 09db33d..2e28ecc 100644 --- a/src/muxer/mod.rs +++ b/src/muxer/mod.rs @@ -1,3 +1,5 @@ +mod hls; + use std::sync::{mpsc, Arc}; use std::error::Error; use std::thread; @@ -9,31 +11,16 @@ use crate::util; pub fn spawn( v: mpsc::Receiver, a: mpsc::Receiver, - metadata: Arc + metadata: Arc, + hls_args: util::HLSArgs ) -> Result< mpsc::Receiver>, Box > { let (err_in, err_out) = mpsc::channel(); - let metadata_handle = metadata.clone(); + let mut mux_segmenter = hls::spawn(v, a, metadata, err_in, hls_args)?; thread::spawn(move || { - write_to_file(v, "dump.av1"); - }); - thread::spawn(move || { - write_to_file(a, "dump.opus"); - }); - thread::spawn(move || { - &err_in; - &metadata_handle; - thread::park(); + mux_segmenter.data_loop() }); return Ok(err_out); } - -fn write_to_file(c: mpsc::Receiver, filename: &str) { - let mut f = File::create(filename).unwrap(); - loop { - let nalu = c.recv().unwrap(); - f.write_all(&nalu.packet_data); - } -} diff --git a/src/util/mod.rs b/src/util/mod.rs index e2c546f..c6ce06a 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -74,6 +74,12 @@ pub struct RawMedia { pub sample: Vec, } +pub struct HLSArgs { + pub segment_time: u32, + pub segment_prepend: String, + pub max_segments: u8, +} + // Errors pub struct ThreadError(pub usize);