typedef struct FlashSVContext {
AVCodecContext *avctx;
- AVFrame frame;
+ AVFrame *frame;
int image_width, image_height;
int block_width, block_height;
uint8_t *tmpblock;
return sptr - orig_src;
}
+static av_cold int flashsv_decode_end(AVCodecContext *avctx)
+{
+ FlashSVContext *s = avctx->priv_data;
+ inflateEnd(&s->zstream);
+ /* release the frame if needed */
+ av_frame_free(&s->frame);
+
+ /* free the tmpblock */
+ av_free(s->tmpblock);
+
+ return 0;
+}
+
static av_cold int flashsv_decode_init(AVCodecContext *avctx)
{
FlashSVContext *s = avctx->priv_data;
return 1;
}
avctx->pix_fmt = AV_PIX_FMT_BGR24;
- avcodec_get_frame_defaults(&s->frame);
+
+ s->frame = av_frame_alloc();
+ if (!s->frame) {
+ flashsv_decode_end(avctx);
+ return AVERROR(ENOMEM);
+ }
return 0;
}
/* Flash Screen Video stores the image upside down, so copy
* lines to destination in reverse order. */
for (k = 1; k <= s->diff_height; k++) {
- memcpy(s->frame.data[0] + x_pos * 3 +
- (s->image_height - y_pos - k) * s->frame.linesize[0],
+ memcpy(s->frame->data[0] + x_pos * 3 +
+ (s->image_height - y_pos - k) * s->frame->linesize[0],
line, width * 3);
/* advance source pointer to next line */
line += width * 3;
}
} else {
/* hybrid 15-bit/palette mode */
- decode_hybrid(s->tmpblock, s->frame.data[0],
+ decode_hybrid(s->tmpblock, s->frame->data[0],
s->image_height - (y_pos + 1 + s->diff_height),
x_pos, s->diff_height, width,
- s->frame.linesize[0], s->pal);
+ s->frame->linesize[0], s->pal);
}
skip_bits_long(gb, 8 * block_size); /* skip the consumed bits */
return 0;
/* the block size could change between frames, make sure the buffer
* is large enough, if not, get a larger one */
if (s->block_size < s->block_width * s->block_height) {
- int tmpblock_size = 3 * s->block_width * s->block_height;
+ int tmpblock_size = 3 * s->block_width * s->block_height, err;
- s->tmpblock = av_realloc(s->tmpblock, tmpblock_size);
- if (!s->tmpblock) {
+ if ((err = av_reallocp(&s->tmpblock, tmpblock_size)) < 0) {
+ s->block_size = 0;
av_log(avctx, AV_LOG_ERROR,
"Cannot allocate decompression buffer.\n");
- return AVERROR(ENOMEM);
+ return err;
}
if (s->ver == 2) {
s->deflate_block_size = calc_deflate_block_size(tmpblock_size);
"Cannot determine deflate buffer size.\n");
return -1;
}
- s->deflate_block = av_realloc(s->deflate_block,
- s->deflate_block_size);
- if (!s->deflate_block) {
- av_log(avctx, AV_LOG_ERROR,
- "Cannot allocate deflate buffer.\n");
- return AVERROR(ENOMEM);
+ if ((err = av_reallocp(&s->deflate_block, s->deflate_block_size)) < 0) {
+ s->block_size = 0;
+ av_log(avctx, AV_LOG_ERROR, "Cannot allocate deflate buffer.\n");
+ return err;
}
}
}
/* we care for keyframes only in Screen Video v2 */
s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2);
if (s->is_keyframe) {
- s->keyframedata = av_realloc(s->keyframedata, avpkt->size);
+ int err;
+ int nb_blocks = (v_blocks + !!v_part) *
+ (h_blocks + !!h_part) * sizeof(s->blocks[0]);
+ if ((err = av_reallocp(&s->keyframedata, avpkt->size)) < 0)
+ return err;
memcpy(s->keyframedata, avpkt->data, avpkt->size);
- s->blocks = av_realloc(s->blocks,
- (v_blocks + !!v_part) * (h_blocks + !!h_part) *
- sizeof(s->blocks[0]));
+ if ((err = av_reallocp(&s->blocks, nb_blocks)) < 0)
+ return err;
+ memset(s->blocks, 0, nb_blocks);
}
- av_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n",
+ ff_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n",
s->image_width, s->image_height, s->block_width, s->block_height,
h_blocks, v_blocks, h_part, v_part);
- if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0) {
+ if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret;
}
s->diff_height = cur_blk_height;
if (8 * size > get_bits_left(&gb)) {
- av_frame_unref(&s->frame);
+ av_frame_unref(s->frame);
return AVERROR_INVALIDDATA;
}
if (has_diff) {
int k;
- int off = (s->image_height - y_pos - 1) * s->frame.linesize[0];
+ int off = (s->image_height - y_pos - 1) * s->frame->linesize[0];
for (k = 0; k < cur_blk_height; k++) {
- int x = off - k * s->frame.linesize[0] + x_pos * 3;
- memcpy(s->frame.data[0] + x, s->keyframe + x,
+ int x = off - k * s->frame->linesize[0] + x_pos * 3;
+ memcpy(s->frame->data[0] + x, s->keyframe + x,
cur_blk_width * 3);
}
}
}
if (s->is_keyframe && s->ver == 2) {
if (!s->keyframe) {
- s->keyframe = av_malloc(s->frame.linesize[0] * avctx->height);
+ s->keyframe = av_malloc(s->frame->linesize[0] * avctx->height);
if (!s->keyframe) {
av_log(avctx, AV_LOG_ERROR, "Cannot allocate image data\n");
return AVERROR(ENOMEM);
}
}
- memcpy(s->keyframe, s->frame.data[0],
- s->frame.linesize[0] * avctx->height);
+ memcpy(s->keyframe, s->frame->data[0],
+ s->frame->linesize[0] * avctx->height);
}
- if ((ret = av_frame_ref(data, &s->frame)) < 0)
+ if ((ret = av_frame_ref(data, s->frame)) < 0)
return ret;
*got_frame = 1;
return buf_size;
}
-static av_cold int flashsv_decode_end(AVCodecContext *avctx)
-{
- FlashSVContext *s = avctx->priv_data;
- inflateEnd(&s->zstream);
- /* release the frame if needed */
- av_frame_unref(&s->frame);
-
- /* free the tmpblock */
- av_free(s->tmpblock);
-
- return 0;
-}
-
#if CONFIG_FLASHSV_DECODER
AVCodec ff_flashsv_decoder = {
.name = "flashsv",
.init = flashsv_decode_init,
.close = flashsv_decode_end,
.decode = flashsv_decode_frame,
- .capabilities = CODEC_CAP_DR1,
+ .capabilities = AV_CODEC_CAP_DR1,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_BGR24, AV_PIX_FMT_NONE },
};
#endif /* CONFIG_FLASHSV_DECODER */
.init = flashsv2_decode_init,
.close = flashsv2_decode_end,
.decode = flashsv_decode_frame,
- .capabilities = CODEC_CAP_DR1,
+ .capabilities = AV_CODEC_CAP_DR1,
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_BGR24, AV_PIX_FMT_NONE },
};
#endif /* CONFIG_FLASHSV2_DECODER */