From 965ea6e948e8648433c507b11f2fa36d20758ee1 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 10 Sep 2011 21:10:54 +0100 Subject: Optimise flags usage. --- src/combined/ffmpeg/ff_audio_decoder.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/combined/ffmpeg/ff_audio_decoder.c') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 14a908d2f..5ff0ce70e 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -128,10 +128,9 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) int out; audio_buffer_t *audio_buffer; int bytes_to_send; - unsigned int codec_type = buf->type & 0xFFFF0000; + unsigned int codec_type = buf->type & (BUF_MAJOR_MASK | BUF_DECODER_MASK); - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_SPECIAL) ) { + if ( (buf->decoder_flags & (BUF_FLAG_HEADER | BUF_FLAG_SPECIAL)) == BUF_FLAG_HEADER ) { /* accumulate init data */ ff_audio_ensure_buffer_size(this, this->size + buf->size); -- cgit v1.2.3 From 72d45226cc4b327d61c620cf3c5c8c22e23c9e1f Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 10 Sep 2011 21:11:41 +0100 Subject: Use xine's fast memcpy function instead of standard library one. --- src/combined/ffmpeg/ff_audio_decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/combined/ffmpeg/ff_audio_decoder.c') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 5ff0ce70e..68380c124 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -134,7 +134,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) /* accumulate init data */ ff_audio_ensure_buffer_size(this, this->size + buf->size); - memcpy(this->buf + this->size, buf->content, buf->size); + xine_fast_memcpy(this->buf + this->size, buf->content, buf->size); this->size += buf->size; if (buf->decoder_flags & BUF_FLAG_FRAME_END) { -- cgit v1.2.3 From 7f5d3fdfb80831aad2949e8975f70d35b4c0752e Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 10 Sep 2011 21:13:57 +0100 Subject: Pad end of audio data buffer with zeros, as instructed by the API documentation. --- src/combined/ffmpeg/ff_audio_decoder.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/combined/ffmpeg/ff_audio_decoder.c') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 68380c124..321d0e8f4 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -115,7 +115,7 @@ static void *realloc16 (void *m, size_t s) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, _("ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n"), this->bufsize); - this->buf = realloc16 (this->buf, this->bufsize); + this->buf = realloc16 (this->buf, this->bufsize + FF_INPUT_BUFFER_PADDING_SIZE); } } @@ -355,6 +355,10 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) if (buf->decoder_flags & BUF_FLAG_FRAME_END) { /* time to decode a frame */ offset = 0; + + /* pad input data */ + memset(&this->buf[this->size], 0, FF_INPUT_BUFFER_PADDING_SIZE); + while (this->size>0) { decode_buffer_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; #if AVAUDIO > 2 -- cgit v1.2.3 From de65e355ef7f33091ae14854120574b5509941db Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 10 Sep 2011 21:21:52 +0100 Subject: Not every audio packet can be used to determine the sample rate and number of audio channels. So we must keep discarding packets that cannot be used to initialise the codec until we receive one that can be. --- src/combined/ffmpeg/ff_audio_decoder.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/combined/ffmpeg/ff_audio_decoder.c') diff --git a/src/combined/ffmpeg/ff_audio_decoder.c b/src/combined/ffmpeg/ff_audio_decoder.c index 321d0e8f4..7fd5af865 100644 --- a/src/combined/ffmpeg/ff_audio_decoder.c +++ b/src/combined/ffmpeg/ff_audio_decoder.c @@ -321,27 +321,36 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) 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; #if AVAUDIO > 2 av_init_packet (&avpkt); avpkt.data = (uint8_t *)&this->buf[0]; avpkt.size = this->size; avpkt.flags = AV_PKT_FLAG_KEY; - avcodec_decode_audio3 (this->context, - (int16_t *)this->decode_buffer, - &decode_buffer_size, &avpkt); + ret = avcodec_decode_audio3 (this->context, + (int16_t *)this->decode_buffer, + &decode_buffer_size, &avpkt); #else - avcodec_decode_audio2 (this->context, - (int16_t *)this->decode_buffer, - &decode_buffer_size, - &this->buf[0], - this->size); + ret = avcodec_decode_audio2 (this->context, + (int16_t *)this->decode_buffer, + &decode_buffer_size, + &this->buf[0], + this->size); #endif 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) + 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 (error=%d)\n"), ret); + + /* 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, -- cgit v1.2.3