From 9fa54f15e1b4b79730e2cefc089805206ec2fb38 Mon Sep 17 00:00:00 2001 From: Petri Hintukainen Date: Wed, 2 Nov 2011 13:57:35 +0200 Subject: ff_audio_decoder: open audio out after decoding the data - Fixes detecting audio parameters when audio packet is splitted to multiple buffers - Simplifies the code (decode function is called only once for each audio frame) --- src/combined/ffmpeg/ff_audio_decoder.c | 56 +++++++++++++++------------------- 1 file changed, 24 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 01b5875fa..2515d657c 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -376,38 +376,6 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); this->size += buf->size; - if (!this->output_open) { - if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) { - int ret; - - decode_buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; - - ret = ff_audio_decode(this->stream->xine, this->context, - (int16_t *)this->decode_buffer, &decode_buffer_size, - this->buf, this->size); - - this->audio_bits = this->context->bits_per_sample; - this->audio_sample_rate = this->context->sample_rate; - this->audio_channels = this->context->channels; - if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - _("ffmpeg_audio_dec: cannot read codec parameters from packet\n")); - - /* We can't use this packet, so we must discard it - * and wait for another one. */ - this->size = 0; - return; - } - } - this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, - this->stream, this->audio_bits, this->audio_sample_rate, - _x_ao_channels2mode(this->audio_channels)); - } - - /* if the audio still isn't open, bail */ - if (!this->output_open) - return; - if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ offset = 0; @@ -432,6 +400,30 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) return; } + if (!this->output_open) { + if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) { + this->audio_bits = this->context->bits_per_sample; + this->audio_sample_rate = this->context->sample_rate; + this->audio_channels = this->context->channels; + if (!this->audio_bits || !this->audio_sample_rate || !this->audio_channels) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("ffmpeg_audio_dec: cannot read codec parameters from packet\n")); + + /* We can't use this packet, so we must discard it + * and wait for another one. */ + this->size = 0; + return; + } + } + this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, + this->stream, this->audio_bits, this->audio_sample_rate, + _x_ao_channels2mode(this->audio_channels)); + } + + /* if the audio still isn't open, bail */ + if (!this->output_open) + return; + /* dispatch the decoded audio */ out = 0; while (out < decode_buffer_size) { -- cgit v1.2.3