avcodec/wmaprodec: cleanup extradata dumping
[ffmpeg.git] / libavcodec / bink.c
index 8f8a036..cc55870 100644 (file)
 #include "libavutil/attributes.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+
+#define BITSTREAM_READER_LE
 #include "avcodec.h"
-#include "dsputil.h"
 #include "binkdata.h"
 #include "binkdsp.h"
+#include "blockdsp.h"
+#include "get_bits.h"
 #include "hpeldsp.h"
 #include "internal.h"
 #include "mathops.h"
 
-#define BITSTREAM_READER_LE
-#include "get_bits.h"
-
 #define BINK_FLAG_ALPHA 0x00100000
 #define BINK_FLAG_GRAY  0x00020000
 
@@ -113,9 +113,9 @@ typedef struct Bundle {
  */
 typedef struct BinkContext {
     AVCodecContext *avctx;
-    DSPContext     dsp;
+    BlockDSPContext bdsp;
     HpelDSPContext hdsp;
-    BinkDSPContext bdsp;
+    BinkDSPContext binkdsp;
     AVFrame        *last;
     int            version;              ///< internal Bink file version
     int            has_alpha;
@@ -185,7 +185,7 @@ static av_cold int init_bundles(BinkContext *c)
     blocks = bw * bh;
 
     for (i = 0; i < BINKB_NB_SRC; i++) {
-        c->bundle[i].data = av_malloc(blocks * 64);
+        c->bundle[i].data = av_mallocz(blocks * 64);
         if (!c->bundle[i].data)
             return AVERROR(ENOMEM);
         c->bundle[i].data_end = c->bundle[i].data + blocks * 64;
@@ -873,7 +873,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 dctblock[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC);
                 qp = binkb_get_value(c, BINKB_SRC_INTRA_Q);
                 read_dct_coeffs(gb, dctblock, bink_scan, (const int32_t (*)[64])binkb_intra_quant, qp);
-                c->bdsp.idct_put(dst, stride, dctblock);
+                c->binkdsp.idct_put(dst, stride, dctblock);
                 break;
             case 3:
                 xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
@@ -886,10 +886,10 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 } else {
                     put_pixels8x8_overlapped(dst, ref, stride);
                 }
-                c->dsp.clear_block(block);
+                c->bdsp.clear_block(block);
                 v = binkb_get_value(c, BINKB_SRC_INTER_COEFS);
                 read_residue(gb, block, v);
-                c->dsp.add_pixels8(dst, block, stride);
+                c->binkdsp.add_pixels8(dst, block, stride);
                 break;
             case 4:
                 xoff = binkb_get_value(c, BINKB_SRC_X_OFF);
@@ -906,11 +906,11 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 dctblock[0] = binkb_get_value(c, BINKB_SRC_INTER_DC);
                 qp = binkb_get_value(c, BINKB_SRC_INTER_Q);
                 read_dct_coeffs(gb, dctblock, bink_scan, (const int32_t (*)[64])binkb_inter_quant, qp);
-                c->bdsp.idct_add(dst, stride, dctblock);
+                c->binkdsp.idct_add(dst, stride, dctblock);
                 break;
             case 5:
                 v = binkb_get_value(c, BINKB_SRC_COLORS);
-                c->dsp.fill_block_tab[1](dst, v, stride, 8);
+                c->bdsp.fill_block_tab[1](dst, v, stride, 8);
                 break;
             case 6:
                 for (i = 0; i < 2; i++)
@@ -950,15 +950,32 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
     return 0;
 }
 
+static int bink_put_pixels(BinkContext *c,
+                           uint8_t *dst, uint8_t *prev, int stride,
+                           uint8_t *ref_start,
+                           uint8_t *ref_end)
+{
+    int xoff     = get_value(c, BINK_SRC_X_OFF);
+    int yoff     = get_value(c, BINK_SRC_Y_OFF);
+    uint8_t *ref = prev + xoff + yoff * stride;
+    if (ref < ref_start || ref > ref_end) {
+        av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
+               xoff, yoff);
+        return AVERROR_INVALIDDATA;
+    }
+    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+
+    return 0;
+}
+
 static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                              int plane_idx, int is_chroma)
 {
     int blk, ret;
     int i, j, bx, by;
-    uint8_t *dst, *prev, *ref, *ref_start, *ref_end;
+    uint8_t *dst, *prev, *ref_start, *ref_end;
     int v, col[2];
     const uint8_t *scan;
-    int xoff, yoff;
     LOCAL_ALIGNED_16(int16_t, block, [64]);
     LOCAL_ALIGNED_16(uint8_t, ublock, [64]);
     LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
@@ -1049,11 +1066,11 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                     memset(dctblock, 0, sizeof(*dctblock) * 64);
                     dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
                     read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
-                    c->bdsp.idct_put(ublock, 8, dctblock);
+                    c->binkdsp.idct_put(ublock, 8, dctblock);
                     break;
                 case FILL_BLOCK:
                     v = get_value(c, BINK_SRC_COLORS);
-                    c->dsp.fill_block_tab[0](dst, v, stride, 16);
+                    c->bdsp.fill_block_tab[0](dst, v, stride, 16);
                     break;
                 case PATTERN_BLOCK:
                     for (i = 0; i < 2; i++)
@@ -1074,21 +1091,16 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                     return AVERROR_INVALIDDATA;
                 }
                 if (blk != FILL_BLOCK)
-                c->bdsp.scale_block(ublock, dst, stride);
+                c->binkdsp.scale_block(ublock, dst, stride);
                 bx++;
                 dst  += 8;
                 prev += 8;
                 break;
             case MOTION_BLOCK:
-                xoff = get_value(c, BINK_SRC_X_OFF);
-                yoff = get_value(c, BINK_SRC_Y_OFF);
-                ref = prev + xoff + yoff * stride;
-                if (ref < ref_start || ref > ref_end) {
-                    av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
-                           bx*8 + xoff, by*8 + yoff);
-                    return AVERROR_INVALIDDATA;
-                }
-                c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+                ret = bink_put_pixels(c, dst, prev, stride,
+                                      ref_start, ref_end);
+                if (ret < 0)
+                    return ret;
                 break;
             case RUN_BLOCK:
                 scan = bink_patterns[get_bits(gb, 4)];
@@ -1114,44 +1126,34 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                     dst[coordmap[*scan++]] = get_value(c, BINK_SRC_COLORS);
                 break;
             case RESIDUE_BLOCK:
-                xoff = get_value(c, BINK_SRC_X_OFF);
-                yoff = get_value(c, BINK_SRC_Y_OFF);
-                ref = prev + xoff + yoff * stride;
-                if (ref < ref_start || ref > ref_end) {
-                    av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
-                           bx*8 + xoff, by*8 + yoff);
-                    return AVERROR_INVALIDDATA;
-                }
-                c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
-                c->dsp.clear_block(block);
+                ret = bink_put_pixels(c, dst, prev, stride,
+                                      ref_start, ref_end);
+                if (ret < 0)
+                    return ret;
+                c->bdsp.clear_block(block);
                 v = get_bits(gb, 7);
                 read_residue(gb, block, v);
-                c->dsp.add_pixels8(dst, block, stride);
+                c->binkdsp.add_pixels8(dst, block, stride);
                 break;
             case INTRA_BLOCK:
                 memset(dctblock, 0, sizeof(*dctblock) * 64);
                 dctblock[0] = get_value(c, BINK_SRC_INTRA_DC);
                 read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1);
-                c->bdsp.idct_put(dst, stride, dctblock);
+                c->binkdsp.idct_put(dst, stride, dctblock);
                 break;
             case FILL_BLOCK:
                 v = get_value(c, BINK_SRC_COLORS);
-                c->dsp.fill_block_tab[1](dst, v, stride, 8);
+                c->bdsp.fill_block_tab[1](dst, v, stride, 8);
                 break;
             case INTER_BLOCK:
-                xoff = get_value(c, BINK_SRC_X_OFF);
-                yoff = get_value(c, BINK_SRC_Y_OFF);
-                ref = prev + xoff + yoff * stride;
-                if (ref < ref_start || ref > ref_end) {
-                    av_log(c->avctx, AV_LOG_ERROR, "Copy out of bounds @%d, %d\n",
-                           bx*8 + xoff, by*8 + yoff);
-                    return -1;
-                }
-                c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+                ret = bink_put_pixels(c, dst, prev, stride,
+                                      ref_start, ref_end);
+                if (ret < 0)
+                    return ret;
                 memset(dctblock, 0, sizeof(*dctblock) * 64);
                 dctblock[0] = get_value(c, BINK_SRC_INTER_DC);
                 read_dct_coeffs(gb, dctblock, bink_scan, bink_inter_quant, -1);
-                c->bdsp.idct_add(dst, stride, dctblock);
+                c->binkdsp.idct_add(dst, stride, dctblock);
                 break;
             case PATTERN_BLOCK:
                 for (i = 0; i < 2; i++)
@@ -1238,7 +1240,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
 }
 
 /**
- * Caclulate quantization tables for version b
+ * Calculate quantization tables for version b
  */
 static av_cold void binkb_calc_quant(void)
 {
@@ -1306,9 +1308,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     avctx->pix_fmt = c->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P;
 
-    ff_dsputil_init(&c->dsp, avctx);
+    ff_blockdsp_init(&c->bdsp, avctx);
     ff_hpeldsp_init(&c->hdsp, avctx->flags);
-    ff_binkdsp_init(&c->bdsp);
+    ff_binkdsp_init(&c->binkdsp);
 
     if ((ret = init_bundles(c)) < 0) {
         free_bundles(c);
@@ -1352,5 +1354,5 @@ AVCodec ff_bink_decoder = {
     .close          = decode_end,
     .decode         = decode_frame,
     .flush          = flush,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = AV_CODEC_CAP_DR1,
 };