From c5dfb9033f528f68370c72c30af087efe1e6cae8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 1/4] msrle: use the AVFrame API properly. --- libavcodec/msrle.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c index a57040f8dc..4b39c92061 100644 --- a/libavcodec/msrle.c +++ b/libavcodec/msrle.c @@ -38,7 +38,7 @@ typedef struct MsrleContext { AVCodecContext *avctx; - AVFrame frame; + AVFrame *frame; GetByteContext gb; const unsigned char *buf; @@ -66,7 +66,9 @@ static av_cold int msrle_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } - avcodec_get_frame_defaults(&s->frame); + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); return 0; } @@ -84,7 +86,7 @@ static int msrle_decode_frame(AVCodecContext *avctx, s->buf = buf; s->size = buf_size; - 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; } @@ -93,18 +95,18 @@ static int msrle_decode_frame(AVCodecContext *avctx, const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); if (pal) { - s->frame.palette_has_changed = 1; + s->frame->palette_has_changed = 1; memcpy(s->pal, pal, AVPALETTE_SIZE); } /* make the palette available */ - memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); } /* FIXME how to correctly detect RLE ??? */ if (avctx->height * istride == avpkt->size) { /* assume uncompressed */ int linesize = avctx->width * avctx->bits_per_coded_sample / 8; - uint8_t *ptr = s->frame.data[0]; + uint8_t *ptr = s->frame->data[0]; uint8_t *buf = avpkt->data + (avctx->height-1)*istride; int i, j; @@ -120,14 +122,14 @@ static int msrle_decode_frame(AVCodecContext *avctx, memcpy(ptr, buf, linesize); } buf -= istride; - ptr += s->frame.linesize[0]; + ptr += s->frame->linesize[0]; } } else { bytestream2_init(&s->gb, buf, buf_size); - ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, &s->gb); + ff_msrle_decode(avctx, (AVPicture*)s->frame, avctx->bits_per_coded_sample, &s->gb); } - if ((ret = av_frame_ref(data, &s->frame)) < 0) + if ((ret = av_frame_ref(data, s->frame)) < 0) return ret; *got_frame = 1; @@ -141,7 +143,7 @@ static av_cold int msrle_decode_end(AVCodecContext *avctx) MsrleContext *s = avctx->priv_data; /* release the last frame */ - av_frame_unref(&s->frame); + av_frame_free(&s->frame); return 0; } From 4b8a1941465c8e30b2c1d22b9c0969bfa53ad614 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 2/4] iff: use the AVFrame API properly. --- libavcodec/iff.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/libavcodec/iff.c b/libavcodec/iff.c index 1ee02bd506..7ac78b0e5c 100644 --- a/libavcodec/iff.c +++ b/libavcodec/iff.c @@ -32,7 +32,7 @@ #include "internal.h" typedef struct { - AVFrame frame; + AVFrame *frame; int planesize; uint8_t * planebuf; int init; // 1 if buffer and palette data already initialized, 0 otherwise @@ -144,6 +144,14 @@ static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal) return 0; } +static av_cold int decode_end(AVCodecContext *avctx) +{ + IffContext *s = avctx->priv_data; + av_frame_free(&s->frame); + av_freep(&s->planebuf); + return 0; +} + static av_cold int decode_init(AVCodecContext *avctx) { IffContext *s = avctx->priv_data; @@ -166,7 +174,11 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!s->planebuf) return AVERROR(ENOMEM); - avcodec_get_frame_defaults(&s->frame); + s->frame = av_frame_alloc(); + if (!s->frame) { + decode_end(avctx); + return AVERROR(ENOMEM); + } return 0; } @@ -255,12 +267,12 @@ static int decode_frame_ilbm(AVCodecContext *avctx, const uint8_t *buf_end = buf + buf_size; int y, plane, res; - if ((res = ff_reget_buffer(avctx, &s->frame)) < 0) + if ((res = ff_reget_buffer(avctx, s->frame)) < 0) return res; if (!s->init && avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt != AV_PIX_FMT_GRAY8) { - if ((res = cmap_read_palette(avctx, (uint32_t *)s->frame.data[1])) < 0) + if ((res = cmap_read_palette(avctx, (uint32_t *)s->frame->data[1])) < 0) return res; } s->init = 1; @@ -268,7 +280,7 @@ static int decode_frame_ilbm(AVCodecContext *avctx, if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M')) { // interleaved if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) { for (y = 0; y < avctx->height; y++) { - uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; + uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]]; memset(row, 0, avctx->width); for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) { @@ -278,7 +290,7 @@ static int decode_frame_ilbm(AVCodecContext *avctx, } } else { // AV_PIX_FMT_BGR32 for (y = 0; y < avctx->height; y++) { - uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; + uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]]; memset(row, 0, avctx->width << 2); for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) { @@ -290,13 +302,13 @@ static int decode_frame_ilbm(AVCodecContext *avctx, } } else if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) { // IFF-PBM for (y = 0; y < avctx->height && buf < buf_end; y++) { - uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; + uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]]; memcpy(row, buf, FFMIN(avctx->width, buf_end - buf)); buf += avctx->width + (avctx->width % 2); // padding if odd } } - if ((res = av_frame_ref(data, &s->frame)) < 0) + if ((res = av_frame_ref(data, s->frame)) < 0) return res; *got_frame = 1; @@ -314,12 +326,12 @@ static int decode_frame_byterun1(AVCodecContext *avctx, const uint8_t *buf_end = buf + buf_size; int y, plane, res; - if ((res = ff_reget_buffer(avctx, &s->frame)) < 0) + if ((res = ff_reget_buffer(avctx, s->frame)) < 0) return res; if (!s->init && avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt != AV_PIX_FMT_GRAY8) { - if ((res = cmap_read_palette(avctx, (uint32_t *)s->frame.data[1])) < 0) + if ((res = cmap_read_palette(avctx, (uint32_t *)s->frame->data[1])) < 0) return res; } s->init = 1; @@ -327,7 +339,7 @@ static int decode_frame_byterun1(AVCodecContext *avctx, if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M')) { // interleaved if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) { for (y = 0; y < avctx->height; y++) { - uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; + uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]]; memset(row, 0, avctx->width); for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) { buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end); @@ -336,7 +348,7 @@ static int decode_frame_byterun1(AVCodecContext *avctx, } } else { // AV_PIX_FMT_BGR32 for (y = 0; y < avctx->height; y++) { - uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; + uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]]; memset(row, 0, avctx->width << 2); for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) { buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end); @@ -346,12 +358,12 @@ static int decode_frame_byterun1(AVCodecContext *avctx, } } else { for (y = 0; y < avctx->height; y++) { - uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; + uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]]; buf += decode_byterun(row, avctx->width, buf, buf_end); } } - if ((res = av_frame_ref(data, &s->frame)) < 0) + if ((res = av_frame_ref(data, s->frame)) < 0) return res; *got_frame = 1; @@ -359,14 +371,6 @@ static int decode_frame_byterun1(AVCodecContext *avctx, return buf_size; } -static av_cold int decode_end(AVCodecContext *avctx) -{ - IffContext *s = avctx->priv_data; - av_frame_unref(&s->frame); - av_freep(&s->planebuf); - return 0; -} - AVCodec ff_iff_ilbm_decoder = { .name = "iff_ilbm", .long_name = NULL_IF_CONFIG_SMALL("IFF ILBM"), From 79d501a860bd48a17d37bbb7097311587dc46e6c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 3/4] indeo2: use the AVFrame API properly. --- libavcodec/indeo2.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c index 67c2facba7..7df6e69f2a 100644 --- a/libavcodec/indeo2.c +++ b/libavcodec/indeo2.c @@ -34,7 +34,7 @@ typedef struct Ir2Context{ AVCodecContext *avctx; - AVFrame picture; + AVFrame *picture; GetBitContext gb; int decode_delta; } Ir2Context; @@ -146,7 +146,7 @@ static int ir2_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AVFrame *picture = data; - AVFrame * const p = &s->picture; + AVFrame * const p = s->picture; int start, ret; if ((ret = ff_reget_buffer(avctx, p)) < 0) { @@ -173,36 +173,36 @@ static int ir2_decode_frame(AVCodecContext *avctx, if (s->decode_delta) { /* intraframe */ if ((ret = ir2_decode_plane(s, avctx->width, avctx->height, - s->picture.data[0], s->picture.linesize[0], + p->data[0], p->linesize[0], ir2_luma_table)) < 0) return ret; /* swapped U and V */ if ((ret = ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[2], s->picture.linesize[2], + p->data[2], p->linesize[2], ir2_luma_table)) < 0) return ret; if ((ret = ir2_decode_plane(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[1], s->picture.linesize[1], + p->data[1], p->linesize[1], ir2_luma_table)) < 0) return ret; } else { /* interframe */ if ((ret = ir2_decode_plane_inter(s, avctx->width, avctx->height, - s->picture.data[0], s->picture.linesize[0], + p->data[0], p->linesize[0], ir2_luma_table)) < 0) return ret; /* swapped U and V */ if ((ret = ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[2], s->picture.linesize[2], + p->data[2], p->linesize[2], ir2_luma_table)) < 0) return ret; if ((ret = ir2_decode_plane_inter(s, avctx->width >> 2, avctx->height >> 2, - s->picture.data[1], s->picture.linesize[1], + p->data[1], p->linesize[1], ir2_luma_table)) < 0) return ret; } - if ((ret = av_frame_ref(picture, &s->picture)) < 0) + if ((ret = av_frame_ref(picture, p)) < 0) return ret; *got_frame = 1; @@ -219,7 +219,9 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx) avctx->pix_fmt= AV_PIX_FMT_YUV410P; - avcodec_get_frame_defaults(&ic->picture); + ic->picture = av_frame_alloc(); + if (!ic->picture) + return AVERROR(ENOMEM); ir2_vlc.table = vlc_tables; ir2_vlc.table_allocated = 1 << CODE_VLC_BITS; @@ -239,9 +241,8 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx) static av_cold int ir2_decode_end(AVCodecContext *avctx) { Ir2Context * const ic = avctx->priv_data; - AVFrame *pic = &ic->picture; - av_frame_unref(pic); + av_frame_free(&ic->picture); return 0; } From 2e09096da912f563c4dd889a8f25c314529bbaa6 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH 4/4] kgv1: use the AVFrame API properly. --- libavcodec/kgv1dec.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavcodec/kgv1dec.c b/libavcodec/kgv1dec.c index 62b5c6e233..1436ccbaea 100644 --- a/libavcodec/kgv1dec.c +++ b/libavcodec/kgv1dec.c @@ -32,14 +32,14 @@ typedef struct { AVCodecContext *avctx; - AVFrame prev; + AVFrame *prev; } KgvContext; static void decode_flush(AVCodecContext *avctx) { KgvContext * const c = avctx->priv_data; - av_frame_unref(&c->prev); + av_frame_free(&c->prev); } static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, @@ -62,7 +62,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, buf += 2; if (w != avctx->width || h != avctx->height) { - av_frame_unref(&c->prev); + av_frame_unref(c->prev); if ((res = ff_set_dimensions(avctx, w, h)) < 0) return res; } @@ -72,8 +72,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if ((res = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) return res; out = (uint16_t *) frame->data[0]; - if (c->prev.data[0]) { - prev = (uint16_t *) c->prev.data[0]; + if (c->prev->data[0]) { + prev = (uint16_t *) c->prev->data[0]; } else { prev = NULL; } @@ -152,8 +152,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (outcnt - maxcnt) av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt); - av_frame_unref(&c->prev); - if ((res = av_frame_ref(&c->prev, frame)) < 0) + av_frame_unref(c->prev); + if ((res = av_frame_ref(c->prev, frame)) < 0) return res; *got_frame = 1; @@ -165,6 +165,10 @@ static av_cold int decode_init(AVCodecContext *avctx) { KgvContext * const c = avctx->priv_data; + c->prev = av_frame_alloc(); + if (!c->prev) + return AVERROR(ENOMEM); + c->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_RGB555; avctx->flags |= CODEC_FLAG_EMU_EDGE;