History

avcodec/webp: use av_packet_alloc() to allocate packets

James Almer committed 5 years ago

Commit 4ab76701 parent fc2e0221 file · +19 −5Browse files

Unified · Split

libavcodec/webp.c+19−5
@@ -189,6 +189,7 @@ typedef struct WebPContext { · 188 unmodified lines
189189 VP8Context v; /* VP8 Context used for lossy decoding */
190190 GetBitContext gb; /* bitstream reader for main image chunk */
191191 AVFrame *alpha_frame; /* AVFrame for alpha data decompressed from VP8L */
192+ AVPacket *pkt; /* AVPacket to be passed to the underlying VP8 decoder */
192193 AVCodecContext *avctx; /* parent AVCodecContext */
193194 int initialized; /* set once the VP8 context is initialized */
194195 int has_alpha; /* has a separate alpha chunk */
@@ -1290,7 +1291,6 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, · 1095 unmodified lines
12901291 unsigned int data_size)
12911292 {
12921293 WebPContext *s = avctx->priv_data;
1293− AVPacket pkt;
12941294 int ret;
12951295
12961296 if (!s->initialized) {
@@ -1306,11 +1306,11 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, · 9 unmodified lines
13061306 return AVERROR_PATCHWELCOME;
13071307 }
13081308
1309− av_init_packet(&pkt);
1310− pkt.data = data_start;
1311− pkt.size = data_size;
1309+ av_packet_unref(s->pkt);
1310+ s->pkt->data = data_start;
1311+ s->pkt->size = data_size;
13121312
1313− ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
1313+ ret = ff_vp8_decode_frame(avctx, p, got_frame, s->pkt);
13141314 if (ret < 0)
13151315 return ret;
13161316
@@ -1527,10 +1527,23 @@ exif_end: · 210 unmodified lines
15271527 return avpkt->size;
15281528 }
15291529
1530+static av_cold int webp_decode_init(AVCodecContext *avctx)
1531+{
1532+ WebPContext *s = avctx->priv_data;
1533+
1534+ s->pkt = av_packet_alloc();
1535+ if (!s->pkt)
1536+ return AVERROR(ENOMEM);
1537+
1538+ return 0;
1539+}
1540+
15301541 static av_cold int webp_decode_close(AVCodecContext *avctx)
15311542 {
15321543 WebPContext *s = avctx->priv_data;
15331544
1545+ av_packet_free(&s->pkt);
1546+
15341547 if (s->initialized)
15351548 return ff_vp8_decode_free(avctx);
15361549
@@ -1543,6 +1556,7 @@ AVCodec ff_webp_decoder = { · 6 unmodified lines
15431556 .type = AVMEDIA_TYPE_VIDEO,
15441557 .id = AV_CODEC_ID_WEBP,
15451558 .priv_data_size = sizeof(WebPContext),
1559+ .init = webp_decode_init,
15461560 .decode = webp_decode_frame,
15471561 .close = webp_decode_close,
15481562 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t