Skip to content

Commit

Permalink
Let flac -t parse all metadata blocks (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmf01 authored Mar 1, 2024
1 parent 7f7da55 commit 6615279
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion man/flac.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ the HTML documentation.
: Decode (the default behavior is to encode)

**-t, \--test**
: Test a flac encoded file (same as -d except no decoded file is written)
: Test a flac encoded file. This works the same as -d except no
decoded file is written, with some additional checks like parsing
of all metadata blocks.

**-a, \--analyze**
: Analyze a FLAC encoded file (same as -d except an analysis file is
Expand Down
9 changes: 6 additions & 3 deletions src/flac/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ FLAC__bool DecoderSession_init_decoder(DecoderSession *decoder_session, const ch
FLAC__stream_decoder_set_metadata_respond_application(decoder_session->decoder, (FLAC__byte *)FLAC__FOREIGN_METADATA_APPLICATION_ID[i]);
}

if(decoder_session->test_only)
FLAC__stream_decoder_set_metadata_respond_all(decoder_session->decoder);

#if FLAC__HAS_OGG
if(decoder_session->is_ogg) {
if(!decoder_session->use_first_serial_number)
Expand Down Expand Up @@ -1521,7 +1524,7 @@ void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMet
return;
}
}
else if(metadata->type == FLAC__METADATA_TYPE_CUESHEET) {
else if(metadata->type == FLAC__METADATA_TYPE_CUESHEET && !decoder_session->test_only) {
/* remember, at this point, decoder_session->total_samples can be 0, meaning 'unknown' */
if(decoder_session->total_samples == 0) {
flac__utils_printf(stderr, 1, "%s: ERROR can't use --cue when FLAC metadata has total sample count of 0\n", decoder_session->inbasefilename);
Expand All @@ -1544,7 +1547,7 @@ void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMet

decoder_session->total_samples = decoder_session->until_specification->value.samples - decoder_session->skip_specification->value.samples;
}
else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
else if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT && !decoder_session->test_only) {
if (decoder_session->replaygain.spec.apply) {
double reference, gain, peak;
if (!(decoder_session->replaygain.apply = grabbag__replaygain_load_from_vorbiscomment(metadata, decoder_session->replaygain.spec.use_album_gain, /*strict=*/false, &reference, &gain, &peak))) {
Expand Down Expand Up @@ -1574,7 +1577,7 @@ void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMet
}
(void)flac__utils_get_channel_mask_tag(metadata, &decoder_session->channel_mask);
}
else if(metadata->type == FLAC__METADATA_TYPE_APPLICATION && decoder_session->warn_user_about_foreign_metadata) {
else if(metadata->type == FLAC__METADATA_TYPE_APPLICATION && decoder_session->warn_user_about_foreign_metadata && !decoder_session->test_only) {
/* Foreign metadata signalling */
flac__utils_printf(stderr, 1, "%s: WARNING: found foreign metadata, use --keep-foreign-metadata to restore\n", decoder_session->inbasefilename);
decoder_session->warn_user_about_foreign_metadata = false;
Expand Down
6 changes: 4 additions & 2 deletions src/flac/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,8 @@ void show_help(void)
printf(" -h, --help Show this screen\n");
printf(" -H, --explain Show detailed explanation of usage and options\n");
printf(" -d, --decode Decode (the default behavior is to encode)\n");
printf(" -t, --test Same as -d except no decoded file is written\n");
printf(" -t, --test Same as -d except no decoded file is written,\n");
printf(" with some additional checks.\n");
printf(" -a, --analyze Same as -d except an analysis file is written\n");
printf(" -c, --stdout Write output to stdout\n");
printf(" -s, --silent Do not write runtime encode/decode statistics\n");
Expand Down Expand Up @@ -1410,7 +1411,8 @@ void show_explain(void)
printf(" -h, --help Show basic usage a list of all options\n");
printf(" -H, --explain Show this screen\n");
printf(" -d, --decode Decode (the default behavior is to encode)\n");
printf(" -t, --test Same as -d except no decoded file is written\n");
printf(" -t, --test Same as -d except no decoded file is written,\n");
printf(" with some additional checks.\n");
printf(" -a, --analyze Same as -d except an analysis file is written\n");
printf(" -c, --stdout Write output to stdout\n");
printf(" -s, --silent Do not write runtime encode/decode statistics\n");
Expand Down

0 comments on commit 6615279

Please sign in to comment.