diff --git a/recisdb-rs/src/commands/mod.rs b/recisdb-rs/src/commands/mod.rs index 0c40957..9342bdf 100644 --- a/recisdb-rs/src/commands/mod.rs +++ b/recisdb-rs/src/commands/mod.rs @@ -73,6 +73,7 @@ pub(crate) fn process_command( no_simd, no_strip, output, + continue_on_error, } => { // Get channel let channel = channel.map(|ch| Channel::new(ch, tsid)).unwrap(); @@ -124,7 +125,7 @@ pub(crate) fn process_command( }) }; - let (body, _) = AsyncInOutTriple::new(input, output, dec); + let (body, _) = AsyncInOutTriple::new(input, output, dec, continue_on_error); info!("Recording..."); (body, rec_duration, None) } @@ -156,7 +157,7 @@ pub(crate) fn process_command( ..DecoderOptions::default() }); - let (body, progress) = AsyncInOutTriple::new(input, output, dec); + let (body, progress) = AsyncInOutTriple::new(input, output, dec, false); info!("Decoding..."); (body, None, input_sz.map(|sz| (sz, progress))) } diff --git a/recisdb-rs/src/context.rs b/recisdb-rs/src/context.rs index 458f3cc..9ef66a3 100644 --- a/recisdb-rs/src/context.rs +++ b/recisdb-rs/src/context.rs @@ -98,6 +98,10 @@ pub(crate) enum Commands { #[clap(short, long, value_name = "seconds")] time: Option, + /// Continue on error when the decoding failed while processing. + #[clap(short = 'k', long)] + continue_on_error: bool, + /// Disable ARIB STD-B25 decoding. /// If this flag is specified, ARIB STD-B25 decoding is not performed. #[clap(long = "no-decode")] @@ -121,13 +125,13 @@ pub(crate) enum Commands { /// The first working key is a 64-bit hexadecimal number. /// If the first working key is not specified, this subcommand /// will not decode ECM. - #[clap(short = 'k', long = "key0")] + #[clap(long = "key0")] key0: Option>, /// The second working key (only available w/ "crypto" feature). /// The second working key is a 64-bit hexadecimal number. /// If the second working key is not specified, this subcommand /// will not decode ECM. - #[clap(short = 'K', long = "key1")] + #[clap(long = "key1")] key1: Option>, /// The location of the output. @@ -167,13 +171,13 @@ pub(crate) enum Commands { /// The first working key is a 64-bit hexadecimal number. /// If the first working key is not specified, this subcommand /// will not decode ECM. - #[clap(short = 'k', long = "key0")] + #[clap(long = "key0")] key0: Option>, /// The second working key (only available w/ "crypto" feature). /// The second working key is a 64-bit hexadecimal number. /// If the second working key is not specified, this subcommand /// will not decode ECM. - #[clap(short = 'K', long = "key1")] + #[clap(long = "key1")] key1: Option>, /// The location of the output. diff --git a/recisdb-rs/src/io.rs b/recisdb-rs/src/io.rs index e8b1fed..801ed74 100644 --- a/recisdb-rs/src/io.rs +++ b/recisdb-rs/src/io.rs @@ -21,7 +21,7 @@ pin_project! { o: AllowStdIo>, dec: RefCell>>>, amt: u64, - abandon_decoder: bool, + abandon_decoder: Option, abort: Arc, progress_tx: std::sync::mpsc::Sender, } @@ -33,15 +33,19 @@ impl AsyncInOutTriple { i: Box, o: Box, config: Option, + continue_on_error: bool, ) -> (Self, std::sync::mpsc::Receiver) { let raw = config.and_then(|op| match StreamDecoder::new(op) { Ok(raw) => Some(raw), - Err(e) => { + Err(e) if continue_on_error => { error!("Failed to initialize the decoder. ({})", e); info!("Disabling decoding and continue..."); // As a fallback, disable decoding and continue processing None } + Err(e) => { + todo!("{}", e) // early return + } }); let dec = { @@ -72,7 +76,7 @@ impl AsyncInOutTriple { amt: 0, abort, progress_tx, - abandon_decoder: false, + abandon_decoder: if continue_on_error { Some(false) } else { None }, }, progress_rx, ) @@ -88,7 +92,7 @@ impl Future for AsyncInOutTriple { let _ = this.progress_tx.send(*this.amt); match this.dec.get_mut() { - Some(ref mut dec) if !*this.abandon_decoder => { + Some(ref mut dec) if !this.abandon_decoder.unwrap_or(false) => { // A. B. // In -> Decoder -> Out if !this.abort.load(Ordering::Relaxed) { @@ -107,12 +111,13 @@ impl Future for AsyncInOutTriple { *this.amt += i as u64; this.i.as_mut().consume(i); } - Err(e) => { + Err(e) if this.abandon_decoder.is_some() => { // Enable bypassing a decoder - *this.abandon_decoder = true; + *this.abandon_decoder = Some(true); error!("Unexpected failure in the decoder({}).", e); warn!("Falling back to decoder-less mode...") } + Err(e) => return Poll::Ready(Err(e)), } }