#include "libavutil/attributes.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
+#include "libavutil/mem_internal.h"
#define BITSTREAM_READER_LE
#include "avcodec.h"
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
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;
*/
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);
}
/**
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);
}
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);
}
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);
}
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;
}
}
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);
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;
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;
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) {
.decode = decode_frame,
.flush = flush,
.capabilities = AV_CODEC_CAP_DR1,
+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
};