From patchwork Sun Dec 31 12:30:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 45427 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp5731655pzh; Sun, 31 Dec 2023 04:31:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtMIUKaMoNamzhMlanNSV6RsqgpLM34w6k9HiRBX3pNk0xj4JWa2OmVcLcYVyTPgGdVyuu X-Received: by 2002:a17:907:bb86:b0:a28:58c:78e8 with SMTP id xo6-20020a170907bb8600b00a28058c78e8mr30931ejc.54.1704025863839; Sun, 31 Dec 2023 04:31:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704025863; cv=none; d=google.com; s=arc-20160816; b=nTmtagrDNYG1GK7wzEqlNKmgBE68GeGeqcHt/v8fEQ4NFPKrRF6VHQucHZdw4rf46N n27FXgCmI4aqxt5qJ4rmo8dazsy3MMtTCSrJ+rnoHxaeXuJ88DyFoGSxlPCL0ZX6tcrZ D9fwUQqX38b8mPasDXH851rbtrGR0zuhEa5o1zzdOv985rcycNG6iPldJD27H2Qq8FYY HN3DOnrb2UfW7cIdCWMCMyw0efVePtPdfJR37op5qwdv+p8CtGr5yhFYmAv10LTb/+Qw heCoSw749tZ875fLT2Tm+SlD0KDkNsA52Dob4nNr9U59zUn9SWYVCIJ55fIdA3cmB1Gc y8rA== 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=hrWi/Spjt6W4bMdo+CKj2qX3x4GC79oMJy6yXU3v4+0=; fh=uZWItAgYCSLFS5Zum7Ip+PilGyWYOeCwun+We0BTHAs=; b=sk+iQ+4eRXsZ3AhwpTGBinPjFuBrqEJIvTl/lQXVX0HOhFZUgqA4nydyTTkyHQVTir jlFMVry5iM0Q8s9UT9Y2235bCyqmjxwCl4r2KsvqXq7gIHSN2mXx6nqPN5oLkIEJVqYE 0Zxeij+I3vWwxw3PwT5SSDxIHEyMDShuvFimYveoY67xlvnT6HcDHB1PNiRGW7NEUZas Xb1KF7BZ/Ze2ZlXY2GXTv+xxyrmmfVXrCV0BP+wm47IZM+Bo0BiLieRlv5S69e6w7Tz7 aHkAFtPlN/WimwJrZ4i5CINe8hNnk93yoCCSohGpnuHe4swQA4qLoe7ASvMgSXbEl+d+ fyDw== 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 bw3-20020a170906c1c300b00a26db4e7af1si6902835ejb.448.2023.12.31.04.31.03; Sun, 31 Dec 2023 04:31:03 -0800 (PST) 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 7AD6A68CD64; Sun, 31 Dec 2023 14:30:31 +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 5E28868CD0C for ; Sun, 31 Dec 2023 14:30:25 +0200 (EET) Received: from postfix01.mail.de (postfix01.bt.mail.de [10.0.121.125]) by shout02.mail.de (Postfix) with ESMTP id 0A2A1240BF2 for ; Sun, 31 Dec 2023 13:30:20 +0100 (CET) Received: from smtp01.mail.de (smtp02.bt.mail.de [10.0.121.212]) by postfix01.mail.de (Postfix) with ESMTP id E6EF5801EC for ; Sun, 31 Dec 2023 13:30:19 +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 BACF2240ACC for ; Sun, 31 Dec 2023 13:30:19 +0100 (CET) To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Dec 2023 13:30:14 +0100 Message-Id: <20231231123018.59035-3-thilo.borgmann@mail.de> In-Reply-To: <20231231123018.59035-1-thilo.borgmann@mail.de> References: <20231231123018.59035-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: 3782 X-purgate-ID: 154282::1704025819-B252C878-D5E727E2/0/0 Subject: [FFmpeg-devel] [PATCH v9 2/6] 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: 9NZocySmOjqU --- libavcodec/webp.c | 50 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 4fd107aa0c..58a20b73da 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, @@ -1533,11 +1553,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; } @@ -1546,6 +1583,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);