diff options
author | Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> | 2016-11-01 19:06:51 +0300 |
---|---|---|
committer | Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> | 2016-11-01 20:49:28 +0300 |
commit | e0c6b32046f4bab7d34be77dd2f03b2a80c86d39 (patch) | |
tree | ca51b513cd1526d253b1827be0c0062884916af6 /libavcodec/pngdec.c | |
parent | 9d83b209d8861f1daf55f6719b1e0c226ed7269a (diff) |
apngdec: use side data to pass extradata to the decoder
Fixes remuxing apng streams coming from the apng demuxer.
This is a regression since 940b8908b94404a65f9f55e33efb4ccc6c81383c.
Found-by: James Almer <jamrial@gmail.com>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Diffstat (limited to 'libavcodec/pngdec.c')
-rw-r--r-- | libavcodec/pngdec.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 36275ae43f..83eeb8d322 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -45,6 +45,9 @@ typedef struct PNGDecContext { ThreadFrame last_picture; ThreadFrame picture; + uint8_t* extra_data; + int extra_data_size; + int state; int width, height; int cur_w, cur_h; @@ -1361,14 +1364,28 @@ static int decode_frame_apng(AVCodecContext *avctx, p = s->picture.f; if (!(s->state & PNG_IHDR)) { - if (!avctx->extradata_size) + int side_data_size = 0; + uint8_t *side_data = NULL; + if (avpkt) + side_data = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &side_data_size); + + if (side_data_size) { + av_freep(&s->extra_data); + s->extra_data = av_mallocz(side_data_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!s->extra_data) + return AVERROR(ENOMEM); + s->extra_data_size = side_data_size; + memcpy(s->extra_data, side_data, s->extra_data_size); + } + + if (!s->extra_data_size) return AVERROR_INVALIDDATA; /* only init fields, there is no zlib use in extradata */ s->zstream.zalloc = ff_png_zalloc; s->zstream.zfree = ff_png_zfree; - bytestream2_init(&s->gb, avctx->extradata, avctx->extradata_size); + bytestream2_init(&s->gb, s->extra_data, s->extra_data_size); if ((ret = decode_frame_common(avctx, s, p, avpkt)) < 0) goto end; } @@ -1494,6 +1511,8 @@ static av_cold int png_dec_end(AVCodecContext *avctx) s->last_row_size = 0; av_freep(&s->tmp_row); s->tmp_row_size = 0; + av_freep(&s->extra_data); + s->extra_data_size = 0; return 0; } |