]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/crystalhd.c
DV: check coded_width/height instead of width/height.
[ffmpeg] / libavcodec / crystalhd.c
index 833b8d97faaac064a4b1bca694cd744ed1855964..2d10aa9ee720e85de5ea2c76cb70e6d79e32a070 100644 (file)
@@ -124,6 +124,9 @@ typedef struct {
     AVFrame pic;
     HANDLE dev;
 
+    uint8_t *orig_extradata;
+    uint32_t orig_extradata_size;
+
     AVBitStreamFilterContext *bsfc;
     AVCodecParserContext *parser;
 
@@ -338,6 +341,19 @@ static av_cold int uninit(AVCodecContext *avctx)
     DtsCloseDecoder(device);
     DtsDeviceClose(device);
 
+    /*
+     * Restore original extradata, so that if the decoder is
+     * reinitialised, the bitstream detection and filtering
+     * will work as expected.
+     */
+    if (priv->orig_extradata) {
+        av_free(avctx->extradata);
+        avctx->extradata = priv->orig_extradata;
+        avctx->extradata_size = priv->orig_extradata_size;
+        priv->orig_extradata = NULL;
+        priv->orig_extradata_size = 0;
+    }
+
     av_parser_close(priv->parser);
     if (priv->bsfc) {
         av_bitstream_filter_close(priv->bsfc);
@@ -402,6 +418,16 @@ static av_cold int init(AVCodecContext *avctx)
             uint8_t *dummy_p;
             int dummy_int;
 
+            /* Back up the extradata so it can be restored at close time. */
+            priv->orig_extradata = av_malloc(avctx->extradata_size);
+            if (!priv->orig_extradata) {
+                av_log(avctx, AV_LOG_ERROR,
+                       "Failed to allocate copy of extradata\n");
+                return AVERROR(ENOMEM);
+            }
+            priv->orig_extradata_size = avctx->extradata_size;
+            memcpy(priv->orig_extradata, avctx->extradata, avctx->extradata_size);
+
             priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb");
             if (!priv->bsfc) {
                 av_log(avctx, AV_LOG_ERROR,
@@ -512,7 +538,7 @@ static inline CopyRet copy_frame(AVCodecContext *avctx,
                                  void *data, int *data_size)
 {
     BC_STATUS ret;
-    BC_DTS_STATUS decoder_status;
+    BC_DTS_STATUS decoder_status = { 0, };
     uint8_t trust_interlaced;
     uint8_t interlaced;
 
@@ -786,7 +812,7 @@ static inline CopyRet receive_frame(AVCodecContext *avctx,
 static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
 {
     BC_STATUS ret;
-    BC_DTS_STATUS decoder_status;
+    BC_DTS_STATUS decoder_status = { 0, };
     CopyRet rec_ret;
     CHDContext *priv   = avctx->priv_data;
     HANDLE dev         = priv->dev;