Commit 6a97ea65 authored by Anton Khirnov's avatar Anton Khirnov

bink: operate with pointers to AVFrames instead of whole structs.

This is more correct and avoids breaking extended_data.
parent 86d4e754
...@@ -112,7 +112,7 @@ typedef struct BinkContext { ...@@ -112,7 +112,7 @@ typedef struct BinkContext {
AVCodecContext *avctx; AVCodecContext *avctx;
DSPContext dsp; DSPContext dsp;
BinkDSPContext bdsp; BinkDSPContext bdsp;
AVFrame pic, last; AVFrame *pic, *last;
int version; ///< internal Bink file version int version; ///< internal Bink file version
int has_alpha; int has_alpha;
int swap_planes; int swap_planes;
...@@ -806,13 +806,13 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, ...@@ -806,13 +806,13 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
int ybias = is_key ? -15 : 0; int ybias = is_key ? -15 : 0;
int qp; 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 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 bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;
binkb_init_bundles(c); binkb_init_bundles(c);
ref_start = c->pic.data[plane_idx]; ref_start = c->pic->data[plane_idx];
ref_end = c->pic.data[plane_idx] + (bh * c->pic.linesize[plane_idx] + bw) * 8; ref_end = c->pic->data[plane_idx] + (bh * c->pic->linesize[plane_idx] + bw) * 8;
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
coordmap[i] = (i & 7) + (i >> 3) * stride; coordmap[i] = (i & 7) + (i >> 3) * stride;
...@@ -823,7 +823,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, ...@@ -823,7 +823,7 @@ static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
return ret; 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) { for (bx = 0; bx < bw; bx++, dst += 8) {
blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES); blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES);
switch (blk) { switch (blk) {
...@@ -951,7 +951,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, ...@@ -951,7 +951,7 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
LOCAL_ALIGNED_16(int32_t, dctblock, [64]); LOCAL_ALIGNED_16(int32_t, dctblock, [64]);
int coordmap[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 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 bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3;
int width = c->avctx->width >> is_chroma; int width = c->avctx->width >> is_chroma;
...@@ -960,10 +960,10 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, ...@@ -960,10 +960,10 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
for (i = 0; i < BINK_NB_SRC; i++) for (i = 0; i < BINK_NB_SRC; i++)
read_bundle(gb, c, i); read_bundle(gb, c, i);
ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx] ref_start = c->last->data[plane_idx] ? c->last->data[plane_idx]
: c->pic.data[plane_idx]; : c->pic->data[plane_idx];
ref_end = ref_start 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++) for (i = 0; i < 64; i++)
coordmap[i] = (i & 7) + (i >> 3) * stride; coordmap[i] = (i & 7) + (i >> 3) * stride;
...@@ -990,9 +990,9 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, ...@@ -990,9 +990,9 @@ static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx,
if (by == bh) if (by == bh)
break; break;
dst = 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] prev = (c->last->data[plane_idx] ? c->last->data[plane_idx]
: c->pic.data[plane_idx]) + 8*by*stride; : c->pic->data[plane_idx]) + 8*by*stride;
for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) { for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) {
blk = get_value(c, BINK_SRC_BLOCK_TYPES); blk = get_value(c, BINK_SRC_BLOCK_TYPES);
// 16x16 block type on odd line means part of the already decoded block, so skip it // 16x16 block type on odd line means part of the already decoded block, so skip it
...@@ -1169,15 +1169,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac ...@@ -1169,15 +1169,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
int bits_count = pkt->size << 3; int bits_count = pkt->size << 3;
if (c->version > 'b') { if (c->version > 'b') {
if(c->pic.data[0]) if(c->pic->data[0])
avctx->release_buffer(avctx, &c->pic); avctx->release_buffer(avctx, c->pic);
if ((ret = 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"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret; return ret;
} }
} else { } else {
if ((ret = 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"); av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret; return ret;
} }
...@@ -1209,10 +1209,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac ...@@ -1209,10 +1209,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPac
emms_c(); emms_c();
*got_frame = 1; *got_frame = 1;
*(AVFrame*)data = c->pic; *(AVFrame*)data = *c->pic;
if (c->version > 'b') if (c->version > 'b')
FFSWAP(AVFrame, c->pic, c->last); FFSWAP(AVFrame*, c->pic, c->last);
/* always report that the buffer was completely consumed */ /* always report that the buffer was completely consumed */
return pkt->size; return pkt->size;
...@@ -1291,10 +1291,12 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -1291,10 +1291,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
} }
c->avctx = avctx; c->avctx = avctx;
c->pic.data[0] = NULL; c->pic = avcodec_alloc_frame();
c->last = avcodec_alloc_frame();
if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { if (!c->pic || !c->last) {
return 1; 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) if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
...@@ -1322,10 +1324,12 @@ static av_cold int decode_end(AVCodecContext *avctx) ...@@ -1322,10 +1324,12 @@ static av_cold int decode_end(AVCodecContext *avctx)
{ {
BinkContext * const c = avctx->priv_data; BinkContext * const c = avctx->priv_data;
if (c->pic.data[0]) if (c->pic->data[0])
avctx->release_buffer(avctx, &c->pic); avctx->release_buffer(avctx, c->pic);
if (c->last.data[0]) if (c->last->data[0])
avctx->release_buffer(avctx, &c->last); avctx->release_buffer(avctx, c->last);
avcodec_free_frame(&c->pic);
avcodec_free_frame(&c->last);
free_bundles(c); free_bundles(c);
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment