proper file end handling
This commit is contained in:
parent
0e48e03f17
commit
0d4dbdc780
3 changed files with 18 additions and 5 deletions
14
src/main.rs
14
src/main.rs
|
@ -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>> {
|
||||
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::<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(err) => return Err(Box::new(util::ThreadError(i))),
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue