|
|
|
@ -112,7 +112,7 @@ typedef struct BinkContext { |
|
|
|
|
AVCodecContext *avctx; |
|
|
|
|
DSPContext dsp; |
|
|
|
|
BinkDSPContext bdsp; |
|
|
|
|
AVFrame pic, last; |
|
|
|
|
AVFrame *pic, *last; |
|
|
|
|
int version; ///< internal Bink file version
|
|
|
|
|
int has_alpha; |
|
|
|
|
int swap_planes; |
|
|
|
@ -313,7 +313,7 @@ static int read_runs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) |
|
|
|
|
dec_end = b->cur_dec + t; |
|
|
|
|
if (dec_end > b->data_end) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Run value went out of bounds\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (get_bits1(gb)) { |
|
|
|
|
v = get_bits(gb, 4); |
|
|
|
@ -335,7 +335,7 @@ static int read_motion_values(AVCodecContext *avctx, GetBitContext *gb, Bundle * |
|
|
|
|
dec_end = b->cur_dec + t; |
|
|
|
|
if (dec_end > b->data_end) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many motion values\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (get_bits1(gb)) { |
|
|
|
|
v = get_bits(gb, 4); |
|
|
|
@ -370,7 +370,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) |
|
|
|
|
dec_end = b->cur_dec + t; |
|
|
|
|
if (dec_end > b->data_end) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many block type values\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (get_bits1(gb)) { |
|
|
|
|
v = get_bits(gb, 4); |
|
|
|
@ -386,7 +386,7 @@ static int read_block_types(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) |
|
|
|
|
int run = bink_rlelens[v - 12]; |
|
|
|
|
|
|
|
|
|
if (dec_end - b->cur_dec < run) |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
memset(b->cur_dec, last, run); |
|
|
|
|
b->cur_dec += run; |
|
|
|
|
} |
|
|
|
@ -404,7 +404,7 @@ static int read_patterns(AVCodecContext *avctx, GetBitContext *gb, Bundle *b) |
|
|
|
|
dec_end = b->cur_dec + t; |
|
|
|
|
if (dec_end > b->data_end) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Too many pattern values\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
while (b->cur_dec < dec_end) { |
|
|
|
|
v = GET_HUFF(gb, b->tree); |
|
|
|
@ -424,7 +424,7 @@ static int read_colors(GetBitContext *gb, Bundle *b, BinkContext *c) |
|
|
|
|
dec_end = b->cur_dec + t; |
|
|
|
|
if (dec_end > b->data_end) { |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Too many color values\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (get_bits1(gb)) { |
|
|
|
|
c->col_lastval = GET_HUFF(gb, c->col_high[c->col_lastval]); |
|
|
|
@ -470,13 +470,13 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, |
|
|
|
|
v = (v ^ sign) - sign; |
|
|
|
|
} |
|
|
|
|
if (dst_end - dst < 1) |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
*dst++ = v; |
|
|
|
|
len--; |
|
|
|
|
for (i = 0; i < len; i += 8) { |
|
|
|
|
len2 = FFMIN(len - i, 8); |
|
|
|
|
if (dst_end - dst < len2) |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
bsize = get_bits(gb, 4); |
|
|
|
|
if (bsize) { |
|
|
|
|
for (j = 0; j < len2; j++) { |
|
|
|
@ -489,7 +489,7 @@ static int read_dcs(AVCodecContext *avctx, GetBitContext *gb, Bundle *b, |
|
|
|
|
*dst++ = v; |
|
|
|
|
if (v < -32768 || v > 32767) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "DC value went out of bounds: %d\n", v); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -545,7 +545,7 @@ static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num) |
|
|
|
|
|
|
|
|
|
CHECK_READ_VAL(gb, b, len); |
|
|
|
|
if (b->data_end - b->cur_dec < len * (1 + (bits > 8))) |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
if (bits <= 8) { |
|
|
|
|
if (!issigned) { |
|
|
|
|
for (i = 0; i < len; i++) |
|
|
|
@ -798,7 +798,7 @@ static inline void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stri |
|
|
|
|
static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
int is_key, int is_chroma) |
|
|
|
|
{ |
|
|
|
|
int blk; |
|
|
|
|
int blk, ret; |
|
|
|
|
int i, j, bx, by; |
|
|
|
|
uint8_t *dst, *ref, *ref_start, *ref_end; |
|
|
|
|
int v, col[2]; |
|
|
|
@ -810,24 +810,24 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
int ybias = is_key ? -15 : 0; |
|
|
|
|
int qp; |
|
|
|
|
|
|
|
|
|
const int stride = c->pic.linesize[plane_idx]; |
|
|
|
|
const int stride = c->pic->linesize[plane_idx]; |
|
|
|
|
int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; |
|
|
|
|
int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; |
|
|
|
|
|
|
|
|
|
binkb_init_bundles(c); |
|
|
|
|
ref_start = c->pic.data[plane_idx]; |
|
|
|
|
ref_end = c->pic.data[plane_idx] + (bh * c->pic.linesize[plane_idx] + bw) * 8; |
|
|
|
|
ref_start = c->pic->data[plane_idx]; |
|
|
|
|
ref_end = c->pic->data[plane_idx] + (bh * c->pic->linesize[plane_idx] + bw) * 8; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++) |
|
|
|
|
coordmap[i] = (i & 7) + (i >> 3) * stride; |
|
|
|
|
|
|
|
|
|
for (by = 0; by < bh; by++) { |
|
|
|
|
for (i = 0; i < BINKB_NB_SRC; i++) { |
|
|
|
|
if (binkb_read_bundle(c, gb, i) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if ((ret = binkb_read_bundle(c, gb, i)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dst = c->pic.data[plane_idx] + 8*by*stride; |
|
|
|
|
dst = c->pic->data[plane_idx] + 8*by*stride; |
|
|
|
|
for (bx = 0; bx < bw; bx++, dst += 8) { |
|
|
|
|
blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES); |
|
|
|
|
switch (blk) { |
|
|
|
@ -845,7 +845,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
i += run; |
|
|
|
|
if (i > 64) { |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (mode) { |
|
|
|
|
v = binkb_get_value(c, BINKB_SRC_COLORS); |
|
|
|
@ -931,7 +931,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -944,7 +944,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
int is_chroma) |
|
|
|
|
{ |
|
|
|
|
int blk; |
|
|
|
|
int blk, ret; |
|
|
|
|
int i, j, bx, by; |
|
|
|
|
uint8_t *dst, *prev, *ref, *ref_start, *ref_end; |
|
|
|
|
int v, col[2]; |
|
|
|
@ -955,7 +955,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
LOCAL_ALIGNED_16(int32_t, dctblock, [64]); |
|
|
|
|
int coordmap[64]; |
|
|
|
|
|
|
|
|
|
const int stride = c->pic.linesize[plane_idx]; |
|
|
|
|
const int stride = c->pic->linesize[plane_idx]; |
|
|
|
|
int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; |
|
|
|
|
int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; |
|
|
|
|
int width = c->avctx->width >> is_chroma; |
|
|
|
@ -964,39 +964,39 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
for (i = 0; i < BINK_NB_SRC; i++) |
|
|
|
|
read_bundle(gb, c, i); |
|
|
|
|
|
|
|
|
|
ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx] |
|
|
|
|
: c->pic.data[plane_idx]; |
|
|
|
|
ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx] |
|
|
|
|
: c->pic->data[plane_idx]; |
|
|
|
|
ref_end = ref_start |
|
|
|
|
+ (bw - 1 + c->last.linesize[plane_idx] * (bh - 1)) * 8; |
|
|
|
|
+ (bw - 1 + c->last->linesize[plane_idx] * (bh - 1)) * 8; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < 64; i++) |
|
|
|
|
coordmap[i] = (i & 7) + (i >> 3) * stride; |
|
|
|
|
|
|
|
|
|
for (by = 0; by < bh; by++) { |
|
|
|
|
if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES]) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES]) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_colors(gb, &c->bundle[BINK_SRC_COLORS], c) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN]) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF]) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF]) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if (read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN]) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_BLOCK_TYPES])) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_block_types(c->avctx, gb, &c->bundle[BINK_SRC_SUB_BLOCK_TYPES])) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_colors(gb, &c->bundle[BINK_SRC_COLORS], c)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_patterns(c->avctx, gb, &c->bundle[BINK_SRC_PATTERN])) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_X_OFF])) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_motion_values(c->avctx, gb, &c->bundle[BINK_SRC_Y_OFF])) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTRA_DC], DC_START_BITS, 0)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_dcs(c->avctx, gb, &c->bundle[BINK_SRC_INTER_DC], DC_START_BITS, 1)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
if ((ret = read_runs(c->avctx, gb, &c->bundle[BINK_SRC_RUN])) < 0) |
|
|
|
|
return ret; |
|
|
|
|
|
|
|
|
|
if (by == bh) |
|
|
|
|
break; |
|
|
|
|
dst = c->pic.data[plane_idx] + 8*by*stride; |
|
|
|
|
prev = (c->last.data[plane_idx] ? c->last.data[plane_idx] |
|
|
|
|
: c->pic.data[plane_idx]) + 8*by*stride; |
|
|
|
|
dst = c->pic->data[plane_idx] + 8*by*stride; |
|
|
|
|
prev = (c->last->data[plane_idx] ? c->last->data[plane_idx] |
|
|
|
|
: c->pic->data[plane_idx]) + 8*by*stride; |
|
|
|
|
for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) { |
|
|
|
|
blk = get_value(c, BINK_SRC_BLOCK_TYPES); |
|
|
|
|
// 16x16 block type on odd line means part of the already decoded block, so skip it
|
|
|
|
@ -1022,7 +1022,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
i += run; |
|
|
|
|
if (i > 64) { |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (get_bits1(gb)) { |
|
|
|
|
v = get_value(c, BINK_SRC_COLORS); |
|
|
|
@ -1062,7 +1062,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Incorrect 16x16 block type %d\n", blk); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (blk != FILL_BLOCK) |
|
|
|
|
c->bdsp.scale_block(ublock, dst, stride); |
|
|
|
@ -1077,7 +1077,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
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; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); |
|
|
|
|
break; |
|
|
|
@ -1090,7 +1090,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
i += run; |
|
|
|
|
if (i > 64) { |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
if (get_bits1(gb)) { |
|
|
|
|
v = get_value(c, BINK_SRC_COLORS); |
|
|
|
@ -1111,7 +1111,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
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; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); |
|
|
|
|
c->dsp.clear_block(block); |
|
|
|
@ -1160,7 +1160,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -1174,21 +1174,21 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac |
|
|
|
|
{ |
|
|
|
|
BinkContext * const c = avctx->priv_data; |
|
|
|
|
GetBitContext gb; |
|
|
|
|
int plane, plane_idx; |
|
|
|
|
int plane, plane_idx, ret; |
|
|
|
|
int bits_count = pkt->size << 3; |
|
|
|
|
|
|
|
|
|
if (c->version > 'b') { |
|
|
|
|
if(c->pic.data[0]) |
|
|
|
|
avctx->release_buffer(avctx, &c->pic); |
|
|
|
|
if(c->pic->data[0]) |
|
|
|
|
avctx->release_buffer(avctx, c->pic); |
|
|
|
|
|
|
|
|
|
if(ff_get_buffer(avctx, &c->pic) < 0){ |
|
|
|
|
if ((ret = ff_get_buffer(avctx, c->pic)) < 0) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
|
|
|
return -1; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if(avctx->reget_buffer(avctx, &c->pic) < 0){ |
|
|
|
|
if ((ret = avctx->reget_buffer(avctx, c->pic)) < 0) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
|
|
|
|
return -1; |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1196,8 +1196,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac |
|
|
|
|
if (c->has_alpha) { |
|
|
|
|
if (c->version >= 'i') |
|
|
|
|
skip_bits_long(&gb, 32); |
|
|
|
|
if (bink_decode_plane(c, &gb, 3, 0) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if ((ret = bink_decode_plane(c, &gb, 3, 0)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
if (c->version >= 'i') |
|
|
|
|
skip_bits_long(&gb, 32); |
|
|
|
@ -1206,11 +1206,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac |
|
|
|
|
plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); |
|
|
|
|
|
|
|
|
|
if (c->version > 'b') { |
|
|
|
|
if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if ((ret = bink_decode_plane(c, &gb, plane_idx, !!plane)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
} else { |
|
|
|
|
if (binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane) < 0) |
|
|
|
|
return -1; |
|
|
|
|
if ((ret = binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
if (get_bits_count(&gb) >= bits_count) |
|
|
|
|
break; |
|
|
|
@ -1218,10 +1218,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac |
|
|
|
|
emms_c(); |
|
|
|
|
|
|
|
|
|
*got_frame = 1; |
|
|
|
|
*(AVFrame*)data = c->pic; |
|
|
|
|
*(AVFrame*)data = *c->pic; |
|
|
|
|
|
|
|
|
|
if (c->version > 'b') |
|
|
|
|
FFSWAP(AVFrame, c->pic, c->last); |
|
|
|
|
FFSWAP(AVFrame*, c->pic, c->last); |
|
|
|
|
|
|
|
|
|
/* always report that the buffer was completely consumed */ |
|
|
|
|
return pkt->size; |
|
|
|
@ -1264,13 +1264,13 @@ 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; |
|
|
|
|
int i; |
|
|
|
|
int i, ret; |
|
|
|
|
int flags; |
|
|
|
|
|
|
|
|
|
c->version = avctx->codec_tag >> 24; |
|
|
|
|
if (avctx->extradata_size < 4) { |
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n"); |
|
|
|
|
return -1; |
|
|
|
|
return AVERROR_INVALIDDATA; |
|
|
|
|
} |
|
|
|
|
flags = AV_RL32(avctx->extradata); |
|
|
|
|
c->has_alpha = flags & BINK_FLAG_ALPHA; |
|
|
|
@ -1287,12 +1287,17 @@ static av_cold int decode_init(AVCodecContext *avctx) |
|
|
|
|
} |
|
|
|
|
c->avctx = avctx; |
|
|
|
|
|
|
|
|
|
c->pic.data[0] = NULL; |
|
|
|
|
|
|
|
|
|
if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { |
|
|
|
|
return 1; |
|
|
|
|
c->pic = avcodec_alloc_frame(); |
|
|
|
|
c->last = avcodec_alloc_frame(); |
|
|
|
|
if (!c->pic || !c->last) { |
|
|
|
|
avcodec_free_frame(&c->pic); |
|
|
|
|
avcodec_free_frame(&c->last); |
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0) |
|
|
|
|
return ret; |
|
|
|
|
|
|
|
|
|
avctx->pix_fmt = c->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P; |
|
|
|
|
|
|
|
|
|
avctx->idct_algo = FF_IDCT_BINK; |
|
|
|
@ -1315,10 +1320,12 @@ static av_cold int decode_end(AVCodecContext *avctx) |
|
|
|
|
{ |
|
|
|
|
BinkContext * const c = avctx->priv_data; |
|
|
|
|
|
|
|
|
|
if (c->pic.data[0]) |
|
|
|
|
avctx->release_buffer(avctx, &c->pic); |
|
|
|
|
if (c->last.data[0]) |
|
|
|
|
avctx->release_buffer(avctx, &c->last); |
|
|
|
|
if (c->pic->data[0]) |
|
|
|
|
avctx->release_buffer(avctx, c->pic); |
|
|
|
|
if (c->last->data[0]) |
|
|
|
|
avctx->release_buffer(avctx, c->last); |
|
|
|
|
avcodec_free_frame(&c->pic); |
|
|
|
|
avcodec_free_frame(&c->last); |
|
|
|
|
|
|
|
|
|
free_bundles(c); |
|
|
|
|
return 0; |
|
|
|
|