]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/bink.c
avformat/avio: Add Metacube support
[ffmpeg] / libavcodec / bink.c
index 5bb3955f93e59aeccce81d718cd3e424fe89fb70..36d1ab6c0a9472136e88d725056d9d831f229305 100644 (file)
@@ -23,6 +23,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
 
 #define BITSTREAM_READER_LE
 #include "avcodec.h"
@@ -114,7 +115,7 @@ typedef struct Bundle {
 typedef struct BinkContext {
     AVCodecContext *avctx;
     BlockDSPContext bdsp;
-    HpelDSPContext hdsp;
+    op_pixels_func put_pixels_tab;
     BinkDSPContext binkdsp;
     AVFrame        *last;
     int            version;              ///< internal Bink file version
@@ -178,17 +179,20 @@ static void init_lengths(BinkContext *c, int width, int bw)
 static av_cold int init_bundles(BinkContext *c)
 {
     int bw, bh, blocks;
+    uint8_t *tmp;
     int i;
 
     bw = (c->avctx->width  + 7) >> 3;
     bh = (c->avctx->height + 7) >> 3;
     blocks = bw * bh;
 
+    tmp = av_calloc(blocks, 64 * BINKB_NB_SRC);
+    if (!tmp)
+        return AVERROR(ENOMEM);
     for (i = 0; i < BINKB_NB_SRC; i++) {
-        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;
+        c->bundle[i].data     = tmp;
+        tmp                  += blocks * 64;
+        c->bundle[i].data_end = tmp;
     }
 
     return 0;
@@ -201,9 +205,7 @@ static av_cold int init_bundles(BinkContext *c)
  */
 static av_cold void free_bundles(BinkContext *c)
 {
-    int i;
-    for (i = 0; i < BINKB_NB_SRC; i++)
-        av_freep(&c->bundle[i].data);
+    av_freep(&c->bundle[0].data);
 }
 
 /**
@@ -926,7 +928,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 if (ref < ref_start || ref + 8*stride > ref_end) {
                     av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
                 } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
-                    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+                    c->put_pixels_tab(dst, ref, stride, 8);
                 } else {
                     put_pixels8x8_overlapped(dst, ref, stride);
                 }
@@ -942,7 +944,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 if (ref < ref_start || ref + 8 * stride > ref_end) {
                     av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
                 } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
-                    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+                    c->put_pixels_tab(dst, ref, stride, 8);
                 } else {
                     put_pixels8x8_overlapped(dst, ref, stride);
                 }
@@ -974,7 +976,7 @@ static int binkb_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
                 if (ref < ref_start || ref + 8 * stride > ref_end) {
                     av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n");
                 } else if (ref + 8*stride < dst || ref >= dst + 8*stride) {
-                    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+                    c->put_pixels_tab(dst, ref, stride, 8);
                 } else {
                     put_pixels8x8_overlapped(dst, ref, stride);
                 }
@@ -1009,7 +1011,7 @@ static int bink_put_pixels(BinkContext *c,
                xoff, yoff);
         return AVERROR_INVALIDDATA;
     }
-    c->hdsp.put_pixels_tab[1][0](dst, ref, stride, 8);
+    c->put_pixels_tab(dst, ref, stride, 8);
 
     return 0;
 }
@@ -1092,7 +1094,7 @@ static int bink_decode_plane(BinkContext *c, AVFrame *frame, GetBitContext *gb,
             }
             switch (blk) {
             case SKIP_BLOCK:
-                c->hdsp.put_pixels_tab[1][0](dst, prev, stride, 8);
+                c->put_pixels_tab(dst, prev, stride, 8);
                 break;
             case SCALED_BLOCK:
                 blk = get_value(c, BINK_SRC_SUB_BLOCK_TYPES);
@@ -1261,7 +1263,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
         if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
             return ret;
     } else {
-        if ((ret = ff_reget_buffer(avctx, c->last)) < 0)
+        if ((ret = ff_reget_buffer(avctx, c->last, 0)) < 0)
             return ret;
         if ((ret = av_frame_ref(frame, c->last)) < 0)
             return ret;
@@ -1344,6 +1346,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     BinkContext * const c = avctx->priv_data;
     static VLC_TYPE table[16 * 128][2];
     static int binkb_initialised = 0;
+    HpelDSPContext hdsp;
     int i, ret;
     int flags;
 
@@ -1378,13 +1381,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
     avctx->color_range = c->version == 'k' ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
 
     ff_blockdsp_init(&c->bdsp, avctx);
-    ff_hpeldsp_init(&c->hdsp, avctx->flags);
+    ff_hpeldsp_init(&hdsp, avctx->flags);
+    c->put_pixels_tab = hdsp.put_pixels_tab[1][0];
     ff_binkdsp_init(&c->binkdsp);
 
-    if ((ret = init_bundles(c)) < 0) {
-        free_bundles(c);
+    if ((ret = init_bundles(c)) < 0)
         return ret;
-    }
 
     if (c->version == 'b') {
         if (!binkb_initialised) {
@@ -1413,7 +1415,7 @@ static void flush(AVCodecContext *avctx)
     c->frame_num = 0;
 }
 
-AVCodec ff_bink_decoder = {
+const AVCodec ff_bink_decoder = {
     .name           = "binkvideo",
     .long_name      = NULL_IF_CONFIG_SMALL("Bink video"),
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -1424,4 +1426,5 @@ AVCodec ff_bink_decoder = {
     .decode         = decode_frame,
     .flush          = flush,
     .capabilities   = AV_CODEC_CAP_DR1,
+    .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
 };