proper file end handling

This commit is contained in:
Muaz Ahmad 2023-10-25 14:36:37 +05:00
parent 0e48e03f17
commit 0d4dbdc780
3 changed files with 18 additions and 5 deletions

View file

@ -18,10 +18,22 @@ fn init() -> Result<[mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 4
} }
fn process(error_handles: [mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 4]) -> Result<(), Box<dyn std::error::Error>> { fn process(error_handles: [mpsc::Receiver<Box<dyn std::error::Error + Send + Sync>>; 4]) -> Result<(), Box<dyn std::error::Error>> {
let (mut v_eof, mut a_eof) = (false, false);
loop { loop {
if v_eof && a_eof {return Ok(())}
for i in 0..4 { for i in 0..4 {
match error_handles[i].try_recv() { match error_handles[i].try_recv() {
Ok(err) => return Err(err), Ok(err) => {
if let Some(eof_error) = err.downcast_ref::<util::MuxerError>() {
match eof_error {
util::MuxerError::VideoEOF => {v_eof = true;},
util::MuxerError::AudioEOF => {a_eof = true;},
_ => return Err(err)
}
} else {
return Err(err)
}
},
Err(mpsc::TryRecvError::Empty) => (), Err(mpsc::TryRecvError::Empty) => (),
Err(err) => return Err(Box::new(util::ThreadError(i))), Err(err) => return Err(Box::new(util::ThreadError(i))),
} }

View file

@ -42,6 +42,7 @@ impl mp4::MP4Muxer {
let (mut v, mut a) = (self.v.take().unwrap(), self.a.take().unwrap()); let (mut v, mut a) = (self.v.take().unwrap(), self.a.take().unwrap());
let v_queue = self.v_samples.clone(); let v_queue = self.v_samples.clone();
let a_queue = self.a_samples.clone(); let a_queue = self.a_samples.clone();
let (err_in1, err_in2) = (self.err_in.clone(), self.err_in.clone());
thread::spawn(move || { thread::spawn(move || {
let mut i = 1; let mut i = 1;
@ -49,7 +50,7 @@ impl mp4::MP4Muxer {
match v.recv() { match v.recv() {
Ok(x) => {v_queue.push(x.packet_data, if i % 30 == 0 {0x02000000} else {0x01010000});}, Ok(x) => {v_queue.push(x.packet_data, if i % 30 == 0 {0x02000000} else {0x01010000});},
Err(_) => { Err(_) => {
thread::park(); util::thread_freeze(err_in1, Box::new(util::MuxerError::VideoEOF));
return return
} }
} }
@ -61,7 +62,7 @@ impl mp4::MP4Muxer {
match a.recv() { match a.recv() {
Ok(x) => {a_queue.push(x.packet_data, 0x01010000);}, Ok(x) => {a_queue.push(x.packet_data, 0x01010000);},
Err(_) => { Err(_) => {
thread::park(); util::thread_freeze(err_in2, Box::new(util::MuxerError::AudioEOF));
return return
} }
} }

View file

@ -198,7 +198,8 @@ impl fmt::Display for EncoderError {
pub enum MuxerError { pub enum MuxerError {
InvalidCodec, InvalidCodec,
CCParseError, CCParseError,
EOF, VideoEOF,
AudioEOF,
} }
impl Error for MuxerError {} impl Error for MuxerError {}
@ -209,7 +210,6 @@ impl fmt::Debug for MuxerError {
match self { match self {
MuxerError::InvalidCodec => write!(f, "Codec not valid, unhandled"), MuxerError::InvalidCodec => write!(f, "Codec not valid, unhandled"),
MuxerError::CCParseError => write!(f, "Generic error while parsing codec config box"), MuxerError::CCParseError => write!(f, "Generic error while parsing codec config box"),
MuxerError::EOF => write!(f, "input EOF"),
_ => write!(f, "Error not described yet") _ => write!(f, "Error not described yet")
} }
} }