Skip to content

Commit

Permalink
Add the continue-on-error option in the tune command.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki0824 committed Nov 3, 2023
1 parent 447075c commit 31b2341
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
5 changes: 3 additions & 2 deletions recisdb-rs/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)))
}
Expand Down
12 changes: 8 additions & 4 deletions recisdb-rs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ pub(crate) enum Commands {
#[clap(short, long, value_name = "seconds")]
time: Option<f64>,

/// 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")]
Expand All @@ -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<Vec<String>>,
/// 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<Vec<String>>,

/// The location of the output.
Expand Down Expand Up @@ -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<Vec<String>>,
/// 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<Vec<String>>,

/// The location of the output.
Expand Down
17 changes: 11 additions & 6 deletions recisdb-rs/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pin_project! {
o: AllowStdIo<Box<dyn Write>>,
dec: RefCell<Option<BufReader<AllowStdIo<StreamDecoder>>>>,
amt: u64,
abandon_decoder: bool,
abandon_decoder: Option<bool>,
abort: Arc<AtomicBool>,
progress_tx: std::sync::mpsc::Sender<u64>,
}
Expand All @@ -33,15 +33,19 @@ impl AsyncInOutTriple {
i: Box<dyn AsyncBufRead + Unpin>,
o: Box<dyn Write>,
config: Option<DecoderOptions>,
continue_on_error: bool,
) -> (Self, std::sync::mpsc::Receiver<u64>) {
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 = {
Expand Down Expand Up @@ -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,
)
Expand All @@ -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) {
Expand All @@ -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)),
}
}

Expand Down

0 comments on commit 31b2341

Please sign in to comment.