From patchwork Wed Apr 17 19:19:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Felix de Souza via ffmpeg-devel X-Patchwork-Id: 48116 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:ce4e:b0:1a9:af23:56c1 with SMTP id id14csp1232404pzb; Wed, 17 Apr 2024 12:20:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVBGiKbzoo6s/3PDsHRBaJsA4C7qmbwH0ROB21U3hKCiOcBrLLOr5R+UijU2soveybAppT+OQZaavcTMa/igvuPHN6hhD3gw0WpNw== X-Google-Smtp-Source: AGHT+IEqPF3RKtPF4F45qLPKJs4LRc1oHuwkLayeAHDUQbQF57+g7Vu98apNRgMNBpmiM3BmMgj6 X-Received: by 2002:a17:906:7188:b0:a52:5613:67dc with SMTP id h8-20020a170906718800b00a52561367dcmr283820ejk.5.1713381656204; Wed, 17 Apr 2024 12:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713381656; cv=none; d=google.com; s=arc-20160816; b=zHRlNhjtSd8gJfgVg2zLQkg/ph7Dc2lO+Obx9V0lcHJOUQ3suqEp+owDT5CY8ZY9ZC eL6JqUYL4ELZwWwCZpGnMSiJxZr/CURp3bMMQXhmSVZlOahfu88KP8A4N90qkQQCc/Q0 8rcqIGj9mP+PtVf++SLxqhYGflPlUvlpIHXAcxDTQC5WsEZEDVDqsUVULoC8enwhg4jb PAVOroidjO/NkVXhOZ8rl9yftPzrDf7SyS/el/dGkm/NVIW9A9mfieWHRQ0d91DizQMd FEu3f/oq7x6UAq3D6MIemFbczOR1CfdEJ+pPQFp2WHm/OCyL1PQIpA7iliFnP+ATnd0n Badw== 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=prIPbC0iwy9b0biMsj+vQIOwpCULTTriO36koMfoxvc=; fh=XuleKIHF9MUFgiZ1qrMyNqDu84gapm8sSgQI0zYajBE=; b=P82jqLAcRCApno9aEWaj0y88rKpyN6L8vhLBfXa+ROUGiHw68Nkonl7EHWOK9T+PNE H40pQ8vlouegpMbnyjfy605aHeULTnSiW0ZQ6OL2BBNUqHYbJzSoUgRXNGAB54JdwpCI SEtCXglcdMa5p+9wCL0hAHsB222EqdIb+0VIwetIV80IL5GWPbBBELZ+mZbiMVZQJvx3 uU4IPSPNxKd85xwRm3Li9xiZfRKc2v9oXyQAwyFqsxW2eS2q1VkVbNpWaibAfaT3vILG BoxQP/TaX5f+oPOsjLTujCHUihqtpbiRVN24SSd9eLulf7SuW14AV8849w6fuZHApaNx kuSw==; 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 ay9-20020a170906d28900b00a51aad6c6dfsi7256500ejb.980.2024.04.17.12.20.55; Wed, 17 Apr 2024 12:20:56 -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 61ACA68D39B; Wed, 17 Apr 2024 22:20:50 +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 1D74C68D2EE for ; Wed, 17 Apr 2024 22:20:43 +0300 (EEST) Received: from postfix01.mail.de (postfix01.bt.mail.de [10.0.121.125]) by shout02.mail.de (Postfix) with ESMTP id C0BF4240E36 for ; Wed, 17 Apr 2024 21:20:42 +0200 (CEST) Received: from smtp01.mail.de (smtp03.bt.mail.de [10.0.121.213]) by postfix01.mail.de (Postfix) with ESMTP id A7F59801CF for ; Wed, 17 Apr 2024 21:20:42 +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 0FAAF240A6D for ; Wed, 17 Apr 2024 21:20:31 +0200 (CEST) To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Apr 2024 12:19:58 -0700 Message-ID: <20240417192012.22436-3-thilo.borgmann@mail.de> In-Reply-To: <20240417192012.22436-1-thilo.borgmann@mail.de> References: <20240417192012.22436-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: 3831 X-purgate-ID: 154282::1713381642-551C31F9-815AA1A6/0/0 Subject: [FFmpeg-devel] [PATCH v12 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: Diego Felix de Souza via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: thilo.borgmann@mail.de Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: DQjODDM5LPSE 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 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);