boilerplate for mp4 muxing
This commit is contained in:
parent
fd1c6347c1
commit
f287cc2d64
7 changed files with 92 additions and 3 deletions
|
@ -37,6 +37,7 @@ impl Encoder for AV1Encoder {
|
|||
let nalu_len = u32::from_le_bytes(buff[..4].try_into().unwrap()) as usize;
|
||||
let mut data = vec![0u8; nalu_len];
|
||||
stdout.read_exact(data.as_mut_slice())?;
|
||||
data.drain(..2);
|
||||
return Ok(util::NALUPacket {packet_type: util::NALUPacketType::Video(util::VideoCodec::AV1), packet_data: data});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
pub struct HLSHandler;
|
||||
use std::error::Error;
|
||||
use std::sync::{mpsc, Arc};
|
||||
|
||||
use crate::util;
|
||||
use crate::muxer::hls::mp4;
|
||||
|
||||
pub struct HLSHandler {
|
||||
muxer: mp4::MP4Muxer,
|
||||
err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>,
|
||||
args: util::HLSArgs,
|
||||
}
|
||||
|
||||
impl HLSHandler {
|
||||
pub fn data_loop(&mut self) {
|
||||
pub fn data_loop(&self) {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn(v: mpsc::Receiver<util::NALUPacket>, a: mpsc::Receiver<util::NALUPacket>, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>, metadata: Arc<util::Metadata>, args: util::HLSArgs) -> Result<HLSHandler, Box<dyn Error>> {
|
||||
Ok(HLSHandler {muxer: mp4::new_muxer(v, a, metadata, err_in.clone())?, err_in: err_in, args: args})
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
mod handler;
|
||||
mod mp4;
|
||||
|
||||
use std::sync::{Arc, mpsc};
|
||||
use std::error::Error;
|
||||
|
@ -6,5 +7,6 @@ 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!();
|
||||
let hls_handler = handler::spawn(v, a, err_in, metadata, hls_args)?;
|
||||
Ok(hls_handler)
|
||||
}
|
||||
|
|
0
src/muxer/hls/mp4/atoms.rs
Normal file
0
src/muxer/hls/mp4/atoms.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
mod mp4muxer;
|
||||
|
||||
use std::sync::{mpsc, Arc};
|
||||
use std::error::Error;
|
||||
|
||||
use crate::util;
|
||||
|
||||
pub struct MP4Muxer {
|
||||
v: mpsc::Receiver<util::NALUPacket>,
|
||||
v_samples: Vec<util::NALUPacket>,
|
||||
a: mpsc::Receiver<util::NALUPacket>,
|
||||
a_samples: Vec<util::NALUPacket>,
|
||||
metadata: Arc<util::Metadata>,
|
||||
err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>,
|
||||
}
|
||||
|
||||
pub fn new_muxer(v: mpsc::Receiver<util::NALUPacket>, a: mpsc::Receiver<util::NALUPacket>, metadata: Arc<util::Metadata>, err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>) -> Result<MP4Muxer, Box<dyn Error>> {
|
||||
let mut muxer = MP4Muxer {
|
||||
v: v,
|
||||
a: a,
|
||||
metadata: metadata,
|
||||
err_in: err_in,
|
||||
v_samples: Vec::new(),
|
||||
a_samples: Vec::new(),
|
||||
};
|
||||
muxer.gen_init()?;
|
||||
return Ok(muxer);
|
||||
}
|
||||
|
||||
|
20
src/muxer/hls/mp4/mp4muxer.rs
Normal file
20
src/muxer/hls/mp4/mp4muxer.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use std::error::Error;
|
||||
|
||||
use crate::util;
|
||||
use crate::muxer::hls::mp4;
|
||||
|
||||
impl mp4::MP4Muxer {
|
||||
pub fn gen_init(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
let a_CC = self.handle_a_CC()?;
|
||||
let v_CC = self.handle_v_CC()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_a_CC(&mut self) -> Result<util::NALUPacket, Box<dyn Error>> {
|
||||
todo!();
|
||||
}
|
||||
|
||||
fn handle_v_CC(&mut self) -> Result<util::NALUPacket, Box<dyn Error>> {
|
||||
todo!();
|
||||
}
|
||||
}
|
|
@ -194,6 +194,28 @@ impl fmt::Display for EncoderError {
|
|||
fmt::Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MuxerError {
|
||||
InvalidCodec,
|
||||
}
|
||||
|
||||
impl Error for MuxerError {}
|
||||
|
||||
#[allow(unreachable_patterns)]
|
||||
impl fmt::Debug for MuxerError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
MuxerError::InvalidCodec => write!(f, "Codec not valid, unhandled"),
|
||||
_ => write!(f, "Error not described yet")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MuxerError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
// funcs
|
||||
|
||||
pub fn thread_freeze(err_sender: mpsc::Sender<Box<dyn Error + Send + Sync>>, err: Box<dyn Error + Send + Sync>) {
|
||||
|
|
Loading…
Reference in a new issue