From patchwork Thu Jul 20 23:07:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 42880 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:672f:b0:130:ccc6:6c4b with SMTP id q47csp144853pzh; Thu, 20 Jul 2023 16:08:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlF7bnusIV1DLrTQi8oo4VRJaWs4uz8YIcZ20ILjyvt2a6bVd9ekP3aiZ0pqKaG9z/QzvpmV X-Received: by 2002:a17:907:7ba6:b0:99b:4867:5e1c with SMTP id ne38-20020a1709077ba600b0099b48675e1cmr4943674ejc.28.1689894537170; Thu, 20 Jul 2023 16:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689894537; cv=none; d=google.com; s=arc-20160816; b=QF76QonyxXL65sKcDjzGMB0RvHas5U5mlNUSBwj2kav9oiMXDSqJr3RVQqHGcvIDC/ sYp2UHCLh7bFGFtjQnKGYFPOeBEnVVyeQT5/Ra33KP3ClhMwbGrLF6phv39x2xRYbRSM dSdtRLXrZNRDqvllV5ODYd8bcFRxydFicR+QcOT09QVs3G0Qb6E+80L05jiQj0ImcwR6 YMJBQas6W1ML1ghvCZHflmtwfKz7p+/sL+r4j97xSBh61GsJoO4xXr1ZWJcilxBg2Cd5 bCKwM1NEBKvODcQncNfPGO3dwliBcRQmTDyoFlKCSbdDMC1SJr38FqeA79oYuyUexoCY zSUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=6AgBEOJGh322qHzqJMHARDsvULDvj4FKgKab2g9rSfk=; fh=HD4ndZ9hLL4mcfDFnlTmTEEgN7ZZ8c1Zu9bV17rPaE8=; b=PNeGA732xqeG7ou7199wth6iZUSZwShH1BzZcsu4Re4hcjMF2eVauq57wEbCDSJIEt qIskO7KOc11eL3i0En/Zs7gohrcOfG+2/taowzezcZ3xbmytoy2PDvrpBMCCoYcF0pa7 N3tCw+QwMZeMoKjvxmuPoQQky83AEJvqC9Tath8AtjNDQse2Mqk21iceNNh6wSH0M507 BYNd/x8aSx5t9E1r0SCp1vSqEXvD2v8akTjhjWIDArgxT09fO1N75etNrdhVlQrnz0WF 9zsE/FxnafXIyoxW6YY6JmbM/nLYTRwguyVrKXQE/pasPSw1a9x3mej3H4g1Y1LnZDzH P5hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=c63ko7vD; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kt1-20020a170906aac100b0099392706398si1315758ejb.231.2023.07.20.16.08.56; Thu, 20 Jul 2023 16:08:57 -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; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=c63ko7vD; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D8A3968C526; Fri, 21 Jul 2023 02:08:07 +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 9517168C637 for ; Fri, 21 Jul 2023 02:07:59 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout02.mail.de (Postfix) with ESMTP id AAD73A0AB5 for ; Fri, 21 Jul 2023 01:07:54 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix03.mail.de (Postfix) with ESMTP id 92843800C3 for ; Fri, 21 Jul 2023 01:07:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1689894474; bh=bp2pcYA0zxCpmXEotxIcHS84KvjBbUpQRvQW9slrvX0=; h=From:To:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=c63ko7vDa1ZQgc+yZTSc9GUca4ChHEoJKV9fJ5bBJ3xaVSgDZPpmZK6OYdbGEeimw C3Rc9Lx74/bHCXAWDDbsfi+DgTeb4+VDSIvT1nV+VsnJZrVM86Vh29K5stp4HK15Dx LPFRoVF7uoWk8GaWV+Tk2QrS1vV8XoxhK+hgmMtO+fEjEfGdQV4gQS2i6Xoq9WvnVr pbVelQuI09Dz6LkP6dkNKpZmvQ5/IWr1xpa3d3zk1Q6iGGjhH+s6ZNMJlb+pU+phHT rWtBVK0iONQaAE83A4naTreyKsRqLWHgLDICsJkVOQoO4VbbLqVJFMF1ongtHnBkdF OMHeS3wLS51Og== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtp04.mail.de (Postfix) with ESMTPSA id 5FC4EC009A for ; Fri, 21 Jul 2023 01:07:54 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Jul 2023 01:07:51 +0200 Message-Id: <20230720230752.68246-6-thilo.borgmann@mail.de> In-Reply-To: <20230720230752.68246-1-thilo.borgmann@mail.de> References: <20230720230752.68246-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: 6450 X-purgate-ID: 154282::1689894474-DA7FEC09-265AD269/0/0 Subject: [FFmpeg-devel] [PATCH v3 5/6] avcodec/webp: make init_canvas_frame static 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BcdXKsSho4iH --- libavcodec/webp.c | 143 +++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 8cc417af36..277f2c58bb 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1351,7 +1351,77 @@ static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, } return ret; } -int init_canvas_frame(WebPContext *s, int format, int key_frame); + +static int init_canvas_frame(WebPContext *s, int format, int key_frame) +{ + AVFrame *canvas = s->canvas_frame.f; + int height; + int ret; + + // canvas is needed only for animation + if (!(s->vp8x_flags & VP8X_FLAG_ANIMATION)) + return 0; + + // avoid init for non-key frames whose format and size did not change + if (!key_frame && + canvas->data[0] && + canvas->format == format && + canvas->width == s->canvas_width && + canvas->height == s->canvas_height) + return 0; + + // canvas changes within IPPP sequences will lose thread sync + // because of the ThreadFrame reallocation and will wait forever + // so if frame-threading is used, forbid canvas changes and unlock + // previous frames + if (!key_frame && canvas->data[0]) { + if (s->avctx->thread_count > 1) { + av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged. Use -threads 1 to try decoding with best effort.\n"); + // unlock previous frames that have sent an _await() call + ff_thread_report_progress(&s->canvas_frame, INT_MAX, 0); + return AVERROR_PATCHWELCOME; + } else { + // warn for damaged frames + av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged.\n"); + } + } + + s->avctx->pix_fmt = format; + canvas->format = format; + canvas->width = s->canvas_width; + canvas->height = s->canvas_height; + + // VP8 decoder changed the width and height in AVCodecContext. + // Change it back to the canvas size. + ret = ff_set_dimensions(s->avctx, s->canvas_width, s->canvas_height); + if (ret < 0) + return ret; + + ff_thread_release_ext_buffer(s->avctx, &s->canvas_frame); + ret = ff_thread_get_ext_buffer(s->avctx, &s->canvas_frame, AV_GET_BUFFER_FLAG_REF); + if (ret < 0) + return ret; + + if (canvas->format == AV_PIX_FMT_ARGB) { + height = canvas->height; + memset(canvas->data[0], 0, height * canvas->linesize[0]); + } else /* if (canvas->format == AV_PIX_FMT_YUVA420P) */ { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(canvas->format); + for (int comp = 0; comp < desc->nb_components; comp++) { + int plane = desc->comp[comp].plane; + + if (comp == 1 || comp == 2) + height = AV_CEIL_RSHIFT(canvas->height, desc->log2_chroma_h); + else + height = FFALIGN(canvas->height, 1 << desc->log2_chroma_h); + + memset(canvas->data[plane], s->transparent_yuva[plane], + height * canvas->linesize[plane]); + } + } + + return 0; +} static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int size, int *got_frame, int key_frame) @@ -1590,77 +1660,6 @@ exif_end: return size; } -int init_canvas_frame(WebPContext *s, int format, int key_frame) -{ - AVFrame *canvas = s->canvas_frame.f; - int height; - int ret; - - // canvas is needed only for animation - if (!(s->vp8x_flags & VP8X_FLAG_ANIMATION)) - return 0; - - // avoid init for non-key frames whose format and size did not change - if (!key_frame && - canvas->data[0] && - canvas->format == format && - canvas->width == s->canvas_width && - canvas->height == s->canvas_height) - return 0; - - // canvas changes within IPPP sequences will loose thread sync - // because of the ThreadFrame reallocation and will wait forever - // so if frame-threading is used, forbid canvas changes and unlock - // previous frames - if (!key_frame && canvas->data[0]) { - if (s->avctx->thread_count > 1) { - av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged. Use -threads 1 to try decoding with best effort.\n"); - // unlock previous frames that have sent an _await() call - ff_thread_report_progress(&s->canvas_frame, INT_MAX, 0); - return AVERROR_PATCHWELCOME; - } else { - // warn for damaged frames - av_log(s->avctx, AV_LOG_WARNING, "Canvas change detected. The output will be damaged.\n"); - } - } - - s->avctx->pix_fmt = format; - canvas->format = format; - canvas->width = s->canvas_width; - canvas->height = s->canvas_height; - - // VP8 decoder changed the width and height in AVCodecContext. - // Change it back to the canvas size. - ret = ff_set_dimensions(s->avctx, s->canvas_width, s->canvas_height); - if (ret < 0) - return ret; - - ff_thread_release_ext_buffer(s->avctx, &s->canvas_frame); - ret = ff_thread_get_ext_buffer(s->avctx, &s->canvas_frame, AV_GET_BUFFER_FLAG_REF); - if (ret < 0) - return ret; - - if (canvas->format == AV_PIX_FMT_ARGB) { - height = canvas->height; - memset(canvas->data[0], 0, height * canvas->linesize[0]); - } else /* if (canvas->format == AV_PIX_FMT_YUVA420P) */ { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(canvas->format); - for (int comp = 0; comp < desc->nb_components; comp++) { - int plane = desc->comp[comp].plane; - - if (comp == 1 || comp == 2) - height = AV_CEIL_RSHIFT(canvas->height, desc->log2_chroma_h); - else - height = FFALIGN(canvas->height, 1 << desc->log2_chroma_h); - - memset(canvas->data[plane], s->transparent_yuva[plane], - height * canvas->linesize[plane]); - } - } - - return 0; -} - /* * Blend src1 (foreground) and src2 (background) into dest, in ARGB format. * width, height are the dimensions of src1