From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: thilo.borgmann@mail.de Subject: [FFmpeg-devel] [PATCH v12 2/8] avcodec/webp: separate VP8 decoding Date: Wed, 17 Apr 2024 12:19:58 -0700 Message-ID: <20240417192012.22436-3-thilo.borgmann@mail.de> (raw) In-Reply-To: <20240417192012.22436-1-thilo.borgmann@mail.de> From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> --- libavcodec/webp.c | 50 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 3c153d78d1..3075321e86 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -195,6 +195,7 @@ typedef struct WebPContext { 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 */ + AVCodecContext *avctx_vp8; /* wrapper context for VP8 decoder */ int initialized; /* set once the VP8 context is initialized */ int has_alpha; /* has a separate alpha chunk */ enum AlphaCompression alpha_compression; /* compression type for alpha chunk */ @@ -1299,12 +1300,13 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, int ret; if (!s->initialized) { - ff_vp8_decode_init(avctx); + VP8Context *s_vp8 = s->avctx_vp8->priv_data; + s_vp8->actually_webp = 1; s->initialized = 1; - s->v.actually_webp = 1; } avctx->pix_fmt = s->has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P; s->lossless = 0; + s->avctx_vp8->pix_fmt = avctx->pix_fmt; if (data_size > INT_MAX) { av_log(avctx, AV_LOG_ERROR, "unsupported chunk size\n"); @@ -1315,14 +1317,32 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, s->pkt->data = data_start; s->pkt->size = data_size; - ret = ff_vp8_decode_frame(avctx, p, got_frame, s->pkt); - if (ret < 0) + ret = avcodec_send_packet(s->avctx_vp8, s->pkt); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); return ret; + } - if (!*got_frame) + ret = avcodec_receive_frame(s->avctx_vp8, p); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "VP8 decoding error: %s.\n", av_err2str(ret)); return AVERROR_INVALIDDATA; + } + + ret = ff_decode_frame_props(avctx, p); + if (ret < 0) { + return ret; + } + + if (!p->private_ref) { + ret = ff_attach_decode_data(p); + if (ret < 0) { + return ret; + } + } - update_canvas_size(avctx, avctx->width, avctx->height); + *got_frame = 1; + update_canvas_size(avctx, s->avctx_vp8->width, s->avctx_vp8->height); if (s->has_alpha) { ret = vp8_lossy_decode_alpha(avctx, p, s->alpha_data, @@ -1539,11 +1559,28 @@ exif_end: static av_cold int webp_decode_init(AVCodecContext *avctx) { WebPContext *s = avctx->priv_data; + int ret; + const AVCodec *codec; s->pkt = av_packet_alloc(); if (!s->pkt) return AVERROR(ENOMEM); + + /* Prepare everything needed for VP8 decoding */ + codec = avcodec_find_decoder(AV_CODEC_ID_VP8); + if (!codec) + return AVERROR_BUG; + s->avctx_vp8 = avcodec_alloc_context3(codec); + if (!s->avctx_vp8) + return AVERROR(ENOMEM); + s->avctx_vp8->flags = avctx->flags; + s->avctx_vp8->flags2 = avctx->flags2; + s->avctx_vp8->pix_fmt = avctx->pix_fmt; + ret = avcodec_open2(s->avctx_vp8, codec, NULL); + if (ret < 0) { + return ret; + } return 0; } @@ -1552,6 +1589,7 @@ static av_cold int webp_decode_close(AVCodecContext *avctx) WebPContext *s = avctx->priv_data; av_packet_free(&s->pkt); + avcodec_free_context(&s->avctx_vp8); if (s->initialized) return ff_vp8_decode_free(avctx); -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-04-17 19:20 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-17 19:19 [FFmpeg-devel] [PATCH v12 0/8] [WIP] webp: add support for animated WebP decoding Thilo Borgmann via ffmpeg-devel 2024-04-17 19:19 ` [FFmpeg-devel] [PATCH v12 1/8] avcodec/webp: remove unused definitions Thilo Borgmann via ffmpeg-devel 2024-04-17 19:19 ` Thilo Borgmann via ffmpeg-devel [this message] 2024-04-17 19:19 ` [FFmpeg-devel] [PATCH v12 3/8] avcodec/bsf: Add awebp2webp bitstream filter Thilo Borgmann via ffmpeg-devel 2024-04-17 19:37 ` Thilo Borgmann via ffmpeg-devel 2024-04-17 19:20 ` [FFmpeg-devel] [PATCH v12 4/8] libavcodec/webp: add support for animated WebP Thilo Borgmann via ffmpeg-devel 2024-04-17 19:20 ` [FFmpeg-devel] [PATCH v12 5/8] avcodec/webp: make init_canvas_frame static Thilo Borgmann via ffmpeg-devel 2024-04-17 19:20 ` [FFmpeg-devel] [PATCH v12 6/8] libavformat/webp: add WebP demuxer Thilo Borgmann via ffmpeg-devel 2024-04-17 19:20 ` [FFmpeg-devel] [PATCH v12 7/8] fate: add test for animated WebP Thilo Borgmann via ffmpeg-devel 2024-04-17 19:20 ` [FFmpeg-devel] [PATCH v12 8/8] avcodec/webp: export XMP metadata Thilo Borgmann via ffmpeg-devel 2024-04-17 22:52 ` [FFmpeg-devel] [PATCH v12 0/8] [WIP] webp: add support for animated WebP decoding James Zern via ffmpeg-devel 2024-04-18 18:21 ` Thilo Borgmann via ffmpeg-devel 2024-04-18 19:38 ` James Zern via ffmpeg-devel 2024-05-21 16:50 ` Thilo Borgmann via ffmpeg-devel 2024-05-23 2:31 ` James Zern via ffmpeg-devel
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240417192012.22436-3-thilo.borgmann@mail.de \ --to=ffmpeg-devel@ffmpeg.org \ --cc=thilo.borgmann@mail.de \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git