From patchwork Thu Mar 28 14:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 47584 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1349601pzb; Thu, 28 Mar 2024 07:09:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV2VEevzOQRImVZ4MAE9jMPUF+nhfdz3dPq4BPdWhto8inagzCK9gBKv0w/Ovnatxw5AZvZ8hEUr1CPs2xMO876ANwzyRq8qa/YBg== X-Google-Smtp-Source: AGHT+IFTMcv9MeqGatUhk2D3iSWIA8zOZitKOKjgPpElZ2q26oVxORBGeNG2jVoi78HmHod7zMH3 X-Received: by 2002:a05:6402:5253:b0:56c:5863:b00a with SMTP id t19-20020a056402525300b0056c5863b00amr636502edd.1.1711634981669; Thu, 28 Mar 2024 07:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711634981; cv=none; d=google.com; s=arc-20160816; b=NlQlQ6oNFLRoWQYZJHamwm8srV2lm6m/Ab+hFSdP+4Txxb4WGDEdUJv0a8wcw1MaZO 6nci0T1pfnW+PZJvLXTTNuqEvFDiZuCYF7NyOnue9FQ5ZBW5r/lNydfxoHbfwaSeox0A kOujSevx7EyLoKbWdcQyouI4jR19F4UGWXuf/QT9Z6TmXA/xTCh53IJlwAe88POevV/2 RvDp/0u6brwMp5iQ9o73OdxDKUzJT0IQCnIOyQRH1E7tfEX8cXwl4W+T28yrdTBVE0uP KXXy1a2JZ7poYBe8pC8ZoUGeGT16/KB/bHnt98NF1Va3T/+o0q4wPHCm1aGywP1I7OEQ g8Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:delivered-to; bh=KaOLfJHcA6scDjoZthi7RCU2WrkWS3jkD2tYV0Gyx78=; fh=uZWItAgYCSLFS5Zum7Ip+PilGyWYOeCwun+We0BTHAs=; b=WIisu++TRlJB8eneEzJXhdFtC3s6o6poWv0BE8JbmznzyCGPwwI4Il9HsePv/Q21ay qWGHxxXDwJIewAqAeVTVExf7ELlYm7X7jufdLDlVpYkhiPlNfJuGZspjQ/epmtiSutqr 28BlULHPrefoMXta96lqDKVrqspkSdBgRMRL3T5j9ZCbrXRQCDdCR5qk2IVdWT7Hnshl 1zqZTF1FgdcVH3PgTdWKOavooz7KtrilHVyoWjxSCSrZlQ5EZDivqwC+5UeWi6MufD2N e7VvGQ0MbCT8Jfaou2CjdYVBy7rR2Vcelo4i2pIkFmjzp0/DnBYyVITQwhzA1kiDHMgE 69Qw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t10-20020a056402524a00b0056bc20c6e0esi824803edd.49.2024.03.28.07.09.41; Thu, 28 Mar 2024 07:09:41 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE65D68D717; Thu, 28 Mar 2024 16:09:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E289368D681 for ; Thu, 28 Mar 2024 16:09:05 +0200 (EET) Received: from postfix02.mail.de (postfix02.bt.mail.de [10.0.121.126]) by shout02.mail.de (Postfix) with ESMTP id 6FDCB240DF7 for ; Thu, 28 Mar 2024 15:08:59 +0100 (CET) Received: from smtp01.mail.de (smtp02.bt.mail.de [10.0.121.212]) by postfix02.mail.de (Postfix) with ESMTP id 556B5A03C4 for ; Thu, 28 Mar 2024 15:08:59 +0100 (CET) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp01.mail.de (Postfix) with ESMTPSA id 297EA240CFB for ; Thu, 28 Mar 2024 15:08:59 +0100 (CET) To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 15:08:52 +0100 Message-Id: <20240328140858.2521-3-thilo.borgmann@mail.de> In-Reply-To: <20240328140858.2521-1-thilo.borgmann@mail.de> References: <20240328140858.2521-1-thilo.borgmann@mail.de> MIME-Version: 1.0 X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 3780 X-purgate-ID: 154282::1711634939-FED2B878-D9B8ADEB/0/0 Subject: [FFmpeg-devel] [PATCH v11 2/8] avcodec/webp: separate VP8 decoding X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thilo Borgmann via ffmpeg-devel From: Thilo Borgmann Reply-To: FFmpeg development discussions and patches Cc: Thilo Borgmann Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: bFrvgfEb0h4Z --- 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);