From patchwork Fri Jun 21 10:43:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 50035 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:ae71:0:b0:482:c625:d099 with SMTP id w17csp432040vqz; Fri, 21 Jun 2024 03:44:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXiaNn382exCpP4a80VjDFu9guMOnMhS9YeKjT+QGigfN90qKmLpX/X6U2uSpcyMns54kOoirudOV8p69KD4h0hQEo9s2j0Q7WnbQ== X-Google-Smtp-Source: AGHT+IHcJwBNDrOwKzNQvYtJDwQbXxocBHnVBjy2TfMjMfbQCsif4JoG6sogeM0anzRqP39VkjIy X-Received: by 2002:a17:906:4fd6:b0:a6f:b7e4:3ac5 with SMTP id a640c23a62f3a-a6fb7e43d0bmr452087866b.6.1718966658256; Fri, 21 Jun 2024 03:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718966658; cv=none; d=google.com; s=arc-20160816; b=vOXrE0tVnpUS3dceh3PxTG1zZ1Ks4dpkAJH5IVyYMOG1ihxVj+/12PKGD38Bj43oA9 36rSyYaPS0Ln+sGzuGK+exwld2J9fDF+J25CbtgwIggb8b0aviUZhu2sTHOsC6YPveuR 7th3dJ8nAihc3O4PdcvytgF3sw1pQiFIuNlcXko2EWrEk4vW5Q1MKOz2Ha88h7s76iLh 4FkmkugSPX8xYCjoxfWwFsU8UTohhKt0Bd3xvLRaYrYfrMklpojUF7uJ7cKrd/whSMmF ly+w5CarjsYPOeXRCouUJAs7E2FATrPSHSMyGuBVtChF9oRom9829CQdug9B8Dozw8bs 3aTg== 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=Hc9vP8CezwxkSv1+U4DMS5VQj+j+Kfu84j6u9bAOxcQ=; fh=uZWItAgYCSLFS5Zum7Ip+PilGyWYOeCwun+We0BTHAs=; b=FSUu1OCxMMTc2oTjiopVQDNhrZ7MfHTqc0EQyAGNPjKHmLnWJ5gCP7nNGJ5LyqTqSa /6aaEcWSqkO3yFst2C9gQO6MAdiKmvgnuN7vq8zAfGDJ9uWMaKocG72zi+8442lQgNK/ kT+sCPd6mKQMM2zLCeZfVQmYo0MiZsSSsMBYM3uN+urXIYb5iHGiIYwWh2RuJV5UzXex DkIgbXP5GzTAuVVn1UDq3NIdIjula9dH7mJIHi2tLQHy5yEpwfAS34i41GoqP37Z0Q6z M90Q2JQ+Vso+H0w+H/hfuPxbeOrwHhRyr5WlHa+s2tRN+Lw9bL0p+jQdyr8ExI0AH6Rw qoXA==; 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 a640c23a62f3a-a6fcf579698si70472766b.794.2024.06.21.03.44.17; Fri, 21 Jun 2024 03:44:18 -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 AFE6368D7EA; Fri, 21 Jun 2024 13:43:40 +0300 (EEST) 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 A8AA568D81A for ; Fri, 21 Jun 2024 13:43:30 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout01.mail.de (Postfix) with ESMTP id A4472240EA1 for ; Fri, 21 Jun 2024 12:43:26 +0200 (CEST) Received: from smtp01.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix03.mail.de (Postfix) with ESMTP id 8BCC080209 for ; Fri, 21 Jun 2024 12:43:26 +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 0130D240AD7 for ; Fri, 21 Jun 2024 12:43:25 +0200 (CEST) To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Jun 2024 12:43:20 +0200 Message-Id: <20240621104323.92453-6-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: 6528 X-purgate-ID: 154282::1718966606-E17EB338-8081FF3F/0/0 Subject: [FFmpeg-devel] [PATCH v13 5/8] 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: Thilo Borgmann Reply-To: FFmpeg development discussions and patches Cc: Thilo Borgmann Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nfGNppFeOWQI From: Thilo Borgmann via ffmpeg-devel --- libavcodec/webp.c | 146 +++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 74 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 146d5cb393..bacf605ff2 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1383,7 +1383,78 @@ 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 && + 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) { + 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_progress_frame_report(&s->canvas_frame, INT_MAX); + 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; + + // 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_progress_frame_unref(&s->canvas_frame); + ret = ff_progress_frame_get_buffer(s->avctx, &s->canvas_frame, AV_GET_BUFFER_FLAG_REF); + if (ret < 0) + return ret; + + canvas = s->canvas_frame.f; + canvas->format = format; + canvas->duration = s->duration; + canvas->width = s->canvas_width; + canvas->height = s->canvas_height; + + 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, AVFrame *p) @@ -1629,79 +1700,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 && - 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) { - 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_progress_frame_report(&s->canvas_frame, INT_MAX); - 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; - - // 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_progress_frame_unref(&s->canvas_frame); - ret = ff_progress_frame_get_buffer(s->avctx, &s->canvas_frame, AV_GET_BUFFER_FLAG_REF); - if (ret < 0) - return ret; - - canvas = s->canvas_frame.f; - canvas->format = format; - canvas->duration = s->duration; - canvas->width = s->canvas_width; - canvas->height = s->canvas_height; - - 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