From 081a3b484429a4f0db641432f6bf2fb8850da838 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Mon, 20 Sep 2004 12:29:03 +0000 Subject: [PATCH] ext/ffmpeg/gstffmpegcodecmap.c: WMV extradata (make #152798 work). J-frames are only available in the bitstream if th... Original commit message from CVS: * ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_codecid_to_caps), (gst_ffmpeg_caps_with_codecid): WMV extradata (make #152798 work). J-frames are only available in the bitstream if the J-frame bit has been set in the extradata. If not (or if extradata is not provided), the movie won't play. * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_close), (gst_ffmpegdec_connect), (gst_ffmpegdec_chain): Only close ffmpeg if privdata was allocated (else it segfaults). Autodetect encoding bugs and workaround it. Don't copy data if decoding failed. * ext/ffmpeg/gstffmpegdemux.c: (gst_ffmpegdemux_loop): Use read_frame() instead of read_packet() which is obsolete. --- ChangeLog | 15 +++++++++++++++ common | 2 +- ext/ffmpeg/gstffmpegcodecmap.c | 10 +++++----- ext/ffmpeg/gstffmpegdec.c | 10 ++++++++-- ext/ffmpeg/gstffmpegdemux.c | 2 +- 5 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8134d5e00..52560e14c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-09-20 Ronald S. Bultje + + * ext/ffmpeg/gstffmpegcodecmap.c: (gst_ffmpeg_codecid_to_caps), + (gst_ffmpeg_caps_with_codecid): + WMV extradata (make #152798 work). J-frames are only available + in the bitstream if the J-frame bit has been set in the extradata. + If not (or if extradata is not provided), the movie won't play. + * ext/ffmpeg/gstffmpegdec.c: (gst_ffmpegdec_close), + (gst_ffmpegdec_connect), (gst_ffmpegdec_chain): + Only close ffmpeg if privdata was allocated (else it segfaults). + Autodetect encoding bugs and workaround it. Don't copy data if + decoding failed. + * ext/ffmpeg/gstffmpegdemux.c: (gst_ffmpegdemux_loop): + Use read_frame() instead of read_packet() which is obsolete. + 2004-09-16 Iain * ext/ffmpeg/gstffmpegmux.c (gst_ffmpegmux_register): Free name fix diff --git a/common b/common index 5ec931d243..ded6dc5186 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 5ec931d243c53ddda5b2cbb9a2c21ce89747bcb4 +Subproject commit ded6dc5186cb7f8c64cb06a8591b9f787122c6f1 diff --git a/ext/ffmpeg/gstffmpegcodecmap.c b/ext/ffmpeg/gstffmpegcodecmap.c index 018ced65f7..00dd05c7df 100644 --- a/ext/ffmpeg/gstffmpegcodecmap.c +++ b/ext/ffmpeg/gstffmpegcodecmap.c @@ -295,7 +295,7 @@ gst_ffmpeg_codecid_to_caps (enum CodecID codec_id, do { gint version = (codec_id == CODEC_ID_WMV1) ? 1 : 2; - if (context) + if (context && context->extradata_size) { GstBuffer *buffer; @@ -343,7 +343,7 @@ gst_ffmpeg_codecid_to_caps (enum CodecID codec_id, do { gint version = (codec_id == CODEC_ID_WMAV1) ? 1 : 2; - if (context) + if (context && context->extradata_size) { GstBuffer *buffer; @@ -355,9 +355,7 @@ gst_ffmpeg_codecid_to_caps (enum CodecID codec_id, "codec_data", GST_TYPE_BUFFER, buffer, "block_align", G_TYPE_INT, context->block_align, "bitrate", G_TYPE_INT, context->bit_rate, NULL); - } - else - { + } else { caps = GST_FF_AUD_CAPS_NEW ("audio/x-wma", "wmaversion", G_TYPE_INT, version, "block_align", GST_TYPE_INT_RANGE, 0, G_MAXINT, @@ -1167,6 +1165,8 @@ gst_ffmpeg_caps_with_codecid (enum CodecID codec_id, case CODEC_ID_WMAV1: case CODEC_ID_WMAV2: + case CODEC_ID_WMV1: + case CODEC_ID_WMV2: do { const GValue *value; const GstBuffer *buf; diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c index d79d0ed711..9efc9af9f2 100644 --- a/ext/ffmpeg/gstffmpegdec.c +++ b/ext/ffmpeg/gstffmpegdec.c @@ -219,7 +219,8 @@ gst_ffmpegdec_close (GstFFMpegDec *ffmpegdec) if (!ffmpegdec->opened) return; - avcodec_close (ffmpegdec->context); + if (ffmpegdec->context->priv_data) + avcodec_close (ffmpegdec->context); ffmpegdec->opened = FALSE; if (ffmpegdec->context->palctrl) { @@ -294,6 +295,9 @@ gst_ffmpegdec_connect (GstPad * pad, const GstCaps * caps) /* do *not* draw edges */ ffmpegdec->context->flags |= CODEC_FLAG_EMU_EDGE; + /* workaround encoder bugs */ + ffmpegdec->context->workaround_bugs |= FF_BUG_AUTODETECT; + /* open codec - we don't select an output pix_fmt yet, * simply because we don't know! We only get it * during playback... */ @@ -395,9 +399,11 @@ gst_ffmpegdec_chain (GstPad * pad, GstData * _data) data = GST_BUFFER_DATA (inbuf); size = GST_BUFFER_SIZE (inbuf); } + len = avcodec_decode_video (ffmpegdec->context, ffmpegdec->picture, &have_data, data, size); - if (have_data) { + + if (len >= 0 && have_data) { /* libavcodec constantly crashes on stupid buffer allocation * errors inside. This drives me crazy, so we let it allocate * it's own buffers and copy to our own buffer afterwards... */ diff --git a/ext/ffmpeg/gstffmpegdemux.c b/ext/ffmpeg/gstffmpegdemux.c index 195145ca6f..cfd05cda4f 100644 --- a/ext/ffmpeg/gstffmpegdemux.c +++ b/ext/ffmpeg/gstffmpegdemux.c @@ -573,7 +573,7 @@ gst_ffmpegdemux_loop (GstElement * element) } /* read a package */ - res = av_read_packet (demux->context, &pkt); + res = av_read_frame (demux->context, &pkt); if (res < 0) { #if 0 /* This doesn't work - FIXME */