From 24d918b7a371994455470b2bd90c04c6e1ee7d24 Mon Sep 17 00:00:00 2001 From: gb Date: Mon, 3 May 2010 16:17:51 +0000 Subject: [PATCH] Try to improve heuristics to use an AVCodecContextParser. --- gst-libs/gst/vaapi/gstvaapidecoder_ffmpeg.c | 41 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_ffmpeg.c b/gst-libs/gst/vaapi/gstvaapidecoder_ffmpeg.c index a99ef5c..5b32e2c 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_ffmpeg.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_ffmpeg.c @@ -315,7 +315,7 @@ gst_vaapi_decoder_ffmpeg_open(GstVaapiDecoderFfmpeg *ffdecoder, GstBuffer *buffe GstVaapiCodec codec = GST_VAAPI_DECODER_CODEC(ffdecoder); enum CodecID codec_id; AVCodec *ffcodec; - gboolean parser_is_needed; + gboolean try_parser, need_parser; int ret; gst_vaapi_decoder_ffmpeg_close(ffdecoder); @@ -339,36 +339,45 @@ gst_vaapi_decoder_ffmpeg_open(GstVaapiDecoderFfmpeg *ffdecoder, GstBuffer *buffe case CODEC_ID_H264: /* For AVC1 formats, sequence headers are in extradata and input encoded buffers represent the whole NAL unit */ - parser_is_needed = priv->avctx->extradata_size == 0; + try_parser = priv->avctx->extradata_size == 0; + need_parser = try_parser; break; case CODEC_ID_WMV3: /* There is no WMV3 parser in FFmpeg */ - parser_is_needed = FALSE; + try_parser = FALSE; + need_parser = FALSE; break; case CODEC_ID_VC1: /* For VC-1, sequence headers ae in extradata and input encoded buffers represent the whole slice */ - parser_is_needed = FALSE; + try_parser = priv->avctx->extradata_size == 0; + need_parser = FALSE; break; default: - parser_is_needed = TRUE; + try_parser = TRUE; + need_parser = TRUE; break; } - if (parser_is_needed) { + if (try_parser) { priv->pctx = av_parser_init(codec_id); - if (!priv->pctx) + if (!priv->pctx && need_parser) return FALSE; + } - /* XXX: av_find_stream_info() does this and some codecs really - want hard an extradata buffer for initialization (e.g. VC-1) */ - if (!priv->avctx->extradata && priv->pctx->parser->split) { - const guchar *buf = GST_BUFFER_DATA(buffer); - guint buf_size = GST_BUFFER_SIZE(buffer); - buf_size = priv->pctx->parser->split(priv->avctx, buf, buf_size); - if (buf_size > 0 && !set_codec_data(priv->avctx, buf, buf_size)) - return FALSE; - } + /* XXX: av_find_stream_info() does this and some codecs really + want hard an extradata buffer for initialization (e.g. VC-1) */ + if (!priv->avctx->extradata && priv->pctx && priv->pctx->parser->split) { + const guchar *buf = GST_BUFFER_DATA(buffer); + guint buf_size = GST_BUFFER_SIZE(buffer); + buf_size = priv->pctx->parser->split(priv->avctx, buf, buf_size); + if (buf_size > 0 && !set_codec_data(priv->avctx, buf, buf_size)) + return FALSE; + } + + if (priv->pctx && !need_parser) { + av_parser_close(priv->pctx); + priv->pctx = NULL; } /* Use size information from the demuxer, whenever available */ -- 2.7.4