From: Thilo Borgmann via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Thilo Borgmann <thilo.borgmann@mail.de>
Subject: [FFmpeg-devel] [PATCH v11 2/8] avcodec/webp: separate VP8 decoding
Date: Thu, 28 Mar 2024 15:08:52 +0100
Message-ID: <20240328140858.2521-3-thilo.borgmann@mail.de> (raw)
In-Reply-To: <20240328140858.2521-1-thilo.borgmann@mail.de>
---
libavcodec/webp.c | 50 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 44 insertions(+), 6 deletions(-)
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 2301699e5a..d6af48585e 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -194,6 +194,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 */
@@ -1298,12 +1299,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");
@@ -1314,14 +1316,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,
@@ -1538,11 +1558,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;
}
@@ -1551,6 +1588,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.39.3 (Apple Git-146)
_______________________________________________
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-03-28 14:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-28 14:08 [FFmpeg-devel] [PATCH v11 0/8] webp: add support for animated WebP decoding Thilo Borgmann via ffmpeg-devel
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 1/8] avcodec/webp: remove unused definitions Thilo Borgmann via ffmpeg-devel
2024-03-28 14:08 ` Thilo Borgmann via ffmpeg-devel [this message]
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 3/8] avcodec/bsf: Add awebp2webp bitstream filter Thilo Borgmann via ffmpeg-devel
2024-03-28 18:11 ` Stefano Sabatini
2024-03-29 10:41 ` Thilo Borgmann via ffmpeg-devel
2024-03-29 13:39 ` Andreas Rheinhardt
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 4/8] libavcodec/webp: add support for animated WebP Thilo Borgmann via ffmpeg-devel
2024-04-17 17:30 ` James Zern via ffmpeg-devel
2024-04-17 19:27 ` Thilo Borgmann via ffmpeg-devel
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 5/8] avcodec/webp: make init_canvas_frame static Thilo Borgmann via ffmpeg-devel
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 6/8] libavformat/webp: add WebP demuxer Thilo Borgmann via ffmpeg-devel
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 7/8] fate: add test for animated WebP Thilo Borgmann via ffmpeg-devel
2024-03-28 14:08 ` [FFmpeg-devel] [PATCH v11 8/8] avcodec/webp: export XMP metadata Thilo Borgmann 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=20240328140858.2521-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