demuxer data loop impl
This commit is contained in:
parent
64bcb35c49
commit
0d65197ce9
3 changed files with 34 additions and 2 deletions
|
@ -74,7 +74,7 @@ impl input::FileReader for FLVReader {
|
|||
self.skip_init_header()?;
|
||||
return self.read_metadata()
|
||||
}
|
||||
fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error>> {
|
||||
fn read_nalu(&mut self, metadata: &util::Metadata) -> Result<util::NALUPacket, Box<dyn Error>> {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,36 @@
|
|||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::io::Read;
|
||||
use std::sync::mpsc;
|
||||
|
||||
use crate::util;
|
||||
use crate::demux::flv;
|
||||
|
||||
pub trait FileReader {
|
||||
fn init(&mut self) -> Result<util::Metadata, Box<dyn Error>>;
|
||||
fn read_nalu(&mut self) -> Result<util::NALUPacket, Box<dyn Error>>;
|
||||
fn read_nalu(&mut self, metadata: &util::Metadata) -> Result<util::NALUPacket, Box<dyn Error>>;
|
||||
fn data_loop(&mut self, v_in: mpsc::Sender<util::NALUPacket>, a_in: mpsc::Sender<util::NALUPacket>, metadata: &util::Metadata, err_in: mpsc::Sender<Box<dyn Error>>) {
|
||||
loop {
|
||||
let nalu = match self.read_nalu(metadata) {
|
||||
Ok(x) => x,
|
||||
Err(err) => {util::thread_freeze(err_in, err); return}
|
||||
};
|
||||
match nalu.packet_type {
|
||||
util::NALUPacketType::Audio => {
|
||||
match a_in.send(nalu) {
|
||||
Ok(_) => (),
|
||||
Err(err) => {util::thread_freeze(err_in, Box::new(err)); return}
|
||||
}
|
||||
}
|
||||
util::NALUPacketType::Video => {
|
||||
match v_in.send(nalu) {
|
||||
Ok(_) => (),
|
||||
Err(err) => {util::thread_freeze(err_in, Box::new(err)); return}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_reader() -> Result<impl FileReader, Box<dyn Error>> {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::thread;
|
||||
use std::sync::mpsc;
|
||||
|
||||
// Data structs/enums
|
||||
|
||||
|
@ -108,3 +110,10 @@ impl fmt::Display for DemuxerError {
|
|||
fmt::Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
// funcs
|
||||
|
||||
pub fn thread_freeze(err_sender: mpsc::Sender<Box<dyn Error>>, err: Box<dyn Error>) {
|
||||
err_sender.send(err).unwrap();
|
||||
thread::park();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue