]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dnxhddec.c
Add stereo rematrixing support to the AC-3 encoders.
[ffmpeg] / libavcodec / dnxhddec.c
index 593ee95c3158d381889a2f140bb1bea69ccb4c19..67dd7fc60dc3dc9f55bafea3ba3b03ba37f42626 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * VC3/DNxHD decoder.
- * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>.
+ * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
  *
  * This file is part of FFmpeg.
  *
@@ -22,8 +22,9 @@
 //#define TRACE
 //#define DEBUG
 
+#include "libavcore/imgutils.h"
 #include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
 #include "dnxhddata.h"
 #include "dsputil.h"
 
@@ -39,8 +40,8 @@ typedef struct {
     VLC ac_vlc, dc_vlc, run_vlc;
     int last_dc[3];
     DSPContext dsp;
-    DECLARE_ALIGNED_16(DCTELEM, blocks[8][64]);
-    DECLARE_ALIGNED_8(ScanTable, scantable);
+    DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64];
+    ScanTable scantable;
     const CIDEntry *cid_table;
 } DNXHDContext;
 
@@ -55,6 +56,7 @@ static av_cold int dnxhd_decode_init(AVCodecContext *avctx)
     dsputil_init(&ctx->dsp, avctx);
     avctx->coded_frame = &ctx->picture;
     ctx->picture.type = FF_I_TYPE;
+    ctx->picture.key_frame = 1;
     return 0;
 }
 
@@ -126,12 +128,17 @@ static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_si
     ctx->mb_width = ctx->width>>4;
     ctx->mb_height = buf[0x16d];
 
-    if (ctx->mb_height > 68) {
-        av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big\n");
+    dprintf(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height);
+
+    if ((ctx->height+15)>>4 == ctx->mb_height && ctx->picture.interlaced_frame)
+        ctx->height <<= 1;
+
+    if (ctx->mb_height > 68 ||
+        (ctx->mb_height<<ctx->picture.interlaced_frame) > (ctx->height+15)>>4) {
+        av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height);
         return -1;
     }
 
-    dprintf(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height);
     for (i = 0; i < ctx->mb_height; i++) {
         ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2));
         dprintf(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]);
@@ -219,14 +226,12 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y)
     int dct_offset;
     int qscale, i;
 
-    ctx->dsp.clear_blocks(ctx->blocks[0]);
-    ctx->dsp.clear_blocks(ctx->blocks[2]); // FIXME change clear blocks to take block amount
-
     qscale = get_bits(&ctx->gb, 11);
     skip_bits1(&ctx->gb);
     //av_log(ctx->avctx, AV_LOG_DEBUG, "qscale %d\n", qscale);
 
     for (i = 0; i < 8; i++) {
+        ctx->dsp.clear_block(ctx->blocks[i]);
         dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale);
     }
 
@@ -280,8 +285,10 @@ static int dnxhd_decode_macroblocks(DNXHDContext *ctx, const uint8_t *buf, int b
 }
 
 static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
-                              const uint8_t *buf, int buf_size)
+                              AVPacket *avpkt)
 {
+    const uint8_t *buf = avpkt->data;
+    int buf_size = avpkt->size;
     DNXHDContext *ctx = avctx->priv_data;
     AVFrame *picture = data;
     int first_field = 1;
@@ -292,8 +299,15 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0)
         return -1;
 
+    if ((avctx->width || avctx->height) &&
+        (ctx->width != avctx->width || ctx->height != avctx->height)) {
+        av_log(avctx, AV_LOG_WARNING, "frame size changed: %dx%d -> %dx%d\n",
+               avctx->width, avctx->height, ctx->width, ctx->height);
+        first_field = 1;
+    }
+
     avctx->pix_fmt = PIX_FMT_YUV422P;
-    if (avcodec_check_dimensions(avctx, ctx->width, ctx->height))
+    if (av_image_check_size(ctx->width, ctx->height, 0, avctx))
         return -1;
     avcodec_set_dimensions(avctx, ctx->width, ctx->height);
 
@@ -334,7 +348,7 @@ static av_cold int dnxhd_decode_close(AVCodecContext *avctx)
 
 AVCodec dnxhd_decoder = {
     "dnxhd",
-    CODEC_TYPE_VIDEO,
+    AVMEDIA_TYPE_VIDEO,
     CODEC_ID_DNXHD,
     sizeof(DNXHDContext),
     dnxhd_decode_init,
@@ -342,5 +356,5 @@ AVCodec dnxhd_decoder = {
     dnxhd_decode_close,
     dnxhd_decode_frame,
     CODEC_CAP_DR1,
-    .long_name = "VC3/DNxHD",
+    .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"),
 };