boilerplate for hls handling

This commit is contained in:
Muaz Ahmad 2023-10-16 15:26:29 +05:00
parent 08359cf7e2
commit fd1c6347c1
6 changed files with 30 additions and 20 deletions

View file

@ -13,7 +13,7 @@ fn init() -> Result<[mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 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]);
}

7
src/muxer/hls/handler.rs Normal file
View file

@ -0,0 +1,7 @@
pub struct HLSHandler;
impl HLSHandler {
pub fn data_loop(&mut self) {
todo!();
}
}

10
src/muxer/hls/mod.rs Normal file
View file

@ -0,0 +1,10 @@
mod handler;
use std::sync::{Arc, mpsc};
use std::error::Error;
use crate::util;
pub fn spawn(v: mpsc::Receiver<util::NALUPacket>, a: mpsc::Receiver<util::NALUPacket>, metadata: Arc<util::Metadata>, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>, hls_args: util::HLSArgs) -> Result<handler::HLSHandler, Box<dyn Error>> {
todo!();
}

0
src/muxer/hls/mp4/mod.rs Normal file
View file

View file

@ -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<util::NALUPacket>,
a: mpsc::Receiver<util::NALUPacket>,
metadata: Arc<util::Metadata>
metadata: Arc<util::Metadata>,
hls_args: util::HLSArgs
) -> Result<
mpsc::Receiver<Box<dyn Error + Send + Sync>>,
Box<dyn Error>
> {
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<util::NALUPacket>, filename: &str) {
let mut f = File::create(filename).unwrap();
loop {
let nalu = c.recv().unwrap();
f.write_all(&nalu.packet_data);
}
}

View file

@ -74,6 +74,12 @@ pub struct RawMedia {
pub sample: Vec<u8>,
}
pub struct HLSArgs {
pub segment_time: u32,
pub segment_prepend: String,
pub max_segments: u8,
}
// Errors
pub struct ThreadError(pub usize);