diff options
author | Max Kellermann <max@duempel.org> | 2009-11-11 19:01:31 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-11-11 19:08:10 +0100 |
commit | f937ec9a7c6b2439cda68c9cfdaa603258f8a0d4 (patch) | |
tree | 3ec83fd05d90c5fcca6674152d85c47eb855b0ac | |
parent | a3f5284dc6728321feb6efb1ade91855a9a90afa (diff) | |
download | mpd-f937ec9a7c6b2439cda68c9cfdaa603258f8a0d4.tar.gz mpd-f937ec9a7c6b2439cda68c9cfdaa603258f8a0d4.tar.xz mpd-f937ec9a7c6b2439cda68c9cfdaa603258f8a0d4.zip |
decoder/flac: merge code into flac_decoder_initialize()
Wrapper for FLAC__stream_decoder_process_until_end_of_metadata(),
decoder_initialized().
-rw-r--r-- | src/decoder/flac_plugin.c | 89 |
1 files changed, 39 insertions, 50 deletions
diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c index 774d40df1..98bcd64d3 100644 --- a/src/decoder/flac_plugin.c +++ b/src/decoder/flac_plugin.c @@ -391,6 +391,32 @@ flac_decoder_new(void) return sd; } +static bool +flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd, + bool seekable, FLAC__uint64 duration) +{ + if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) { + g_warning("problem reading metadata"); + return false; + } + + if (!audio_format_valid(&data->audio_format)) { + g_warning("Invalid audio format: %u:%u:%u\n", + data->audio_format.sample_rate, + data->audio_format.bits, + data->audio_format.channels); + return false; + } + + if (duration != 0) + data->total_time = (float)duration / + (float)data->audio_format.sample_rate; + + decoder_initialized(data->decoder, &data->audio_format, + seekable, data->total_time); + return true; +} + static void flac_decoder_loop(struct flac_data *data, FLAC__StreamDecoder *flac_dec, FLAC__uint64 t_start, FLAC__uint64 t_end) @@ -496,22 +522,13 @@ flac_decode_internal(struct decoder * decoder, } } - if (!FLAC__stream_decoder_process_until_end_of_metadata(flac_dec)) { - err = "problem reading metadata"; - goto fail; - } - - if (!audio_format_valid(&data.audio_format)) { - g_warning("Invalid audio format: %u:%u:%u\n", - data.audio_format.sample_rate, - data.audio_format.bits, - data.audio_format.channels); - goto fail; + if (!flac_decoder_initialize(&data, flac_dec, + input_stream->seekable, 0)) { + flac_data_deinit(&data); + FLAC__stream_decoder_delete(flac_dec); + return; } - decoder_initialized(decoder, &data.audio_format, - input_stream->seekable, data.total_time); - flac_decoder_loop(&data, flac_dec, 0, 0); fail: @@ -601,28 +618,12 @@ flac_container_decode(struct decoder* decoder, goto fail; } - if (!FLAC__stream_decoder_process_until_end_of_metadata(flac_dec)) - { - err = "problem reading metadata"; - goto fail; - } - - if (!audio_format_valid(&data.audio_format)) - { - g_warning("Invalid audio format: %u:%u:%u\n", - data.audio_format.sample_rate, - data.audio_format.bits, - data.audio_format.channels); - goto fail; + if (!flac_decoder_initialize(&data, flac_dec, true, track_time)) { + flac_data_deinit(&data); + FLAC__stream_decoder_delete(flac_dec); + return; } - // set track time (order is important: after stream init) - data.total_time = ((float)track_time / (float)data.audio_format.sample_rate); - data.position = 0; - - decoder_initialized(decoder, &data.audio_format, - true, data.total_time); - // seek to song start (order is important: after decoder init) FLAC__stream_decoder_seek_absolute(flac_dec, (FLAC__uint64)t_start); data.next_frame = t_start; @@ -694,24 +695,12 @@ flac_filedecode_internal(struct decoder* decoder, } } - if (!FLAC__stream_decoder_process_until_end_of_metadata(flac_dec)) - { - err = "problem reading metadata"; - goto fail; - } - - if (!audio_format_valid(&data.audio_format)) - { - g_warning("Invalid audio format: %u:%u:%u\n", - data.audio_format.sample_rate, - data.audio_format.bits, - data.audio_format.channels); - goto fail; + if (!flac_decoder_initialize(&data, flac_dec, true, 0)) { + flac_data_deinit(&data); + FLAC__stream_decoder_delete(flac_dec); + return; } - decoder_initialized(decoder, &data.audio_format, - true, data.total_time); - flac_decoder_loop(&data, flac_dec, 0, 0); fail: |