type to manage moof fragment sample queue

This commit is contained in:
Muaz Ahmad 2023-10-20 16:37:37 +05:00
parent 28a43ecdaa
commit b2c2163928
3 changed files with 32 additions and 5 deletions

View file

@ -1,5 +1,6 @@
mod mp4muxer;
mod atoms;
mod samples;
use std::sync::{mpsc, Arc};
use std::error::Error;
@ -8,9 +9,9 @@ use crate::util;
pub struct MP4Muxer {
v: mpsc::Receiver<util::NALUPacket>,
v_samples: Vec<Vec<u8>>,
v_samples: samples::SampleQueue,
a: mpsc::Receiver<util::NALUPacket>,
a_samples: Vec<Vec<u8>>,
a_samples: samples::SampleQueue,
metadata: Arc<util::Metadata>,
err_in: mpsc::Sender<Box<dyn Error + Send + Sync>>,
}
@ -21,8 +22,14 @@ pub fn new_muxer(v: mpsc::Receiver<util::NALUPacket>, a: mpsc::Receiver<util::NA
a: a,
metadata: metadata,
err_in: err_in,
v_samples: Vec::new(),
a_samples: Vec::new(),
v_samples: samples::SampleQueue {
queue: Vec::new(),
default_duration: 1000,
},
a_samples: samples::SampleQueue {
queue: Vec::new(),
default_duration: 960,
},
};
muxer.gen_init()?;
return Ok(muxer);

View file

@ -18,7 +18,7 @@ impl mp4::MP4Muxer {
let v_cc = self.v.recv()?;
return match v_cc.packet_type {
util::NALUPacketType::Video(util::VideoCodec::AV1) => {
self.v_samples.push(v_cc.packet_data.clone());
self.v_samples.push(v_cc.packet_data.clone(), 0x02000000);
Ok(get_av1_stsd(v_cc.packet_data, &self.metadata))
},
_ => Err(Box::new(util::MuxerError::InvalidCodec))

View file

@ -0,0 +1,20 @@
pub struct Sample {
pub data: Vec<u8>,
pub size: u32,
pub flags: u32,
}
pub struct SampleQueue {
pub queue: Vec<Sample>,
pub default_duration: u32,
}
impl SampleQueue {
pub fn push(&mut self, data: Vec<u8>, flags: u32) {
self.queue.push(Sample {
size: data.len() as u32,
data: data,
flags: flags,
})
}
}