diff --git a/src/main.rs b/src/main.rs index 2d9d0e2..8ca946a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,10 +18,22 @@ fn init() -> Result<[mpsc::Receiver>; 4 } fn process(error_handles: [mpsc::Receiver>; 4]) -> Result<(), Box> { + let (mut v_eof, mut a_eof) = (false, false); loop { + if v_eof && a_eof {return Ok(())} for i in 0..4 { match error_handles[i].try_recv() { - Ok(err) => return Err(err), + Ok(err) => { + if let Some(eof_error) = err.downcast_ref::() { + 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(err) => return Err(Box::new(util::ThreadError(i))), } diff --git a/src/muxer/hls/mp4/mp4muxer.rs b/src/muxer/hls/mp4/mp4muxer.rs index a4d6cc2..8dee66e 100644 --- a/src/muxer/hls/mp4/mp4muxer.rs +++ b/src/muxer/hls/mp4/mp4muxer.rs @@ -42,6 +42,7 @@ impl mp4::MP4Muxer { let (mut v, mut a) = (self.v.take().unwrap(), self.a.take().unwrap()); let v_queue = self.v_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 || { let mut i = 1; @@ -49,7 +50,7 @@ impl mp4::MP4Muxer { match v.recv() { Ok(x) => {v_queue.push(x.packet_data, if i % 30 == 0 {0x02000000} else {0x01010000});}, Err(_) => { - thread::park(); + util::thread_freeze(err_in1, Box::new(util::MuxerError::VideoEOF)); return } } @@ -61,7 +62,7 @@ impl mp4::MP4Muxer { match a.recv() { Ok(x) => {a_queue.push(x.packet_data, 0x01010000);}, Err(_) => { - thread::park(); + util::thread_freeze(err_in2, Box::new(util::MuxerError::AudioEOF)); return } } diff --git a/src/util/mod.rs b/src/util/mod.rs index 31c0c70..2fc5403 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -198,7 +198,8 @@ impl fmt::Display for EncoderError { pub enum MuxerError { InvalidCodec, CCParseError, - EOF, + VideoEOF, + AudioEOF, } impl Error for MuxerError {} @@ -209,7 +210,6 @@ impl fmt::Debug for MuxerError { match self { MuxerError::InvalidCodec => write!(f, "Codec not valid, unhandled"), MuxerError::CCParseError => write!(f, "Generic error while parsing codec config box"), - MuxerError::EOF => write!(f, "input EOF"), _ => write!(f, "Error not described yet") } }