From 79378eecf6e82b850f5f49695b92bd8bbca91166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 11 Oct 2006 12:53:12 +0000 Subject: Use av_parser to decode audio, should make MP3 playback saner. Don't override avcodec_register_all() function when using external FFmpeg. CVS patchset: 8334 CVS date: 2006/10/11 12:53:12 --- src/libffmpeg/audio_decoder.c | 44 +++++++++++++++++++++++++++++++++---------- src/libffmpeg/xine_decoder.c | 4 +++- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/libffmpeg/audio_decoder.c b/src/libffmpeg/audio_decoder.c index 94237c817..56b142f21 100644 --- a/src/libffmpeg/audio_decoder.c +++ b/src/libffmpeg/audio_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: audio_decoder.c,v 1.27 2006/08/04 06:18:35 tmmm Exp $ + * $Id: audio_decoder.c,v 1.28 2006/10/11 12:53:12 dgp85 Exp $ * * xine audio decoder plugin using ffmpeg * @@ -68,6 +68,7 @@ typedef struct ff_audio_decoder_s { AVCodecContext *context; AVCodec *codec; + AVCodecParserContext *parser; char *decode_buffer; int decoder_ok; @@ -165,6 +166,7 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) } this->context = avcodec_alloc_context(); + this->parser = NULL; if(buf->decoder_flags & BUF_FLAG_STDHEADER) { this->audio_sample_rate = buf->decoder_info[1]; @@ -233,7 +235,8 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) this->size = 0; this->decode_buffer = xine_xmalloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); - + + this->parser = av_parser_init(this->context->codec_id); return; } } else if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && @@ -288,11 +291,25 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) offset = 0; while (this->size>0) { - bytes_consumed = avcodec_decode_audio (this->context, - (int16_t *)this->decode_buffer, - &decode_buffer_size, - &this->buf[offset], - this->size); + uint8_t *parsed_data = NULL; + int parsed_size = 0; + + if ( ! this->parser ) + this->parser = av_parser_init(this->context->codec_id); + + bytes_consumed = av_parser_parse(this->parser, + this->context, + &parsed_data, + &parsed_size, + &this->buf[offset], + this->size, + 0, 0); + avcodec_decode_audio(this->context, + (int16_t *)this->decode_buffer, + &decode_buffer_size, + parsed_data, + parsed_size); + free(parsed_data); if (bytes_consumed<0) { xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, @@ -354,6 +371,10 @@ static void ff_audio_reset (audio_decoder_t *this_gen) { if( this->context && this->decoder_ok ) { pthread_mutex_lock (&ffmpeg_lock); avcodec_close (this->context); + if ( this->parser ) { + av_parser_close (this->parser); + this->parser = NULL; + } avcodec_open (this->context, this->codec); pthread_mutex_unlock (&ffmpeg_lock); } @@ -369,6 +390,10 @@ static void ff_audio_dispose (audio_decoder_t *this_gen) { if( this->context && this->decoder_ok ) { pthread_mutex_lock (&ffmpeg_lock); avcodec_close (this->context); + if ( this->parser ) { + av_parser_close (this->parser); + this->parser = NULL; + } pthread_mutex_unlock (&ffmpeg_lock); } @@ -379,11 +404,10 @@ static void ff_audio_dispose (audio_decoder_t *this_gen) { free(this->buf); free(this->decode_buffer); - if(this->context && this->context->extradata) + if(this->context) free(this->context->extradata); - if(this->context) - free(this->context); + free(this->context); free (this_gen); } diff --git a/src/libffmpeg/xine_decoder.c b/src/libffmpeg/xine_decoder.c index 323ce4e3c..10f420997 100644 --- a/src/libffmpeg/xine_decoder.c +++ b/src/libffmpeg/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.170 2006/08/02 07:15:27 tmmm Exp $ + * $Id: xine_decoder.c,v 1.171 2006/10/11 12:53:12 dgp85 Exp $ * * xine decoder plugin using ffmpeg * @@ -38,6 +38,7 @@ pthread_once_t once_control = PTHREAD_ONCE_INIT; pthread_mutex_t ffmpeg_lock; +#ifndef HAVE_FFMPEG void avcodec_register_all(void) { static int inited = 0; @@ -146,6 +147,7 @@ void avcodec_register_all(void) register_avcodec(&truespeech_decoder); register_avcodec(&tta_decoder); } +#endif void init_once_routine(void) { pthread_mutex_init(&ffmpeg_lock, NULL); -- cgit v1.2.3