diff options
author | Max Kellermann <max@duempel.org> | 2009-11-11 20:34:59 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-11-11 20:44:21 +0100 |
commit | 37181c91815d6807df77d6920973b924dba05f1f (patch) | |
tree | d3178e76d8ab9379ce615c5e92729592e605f11a /src/decoder/_flac_common.c | |
parent | 08b139f37c891b9b5f43f12910efda439add3f5b (diff) | |
download | mpd-37181c91815d6807df77d6920973b924dba05f1f.tar.gz mpd-37181c91815d6807df77d6920973b924dba05f1f.tar.xz mpd-37181c91815d6807df77d6920973b924dba05f1f.zip |
decoder/flac: moved code to flac_data_get_audio_format()
Remove the audio_format attribute, add "frame_size" instead. The
audio_format initialization and check is moved both to
flac_data_get_audio_format().
Diffstat (limited to '')
-rw-r--r-- | src/decoder/_flac_common.c | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c index 1e2ab6413..70fc2cbcc 100644 --- a/src/decoder/_flac_common.c +++ b/src/decoder/_flac_common.c @@ -58,19 +58,41 @@ flac_data_deinit(struct flac_data *data) tag_free(data->tag); } +bool +flac_data_get_audio_format(struct flac_data *data, + struct audio_format *audio_format) +{ + if (!data->have_stream_info) { + g_warning("no STREAMINFO packet found"); + return false; + } + + audio_format_init(audio_format, data->stream_info.sample_rate, + data->stream_info.bits_per_sample, + data->stream_info.channels); + + if (!audio_format_valid(audio_format)) { + g_warning("Invalid audio format: %u:%u:%u\n", + audio_format->sample_rate, + audio_format->bits, + audio_format->channels); + return false; + } + + data->frame_size = audio_format_frame_size(audio_format); + + return true; +} + void flac_metadata_common_cb(const FLAC__StreamMetadata * block, struct flac_data *data) { - const FLAC__StreamMetadata_StreamInfo *si = &(block->data.stream_info); - switch (block->type) { case FLAC__METADATA_TYPE_STREAMINFO: data->stream_info = block->data.stream_info; data->have_stream_info = true; - - audio_format_init(&data->audio_format, si->sample_rate, - si->bits_per_sample, si->channels); break; + case FLAC__METADATA_TYPE_VORBIS_COMMENT: if (data->replay_gain_info) replay_gain_info_free(data->replay_gain_info); @@ -113,8 +135,7 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame, FLAC__uint64 nbytes) { enum decoder_command cmd; - size_t buffer_size = frame->header.blocksize * - audio_format_frame_size(&data->audio_format); + size_t buffer_size = frame->header.blocksize * data->frame_size; void *buffer; float position; unsigned bit_rate; |