From c25905047080cd6115f21f93e06e47cfdc2a1b1c Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Thu, 14 Dec 2006 06:58:49 +0000 Subject: [PATCH] Fix bug where using -F with FLAC-to-FLAC transcoding of a corrupted FLAC would have no effect (SF#1615391: https://sourceforge.net/tracker/index.php?func=detail&aid=1615391&group_id=13478&atid=113478) --- doc/html/changelog.html | 1 + src/flac/encode.c | 19 ++++++++++++++++--- src/flac/encode.h | 1 + src/flac/main.c | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/html/changelog.html b/doc/html/changelog.html index 494a6ac..86b5ab1 100644 --- a/doc/html/changelog.html +++ b/doc/html/changelog.html @@ -86,6 +86,7 @@
  • diff --git a/src/flac/encode.c b/src/flac/encode.c index 5ec2be1..7803fe6 100644 --- a/src/flac/encode.c +++ b/src/flac/encode.c @@ -67,6 +67,7 @@ typedef struct { FLAC__uint64 skip; FLAC__uint64 until; /* a value of 0 mean end-of-stream (i.e. --until=-0) */ + FLAC__bool continue_through_decode_errors; FLAC__bool replay_gain; unsigned channels; unsigned bits_per_sample; @@ -118,7 +119,7 @@ extern FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEn /* * local routines */ -static FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FILE *infile, const char *infilename, const char *outfilename); +static FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FLAC__bool continue_through_decode_errors, FILE *infile, const char *infilename, const char *outfilename); static void EncoderSession_destroy(EncoderSession *e); static int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero); static int EncoderSession_finish_error(EncoderSession *e); @@ -178,6 +179,7 @@ int flac__encode_aif(FILE *infile, off_t infilesize, const char *infilename, con /*use_ogg=*/false, #endif options.common.verify, + options.common.continue_through_decode_errors, infile, infilename, outfilename @@ -590,6 +592,7 @@ int flac__encode_wav(FILE *infile, off_t infilesize, const char *infilename, con /*use_ogg=*/false, #endif options.common.verify, + options.common.continue_through_decode_errors, infile, infilename, outfilename @@ -1111,6 +1114,7 @@ int flac__encode_raw(FILE *infile, off_t infilesize, const char *infilename, con /*use_ogg=*/false, #endif options.common.verify, + options.common.continue_through_decode_errors, infile, infilename, outfilename @@ -1365,6 +1369,7 @@ int flac__encode_flac(FILE *infile, off_t infilesize, const char *infilename, co /*use_ogg=*/false, #endif options.common.verify, + options.common.continue_through_decode_errors, infile, infilename, outfilename @@ -1481,6 +1486,12 @@ int flac__encode_flac(FILE *infile, off_t infilesize, const char *infilename, co * now do samples from the file */ while(!decoder_data.fatal_error && decoder_data.samples_left_to_process > 0) { + /* We can also hit the end of stream without samples_left_to_process + * going to 0 if there are errors and continue_through_decode_errors + * is on, so we want to break in that case too: + */ + if(encoder_session.continue_through_decode_errors && FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_END_OF_STREAM) + break; if(!FLAC__stream_decoder_process_single(decoder)) { flac__utils_printf(stderr, 1, "%s: ERROR: while decoding FLAC input, state = %s\n", encoder_session.inbasefilename, FLAC__stream_decoder_get_resolved_state_string(decoder)); goto fubar2; /*@@@ yuck */ @@ -1507,7 +1518,7 @@ fubar1: return EncoderSession_finish_error(&encoder_session); } -FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FILE *infile, const char *infilename, const char *outfilename) +FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC__bool verify, FLAC__bool continue_through_decode_errors, FILE *infile, const char *infilename, const char *outfilename) { unsigned i; FLAC__uint32 test = 1; @@ -1532,6 +1543,7 @@ FLAC__bool EncoderSession_construct(EncoderSession *e, FLAC__bool use_ogg, FLAC_ (void)use_ogg; #endif e->verify = verify; + e->continue_through_decode_errors = continue_through_decode_errors; e->is_stdout = (0 == strcmp(outfilename, "-")); e->outputfile_opened = false; @@ -2379,7 +2391,8 @@ void flac_decoder_error_callback(const FLAC__StreamDecoder *decoder, FLAC__Strea (void)decoder; flac__utils_printf(stderr, 1, "%s: ERROR got %s while decoding FLAC input\n", data->encoder_session->inbasefilename, FLAC__StreamDecoderErrorStatusString[status]); - data->fatal_error = true; + if(!data->encoder_session->continue_through_decode_errors) + data->fatal_error = true; } FLAC__bool parse_cuesheet(FLAC__StreamMetadata **cuesheet, const char *cuesheet_filename, const char *inbasefilename, FLAC__bool is_cdda, FLAC__uint64 lead_out_offset) diff --git a/src/flac/encode.h b/src/flac/encode.h index d117164..5202479 100644 --- a/src/flac/encode.h +++ b/src/flac/encode.h @@ -73,6 +73,7 @@ typedef struct { char *requested_seek_points; int num_requested_seek_points; const char *cuesheet_filename; + FLAC__bool continue_through_decode_errors; /* currently only obeyed when encoding from FLAC or Ogg FLAC */ FLAC__bool cued_seekpoints; FLAC__bool channel_map_none; /* --channel-map=none specified, eventually will expand to take actual channel map */ diff --git a/src/flac/main.c b/src/flac/main.c index 8f7ade1..62fc963 100644 --- a/src/flac/main.c +++ b/src/flac/main.c @@ -1680,6 +1680,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_ common_options.requested_seek_points = option_values.requested_seek_points; common_options.num_requested_seek_points = option_values.num_requested_seek_points; common_options.cuesheet_filename = option_values.cuesheet_filename; + common_options.continue_through_decode_errors = option_values.continue_through_decode_errors; common_options.cued_seekpoints = option_values.cued_seekpoints; common_options.channel_map_none = option_values.channel_map_none; common_options.is_first_file = is_first_file; -- 2.7.4