From patchwork Mon Jul 22 09:43:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50678 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a742:0:b0:482:c625:d099 with SMTP id f2csp1905644vqm; Mon, 22 Jul 2024 02:51:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU0STwowpq5RLQc+ywUJhrLVq16MARUB3Idr4eS5M0yl4dmDgtWpM8LYuQHbvaU/+ReKabGqu+sp4WRSbA1PmXP59MQctXMpR64ZA== X-Google-Smtp-Source: AGHT+IEbUsFRDQKUNsMD6SOFWHWjdk0n5AsGMmp3shsnhdjbUNA/dppqCSNNgqoyP/ybTAxjBGe6 X-Received: by 2002:a17:907:d17:b0:a72:b43c:72f2 with SMTP id a640c23a62f3a-a7a41a965b8mr794146366b.2.1721641910419; Mon, 22 Jul 2024 02:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721641910; cv=none; d=google.com; s=arc-20160816; b=bfWDt97sZNYeljMRd0zPlbYNeKAmNp/slbkUFfZ2FaiUtk2kAv6PEXJkgbrdZIKaB7 lV6NKKmBFZxOW7tKtbECJh7QDa1W6Zzti66wrHiG7a9EJ3HcHEWIVCFTE5yQTV03lm7I zuYPR89ZcLfbg1MQZgg3WQJKV5ROE/WKN3eBf7GJHeG82qowFL8iSkGoplT/JsDUELTa 8HsVi/rfqE2SXtuH/7Rgj66eGo1DtzugLlplbJaPTd1YuII1qlzpgxCnKLUnjBtVjc3O O5WtwL8Zjis5so5OwS5Emo1YMI7yX10dLzJQ31izDXbq0UWQ3cbPlDpNvMjPGKoNpEPU VDag== 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=yevyi0W5/v6G/j7qkhgDHh9wSdKLUgbVpsR3IW5dqv0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cWPq5bAyQNsDugkzsYjsO7yFW8SxHC0PWbUMU1mAXNwSpV31uOfloM+N1XIRUnB/dH aVDD5h7OZ4Wlph3qoYsHU94F3ELTv2Z8lln5HqfMpo6pk7EIDnfrLsc8QJV8DdDNbIaB nf4TU9/6GbwFjl1+K6G/VMJ5amkvqy4VbyECqgq8cp7aDkNmRxzYrKSYfgYrft4BQ0DL eJbHGq0HV/49fZ8cdcVA+L9D3WAfXsGuBYOeIcuNCOb58P+pV+X2AUA68Gc0GcDQBgvA BclFUr4W9ELV8jvHRExanaDP6dRtsZ2fsRbUHKuUgHDA88K8KCzO2h0oSL5Ob8E+AqgP mGoA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=RJZmAhe1; 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-a7a3c928447si359639966b.655.2024.07.22.02.51.50; Mon, 22 Jul 2024 02:51:50 -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=@khirnov.net header.s=mail header.b=RJZmAhe1; 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 1EDCA68D6C1; Mon, 22 Jul 2024 12:43:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0225968D67F for ; Mon, 22 Jul 2024 12:43:42 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=RJZmAhe1; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 4C5504DE4 for ; Mon, 22 Jul 2024 11:43:39 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id byH8_P8qIpEJ for ; Mon, 22 Jul 2024 11:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721641418; bh=gxPnGzBOjPuDzm5kfjby9GF9gd6KoiBkI1BdpBut2gY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RJZmAhe1J1WOxY2L9TYoDnkIXJWHcgH7F//GUErwtG9ha/UpSVFrIHn2RjW0VU2Ni eHwS4vefAlvYUGqBABl4yAo4QYnsXiHFmJuhEQZXxVvxrdA6hs/me5ePXBPSyQ8H3Y uvGbn9uDsmh2nb2Khq6pAEA8OK2m1xTlpSSW0ypjay9TcEHT6P1by6U09C4moI8E7K 2jdQuMs2oDZaxtUH7MU5DCrTTGoQxRzcLwlAUis/yqLfgdhFY0PXRRIaYienn6gDLU dYVkCP2l7oujIr81uLjpfY2eZ7N6mnnJ+gdaIPV53lyw1KHfd28PMsxnfvF5lOGEV8 zXloRCt7Tfrbw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 750D74DDB for ; Mon, 22 Jul 2024 11:43:37 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 306413A02CA for ; Mon, 22 Jul 2024 11:43:31 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Jul 2024 11:43:20 +0200 Message-ID: <20240722094322.28916-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240717205156.GT4991@pb2> References: <20240717205156.GT4991@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/3] lavc/ffv1dec: drop code handling AV_PIX_FMT_FLAG_PAL 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: c3ziryaLpUtF No paletted pixel formats are supported by the decoder. --- libavcodec/ffv1dec.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 7dc4a537a9..aa2c35880e 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -981,10 +981,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); } - if (desc->flags & AV_PIX_FMT_FLAG_PAL) { - dst[1] = p->data[1]; - src[1] = f->last_picture.f->data[1]; - } + av_image_copy(dst, p->linesize, src, f->last_picture.f->linesize, avctx->pix_fmt, From patchwork Mon Jul 22 09:43:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50676 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a742:0:b0:482:c625:d099 with SMTP id f2csp1902638vqm; Mon, 22 Jul 2024 02:44:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV/+RIYrtgIKJgqurK7cQPJsUSbLjwwqgZwejAtGAsrlND5p0ckip1u39VTr5Vvo6C2iblw4NOOVMZJNBxrwaunzuanUihDsjLvqA== X-Google-Smtp-Source: AGHT+IHfl4Rst0Pd7XLJFZXKMdebkqya4t0Cj1ljHgnuQBYWby06U5WcP7G9kzjtRgS3ggBbo9Lx X-Received: by 2002:a05:6512:b07:b0:52c:90b6:170f with SMTP id 2adb3069b0e04-52efb7699a4mr4333989e87.29.1721641443958; Mon, 22 Jul 2024 02:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721641443; cv=none; d=google.com; s=arc-20160816; b=Jf09+L3I+1qjEmB9SMhTw4p/zkLfQmCuKwL7jWrw5qk3T2rVsbxrAMt+ovkpC1d/pm i1r7CKpL9BazJw5jo4GU1nFOGUaQsIS/2chm5mpmFYDS/jQ1JNXrPmMRFv74AqL/OahA wa3Vfu2XkubTLc4V0/u6UKMD2+5H468RX5F7du7s/uEffrhxJvNDHtxieTSl0ExhLlEJ VT/IXNAO6YS8NVw6v6hgQBBsAJP1MboGigx6gDveurveMyD76uVqtnX7KQnszcdSiaAA Z046rseNj9QlXUTmz/iE6uk/HixJmr1vDE2NxMA8gkViDwgBbROSDTybUtc0dWMIBRT9 XNrA== 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=zBVzOraAmgh7Q5uiGNXkBSQ4mp4dmw01m7lCjjNUC4U=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=WqIdsLb0wpVOZLMnXLbq9D6VhBXzhCy9h2CuEoXwe6QfrhjOh9WQya5b7FMcBq9Zmz m3XFFN2FM0Xbsq+SLpCdPTJmFTGhpkFlHQFUp2XBdpCYKqHS7fcyWRvOpJU/x3VVTCGU o6le7R+oDyByaf+BXkOWbRSqC7vurKAEPNwEaWKwvPvKDLJxXXrTjjw0llc05Ybhyb8C wkniH3of88cVTXoX/orD+uOxhqeCutE0OxDfBbM25xnZSecJGP03mDVjbm6DYjGJ5iy4 6xxPZa3GqB/Lnhon/8gTqZWjAAyM+HYqgomIz+fgX92HmP7P2d9/tzAZ349+P+0kxphW 917A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=qt3eQ5R2; 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 2adb3069b0e04-52fc1eb6702si172673e87.62.2024.07.22.02.44.03; Mon, 22 Jul 2024 02:44:03 -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=@khirnov.net header.s=mail header.b=qt3eQ5R2; 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 5C2D268D678; Mon, 22 Jul 2024 12:43:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E45B268D553 for ; Mon, 22 Jul 2024 12:43:42 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=qt3eQ5R2; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 4F8804DE7 for ; Mon, 22 Jul 2024 11:43:39 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id z-6SSjbeyEd5 for ; Mon, 22 Jul 2024 11:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721641418; bh=fjaYtA8S2N9NYDtTE/WWXbJ+4Ue/CjJ1kdALTdKSngY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qt3eQ5R2DbTtBARXkIMU6nIFLrc4uU8qnFFTCa8kw8nLtwEaamsCpVruihtvoP4Ro aQ09QUai/JdU8oERKIlpwgVZHqrKtWNqya2r9PqDlAv0GUd2tyKJiL5/ysODSUbxoD cYRQapAPZfLhb5hyXha58ma2c1wxbYtyNmHteGyTZhHCFV+jpVPdRttpT7baZ2ij/l zd1fLb1prp78Gqs/IyTtacjmxLtgShZm3gaE+wqDjmPdGgqdZnC4BCD1/IwEsliqc1 r+HeM9Xfp0y7b8K0PZxA1HvWL/hI4ibfpodUp9K2XYzut1XH3R2sjcOiK4WA+KdAh5 BDhFJMe+Ika/g== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 73B8F25F for ; Mon, 22 Jul 2024 11:43:37 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3E1413A031C for ; Mon, 22 Jul 2024 11:43:31 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Jul 2024 11:43:21 +0200 Message-ID: <20240722094322.28916-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240722094322.28916-1-anton@khirnov.net> References: <20240717205156.GT4991@pb2> <20240722094322.28916-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] lavc/ffv1: move damage handling code to decode_slice() 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: LtISNQ0oC9zS There is no reason to delay it and this is a more natural place for this code. --- libavcodec/ffv1dec.c | 53 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index aa2c35880e..5821a4156a 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -290,7 +290,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) { ff_ffv1_clear_slice_state(f, sc); } else if (sc->slice_damaged) { - return AVERROR_INVALIDDATA; + goto handle_damage; } width = sc->slice_width; @@ -347,6 +347,32 @@ static int decode_slice(AVCodecContext *c, void *arg) } } +handle_damage: + if (sc->slice_damaged && f->last_picture.f) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->pix_fmt); + const uint8_t *src[4]; + uint8_t *dst[4]; + + ff_progress_frame_await(&f->last_picture, si); + + for (int j = 0; j < desc->nb_components; j++) { + int pixshift = desc->comp[j].depth > 8; + int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0; + int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0; + dst[j] = p->data[j] + p->linesize[j] * + (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); + src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] * + (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); + + } + + av_image_copy(dst, p->linesize, src, + f->last_picture.f->linesize, + c->pix_fmt, + sc->slice_width, + sc->slice_height); + } + ff_progress_frame_report(&f->picture, si); return 0; @@ -964,31 +990,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, f->slice_count, sizeof(*f->slices)); - for (int i = f->slice_count - 1; i >= 0; i--) { - FFV1SliceContext *sc = &f->slices[i]; - if (sc->slice_damaged && f->last_picture.f) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); - const uint8_t *src[4]; - uint8_t *dst[4]; - ff_progress_frame_await(&f->last_picture, INT_MAX); - for (int j = 0; j < desc->nb_components; j++) { - int pixshift = desc->comp[j].depth > 8; - int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0; - int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0; - dst[j] = p->data[j] + p->linesize[j] * - (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); - src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] * - (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); - - } - - av_image_copy(dst, p->linesize, src, - f->last_picture.f->linesize, - avctx->pix_fmt, - sc->slice_width, - sc->slice_height); - } - } ff_progress_frame_report(&f->picture, INT_MAX); ff_progress_frame_unref(&f->last_picture); From patchwork Mon Jul 22 09:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50677 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:a742:0:b0:482:c625:d099 with SMTP id f2csp1902716vqm; Mon, 22 Jul 2024 02:44:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXUDed44eS+QvYs8KngSpMZvvPtdBBbUjhiFHlh7pAlKGgrk9Xc26e4+5hM3TJ05Vqw0pmfPaXtsd/9s81v66SqZzxTwuafNrMglg== X-Google-Smtp-Source: AGHT+IFEd+mcoaORWPuQtjWkpfmE7YP71FWj+wLu9edoFlVOqIvSLWPN96Q9P9To0rABXw1lcMlo X-Received: by 2002:a5d:47a7:0:b0:368:4def:921a with SMTP id ffacd0b85a97d-369bb2b3d24mr6126104f8f.48.1721641453200; Mon, 22 Jul 2024 02:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721641453; cv=none; d=google.com; s=arc-20160816; b=HBmW2VaD5nY9eaKT+FRO1Ks+otL09VAUnl4hYk+9XUTeKApatXsT/FhuQDta/uA6PL oN4HzrQanKIkOcORtLuTDVbzMgkNnSQw2qtVqjRlqrgw6TquYvjXyEaE3P1VjyH6gz7I fLzW6cIHhpKV9ICSCeIoChg8iS9JmdNDVHXwmhP3x/iGMtXS8ZXeZlkNouVF5ZOuhJgK SahfnXU+LSMMujujAn7vEjwhilNN7PLdI3uBBw2j5dC259suX37ovGH99Xo3V8SE8+PD Fj42vTo8gO0xxP51SCZ+egHrMR3xZ3MKjhNwe50MJMtGn5rjxu0DGC0h9PmrFfRPjeXW BZQg== 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=UEqMYUhB7dAcOK9kaAyq1ENlcV4WaYKxyyCw/2sOi1s=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=qVAZsau5TGHn+kjaY2SRk9s59jgBpZVm5tVU76sCuu4Mr1Jo77pEA/Oeo8i9PPdgIh jvN8pqCrGzYMuTPIj2r1TBWo6y2HE0B+lE3TwyhIiM7oR617pWjb+FVClGdTBU36Mdho 2PtCu3dtJ0GEnsSKFods8GrGUz/ACqCDJTal9NO0gRCJIRb28rvJuTxPhtsHsJ8731b9 s0mKye3hi3ORrEX7up9M7t4pbOAXw2PSAryT8Q6PK2txZt0r8mWdi/shJqrKtBQtms2K lV6DoHDoBeGo5ip/GadA+vbqtV0W37GUF8TWQpW6//0znWOyNSRS2E51xuQUFsspDBMa Lg4w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=OokbjicT; 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-a7a3c95100fsi358712166b.748.2024.07.22.02.44.12; Mon, 22 Jul 2024 02:44:13 -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=@khirnov.net header.s=mail header.b=OokbjicT; 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 9822D68D6FA; Mon, 22 Jul 2024 12:43:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E755168D645 for ; Mon, 22 Jul 2024 12:43:42 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=OokbjicT; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 0553625F for ; Mon, 22 Jul 2024 11:43:40 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id jjmyoVjnBSUz for ; Mon, 22 Jul 2024 11:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721641418; bh=NvySu4ojiYbj4Ubq1kttwMakuc7dAP6jT6hbtoWZaCg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OokbjicTqw0hEN01MPB/Lz/YFvKTLSR1VJIK/NwF1Tz5QutYSQdYQotThJABdLjLn OnjCbwiOjr4h2MAfmFYxMDAN/4UlCy51JdLLHgirklJENaGzqJ3i9Th2E1baQgGUjC 3tRnfPyrZSSZpV7594o+uwGBGA38+WxBjtW5TZDYm92ZrdzxzaAi+1t8ESfaJdUVao WYRTnT6Qhl2LbwtfggZvGwdzIRRP2KGd92pYC/OhAXOFPoxzGhWcY3rJzGSbgUWdvn vASSHd9t9Y/g7MPlSf7eoMrUJoo+C7e9e/Skm7Luspz6/r0ooUgV0fwvbZFe2FU8UE EsTPPaWCKnluQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 7662D4DDE for ; Mon, 22 Jul 2024 11:43:37 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 499CA3A083A for ; Mon, 22 Jul 2024 11:43:31 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Jul 2024 11:43:22 +0200 Message-ID: <20240722094322.28916-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240722094322.28916-1-anton@khirnov.net> References: <20240717205156.GT4991@pb2> <20240722094322.28916-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] lavc/ffv1dec: fix races in accessing FFV1SliceContext.slice_damaged 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: 21KQuhQHuL01 That variable is shared between frame threads in the same defective way described in the previous commit. Fix it by adding a RefStruct-managed arrays of flags that is propagated across frame threads in the standard manner. Remove now-unused FFV1Context.fsrc --- libavcodec/ffv1.c | 2 ++ libavcodec/ffv1.h | 9 ++++++++- libavcodec/ffv1dec.c | 26 +++++++++++++------------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 9c219b5ddb..333fb3d79b 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -214,6 +214,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) ff_refstruct_unref(&sc->plane); } + ff_refstruct_unref(&s->slice_damaged); + av_freep(&avctx->stats_out); for (j = 0; j < s->quant_table_count; j++) { av_freep(&s->initial_states[j]); diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index edc3f6aef0..92c629c823 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -118,7 +118,6 @@ typedef struct FFV1Context { int64_t picture_number; int key_frame; ProgressFrame picture, last_picture; - struct FFV1Context *fsrc; const AVFrame *cur_enc_frame; int plane_count; @@ -148,6 +147,14 @@ typedef struct FFV1Context { int num_h_slices; FFV1SliceContext *slices; + /* RefStruct object, per-slice damage flags shared between frame threads. + * + * After a frame thread marks some slice as finished with + * ff_progress_frame_report(), the corresponding array element must not be + * accessed by this thread anymore, as from then on it is owned by the next + * thread. + */ + uint8_t *slice_damaged; } FFV1Context; int ff_ffv1_common_init(AVCodecContext *avctx); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 5821a4156a..a69f18e252 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -263,15 +263,10 @@ static int decode_slice(AVCodecContext *c, void *arg) const int si = sc - f->slices; GetBitContext gb; - if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) + if (!(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) ff_progress_frame_await(&f->last_picture, si); - if (f->fsrc) { - const FFV1SliceContext *scsrc = &f->fsrc->slices[si]; - - if (!(p->flags & AV_FRAME_FLAG_KEY)) - sc->slice_damaged |= scsrc->slice_damaged; - } + sc->slice_damaged |= f->slice_damaged[si]; sc->slice_rct_by_coef = 1; sc->slice_rct_ry_coef = 1; @@ -373,6 +368,8 @@ handle_damage: sc->slice_height); } + f->slice_damaged[si] = sc->slice_damaged; + ff_progress_frame_report(&f->picture, si); return 0; @@ -793,11 +790,14 @@ static int read_header(FFV1Context *f) return AVERROR_INVALIDDATA; } + ff_refstruct_unref(&f->slice_damaged); + f->slice_damaged = ff_refstruct_allocz(f->slice_count * sizeof(*f->slice_damaged)); + if (!f->slice_damaged) + return AVERROR(ENOMEM); + for (int j = 0; j < f->slice_count; j++) { FFV1SliceContext *sc = &f->slices[j]; - sc->slice_damaged = 0; - if (f->version == 2) { int sx = get_symbol(c, state, 0); int sy = get_symbol(c, state, 0); @@ -945,6 +945,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, int trailer = 3 + 5*!!f->ec; int v; + sc->slice_damaged = 0; + if (i || f->version > 2) { if (trailer > buf_p - buf) v = INT_MAX; else v = AV_RB24(buf_p-trailer) + trailer; @@ -1039,8 +1041,6 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) FFV1SliceContext *sc = &fdst->slices[i]; const FFV1SliceContext *sc0 = &fsrc->slices[i]; - sc->slice_damaged = sc0->slice_damaged; - ff_refstruct_replace(&sc->plane, sc0->plane); if (fsrc->version < 3) { @@ -1051,12 +1051,12 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) } } + ff_refstruct_replace(&fdst->slice_damaged, fsrc->slice_damaged); + av_assert1(fdst->max_slice_count == fsrc->max_slice_count); ff_progress_frame_replace(&fdst->picture, &fsrc->picture); - fdst->fsrc = fsrc; - return 0; } #endif