diff options
-rw-r--r-- | src/libffmpeg/xine_decoder.c | 107 |
1 files changed, 38 insertions, 69 deletions
diff --git a/src/libffmpeg/xine_decoder.c b/src/libffmpeg/xine_decoder.c index 54aa7bd1b..ceb5a9121 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.64 2002/11/11 13:45:34 miguelfreitas Exp $ + * $Id: xine_decoder.c,v 1.65 2002/11/11 16:22:58 miguelfreitas Exp $ * * xine decoder plugin using ffmpeg * @@ -69,7 +69,7 @@ typedef struct ff_decoder_s { int skipframes; AVPicture av_picture; - AVCodecContext context; + AVCodecContext *context; /* mpeg sequence header parsing, stolen from libmpeg2 */ @@ -100,7 +100,7 @@ typedef struct ff_audio_decoder_s { int bufsize; int size; - AVCodecContext context; + AVCodecContext *context; char *decode_buffer; int decoder_ok; @@ -114,19 +114,20 @@ static pthread_once_t once_control = PTHREAD_ONCE_INIT; #define AUDIOBUFSIZE VIDEOBUFSIZE -static void init_codec (ff_video_decoder_t *this, AVCodec *codec) { +static void init_video_codec (ff_video_decoder_t *this, AVCodec *codec) { /* force (width % 8 == 0), otherwise there will be * display problems with Xv. */ this->bih.biWidth = (this->bih.biWidth + 7) & (~7); - memset(&this->context, 0, sizeof(this->context)); - this->context.width = this->bih.biWidth; - this->context.height = this->bih.biHeight; + this->context = avcodec_alloc_context(); + this->context->width = this->bih.biWidth; + this->context->height = this->bih.biHeight; - if (avcodec_open (&this->context, codec) < 0) { + if (avcodec_open (this->context, codec) < 0) { printf ("ffmpeg: couldn't open decoder\n"); + free(this->context); return; } @@ -139,7 +140,7 @@ static void init_codec (ff_video_decoder_t *this, AVCodec *codec) { decoder which support error resilience should handle them like errors. */ if (this->class->illegal_vlc) - this->context.error_resilience=-1; + this->context->error_resilience=-1; if (this->buf) free (this->buf); @@ -279,7 +280,7 @@ static void find_sequence_header (ff_video_decoder_t *this, } this->is_continous = 1; - init_codec (this, codec); + init_video_codec (this, codec); } } } @@ -397,40 +398,9 @@ static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { printf ("ffmpeg: couldn't find decoder\n"); return; } - - /* force (width % 8 == 0), otherwise there will be - * display problems with Xv. - */ - this->bih.biWidth = (this->bih.biWidth + 7) & (~7); - - memset(&this->context, 0, sizeof(this->context)); - this->context.width = this->bih.biWidth; - this->context.height = this->bih.biHeight; - - if (avcodec_open (&this->context, codec) < 0) { - printf ("ffmpeg: couldn't open decoder\n"); - return; - } - this->decoder_ok = 1; - this->stream->video_out->open (this->stream->video_out); - - /* needed to play streams generated by MS ISO MPEG4 codec. - Michael Niedermayer explained: - M$ "ISO MPEG4" uses illegal vlc code combinations, a ISO MPEG4 compliant - decoder which support error resilience should handle them like errors. - */ - if (this->class->illegal_vlc) - this->context.error_resilience=-1; - - if( this->buf ) - free( this->buf ); - - this->buf = malloc( VIDEOBUFSIZE ); - this->bufsize = VIDEOBUFSIZE; - - this->skipframes = 0; - + init_video_codec (this, codec); + } else if (this->decoder_ok) { if( this->size + buf->size > this->bufsize ) { @@ -457,11 +427,11 @@ static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { /* decode video frame(s) */ /* skip decoding b frames if too late */ - this->context.hurry_up = (this->skipframes > 2) ? 1:0; + this->context->hurry_up = (this->skipframes > 2) ? 1:0; offset = 0; while (this->size>0) { - len = avcodec_decode_video (&this->context, &this->av_picture, + len = avcodec_decode_video (this->context, &this->av_picture, &got_picture, &this->buf[offset], this->size); if (len<0) { @@ -491,7 +461,7 @@ static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { emms_c (); #endif - switch(this->context.aspect_ratio_info) { + switch(this->context->aspect_ratio_info) { case FF_ASPECT_SQUARE: ratio = XINE_VO_ASPECT_SQUARE; break; @@ -543,7 +513,7 @@ static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { for (y=0; y<(this->bih.biHeight/2); y++) { - if (this->context.pix_fmt != PIX_FMT_YUV444P) { + if (this->context->pix_fmt != PIX_FMT_YUV444P) { xine_fast_memcpy (du, su, this->bih.biWidth/2); xine_fast_memcpy (dv, sv, this->bih.biWidth/2); @@ -574,7 +544,7 @@ static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { du += img->pitches[1]; dv += img->pitches[2]; - if (this->context.pix_fmt != PIX_FMT_YUV420P) { + if (this->context->pix_fmt != PIX_FMT_YUV420P) { su += 2*this->av_picture.linesize[1]; sv += 2*this->av_picture.linesize[2]; } else { @@ -664,11 +634,14 @@ static void ff_dispose (video_decoder_t *this_gen) { #endif if (this->decoder_ok) { - avcodec_close (&this->context); + avcodec_close (this->context); this->stream->video_out->close(this->stream->video_out); this->decoder_ok = 0; } + + if( this->context ) + free( this->context ); if (this->buf) free(this->buf); @@ -751,8 +724,6 @@ static void *init_video_plugin (xine_t *xine, void *data) { return this; } -void avcodec_get_context_defaults(AVCodecContext *s); - static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { ff_audio_decoder_t *this = (ff_audio_decoder_t *) this_gen; @@ -790,20 +761,18 @@ static void ff_audio_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) return; } - memset(&this->context, 0, sizeof(this->context)); - avcodec_get_context_defaults(&this->context); + this->context = avcodec_alloc_context(); - this->context.sample_rate = this->audio_sample_rate = buf->decoder_info[1]; + this->context->sample_rate = this->audio_sample_rate = buf->decoder_info[1]; this->audio_bits = buf->decoder_info[2]; - this->context.channels = this->audio_channels = buf->decoder_info[3]; - this->context.block_align = audio_header->nBlockAlign; - this->context.bit_rate = audio_header->nAvgBytesPerSec * 8; - this->context.codec_id = codec->id; + this->context->channels = this->audio_channels = buf->decoder_info[3]; + this->context->block_align = audio_header->nBlockAlign; + this->context->bit_rate = audio_header->nAvgBytesPerSec * 8; + this->context->codec_id = codec->id; if( audio_header->cbSize > 0 ) { -printf ("extra data size = %d\n", audio_header->cbSize); - this->context.extradata = malloc(audio_header->cbSize); - this->context.extradata_size = audio_header->cbSize; - memcpy( this->context.extradata, + this->context->extradata = malloc(audio_header->cbSize); + this->context->extradata_size = audio_header->cbSize; + memcpy( this->context->extradata, (uint8_t *)audio_header + sizeof(xine_waveformatex), audio_header->cbSize ); } @@ -816,7 +785,7 @@ printf ("decode buffer (before) = %p\n", this->decode_buffer); this->decode_buffer = xine_xmalloc(100000); printf ("decode buffer (after) = %p\n", this->decode_buffer); - if (avcodec_open (&this->context, codec) < 0) { + if (avcodec_open (this->context, codec) < 0) { printf ("ffmpeg: couldn't open decoder\n"); return; } @@ -826,9 +795,6 @@ printf ("decode buffer (after) = %p\n", this->decode_buffer); return; } else if (this->decoder_ok) { -printf("buf->content = [%x %x %x %x]\n", -*((char *)buf->content+0),*((char *)buf->content+1),*((char *)buf->content+2),*((char *)buf->content+3)); - if (!this->output_open) { this->output_open = this->stream->audio_out->open(this->stream->audio_out, this->audio_bits, this->audio_sample_rate, @@ -856,7 +822,7 @@ printf (" *** time to decode audio\n"); offset = 0; while (this->size>0) { printf (" size = %d\n", this->size); - bytes_consumed = avcodec_decode_audio (&this->context, + bytes_consumed = avcodec_decode_audio (this->context, (INT16 *)this->decode_buffer, &decode_buffer_size, &this->buf[offset], @@ -942,8 +908,11 @@ static void ff_audio_dispose (audio_decoder_t *this_gen) { free(this->buf); free(this->decode_buffer); - if(this->context.extradata) - free(this->context.extradata); + if(this->context && this->context->extradata) + free(this->context->extradata); + + if(this->context) + free(this->context); free (this_gen); } |