From patchwork Mon Feb 5 19:41:40 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: 46056 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:7b08:b0:19e:8a94:b663 with SMTP id s8csp971999pzh; Mon, 5 Feb 2024 11:42:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5vgT5HcigbOKhTwshShfh9Enlg6kmznyADK8sEeB5RboQbj/kal+h+RYqdU6YFFXZ9Woh X-Received: by 2002:a17:906:b78e:b0:a35:a7ba:c647 with SMTP id dt14-20020a170906b78e00b00a35a7bac647mr658801ejb.3.1707162160086; Mon, 05 Feb 2024 11:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1707162160; cv=none; d=google.com; s=arc-20160816; b=tAUBNv0D1X1rcLF93nAyxarbqmAtPeKlkS9UBsWVYxXg+hM7OrJgjf+TW2HmBE/+aZ 0GD5HvPpDcsfblKAjTsVFMZE7qED4CZe95lbsK7y4t++Oa5Tlpamv80ra7ZFfYXlgdB6 8YusJWSuwwhfEO8JTsPBvxPFDGTKnWzfZGwjiCJNKiTKDK+IGFgmuLOIhigZC2SppnEF kd+wfMvs+VH+RyQpviDYqfdvbEGp85/a7uinMAljujSpJneXLWhvS13lITNdS0QkD0pu Vw4+epqbGY11MKmMHLkUrsTz/c2DY8UaxS/dTle6sHCG73+MBdXXllldJ6eZHsYPyvwV myiA== 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=8UkhZHUhXs2MLzhFxd0LSQHHK42W4WABsVri5VzOtHk=; fh=6UarRAnudHUwVDH3LMoHBuI1vFxTdIF5q7bS4cGa0uc=; b=z7wIt4DzH+jUJJr2jU8ZcQBcfohRwFKHxPyFzU2azTNxR8gJTNV23nOC5VVohsmWlk 4GvSdC9plorrN623rDUPqcA3lz4RRs9DIDqcfecO8kzJE2nw+6azaa9pizWAV8YmtkJN EcdoIg7xu9Lf7jm5uFvDZ+K/IeuWmxOqNEh4b3EwxZRVPTVTiolK0+DD4x3xEaHfqqxf ErLyiZiB9ieWUCKn3RkhySS23NE9ivAPbsCYF326z5bPCuOQiEcHiXdMCldHPH+dgHH4 fpmxyGqqQ+dUE7uBASm58eW8HEobyIPVB906wkkmUQprKeAoYoZxNK46oTrXrSTUVJO1 elyA==; 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 X-Forwarded-Encrypted: i=0; AJvYcCXkCoCxV+Z5w2CUL0sgg8DmgrUwjIv+Kw+7lNC4l94UmN+4VMfXSGbPceT6ANXBqt54wTUh2sQJ2FKbKafwJBE8h1Iz6Nrt3yz96OH6NRyObQgOQuqKHRtzaNqU98DcblbSNYIwGY3W1JxEAQuw0dly8j1s/He2ibOHxEM7MiFgQ9rSn+YNpRi2nrrvoWRJpkRSc4+6OSVafY2zZsmofo2aSVzvXog9tDUHDFGzJ5OzjihloZ1pvL4KRcBGHaOZNjFuKCofbyrHWG75/X1897sWjZ0CMrjv/tRIxokL/eNcTtzFGYujQjB6SCWK4VjbrsfgrqeYbhF3GN6Uu9SgPlLbZpUd/iRkIwwrABLWI9XIfpzJS60VCpXvfexZwcwvp1hLMqCVyZQJHsRh1TKTdxmVPr07ydyIaCLNo2jCXmrhGOUNUg1+vrE06SVme1ASQRb+9C1KF0XzmwUJ0NhHGUatT35hj15VASLdSuGwkY8AMTgPBB6u0J98txp+ivx/pd/D8PsjVoB91jixDkBjKsu6yDFnYKlCr4r8a1rfv3Zn/3gMOCpOHLzyCwEGt3jHbva8KiqT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ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gr7-20020a170906e2c700b00a298b1de849si164956ejb.648.2024.02.05.11.42.39; Mon, 05 Feb 2024 11:42:40 -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 C96A268D199; Mon, 5 Feb 2024 21:41:57 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout01.mail.de (shout01.mail.de [62.201.172.24]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32D5D68D17D for ; Mon, 5 Feb 2024 21:41:51 +0200 (EET) Received: from postfix02.mail.de (postfix02.bt.mail.de [10.0.121.126]) by shout01.mail.de (Postfix) with ESMTP id 218FF240D15 for ; Mon, 5 Feb 2024 20:41:46 +0100 (CET) Received: from smtp01.mail.de (smtp03.bt.mail.de [10.0.121.213]) by postfix02.mail.de (Postfix) with ESMTP id 08B50A00E2 for ; Mon, 5 Feb 2024 20:41:46 +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 9D940240A70 for ; Mon, 5 Feb 2024 20:41:45 +0100 (CET) To: ffmpeg-devel@ffmpeg.org Date: Mon, 5 Feb 2024 20:41:40 +0100 Message-Id: <20240205194142.37049-4-thilo.borgmann@mail.de> In-Reply-To: <20240205194142.37049-1-thilo.borgmann@mail.de> References: <20240205194142.37049-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: 6479 X-purgate-ID: 154282::1707162105-30E261F9-DC96EB2E/0/0 Subject: [FFmpeg-devel] [PATCH v10 3/5] 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: , 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: 3dBLiYIjuWpH From: Thilo Borgmann --- libavcodec/webp.c | 142 +++++++++++++++++++++++----------------------- 1 file changed, 70 insertions(+), 72 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 4119ae679d..0931112546 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1358,7 +1358,76 @@ 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->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) @@ -1597,77 +1666,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