From patchwork Thu Jun 8 14:20:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 42010 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp434587pzb; Thu, 8 Jun 2023 07:21:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Z/NAsxjUGLshYSZ6Ki02Uy4BcR2XBI/SUdpGWa23QTcifBkUddQ/f1Y1IfpNchnMC+lQr X-Received: by 2002:a17:907:3f1c:b0:96a:fd8a:f840 with SMTP id hq28-20020a1709073f1c00b0096afd8af840mr10391051ejc.49.1686234086031; Thu, 08 Jun 2023 07:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686234086; cv=none; d=google.com; s=arc-20160816; b=llBkIGajL1NRUB/KcPL144XFyCONc34SUC/JQCgXV/m3QiZBqfPP8CMM1PdrdiwDdj vGSYd4RmITO5XIS5RNE5JksH35L+YAi9bInsqAg4e3mpaYJhOliE92NzCcpM9KYhiYnC x01x3QuZncV6vkysULV7gn6/+IbWlkFXzyvAZIFuD6pHIL6LlkwauQsF5ESKz4ye6SFw OW0Cd83d95+Lxk/w38rEr8XTphD/u7yqUEWFwyLzlzDqNou/Kjv1u1p55rMnQqNKJxJy gasg3/vuyD+zrp0uoT4kEwxzU3JnUCwe4ESDtG+OtebvDImN45jxxs9fdugruz5ErigP tbPw== 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=tGR90c8XikxcFWJXmVKW+B0fxO80rFVmJ3kqeowwsWs=; b=PGP18wYfPIO2X5OWY987AB5/BgZh0q1KRhBbQ9VnZhDHDv1BiJXoVlYH3bWF9ZHZtL EGcFbIoal+WnHg/19roO8oNhqFoZHnrrZe/z0Y8DMmukq4XcK3gr1ddbZDpY5y3k1Mfo bn/6bOC+vnRXPRQuOurJGlqdcPOzPTQxLWRPN73S3MCMSlt8IaBScSCbxz6LgSVwiX+N Ic+4zsVrUzxga/8d7A+bOvHTzD9wKSjzKBmB+1bpvdF1Jr+USe1e3eOM4AxcWzmzpTWl tRI9pwUkXJjNfoBv6cn2yEBTPnGtyPQXtn3h5ESPqD5SqfyJKRJ0TMdMGS3MlybXKFAq torQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=pV1iWwvN; 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=NONE sp=NONE 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 t19-20020a170906269300b0096a90bba2ddsi742864ejc.29.2023.06.08.07.21.25; Thu, 08 Jun 2023 07:21:26 -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=pV1iWwvN; 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=NONE sp=NONE 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 D7E1768C308; Thu, 8 Jun 2023 17:20:43 +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 4770C68C2E6 for ; Thu, 8 Jun 2023 17:20:37 +0300 (EEST) Received: from postfix03.mail.de (postfix03.bt.mail.de [10.0.121.127]) by shout02.mail.de (Postfix) with ESMTP id 21099A0631 for ; Thu, 8 Jun 2023 16:20:32 +0200 (CEST) Received: from smtp01.mail.de (smtp01.bt.mail.de [10.0.121.211]) by postfix03.mail.de (Postfix) with ESMTP id 0A96180229 for ; Thu, 8 Jun 2023 16:20:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1686234032; bh=OCb1Kt4K1lPDLsFB+fYaZtz+gNqHYdQ+1nOwqLG3MNQ=; h=From:To:Subject:Date:Message-Id:From:To:CC:Subject:Reply-To; b=pV1iWwvNsp/gO2kcNlfBXBA6Q4eccsCj0/+K7PaK3EXtZMglKefbIr7IG+mvOWVAP Ho3iLgey3NpwtQ05/1KIQu8j3l97bQGbsYONK/5cW2yC+JNxJZnXdGoUcpGatS8gS4 oOmqrg5QU4pWM0x69DBM61AIO+zFH8B2atJPcd+kh46ViUo13MJe/RytcQyvPHCtdS uFpAxmbmB/cxG1kwdT73mGm419h8e3tnKf+fnUL9o94nGQwE7f02JrIIwwrRA8y/gF RaQYSi9IIxjxbxavoVmuLYn2lwes0arPCJGFm90PVKd8iv/E6BKDYsvtTAxIZRXqal f6KdmMH8XnhrQ== 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 smtp01.mail.de (Postfix) with ESMTPSA id B6786100B7D for ; Thu, 8 Jun 2023 16:20:31 +0200 (CEST) From: Thilo Borgmann To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Jun 2023 16:20:29 +0200 Message-Id: <20230608142029.16564-5-thilo.borgmann@mail.de> In-Reply-To: <20230608142029.16564-1-thilo.borgmann@mail.de> References: <20230608142029.16564-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: 6446 X-purgate-ID: 154282::1686234031-077FA7B6-466E95DB/0/0 Subject: [FFmpeg-devel] [PATCH v1 4/4] 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: cY/dPUFZMsGx --- libavcodec/webp.c | 143 +++++++++++++++++++++++----------------------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/libavcodec/webp.c b/libavcodec/webp.c index bee43fcf19..d3e3f85dd3 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1337,7 +1337,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 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; +} static int webp_decode_frame_common(AVCodecContext *avctx, uint8_t *data, int size, int *got_frame, int key_frame) @@ -1577,77 +1647,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