flac: Implement --no-error-on-compression-fail command line option.
authorErik de Castro Lopo <erikd@mega-nerd.com>
Mon, 22 Jul 2013 10:32:01 +0000 (20:32 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Thu, 1 Aug 2013 12:06:18 +0000 (22:06 +1000)
This is designed for the test suite where a number of artificially created
files end up bigger than the original.

src/flac/encode.c
src/flac/encode.h
src/flac/main.c

index 033fbe7..5a6c829 100644 (file)
@@ -129,7 +129,7 @@ static FLAC__int32 *input_[FLAC__MAX_CHANNELS];
  */
 static FLAC__bool EncoderSession_construct(EncoderSession *e, encode_options_t options, FLAC__off_t infilesize, FILE *infile, const char *infilename, const char *outfilename, const FLAC__byte *lookahead, unsigned lookahead_length);
 static void EncoderSession_destroy(EncoderSession *e);
-static int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata);
+static int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail);
 static int EncoderSession_finish_error(EncoderSession *e);
 static FLAC__bool EncoderSession_init_encoder(EncoderSession *e, encode_options_t options);
 static FLAC__bool EncoderSession_process(EncoderSession *e, const FLAC__int32 * const buffer[], unsigned samples);
@@ -1489,7 +1489,8 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
                &encoder_session,
                info_align_carry,
                info_align_zero,
-               EncoderSession_format_is_iff(&encoder_session)? options.format_options.iff.foreign_metadata : 0
+               EncoderSession_format_is_iff(&encoder_session)? options.format_options.iff.foreign_metadata : 0,
+               options.error_on_compression_fail
        );
 }
 
@@ -1608,7 +1609,7 @@ void EncoderSession_destroy(EncoderSession *e)
        }
 }
 
-int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata)
+int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_align_zero, foreign_metadata_t *foreign_metadata, FLAC__bool error_on_compression_fail)
 {
        FLAC__StreamEncoderState fse_state = FLAC__STREAM_ENCODER_OK;
        int ret = 0;
@@ -1652,7 +1653,7 @@ int EncoderSession_finish_ok(EncoderSession *e, int info_align_carry, int info_a
                }
        }
 
-       if (e->compression_ratio >= 1.0) {
+       if (error_on_compression_fail && e->compression_ratio >= 1.0) {
                flac__utils_printf(stderr, 1, "ERROR: Compression failed (ratio %0.3f, should be < 1.0). Please contact the developers.\n", e->compression_ratio);
                ret = 1;
        }
index 63769c8..d044037 100644 (file)
@@ -84,6 +84,7 @@ typedef struct {
        FLAC__bool replay_gain;
        FLAC__bool ignore_chunk_sizes;
        FLAC__bool sector_align;
+       FLAC__bool error_on_compression_fail;
 
        FLAC__StreamMetadata *vorbis_comment;
        FLAC__StreamMetadata *pictures[64];
index 39a2514..102ff3f 100644 (file)
@@ -207,6 +207,7 @@ static struct share__option long_options_[] = {
        { "no-warnings-as-errors"     , share__no_argument, 0, 0 },
        { "no-residual-gnuplot"       , share__no_argument, 0, 0 },
        { "no-residual-text"          , share__no_argument, 0, 0 },
+       { "no-error-on-compression-fail", share__no_argument, 0, 0 },
        /*
         * undocumented debugging options for the test suite
         */
@@ -271,6 +272,7 @@ static struct {
        const char *cuesheet_filename;
        FLAC__bool cued_seekpoints;
        FLAC__bool channel_map_none; /* --channel-map=none specified, eventually will expand to take actual channel map */
+       FLAC__bool error_on_compression_fail;
 
        unsigned num_files;
        char **filenames;
@@ -594,6 +596,7 @@ FLAC__bool init_options(void)
        option_values.cuesheet_filename = 0;
        option_values.cued_seekpoints = true;
        option_values.channel_map_none = false;
+       option_values.error_on_compression_fail = true;
 
        option_values.num_files = 0;
        option_values.filenames = 0;
@@ -908,6 +911,9 @@ int parse_option(int short_option, const char *long_option, const char *option_a
                else if(0 == strcmp(long_option, "no-md5-sum")) {
                        option_values.debug.do_md5 = false;
                }
+               else if(0 == strcmp(long_option, "no-error-on-compression-fail")) {
+                       option_values.error_on_compression_fail = false;
+               }
        }
        else {
                switch(short_option) {
@@ -1901,6 +1907,7 @@ int encode_file(const char *infilename, FLAC__bool is_first_file, FLAC__bool is_
        encode_options.debug.disable_fixed_subframes = option_values.debug.disable_fixed_subframes;
        encode_options.debug.disable_verbatim_subframes = option_values.debug.disable_verbatim_subframes;
        encode_options.debug.do_md5 = option_values.debug.do_md5;
+       encode_options.error_on_compression_fail = option_values.error_on_compression_fail;
 
        /* if infilename and outfilename point to the same file, we need to write to a temporary file */
        if(encode_infile != stdin && grabbag__file_are_same(infilename, outfilename)) {