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

Philip Langdale philipl at overt.org
Sat Mar 26 18:50:47 CET 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 |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 42b5862..cd85ca1 100755
--- a/configure
+++ b/configure
@@ -1276,7 +1276,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..849fabe 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,13 @@ 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");
+    }
     av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n");
 
     return 0;
@@ -737,11 +749,29 @@ 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 = NULL;
+            int psize = len;
+            H264Context *h = priv->parser->priv_data;
+
+            while (psize) {
+                ret = av_parser_parse2(priv->parser, avctx, &pout, &psize,
+                                       avpkt->data, len, avctx->pkt->pts,
+                                       avctx->pkt->dts, len - psize);
+            }
+            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.1




More information about the ffmpeg-devel mailing list