[FFmpeg-devel] [PATCH 4/6] CrystalHD: Bring in h.264 parser to establish picture type.

Philip Langdale philipl at overt.org
Tue Apr 5 05:51:49 CEST 2011


As the hardware is unreliable, we will have to use the h.264 parser
to identify whether an input picture is a field or a frame. This
change loads the parser and extracts the picture type.

Signed-off-by: Philip Langdale <philipl at overt.org>
---
 configure              |    2 +-
 libavcodec/crystalhd.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index d2fe04c..5cccddc 100755
--- a/configure
+++ b/configure
@@ -1278,7 +1278,7 @@ h263_vaapi_hwaccel_select="vaapi h263_decoder"
 h263i_decoder_select="h263_decoder"
 h263p_encoder_select="h263_encoder"
 h264_decoder_select="golomb h264dsp h264pred"
-h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf"
+h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
 h264_dxva2_hwaccel_deps="dxva2api_h"
 h264_dxva2_hwaccel_select="dxva2 h264_decoder"
 h264_vaapi_hwaccel_select="vaapi"
diff --git a/libavcodec/crystalhd.c b/libavcodec/crystalhd.c
index f971056..69ea541 100644
--- a/libavcodec/crystalhd.c
+++ b/libavcodec/crystalhd.c
@@ -84,6 +84,7 @@
 #include <libcrystalhd/libcrystalhd_if.h>
 
 #include "avcodec.h"
+#include "h264.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
 
@@ -120,6 +121,8 @@ typedef struct {
     AVFrame pic;
     HANDLE dev;
 
+    AVCodecParserContext *parser;
+
     uint8_t is_70012;
     uint8_t *sps_pps_buf;
     uint32_t sps_pps_size;
@@ -316,6 +319,8 @@ static av_cold int uninit(AVCodecContext *avctx)
     DtsCloseDecoder(device);
     DtsDeviceClose(device);
 
+    av_parser_close(priv->parser);
+
     av_free(priv->sps_pps_buf);
 
     if (priv->pic.data[0])
@@ -478,6 +483,14 @@ static av_cold int init(AVCodecContext *avctx)
         goto fail;
     }
 
+    if (avctx->codec->id == CODEC_ID_H264) {
+        priv->parser = av_parser_init(avctx->codec->id);
+        if (!priv->parser)
+            av_log(avctx, AV_LOG_WARNING,
+                   "Cannot open the h.264 parser! Interlaced h.264 content "
+                   "will not be detected reliably.\n");
+        priv->parser->flags = PARSER_FLAG_COMPLETE_FRAMES;
+    }
     av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n");
 
     return 0;
@@ -737,11 +750,27 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *a
     CHDContext *priv   = avctx->priv_data;
     HANDLE dev         = priv->dev;
     int len            = avpkt->size;
+    uint8_t pic_type   = 0;
 
     av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n");
 
     if (len) {
         int32_t tx_free = (int32_t)DtsTxFreeSize(dev);
+
+        if (priv->parser) {
+            uint8_t *pout; /* dummy */
+            int psize;     /* dummy */
+            H264Context *h = priv->parser->priv_data;
+
+            ret = av_parser_parse2(priv->parser, avctx, &pout, &psize,
+                                   avpkt->data, len, avctx->pkt->pts,
+                                   avctx->pkt->dts, 0);
+            av_log(avctx, AV_LOG_VERBOSE,
+                   "CrystalHD: parser picture type %d\n",
+                   h->s.picture_structure);
+            pic_type = h->s.picture_structure;
+        }
+
         if (len < tx_free - 1024) {
             /*
              * Despite being notionally opaque, either libcrystalhd or
-- 
1.7.4.1



More information about the ffmpeg-devel mailing list