Enable MD5 checking of input when reencoding to stdout

This commit is contained in:
Martijn van Beurden 2024-07-16 08:55:37 +02:00
parent 3adb645559
commit f94d34ffba
3 changed files with 30 additions and 5 deletions

View File

@ -802,10 +802,10 @@ static FLAC__bool get_sample_info_aiff(EncoderSession *e, encode_options_t optio
return true;
}
static FLAC__bool get_sample_info_flac(EncoderSession *e)
static FLAC__bool get_sample_info_flac(EncoderSession *e, FLAC__bool do_check_md5)
{
if (!(
FLAC__stream_decoder_set_md5_checking(e->fmt.flac.decoder, false) &&
FLAC__stream_decoder_set_md5_checking(e->fmt.flac.decoder, do_check_md5) &&
FLAC__stream_decoder_set_metadata_respond_all(e->fmt.flac.decoder)
)) {
flac__utils_printf(stderr, 1, "%s: ERROR: setting up decoder for FLAC input\n", e->inbasefilename);
@ -922,7 +922,7 @@ int flac__encode_file(FILE *infile, FLAC__off_t infilesize, const char *infilena
flac__utils_printf(stderr, 1, "%s: ERROR: creating decoder for FLAC input\n", encoder_session.inbasefilename);
return EncoderSession_finish_error(&encoder_session);
}
if(!get_sample_info_flac(&encoder_session))
if(!get_sample_info_flac(&encoder_session, encoder_session.is_stdout && flac__utils_check_empty_skip_until_specification(&options.skip_specification) && flac__utils_check_empty_skip_until_specification(&options.until_specification)))
return EncoderSession_finish_error(&encoder_session);
break;
default:
@ -1531,7 +1531,7 @@ int EncoderSession_finish_ok(EncoderSession *e, foreign_metadata_t *foreign_meta
ret = 1;
}
if(memcmp(e->md5sum_input,&empty_md5sum,16) != 0) {
if(ret == 0 && memcmp(e->md5sum_input,&empty_md5sum,16) != 0) {
FLAC__StreamMetadata streaminfo;
if(!FLAC__metadata_get_streaminfo(e->outfilename, &streaminfo)) {
flac__utils_printf(stderr, 1, "%s: ERROR: could not read back MD5sum of output\n", e->inbasefilename);
@ -1542,7 +1542,14 @@ int EncoderSession_finish_ok(EncoderSession *e, foreign_metadata_t *foreign_meta
ret = 1;
}
}
/*@@@@@@ should this go here or somewhere else? */
if(ret == 0 && (e->format == FORMAT_FLAC || e->format == FORMAT_OGGFLAC) && e->fmt.flac.decoder) {
if(!FLAC__stream_decoder_finish(e->fmt.flac.decoder)) {
flac__utils_printf(stderr, 1, "%s: ERROR: MD5sum of input FLAC file mismatched\n", e->inbasefilename);
ret = 1;
}
}
if(ret == 0 && foreign_metadata) {
const char *error;
if(!flac__foreign_metadata_write_to_flac(foreign_metadata, e->infilename, e->outfilename, &error)) {

View File

@ -330,6 +330,23 @@ FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__Skip
return true;
}
FLAC__bool flac__utils_check_empty_skip_until_specification(utils__SkipUntilSpecification *spec)
{
FLAC__ASSERT(0 != spec);
if(spec->value_is_samples) {
if(spec->value.samples == 0)
return true;
else
return false;
}
else {
if(spec->value.seconds == 0.0)
return true;
else
return false;
}
}
FLAC__bool flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate)
{
FLAC__ASSERT(0 != spec);

View File

@ -65,6 +65,7 @@ void stats_clear(void);
void stats_print_name(int level, const char *name);
void stats_print_info(int level, const char *format, ...);
FLAC__bool flac__utils_check_empty_skip_until_specification(utils__SkipUntilSpecification *spec);
FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec);
FLAC__bool flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, uint32_t sample_rate);