aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-01-28 23:15:36 -0300
committerJames Almer <jamrial@gmail.com>2021-03-17 15:06:48 -0300
commit4ab7670762b073619aa22da5ab7370bb51bef178 (patch)
treec6b8a1b3538dce62f6784e44844e7f3b729f2062 /libavcodec
parentfc2e022a14634db9f9f84d321aaccbbd3c4cd863 (diff)
downloadffmpeg-4ab7670762b073619aa22da5ab7370bb51bef178.tar.gz
avcodec/webp: use av_packet_alloc() to allocate packets
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/webp.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 6de6a5c036..5a7aebc587 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -189,6 +189,7 @@ typedef struct WebPContext {
VP8Context v; /* VP8 Context used for lossy decoding */
GetBitContext gb; /* bitstream reader for main image chunk */
AVFrame *alpha_frame; /* AVFrame for alpha data decompressed from VP8L */
+ AVPacket *pkt; /* AVPacket to be passed to the underlying VP8 decoder */
AVCodecContext *avctx; /* parent AVCodecContext */
int initialized; /* set once the VP8 context is initialized */
int has_alpha; /* has a separate alpha chunk */
@@ -1290,7 +1291,6 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
unsigned int data_size)
{
WebPContext *s = avctx->priv_data;
- AVPacket pkt;
int ret;
if (!s->initialized) {
@@ -1306,11 +1306,11 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
return AVERROR_PATCHWELCOME;
}
- av_init_packet(&pkt);
- pkt.data = data_start;
- pkt.size = data_size;
+ av_packet_unref(s->pkt);
+ s->pkt->data = data_start;
+ s->pkt->size = data_size;
- ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
+ ret = ff_vp8_decode_frame(avctx, p, got_frame, s->pkt);
if (ret < 0)
return ret;
@@ -1527,10 +1527,23 @@ exif_end:
return avpkt->size;
}
+static av_cold int webp_decode_init(AVCodecContext *avctx)
+{
+ WebPContext *s = avctx->priv_data;
+
+ s->pkt = av_packet_alloc();
+ if (!s->pkt)
+ return AVERROR(ENOMEM);
+
+ return 0;
+}
+
static av_cold int webp_decode_close(AVCodecContext *avctx)
{
WebPContext *s = avctx->priv_data;
+ av_packet_free(&s->pkt);
+
if (s->initialized)
return ff_vp8_decode_free(avctx);
@@ -1543,6 +1556,7 @@ AVCodec ff_webp_decoder = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WEBP,
.priv_data_size = sizeof(WebPContext),
+ .init = webp_decode_init,
.decode = webp_decode_frame,
.close = webp_decode_close,
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,