From patchwork Fri Jun 21 10:43:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 50032 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ae71:0:b0:482:c625:d099 with SMTP id w17csp431782vqz; Fri, 21 Jun 2024 03:43:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVJ/6fKiU5pQ/dJPN+qTVuwzj65PpE9J5OWc3u7w4fjc8LqIoRoHhipg/ikWvsCeiJtzBTSMrZiAv1SONHHGLXIiRx1B3NM/M2Vw== X-Google-Smtp-Source: AGHT+IGSHGEm4pJc0wYnVl1QUljZZy43Z31OyxN57GuaJoVVXsIAWX5Zky6qYerK30GO9xfd7Bak X-Received: by 2002:a05:6512:3c9a:b0:52c:8c4d:f8d6 with SMTP id 2adb3069b0e04-52ccaa53d09mr7036622e87.45.1718966628662; Fri, 21 Jun 2024 03:43:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718966628; cv=none; d=google.com; s=arc-20160816; b=p0D7qfQ1dYJCssTZ0uwBYA8q75q2F3q5rgj6SoIXZuUQxBDQeKey/gBq3jj7xoBi7P TSHAnlhuoywpbaP92TQxEnUD8lqH4v9JeCxBnXdivzaga6jwgVrox46dhi5QZXRI6jQC qssgNB8hgwg6j1Unimpw4Tivf7s1/K5aVi9IUgVrJMFS91cnGjbljs8bxdi8EKEO1kJe YDujJSW+TiTegHjQOVt94BeEAGmRDUZg3ChoT9i6FYUDHBiYSZ13FgQx9nJ4rjovBXYx sxbtcKshyrWIQPJlzY9hskEekaQ7g98/S/2JaCggGdCNYAAMyoEWt7QysuploQwjdCsu jPYQ== 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=wB8TX99lTpkvDd/Gm9GFsJhcBPmLboi7z3F8Wu0sBrc=; fh=uZWItAgYCSLFS5Zum7Ip+PilGyWYOeCwun+We0BTHAs=; b=VfpVf2h06pTIHuvveUacO7EXBkWsyLxu2uquu/VLi9aZc5ythiV167IQHzGfs6wYll fqxlnBsqd2G0TRV4+o1H5pefrnKDwe+IBW6Po6nR51yOwSMN+kYk2IonvbO6DzJpbFAc edGXxkx60uEea8+zQ5hEJFC+7l9I/RTfIO487O2uZDCE8mjNHOef1YkRUHLLddNrPvaS 2Xzaekw336A8yyfpKgauVDZdD3bc7IhkSFi4pbqRbg64SHmrC0WyY3h7HYb+OnFfv09f zTSoF600+nn/y55h/jjaoprwCD0iVH5TbTT/yFN0GHMIIiarI0dlkX9ZiEyYvwN0TUQa 77RA==; 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 2adb3069b0e04-52cd643bfb8si356585e87.431.2024.06.21.03.43.48; Fri, 21 Jun 2024 03:43:48 -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 ABBD268D81C; Fri, 21 Jun 2024 13:43:35 +0300 (EEST) 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 AC62E68D7B9 for ; Fri, 21 Jun 2024 13:43:25 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout02.mail.de (Postfix) with ESMTP id 4D792240E47 for ; Fri, 21 Jun 2024 12:43:25 +0200 (CEST) Received: from smtp01.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix03.mail.de (Postfix) with ESMTP id 3456B80209 for ; Fri, 21 Jun 2024 12:43:25 +0200 (CEST) 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 80B21240A68 for ; Fri, 21 Jun 2024 12:43:24 +0200 (CEST) To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Jun 2024 12:43:17 +0200 Message-Id: <20240621104323.92453-3-thilo.borgmann@mail.de> In-Reply-To: <20240621104323.92453-1-thilo.borgmann@mail.de> References: <20240621104323.92453-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: 3847 X-purgate-ID: 154282::1718966604-E17EB338-08D6E00B/0/0 Subject: [FFmpeg-devel] [PATCH v13 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: r/+sRnJkA2Ql From: Thilo Borgmann via ffmpeg-devel --- libavcodec/webp.c | 50 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index af4ebcec27..c52b9732b4 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);