From patchwork Tue Jul 16 17:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50601 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp478679vqb; Tue, 16 Jul 2024 11:41:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV73INPVVOxpY6xZGk/ep4ifvHDsfTlwbfyDXpbrZIYz9fIhZIlSTue9OFhPaC1sVnlBgu9RrBt/o6yd9i0NUR2bKVY4gbehuDzGw== X-Google-Smtp-Source: AGHT+IEPFqpg4/uxzfhwTcm+VcR8jGO160fRA60ao+pZcc8M03QknbYBOeTfWRYgU+GF/3IeFjGo X-Received: by 2002:a05:6402:1e88:b0:58e:2b65:385b with SMTP id 4fb4d7f45d1cf-59eee73bb19mr2051371a12.14.1721155314224; Tue, 16 Jul 2024 11:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721155314; cv=none; d=google.com; s=arc-20160816; b=SD4RAmvJ0p47Z/9XYaQb67fVGyKR/t2r9JrTtRaNyMND+QLILzwRuQum/j1aMmEKU1 aa0mVbJkjs3/Z3Ry596RwZpuSVcCkVXlC3ZhiP9igi7NoiogeuaqTTeFCdDExSOOf0Ms dXFUlYBCHPAq5svrcvG2TMyzINNsDT/hmteYSbsO/qCw8yyMo5CYLFARpafYitUO9uq/ 8+GTVQ7i94uCpjYLBbc3JWiGyZ3h5wZwffTb4llJ4h8Ap7TSvEfWzAslkP5AGuDKk9f0 5PTG5YBununMuytMq8zXJtlBX1Zg02WrEnIBUdVx7skG1PJ0zuC8DRVJJrf/5MOvLbM+ y5YQ== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=fmt1LqnXC8smtofJNHI4790f2V95/gDnCK3Sj8+rRDo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=AeCjrznkF2uSZTjnLDtD2yWuVEjKsl0kMbBULfrKteWjmeCAAzbWO/DfoUshZtiumj EcFI5fRUChtd0GUdRlLyuhFGZI5XvgEcgHU7fLe1hWJrg+er60fWkFh89tMA3YnLtDBj NdThPOF96rVfNkl8d0dLJF7R1PbkRJwujmjinwVW5+w3udRgf+T+iiGyRpiN+RObJyj7 9T2qzUg1yNZCsjZ4Vws+oU4RIjXLGTKNUflkihHqOmTP5plUw/Bcy6OKyeMkJwEZHAOu k2nYp+Q/3ZBEo7+7t+0Whbolfj8sAUwXpoo5j/MBI0if69OeGSj2+KkwUvyKdTxOOj8h 4lQg==; 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=HbJaAkmZ; 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 4fb4d7f45d1cf-59c8100aa1esi3102209a12.676.2024.07.16.11.41.53; Tue, 16 Jul 2024 11:41:54 -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=HbJaAkmZ; 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 C14A168DB92; Tue, 16 Jul 2024 21:14:30 +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 AEA8F68DAAF for ; Tue, 16 Jul 2024 21:14:04 +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=HbJaAkmZ; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E661B4DBA for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id At7ubPsBJxaR for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=rDwzJgQvjPMLXc4lSJpdiysxlJnDd+GMblkLLsiM+O0=; h=From:To:Subject:Date:From; b=HbJaAkmZWN1TMpKv0fKs8DWxjN9gTrW344UvyydmyNkGMIPxYsrzhV+1wBkfo8XUU VCpaW1FAtu6bFOGqh+K7fyw59J/qzHxer3+LFHFMknu5pvF78ExGcXs9o6j32ImtVl K/2Yxea86oabMPHT+jmYT4y7tg2N7Fie+TzVu95nrdYxuyTCtebd525yWRnupMfCNN H7r57Q/2quMW+BAf2LEp4oUXM/tUHnQ8nXV7hYBxX95lDXB3ZakJ3macai5nlM92ee mwg6fSZKb/soXn3YKQUR/7MSmq0nx1NbFhzrA7M+rWXxrkTtd7a2gBUhOCxT1B3k6G xfJcqQHkPudTA== 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 8E32B4DA2 for ; Tue, 16 Jul 2024 19:16:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 307203A0212 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:16 +0200 Message-ID: <20240716171155.31838-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/39] tests/fate/vcodec: add vsynth tests for FFV1 version 2 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: MAYvhHn5eiK/ --- tests/fate/vcodec.mak | 3 ++- tests/ref/vsynth/vsynth1-ffv1-v2 | 4 ++++ tests/ref/vsynth/vsynth2-ffv1-v2 | 4 ++++ tests/ref/vsynth/vsynth3-ffv1-v2 | 4 ++++ tests/ref/vsynth/vsynth_lena-ffv1-v2 | 4 ++++ 5 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/ref/vsynth/vsynth1-ffv1-v2 create mode 100644 tests/ref/vsynth/vsynth2-ffv1-v2 create mode 100644 tests/ref/vsynth/vsynth3-ffv1-v2 create mode 100644 tests/ref/vsynth/vsynth_lena-ffv1-v2 diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak index abdc481f8a..b9829be027 100644 --- a/tests/fate/vcodec.mak +++ b/tests/fate/vcodec.mak @@ -154,13 +154,14 @@ $(FATE_VCODEC_DV:%=fate-vsynth\%-%): CODEC = dvvideo $(FATE_VCODEC_DV:%=fate-vsynth\%-%): FMT = dv $(FATE_VCODEC_DV:%=fate-vsynth\%-%): DECOPTS += $(DEFAULT_SIZE) -FATE_VCODEC-$(call ENCDEC, FFV1, AVI) += ffv1 ffv1-v0 \ +FATE_VCODEC-$(call ENCDEC, FFV1, AVI) += ffv1 ffv1-v0 ffv1-v2 \ ffv1-v3-yuv420p \ ffv1-2pass FATE_VCODEC_SCALE-$(call ENCDEC, FFV1, AVI) += ffv1-v3-yuv422p10 ffv1-v3-yuv444p16 \ ffv1-v3-bgr0 ffv1-v3-rgb48 fate-vsynth%-ffv1: ENCOPTS = -slices 4 fate-vsynth%-ffv1-v0: CODEC = ffv1 +fate-vsynth%-ffv1-v2: ENCOPTS = -level 2 -strict experimental fate-vsynth%-ffv1-v3-yuv420p: ENCOPTS = -level 3 -pix_fmt yuv420p fate-vsynth%-ffv1-v3-yuv422p10: ENCOPTS = -level 3 -pix_fmt yuv422p10 \ -sws_flags neighbor+bitexact diff --git a/tests/ref/vsynth/vsynth1-ffv1-v2 b/tests/ref/vsynth/vsynth1-ffv1-v2 new file mode 100644 index 0000000000..69536fb390 --- /dev/null +++ b/tests/ref/vsynth/vsynth1-ffv1-v2 @@ -0,0 +1,4 @@ +0f9298229cf53ce257648ccec70c893f *tests/data/fate/vsynth1-ffv1-v2.avi +2689724 tests/data/fate/vsynth1-ffv1-v2.avi +c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-ffv1-v2.out.rawvideo +stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth2-ffv1-v2 b/tests/ref/vsynth/vsynth2-ffv1-v2 new file mode 100644 index 0000000000..0b3f288f8f --- /dev/null +++ b/tests/ref/vsynth/vsynth2-ffv1-v2 @@ -0,0 +1,4 @@ +3144d06b9af1af98d072ccf05ff116ba *tests/data/fate/vsynth2-ffv1-v2.avi +3716500 tests/data/fate/vsynth2-ffv1-v2.avi +36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffv1-v2.out.rawvideo +stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth3-ffv1-v2 b/tests/ref/vsynth/vsynth3-ffv1-v2 new file mode 100644 index 0000000000..3b0397ec02 --- /dev/null +++ b/tests/ref/vsynth/vsynth3-ffv1-v2 @@ -0,0 +1,4 @@ +72f1126e9e270f019d90f74959bcf0cb *tests/data/fate/vsynth3-ffv1-v2.avi +60648 tests/data/fate/vsynth3-ffv1-v2.avi +a038ad7c3c09f776304ef7accdea9c74 *tests/data/fate/vsynth3-ffv1-v2.out.rawvideo +stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 86700/ 86700 diff --git a/tests/ref/vsynth/vsynth_lena-ffv1-v2 b/tests/ref/vsynth/vsynth_lena-ffv1-v2 new file mode 100644 index 0000000000..5f180462b5 --- /dev/null +++ b/tests/ref/vsynth/vsynth_lena-ffv1-v2 @@ -0,0 +1,4 @@ +4a0dbd5b50fa68fc7d5a8d6d64bd695a *tests/data/fate/vsynth_lena-ffv1-v2.avi +3546264 tests/data/fate/vsynth_lena-ffv1-v2.avi +dde5895817ad9d219f79a52d0bdfb001 *tests/data/fate/vsynth_lena-ffv1-v2.out.rawvideo +stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 From patchwork Tue Jul 16 17:11:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50570 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp436679vqb; Tue, 16 Jul 2024 10:17:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVHGfx8+6yZFWeNqiQp9lLalhjoyPVIp3CwqXSJqTMGolkOyjEA7d/VqPdJZtVt43UwUt6sVqgfG4Oa9nfg4PTB1GiqRJsFFIqRmQ== X-Google-Smtp-Source: AGHT+IGn2KAscjcHudjRC/n98A+C5ahsTVVwWMkAL0zDFI0Dg6BbnH1rKTVMSRZ4ZMJPkowNkB5z X-Received: by 2002:a05:6402:2116:b0:58d:b529:7db8 with SMTP id 4fb4d7f45d1cf-59eee641f0dmr2400636a12.9.1721150236581; Tue, 16 Jul 2024 10:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150236; cv=none; d=google.com; s=arc-20160816; b=XLT7ab64jRevtuc6DtX++ADGi/80njPErzKsHMxhyUADYmzaBXAr8vhn4uRd0G9Uwy 4DlvbPPFuZ3mUjbML7AFWPKHNk9tZeN0wTEksXFmKX1sElyQmWydKVctMYhlQD3sUX/p 1erIogNu64g0uQRKFWagGtspkroyskrgiSUB9GeRuRaXz9xKh/wv3icvRoe1z6TM/OFO 179kKqeCMVaFx5XJh4S6cJ/3316R4vnkulzF6kJGh021bndHxuz8fFN9WOTUB+BEa3Os 2kj6D09QJKGGP13umLefX3Cj0g6p5aucrqzj1ftFE0Hwx/1aMJWgirBKg9rqEwpMIzln Yurg== 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=y7SXwyICNVSWlL98E+GRo/tZGhMX8NEfSc+rJruSZso=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=t3lBKFjFsV1ifMsy0LWFFXIf+htFqeUR1Yy3SYJxEx/0V1m3xD+4pyG3ZXiP1/PxxP CmgYV0ckqy6QIf9EO4OFthic3v8OKIrO3m4aZNns/lehIbs7bILLKLGxH7vn3c31L2p1 0y6ZrupUjpfp1PkyQPvZJ7+uvppP1MzHOVNYkIC4HOkKTKcnDaVSlggtM/1A/Vh/MGqQ OVt+gjHInFuwbvj0ljyR0Z5oCTYSEqoZ4w0W9jgN4vdsYV/xPGCrhjK/XtzL2TA7TBHJ /JKmDBd4yBUo078+yuPGj/GXY5wnWNjcw0VFJDIrjZq3PX7Ixl/sDsHH6dg0vufYRKPB CoPA==; 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=DtwdwGWl; 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 4fb4d7f45d1cf-59eb9d95f79si1356294a12.243.2024.07.16.10.17.16; Tue, 16 Jul 2024 10:17:16 -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=DtwdwGWl; 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 3AAFD68DAC8; Tue, 16 Jul 2024 20:16:41 +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 9BBFE68D918 for ; Tue, 16 Jul 2024 20:16:31 +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=DtwdwGWl; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 195504E13 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ih--nmnolcQa for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150186; bh=x2haSI6SIJQwLj8sQBfXkMJXYWgs//6BrasNXQb1fEw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DtwdwGWle9bsBNdWtCbihkVz413yozTgQpqyF5wt+P36rDOKLrX9L8TdUVwE0JRUf y1gPTj9U0OtOmB/w6NKmAePoMXatVAPHD4VaE12PvbbdsPK5J6QRGGsORESXrWJvBZ XM3FHTdQjbAu2k6vjOKC6CeY9RltFGiYeV5D9l+3hpGzZFnbrcDMo+J7lyFCAhHeAr EQ81OoXpSyjn6sUDMQ/FDfdFCje6/01O4z3ksgKYSuutltRcBUQtHy3UlCQE89chxF sOl82XCBWTvOaR5tlt5utbF8HG5xZKC18kVvYWbcuH/XHn0mDglQzq+QjYHymEKxF7 uF6empSiMTxcw== 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 8CD44998 for ; Tue, 16 Jul 2024 19:16:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3E08A3A031C for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:17 +0200 Message-ID: <20240716171155.31838-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/39] lavc/ffv1dec: declare loop variables in the loop where possible 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: Wq2WtmcoI2Bo --- libavcodec/ffv1dec.c | 45 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 7a0d1909aa..5c515e97b6 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -46,7 +46,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, if (get_rac(c, state + 0)) return 0; else { - int i, e; + int e; unsigned a; e = 0; while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10 @@ -56,7 +56,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, } a = 1; - for (i = e - 1; i >= 0; i--) + for (int i = e - 1; i >= 0; i--) a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31 e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21 @@ -167,7 +167,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; - unsigned ps, i, context_count; + unsigned ps, context_count; int sx, sy, sw, sh; memset(state, 128, sizeof(state)); @@ -197,7 +197,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23)) return AVERROR_INVALIDDATA; - for (i = 0; i < f->plane_count; i++) { + for (unsigned i = 0; i < f->plane_count; i++) { PlaneContext * const p = &fs->plane[i]; int idx = get_symbol(c, state, 0); if (idx >= (unsigned)f->quant_table_count) { @@ -259,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg) int width, height, x, y, ret; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; AVFrame * const p = f->cur; - int i, si; + int si; for( si=0; fs != f->slice_context[si]; si ++) ; @@ -276,7 +276,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if (!(p->flags & AV_FRAME_FLAG_KEY)) fsdst->slice_damaged |= fssrc->slice_damaged; - for (i = 0; i < f->plane_count; i++) { + for (int i = 0; i < f->plane_count; i++) { PlaneContext *psrc = &fssrc->plane[i]; PlaneContext *pdst = &fsdst->plane[i]; @@ -424,7 +424,7 @@ static int read_extra_header(FFV1Context *f) { RangeCoder *const c = &f->c; uint8_t state[CONTEXT_SIZE]; - int i, j, k, ret; + int ret; uint8_t state2[32][CONTEXT_SIZE]; unsigned crc = 0; @@ -453,7 +453,7 @@ static int read_extra_header(FFV1Context *f) f->ac = get_symbol(c, state, 0); if (f->ac == AC_RANGE_CUSTOM_TAB) { - for (i = 1; i < 256; i++) + for (int i = 1; i < 256; i++) f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i]; } @@ -492,7 +492,7 @@ static int read_extra_header(FFV1Context *f) return AVERROR_INVALIDDATA; } - for (i = 0; i < f->quant_table_count; i++) { + for (int i = 0; i < f->quant_table_count; i++) { f->context_count[i] = read_quant_tables(c, f->quant_tables[i]); if (f->context_count[i] < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); @@ -502,10 +502,10 @@ static int read_extra_header(FFV1Context *f) if ((ret = ff_ffv1_allocate_initial_states(f)) < 0) return ret; - for (i = 0; i < f->quant_table_count; i++) + for (int i = 0; i < f->quant_table_count; i++) if (get_rac(c, state)) { - for (j = 0; j < f->context_count[i]; j++) - for (k = 0; k < CONTEXT_SIZE; k++) { + for (int j = 0; j < f->context_count[i]; j++) + for (int k = 0; k < CONTEXT_SIZE; k++) { int pred = j ? f->initial_states[i][j - 1][k] : 128; f->initial_states[i][j][k] = (pred + get_symbol(c, state2[k], 1)) & 0xFF; @@ -550,7 +550,7 @@ static int read_extra_header(FFV1Context *f) static int read_header(FFV1Context *f) { uint8_t state[CONTEXT_SIZE]; - int i, j, context_count = -1; //-1 to avoid warning + int context_count = -1; //-1 to avoid warning RangeCoder *const c = &f->slice_context[0]->c; memset(state, 128, sizeof(state)); @@ -566,7 +566,7 @@ static int read_header(FFV1Context *f) f->ac = get_symbol(c, state, 0); if (f->ac == AC_RANGE_CUSTOM_TAB) { - for (i = 1; i < 256; i++) { + for (int i = 1; i < 256; i++) { int st = get_symbol(c, state, 1) + c->one_state[i]; if (st < 1 || st > 255) { av_log(f->avctx, AV_LOG_ERROR, "invalid state transition %d\n", st); @@ -790,7 +790,7 @@ static int read_header(FFV1Context *f) return AVERROR_INVALIDDATA; } - for (j = 0; j < f->slice_count; j++) { + for (int j = 0; j < f->slice_count; j++) { FFV1Context *fs = f->slice_context[j]; fs->ac = f->ac; fs->packed_at_lsb = f->packed_at_lsb; @@ -819,7 +819,7 @@ static int read_header(FFV1Context *f) && (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= f->height); } - for (i = 0; i < f->plane_count; i++) { + for (int i = 0; i < f->plane_count; i++) { PlaneContext *const p = &fs->plane[i]; if (f->version == 2) { @@ -874,7 +874,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, int buf_size = avpkt->size; FFV1Context *f = avctx->priv_data; RangeCoder *const c = &f->slice_context[0]->c; - int i, ret, key_frame; + int ret, key_frame; uint8_t keystate = 128; uint8_t *buf_p; AVFrame *p; @@ -908,6 +908,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, } else { int w = avctx->width; int s = 1 + w / (1<<23); + int i; w /= s; @@ -941,7 +942,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, ff_thread_finish_setup(avctx); buf_p = buf + buf_size; - for (i = f->slice_count - 1; i >= 0; i--) { + for (int i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; int trailer = 3 + 5*!!f->ec; int v; @@ -991,15 +992,14 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, f->slice_count, sizeof(void*)); - for (i = f->slice_count - 1; i >= 0; i--) { + for (int i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; - int j; if (fs->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 (j = 0; j < desc->nb_components; j++) { + 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; @@ -1064,7 +1064,6 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { FFV1Context *fsrc = src->priv_data; FFV1Context *fdst = dst->priv_data; - int i; if (dst == src) return 0; @@ -1075,7 +1074,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) sizeof(fdst->state_transition)); memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table)); - for (i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { + for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; copy_fields(fsdst, fssrc, fsrc); From patchwork Tue Jul 16 17:11:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50567 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp436420vqb; Tue, 16 Jul 2024 10:16:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUcuSs5tctGPKuGmCI1mBZNCb3IF+XN2OLQpLF6OKPMcAfF8/o6eofqLJ/+jKb5X8ogaC5q/MdQf5novbfUsV5h7F4ZlkDouMvyJA== X-Google-Smtp-Source: AGHT+IFhXBfehhC27ZZhZRZrhcN7SPGYRMrpRFZ/vnrVkfu6oj3SmnFDicNQwPfkQNsRc+7FEuPx X-Received: by 2002:a2e:83c3:0:b0:2ee:db2c:5753 with SMTP id 38308e7fff4ca-2eef41ec98cmr19142321fa.42.1721150203801; Tue, 16 Jul 2024 10:16:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150203; cv=none; d=google.com; s=arc-20160816; b=edp6igpQ+qlOCwr5KQt8yRQxxcmmarCY/dsK2ksIpJSFNMLeIC4ARkT/SlZW4gDikp YPoMnqNky6u/wrVzOUDS/QS3FmaxuAlA4TV29+EtbY47rZ4YxVP+d4CjeQ69yNK5YJD2 BS7g8texkT6wJBYzk4UtkkHKtIiuhvNOgg4I1245BeaiWVoNGeWAjgX2qcpOLG8+bo8Q TfBQKd+wuF4yb2kMrhTbTGHcbLesmpZA6gYGQAGsFoAqExX6F4oFZuOQz9ORSZ6SpyAv 4mW7g+key30YPGMMjlGXhlROCOiIuRZ6lxehOuqdroCUEwLKgBS2YNRVlP9jGL37zbsN 4piA== 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=xicypxa9K3LcxDW7+TXi9NF1FMzBtBMz5uE2W2LCTLc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=ImImPvb9s7pNEYk2ctcndA5TYBdvlRA2+ckd7o7T81OVW4I3TQtt5BERg23w+v8olK 6bWuc8r+P8ZFC8FoQM/nIKHOY0wGp3+fvfwBiw3B+KM58zE1XetvxRvbWdNmhD/Ku9+R i0RZnsSzwNHwsAfzOu5j8AYItcJCUefVYOiRihdyYq1YBFbaWI1ujk2URU0SuY3wrRpn Jj95EN5DmvpBNQg8YVh+wcgzgymh0astTxEdhIAvuFf1rNiUSI+wr9K3yjBIAucf7fKr FVxMUfpICvbhJW809aINFNYW9i3KGSr99NNeJGkTgm/yKB6GNGQB08Z9tNP0ZRJkvd6Z XUNg==; 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=Q3yvY003; 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 38308e7fff4ca-2eee17b16b1si18916811fa.175.2024.07.16.10.16.43; Tue, 16 Jul 2024 10:16:43 -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=Q3yvY003; 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 1179B68DABD; Tue, 16 Jul 2024 20:16:38 +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 E068568D86A for ; Tue, 16 Jul 2024 20:16:30 +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=Q3yvY003; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 9E9E24E09 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id jZHxtDzdt_Bu for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150186; bh=S1eLFVFHlHQVHsYWj6u4/vg+hXZGmSXlbUsFgf7Qa/k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Q3yvY003ztYRar9//n+goDJbC2P+S6FKcIKdZUeOfVdJHQhhQfR4xWcbNlOqimjsk xJL12kzshMWOfzRKsA9kZimG0dlkEJ4dJrKYtL8848vCc2FHgruLZA/2Q+SPCOZ/RN p0PyadDiqFrzHes02YLEB8K7xHcYR9vr8UcliuDHrOFNfegTrkQ3tW66cI9TqMETDn wpHWf+M7d5pZ/HpAtqGZ93YDfA9aQ/i4idvGn2r+6cNM3BbbHTourS0MPdN/GUvSM2 AUcfj+C7on2n4AoXzRnf45tZydqtiabDAK2b4/Rmhk6oSU7VryFDkENyI8Y7PRk4Sp DgJInes1SfDYQ== 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 8F83A4DA7 for ; Tue, 16 Jul 2024 19:16:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 498283A083A for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:18 +0200 Message-ID: <20240716171155.31838-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/39] lavc/ffv1dec: simplify slice index calculation 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: Yfn4toNbgt0h --- libavcodec/ffv1dec.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 5c515e97b6..7066146477 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -259,10 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg) int width, height, x, y, ret; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; AVFrame * const p = f->cur; - int si; - - for( si=0; fs != f->slice_context[si]; si ++) - ; + const int si = (FFV1Context**)arg - f->slice_context; if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) ff_progress_frame_await(&f->last_picture, si); From patchwork Tue Jul 16 17:11:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50584 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp466848vqb; Tue, 16 Jul 2024 11:14:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXbr/Ju3EP0uQUTKPO+YGnGuUTYi54Io2C2TdAVFvOvJvYNYjmN3xV1/BRrx1K0/OwdIhgNt5Zc0CYSvBwFcU3NdQJPZ3/+XmuqlQ== X-Google-Smtp-Source: AGHT+IEfsyx8A/KCTc5RwdQvTGCpd75DHiDhQy2hnG6KayyoRcX4MEz3n9X8mhltw5SiWN3kDjpl X-Received: by 2002:a05:6402:27c6:b0:59f:68e0:fcab with SMTP id 4fb4d7f45d1cf-59f68e10105mr1649264a12.33.1721153699204; Tue, 16 Jul 2024 11:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153699; cv=none; d=google.com; s=arc-20160816; b=g7ScjpWI+4aG/pR1IOdOr+kX2sbkOXMujUs+OiUct/8ZnXYdGSqk4xmPTrVvFcrOGS xlYH51+djWkLFTr/WszPT8JuiTy3v7pPtiERdlaAgZKZ3G7pfjL1cKH4ZAqv1IIrdu64 OnAVDRZe+Uy4qM5Me3t0AWqXki/cbHq3gA/cge8UN0KXs/buvUdLTcFjn6BF1QtFOl6T 4WVR+5HpH/iMaiaIehVjqX4+LXk14IDbgBO4HD0K6hfRzvZJEjFBJDkboIGWd0IoMF9M eY9cXF3zuCx9CgPPPxgNfZW2EwkOUhVM6XPzXFOs1goTpyHzjQ9bW1yvt2ahIPh1udQb hLsw== 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=II7oWydZ1I/Lpx3m6epYJ21Bd9/LhwyKLxKdF8TKUCY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=PM7CaEIFlpsBDrdOOyqJvNzE3tLxlvVuXTMVMk/rZnIxd5xgVaNYKcUR9R9WhB9bFR fNuPnZ545VmQK98FRe+IP6kV0UR1KqE6P0NWPGpYp9Wj+RHjSR6kqMTBMxZmdGxSqQqh Wv3aUPTHcLL5Pra3OBBgguN36tHDRAev56Lms1C9F0L8ZiCP7dLkQoorOHXcbxvLgJF2 TI/jy3aa2xB/m+rsrGn6pCtm1IItXKrdGMV/v3CiyGcWnFLxNZ7k63vEDP3Tn7u4H9Ne iwwrpE4686YSib0TD4H6kYO/mTAA/7WduBJ+YIdtYw/1wxVciB3opTyOwHsqbz2tlTz6 P8wA==; 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="kCqjpYD/"; 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 4fb4d7f45d1cf-59b26f66263si4014259a12.365.2024.07.16.11.14.58; Tue, 16 Jul 2024 11:14:59 -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="kCqjpYD/"; 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 4914168DB1A; Tue, 16 Jul 2024 21:14:15 +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 845CD68D88A for ; Tue, 16 Jul 2024 21:14:04 +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=kCqjpYD/; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 23F7A4DE6 for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id mWt5e_RMDTDz for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=D0Njjaajs3DtGw2fXNWC0Zw5V6ekugRhmfTGKDjhHzg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kCqjpYD/42TH/w5IiJ6DEJXMOv9OIUh3ZRVqqyOWC4Mk4DUBGuRFwAbM4OGfXoiFD Hm1Om+XTPKGz1uuZgaLKBNQsW1tjpxt6WCRMGl8nFpbXZAftEe7FMDXyXumEEb3tvA I2jmDcIkfidYsCyYPuTRJWKzcvicCgiNkWqcos4bj5+Y9LOmiG6lWn2ddpOkYeTBsl S8HoBOsIA2Fd90ekFlRG9QgEvfvO3RNMRa20u9h5ghq+K6UFuTVZK2UXNKDaqNnxe6 pviGqvzRejBcMHqJj/9YWfZJ804rAxna46HdPoU+c8tUh/d5L36LXSKro3QdK5/TqI 2IR3hZxBqLVKQ== 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 655DE4DF1 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 547223A083F for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:19 +0200 Message-ID: <20240716171155.31838-4-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/39] lavc/ffv1dec: drop FFV1Context.cur 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: 9tDaQgdZ3f3F It is merely a pointer to FFV1Context.picture.f, which can just as well be used directly. --- libavcodec/ffv1.h | 1 - libavcodec/ffv1dec.c | 33 +++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index acec22e83e..d99367ce81 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -89,7 +89,6 @@ typedef struct FFV1Context { ProgressFrame picture, last_picture; struct FFV1Context *fsrc; - AVFrame *cur; const AVFrame *cur_enc_frame; int plane_count; int ac; ///< 1=range coder <-> 0=golomb rice diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 7066146477..60d04f04b9 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -163,7 +163,8 @@ static int decode_plane(FFV1Context *s, uint8_t *src, return 0; } -static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) +static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, + AVFrame *frame) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; @@ -217,23 +218,23 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs) ps = get_symbol(c, state, 0); if (ps == 1) { - f->cur->flags |= AV_FRAME_FLAG_INTERLACED; - f->cur->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; + frame->flags |= AV_FRAME_FLAG_INTERLACED; + frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST; } else if (ps == 2) { - f->cur->flags |= AV_FRAME_FLAG_INTERLACED; - f->cur->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; + frame->flags |= AV_FRAME_FLAG_INTERLACED; + frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; } else if (ps == 3) { - f->cur->flags &= ~AV_FRAME_FLAG_INTERLACED; + frame->flags &= ~AV_FRAME_FLAG_INTERLACED; } - f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0); - f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0); + frame->sample_aspect_ratio.num = get_symbol(c, state, 0); + frame->sample_aspect_ratio.den = get_symbol(c, state, 0); if (av_image_check_sar(f->width, f->height, - f->cur->sample_aspect_ratio) < 0) { + frame->sample_aspect_ratio) < 0) { av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n", - f->cur->sample_aspect_ratio.num, - f->cur->sample_aspect_ratio.den); - f->cur->sample_aspect_ratio = (AVRational){ 0, 1 }; + frame->sample_aspect_ratio.num, + frame->sample_aspect_ratio.den); + frame->sample_aspect_ratio = (AVRational){ 0, 1 }; } if (fs->version > 3) { @@ -258,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg) FFV1Context *f = fs->avctx->priv_data; int width, height, x, y, ret; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; - AVFrame * const p = f->cur; + AVFrame * const p = f->picture.f; const int si = (FFV1Context**)arg - f->slice_context; if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) @@ -299,7 +300,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->version > 2) { if (ff_ffv1_init_slice_state(f, fs) < 0) return AVERROR(ENOMEM); - if (decode_slice_header(f, fs) < 0) { + if (decode_slice_header(f, fs, p) < 0) { fs->slice_x = fs->slice_y = fs->slice_height = fs->slice_width = 0; fs->slice_damaged = 1; return AVERROR_INVALIDDATA; @@ -307,7 +308,7 @@ static int decode_slice(AVCodecContext *c, void *arg) } if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0) return ret; - if ((f->cur->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { + if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { ff_ffv1_clear_slice_state(f, fs); } else if (fs->slice_damaged) { return AVERROR_INVALIDDATA; @@ -920,7 +921,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, if (ret < 0) return ret; - f->cur = p = f->picture.f; + p = f->picture.f; p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P p->flags = (p->flags & ~AV_FRAME_FLAG_KEY) | key_frame; From patchwork Tue Jul 16 17:11: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: 50575 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp442040vqb; Tue, 16 Jul 2024 10:27:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUGd5H4JH/s+uHfW2GIRLM2DDH2xVf0sX+LNbvZ1JGLrVw5o9ZvCVuGOiLFairlBRzfkgjdHUZUOcjRqYs2V2GDzwFplMW1CANAEw== X-Google-Smtp-Source: AGHT+IFAMPrK69q+vMBsRCilry+6Z8IgBTc2wPYzn5ONtzA9pMoCLm8yo+z31fDYJokN3qdF5uvq X-Received: by 2002:a17:906:3e44:b0:a77:cf09:9c5b with SMTP id a640c23a62f3a-a79ea454b67mr210723566b.35.1721150820678; Tue, 16 Jul 2024 10:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150820; cv=none; d=google.com; s=arc-20160816; b=Cnhb7q0TWCIrdtV9abK6D42HFAePg3rJOc+ACmEiclNnBf9VGkRSQxV5byHxV+flnY Fy/Me2eRuQUgvCMRN1ST6HOD94UHrWzk9nceOARNLhZSy15cjMaPdbp6c70+iH1gK2nh esDT/Cd757iM5Ttj1iZQHNbC/Ru8LcULS7Ut9Q0i2dALl9XW+2R4JTP6EmU62DdibNJ3 mdyQM5ORtSqKfDtZ1NTyzKHp1V2sR/ndEy9uDm0vD6wIEEWau8A2ISfz3SxvYDtCXFJd 4DGk0MkEUM1QTkjiBiAlGgJE4vR8RsoZL7mS5rE0Fqhh6+sOhAsxBfdXkgqyLRsoa69o iUzQ== 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=7N5OkN/ysoQBBOXSxjwmGUBJIuP9s0NHuCXhu+UPMV4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=uHlYHHW6Lrqiy+i1lXALs4memza6U8vLInYjCXIXQa43myrZiKU8GHwjUwpPRTLzWU ALJR4EpQIWovEQIHnoVYgPhLA4KAiPnN8dKGEiHo0F8rOrJE4GMRFYi6jKQbQjGL5A1X IsBz7P5OJ8wbbkGyGG394/pjLGfreTOq2xU1yxKwoisgd1kEhuFhOKxwJoeOxMtiS/LH 3Wua3uiGlFnp/V0mIg+y79Kj6TJIZeW488toiYt0zaYq83VvlqacCsW4LasjEshdXW5m BdhFpjSLy8M9hCRJlLZrFBonBAsVvrIQsZTQAa3rZFvDOPodEj9uGFsWtOdZJ4coWYQi gxpA==; 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=QKJYW0OI; 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-a79bc58b0cdsi410671966b.94.2024.07.16.10.27.00; Tue, 16 Jul 2024 10:27:00 -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=QKJYW0OI; 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 C6E8468DAEC; Tue, 16 Jul 2024 20:16:48 +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 EB65368D918 for ; Tue, 16 Jul 2024 20:16:31 +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=QKJYW0OI; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 8F20B998 for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id PXtB_Fb9UQax for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=nSos1tdSmy4gmgr2wyPKIClIyLAzxkNLX6pmTE/fglw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QKJYW0OIVDVqAKuVmKnlUl5JHsflgWugkWIAs6rgmEVsrjDWnZp+fU+Vc4ZaKHR8e hJPGq32nizRAL4G7J2/StxOhKOS+1XXq1gC+J0UUsdb40fDG/bRRr9qCdLKmCiKJid /ve8Z1QLEpLObS0biieZ+0Yw1nYAn77Gx+EYbe6B5YpY02CkDW2lqUyPxrhcKwuyg8 THKLZcDUgLQ6nFbQYSbQNc8WI3JBUhifmkF6Pzfx8CnooWUVC+20+fv9Nyo7Ln3QYc 8fdl30HrjzUHE7ZJmOJ99XavLnXRo5paitfubmDm01uPw3Y6y3zPcFc9qXu+NsIFlD nx2cTuV59p2Rw== 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 C90D24DBA for ; Tue, 16 Jul 2024 19:16:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6024D3A09EE for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:20 +0200 Message-ID: <20240716171155.31838-5-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/39] lavc/ffv1dec: drop a pointless variable in 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: n4FVnrjERt37 fsdst is by construction always equal to fs, there is even an av_assert1() checking that. Just use fs directly. --- libavcodec/ffv1dec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 60d04f04b9..dbb7e082a3 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -267,16 +267,14 @@ static int decode_slice(AVCodecContext *c, void *arg) if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) { FFV1Context *fssrc = f->fsrc->slice_context[si]; - FFV1Context *fsdst = f->slice_context[si]; - av_assert1(fsdst->plane_count == fssrc->plane_count); - av_assert1(fsdst == fs); + av_assert1(fs->plane_count == fssrc->plane_count); if (!(p->flags & AV_FRAME_FLAG_KEY)) - fsdst->slice_damaged |= fssrc->slice_damaged; + fs->slice_damaged |= fssrc->slice_damaged; for (int i = 0; i < f->plane_count; i++) { PlaneContext *psrc = &fssrc->plane[i]; - PlaneContext *pdst = &fsdst->plane[i]; + PlaneContext *pdst = &fs->plane[i]; av_free(pdst->state); av_free(pdst->vlc_state); From patchwork Tue Jul 16 17:11: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: 50568 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp436506vqb; Tue, 16 Jul 2024 10:16:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUeUNN2FJm/0OFkPQDBNPsjMYp+ts/gJvh1g+lNcgqUCbTBmvTN60Jv196JjiJHlNtAqaKEmcr4Wv8RShUe3XiA8H6gCGDw/93Iww== X-Google-Smtp-Source: AGHT+IH5+zWgB0Nthmv3WVrnjegJmTmMUBBe/plIl2A9q7iG2/Z8OvjJcQrnAUbdsF1NWqfLYxDb X-Received: by 2002:a05:6512:128e:b0:52e:7125:c70a with SMTP id 2adb3069b0e04-52edf0389c3mr2288901e87.47.1721150215206; Tue, 16 Jul 2024 10:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150215; cv=none; d=google.com; s=arc-20160816; b=Vk2zWP7ea14cGbCzW31G3hJdZkwLGNhgELRXpWg5QzUdNGFQklmTotflj3RwW+XUcx O2+JwbCaiVaYcR/T+T9RmJtN/JYPSTFEYzv6AtyLdTYiPBEmvNAazOf9gCaRB/B8tc1t jApwnOLKAnN2V2FxysMmezfpsvGGtQFcMDAt27t89gx83aZgmiDyzExCVmyMtS6yVG3N krdOKxN/6FC6Cugr3jFQp2g2W3IF/d+S4SFhFwLs29ZTsyPBASz590HYTN8DWomUOqwh 0cerwFMEV4vC9f2wmwx5q6FLceMaWnUsv5TBQ3cHxXnXIofpwXHVZNksRNgxx82fcuQV FukQ== 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=16DbvZcR1wdAxq07pb17c4Eba75NNqHRv4H0XcaqIMc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=JzzEBBGdZFsgL8fENMXqdx5+VzGeUFgj2lCKVCcf/Glb5Vkm0UFPtiDjhnNHBc+/vi WRH6Xo8zwfpA6tSoJrzl18ob05HCwPOn5bLDFGgm0fcGZvihQR8BgDWW7PZWTsEb0oa8 tIBgZFEUYzlUMJ137Eb7BtRsOcgMknXBrMW7eC2/zoBhktYOoirHVBaXq7KFFPDqxRaB SCRKgy9bzIV0dUEvnvaXbql3ex4gf5G76vNc2KCDui7/AoIoFyEqH164NOgw0Xt0E0xv EcrrrpVCuHMmgsrqf5IkRaIjylGGKXsvSQ96EIgN/BN5CBx/bHcSb3sVCLmkAaaTfS1A MKeQ==; 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=dn8Vb1h2; 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-52ed2571964si2257874e87.557.2024.07.16.10.16.54; Tue, 16 Jul 2024 10:16:55 -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=dn8Vb1h2; 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 1619368DA91; Tue, 16 Jul 2024 20:16:39 +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 E12EB68D918 for ; Tue, 16 Jul 2024 20:16:30 +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=dn8Vb1h2; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E90964DA7 for ; Tue, 16 Jul 2024 19:16:29 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id phIjIy2iZiFF for ; Tue, 16 Jul 2024 19:16:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=TfY2T6WVUUhNfF/9WDur98EkaFL80LlfXrVIbRNOk2k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dn8Vb1h2nqiPPZspoNIohRUhvC1fWrFgskSFfTyhQIYA10tAuGUU31W4SJDcqcXxg 4Mg8LYd6WzfgVEjHi1ghTgIjDIKSvCaW3Tf4BMWVz7rf/RP6C7T7DfuhxzNYhcDZN3 jaehB+fbgoDf5k+cynlDNAP84R/MHSCgrdNR+/ClKCw1LRAu47r5duVnj4dT/DIICk kZ1rH1AQ06AD0ll7l2zqWqmiH259G45OCI2rK0PP5BJD6VKKtGmdjLcvvOREHb0jH5 8jKzNRoF767RVdjDCfqHWgq+aUdmKBvsGKsrdEqwZiRgbBYPDJcb4bnZnU3rVFy29+ JjjdCPbYc1+Rw== 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 169BA4DBC for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6BDFC3A155A for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:21 +0200 Message-ID: <20240716171155.31838-6-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/39] lavc/ffv1dec: move copy_fields() under HAVE_THREADS 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: XKKSN24NpsJS It is unused otherwise --- libavcodec/ffv1dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index dbb7e082a3..6d59355c23 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1027,6 +1027,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, return buf_size; } +#if HAVE_THREADS static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, const FFV1Context *fsrc) { @@ -1055,7 +1056,6 @@ static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, } } -#if HAVE_THREADS static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { FFV1Context *fsrc = src->priv_data; From patchwork Tue Jul 16 17:11: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: 50593 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp470156vqb; Tue, 16 Jul 2024 11:21:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX5QiozPV7BObnjKU9/Gf1Qmp2WYrgkv5Zqz+D5AeQJ/1gQyLau2DzxwtFGkFtxmHb3vT3TEQJ9mPBdpFWk2dk11QCNMI3HgNue2w== X-Google-Smtp-Source: AGHT+IG5yIsRlSw3Xt23GH7ivEmrAzpP9yeDaK8Wyq5INgWwOUfh+iVzG8h/tWmuPB69t/JVB6TK X-Received: by 2002:a05:6512:3f06:b0:52c:da09:ae65 with SMTP id 2adb3069b0e04-52edef10760mr1908310e87.9.1721154112984; Tue, 16 Jul 2024 11:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154112; cv=none; d=google.com; s=arc-20160816; b=PYMiDYti1kAknfovjlFyFyegLKc0td8+32OF2/k0ZzVOVClpFs9HkRuv4H6oPO4DgD W1uO5D1spgINRPlJeD6SEn7oobYfpSE2Ij6kURYdiFxS3g6/2oAUZ/lwFx/CG91bF9ZG UPWz2iIT1mH+JWmgPE5xByRoKytmE3GtwH5YLmOUp4EZCD1bk0Fn0jUQ9YxlfH0WEkp7 G4Za9pmr0mqner95BzjeM1UVC0ZfJTMeDl/NSzmJ14GbzzyIaudCvX2a2qjF7nB/0EHa J+cyd3xCx6O6JjS1l8ThtQZHxwgr3IhCBnHdgrJBYuRV7Hw1/S27mGxV/VwuJ5RuB0qi Cokg== 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=Lh+kNPjczGb0RKuUr8Le2wP2p45olXfbT903V1M/SHA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=YJnCer8CgNRfveZtUZuDGshIjfmZpgiXHhRvlEOAjyn8P1rj2ivH8XzgV0df6bqtX0 pmGwCujtSxaftRPnzGR7gt+aI/WRjnsi6A7nEFaRUPkYzHhMvzp8PprT8jm/i89JZYTj WupS8eG41l3a1YTWXJ7bRRFWxK2qSCfhLfnlCVLjk21/rLpCrjGaaZ9f3tniGNgJLXng 5u3JqC+ZQHaNS2zbj2IdRYnqMI0O4yAg0HbP+No6K+PoMHbjengWsZ7Q8iJaq6wlEEt0 jtTHKb6xARvnxDKtr+Orvrj7trLX9AKH5gG/XLBQ6pbFtXmk1Bu8z82Z4aBRimR4K2Lg W9GA==; 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="RppQUI/s"; 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-52ed252d20asi2296558e87.193.2024.07.16.11.21.52; Tue, 16 Jul 2024 11:21:52 -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="RppQUI/s"; 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 A79B268D977; Tue, 16 Jul 2024 21:14:08 +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 0259E68D504 for ; Tue, 16 Jul 2024 21:13:59 +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=RppQUI/s; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 8B3444DA2 for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id nTx6GG_nV5ul for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=OXHCR5fW0Gr7rAZmacub+wDtr2kj46yBbh+8XlkOrbg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RppQUI/smSQ/N22Z9tRc7ob+tagsOLPCt3OQDMz7Tqvsva75BfpB0EcvBORvySMiA GpS7B3QM4l3/0JIy6w58mOj3GQMG02WJHWjgtIfOykis27pSVX0r6yAc8s+qCN4u2/ CSdSWI4lMN1Oy+8J06gv61QTZwjXIeuDVTtEyjkB2eQ3z7Tc4h0123YaR4l5RPxeaB g3b6aTi1t49qHUiC79sOA0XLSjT8WdySd6eovMRGB4Y2Rrv0zjwrGIy+F2wtDn2BDp n0KicD2RxIrNOHRusU/kKLHA8XlaFb7/kytUv2nGHZrwoLC107bBYaYTuEw2lLHTQe WZKXGi7jA/pzQ== 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 216014DE1 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 77D4B3A180F for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:22 +0200 Message-ID: <20240716171155.31838-7-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/39] lavc/ffv1: add a per-slice context 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: HAKeEvUww13U FFV1 decoder and encoder currently use the same struct - FFV1Context - both as codec private data and per-slice context. For this purpose FFV1Context contains an array of pointers to per-slice FFV1Context instances. This pattern is highly confusing, as it is not clear which fields are per-slice and which per-codec. Address this by adding a new struct storing only per-slice data. Start by moving slice_{x,y,width,height} to it. --- libavcodec/ffv1.c | 15 ++++++--- libavcodec/ffv1.h | 13 +++++--- libavcodec/ffv1dec.c | 76 ++++++++++++++++++++++++-------------------- libavcodec/ffv1enc.c | 25 ++++++++------- 4 files changed, 76 insertions(+), 53 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 6ec24fed4a..25f28287c0 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -108,7 +108,12 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) av_assert0(max_slice_count > 0); + f->slices = av_calloc(max_slice_count, sizeof(*f->slices)); + if (!f->slices) + return AVERROR(ENOMEM); + for (i = 0; i < max_slice_count;) { + FFV1SliceContext *sc = &f->slices[i]; int sx = i % f->num_h_slices; int sy = i / f->num_h_slices; int sxs = f->avctx->width * sx / f->num_h_slices; @@ -124,10 +129,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) memcpy(fs, f, sizeof(*fs)); memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2)); - fs->slice_width = sxe - sxs; - fs->slice_height = sye - sys; - fs->slice_x = sxs; - fs->slice_y = sys; + sc->slice_width = sxe - sxs; + sc->slice_height = sye - sys; + sc->slice_x = sxs; + sc->slice_y = sys; fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * sizeof(*fs->sample_buffer)); @@ -217,5 +222,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) for (i = 0; i < s->max_slice_count; i++) av_freep(&s->slice_context[i]); + av_freep(&s->slices); + return 0; } diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index d99367ce81..256904b283 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -69,6 +69,13 @@ typedef struct PlaneContext { #define MAX_SLICES 1024 +typedef struct FFV1SliceContext { + int slice_width; + int slice_height; + int slice_x; + int slice_y; +} FFV1SliceContext; + typedef struct FFV1Context { AVClass *class; AVCodecContext *avctx; @@ -123,14 +130,12 @@ typedef struct FFV1Context { int max_slice_count; int num_v_slices; int num_h_slices; - int slice_width; - int slice_height; - int slice_x; - int slice_y; int slice_reset_contexts; int slice_coding_mode; int slice_rct_by_coef; int slice_rct_ry_coef; + + FFV1SliceContext *slices; } FFV1Context; int ff_ffv1_common_init(AVCodecContext *avctx); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 6d59355c23..28e4a05b21 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -164,7 +164,7 @@ static int decode_plane(FFV1Context *s, uint8_t *src, } static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, - AVFrame *frame) + FFV1SliceContext *sc, AVFrame *frame) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; @@ -185,17 +185,17 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh) return AVERROR_INVALIDDATA; - fs->slice_x = sx * (int64_t)f->width / f->num_h_slices; - fs->slice_y = sy * (int64_t)f->height / f->num_v_slices; - fs->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - fs->slice_x; - fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - fs->slice_y; + sc->slice_x = sx * (int64_t)f->width / f->num_h_slices; + sc->slice_y = sy * (int64_t)f->height / f->num_v_slices; + sc->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - sc->slice_x; + sc->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - sc->slice_y; - av_assert0((unsigned)fs->slice_width <= f->width && - (unsigned)fs->slice_height <= f->height); - av_assert0 ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width <= f->width - && (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= f->height); + av_assert0((unsigned)sc->slice_width <= f->width && + (unsigned)sc->slice_height <= f->height); + av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width + && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height); - if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23)) + if (fs->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23)) return AVERROR_INVALIDDATA; for (unsigned i = 0; i < f->plane_count; i++) { @@ -261,6 +261,7 @@ static int decode_slice(AVCodecContext *c, void *arg) const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; AVFrame * const p = f->picture.f; const int si = (FFV1Context**)arg - f->slice_context; + FFV1SliceContext *sc = &f->slices[si]; if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) ff_progress_frame_await(&f->last_picture, si); @@ -298,8 +299,8 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->version > 2) { if (ff_ffv1_init_slice_state(f, fs) < 0) return AVERROR(ENOMEM); - if (decode_slice_header(f, fs, p) < 0) { - fs->slice_x = fs->slice_y = fs->slice_height = fs->slice_width = 0; + if (decode_slice_header(f, fs, sc, p) < 0) { + sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; fs->slice_damaged = 1; return AVERROR_INVALIDDATA; } @@ -312,10 +313,10 @@ static int decode_slice(AVCodecContext *c, void *arg) return AVERROR_INVALIDDATA; } - width = fs->slice_width; - height = fs->slice_height; - x = fs->slice_x; - y = fs->slice_y; + width = sc->slice_width; + height = sc->slice_height; + x = sc->slice_x; + y = sc->slice_y; if (fs->ac == AC_GOLOMB_RICE) { if (f->version == 3 && f->micro_version > 1 || f->version > 3) @@ -788,6 +789,7 @@ static int read_header(FFV1Context *f) for (int j = 0; j < f->slice_count; j++) { FFV1Context *fs = f->slice_context[j]; + FFV1SliceContext *sc = &f->slices[j]; fs->ac = f->ac; fs->packed_at_lsb = f->packed_at_lsb; @@ -804,15 +806,15 @@ static int read_header(FFV1Context *f) if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh) return AVERROR_INVALIDDATA; - fs->slice_x = sx * (int64_t)f->width / f->num_h_slices; - fs->slice_y = sy * (int64_t)f->height / f->num_v_slices; - fs->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - fs->slice_x; - fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - fs->slice_y; + sc->slice_x = sx * (int64_t)f->width / f->num_h_slices; + sc->slice_y = sy * (int64_t)f->height / f->num_v_slices; + sc->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - sc->slice_x; + sc->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - sc->slice_y; - av_assert0((unsigned)fs->slice_width <= f->width && - (unsigned)fs->slice_height <= f->height); - av_assert0 ( (unsigned)fs->slice_x + (uint64_t)fs->slice_width <= f->width - && (unsigned)fs->slice_y + (uint64_t)fs->slice_height <= f->height); + av_assert0((unsigned)sc->slice_width <= f->width && + (unsigned)sc->slice_height <= f->height); + av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width + && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height); } for (int i = 0; i < f->plane_count; i++) { @@ -990,6 +992,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, for (int i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; + FFV1SliceContext *sc = &f->slices[i]; if (fs->slice_damaged && f->last_picture.f) { const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); const uint8_t *src[4]; @@ -1000,9 +1003,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, 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] * - (fs->slice_y >> sv) + ((fs->slice_x >> sh) << pixshift); + (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] * - (fs->slice_y >> sv) + ((fs->slice_x >> sh) << pixshift); + (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift); } if (desc->flags & AV_PIX_FMT_FLAG_PAL) { @@ -1012,8 +1015,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, av_image_copy(dst, p->linesize, src, f->last_picture.f->linesize, avctx->pix_fmt, - fs->slice_width, - fs->slice_height); + sc->slice_width, + sc->slice_height); } } ff_progress_frame_report(&f->picture, INT_MAX); @@ -1048,12 +1051,6 @@ static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, fsdst->packed_at_lsb = fsrc->packed_at_lsb; fsdst->slice_count = fsrc->slice_count; - if (fsrc->version<3){ - fsdst->slice_x = fssrc->slice_x; - fsdst->slice_y = fssrc->slice_y; - fsdst->slice_width = fssrc->slice_width; - fsdst->slice_height = fssrc->slice_height; - } } static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) @@ -1073,7 +1070,18 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { FFV1Context *fssrc = fsrc->slice_context[i]; FFV1Context *fsdst = fdst->slice_context[i]; + + FFV1SliceContext *sc = &fdst->slices[i]; + const FFV1SliceContext *sc0 = &fsrc->slices[i]; + copy_fields(fsdst, fssrc, fsrc); + + if (fsrc->version < 3) { + sc->slice_x = sc0->slice_x; + sc->slice_y = sc0->slice_y; + sc->slice_width = sc0->slice_width; + sc->slice_height = sc0->slice_height; + } } av_assert0(!fdst->plane[0].state); av_assert0(!fdst->sample_buffer); diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 94d9215acd..c46df15b0c 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -370,7 +370,7 @@ static void write_header(FFV1Context *f) } else if (f->version < 3) { put_symbol(c, state, f->slice_count, 0); for (i = 0; i < f->slice_count; i++) { - FFV1Context *fs = f->slice_context[i]; + FFV1SliceContext *fs = &f->slices[i]; put_symbol(c, state, (fs->slice_x + 1) * f->num_h_slices / f->width, 0); put_symbol(c, state, @@ -904,17 +904,18 @@ slices_ok: return 0; } -static void encode_slice_header(FFV1Context *f, FFV1Context *fs) +static void encode_slice_header(FFV1Context *f, FFV1Context *fs, + FFV1SliceContext *sc) { RangeCoder *c = &fs->c; uint8_t state[CONTEXT_SIZE]; int j; memset(state, 128, sizeof(state)); - put_symbol(c, state, (fs->slice_x +1)*f->num_h_slices / f->width , 0); - put_symbol(c, state, (fs->slice_y +1)*f->num_v_slices / f->height , 0); - put_symbol(c, state, (fs->slice_width +1)*f->num_h_slices / f->width -1, 0); - put_symbol(c, state, (fs->slice_height+1)*f->num_v_slices / f->height-1, 0); + put_symbol(c, state, (sc->slice_x +1)*f->num_h_slices / f->width , 0); + put_symbol(c, state, (sc->slice_y +1)*f->num_v_slices / f->height , 0); + put_symbol(c, state, (sc->slice_width +1)*f->num_h_slices / f->width -1, 0); + put_symbol(c, state, (sc->slice_height+1)*f->num_v_slices / f->height-1, 0); for (j=0; jplane_count; j++) { put_symbol(c, state, f->plane[j].quant_table_index, 0); av_assert0(f->plane[j].quant_table_index == f->context_model); @@ -1023,10 +1024,12 @@ static int encode_slice(AVCodecContext *c, void *arg) { FFV1Context *fs = *(void **)arg; FFV1Context *f = fs->avctx->priv_data; - int width = fs->slice_width; - int height = fs->slice_height; - int x = fs->slice_x; - int y = fs->slice_y; + const int si = (FFV1Context**)arg - f->slice_context; + FFV1SliceContext *sc = &f->slices[si]; + int width = sc->slice_width; + int height = sc->slice_height; + int x = sc->slice_x; + int y = sc->slice_y; const AVFrame *const p = f->cur_enc_frame; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; int ret; @@ -1048,7 +1051,7 @@ retry: if (f->key_frame) ff_ffv1_clear_slice_state(f, fs); if (f->version > 2) { - encode_slice_header(f, fs); + encode_slice_header(f, fs, sc); } if (fs->ac == AC_GOLOMB_RICE) { fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; From patchwork Tue Jul 16 17:11:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50569 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp436579vqb; Tue, 16 Jul 2024 10:17:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXd6g53Sl2ZaY3wTs4fWpHV0tGX4L2n46VVv26ZX6HUEZeAiUMJxv2kxkzgfVgiE6u5wf/td/Z8lJ11FMHi/okoG9+vbwsT+Y4wrA== X-Google-Smtp-Source: AGHT+IG7EPSVaWSG7ilhTUDX2y3mQuUF3YDkih8a6vKFQ6pn7NyKvViSMhoCxofUh3sGW5bCns6n X-Received: by 2002:a05:6402:26d4:b0:57d:692:92d9 with SMTP id 4fb4d7f45d1cf-59eee83233fmr2168519a12.4.1721150226220; Tue, 16 Jul 2024 10:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150226; cv=none; d=google.com; s=arc-20160816; b=TQSunNAay3r3Lb5OzNNvNWioaPyc/L8bF8T7MBsx2fAgFc0eaSunk6Djtcb9RQCbBo dw2rLNpX+zbYBoCU8bedaTAYC5QuHSbrJ3YvBJrPRfmsSJR4yI5rYGIYGOGWHBiKUoGS 8rLVa1EopAhR0z3DmuSVagK8rSMlE3ysfHQROJhvdOb+QMvv1UVupQfQrGYyqmREfnrm PdxKolxhNY29Iul1vcHXGnbzxbCWnJQuuq2o4fsYtiQA+pNIXEFNQ4naz53PNzP5MxPs xqkneXKWrCKynLiqByEENd9G0HWvhLul39n2T9dRCvlmWFi/+DR+02ARKcRntIWpDcKa Y+Qg== 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=OnWfhEN9yob0Q5dCiZiwG8KuZVHnQlI3PVdmc8LlXV0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=hlI2AvKe2OSonrxFh8EjFCT3TEhfhib42bOPKETjJaoigBQgVx7Vf8sgCSg9U9/enH V6QUM4azEQnbwwV0DocHMWR1k4+Y/JwOmF9EWeio8QrAFKWKVVciTi/qPQcOEw/spfS9 HITQXuxr+bVmBvEyJOhZE8Sg1Q0r04PJKtYR0HRCVPq+HnIA6iqGSjIARwGiVGlda4KL fQU8Qrqp6Rodhzr0gr+VDP+Up+lpw9f8xmTOTIKiNfQlmwfo+S2Z0Amkrh811I+5ZI+L 3Ir+Y3DslysSZUuIz2hWxO7Nlf/BobK4iiC/gAjq14BrkrUgAiceLgfHE1ehZTyQ79Aq 6s5A==; 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=EQBt0KMi; 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 4fb4d7f45d1cf-59b26f657c9si4113081a12.352.2024.07.16.10.17.05; Tue, 16 Jul 2024 10:17:06 -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=EQBt0KMi; 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 1CBAE68D918; Tue, 16 Jul 2024 20:16:40 +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 A01B468DA77 for ; Tue, 16 Jul 2024 20:16:31 +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=EQBt0KMi; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3BCE14DBC for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id R_22z0raJ-Br for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=ArabD8jIihR8W5JkI3NgsV0hy8xNrHWgiuZvGvTUsn4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EQBt0KMi2D7x5WCfcwR7L5kgTkqsaLY5vSUnESFsgiJua1wyvxC9zvTk13CgR3iZC cRYtePj3vyemvakIu5Z0jc+5iMhBpFKqPU+WwlyAFAPgrGNyFhut6uRJHdeXSSsjiv pxlGXZmH8b8ym89L3Hc479VGf1PbO2wbv144HWbHBa7a07vG+zKvxOBKjNu4nHLFyw 8Q/b3iOzaPGlZJjmzSfW/nhYGLAxlar9BdEGvrHf7bNDFp9OmDJ9C8Y+peVOhNhAsc wVPF4MzPIZvlkpOObj+7ku+Oxkbz0WU4L1csclICJeFT+GAM7739ME2mYhUn1LtJ0V 8Ou97edUzXC1A== 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 23BD94DE2 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8385D3A1862 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:23 +0200 Message-ID: <20240716171155.31838-8-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/39] lavc/ffv1: move sample_buffer to the per-slice context 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: EX5+F+iHgpsC --- libavcodec/ffv1.c | 35 ++++++++++++++++++++--------------- libavcodec/ffv1.h | 5 +++-- libavcodec/ffv1dec.c | 27 +++++++++++++-------------- libavcodec/ffv1dec_template.c | 9 +++++---- libavcodec/ffv1enc.c | 30 ++++++++++++++++-------------- libavcodec/ffv1enc_template.c | 9 +++++---- 6 files changed, 62 insertions(+), 53 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 25f28287c0..a102425596 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -112,6 +112,8 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) if (!f->slices) return AVERROR(ENOMEM); + f->max_slice_count = max_slice_count; + for (i = 0; i < max_slice_count;) { FFV1SliceContext *sc = &f->slices[i]; int sx = i % f->num_h_slices; @@ -123,7 +125,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) FFV1Context *fs = av_mallocz(sizeof(*fs)); if (!fs) - goto memfail; + return AVERROR(ENOMEM); f->slice_context[i++] = fs; memcpy(fs, f, sizeof(*fs)); @@ -134,19 +136,15 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) sc->slice_x = sxs; sc->slice_y = sys; - fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * - sizeof(*fs->sample_buffer)); - fs->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * - sizeof(*fs->sample_buffer32)); - if (!fs->sample_buffer || !fs->sample_buffer32) - goto memfail; + sc->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * + sizeof(*sc->sample_buffer)); + sc->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * + sizeof(*sc->sample_buffer32)); + if (!sc->sample_buffer || !sc->sample_buffer32) + return AVERROR(ENOMEM); } - f->max_slice_count = max_slice_count; - return 0; -memfail: - f->max_slice_count = i; - return AVERROR(ENOMEM); + return 0; } int ff_ffv1_allocate_initial_states(FFV1Context *f) @@ -199,14 +197,20 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) for (j = 0; j < s->max_slice_count; j++) { FFV1Context *fs = s->slice_context[j]; + FFV1SliceContext *sc = &s->slices[j]; + + av_freep(&sc->sample_buffer); + av_freep(&sc->sample_buffer32); + + if (!fs) + continue; + for (i = 0; i < s->plane_count; i++) { PlaneContext *p = &fs->plane[i]; av_freep(&p->state); av_freep(&p->vlc_state); } - av_freep(&fs->sample_buffer); - av_freep(&fs->sample_buffer32); } av_freep(&avctx->stats_out); @@ -214,7 +218,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) av_freep(&s->initial_states[j]); for (i = 0; i < s->max_slice_count; i++) { FFV1Context *sf = s->slice_context[i]; - av_freep(&sf->rc_stat2[j]); + if (sf) + av_freep(&sf->rc_stat2[j]); } av_freep(&s->rc_stat2[j]); } diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 256904b283..ccb510a483 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -70,6 +70,9 @@ typedef struct PlaneContext { #define MAX_SLICES 1024 typedef struct FFV1SliceContext { + int16_t *sample_buffer; + int32_t *sample_buffer32; + int slice_width; int slice_height; int slice_x; @@ -108,8 +111,6 @@ typedef struct FFV1Context { uint8_t (*initial_states[MAX_QUANT_TABLES])[32]; int run_index; int colorspace; - int16_t *sample_buffer; - int32_t *sample_buffer32; int use32bit; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 28e4a05b21..fcf8977a36 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -117,18 +117,18 @@ static int is_input_end(FFV1Context *s) #define RENAME(name) name ## 32 #include "ffv1dec_template.c" -static int decode_plane(FFV1Context *s, uint8_t *src, - int w, int h, int stride, int plane_index, +static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, + uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { int x, y; int16_t *sample[2]; - sample[0] = s->sample_buffer + 3; - sample[1] = s->sample_buffer + w + 6 + 3; + sample[0] = sc->sample_buffer + 3; + sample[1] = sc->sample_buffer + w + 6 + 3; s->run_index = 0; - memset(s->sample_buffer, 0, 2 * (w + 6) * sizeof(*s->sample_buffer)); + memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer)); for (y = 0; y < h; y++) { int16_t *temp = sample[0]; // FIXME: try a normal buffer @@ -333,29 +333,29 @@ static int decode_slice(AVCodecContext *c, void *arg) const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift); const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + decode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + decode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (fs->transparency) - decode_plane(fs, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); + decode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); } else if (f->colorspace == 0) { - decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); - decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); + decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); + decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame32(fs, planes, width, height, p->linesize); + decode_rgb_frame32(fs, sc, planes, width, height, p->linesize); } else { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame(fs, planes, width, height, p->linesize); + decode_rgb_frame(fs, sc, planes, width, height, p->linesize); } if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { int v; @@ -1084,7 +1084,6 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) } } av_assert0(!fdst->plane[0].state); - av_assert0(!fdst->sample_buffer); av_assert1(fdst->max_slice_count == fsrc->max_slice_count); diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index a90c28cd0e..b9316e04ca 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -127,7 +127,8 @@ static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w, return 0; } -static int RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int h, int stride[4]) +static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, + uint8_t *src[4], int w, int h, int stride[4]) { int x, y, p; TYPE *sample[4][2]; @@ -137,13 +138,13 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, uint8_t *src[4], int w, int int transparency = s->transparency; for (x = 0; x < 4; x++) { - sample[x][0] = RENAME(s->sample_buffer) + x * 2 * (w + 6) + 3; - sample[x][1] = RENAME(s->sample_buffer) + (x * 2 + 1) * (w + 6) + 3; + sample[x][0] = RENAME(sc->sample_buffer) + x * 2 * (w + 6) + 3; + sample[x][1] = RENAME(sc->sample_buffer) + (x * 2 + 1) * (w + 6) + 3; } s->run_index = 0; - memset(RENAME(s->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(s->sample_buffer))); + memset(RENAME(sc->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(sc->sample_buffer))); for (y = 0; y < h; y++) { for (p = 0; p < 3 + transparency; p++) { diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index c46df15b0c..f6b1919ee4 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -269,7 +269,8 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, #define RENAME(name) name ## 32 #include "ffv1enc_template.c" -static int encode_plane(FFV1Context *s, const uint8_t *src, int w, int h, +static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, + const uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { int x, y, i, ret; @@ -277,11 +278,11 @@ static int encode_plane(FFV1Context *s, const uint8_t *src, int w, int h, int16_t *sample[3]; s->run_index = 0; - memset(s->sample_buffer, 0, ring_size * (w + 6) * sizeof(*s->sample_buffer)); + memset(sc->sample_buffer, 0, ring_size * (w + 6) * sizeof(*sc->sample_buffer)); for (y = 0; y < h; y++) { for (i = 0; i < ring_size; i++) - sample[i] = s->sample_buffer + (w + 6) * ((h + i - y) % ring_size) + 3; + sample[i] = sc->sample_buffer + (w + 6) * ((h + i - y) % ring_size) + 3; sample[0][-1]= sample[1][0 ]; sample[1][ w]= sample[1][w-1]; @@ -938,7 +939,8 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs, } } -static void choose_rct_params(FFV1Context *fs, const uint8_t *src[3], const int stride[3], int w, int h) +static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, + const uint8_t *src[3], const int stride[3], int w, int h) { #define NB_Y_COEFF 15 static const int rct_y_coeff[15][2] = { @@ -968,7 +970,7 @@ static void choose_rct_params(FFV1Context *fs, const uint8_t *src[3], const int for (y = 0; y < h; y++) { int lastr=0, lastg=0, lastb=0; for (p = 0; p < 3; p++) - sample[p] = fs->sample_buffer + p*w; + sample[p] = sc->sample_buffer + p*w; for (x = 0; x < w; x++) { int b, g, r; @@ -1041,7 +1043,7 @@ static int encode_slice(AVCodecContext *c, void *arg) fs->slice_coding_mode = 0; if (f->version > 3) { - choose_rct_params(fs, planes, p->linesize, width, height); + choose_rct_params(fs, sc, planes, p->linesize, width, height); } else { fs->slice_rct_by_coef = 1; fs->slice_rct_ry_coef = 1; @@ -1066,21 +1068,21 @@ retry: const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - ret = encode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + ret = encode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - ret |= encode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - ret |= encode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + ret |= encode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + ret |= encode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (fs->transparency) - ret |= encode_plane(fs, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); + ret |= encode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); } else if (c->pix_fmt == AV_PIX_FMT_YA8) { - ret = encode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); - ret |= encode_plane(fs, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); + ret = encode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); + ret |= encode_plane(fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { - ret = encode_rgb_frame32(fs, planes, width, height, p->linesize); + ret = encode_rgb_frame32(fs, sc, planes, width, height, p->linesize); } else { - ret = encode_rgb_frame(fs, planes, width, height, p->linesize); + ret = encode_rgb_frame(fs, sc, planes, width, height, p->linesize); } if (ret < 0) { diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 8953dbe07c..85fbac224b 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -124,7 +124,8 @@ static av_always_inline int RENAME(encode_line)(FFV1Context *s, int w, return 0; } -static int RENAME(encode_rgb_frame)(FFV1Context *s, const uint8_t *src[4], +static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, + const uint8_t *src[4], int w, int h, const int stride[4]) { int x, y, p, i; @@ -139,13 +140,13 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, const uint8_t *src[4], s->run_index = 0; - memset(RENAME(s->sample_buffer), 0, ring_size * MAX_PLANES * - (w + 6) * sizeof(*RENAME(s->sample_buffer))); + memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES * + (w + 6) * sizeof(*RENAME(sc->sample_buffer))); for (y = 0; y < h; y++) { for (i = 0; i < ring_size; i++) for (p = 0; p < MAX_PLANES; p++) - sample[p][i]= RENAME(s->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3; + sample[p][i]= RENAME(sc->sample_buffer) + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3; for (x = 0; x < w; x++) { int b, g, r, av_uninit(a); From patchwork Tue Jul 16 17:11:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50596 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp472141vqb; Tue, 16 Jul 2024 11:26:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVTctFkprOCUnV0+9RFiiizPOnkrz/RyNSBptxG2eeGiutrIRAbxAeNBSCkCS20sVETU+KJT2Z9EA24hnWOPvnKTm/1fxH4/OPHTA== X-Google-Smtp-Source: AGHT+IG4Y2HU4BgSwdyTb7pEGGSIkTw0RlcV5BA8LhiiUqnEIeAWm//d3oMYr8f5VT9knSKKlaiy X-Received: by 2002:a50:8e4f:0:b0:57d:5442:a709 with SMTP id 4fb4d7f45d1cf-59f076a2869mr3035231a12.0.1721154410805; Tue, 16 Jul 2024 11:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154410; cv=none; d=google.com; s=arc-20160816; b=BiAL7tAh0oqHh+ctmjwlUEoCqTjk9jZLAEcAoDu3H3ib2UYdSNL67XEtIC5SppdvQ3 dsfL8HnRVeMJ85V3rkvQdMLhUcC537MIBCoBkv9qoZab+5fdC5FX8Bu9pbVBfyQ/zYsP DgtW2N2/b4LnQw6CaLRmYQ8sNqoqmXuBR1kCq/XvdiIJ5TT4VGIR7nbPsNho+so5uu1B UrRQDHhq11bcIXaVo1wPFGpYYCUMXTKfprjxwGu+qvKKA9FkbDQ6wfqqdMizWN7nehwl Jv151hCjDpriU6aE8pR33pEldng89WbWY2M2jhx9HfLCdoUj2ajCgtv4IcyzX+IqsWjR 2zag== 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=dX01FBKKBxtThO4Gl2z16cuLfUNPpLPnP1OrUAalfhI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Y3Nx0csNUG2dt0o0LWhQNfFBucFmTMzpxF92N8L4R7ewAoDZYqKWRG905FQBC1CHQ7 pFvq9YM3c0pYMwDy40XMh1iwZczRtwr4p6uYiiHJiBdvBBxAvU8SZWc1n4qpK3HakWjO xPa8abwu668BHmpT2AZWHBmFgd+K1UcbPLT8OUQFugsKaNO+deAig2oxcXSchKU7uEjb /zWuh8If4ggrlkcYDh2miVuCJvt4Ga6Wa95K8Y/ll/14BhHgHgphItaRye8HdP05G/VI DNjlb6mPWA+dXizqTQQl7MB/kGODc8ANqiMHhyEPu6RUNps7aIEaAO290nS093QAUUXL uWOQ==; 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=CIcR8qAY; 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 4fb4d7f45d1cf-59cf5d607b8si2770006a12.278.2024.07.16.11.26.50; Tue, 16 Jul 2024 11:26: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=CIcR8qAY; 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 34FAF68DB6D; Tue, 16 Jul 2024 21:14:28 +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 A98F968DAA3 for ; Tue, 16 Jul 2024 21:14:04 +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=CIcR8qAY; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id B7B754DE9 for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id T7oXt6TVSCzc for ; Tue, 16 Jul 2024 19:16:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=XaKE7i+IoOi+3WGLPsBuoLdSm+6P5eXvJefJZIqvQiI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CIcR8qAYaN4Y03CBr9mTYeXEEnR6ql/HNzKeiR2iuKzL17Lm48IJ9whExUb4ll1Ao btHXc0aFu7FH3hmLD7trlcGdibTJGWu1VXT+u4dnzQEHfAtJgr8ODePW5sgh6/8ovK Fen+CJYXVHg7gm4tCAtXFM7gts/GW2+1E8KxD0tr6YxXn0gOl75aIAyFAxYG/zPrgR tSwypKKvCzduFcKNL3nClG27ICn/znm+WHO5Jhrw7xkSztwlb6GlqCwPrkkYIP+kps ZG9frZoxLmmryWAfcfHLA3X+XetO4paKbCx9AS9sC1pE1gC+j6tR69+YGLdWX90Bhl 1JC2rxDHl5UtQ== 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 36D744DE6 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8F5063A1A22 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:24 +0200 Message-ID: <20240716171155.31838-9-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/39] lavc/ffv1: move run_index to the per-slice context 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: AsINHvbbG+HS --- libavcodec/ffv1.h | 3 ++- libavcodec/ffv1dec.c | 6 +++--- libavcodec/ffv1dec_template.c | 16 ++++++++-------- libavcodec/ffv1enc.c | 6 +++--- libavcodec/ffv1enc_template.c | 16 ++++++++-------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index ccb510a483..68d13a2964 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -77,6 +77,8 @@ typedef struct FFV1SliceContext { int slice_height; int slice_x; int slice_y; + + int run_index; } FFV1SliceContext; typedef struct FFV1Context { @@ -109,7 +111,6 @@ typedef struct FFV1Context { int context_count[MAX_QUANT_TABLES]; uint8_t state_transition[256]; uint8_t (*initial_states[MAX_QUANT_TABLES])[32]; - int run_index; int colorspace; int use32bit; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index fcf8977a36..a2971d7eea 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -126,7 +126,7 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, sample[0] = sc->sample_buffer + 3; sample[1] = sc->sample_buffer + w + 6 + 3; - s->run_index = 0; + sc->run_index = 0; memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer)); @@ -140,13 +140,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, sample[0][w] = sample[0][w - 1]; if (s->avctx->bits_per_raw_sample <= 8) { - int ret = decode_line(s, w, sample, plane_index, 8); + int ret = decode_line(s, sc, w, sample, plane_index, 8); if (ret < 0) return ret; for (x = 0; x < w; x++) src[x*pixel_stride + stride * y] = sample[1][x]; } else { - int ret = decode_line(s, w, sample, plane_index, s->avctx->bits_per_raw_sample); + int ret = decode_line(s, sc, w, sample, plane_index, s->avctx->bits_per_raw_sample); if (ret < 0) return ret; if (s->packed_at_lsb) { diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index b9316e04ca..8e2e38c0b9 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -22,16 +22,16 @@ #include "ffv1_template.c" -static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w, - TYPE *sample[2], - int plane_index, int bits) +static av_always_inline int +RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, + TYPE *sample[2], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; int x; int run_count = 0; int run_mode = 0; - int run_index = s->run_index; + int run_index = sc->run_index; if (is_input_end(s)) return AVERROR_INVALIDDATA; @@ -123,7 +123,7 @@ static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w, sample[1][x] = av_zero_extend(RENAME(predict)(sample[1] + x, sample[0] + x) + (SUINT)diff, bits); } - s->run_index = run_index; + sc->run_index = run_index; return 0; } @@ -142,7 +142,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, sample[x][1] = RENAME(sc->sample_buffer) + (x * 2 + 1) * (w + 6) + 3; } - s->run_index = 0; + sc->run_index = 0; memset(RENAME(sc->sample_buffer), 0, 8 * (w + 6) * sizeof(*RENAME(sc->sample_buffer))); @@ -157,9 +157,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; if (lbd && s->slice_coding_mode == 0) - ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9); + ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, 9); else - ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); if (ret < 0) return ret; } diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index f6b1919ee4..8bb9174a1d 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -276,7 +276,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, int x, y, i, ret; const int ring_size = s->context_model ? 3 : 2; int16_t *sample[3]; - s->run_index = 0; + sc->run_index = 0; memset(sc->sample_buffer, 0, ring_size * (w + 6) * sizeof(*sc->sample_buffer)); @@ -289,7 +289,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, if (s->bits_per_raw_sample <= 8) { for (x = 0; x < w; x++) sample[0][x] = src[x * pixel_stride + stride * y]; - if((ret = encode_line(s, w, sample, plane_index, 8)) < 0) + if((ret = encode_line(s, sc, w, sample, plane_index, 8)) < 0) return ret; } else { if (s->packed_at_lsb) { @@ -301,7 +301,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample); } } - if((ret = encode_line(s, w, sample, plane_index, s->bits_per_raw_sample)) < 0) + if((ret = encode_line(s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0) return ret; } } diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 85fbac224b..4dccd531a8 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -22,14 +22,14 @@ #include "ffv1_template.c" -static av_always_inline int RENAME(encode_line)(FFV1Context *s, int w, - TYPE *sample[3], - int plane_index, int bits) +static av_always_inline int +RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, + int w, TYPE *sample[3], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; int x; - int run_index = s->run_index; + int run_index = sc->run_index; int run_count = 0; int run_mode = 0; @@ -119,7 +119,7 @@ static av_always_inline int RENAME(encode_line)(FFV1Context *s, int w, if (run_count) put_bits(&s->pb, 1, 1); } - s->run_index = run_index; + sc->run_index = run_index; return 0; } @@ -138,7 +138,7 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, int transparency = s->transparency; int packed_size = (3 + transparency)*2; - s->run_index = 0; + sc->run_index = 0; memset(RENAME(sc->sample_buffer), 0, ring_size * MAX_PLANES * (w + 6) * sizeof(*RENAME(sc->sample_buffer))); @@ -193,9 +193,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, sample[p][0][-1] = sample[p][1][0 ]; sample[p][1][ w] = sample[p][1][w-1]; if (lbd && s->slice_coding_mode == 0) - ret = RENAME(encode_line)(s, w, sample[p], (p + 1) / 2, 9); + ret = RENAME(encode_line)(s, sc, w, sample[p], (p + 1) / 2, 9); else - ret = RENAME(encode_line)(s, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(encode_line)(s, sc, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1)); if (ret < 0) return ret; } From patchwork Tue Jul 16 17:11:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50588 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp468003vqb; Tue, 16 Jul 2024 11:17:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUC0zEup2kfqg4Y1AR6YghnO0TRZJv9reFF8Cgnaff9UXGczKrcJgi/9T88cU4Rh5+KcXbrmkS1ULoRecgeX6khZ6Yxwwgbl/vxfQ== X-Google-Smtp-Source: AGHT+IF/pBXDq9uZFBvCayeas1CQ2RzbmAQWiOe7nSVleB0EGvV+Axz/FmS5Z9FxLkIrqX7kNvvm X-Received: by 2002:a05:6512:1149:b0:52e:be1f:bf84 with SMTP id 2adb3069b0e04-52edf0345e4mr1921978e87.53.1721153828647; Tue, 16 Jul 2024 11:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153828; cv=none; d=google.com; s=arc-20160816; b=arxngNymgYavVsCJPBunucMURN7d6ZhdFdVgpIGnA5VbN9BgfHAHND/+OKtsTreUvE K8DAaXGBlNFioDjREhGbW/KIpEsKIDrFfGeZN/PcpwFTLKivfX5UfNCA78JRNk8CorbR 6mRPELIyJHsE9/R0WuBUvPBaSuZveweZ7XB7J3JIVlQgBLJryoVAxblFQFszE/xGuXeX KDogYnBM8vy+pxA0OgnerJLg59i7wiuUHx5ginJFGhr5D7HvjX8V4cj12Hb2Y/ltdt3K X+BuLz0SMFW/rXuaeuL5gOqePAQdmASJnqLeRT0kLIfKjOhmuCtfvctt62vQgThGUiDC ZczA== 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=jUk0/E04RWggASDyNZNOZMuRQ95mUuzdD2PlWeeTYJU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Gs6QXrBAt/EWovf9nBrKrdD0ubOljPii4yp/sCg9o/TZvN+AYpnZRYU5MJTDDMIn/W EXClFVxzU3eW7xxFOHz8jcbjpmaGU6GXo3LX6mjYHo/gaZXDKRiDNTxgd1CxL9dDobyK SHcQgi6lMIu3khDg1n3LaF0x4RO6vDIaDzhes02Tfq50JttNvRCzalwaj2CQPIUnjPw2 9j2qJ3XfkvPzJJyVgoR0+xFasWBanKBKNhUx2TqI2s3Je7718gKpgX6XRbsSbu8fbmK+ AdXlXaJeVH0VhQuADu3MJdM7pqaDoql3y3fgJg7rsG958nTlAOqo/wjX/FUyiTSmBvEZ kXng==; 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=PZHnSeoz; 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-52ed255c1a6si2344595e87.320.2024.07.16.11.17.08; Tue, 16 Jul 2024 11:17:08 -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=PZHnSeoz; 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 D577268DBE1; Tue, 16 Jul 2024 21:14:32 +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 C310668DAB9 for ; Tue, 16 Jul 2024 21:14:04 +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=PZHnSeoz; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3F0234E06 for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 9zLWPTOopYcP for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=1Y3CMGcvJ29d0oKadwkFfgja0lbkLfY4mjlYCwMs+p8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PZHnSeozCEy4UleZ3hOmDMTR56zyZI41fF30g2b0cEK5nJnKKdxjVKTwss1H6HWNp qMKdEYI9qWQK/3NdYxxb8kutKV92it0ieiVocY8qmrZIdwyvJY0rkgqajtkEI2TsN6 /2TY3hAAHHSyHPdFYBVEYSpJ5iH5h3I1xG5LmniXDPwZ4xCxt61RstrbWNl/jdEp04 HBPn249xJVFlqCKoMcxKrsAZ2mmIt7LZGY0xuKjPzfPfxxJYcIXKXD0DhkC0hqH8fd mMAFg71z1L74plTBA46EVkpbJih25XkvsKFpJIAtKO2NJDDx91SJpXs4cz2+Zl6bNa h5zJds4kfF8rw== 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 6B57A4DEC for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9AEC63A1EA0 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:25 +0200 Message-ID: <20240716171155.31838-10-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/39] lavc/ffv1dec: move the bitreader to stack 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: KHFf4DftUHS8 There is no reason to place it in persistent state. --- libavcodec/ffv1.h | 1 - libavcodec/ffv1dec.c | 28 +++++++++++++++------------- libavcodec/ffv1dec_template.c | 23 ++++++++++++----------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 68d13a2964..c88aa8c30d 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -85,7 +85,6 @@ typedef struct FFV1Context { AVClass *class; AVCodecContext *avctx; RangeCoder c; - GetBitContext gb; PutBitContext pb; uint64_t rc_stat[256][2]; uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index a2971d7eea..a1f7206871 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -94,14 +94,14 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, return ret; } -static int is_input_end(FFV1Context *s) +static int is_input_end(FFV1Context *s, GetBitContext *gb) { if (s->ac != AC_GOLOMB_RICE) { RangeCoder *const c = &s->c; if (c->overread > MAX_OVERREAD) return AVERROR_INVALIDDATA; } else { - if (get_bits_left(&s->gb) < 1) + if (get_bits_left(gb) < 1) return AVERROR_INVALIDDATA; } return 0; @@ -118,6 +118,7 @@ static int is_input_end(FFV1Context *s) #include "ffv1dec_template.c" static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, + GetBitContext *gb, uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { @@ -140,13 +141,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, sample[0][w] = sample[0][w - 1]; if (s->avctx->bits_per_raw_sample <= 8) { - int ret = decode_line(s, sc, w, sample, plane_index, 8); + int ret = decode_line(s, sc, gb, w, sample, plane_index, 8); if (ret < 0) return ret; for (x = 0; x < w; x++) src[x*pixel_stride + stride * y] = sample[1][x]; } else { - int ret = decode_line(s, sc, w, sample, plane_index, s->avctx->bits_per_raw_sample); + int ret = decode_line(s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample); if (ret < 0) return ret; if (s->packed_at_lsb) { @@ -262,6 +263,7 @@ static int decode_slice(AVCodecContext *c, void *arg) AVFrame * const p = f->picture.f; const int si = (FFV1Context**)arg - f->slice_context; FFV1SliceContext *sc = &f->slices[si]; + GetBitContext gb; if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) ff_progress_frame_await(&f->last_picture, si); @@ -322,7 +324,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->version == 3 && f->micro_version > 1 || f->version > 3) get_rac(&fs->c, (uint8_t[]) { 129 }); fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0; - init_get_bits(&fs->gb, + init_get_bits(&gb, fs->c.bytestream_start + fs->ac_byte_count, (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8); } @@ -333,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg) const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift); const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - decode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - decode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + decode_plane(fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + decode_plane(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (fs->transparency) - decode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); + decode_plane(fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); } else if (f->colorspace == 0) { - decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); - decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); + decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); + decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame32(fs, sc, planes, width, height, p->linesize); + decode_rgb_frame32(fs, sc, &gb, planes, width, height, p->linesize); } else { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame(fs, sc, planes, width, height, p->linesize); + decode_rgb_frame(fs, sc, &gb, planes, width, height, p->linesize); } if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { int v; diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 8e2e38c0b9..e9d3002be9 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -23,8 +23,8 @@ #include "ffv1_template.c" static av_always_inline int -RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, - TYPE *sample[2], int plane_index, int bits) +RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, + int w, TYPE *sample[2], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; RangeCoder *const c = &s->c; @@ -33,7 +33,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, int run_mode = 0; int run_index = sc->run_index; - if (is_input_end(s)) + if (is_input_end(s, gb)) return AVERROR_INVALIDDATA; if (s->slice_coding_mode == 1) { @@ -53,7 +53,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, int diff, context, sign; if (!(x & 1023)) { - if (is_input_end(s)) + if (is_input_end(s, gb)) return AVERROR_INVALIDDATA; } @@ -74,13 +74,13 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, if (run_mode) { if (run_count == 0 && run_mode == 1) { - if (get_bits1(&s->gb)) { + if (get_bits1(gb)) { run_count = 1 << ff_log2_run[run_index]; if (x + run_count <= w) run_index++; } else { if (ff_log2_run[run_index]) - run_count = get_bits(&s->gb, ff_log2_run[run_index]); + run_count = get_bits(gb, ff_log2_run[run_index]); else run_count = 0; if (run_index) @@ -105,17 +105,17 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, if (run_count < 0) { run_mode = 0; run_count = 0; - diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], + diff = get_vlc_symbol(gb, &p->vlc_state[context], bits); if (diff >= 0) diff++; } else diff = 0; } else - diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits); + diff = get_vlc_symbol(gb, &p->vlc_state[context], bits); ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", - run_count, run_index, run_mode, x, get_bits_count(&s->gb)); + run_count, run_index, run_mode, x, get_bits_count(gb)); } if (sign) @@ -128,6 +128,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, } static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, + GetBitContext *gb, uint8_t *src[4], int w, int h, int stride[4]) { int x, y, p; @@ -157,9 +158,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; if (lbd && s->slice_coding_mode == 0) - ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, 9); + ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, 9); else - ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); if (ret < 0) return ret; } From patchwork Tue Jul 16 17:11:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50605 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp559307vqb; Tue, 16 Jul 2024 14:51:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVndlZ78Qi+B9cM0kVxShaUUTtIFZNGXZMRI2u+QgmNXTDBZUMjOrTZv4+fOSROd1oDgNbhvQm+eytnqkWkBazaCNSE6kH+QSikSQ== X-Google-Smtp-Source: AGHT+IEUFsOGKrCIrLgPScyGlflqp1kPIXOPXmC6QJTKIonIoRZLAvhGWQeAN2BOpzudvbQXjYMt X-Received: by 2002:a05:651c:237:b0:2ee:8c48:ffaf with SMTP id 38308e7fff4ca-2eef41eb0d3mr22601541fa.47.1721166709442; Tue, 16 Jul 2024 14:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721166709; cv=none; d=google.com; s=arc-20160816; b=n9mfRZRrwuzUGuA0xXVMkObNMIMgDpxjoZKcTZKdHDMf9RzoCnlHLbv02RaUzIkaDa Nk7yFp/pTFSIjVAmAvzHcBEOjAnWJKHRWFhUOZNjI9RWkjrZZrMQGHhhANDGDz9ppHq8 rncimAayq26NmCpxqNRnyDF79W7B9CP1HmDkj0HhxzqCfniOo4vdFzG0totWkX4ONhYi wusA+MaRhcWQwWABTKIRadNvum08kmuQfIs1YQVhcokBsTT+kmdd9jG6Ck9Wg3Mp+Yxa nsSIYLb9502hYGTcsh3KnOJemBCDnVkIps7h9nklqe89iixvkIiOSkYOVP7vc7ZKS1TJ +RBQ== 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=I4HUAKGzAyjR8kb/hp0ldPwZ2dCxJ9giLrDhGtTHGkM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=N/q12f33BVvvnb+KRhzAJWdz9sjh/aZq01E43QhfJW9ykXNBA4qDMKKESswfn7IHTN LYrJgmP2E6er7drxqOYpwlLh0hPts4ZNDGOLjeo/Gr8WJ0AP1LbHuDzTNz+hIvtLQsU1 1TSUenvsDv3Y9DDwpY/W+9ARR0+KmAsHsVkEwuZmJdUsMJlqYwU2dwUSkYeIfUG8bZfu 9kgwD/Gfj5Qui2BnjZFuTVqfijj88P2JoiQmWID4B13RxMUNrC4oYcdcGX5lkDHOKa1g E9EXHyjRvsW+am8Z+lMTyghc1mFEsGM3esHHRnvwlPlir3JlIThVtcUTEJhBmXerkyjS 95WA==; 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=oM86FmLX; 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 38308e7fff4ca-2eee190f96asi20887361fa.234.2024.07.16.14.51.49; Tue, 16 Jul 2024 14:51:49 -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=oM86FmLX; 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 0FF3368DB28; Tue, 16 Jul 2024 21:14:21 +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 84DCF68DA38 for ; Tue, 16 Jul 2024 21:14:04 +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=oM86FmLX; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id DDD0F4DF5 for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id YRY_qPvl97YX for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=Qw2kyh5MElUzmcAt70EAsd6r7vSsH8da6CaRAeF1tHQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oM86FmLXsfdAHmFHhzJzy+hmU4IpAwgn+NPRf/E9wIRIfq+heuhUbqvyDfUP18Yb/ WTO/EnAgFi7IaZ/caPyBW0JGykhgMLv63Wuyf3QUa4cZZRnRgAKnbvvulrPFCUVCkJ +WNVKZ8HfjsDl8Zu3dmb18d5usUtEKm8xkLN/R6sSKVZ3lqgAsnQaP6JdEScWJiR1v /JbIkwXyDunJ5T4N8NHVV3tCtgA/gjFe3QHs4lQ0DjAic4/+cJrQw1PnUehiX3EgHb rLmPLyABbnh8sCAHcsHWO3HciQvH9u9DermIRaUw8uIkqf33Vyn/5rQmj9GY61KFgc 48oBOBGuktB/w== 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 6621C4DF2 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A6A323A25B7 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:26 +0200 Message-ID: <20240716171155.31838-11-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/39] lavc/ffv1enc: move bit writer to per-slice context 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: Nhmy9ulXkbsv --- libavcodec/ffv1.h | 3 ++- libavcodec/ffv1enc.c | 7 ++++--- libavcodec/ffv1enc_template.c | 14 +++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index c88aa8c30d..dce6e177eb 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -79,13 +79,14 @@ typedef struct FFV1SliceContext { int slice_y; int run_index; + + PutBitContext pb; } FFV1SliceContext; typedef struct FFV1Context { AVClass *class; AVCodecContext *avctx; RangeCoder c; - PutBitContext pb; uint64_t rc_stat[256][2]; uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; int version; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 8bb9174a1d..5692bfa1fc 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1057,7 +1057,7 @@ retry: } if (fs->ac == AC_GOLOMB_RICE) { fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; - init_put_bits(&fs->pb, + init_put_bits(&sc->pb, fs->c.bytestream_start + fs->ac_byte_count, fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count); } @@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, buf_p = pkt->data; for (i = 0; i < f->slice_count; i++) { FFV1Context *fs = f->slice_context[i]; + FFV1SliceContext *sc = &f->slices[i]; int bytes; if (fs->ac != AC_GOLOMB_RICE) { bytes = ff_rac_terminate(&fs->c, 1); } else { - flush_put_bits(&fs->pb); // FIXME: nicer padding - bytes = fs->ac_byte_count + put_bytes_output(&fs->pb); + flush_put_bits(&sc->pb); // FIXME: nicer padding + bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); } if (i > 0 || f->version > 2) { av_assert0(bytes < pkt->size / f->slice_count); diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 4dccd531a8..8b9e53fa1b 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -39,7 +39,7 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, return AVERROR_INVALIDDATA; } } else { - if (put_bytes_left(&s->pb, 0) < w * 4) { + if (put_bytes_left(&sc->pb, 0) < w * 4) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } @@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, while (run_count >= 1 << ff_log2_run[run_index]) { run_count -= 1 << ff_log2_run[run_index]; run_index++; - put_bits(&s->pb, 1, 1); + put_bits(&sc->pb, 1, 1); } - put_bits(&s->pb, 1 + ff_log2_run[run_index], run_count); + put_bits(&sc->pb, 1 + ff_log2_run[run_index], run_count); if (run_index) run_index--; run_count = 0; @@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, - (int)put_bits_count(&s->pb)); + (int)put_bits_count(&sc->pb)); if (run_mode == 0) - put_vlc_symbol(&s->pb, &p->vlc_state[context], diff, bits); + put_vlc_symbol(&sc->pb, &p->vlc_state[context], diff, bits); } } if (run_mode) { while (run_count >= 1 << ff_log2_run[run_index]) { run_count -= 1 << ff_log2_run[run_index]; run_index++; - put_bits(&s->pb, 1, 1); + put_bits(&sc->pb, 1, 1); } if (run_count) - put_bits(&s->pb, 1, 1); + put_bits(&sc->pb, 1, 1); } sc->run_index = run_index; From patchwork Tue Jul 16 17:11:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50589 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp468255vqb; Tue, 16 Jul 2024 11:17:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUgtmYUq5/KEdbNY/3XkE5FJFV9hkXZwafNSRaO8jsvQJcU00rYvrb2I1FilHoWm62MT0Xev4k7tWXeibsFpFULdOCKKV31FtyomA== X-Google-Smtp-Source: AGHT+IF/EQwzWhf3Y8fOacKEGR9fujSpnyztuP4Hf0T3y4pLBkl32U/XL/lkTvUjS/1bG+rY+YzD X-Received: by 2002:a17:906:a20c:b0:a72:66d5:892c with SMTP id a640c23a62f3a-a79edc0e7cbmr204275566b.18.1721153864372; Tue, 16 Jul 2024 11:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153864; cv=none; d=google.com; s=arc-20160816; b=qK0WwPanMMffLdkA3iUBYn+SfXh1jHcViwennIbQXDc8dnreWdjGswoIPT/EbLzOWP VUZu841ro0CLkWD3ieE5ZwDSmMpinWmXt+hFqcKoyWywWUqtHzBKKhLZo0JKRQRfoY+Z TDKiaMmHL/eyGtHxMGihgf3CzCnRR26GdEmE24JjZxGh1RHQKHVfRXFYxDMj2lzoaXTt 6xJfdV4f8acXmubOHYxXd3HX9wLBtqVWv/KOnxkhrqACNMCrKjQN2V98cZArfFofWE0M I96mQ7cmyGNDEIyDDPvnEGMKlqbDCBPqIiNGyytcXeZFEjQG4yAoZJcMgLCVu0TrqviT LpWQ== 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=bGJjZNCY/rzd0ft+L97wIJr42gC8aBvQZypw+YMHmsI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=pwW9NenlqbQfW8XEM98E43JeF8Ljk6BHl3vDudGvw/q5xiYYkscDgNyGPwzBNrx/u4 aQs7WqAOf0cVx56aXLgxvLH5+kgDAyiTGUn3zvsAx2te5mAOwequikQpSBKJveLjBOQC WYPKr7Ny14vkJSjFxAxi/1eMZLCWg/zvLREP3Gz6kuPtjrjj51A6tq4VnVTf+wOt5Z5x 8g+3A+ycadLclSbSRNf+eKjb4zPwvjp+zC8ZZGiu8c64t+KlLhzCC7AI04OSFvrKee09 50EFapnIu8HZ7A1EDgIbRcBNysWI6GRakE3h3I3pQrEL2BXKdurcB6zibP25jxjjC30x pL2w==; 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=ChmZu19n; 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-a79bc7c168dsi402488166b.418.2024.07.16.11.17.43; Tue, 16 Jul 2024 11:17:44 -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=ChmZu19n; 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 3BD8168DC0D; Tue, 16 Jul 2024 21:14:39 +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 2A2B668DAC5 for ; Tue, 16 Jul 2024 21:14:05 +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=ChmZu19n; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C049F4DBC for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id iPxAD0SO3y1r for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=qZIlLlE40mRFqdqDRmXA3++kcjQhODAinxRl+47kCXc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ChmZu19nmJ1slGAzpbczWObp79uhGMwrKxAj0ZMKTgN4fh7PG+0KZXDqPkQoir0Fw /jFXejQqaUQWy9F5oVaUt1diiXnFXU74yF5jXw8Irsi9w3FuIeJ/0sH7sbgUqeTKqZ 4DmTy4fEyMKpCF/gJbVmCiISh1G8uw2jv/DAHOJ1VM/IZVmXhfrb2z3GgI1luBt8va ho8iWj67agzmKmB7F+4eBhGMwA46zms5OFX5nXBywjcHxPdKWi4K+VDG/HerEyBye8 /E6u2B+cXZx+iMSlUw0gUwpd1tJ8Z1PKVjk/GQnEXagJwNX5+uefHCOOjYxw6uMnqL b7zraOFPA6tMQ== 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 69BB14DF3 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B208D3A2729 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:27 +0200 Message-ID: <20240716171155.31838-12-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/39] lavc/ffv1: drop redundant FFV1Context.quant_table 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: sx+DRqVORrxj In all cases except decoding version 1 it's either not used, or contains a copy of a table from quant_tables, which we can just as well use directly. When decoding version 1, we can just as well decode into quant_tables[0], which would otherwise be unused. --- libavcodec/ffv1.h | 1 - libavcodec/ffv1dec.c | 10 +++++++--- libavcodec/ffv1enc.c | 6 ++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index dce6e177eb..4d57172d5b 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -106,7 +106,6 @@ typedef struct FFV1Context { int ac; ///< 1=range coder <-> 0=golomb rice int ac_byte_count; ///< number of bytes used for AC coding PlaneContext plane[MAX_PLANES]; - int16_t quant_table[MAX_CONTEXT_INPUTS][256]; int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256]; int context_count[MAX_QUANT_TABLES]; uint8_t state_transition[256]; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index a1f7206871..66d9f63c1a 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -764,7 +764,7 @@ static int read_header(FFV1Context *f) ff_dlog(f->avctx, "%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt); if (f->version < 2) { - context_count = read_quant_tables(c, f->quant_table); + context_count = read_quant_tables(c, f->quant_tables[0]); if (context_count < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return AVERROR_INVALIDDATA; @@ -834,7 +834,7 @@ static int read_header(FFV1Context *f) sizeof(p->quant_table)); context_count = f->context_count[idx]; } else { - memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table)); + memcpy(p->quant_table, f->quant_tables[0], sizeof(p->quant_table)); } if (f->version <= 2) { @@ -1067,7 +1067,11 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) fdst->use32bit = fsrc->use32bit; memcpy(fdst->state_transition, fsrc->state_transition, sizeof(fdst->state_transition)); - memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table)); + + // in version 1 there is a single per-keyframe quant table, so + // we need to propagate it between threads + if (fsrc->version < 2) + memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], sizeof(fsrc->quant_tables[0])); for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { FFV1Context *fssrc = fsrc->slice_context[i]; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 5692bfa1fc..1d00a46cdd 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -367,7 +367,7 @@ static void write_header(FFV1Context *f) put_symbol(c, state, f->chroma_v_shift, 0); put_rac(c, state, f->transparency); - write_quant_tables(c, f->quant_table); + write_quant_tables(c, f->quant_tables[f->context_model]); } else if (f->version < 3) { put_symbol(c, state, f->slice_count, 0); for (i = 0; i < f->slice_count; i++) { @@ -735,15 +735,13 @@ static av_cold int encode_init(AVCodecContext *avctx) } s->context_count[0] = (11 * 11 * 11 + 1) / 2; s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2; - memcpy(s->quant_table, s->quant_tables[s->context_model], - sizeof(s->quant_table)); for (i = 0; i < s->plane_count; i++) { PlaneContext *const p = &s->plane[i]; - memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table)); p->quant_table_index = s->context_model; p->context_count = s->context_count[p->quant_table_index]; + memcpy(p->quant_table, s->quant_tables[p->quant_table_index], sizeof(p->quant_table)); } if ((ret = ff_ffv1_allocate_initial_states(s)) < 0) From patchwork Tue Jul 16 17:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50572 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp436955vqb; Tue, 16 Jul 2024 10:17:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXbA8m0wbN5Ev/3bPxJZXDfZlXwtbUW0Nb/i/UzzC8IVB2QXogBDpIGpQddgWHpfM4ULLOhkcKmiGygOP0EZt4DHTTP7+fu5k+pGg== X-Google-Smtp-Source: AGHT+IFeHZwbsgnA7JpEhYvqm2EoGxuUircfSswXEbz5pxhHrEQTB9sVu5Z8NcLPacJfHEep/kNy X-Received: by 2002:a05:6512:b11:b0:52c:ce28:82c8 with SMTP id 2adb3069b0e04-52edf02b7ffmr1998298e87.52.1721150266023; Tue, 16 Jul 2024 10:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150266; cv=none; d=google.com; s=arc-20160816; b=L8tPflAMggMhv7r2FkdaiHTVHkSQjOOCGIWBg3zhavwfMtfYlXSjo2jPbHYofsT/IP QNNSNww3IoqpgX5bTpKDP5/IJCoZJSSJmQCCmf3BMmZS2stYjiMZweuzkyhe2SGYzkAY QcsAhj71hsnTuYlQWRrymxtGMSpug1ozGx4uRdIptwVkTtsG5uuYDRKNW4JoYIFbmtp8 7SuxOSS4F2xbriZlWaoJ9oWnpe9+xf4QJ6Oj0yFTF/TsdKq125AESiYHTY+eEoUob19n RFVoSXAxAp7u+SxtkcFvJ/4e1Tcv4s/2cgHNdSIONJrgyd+K3JHCcCilFuR038bHftD1 Jk0Q== 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=ozQnhGW/OSqZywGdQFLHlSuR2TaYAiOCQQyEpYDNeSo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=DC7DdmaLkNKyIpje7evFgirGPnjYoPH/2mqfvMAPaxnmesbcA3a5rWBBZYJRESbjl0 Vv0lbebpr2qlqGoP5coJvh7QhnXKsHyrtAkgI2tEDW5Jk7YLMeG9MKTwC+xGsaQpE9tP fs2Z58tydtZ4BX5DvYvAse2OuUqhoKLs9yCzFdMotxstl0NVeI0waRVdDC2rql2692A9 qe1VVdjuClg2PXQZKs+apfKB/1MOJnX3ToC6DKspk14GNSpA8RlfsurAXEGKNMf3cYSr ctJsnf7s9E2YN0YBlbm3gTsx/CC/rtNjdgE4edNmLf/tdUKI7eAlr/AyQo6yMUkvyK6l mW1A==; 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=dKChRQLu; 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-52ed255ad20si2275776e87.325.2024.07.16.10.17.45; Tue, 16 Jul 2024 10:17:46 -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=dKChRQLu; 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 B95E168DA77; Tue, 16 Jul 2024 20:16:45 +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 281DE68DA83 for ; Tue, 16 Jul 2024 20:16:37 +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=dKChRQLu; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id CC71B4DE7 for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id jfE_uTBuwbGA for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=qicKnzIUdszNBNVc+swj8z9JxpVR2/KWOgCdLqEIwj0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dKChRQLuh0991lbf5CNZNhQ1hQ/9z3117CfGGpuIg5m0bxb7upPsJaaf9JiY9b8B1 AHAKsczcZw3BU5y+a4eripvVuD7dvlHaPrNrPzRG8fv98G2mNCnRJic2rlbdSmZaHk hXCBHW61QjnMvPL/p0Ea/2Y7HYo19Aw1PNX4+g5NttVAzb37A2RBb6ujvp+RZftkIY T+YZWgWmu10rixUP1ZICvWDzdA79Qw85H74ZzWH4Ac3wwSA6q2dW2LqoyswEYwR/V0 KuFPUcRmnlRLo88HliLTG7eEo9dVhBsxa7e9hmtfizwJ7GSmReRFZmGVMZbmilpTYb n4BwRXW4k3lUg== 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 7EF024DF4 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BE3F53A2A08 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:28 +0200 Message-ID: <20240716171155.31838-13-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/39] lavc/ffv1: drop redundant PlaneContext.quant_table 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: 2gii+2rSOSys It is a copy of FFV1Context.quant_tables[quant_table_index]. --- libavcodec/ffv1.h | 1 - libavcodec/ffv1_template.c | 22 +++++++++++----------- libavcodec/ffv1dec.c | 28 ++++++++++++---------------- libavcodec/ffv1dec_template.c | 14 +++++++++----- libavcodec/ffv1enc.c | 24 ++++++++++++------------ libavcodec/ffv1enc_template.c | 13 ++++++++----- 6 files changed, 52 insertions(+), 50 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 4d57172d5b..a87c2d2a36 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -59,7 +59,6 @@ typedef struct VlcState { } VlcState; typedef struct PlaneContext { - int16_t quant_table[MAX_CONTEXT_INPUTS][256]; int quant_table_index; int context_count; uint8_t (*state)[CONTEXT_SIZE]; diff --git a/libavcodec/ffv1_template.c b/libavcodec/ffv1_template.c index c5f61b0182..d15ad11021 100644 --- a/libavcodec/ffv1_template.c +++ b/libavcodec/ffv1_template.c @@ -29,25 +29,25 @@ static inline int RENAME(predict)(TYPE *src, TYPE *last) return mid_pred(L, L + T - LT, T); } -static inline int RENAME(get_context)(PlaneContext *p, TYPE *src, - TYPE *last, TYPE *last2) +static inline int RENAME(get_context)(const int16_t quant_table[MAX_CONTEXT_INPUTS][256], + TYPE *src, TYPE *last, TYPE *last2) { const int LT = last[-1]; const int T = last[0]; const int RT = last[1]; const int L = src[-1]; - if (p->quant_table[3][127] || p->quant_table[4][127]) { + if (quant_table[3][127] || quant_table[4][127]) { const int TT = last2[0]; const int LL = src[-2]; - return p->quant_table[0][(L - LT) & 0xFF] + - p->quant_table[1][(LT - T) & 0xFF] + - p->quant_table[2][(T - RT) & 0xFF] + - p->quant_table[3][(LL - L) & 0xFF] + - p->quant_table[4][(TT - T) & 0xFF]; + return quant_table[0][(L - LT) & 0xFF] + + quant_table[1][(LT - T) & 0xFF] + + quant_table[2][(T - RT) & 0xFF] + + quant_table[3][(LL - L) & 0xFF] + + quant_table[4][(TT - T) & 0xFF]; } else - return p->quant_table[0][(L - LT) & 0xFF] + - p->quant_table[1][(LT - T) & 0xFF] + - p->quant_table[2][(T - RT) & 0xFF]; + return quant_table[0][(L - LT) & 0xFF] + + quant_table[1][(LT - T) & 0xFF] + + quant_table[2][(T - RT) & 0xFF]; } diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 66d9f63c1a..618020d10f 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -117,7 +117,8 @@ static int is_input_end(FFV1Context *s, GetBitContext *gb) #define RENAME(name) name ## 32 #include "ffv1dec_template.c" -static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, +static int decode_plane(FFV1Context *f, + FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) @@ -141,13 +142,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, sample[0][w] = sample[0][w - 1]; if (s->avctx->bits_per_raw_sample <= 8) { - int ret = decode_line(s, sc, gb, w, sample, plane_index, 8); + int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8); if (ret < 0) return ret; for (x = 0; x < w; x++) src[x*pixel_stride + stride * y] = sample[1][x]; } else { - int ret = decode_line(s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample); + int ret = decode_line(f, s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample); if (ret < 0) return ret; if (s->packed_at_lsb) { @@ -207,7 +208,6 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, return -1; } p->quant_table_index = idx; - memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table)); context_count = f->context_count[idx]; if (p->context_count < context_count) { @@ -335,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg) const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift); const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - decode_plane(fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - decode_plane(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + decode_plane(f, fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + decode_plane(f, fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (fs->transparency) - decode_plane(fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); + decode_plane(f, fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); } else if (f->colorspace == 0) { - decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); - decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); + decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); + decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame32(fs, sc, &gb, planes, width, height, p->linesize); + decode_rgb_frame32(f, fs, sc, &gb, planes, width, height, p->linesize); } else { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame(fs, sc, &gb, planes, width, height, p->linesize); + decode_rgb_frame(f, fs, sc, &gb, planes, width, height, p->linesize); } if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { int v; @@ -830,11 +830,7 @@ static int read_header(FFV1Context *f) return AVERROR_INVALIDDATA; } p->quant_table_index = idx; - memcpy(p->quant_table, f->quant_tables[idx], - sizeof(p->quant_table)); context_count = f->context_count[idx]; - } else { - memcpy(p->quant_table, f->quant_tables[0], sizeof(p->quant_table)); } if (f->version <= 2) { diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index e9d3002be9..97a28b085a 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -23,7 +23,9 @@ #include "ffv1_template.c" static av_always_inline int -RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, +RENAME(decode_line)(FFV1Context *f, + FFV1Context *s, FFV1SliceContext *sc, + GetBitContext *gb, int w, TYPE *sample[2], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; @@ -57,7 +59,8 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, return AVERROR_INVALIDDATA; } - context = RENAME(get_context)(p, sample[1] + x, sample[0] + x, sample[1] + x); + context = RENAME(get_context)(f->quant_tables[p->quant_table_index], + sample[1] + x, sample[0] + x, sample[1] + x); if (context < 0) { context = -context; sign = 1; @@ -127,7 +130,8 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, return 0; } -static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, +static int RENAME(decode_rgb_frame)(FFV1Context *f, + FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src[4], int w, int h, int stride[4]) { @@ -158,9 +162,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; if (lbd && s->slice_coding_mode == 0) - ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, 9); + ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, 9); else - ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); if (ret < 0) return ret; } diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 1d00a46cdd..714e007659 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -269,7 +269,8 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, #define RENAME(name) name ## 32 #include "ffv1enc_template.c" -static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, +static int encode_plane(FFV1Context *f, + FFV1Context *s, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { @@ -289,7 +290,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, if (s->bits_per_raw_sample <= 8) { for (x = 0; x < w; x++) sample[0][x] = src[x * pixel_stride + stride * y]; - if((ret = encode_line(s, sc, w, sample, plane_index, 8)) < 0) + if((ret = encode_line(f, s, sc, w, sample, plane_index, 8)) < 0) return ret; } else { if (s->packed_at_lsb) { @@ -301,7 +302,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext *sc, sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample); } } - if((ret = encode_line(s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0) + if((ret = encode_line(f, s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0) return ret; } } @@ -741,7 +742,6 @@ static av_cold int encode_init(AVCodecContext *avctx) p->quant_table_index = s->context_model; p->context_count = s->context_count[p->quant_table_index]; - memcpy(p->quant_table, s->quant_tables[p->quant_table_index], sizeof(p->quant_table)); } if ((ret = ff_ffv1_allocate_initial_states(s)) < 0) @@ -1066,21 +1066,21 @@ retry: const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - ret = encode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - ret |= encode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - ret |= encode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + ret |= encode_plane(f, fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + ret |= encode_plane(f, fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (fs->transparency) - ret |= encode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); + ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); } else if (c->pix_fmt == AV_PIX_FMT_YA8) { - ret = encode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); - ret |= encode_plane(fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); + ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); + ret |= encode_plane(f, fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { - ret = encode_rgb_frame32(fs, sc, planes, width, height, p->linesize); + ret = encode_rgb_frame32(f, fs, sc, planes, width, height, p->linesize); } else { - ret = encode_rgb_frame(fs, sc, planes, width, height, p->linesize); + ret = encode_rgb_frame(f, fs, sc, planes, width, height, p->linesize); } if (ret < 0) { diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 8b9e53fa1b..4a5580e1a5 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -23,7 +23,8 @@ #include "ffv1_template.c" static av_always_inline int -RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, +RENAME(encode_line)(FFV1Context *f, + FFV1Context *s, FFV1SliceContext *sc, int w, TYPE *sample[3], int plane_index, int bits) { PlaneContext *const p = &s->plane[plane_index]; @@ -60,7 +61,8 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, for (x = 0; x < w; x++) { int diff, context; - context = RENAME(get_context)(p, sample[0] + x, sample[1] + x, sample[2] + x); + context = RENAME(get_context)(f->quant_tables[p->quant_table_index], + sample[0] + x, sample[1] + x, sample[2] + x); diff = sample[0][x] - RENAME(predict)(sample[0] + x, sample[1] + x); if (context < 0) { @@ -124,7 +126,8 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc, return 0; } -static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, +static int RENAME(encode_rgb_frame)(FFV1Context *f, + FFV1Context *s, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4]) { @@ -193,9 +196,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, sample[p][0][-1] = sample[p][1][0 ]; sample[p][1][ w] = sample[p][1][w-1]; if (lbd && s->slice_coding_mode == 0) - ret = RENAME(encode_line)(s, sc, w, sample[p], (p + 1) / 2, 9); + ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9); else - ret = RENAME(encode_line)(s, sc, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1)); if (ret < 0) return ret; } From patchwork Tue Jul 16 17:11:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50573 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp441951vqb; Tue, 16 Jul 2024 10:26:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUznrb+T0qyXmIkOCkCALvUHn3lGBA3jjOovGjAqLtPY7EceBAEl8CzZG9Pxqfu09Hla7rVWKoIzeJPFOLb4k4pbulq0QN5/3j9mg== X-Google-Smtp-Source: AGHT+IG4kr7piy2L/86j3lqgXqH1X7dgu0/S7D3yFysCVq4wjKhOBR3Grb2sCY4qV5T+nHSb2QJ4 X-Received: by 2002:a05:651c:19aa:b0:2eb:f31e:9e7b with SMTP id 38308e7fff4ca-2eef416878emr24343051fa.14.1721150812008; Tue, 16 Jul 2024 10:26:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150811; cv=none; d=google.com; s=arc-20160816; b=L/mVhEGHYNBkaOBdTTwU0ojVdUSXqQ62M6rRFjcgEtgKXmR4fVJ5o69XYb+/7s4hvD NZDoXug6o/m0q9vBWPo85VEjijEAWXhyqVUwSgsXh9A84QlfsFUTyAos27UVxIFFRMcE 6cQeGsyovwygfAhBX1ezv57OX6Zpy8gQoB88dP90GFK6hThS9KvpdUDHFPhx3yWVM/ln ReiAw7dUgivdZ3M/FiXyJzka/zTg0o1onjY1vAgkHKLTo8ilP7qTbclaWq3IZiU8Fq6u jNebSVnhOSEEh01C9YROnhn1a7ikQuOM4iNro4GzMZYmqZ/8tS5p5RvoOMimNsCEbqKi dDzw== 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=QRitaXWlrwlA4/webND304Y4MXYcqb6mU4HjGq2Axqg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=m/pOg1vn/5ef2bcH4+Bba7gBvcGTxJXSbmwUGZKNDhuBHzatAos42nWQ9CDfX5X91H jzNuMVuU4NVP1dWUCqdLFBUmkEyvsuEipKD1V93SmF7Ejj/PuQnZrxnWZjMX3mW81GNW uokFBDMi0WglSe6ztyErNbZ7ngg3g6FowthwWPwdWSBfr0KuYO+zV8xWT8PGyK4/mxNb lmgYrha+zq+T67vEPdsNflNEHdNlZOOIs3F3++TO7ALaDVjH8xGKHtFpYSEJkjGRk7wV ePtIrFkkNNMrhhTl1LHcWzwVOHulXbRHWjG+xtydmu3XmGpOkAMueicyrVYC64tOhHRl Dpuw==; 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="km7LIG/r"; 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 4fb4d7f45d1cf-59b24a6c983si3898683a12.108.2024.07.16.10.26.51; Tue, 16 Jul 2024 10:26:51 -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="km7LIG/r"; 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 3A16868DA9F; Tue, 16 Jul 2024 20:16:42 +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 274BF68DA80 for ; Tue, 16 Jul 2024 20:16:37 +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=km7LIG/r; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 244FB4DE2 for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id GxCG1aHfup1f for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=bbGj9MDimxm29uCrf2lZyLa1otpwr8OJnCXRRmmNk4Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=km7LIG/rTlT+LFZ57inYsIidPa1dT3M5j4LZ9cFfh8ZZ9hPze5e06kQA/Ow6mvim6 LlxNH1WkgPrWmRvW2Xn4x0E3LQQRJKqs/IVCaCz8K+wKKHhfGUoHhGhxFvf7Y6eAKd Y9jjXwRvrriparoHsBtXvDsXN4oYQ61Vv19ekktGrh6puR+I4EN19rSYnQgcUUCmKB cz19IGjIb4Ukzb+83r2eomHKbnq3v24B7HmBF34rC5BFtP5rumi42zE3Yhgs1BrcyS 2m/MkWLkE2HaJEQPErf4romJG4hm87BFK8oQwEwquRATFCbfiR3eYk9sO7k6ttSyGv Gb1DkLSskjlcQ== 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 9030E4DF5 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C99A63A2AF6 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:29 +0200 Message-ID: <20240716171155.31838-14-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/39] lavc/ffv1: drop write-only PlaneContext.interlace_bit_state 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: it6xeNZYL5vL --- libavcodec/ffv1.c | 3 --- libavcodec/ffv1.h | 1 - 2 files changed, 4 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index a102425596..6a0aca6429 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -169,9 +169,6 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs) for (i = 0; i < f->plane_count; i++) { PlaneContext *p = &fs->plane[i]; - p->interlace_bit_state[0] = 128; - p->interlace_bit_state[1] = 128; - if (fs->ac != AC_GOLOMB_RICE) { if (f->initial_states[p->quant_table_index]) { memcpy(p->state, f->initial_states[p->quant_table_index], diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index a87c2d2a36..a3f3b30b49 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -63,7 +63,6 @@ typedef struct PlaneContext { int context_count; uint8_t (*state)[CONTEXT_SIZE]; VlcState *vlc_state; - uint8_t interlace_bit_state[2]; } PlaneContext; #define MAX_SLICES 1024 From patchwork Tue Jul 16 17:11:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50576 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp442047vqb; Tue, 16 Jul 2024 10:27:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV7X75MpfZIz4K0zhVevIX2UfUNDkHwgQuCzAQbRm4qqnmvpSuUn4csARDmSqMRW5CAtq7/YlXYvmM7NreV2nXKzxH1B8gvfsgLuw== X-Google-Smtp-Source: AGHT+IHhzNA+hABn6jI8dcFQ5NoxSaFl4xgsN1ixceboVRvKIk8eFFdTCk1p71ov2HwAjiVTfLdp X-Received: by 2002:a2e:9bc9:0:b0:2ec:1f9f:a876 with SMTP id 38308e7fff4ca-2eef415febemr19067431fa.6.1721150821611; Tue, 16 Jul 2024 10:27:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150821; cv=none; d=google.com; s=arc-20160816; b=xP7C726K+XpAFY137H/BCMjXfPzPNykVo7mmpI21kCTbLJlCZhscgExDTh2rIQdbjd 0aqXKlxNkMmSrt1MZ0ii5/kWkG42KV5F+Hs7PTacdd0g9k3MbEK1G6I3IG7Zk6y9anY9 R1rj6Bd2/qneTkNUx002ifIEbwV/7aqUz8OXSoteztchl15fli3T+/GKo16RBZNMetIX qpfsYpkTkZjRFZWBvFameff75oXdsxqYjtpBQ/zUl7MXbkgwwKDmrULL5EFMzLt0GQmy Yl6teA9MNBeXMjVUBiIM+7zvyOd+FUSpo3dsDmQbIZ5eL8u8i5tof4amxIkxJ8YoXBGW atwQ== 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=oZnmgGByCRadvJUr1rj9l9i+YtASih1Ho9oDuVYicew=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=fRudicEhpX1pTv33hyOwhNBLKsA1f8Qrs0IVLjC63Ed7HdoO/26kTp/1voFCTdK1kt aGrJt4JGtdBvN6qkmzMLw8cwoNmmPJy30icvFQxnogOryo1ZeL8lrGqgca5WDB8vQ8Mg pcW9RSVLGmFFhAHf+m89oLS0As2V0TOVI2I9SzYj/IXOTS4ZTKcoKXqYxd6COo2d0HY3 twLCXT88N5WsjJeQTTgit+EJciqsP1dlOEQZTLRRd0hAPfm8PD//qSqF+xdZNmwmfsQ9 7yae1seT5x5JVK/YhkgTJGr5cRZ81zk2kLRJsKGMJwNxDq9DVPsMv/DAz0ik/yZvHhoA n7mQ==; 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=qYeqsALA; 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 38308e7fff4ca-2eee191040dsi20060241fa.276.2024.07.16.10.27.01; Tue, 16 Jul 2024 10:27:01 -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=qYeqsALA; 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 C7C9668DAF5; Tue, 16 Jul 2024 20:16: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 49E3B68DA94 for ; Tue, 16 Jul 2024 20:16:37 +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=qYeqsALA; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 7DD664DF4 for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 6M1d5nLiYGiu for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=njpfhvXhJRcoBkER2BiSFbBL1FkurRsjekYRnivFTlY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qYeqsALAZTC0M3aEjZbOcT+Xe1ZVMs8m9PVJGbklBwiLMooNGrRvZ0n7pqgb6EN8s kPfNyFcXXPXcjN/lRnhcQtCVhq5EWxpctNpaVK5LcQ4sy4YOnpW+AOw/HzKgyEDLv9 e99/lRkKi/dMJuBJxqbAasQHuAPQr4p7kuS18UIzvZmgoxD61KeikbvpcovEFm7/M1 oYA2m1ReOv/UQziTrx89CLET83Jlr95+s6A+2i5pY01qTjmpyEPpdymayBiQkN8sjp OExBAK46an3WPbIdmjVo7Zhbyoaot7I2J9p6kP1ua5NHNbY2W1H9+6XfryG9XPfhXE GQl/mwMdy6iZw== 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 AE6E94DFC for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D59163A2B1D for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:30 +0200 Message-ID: <20240716171155.31838-15-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/39] lavc/ffv1: always use the main context values of plane_count/transparency 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: rsCI90GX58ne They cannot change between slices. --- libavcodec/ffv1.c | 2 -- libavcodec/ffv1dec.c | 5 ++--- libavcodec/ffv1dec_template.c | 2 +- libavcodec/ffv1enc.c | 2 +- libavcodec/ffv1enc_template.c | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 6a0aca6429..06a77c3a26 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -56,8 +56,6 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) { int j, i; - fs->plane_count = f->plane_count; - fs->transparency = f->transparency; for (j = 0; j < f->plane_count; j++) { PlaneContext *const p = &fs->plane[j]; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 618020d10f..6d3db25279 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -270,7 +270,6 @@ static int decode_slice(AVCodecContext *c, void *arg) if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) { FFV1Context *fssrc = f->fsrc->slice_context[si]; - av_assert1(fs->plane_count == fssrc->plane_count); if (!(p->flags & AV_FRAME_FLAG_KEY)) fs->slice_damaged |= fssrc->slice_damaged; @@ -330,7 +329,7 @@ static int decode_slice(AVCodecContext *c, void *arg) } av_assert1(width && height); - if (f->colorspace == 0 && (f->chroma_planes || !fs->transparency)) { + if (f->colorspace == 0 && (f->chroma_planes || !f->transparency)) { const int chroma_width = AV_CEIL_RSHIFT(width, f->chroma_h_shift); const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift); const int cx = x >> f->chroma_h_shift; @@ -341,7 +340,7 @@ static int decode_slice(AVCodecContext *c, void *arg) decode_plane(f, fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); decode_plane(f, fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } - if (fs->transparency) + if (f->transparency) decode_plane(f, fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); } else if (f->colorspace == 0) { decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 97a28b085a..d868617de9 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -140,7 +140,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, int lbd = s->avctx->bits_per_raw_sample <= 8; int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8; int offset = 1 << bits; - int transparency = s->transparency; + int transparency = f->transparency; for (x = 0; x < 4; x++) { sample[x][0] = RENAME(sc->sample_buffer) + x * 2 * (w + 6) + 3; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 714e007659..d334220e13 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1072,7 +1072,7 @@ retry: ret |= encode_plane(f, fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); ret |= encode_plane(f, fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } - if (fs->transparency) + if (f->transparency) ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); } else if (c->pix_fmt == AV_PIX_FMT_YA8) { ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 4a5580e1a5..0f47a0b424 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -138,7 +138,7 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, int packed = !src[1]; int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8; int offset = 1 << bits; - int transparency = s->transparency; + int transparency = f->transparency; int packed_size = (3 + transparency)*2; sc->run_index = 0; From patchwork Tue Jul 16 17:11:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50571 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp436862vqb; Tue, 16 Jul 2024 10:17:35 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU33QlFsRL5rv9lVXSiX86okQ6QRySTfhHjsn9tXhbhZ/huCoc7tAExE2OnJZ1j7/nJ+dmjVN6TUiNzbtHIULhQvdlcJjemut8AYQ== X-Google-Smtp-Source: AGHT+IE40p9SolT8x+udOJ3nvc9t8J8rqCxN+jzO4ER2A4ZsWHO+At1w02iwzcR5hoKNNPf/6zQ8 X-Received: by 2002:a05:6512:b24:b0:52b:8ef7:bf1f with SMTP id 2adb3069b0e04-52edef1ee77mr1653783e87.17.1721150255702; Tue, 16 Jul 2024 10:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150255; cv=none; d=google.com; s=arc-20160816; b=A3C9e+2cNm1Xg0dssyiZ6JfByjt+5/vrKQmYe6FWI30lHXO4qoNsCewxbkYMqBlKCe GutVkREnU/sPu6TVx8dEUhEStYvxl8K7GyDFc2GqgZvvTpSRRE1XZI0oCIls5TZwk3zE aVtdQtA2KXQLIaT1f2d/OZFx3yUR2RiWSuxVVlqjAe+UXzTiigAMYHWbwh+mUC4kppSC AIXpruoNSSxzuxLHZ6rzR9IQZqqY+xjrqnuHkXDogFP3ILenMkmRQ3KSIWicgf69dDO+ FyL5GJyAi92ZH+Yf0JXT5qdza9SD5NvMmnfRABULFtNdJ1XN0bVs4wNpxi0lHdxqDpbu tX1g== 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=dO8QDlFvFkUrzSv2/ipv+SFeQSSAdykOk3deaFZW1ik=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Hd/DkrOAfwVZgtDOvGll8wkNBi6I/8R5XeXrjbeVHvpjwGLf19yQS83dQMklTxhirv BO6O2Q9LJL13c+TRqFtUrgtVZD9vpZmCoWJEorcR3I1lXtZvlm0w58Byvn0+verfrENw z13telJG+rlydzFFRbctgiktVQouISiIlCZngFaMbYcO2WtBP8cHOhEaLmmgk/keIIkP NRwWKyAaIWnQtmpoLeryHNlU3GmIXivF4t3JvaH2nWbSA0XjAHmhGf1iLtt2J5wt5m1/ oz1gXPtGHfZ+M98iWgbE8qVCT5MyLg4fYhrEb+Bfkzs7is3ssrpfR4KuApqGejeH0Cdh gitw==; 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=Vlkk0k+N; 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-a79bc80563esi381489266b.787.2024.07.16.10.17.35; Tue, 16 Jul 2024 10:17:35 -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=Vlkk0k+N; 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 CF09C68D654; Tue, 16 Jul 2024 20:16:43 +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 2B94B68DA91 for ; Tue, 16 Jul 2024 20:16:37 +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=Vlkk0k+N; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 820454DF1 for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id xAxJHOv0570j for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=RX/mHqT8iPLiBxrwDB1kue1iRF34wxQYEj9yaQABkxc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Vlkk0k+N2WFeMaZD/3bMuFBxr80cr4DaUmZEXiQjvDTcZBLdA3avaj9ORjujPIPkh fRgf6vb7wXxC9eT75c8w4V8fxn7lBbIylNEfviZBxkRMoMHNZ2hXXQcKsTo49BMwZW ZzAGZEtNGmXxDAfa1fjY+HeHhZCVabUXLiyyIaQWwYvbAEl0cJLHI27U3RxFwE9NjD Jj2Ef757Hp42fWPGOZhF5mFSR3GpQuXqqkO00DajLIa/KkMCXx08P6cp2YPHOqeC1b JIX/PCu8nHwfK2dQbfcCdMhtT6aQ6Zn8yyK2jCuV8f06WXKESBAo+NvapNlICSj+Cr OzBGcJPdhS51Q== 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 91D474DF6 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E12313A2B52 for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:31 +0200 Message-ID: <20240716171155.31838-16-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/39] lavc/ffv1: move FFV1Context.slice_{coding_mode, rct_.y_coef} to per-slice context 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: uxS9vgOmMcAD --- libavcodec/ffv1.h | 6 +++--- libavcodec/ffv1dec.c | 14 +++++++------- libavcodec/ffv1dec_template.c | 10 +++++----- libavcodec/ffv1enc.c | 26 +++++++++++++------------- libavcodec/ffv1enc_template.c | 10 +++++----- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index a3f3b30b49..e466aedbbe 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -77,6 +77,9 @@ typedef struct FFV1SliceContext { int slice_y; int run_index; + int slice_coding_mode; + int slice_rct_by_coef; + int slice_rct_ry_coef; PutBitContext pb; } FFV1SliceContext; @@ -130,9 +133,6 @@ typedef struct FFV1Context { int num_v_slices; int num_h_slices; int slice_reset_contexts; - int slice_coding_mode; - int slice_rct_by_coef; - int slice_rct_ry_coef; FFV1SliceContext *slices; } FFV1Context; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 6d3db25279..8464697fd3 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -240,11 +240,11 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, if (fs->version > 3) { fs->slice_reset_contexts = get_rac(c, state); - fs->slice_coding_mode = get_symbol(c, state, 0); - if (fs->slice_coding_mode != 1) { - fs->slice_rct_by_coef = get_symbol(c, state, 0); - fs->slice_rct_ry_coef = get_symbol(c, state, 0); - if ((uint64_t)fs->slice_rct_by_coef + (uint64_t)fs->slice_rct_ry_coef > 4) { + sc->slice_coding_mode = get_symbol(c, state, 0); + if (sc->slice_coding_mode != 1) { + sc->slice_rct_by_coef = get_symbol(c, state, 0); + sc->slice_rct_ry_coef = get_symbol(c, state, 0); + if ((uint64_t)sc->slice_rct_by_coef + (uint64_t)sc->slice_rct_ry_coef > 4) { av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of range\n"); return AVERROR_INVALIDDATA; } @@ -294,8 +294,8 @@ static int decode_slice(AVCodecContext *c, void *arg) } } - fs->slice_rct_by_coef = 1; - fs->slice_rct_ry_coef = 1; + sc->slice_rct_by_coef = 1; + sc->slice_rct_ry_coef = 1; if (f->version > 2) { if (ff_ffv1_init_slice_state(f, fs) < 0) diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index d868617de9..776dc4144f 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -38,7 +38,7 @@ RENAME(decode_line)(FFV1Context *f, if (is_input_end(s, gb)) return AVERROR_INVALIDDATA; - if (s->slice_coding_mode == 1) { + if (sc->slice_coding_mode == 1) { int i; for (x = 0; x < w; x++) { int v = 0; @@ -161,10 +161,10 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; - if (lbd && s->slice_coding_mode == 0) + if (lbd && sc->slice_coding_mode == 0) ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, 9); else - ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (sc->slice_coding_mode != 1)); if (ret < 0) return ret; } @@ -174,10 +174,10 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, int r = sample[2][1][x]; int a = sample[3][1][x]; - if (s->slice_coding_mode != 1) { + if (sc->slice_coding_mode != 1) { b -= offset; r -= offset; - g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2; + g -= (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2; b += g; r += g; } diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index d334220e13..fb373b598b 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -926,13 +926,13 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs, put_symbol(c, state, f->cur_enc_frame->sample_aspect_ratio.num, 0); put_symbol(c, state, f->cur_enc_frame->sample_aspect_ratio.den, 0); if (f->version > 3) { - put_rac(c, state, fs->slice_coding_mode == 1); - if (fs->slice_coding_mode == 1) + put_rac(c, state, sc->slice_coding_mode == 1); + if (sc->slice_coding_mode == 1) ff_ffv1_clear_slice_state(f, fs); - put_symbol(c, state, fs->slice_coding_mode, 0); - if (fs->slice_coding_mode != 1) { - put_symbol(c, state, fs->slice_rct_by_coef, 0); - put_symbol(c, state, fs->slice_rct_ry_coef, 0); + put_symbol(c, state, sc->slice_coding_mode, 0); + if (sc->slice_coding_mode != 1) { + put_symbol(c, state, sc->slice_rct_by_coef, 0); + put_symbol(c, state, sc->slice_rct_ry_coef, 0); } } } @@ -1016,8 +1016,8 @@ static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, best = i; } - fs->slice_rct_by_coef = rct_y_coeff[best][1]; - fs->slice_rct_ry_coef = rct_y_coeff[best][0]; + sc->slice_rct_by_coef = rct_y_coeff[best][1]; + sc->slice_rct_ry_coef = rct_y_coeff[best][0]; } static int encode_slice(AVCodecContext *c, void *arg) @@ -1039,12 +1039,12 @@ static int encode_slice(AVCodecContext *c, void *arg) p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] : NULL, p->data[3] ? p->data[3] + ps*x + y*p->linesize[3] : NULL}; - fs->slice_coding_mode = 0; + sc->slice_coding_mode = 0; if (f->version > 3) { choose_rct_params(fs, sc, planes, p->linesize, width, height); } else { - fs->slice_rct_by_coef = 1; - fs->slice_rct_ry_coef = 1; + sc->slice_rct_by_coef = 1; + sc->slice_rct_ry_coef = 1; } retry: @@ -1084,13 +1084,13 @@ retry: } if (ret < 0) { - av_assert0(fs->slice_coding_mode == 0); + av_assert0(sc->slice_coding_mode == 0); if (fs->version < 4 || !fs->ac) { av_log(c, AV_LOG_ERROR, "Buffer too small\n"); return ret; } av_log(c, AV_LOG_DEBUG, "Coding slice as PCM\n"); - fs->slice_coding_mode = 1; + sc->slice_coding_mode = 1; fs->c = c_bak; goto retry; } diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 0f47a0b424..29b50637f4 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -46,7 +46,7 @@ RENAME(encode_line)(FFV1Context *f, } } - if (s->slice_coding_mode == 1) { + if (sc->slice_coding_mode == 1) { for (x = 0; x < w; x++) { int i; int v = sample[0][x]; @@ -178,10 +178,10 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, r = *((const uint16_t *)(src[2] + x*2 + stride[2]*y)); } - if (s->slice_coding_mode != 1) { + if (sc->slice_coding_mode != 1) { b -= g; r -= g; - g += (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 2; + g += (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) >> 2; b += offset; r += offset; } @@ -195,10 +195,10 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, int ret; sample[p][0][-1] = sample[p][1][0 ]; sample[p][1][ w] = sample[p][1][w-1]; - if (lbd && s->slice_coding_mode == 0) + if (lbd && sc->slice_coding_mode == 0) ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9); else - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (s->slice_coding_mode != 1)); + ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1)); if (ret < 0) return ret; } From patchwork Tue Jul 16 17:11:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50578 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp449941vqb; Tue, 16 Jul 2024 10:41:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUo2rgsqnwPXa7mFdVyzDcZTjszPCUNgb9LZmJlpzfPNmViO/TX/j0ZseNJpt4f6f+3cBMko0aQqkqul6bB/GgW5glpijZaNGLqgw== X-Google-Smtp-Source: AGHT+IHqsnWwMhr1KzDYNkWrXfD4Ev571Dj5obE7vQmbD1MPiyYsb+Nv9lDz6EkYr1xbLYoyBHS3 X-Received: by 2002:a2e:9d86:0:b0:2ee:4a67:3d82 with SMTP id 38308e7fff4ca-2eef4191defmr23763291fa.28.1721151710152; Tue, 16 Jul 2024 10:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721151710; cv=none; d=google.com; s=arc-20160816; b=xOK8/RhEhOA440sDNsydl8sTaBjOz/4q+3dx4GxN5rCNZvTee116hBXYaM5/K7QqTm 7dkASLoXGgvVsITnMfJEvS29xHNbRdf8v1DNEP2Be3QF/u8K6BdL5+2zJAAtx/15/mmy A4J14SDayRg34WxSMMHtONf5opcXkpI7nBjfBkXFoCyQ2CTKnwGD19o1y+NHj63btJrc 6rlLsQ9kmul26h8+QK0m/055/Gk5TomXROWnQKDKQivZ38l5CyReTRfQngRP9iz+H8DU +DvX3Rd7CrDyl1KDJ0gga6VVDyBRgEutEOFYQnO2Zq/2VRfm+OBrSmxkAhdrx4VwjojO WB0A== 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=jhV+llu2e9QwW3+gnCNLVA0z6jYC4422L8fj1qHLH/Y=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=AD2lOByTZB3MIifh3PhRI+0gqH9gpR2RYjP0v72sXLK8qOiO5RqVkpdbpL+/fUY4wr vM9IvUxnK1Y83reZ8PppHfl16y38lhPnvNnSHaOOjAwv9Zn2kZhppKsx8aTBou9Ogt6O 2khxB2lRVB/9Qvtq3CNhS30+wTmREC95vosIhL39IFYRLwzcJANprZ7lDhofWm9iVL+/ yr55chKcOn6Bo4719oUUt8OSAjzZsGFvi8RWTGiI72zfnu9zbTck+2mXZx4tqftW5QNA RI5WitlpczXXOsQseNvCCHOj3qlUapEwUsUCg7ONMK9lEkQnEnPg2IVPGnIhp1QcEexF j9pg==; 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=N2yp1KGB; 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 38308e7fff4ca-2eee1972269si19676341fa.621.2024.07.16.10.41.49; Tue, 16 Jul 2024 10:41: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=N2yp1KGB; 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 3C04268DAE1; Tue, 16 Jul 2024 20:16:47 +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 2791F68DA81 for ; Tue, 16 Jul 2024 20:16:37 +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=N2yp1KGB; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 06A374DE1 for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id xDKh33v9Q1uX for ; Tue, 16 Jul 2024 19:16:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150187; bh=1tsXoj3N2OFZstBLZxw+Qvz4TdpcQuylVzVGqBSXX3g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N2yp1KGBmODi+38pXKZbHaXxed0XsO+5+BmL12t5FaeCKBRD+pWrhLK/jmKS+ABP+ 2Tjyecxr4nsuhi1YsAuwZGTitq+FDAQ6rEDn371DhLEo+dkkexBtouTIYtyEksHWkF j22Z1NNNMMDwYGyyC4hmg5WfITe5iVTdC0exWkxe2GRPa+pYccsiOYo/7Qic+dfTrz tYiqFzaBgoH9JOiZ6PCv344pJQvO4ztBipcNNa1tKJVzPD0Fyy/pa5NrnO3kwyfOZg Ma3nH9HxW2efCG+0X4IKlErRbZK0JHC8V9TuBdwqx3MI9WCJF8EWLlzm5EyVzmfOl1 NbEu0ilSofdpA== 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 9231B4DF8 for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id ECD9C3A2B5B for ; Tue, 16 Jul 2024 19:16:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:32 +0200 Message-ID: <20240716171155.31838-17-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/39] lavc/ffv1: always use the main context values of ac 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: QyZunDDpNnOj It cannot change between slices. --- libavcodec/ffv1.c | 6 +++--- libavcodec/ffv1dec.c | 14 ++++++-------- libavcodec/ffv1dec_template.c | 6 +++--- libavcodec/ffv1enc.c | 6 +++--- libavcodec/ffv1enc_template.c | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 06a77c3a26..581e775ae2 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -59,7 +59,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) for (j = 0; j < f->plane_count; j++) { PlaneContext *const p = &fs->plane[j]; - if (fs->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { if (!p->state) p->state = av_malloc_array(p->context_count, CONTEXT_SIZE * sizeof(uint8_t)); @@ -78,7 +78,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) } } - if (fs->ac == AC_RANGE_CUSTOM_TAB) { + if (f->ac == AC_RANGE_CUSTOM_TAB) { //FIXME only redo if state_transition changed for (j = 1; j < 256; j++) { fs->c. one_state[ j] = f->state_transition[j]; @@ -167,7 +167,7 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs) for (i = 0; i < f->plane_count; i++) { PlaneContext *p = &fs->plane[i]; - if (fs->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { if (f->initial_states[p->quant_table_index]) { memcpy(p->state, f->initial_states[p->quant_table_index], CONTEXT_SIZE * p->context_count); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 8464697fd3..133baa895a 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -94,10 +94,9 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, return ret; } -static int is_input_end(FFV1Context *s, GetBitContext *gb) +static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac) { - if (s->ac != AC_GOLOMB_RICE) { - RangeCoder *const c = &s->c; + if (ac != AC_GOLOMB_RICE) { if (c->overread > MAX_OVERREAD) return AVERROR_INVALIDDATA; } else { @@ -197,7 +196,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height); - if (fs->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23)) + if (f->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23)) return AVERROR_INVALIDDATA; for (unsigned i = 0; i < f->plane_count; i++) { @@ -284,7 +283,7 @@ static int decode_slice(AVCodecContext *c, void *arg) pdst->state = NULL; pdst->vlc_state = NULL; - if (fssrc->ac) { + if (f->ac) { pdst->state = av_malloc_array(CONTEXT_SIZE, psrc->context_count); memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count); } else { @@ -319,7 +318,7 @@ static int decode_slice(AVCodecContext *c, void *arg) x = sc->slice_x; y = sc->slice_y; - if (fs->ac == AC_GOLOMB_RICE) { + if (f->ac == AC_GOLOMB_RICE) { if (f->version == 3 && f->micro_version > 1 || f->version > 3) get_rac(&fs->c, (uint8_t[]) { 129 }); fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0; @@ -358,7 +357,7 @@ static int decode_slice(AVCodecContext *c, void *arg) p->data[3] + ps * x + y * p->linesize[3] }; decode_rgb_frame(f, fs, sc, &gb, planes, width, height, p->linesize); } - if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { + if (f->ac != AC_GOLOMB_RICE && f->version > 2) { int v; get_rac(&fs->c, (uint8_t[]) { 129 }); v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec; @@ -791,7 +790,6 @@ static int read_header(FFV1Context *f) for (int j = 0; j < f->slice_count; j++) { FFV1Context *fs = f->slice_context[j]; FFV1SliceContext *sc = &f->slices[j]; - fs->ac = f->ac; fs->packed_at_lsb = f->packed_at_lsb; fs->slice_damaged = 0; diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 776dc4144f..30a13e0faf 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -35,7 +35,7 @@ RENAME(decode_line)(FFV1Context *f, int run_mode = 0; int run_index = sc->run_index; - if (is_input_end(s, gb)) + if (is_input_end(c, gb, f->ac)) return AVERROR_INVALIDDATA; if (sc->slice_coding_mode == 1) { @@ -55,7 +55,7 @@ RENAME(decode_line)(FFV1Context *f, int diff, context, sign; if (!(x & 1023)) { - if (is_input_end(s, gb)) + if (is_input_end(c, gb, f->ac)) return AVERROR_INVALIDDATA; } @@ -69,7 +69,7 @@ RENAME(decode_line)(FFV1Context *f, av_assert2(context < p->context_count); - if (s->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { diff = get_symbol_inline(c, p->state[context], 1); } else { if (context == 0 && run_mode == 0) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index fb373b598b..7fb5b997cc 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1053,7 +1053,7 @@ retry: if (f->version > 2) { encode_slice_header(f, fs, sc); } - if (fs->ac == AC_GOLOMB_RICE) { + if (f->ac == AC_GOLOMB_RICE) { fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; init_put_bits(&sc->pb, fs->c.bytestream_start + fs->ac_byte_count, @@ -1085,7 +1085,7 @@ retry: if (ret < 0) { av_assert0(sc->slice_coding_mode == 0); - if (fs->version < 4 || !fs->ac) { + if (fs->version < 4 || !f->ac) { av_log(c, AV_LOG_ERROR, "Buffer too small\n"); return ret; } @@ -1210,7 +1210,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, FFV1SliceContext *sc = &f->slices[i]; int bytes; - if (fs->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { bytes = ff_rac_terminate(&fs->c, 1); } else { flush_put_bits(&sc->pb); // FIXME: nicer padding diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 29b50637f4..970c185e93 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -34,7 +34,7 @@ RENAME(encode_line)(FFV1Context *f, int run_count = 0; int run_mode = 0; - if (s->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { if (c->bytestream_end - c->bytestream < w * 35) { av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; @@ -72,7 +72,7 @@ RENAME(encode_line)(FFV1Context *f, diff = fold(diff, bits); - if (s->ac != AC_GOLOMB_RICE) { + if (f->ac != AC_GOLOMB_RICE) { if (s->flags & AV_CODEC_FLAG_PASS1) { put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat, s->rc_stat2[p->quant_table_index][context]); From patchwork Tue Jul 16 17:11:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50597 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp472194vqb; Tue, 16 Jul 2024 11:26:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWtXbkNNTUi63YAS+kVxHGK5n+v9pJWq/2l2D3oYpzJkR7F0qaP9msZdiBeYgTitbYJjsCnX91oLDX6342aCrhME8zuB9uP1nPWQg== X-Google-Smtp-Source: AGHT+IGaQiyjonIaJG4dUcLoxqOLR0D1sffQ42Z9nL3IziBAYLlYBOYN7O1jtiEkRxpDpGVEDlMI X-Received: by 2002:a05:6512:1056:b0:52c:1d8a:9716 with SMTP id 2adb3069b0e04-52edef1e4bfmr2377905e87.19.1721154418006; Tue, 16 Jul 2024 11:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154417; cv=none; d=google.com; s=arc-20160816; b=lb+2jiIR0Oab+LjYseSo3lU7qgf4hxkXJD3ymg6S2HHISSHqo7k9WuVeTelvkNfawR fXPhTkllkmZcA28g49DHJCHCAMSSMXUp25GAkZUwUAemKw0WLsTfX+45h34Dmxsg9jyh tiwFVW7/e1BSyb0znkJ0AJxOdj4RaMjoxiMnEEzKXNaQ0m4Djubidwt/Q6BFFtxj90sW UuMhcwUeq6InLrE9mqJbVKjZk2+eKmQeBdW5VG8IkJHa/Nxf0oRTAQivKjsDnTKOnnoo xXuIeOmrqds0Rr7R+tvbwOfLMBvZR1nF/p6uXK12k38KyuwZh/8WqKBEDxrZk9gW/FPj 7v+A== 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=siBAm+wJI94umyAmaMExQ9o/3Ff368R2DTHj/hmWclo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=zZc2mwgh+143+kWGKaDWmATAcWFc3RKHa5CLokWaWjZ9Ed6QqlArAr152P0q+vq70b 5HT/q0Njvc/WeBF6ba6HDfsU3IDFN1G6bOQPUglWYZ+3FEEzHGGjDga/RRiKpYKZ+s/U eetflo3MW+FA+6JZ3DYt1w/YNOwCXoMN/7Fx1rft7rKUonATnZH+leKw1hHPMidGCeJD MPZiysALE7grJqxt2zAhWzBUW3k5Oe+YzqSWp2ZfjpDGw6B5dGa3S7i+Aw75WJUzxbmH xpUyz5bIqgo8IQOma5SAsL9XJpyuDTfwyrVIYKLRVo50eCg/AFQDXPAJd3unnYfsBLp0 nUGw==; 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=fcSBjlW1; 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-a79bc83394csi91882066b.1037.2024.07.16.11.26.57; Tue, 16 Jul 2024 11:26: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=@khirnov.net header.s=mail header.b=fcSBjlW1; 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 EEB0468DB76; Tue, 16 Jul 2024 21:14:28 +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 AEA7468D9FF for ; Tue, 16 Jul 2024 21:14:04 +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=fcSBjlW1; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E80314DF3 for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id SS-4Ml0ZxPkz for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=SyIZRgnvZGLzU5rdRMMnxeWpVPFw9LEZbZYWofLtiow=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fcSBjlW1Au80d4YJB9p0afq5iKRfUxoa0BqhyTcNRcSZ0cuu+w4uSdHcPYZjB3fL8 +j9+IFaXWWhUCc3VLDsRj3Evfr5VimI2RsjB8zsAVbbTgfsnIqnF9VOjPxWoP154EP jS8ds8MeJaAQBhdPocVCn4J18LgKhEsvjwShMbHMKaTA2BwcnWoPqqw8WarNFoYFhS IX/CePBBZSMbOqGk/VhkvIYJqVfYY8TR9yCOkvczIAM1G9/mp6hJ8BP2OFC9lgj3cm iE0QWe83fs6LLVlcZDCsxRKiUZ3S4aBAvecJTs9UPwWa0IGbQMWMRGldJiDnjRAB+k ei+hG6LgFvf4w== 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 9268D4DFA for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 047F93A2BD2 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:33 +0200 Message-ID: <20240716171155.31838-18-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/39] lavc/ffv1: move FFV1Context.plane to per-slice context 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: Vy7lsgl6c+S8 --- libavcodec/ffv1.c | 17 +++++++---------- libavcodec/ffv1.h | 7 ++++--- libavcodec/ffv1dec.c | 16 ++++++++-------- libavcodec/ffv1dec_template.c | 2 +- libavcodec/ffv1enc.c | 29 ++++++++++++++++------------- libavcodec/ffv1enc_template.c | 2 +- 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 581e775ae2..7bc4f1b135 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -52,12 +52,13 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx) return 0; } -av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs) +av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, + FFV1Context *fs, FFV1SliceContext *sc) { int j, i; for (j = 0; j < f->plane_count; j++) { - PlaneContext *const p = &fs->plane[j]; + PlaneContext *const p = &sc->plane[j]; if (f->ac != AC_GOLOMB_RICE) { if (!p->state) @@ -94,7 +95,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f) int i, ret; for (i = 0; i < f->max_slice_count; i++) { FFV1Context *fs = f->slice_context[i]; - if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0) + if ((ret = ff_ffv1_init_slice_state(f, fs, &f->slices[i])) < 0) return AVERROR(ENOMEM); } return 0; @@ -160,12 +161,12 @@ int ff_ffv1_allocate_initial_states(FFV1Context *f) return 0; } -void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs) +void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc) { int i, j; for (i = 0; i < f->plane_count; i++) { - PlaneContext *p = &fs->plane[i]; + PlaneContext *p = &sc->plane[i]; if (f->ac != AC_GOLOMB_RICE) { if (f->initial_states[p->quant_table_index]) { @@ -191,17 +192,13 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) int i, j; for (j = 0; j < s->max_slice_count; j++) { - FFV1Context *fs = s->slice_context[j]; FFV1SliceContext *sc = &s->slices[j]; av_freep(&sc->sample_buffer); av_freep(&sc->sample_buffer32); - if (!fs) - continue; - for (i = 0; i < s->plane_count; i++) { - PlaneContext *p = &fs->plane[i]; + PlaneContext *p = &sc->plane[i]; av_freep(&p->state); av_freep(&p->vlc_state); diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index e466aedbbe..68e59b300b 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -81,6 +81,7 @@ typedef struct FFV1SliceContext { int slice_rct_by_coef; int slice_rct_ry_coef; + PlaneContext plane[MAX_PLANES]; PutBitContext pb; } FFV1SliceContext; @@ -106,7 +107,6 @@ typedef struct FFV1Context { int plane_count; int ac; ///< 1=range coder <-> 0=golomb rice int ac_byte_count; ///< number of bytes used for AC coding - PlaneContext plane[MAX_PLANES]; int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256]; int context_count[MAX_QUANT_TABLES]; uint8_t state_transition[256]; @@ -138,11 +138,12 @@ typedef struct FFV1Context { } FFV1Context; int ff_ffv1_common_init(AVCodecContext *avctx); -int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs); +int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs, + FFV1SliceContext *sc); int ff_ffv1_init_slices_state(FFV1Context *f); int ff_ffv1_init_slice_contexts(FFV1Context *f); int ff_ffv1_allocate_initial_states(FFV1Context *f); -void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs); +void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc); int ff_ffv1_close(AVCodecContext *avctx); static av_always_inline int fold(int diff, int bits) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 133baa895a..4d20512643 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -200,7 +200,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, return AVERROR_INVALIDDATA; for (unsigned i = 0; i < f->plane_count; i++) { - PlaneContext * const p = &fs->plane[i]; + PlaneContext * const p = &sc->plane[i]; int idx = get_symbol(c, state, 0); if (idx >= (unsigned)f->quant_table_count) { av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n"); @@ -269,13 +269,14 @@ static int decode_slice(AVCodecContext *c, void *arg) if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) { FFV1Context *fssrc = f->fsrc->slice_context[si]; + const FFV1SliceContext *scsrc = &f->fsrc->slices[si]; if (!(p->flags & AV_FRAME_FLAG_KEY)) fs->slice_damaged |= fssrc->slice_damaged; for (int i = 0; i < f->plane_count; i++) { - PlaneContext *psrc = &fssrc->plane[i]; - PlaneContext *pdst = &fs->plane[i]; + const PlaneContext *psrc = &scsrc->plane[i]; + PlaneContext *pdst = &sc->plane[i]; av_free(pdst->state); av_free(pdst->vlc_state); @@ -297,7 +298,7 @@ static int decode_slice(AVCodecContext *c, void *arg) sc->slice_rct_ry_coef = 1; if (f->version > 2) { - if (ff_ffv1_init_slice_state(f, fs) < 0) + if (ff_ffv1_init_slice_state(f, fs, sc) < 0) return AVERROR(ENOMEM); if (decode_slice_header(f, fs, sc, p) < 0) { sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; @@ -305,10 +306,10 @@ static int decode_slice(AVCodecContext *c, void *arg) return AVERROR_INVALIDDATA; } } - if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0) + if ((ret = ff_ffv1_init_slice_state(f, fs, sc)) < 0) return ret; if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { - ff_ffv1_clear_slice_state(f, fs); + ff_ffv1_clear_slice_state(f, sc); } else if (fs->slice_damaged) { return AVERROR_INVALIDDATA; } @@ -817,7 +818,7 @@ static int read_header(FFV1Context *f) } for (int i = 0; i < f->plane_count; i++) { - PlaneContext *const p = &fs->plane[i]; + PlaneContext *const p = &sc->plane[i]; if (f->version == 2) { int idx = get_symbol(c, state, 0); @@ -1082,7 +1083,6 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) sc->slice_height = sc0->slice_height; } } - av_assert0(!fdst->plane[0].state); av_assert1(fdst->max_slice_count == fsrc->max_slice_count); diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 30a13e0faf..42198b5e0b 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -28,7 +28,7 @@ RENAME(decode_line)(FFV1Context *f, GetBitContext *gb, int w, TYPE *sample[2], int plane_index, int bits) { - PlaneContext *const p = &s->plane[plane_index]; + PlaneContext *const p = &sc->plane[plane_index]; RangeCoder *const c = &s->c; int x; int run_count = 0; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 7fb5b997cc..1c986927fe 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -384,8 +384,8 @@ static void write_header(FFV1Context *f) (fs->slice_height + 1) * f->num_v_slices / f->height - 1, 0); for (j = 0; j < f->plane_count; j++) { - put_symbol(c, state, f->plane[j].quant_table_index, 0); - av_assert0(f->plane[j].quant_table_index == f->context_model); + put_symbol(c, state, fs->plane[j].quant_table_index, 0); + av_assert0(fs->plane[j].quant_table_index == f->context_model); } } } @@ -737,13 +737,6 @@ static av_cold int encode_init(AVCodecContext *avctx) s->context_count[0] = (11 * 11 * 11 + 1) / 2; s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2; - for (i = 0; i < s->plane_count; i++) { - PlaneContext *const p = &s->plane[i]; - - p->quant_table_index = s->context_model; - p->context_count = s->context_count[p->quant_table_index]; - } - if ((ret = ff_ffv1_allocate_initial_states(s)) < 0) return ret; @@ -881,6 +874,16 @@ slices_ok: if ((ret = ff_ffv1_init_slice_contexts(s)) < 0) return ret; s->slice_count = s->max_slice_count; + + for (int j = 0; j < s->slice_count; j++) { + for (int i = 0; i < s->plane_count; i++) { + PlaneContext *const p = &s->slices[j].plane[i]; + + p->quant_table_index = s->context_model; + p->context_count = s->context_count[p->quant_table_index]; + } + } + if ((ret = ff_ffv1_init_slices_state(s)) < 0) return ret; @@ -916,8 +919,8 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs, put_symbol(c, state, (sc->slice_width +1)*f->num_h_slices / f->width -1, 0); put_symbol(c, state, (sc->slice_height+1)*f->num_v_slices / f->height-1, 0); for (j=0; jplane_count; j++) { - put_symbol(c, state, f->plane[j].quant_table_index, 0); - av_assert0(f->plane[j].quant_table_index == f->context_model); + put_symbol(c, state, sc->plane[j].quant_table_index, 0); + av_assert0(sc->plane[j].quant_table_index == f->context_model); } if (!(f->cur_enc_frame->flags & AV_FRAME_FLAG_INTERLACED)) put_symbol(c, state, 3, 0); @@ -928,7 +931,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs, if (f->version > 3) { put_rac(c, state, sc->slice_coding_mode == 1); if (sc->slice_coding_mode == 1) - ff_ffv1_clear_slice_state(f, fs); + ff_ffv1_clear_slice_state(f, sc); put_symbol(c, state, sc->slice_coding_mode, 0); if (sc->slice_coding_mode != 1) { put_symbol(c, state, sc->slice_rct_by_coef, 0); @@ -1049,7 +1052,7 @@ static int encode_slice(AVCodecContext *c, void *arg) retry: if (f->key_frame) - ff_ffv1_clear_slice_state(f, fs); + ff_ffv1_clear_slice_state(f, sc); if (f->version > 2) { encode_slice_header(f, fs, sc); } diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 970c185e93..2116c9aee7 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -27,7 +27,7 @@ RENAME(encode_line)(FFV1Context *f, FFV1Context *s, FFV1SliceContext *sc, int w, TYPE *sample[3], int plane_index, int bits) { - PlaneContext *const p = &s->plane[plane_index]; + PlaneContext *const p = &sc->plane[plane_index]; RangeCoder *const c = &s->c; int x; int run_index = sc->run_index; From patchwork Tue Jul 16 17:11:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50590 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp470116vqb; Tue, 16 Jul 2024 11:21:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUofr039O68RACV1JkykDUw2rdxk/ERaWOiJMlRmXEc9XGUyu9WGuZNGZjEiJuZPlXF49c5imuSl5wOPW/oWoAVUMm0h23cAxe4DA== X-Google-Smtp-Source: AGHT+IHD17aLCZ9n8MEPH4WIHfSHXKOPJ4aXsYux0qRKlGzy4s2k/K34HonKuhRK90f2lS7AxUg1 X-Received: by 2002:a17:906:374a:b0:a72:aeff:dfed with SMTP id a640c23a62f3a-a79eaa3049dmr200631766b.53.1721154108551; Tue, 16 Jul 2024 11:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154108; cv=none; d=google.com; s=arc-20160816; b=qNd1OwV0XcFnVZNTlt9lgM6ZKccTegm5EN+fEz4pWGD5mb40geJkfwaSYTTJ2k+jYa 5D90vUOdEX7/TID5t7rnJfYVhU4l2h32acCK45J43Zn2gjHC0LFFLRqrdorxLVHWqFpr QgpW5D6NOZJSdYtGoLLDFgAdxw6W9jldRYnvO+FLqwEt2XE4ElbUNJY1e+T09n3PW+vP hoVpiBpfjlG4lK6KvxtYPxlec+RXLuDeplRsus/c1Jomp7KjjBdqAafMRIj1Hhywp1iU Gn7CDxXLIRqewcYxwWwgvr6V5yUssQ1H93FIHzWtR2VkFBolJFyHSuL82GqubvgayNiV 2/8A== 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=8TqWLfP8ndGRW9uqIhpmmXZ8RxgF/SfadsL+XnbPIGg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=NVxTOaJyq9wKjDPvFz+fmOf1eTqhDAMRkCLWqQl7EdlNERMlYwyY4VKhAWNHiGOHOX j14AnsfF+gszmwXiQffXHIWUrZDktjVdQP8fvQb5N77W3rF3i/uirS+iIXJNCO1vjfZn GoNkjIr2K1YZ3HoyEyjeDn1+ioxp7UHZ51bWoRhphrNKqxuJA7/Pqb22vO0FpYkymuH7 wQOvf98j2Az3vBSuxQGOXBlIx28a2qNb6hcG3a3mdHRg5s21S7TtVcOldsLgXqh3fWq/ KvR1/txMWuD34ybSvHQLkHaQ0NQAyv7qgIye9j34cu8MN0Opbd8MACwSMfNRZVhzlmay 0rUQ==; 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=A60E2+QM; 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-a79bc7f5ff1si400448066b.504.2024.07.16.11.21.48; Tue, 16 Jul 2024 11:21:48 -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=A60E2+QM; 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 9040868DB42; Tue, 16 Jul 2024 21:14:24 +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 A084568DA65 for ; Tue, 16 Jul 2024 21:14:04 +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=A60E2+QM; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5B3FE4DFE for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id BxrXxmvdUlWu for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150189; bh=j3V03EcQf1WbafiCIz3KUUxpmn4nA56VErKq1/HfxJs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=A60E2+QMmQ6qNDNZYazYSF0bguq0NnhyondtqjQYcKHuTJXC960xmgCMW7mZuSt4c 3MKPs5kh1MOjOB9qErK+9QtkUuJv5vCI+CYHtpjIAaWOoISoUS6MdAAkp+7xU2sXvd me1PjGBwv+jmRPsoTKp93ruLzIrC8RF65C8uBswbIDjx9fZk5j/PqPPwkl9fXw913b ceJZkmD4E8kKruIlV/4bnp123Icv8dbUc7BaG1uaPztKqR82qzVj/eqQP0W3NRXSlD 9siwzdGgpaTkSSBFu5LbdORQnp643Wr7i6C/mdmWgANCDWxMd+PQWANa9YUGM7RPoq ZihpFke2ACjcQ== 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 6B8AA4E02 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1060B3A2CD0 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:34 +0200 Message-ID: <20240716171155.31838-19-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/39] lavc/ffv1: move RangeCoder to per-slice context 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: +FpDlcO+ufcG --- libavcodec/ffv1.c | 9 ++-- libavcodec/ffv1.h | 5 +-- libavcodec/ffv1dec.c | 72 ++++++++++++++++---------------- libavcodec/ffv1dec_template.c | 2 +- libavcodec/ffv1enc.c | 78 ++++++++++++++++++----------------- libavcodec/ffv1enc_template.c | 2 +- 6 files changed, 85 insertions(+), 83 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 7bc4f1b135..490baac233 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -53,7 +53,7 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx) } av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, - FFV1Context *fs, FFV1SliceContext *sc) + FFV1SliceContext *sc) { int j, i; @@ -82,8 +82,8 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, if (f->ac == AC_RANGE_CUSTOM_TAB) { //FIXME only redo if state_transition changed for (j = 1; j < 256; j++) { - fs->c. one_state[ j] = f->state_transition[j]; - fs->c.zero_state[256 - j] = 256 - fs->c.one_state[j]; + sc->c. one_state[ j] = f->state_transition[j]; + sc->c.zero_state[256 - j] = 256 - sc->c.one_state[j]; } } @@ -94,8 +94,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f) { int i, ret; for (i = 0; i < f->max_slice_count; i++) { - FFV1Context *fs = f->slice_context[i]; - if ((ret = ff_ffv1_init_slice_state(f, fs, &f->slices[i])) < 0) + if ((ret = ff_ffv1_init_slice_state(f, &f->slices[i])) < 0) return AVERROR(ENOMEM); } return 0; diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 68e59b300b..01c35dc942 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -83,12 +83,12 @@ typedef struct FFV1SliceContext { PlaneContext plane[MAX_PLANES]; PutBitContext pb; + RangeCoder c; } FFV1SliceContext; typedef struct FFV1Context { AVClass *class; AVCodecContext *avctx; - RangeCoder c; uint64_t rc_stat[256][2]; uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; int version; @@ -138,8 +138,7 @@ typedef struct FFV1Context { } FFV1Context; int ff_ffv1_common_init(AVCodecContext *avctx); -int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs, - FFV1SliceContext *sc); +int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc); int ff_ffv1_init_slices_state(FFV1Context *f); int ff_ffv1_init_slice_contexts(FFV1Context *f); int ff_ffv1_allocate_initial_states(FFV1Context *f); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 4d20512643..e0344c996b 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -167,7 +167,7 @@ static int decode_plane(FFV1Context *f, static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, FFV1SliceContext *sc, AVFrame *frame) { - RangeCoder *c = &fs->c; + RangeCoder *c = &sc->c; uint8_t state[CONTEXT_SIZE]; unsigned ps, context_count; int sx, sy, sw, sh; @@ -298,7 +298,7 @@ static int decode_slice(AVCodecContext *c, void *arg) sc->slice_rct_ry_coef = 1; if (f->version > 2) { - if (ff_ffv1_init_slice_state(f, fs, sc) < 0) + if (ff_ffv1_init_slice_state(f, sc) < 0) return AVERROR(ENOMEM); if (decode_slice_header(f, fs, sc, p) < 0) { sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; @@ -306,7 +306,7 @@ static int decode_slice(AVCodecContext *c, void *arg) return AVERROR_INVALIDDATA; } } - if ((ret = ff_ffv1_init_slice_state(f, fs, sc)) < 0) + if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0) return ret; if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { ff_ffv1_clear_slice_state(f, sc); @@ -321,11 +321,11 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->ac == AC_GOLOMB_RICE) { if (f->version == 3 && f->micro_version > 1 || f->version > 3) - get_rac(&fs->c, (uint8_t[]) { 129 }); - fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0; + get_rac(&sc->c, (uint8_t[]) { 129 }); + fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0; init_get_bits(&gb, - fs->c.bytestream_start + fs->ac_byte_count, - (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8); + sc->c.bytestream_start + fs->ac_byte_count, + (sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count) * 8); } av_assert1(width && height); @@ -360,8 +360,8 @@ static int decode_slice(AVCodecContext *c, void *arg) } if (f->ac != AC_GOLOMB_RICE && f->version > 2) { int v; - get_rac(&fs->c, (uint8_t[]) { 129 }); - v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec; + get_rac(&sc->c, (uint8_t[]) { 129 }); + v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec; if (v) { av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); fs->slice_damaged = 1; @@ -420,7 +420,7 @@ static int read_quant_tables(RangeCoder *c, static int read_extra_header(FFV1Context *f) { - RangeCoder *const c = &f->c; + RangeCoder c; uint8_t state[CONTEXT_SIZE]; int ret; uint8_t state2[32][CONTEXT_SIZE]; @@ -429,10 +429,10 @@ static int read_extra_header(FFV1Context *f) memset(state2, 128, sizeof(state2)); memset(state, 128, sizeof(state)); - ff_init_range_decoder(c, f->avctx->extradata, f->avctx->extradata_size); - ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); + ff_init_range_decoder(&c, f->avctx->extradata, f->avctx->extradata_size); + ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); - f->version = get_symbol(c, state, 0); + f->version = get_symbol(&c, state, 0); if (f->version < 2) { av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n"); return AVERROR_INVALIDDATA; @@ -443,27 +443,27 @@ static int read_extra_header(FFV1Context *f) return AVERROR_PATCHWELCOME; } if (f->version > 2) { - c->bytestream_end -= 4; - f->micro_version = get_symbol(c, state, 0); + c.bytestream_end -= 4; + f->micro_version = get_symbol(&c, state, 0); if (f->micro_version < 0) return AVERROR_INVALIDDATA; } - f->ac = get_symbol(c, state, 0); + f->ac = get_symbol(&c, state, 0); if (f->ac == AC_RANGE_CUSTOM_TAB) { for (int i = 1; i < 256; i++) - f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i]; + f->state_transition[i] = get_symbol(&c, state, 1) + c.one_state[i]; } - f->colorspace = get_symbol(c, state, 0); //YUV cs type - f->avctx->bits_per_raw_sample = get_symbol(c, state, 0); - f->chroma_planes = get_rac(c, state); - f->chroma_h_shift = get_symbol(c, state, 0); - f->chroma_v_shift = get_symbol(c, state, 0); - f->transparency = get_rac(c, state); + f->colorspace = get_symbol(&c, state, 0); //YUV cs type + f->avctx->bits_per_raw_sample = get_symbol(&c, state, 0); + f->chroma_planes = get_rac(&c, state); + f->chroma_h_shift = get_symbol(&c, state, 0); + f->chroma_v_shift = get_symbol(&c, state, 0); + f->transparency = get_rac(&c, state); f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency; - f->num_h_slices = 1 + get_symbol(c, state, 0); - f->num_v_slices = 1 + get_symbol(c, state, 0); + f->num_h_slices = 1 + get_symbol(&c, state, 0); + f->num_v_slices = 1 + get_symbol(&c, state, 0); if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) { av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", @@ -483,7 +483,7 @@ static int read_extra_header(FFV1Context *f) return AVERROR_PATCHWELCOME; } - f->quant_table_count = get_symbol(c, state, 0); + f->quant_table_count = get_symbol(&c, state, 0); if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) { av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count); f->quant_table_count = 0; @@ -491,7 +491,7 @@ static int read_extra_header(FFV1Context *f) } for (int i = 0; i < f->quant_table_count; i++) { - f->context_count[i] = read_quant_tables(c, f->quant_tables[i]); + f->context_count[i] = read_quant_tables(&c, f->quant_tables[i]); if (f->context_count[i] < 0) { av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return AVERROR_INVALIDDATA; @@ -501,19 +501,19 @@ static int read_extra_header(FFV1Context *f) return ret; for (int i = 0; i < f->quant_table_count; i++) - if (get_rac(c, state)) { + if (get_rac(&c, state)) { for (int j = 0; j < f->context_count[i]; j++) for (int k = 0; k < CONTEXT_SIZE; k++) { int pred = j ? f->initial_states[i][j - 1][k] : 128; f->initial_states[i][j][k] = - (pred + get_symbol(c, state2[k], 1)) & 0xFF; + (pred + get_symbol(&c, state2[k], 1)) & 0xFF; } } if (f->version > 2) { - f->ec = get_symbol(c, state, 0); + f->ec = get_symbol(&c, state, 0); if (f->micro_version > 2) - f->intra = get_symbol(c, state, 0); + f->intra = get_symbol(&c, state, 0); } if (f->version > 2) { @@ -549,7 +549,7 @@ static int read_header(FFV1Context *f) { uint8_t state[CONTEXT_SIZE]; int context_count = -1; //-1 to avoid warning - RangeCoder *const c = &f->slice_context[0]->c; + RangeCoder *const c = &f->slices[0].c; memset(state, 128, sizeof(state)); @@ -867,7 +867,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, uint8_t *buf = avpkt->data; int buf_size = avpkt->size; FFV1Context *f = avctx->priv_data; - RangeCoder *const c = &f->slice_context[0]->c; + RangeCoder *const c = &f->slices[0].c; int ret, key_frame; uint8_t keystate = 128; uint8_t *buf_p; @@ -938,6 +938,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, buf_p = buf + buf_size; for (int i = f->slice_count - 1; i >= 0; i--) { FFV1Context *fs = f->slice_context[i]; + FFV1SliceContext *sc = &f->slices[i]; int trailer = 3 + 5*!!f->ec; int v; @@ -972,9 +973,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, } if (i) { - ff_init_range_decoder(&fs->c, buf_p, v); + ff_init_range_decoder(&sc->c, buf_p, v); + ff_build_rac_states(&sc->c, 0.05 * (1LL << 32), 256 - 8); } else - fs->c.bytestream_end = buf_p + v; + sc->c.bytestream_end = buf_p + v; fs->avctx = avctx; } diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 42198b5e0b..4bb15801c1 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -29,7 +29,7 @@ RENAME(decode_line)(FFV1Context *f, int w, TYPE *sample[2], int plane_index, int bits) { PlaneContext *const p = &sc->plane[plane_index]; - RangeCoder *const c = &s->c; + RangeCoder *const c = &sc->c; int x; int run_count = 0; int run_mode = 0; diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 1c986927fe..d615d3da87 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -348,7 +348,7 @@ static void write_header(FFV1Context *f) { uint8_t state[CONTEXT_SIZE]; int i, j; - RangeCoder *const c = &f->slice_context[0]->c; + RangeCoder *const c = &f->slices[0].c; memset(state, 128, sizeof(state)); @@ -393,7 +393,7 @@ static void write_header(FFV1Context *f) static int write_extradata(FFV1Context *f) { - RangeCoder *const c = &f->c; + RangeCoder c; uint8_t state[CONTEXT_SIZE]; int i, j, k; uint8_t state2[32][CONTEXT_SIZE]; @@ -407,56 +407,56 @@ static int write_extradata(FFV1Context *f) f->avctx->extradata = av_malloc(f->avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!f->avctx->extradata) return AVERROR(ENOMEM); - ff_init_range_encoder(c, f->avctx->extradata, f->avctx->extradata_size); - ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); + ff_init_range_encoder(&c, f->avctx->extradata, f->avctx->extradata_size); + ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); - put_symbol(c, state, f->version, 0); + put_symbol(&c, state, f->version, 0); if (f->version > 2) { if (f->version == 3) { f->micro_version = 4; } else if (f->version == 4) f->micro_version = 2; - put_symbol(c, state, f->micro_version, 0); + put_symbol(&c, state, f->micro_version, 0); } - put_symbol(c, state, f->ac, 0); + put_symbol(&c, state, f->ac, 0); if (f->ac == AC_RANGE_CUSTOM_TAB) for (i = 1; i < 256; i++) - put_symbol(c, state, f->state_transition[i] - c->one_state[i], 1); + put_symbol(&c, state, f->state_transition[i] - c.one_state[i], 1); - put_symbol(c, state, f->colorspace, 0); // YUV cs type - put_symbol(c, state, f->bits_per_raw_sample, 0); - put_rac(c, state, f->chroma_planes); - put_symbol(c, state, f->chroma_h_shift, 0); - put_symbol(c, state, f->chroma_v_shift, 0); - put_rac(c, state, f->transparency); - put_symbol(c, state, f->num_h_slices - 1, 0); - put_symbol(c, state, f->num_v_slices - 1, 0); + put_symbol(&c, state, f->colorspace, 0); // YUV cs type + put_symbol(&c, state, f->bits_per_raw_sample, 0); + put_rac(&c, state, f->chroma_planes); + put_symbol(&c, state, f->chroma_h_shift, 0); + put_symbol(&c, state, f->chroma_v_shift, 0); + put_rac(&c, state, f->transparency); + put_symbol(&c, state, f->num_h_slices - 1, 0); + put_symbol(&c, state, f->num_v_slices - 1, 0); - put_symbol(c, state, f->quant_table_count, 0); + put_symbol(&c, state, f->quant_table_count, 0); for (i = 0; i < f->quant_table_count; i++) - write_quant_tables(c, f->quant_tables[i]); + write_quant_tables(&c, f->quant_tables[i]); for (i = 0; i < f->quant_table_count; i++) { if (contains_non_128(f->initial_states[i], f->context_count[i])) { - put_rac(c, state, 1); + put_rac(&c, state, 1); for (j = 0; j < f->context_count[i]; j++) for (k = 0; k < CONTEXT_SIZE; k++) { int pred = j ? f->initial_states[i][j - 1][k] : 128; - put_symbol(c, state2[k], + put_symbol(&c, state2[k], (int8_t)(f->initial_states[i][j][k] - pred), 1); } } else { - put_rac(c, state, 0); + put_rac(&c, state, 0); } } if (f->version > 2) { - put_symbol(c, state, f->ec, 0); - put_symbol(c, state, f->intra = (f->avctx->gop_size < 2), 0); + put_symbol(&c, state, f->ec, 0); + put_symbol(&c, state, f->intra = (f->avctx->gop_size < 2), 0); } - f->avctx->extradata_size = ff_rac_terminate(c, 0); + f->avctx->extradata_size = ff_rac_terminate(&c, 0); v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size); AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v); f->avctx->extradata_size += 4; @@ -882,6 +882,8 @@ slices_ok: p->quant_table_index = s->context_model; p->context_count = s->context_count[p->quant_table_index]; } + + ff_build_rac_states(&s->slices[j].c, 0.05 * (1LL << 32), 256 - 8); } if ((ret = ff_ffv1_init_slices_state(s)) < 0) @@ -909,7 +911,7 @@ slices_ok: static void encode_slice_header(FFV1Context *f, FFV1Context *fs, FFV1SliceContext *sc) { - RangeCoder *c = &fs->c; + RangeCoder *c = &sc->c; uint8_t state[CONTEXT_SIZE]; int j; memset(state, 128, sizeof(state)); @@ -1036,7 +1038,7 @@ static int encode_slice(AVCodecContext *c, void *arg) const AVFrame *const p = f->cur_enc_frame; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; int ret; - RangeCoder c_bak = fs->c; + RangeCoder c_bak = sc->c; const uint8_t *planes[4] = {p->data[0] + ps*x + y*p->linesize[0], p->data[1] ? p->data[1] + ps*x + y*p->linesize[1] : NULL, p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] : NULL, @@ -1057,10 +1059,10 @@ retry: encode_slice_header(f, fs, sc); } if (f->ac == AC_GOLOMB_RICE) { - fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; + fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0; init_put_bits(&sc->pb, - fs->c.bytestream_start + fs->ac_byte_count, - fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count); + sc->c.bytestream_start + fs->ac_byte_count, + sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count); } if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) { @@ -1094,7 +1096,7 @@ retry: } av_log(c, AV_LOG_DEBUG, "Coding slice as PCM\n"); sc->slice_coding_mode = 1; - fs->c = c_bak; + sc->c = c_bak; goto retry; } @@ -1105,7 +1107,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet) { FFV1Context *f = avctx->priv_data; - RangeCoder *const c = &f->slice_context[0]->c; + RangeCoder *const c = &f->slices[0].c; uint8_t keystate = 128; uint8_t *buf_p; int i, ret; @@ -1193,15 +1195,15 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, } for (i = 0; i < f->slice_count; i++) { - FFV1Context *fs = f->slice_context[i]; + FFV1SliceContext *sc = &f->slices[i]; uint8_t *start = pkt->data + pkt->size * (int64_t)i / f->slice_count; int len = pkt->size / f->slice_count; if (i) { - ff_init_range_encoder(&fs->c, start, len); + ff_init_range_encoder(&sc->c, start, len); } else { - av_assert0(fs->c.bytestream_end >= fs->c.bytestream_start + len); - av_assert0(fs->c.bytestream < fs->c.bytestream_start + len); - fs->c.bytestream_end = fs->c.bytestream_start + len; + av_assert0(sc->c.bytestream_end >= sc->c.bytestream_start + len); + av_assert0(sc->c.bytestream < sc->c.bytestream_start + len); + sc->c.bytestream_end = sc->c.bytestream_start + len; } } avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL, @@ -1214,14 +1216,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, int bytes; if (f->ac != AC_GOLOMB_RICE) { - bytes = ff_rac_terminate(&fs->c, 1); + bytes = ff_rac_terminate(&sc->c, 1); } else { flush_put_bits(&sc->pb); // FIXME: nicer padding bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); } if (i > 0 || f->version > 2) { av_assert0(bytes < pkt->size / f->slice_count); - memmove(buf_p, fs->c.bytestream_start, bytes); + memmove(buf_p, sc->c.bytestream_start, bytes); av_assert0(bytes < (1 << 24)); AV_WB24(buf_p + bytes, bytes); bytes += 3; diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index 2116c9aee7..c27a2e3a39 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -28,7 +28,7 @@ RENAME(encode_line)(FFV1Context *f, int w, TYPE *sample[3], int plane_index, int bits) { PlaneContext *const p = &sc->plane[plane_index]; - RangeCoder *const c = &s->c; + RangeCoder *const c = &sc->c; int x; int run_index = sc->run_index; int run_count = 0; From patchwork Tue Jul 16 17:11:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50574 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp441995vqb; Tue, 16 Jul 2024 10:26:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUJPViY4WuIHn0bQoKA9EAc2aX3CcyiI5NcHsmkNT8Im0oGI3WJLLOQTFsbKJ2kdgTetPVQEDnDLG7BYfQs9zP4vxMO2ab/73RvYA== X-Google-Smtp-Source: AGHT+IGZ+HNz7xMRfardZWdjDRDvDfnCkn3GXdYyOeWCmCuoTvQxMouK5eKi5cjRTDq8MkeG9Wg3 X-Received: by 2002:a50:99dc:0:b0:59e:f6b8:fb2a with SMTP id 4fb4d7f45d1cf-59f0bf267d6mr1830599a12.21.1721150816833; Tue, 16 Jul 2024 10:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721150816; cv=none; d=google.com; s=arc-20160816; b=O6Mlz3Q5Q6rg6GehAAtkElmpEK8fvCWj9NE+fKrl67tYuVgaHp/k7zVXr0IbEa2vhH 7Nh8yN2dnXSYPVyvQCuJ/PfoCiV/NwhD37Bp6iGWNsZPIAlwjvhfGc9jwq2HAXy1ZWLI E73Y86WNV7CKOHkCfWT+6UkBm0vSlr1LLki7QYFH8+y3ykLfgRRWlb2vd++nCf77dWPh goIi4IVfkyXXBjYw7GeKkSUjzmCZIbdDBAXnYr79h70lXqOmaQtHGJVPzrZimf55emlN x0+pyBsPhA4ycrj/byXVOaVTAFzHlRxfAFa1NF5PfSm7IPiLPY4tAYvKr/r8mwW5Mqvx zcOw== 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=EbXHtYARn8C1t3JXs2HZ61GiyfqSgAy4phtkaCU79c8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=Yjo2smVLnyj4XUvCCE24SdO3tWqc6NxIKJlCX1ittnlWMZiwIj0h/WUR9HhkzTuQ5F pam+y9b0ZbhjXY2A9MPMfbbSlcEGclwDjK2gpWzC2kqgU1jfmQJI7Yw9hDiWxj04aTcZ VJX9MQc/oeOECR9iKPEfzNTNA2ZDSRA/aoOnBLY7CtZeYKW4Qu11pKOyeCkrxCkt5bk3 8+eO4kMSo3qEufzbKfOHBmC/0entBYDk/jmdudZkHqNhbfufmXIruAbl9xxaXIkPlKg/ vpCrSBq6RYTPBFI6xEJGUtiaeet4/huMX+0356xoK3GzFmSrKz1soCg1fS8wFYcuO60a SUQw==; 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=rp5cHEX6; 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 4fb4d7f45d1cf-59b24a6c825si4149054a12.70.2024.07.16.10.26.55; Tue, 16 Jul 2024 10:26:56 -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=rp5cHEX6; 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 F284268DB14; Tue, 16 Jul 2024 20:16: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 50AE968DA9D for ; Tue, 16 Jul 2024 20:16:37 +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=rp5cHEX6; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5AC594DF8 for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id T-AxqgqkHtAK for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=FjCDxywa/rWdGdlSn05RjKsHMcc1zM5Ukx/npbCHbsA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=rp5cHEX6v8PAPOqawxqlyDxJMaIy8Wi3e83g18goFaiHeRu0h69O0FYS5mtcMN4PS K+PCeB4+rIkA4crnojciQ18v1Ab9VMUcpr372OOKrhNobT0+PmppI/38WW5LhaFeaF 2rjraqsb8jwJNbr/On4K2enAJjozDW9ljA3VOZeJ9UuFwms4a4C+h2iMI/rNMziwGd 5zoCGuXkyI3PgHeN2d5W5QgTowvJkwcRrThU/VP3ZGP8mmtqQUWQEQUfZkeMCmjCpZ b0j16sx8WzERQV2xDOElE6qWzljZyESA8hcnj8i8Fz8CnRt2z8endk7/9qm1BqMpdj /YesQOoKuch+Q== 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 925064E06 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 1BDA13A2CFD for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:35 +0200 Message-ID: <20240716171155.31838-20-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/39] lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext 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: bHSUwbHqTNuH Instead of the per-slice FFV1Context, which will be removed in future commits. --- libavcodec/ffv1.c | 6 ++---- libavcodec/ffv1.h | 3 +++ libavcodec/ffv1enc.c | 20 ++++++++++---------- libavcodec/ffv1enc_template.c | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 490baac233..4ef04f6b9b 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -127,7 +127,6 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) f->slice_context[i++] = fs; memcpy(fs, f, sizeof(*fs)); - memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2)); sc->slice_width = sxe - sxs; sc->slice_height = sye - sys; @@ -208,9 +207,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) for (j = 0; j < s->quant_table_count; j++) { av_freep(&s->initial_states[j]); for (i = 0; i < s->max_slice_count; i++) { - FFV1Context *sf = s->slice_context[i]; - if (sf) - av_freep(&sf->rc_stat2[j]); + FFV1SliceContext *sc = &s->slices[i]; + av_freep(&sc->rc_stat2[j]); } av_freep(&s->rc_stat2[j]); } diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 01c35dc942..bee7b75614 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -84,6 +84,9 @@ typedef struct FFV1SliceContext { PlaneContext plane[MAX_PLANES]; PutBitContext pb; RangeCoder c; + + uint64_t rc_stat[256][2]; + uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; } FFV1SliceContext; typedef struct FFV1Context { diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index d615d3da87..e3d094141c 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -896,11 +896,11 @@ slices_ok: return AVERROR(ENOMEM); for (i = 0; i < s->quant_table_count; i++) for (j = 0; j < s->max_slice_count; j++) { - FFV1Context *sf = s->slice_context[j]; - av_assert0(!sf->rc_stat2[i]); - sf->rc_stat2[i] = av_mallocz(s->context_count[i] * - sizeof(*sf->rc_stat2[i])); - if (!sf->rc_stat2[i]) + FFV1SliceContext *sc = &s->slices[j]; + av_assert0(!sc->rc_stat2[i]); + sc->rc_stat2[i] = av_mallocz(s->context_count[i] * + sizeof(*sc->rc_stat2[i])); + if (!sc->rc_stat2[i]) return AVERROR(ENOMEM); } } @@ -1126,16 +1126,16 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, av_assert0(f->slice_count == f->max_slice_count); for (j = 0; j < f->slice_count; j++) { - FFV1Context *fs = f->slice_context[j]; + const FFV1SliceContext *sc = &f->slices[j]; for (i = 0; i < 256; i++) { - f->rc_stat[i][0] += fs->rc_stat[i][0]; - f->rc_stat[i][1] += fs->rc_stat[i][1]; + f->rc_stat[i][0] += sc->rc_stat[i][0]; + f->rc_stat[i][1] += sc->rc_stat[i][1]; } for (i = 0; i < f->quant_table_count; i++) { for (k = 0; k < f->context_count[i]; k++) for (m = 0; m < 32; m++) { - f->rc_stat2[i][k][m][0] += fs->rc_stat2[i][k][m][0]; - f->rc_stat2[i][k][m][1] += fs->rc_stat2[i][k][m][1]; + f->rc_stat2[i][k][m][0] += sc->rc_stat2[i][k][m][0]; + f->rc_stat2[i][k][m][1] += sc->rc_stat2[i][k][m][1]; } } } diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index c27a2e3a39..c79146d619 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -74,8 +74,8 @@ RENAME(encode_line)(FFV1Context *f, if (f->ac != AC_GOLOMB_RICE) { if (s->flags & AV_CODEC_FLAG_PASS1) { - put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat, - s->rc_stat2[p->quant_table_index][context]); + put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat, + sc->rc_stat2[p->quant_table_index][context]); } else { put_symbol_inline(c, p->state[context], diff, 1, NULL, NULL); } From patchwork Tue Jul 16 17:11:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50581 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp466416vqb; Tue, 16 Jul 2024 11:14:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVsb4yazCEuo0YLjRepqR51h/Yf9mpZF4mCJd8utcVXiKLN7fCtslLhKrFB4WnX4REEKc6DGNZgJSrTbC+IWLSUJFCZ0zbNpk+3WQ== X-Google-Smtp-Source: AGHT+IE+BnX+SfbbMgxx6/R2yD8CaxzNlXjkvR7oYdGVvvFfxdJygmaRBz7XdeNC3l7i3ruYd8+/ X-Received: by 2002:a17:906:1c45:b0:a6f:49b1:dec5 with SMTP id a640c23a62f3a-a79eaa364e6mr190791566b.46.1721153650120; Tue, 16 Jul 2024 11:14:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153650; cv=none; d=google.com; s=arc-20160816; b=Irq7kz91dFwP29l//sn0n7IuP8gCJSGEzWVaWDrO33o+TNoSqG8iFHzs53dXc0XEOr PU1FfX4y2Geu3fAQw/EqrA19/lEtBuiwyVX74Spmj0B9tdHlv5ERfCtBQsLCk7EgivdV muTB1U5pvtfobkfe9jdzizxCFhmmJk25Djn4qOrYOBhrriWxvGJ+S1oaAR4noqxRLCEW fNKTj8e/PoTOtGp4mHmOIrZ4p+FxTv5cNuDsbTgeI1EGcp8DGrJUJuX2vHLxW1WZucio JpS+UZS3psumFuxhu1dbDYtwlTs6+a4M/2zvPzmVsCJbO4yDaB6vfrPKaUnXew61YoR3 wJgA== 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=ZQPg/RdtPUJ/ErJYZKhNWoqaEp7VFqdUYalFS3cQ+2w=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=X7FnZy/z1qUfxz78kd/yYC5uM6OpF8quWttYgi0j59rbQxTwfiVTaS8/maVcPi3ve+ rV9yZRzMJuFDGWdDdoV+izeLloL9HkVdI+zTHfL4VM8CGyeD9q1Gjk9zAWDTDYFf4BbQ 4l5Dz2Hf0vn5d7bJv7i5McHiIbmgbgsZyixLWEQrApuxMmX6S20MSosIgQe1ZjRoI5hQ qMUkBWKk2apLnxoVKz+Fcx6IGPo4r7CtvOrhdDMg1v5X9BYUTLi+FMdlGgHh8ORbwc52 Sqq2wOGJGDIZzE7nrMuBmt3RlsfILweV8GiW/4/djlyregKKTXpq7KWGesQSrr4Rv9np LNwA==; 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=cdo+3mmo; 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-a79bc7c272asi389453466b.416.2024.07.16.11.14.09; Tue, 16 Jul 2024 11:14:10 -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=cdo+3mmo; 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 5293C68DAC0; Tue, 16 Jul 2024 21:14:06 +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 04BD268D86A for ; Tue, 16 Jul 2024 21:13:59 +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=cdo+3mmo; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 8E1654E0B for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id lZ8tFsm7jK5J for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150189; bh=zDZ5ug9he1z5Xq2jAKo0iS/OJOmTFo5noTrhSEAt+ek=; h=From:To:Subject:Date:In-Reply-To:References:From; b=cdo+3mmoILe5P3JoPN4/fQUpgFV4DKN3ThUaz19WLjvc0AbI7+9y4gkX8+uLaCk9j 89rZkr8N/YXaLJQb/LuOT3Uw0ewGKwzCoSIy41My7n0zAqqsR8sn71n7utTgITeL5Q HZO0JTp1p9QCBnS3MlWH0zpPFPO5fVUNpMflHdht+JjSeUfuMu1+TZeI5ThEO9JzNp gotGPAW4eP2R2z9c4TiZ8TLyqpmSRVTkKwVhksam8LnAizCvIaVJg6WsEbqnfEb6eD 9nwrvL1uTrw5QY+Sw45ENgd6YfFMSksi7Yo1bZrmCB9EgoyHyL+ReOWIkVOqDwBESS C8qmIliIX6ocw== 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 B3A694DFE for ; Tue, 16 Jul 2024 19:16:27 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 274F53A2D03 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:36 +0200 Message-ID: <20240716171155.31838-21-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/39] lavc/ffv1: move ac_byte_count to per-slice context 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: QIeVM4DfTPgn --- libavcodec/ffv1.h | 2 +- libavcodec/ffv1dec.c | 6 +++--- libavcodec/ffv1enc.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index bee7b75614..ae81940073 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -85,6 +85,7 @@ typedef struct FFV1SliceContext { PutBitContext pb; RangeCoder c; + int ac_byte_count; ///< number of bytes used for AC coding uint64_t rc_stat[256][2]; uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; } FFV1SliceContext; @@ -109,7 +110,6 @@ typedef struct FFV1Context { const AVFrame *cur_enc_frame; int plane_count; int ac; ///< 1=range coder <-> 0=golomb rice - int ac_byte_count; ///< number of bytes used for AC coding int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256]; int context_count[MAX_QUANT_TABLES]; uint8_t state_transition[256]; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index e0344c996b..4dc1f4b1cf 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -322,10 +322,10 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->ac == AC_GOLOMB_RICE) { if (f->version == 3 && f->micro_version > 1 || f->version > 3) get_rac(&sc->c, (uint8_t[]) { 129 }); - fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0; + sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0; init_get_bits(&gb, - sc->c.bytestream_start + fs->ac_byte_count, - (sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count) * 8); + sc->c.bytestream_start + sc->ac_byte_count, + (sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count) * 8); } av_assert1(width && height); diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index e3d094141c..3a6a0e6d90 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -1059,10 +1059,10 @@ retry: encode_slice_header(f, fs, sc); } if (f->ac == AC_GOLOMB_RICE) { - fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0; + sc->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0; init_put_bits(&sc->pb, - sc->c.bytestream_start + fs->ac_byte_count, - sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count); + sc->c.bytestream_start + sc->ac_byte_count, + sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count); } if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) { From patchwork Tue Jul 16 17:11:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50600 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp475587vqb; Tue, 16 Jul 2024 11:34:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXnJ0I/HTjDhpeeYVHvJ0PqSCXTC/JdYrTi2o7p5b1QTaPq0O+855wbapHnhszm3f5CC0MBIo1aPxNzaZGzBxSnn77jQo1lz9C51g== X-Google-Smtp-Source: AGHT+IH1TfMApUMwHe4q4RakLhVTnOWWuEQwjqkcygJlofKa0P1yRceW/J5GpIks6ITn1uKMoFYs X-Received: by 2002:a2e:98c6:0:b0:2ec:1708:4db2 with SMTP id 38308e7fff4ca-2eef41ea61dmr19031571fa.47.1721154861799; Tue, 16 Jul 2024 11:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154861; cv=none; d=google.com; s=arc-20160816; b=w0zzWY1oLKrUEiXSuvEfRRduGQeMTUdYlTCfkAk96UW02ORDZPTWLQRS4Zki0IGZIK keT4yqzDS87n/0amWTrSwBhLx90u1hVxLhr+0VWaI715g2kZsYAhcwJu6jbr/H7zZVZJ nP3pDUzN+bscEvOhYiMpNaTMxn14gonLRSOuc7dMcv5sFeXgrhLYM3S4Ow1ZrRYUNLK4 cO19TTDp5LdLpwiE4mL0EqLN0NXeaFG6xC2sbAZUPkWVet/0O6aLC+teXu0p95bPCg+0 ofFRWIsZB/hcR4E0+UPXHUG5tvib8F0YpvBaryXeVMfdCYjnky1KARHDDDSpLTYKs1jq ZmKw== 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=IEdqtTasOfSjOAOpEDJljTFLCEepVJ31WhEyDUSH7zc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=njtetOddfT/51xBDX78QWlS+cRr4VnHaLMePO40LbjEOuwuNhjil1mOabxVJSwaX10 2auIjHwr+RwXHAfiOY5wMO8iM834be5SMlR1elaSOW7oxKsT2kQqTAZXbzq7tSrmlHOs hLVREvg0KsuES8591TeS+omO0CutW6pYbbX8LgHt44Tbt8ePSCP9NsusQ4p05B9PqHdO maonkzUeUeYVVDqhtRCXNO9krwEGg938fN3p2Euwd29KXFgOBz1qO3vkjLmDMe/LasAF yXLaKK5/2VyLtgzDicHkocZdiuVybKYhnhf1IgBAmd0UNGYj0YD+teX6sLvgpAgMHSlr O8lQ==; 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=WRaFoATX; 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 4fb4d7f45d1cf-59f8dafeff6si681443a12.647.2024.07.16.11.34.21; Tue, 16 Jul 2024 11:34:21 -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=WRaFoATX; 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 8C01968DB8D; Tue, 16 Jul 2024 21:34:11 +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 84B2A68DAD0 for ; Tue, 16 Jul 2024 21:33:59 +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=WRaFoATX; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 67F8A998 for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id apIfHEsWJUXW for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=13sCUGjR8+qncJEOf7ucR+c891l4HzQczWW3lmvr764=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WRaFoATXp5OS1RDBaoBV1svtrHWZAEnA/C3CtCw9u+VHWOwtTHIykXxJqVDF4+69f xuDTtrEq8Hi5LcSPMD+pnjyK+BL7Qu3iAbOevBXdPDdu6PE2qK56r8WSOHNZmlz71i QNCzvhewn87ctgZEchVTn/JE2XJKHfCAzWt2KEQXt7iJiqqv7hCSfDdzre9t63sIcq TFNVMNYlRxfW/otSiuzEYYFciSqRi05ZM2li72KuLWnP6PR91DtMzCCXqX0o3LoO83 3vgOBs1eQq2M2DfxKQxe58R8a8ge2ZXCGl36TyWTiWqaFBdG5Dohj9tyAY3desT4pT A65rr5GXVHEig== 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 71F1F4E16 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 328363A2D11 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:37 +0200 Message-ID: <20240716171155.31838-22-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/39] lavc/ffv1enc: stop using per-slice FFV1Context 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: b7Dox5uNt6IF All remaining accesses to them are for fields that have the same value in the main encoder context. --- libavcodec/ffv1enc.c | 57 ++++++++++++++++------------------- libavcodec/ffv1enc_template.c | 24 +++++++-------- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 3a6a0e6d90..ba378a54a4 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -269,13 +269,12 @@ static inline void put_vlc_symbol(PutBitContext *pb, VlcState *const state, #define RENAME(name) name ## 32 #include "ffv1enc_template.c" -static int encode_plane(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +static int encode_plane(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) { int x, y, i, ret; - const int ring_size = s->context_model ? 3 : 2; + const int ring_size = f->context_model ? 3 : 2; int16_t *sample[3]; sc->run_index = 0; @@ -287,22 +286,22 @@ static int encode_plane(FFV1Context *f, sample[0][-1]= sample[1][0 ]; sample[1][ w]= sample[1][w-1]; - if (s->bits_per_raw_sample <= 8) { + if (f->bits_per_raw_sample <= 8) { for (x = 0; x < w; x++) sample[0][x] = src[x * pixel_stride + stride * y]; - if((ret = encode_line(f, s, sc, w, sample, plane_index, 8)) < 0) + if((ret = encode_line(f, sc, w, sample, plane_index, 8)) < 0) return ret; } else { - if (s->packed_at_lsb) { + if (f->packed_at_lsb) { for (x = 0; x < w; x++) { sample[0][x] = ((uint16_t*)(src + stride*y))[x]; } } else { for (x = 0; x < w; x++) { - sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - s->bits_per_raw_sample); + sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - f->bits_per_raw_sample); } } - if((ret = encode_line(f, s, sc, w, sample, plane_index, s->bits_per_raw_sample)) < 0) + if((ret = encode_line(f, sc, w, sample, plane_index, f->bits_per_raw_sample)) < 0) return ret; } } @@ -908,8 +907,7 @@ slices_ok: return 0; } -static void encode_slice_header(FFV1Context *f, FFV1Context *fs, - FFV1SliceContext *sc) +static void encode_slice_header(FFV1Context *f, FFV1SliceContext *sc) { RangeCoder *c = &sc->c; uint8_t state[CONTEXT_SIZE]; @@ -942,7 +940,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context *fs, } } -static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, +static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[3], const int stride[3], int w, int h) { #define NB_Y_COEFF 15 @@ -968,7 +966,7 @@ static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, int stat[NB_Y_COEFF] = {0}; int x, y, i, p, best; int16_t *sample[3]; - int lbd = fs->bits_per_raw_sample <= 8; + int lbd = f->bits_per_raw_sample <= 8; for (y = 0; y < h; y++) { int lastr=0, lastg=0, lastb=0; @@ -1027,10 +1025,8 @@ static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc, static int encode_slice(AVCodecContext *c, void *arg) { - FFV1Context *fs = *(void **)arg; - FFV1Context *f = fs->avctx->priv_data; - const int si = (FFV1Context**)arg - f->slice_context; - FFV1SliceContext *sc = &f->slices[si]; + FFV1SliceContext *sc = arg; + FFV1Context *f = c->priv_data; int width = sc->slice_width; int height = sc->slice_height; int x = sc->slice_x; @@ -1046,7 +1042,7 @@ static int encode_slice(AVCodecContext *c, void *arg) sc->slice_coding_mode = 0; if (f->version > 3) { - choose_rct_params(fs, sc, planes, p->linesize, width, height); + choose_rct_params(f, sc, planes, p->linesize, width, height); } else { sc->slice_rct_by_coef = 1; sc->slice_rct_ry_coef = 1; @@ -1056,7 +1052,7 @@ retry: if (f->key_frame) ff_ffv1_clear_slice_state(f, sc); if (f->version > 2) { - encode_slice_header(f, fs, sc); + encode_slice_header(f, sc); } if (f->ac == AC_GOLOMB_RICE) { sc->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0; @@ -1071,26 +1067,26 @@ retry: const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - ret |= encode_plane(f, fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - ret |= encode_plane(f, fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + ret |= encode_plane(f, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + ret |= encode_plane(f, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (f->transparency) - ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); + ret |= encode_plane(f, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], 2, 1); } else if (c->pix_fmt == AV_PIX_FMT_YA8) { - ret = encode_plane(f, fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); - ret |= encode_plane(f, fs, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); + ret = encode_plane(f, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 2); + ret |= encode_plane(f, sc, p->data[0] + 1 + ps*x + y*p->linesize[0], width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { - ret = encode_rgb_frame32(f, fs, sc, planes, width, height, p->linesize); + ret = encode_rgb_frame32(f, sc, planes, width, height, p->linesize); } else { - ret = encode_rgb_frame(f, fs, sc, planes, width, height, p->linesize); + ret = encode_rgb_frame(f, sc, planes, width, height, p->linesize); } if (ret < 0) { av_assert0(sc->slice_coding_mode == 0); - if (fs->version < 4 || !f->ac) { + if (f->version < 4 || !f->ac) { av_log(c, AV_LOG_ERROR, "Buffer too small\n"); return ret; } @@ -1206,12 +1202,11 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, sc->c.bytestream_end = sc->c.bytestream_start + len; } } - avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL, - f->slice_count, sizeof(void *)); + avctx->execute(avctx, encode_slice, f->slices, NULL, + f->slice_count, sizeof(*f->slices)); buf_p = pkt->data; for (i = 0; i < f->slice_count; i++) { - FFV1Context *fs = f->slice_context[i]; FFV1SliceContext *sc = &f->slices[i]; int bytes; @@ -1219,7 +1214,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, bytes = ff_rac_terminate(&sc->c, 1); } else { flush_put_bits(&sc->pb); // FIXME: nicer padding - bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); + bytes = sc->ac_byte_count + put_bytes_output(&sc->pb); } if (i > 0 || f->version > 2) { av_assert0(bytes < pkt->size / f->slice_count); diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c index c79146d619..0bb0070d37 100644 --- a/libavcodec/ffv1enc_template.c +++ b/libavcodec/ffv1enc_template.c @@ -23,8 +23,7 @@ #include "ffv1_template.c" static av_always_inline int -RENAME(encode_line)(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +RENAME(encode_line)(FFV1Context *f, FFV1SliceContext *sc, int w, TYPE *sample[3], int plane_index, int bits) { PlaneContext *const p = &sc->plane[plane_index]; @@ -36,12 +35,12 @@ RENAME(encode_line)(FFV1Context *f, if (f->ac != AC_GOLOMB_RICE) { if (c->bytestream_end - c->bytestream < w * 35) { - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + av_log(f->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } else { if (put_bytes_left(&sc->pb, 0) < w * 4) { - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + av_log(f->avctx, AV_LOG_ERROR, "encoded frame too large\n"); return AVERROR_INVALIDDATA; } } @@ -73,7 +72,7 @@ RENAME(encode_line)(FFV1Context *f, diff = fold(diff, bits); if (f->ac != AC_GOLOMB_RICE) { - if (s->flags & AV_CODEC_FLAG_PASS1) { + if (f->flags & AV_CODEC_FLAG_PASS1) { put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat, sc->rc_stat2[p->quant_table_index][context]); } else { @@ -103,7 +102,7 @@ RENAME(encode_line)(FFV1Context *f, } } - ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", + ff_dlog(f->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, (int)put_bits_count(&sc->pb)); @@ -126,17 +125,16 @@ RENAME(encode_line)(FFV1Context *f, return 0; } -static int RENAME(encode_rgb_frame)(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +static int RENAME(encode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, const uint8_t *src[4], int w, int h, const int stride[4]) { int x, y, p, i; - const int ring_size = s->context_model ? 3 : 2; + const int ring_size = f->context_model ? 3 : 2; TYPE *sample[4][3]; - int lbd = s->bits_per_raw_sample <= 8; + int lbd = f->bits_per_raw_sample <= 8; int packed = !src[1]; - int bits = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8; + int bits = f->bits_per_raw_sample > 0 ? f->bits_per_raw_sample : 8; int offset = 1 << bits; int transparency = f->transparency; int packed_size = (3 + transparency)*2; @@ -196,9 +194,9 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f, sample[p][0][-1] = sample[p][1][0 ]; sample[p][1][ w] = sample[p][1][w-1]; if (lbd && sc->slice_coding_mode == 0) - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, 9); + ret = RENAME(encode_line)(f, sc, w, sample[p], (p + 1) / 2, 9); else - ret = RENAME(encode_line)(f, s, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1)); + ret = RENAME(encode_line)(f, sc, w, sample[p], (p + 1) / 2, bits + (sc->slice_coding_mode != 1)); if (ret < 0) return ret; } From patchwork Tue Jul 16 17:11:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50599 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp475522vqb; Tue, 16 Jul 2024 11:34:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWe3YGP6SfZ0PzBJyg2JP9Vvzhuyx62nso9dFgxM8Eh/s9S4asBoXhRS0ayQkWUJNHk2QxSyvT9mGK2l6jWDTKRRyDhh2S9j6dIvQ== X-Google-Smtp-Source: AGHT+IG+RWD9cXuQI9MSY5CA9aQz6g8i6G3Nm0mTGEPde9xpZ96sB35uccpWaDloAagzBcmzRlS7 X-Received: by 2002:a2e:91da:0:b0:2ec:4399:9bff with SMTP id 38308e7fff4ca-2eef41eaccemr21034981fa.42.1721154853415; Tue, 16 Jul 2024 11:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154853; cv=none; d=google.com; s=arc-20160816; b=qEXrtfl4Yblo7PD4s1s0DaOKgx9Pp7ZNcZcngXiPP0WX+4W4JZDTRHZvm67Ag/zccb 4V7+eEpWTCBCKU3I5IEwP0gxQ3N+RaZrIycFq5mjxf8ID6SYfH8jvRWAIUDoPMUwkHax HW5NHNcYChlsGrqbfyRJuHbYEcebnQTL6rsUwTnA0sa3TqzRaxhYjLfLTBv0KJ47GtI1 kBdJNHHM93h2uMmCgAoUax+1JUmtgC5Z3PSe/zjldrGQxH6g86QbMQpnznVO3Kfk97pI VGcXQj1WmbDGBKV3UfJgIJZiHvg7pZery5xhhI7H7Kx210Rrhqo42FiYzLejjY5M2CC7 GXvQ== 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=dFSSvbNb0yf3X4lVhhU1Uv0Uu+oNFJcylUCFzqY9/yI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=q80vh/HW7i7i6gphOz5PmWO+vpQECEcVGS/TCyWR4vlMWoHIQoOAnVo/R1mgwAhkLF yuIDFoJ0xI+GI+c0jUs8PPzaplmBWxk/3cHDHTDueHBwovnYUK2ApEZ82w3+lSxmVPpG OBZjVtt1CSdUpzma+27oVhdSHfu15JKRCln6M0P+cwGV5JHpWZiZfdStT91X0IrQa4SN qNHTyyRcda/u0ag40LPfOd0MKZNnYZD0ihmazl/flbdCPa5NNJJST80WmIhO36YwE/hZ XpGTbUPOsaP8FGBUPQ9NXt1D3QpEuia8UCNYuY+nga3fUXSPkDMpaOF/GRaRkv9hrUog XGYw==; 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=Q2lo0Vau; 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 4fb4d7f45d1cf-59b26a8d848si4245205a12.313.2024.07.16.11.34.13; Tue, 16 Jul 2024 11:34: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=Q2lo0Vau; 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 58FB668DAD0; Tue, 16 Jul 2024 21:34:10 +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 67D3268D85D for ; Tue, 16 Jul 2024 21:33:59 +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=Q2lo0Vau; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 4090A4DE1 for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id dETkG7BJJxGA for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=W3jQP+2epuOPfWVJFZpYOtkSFh3V9tk8iLrZroywXzM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Q2lo0VauHzXRprbwOIRT+CfTAN7IDWqiBeSeaRdlxbwLanzrwLaMQcHtY7X7Mz3nl pFN+UnYAS1PAlFYMLLUCl6/tsXnLKb+fH1p3yMMRSgH8HE93TtxSKXF9LNn6Y8CxWU eDhwYT8oMlCTqChkjXqMpTZ5sje/JF4LYWLsvTmG3dPvxmFyd0jjNwyk4hKe6KERPN 38xC8Jof3eJQfMUtvzAn41JgZrGD2V/HUtSNJ3s6Q2vlRazn9pG15L9z9niOlhLoEV hvedTzwJ6PUpxhnGu3TQUgVyE37aINDy293deCRZ371el13GpWUR8Oo1xom4M/jxjn 1hQs0L+t+RmSg== 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 9252D4E07 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3E0013A2D94 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:38 +0200 Message-ID: <20240716171155.31838-23-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/39] lavc/ffv1dec: move slice_reset_contexts to per-slice context 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: w6haaJqBz+ri --- libavcodec/ffv1.h | 16 +++++++++++++--- libavcodec/ffv1dec.c | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index ae81940073..cef61f38ec 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -86,8 +86,19 @@ typedef struct FFV1SliceContext { RangeCoder c; int ac_byte_count; ///< number of bytes used for AC coding - uint64_t rc_stat[256][2]; - uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; + + union { + // decoder-only + struct { + int slice_reset_contexts; + }; + + // encoder-only + struct { + uint64_t rc_stat[256][2]; + uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; + }; + }; } FFV1SliceContext; typedef struct FFV1Context { @@ -135,7 +146,6 @@ typedef struct FFV1Context { int max_slice_count; int num_v_slices; int num_h_slices; - int slice_reset_contexts; FFV1SliceContext *slices; } FFV1Context; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 4dc1f4b1cf..92e5b2a80b 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -238,7 +238,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, } if (fs->version > 3) { - fs->slice_reset_contexts = get_rac(c, state); + sc->slice_reset_contexts = get_rac(c, state); sc->slice_coding_mode = get_symbol(c, state, 0); if (sc->slice_coding_mode != 1) { sc->slice_rct_by_coef = get_symbol(c, state, 0); @@ -308,7 +308,7 @@ static int decode_slice(AVCodecContext *c, void *arg) } if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0) return ret; - if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { + if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) { ff_ffv1_clear_slice_state(f, sc); } else if (fs->slice_damaged) { return AVERROR_INVALIDDATA; From patchwork Tue Jul 16 17:11:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50598 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp472333vqb; Tue, 16 Jul 2024 11:27:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXprw4IIkg/DefwxZ4BzooQaCpp1YcBvmdfz2VTRONUR2ulSbrFJhaDwXHddQTO2ebkcHpqx2psovvtRGCBR3ZJpDQ7rY1RLHoP+w== X-Google-Smtp-Source: AGHT+IFKw0J+muS9gAp9+fRz4v3UAYfrT3bvVUpA8qDjeTgh98ZXpB8D3zYbZRbW1wHypRnw9FAM X-Received: by 2002:a05:6512:3087:b0:52e:9b4f:cfdc with SMTP id 2adb3069b0e04-52edf018594mr1898132e87.26.1721154417057; Tue, 16 Jul 2024 11:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154417; cv=none; d=google.com; s=arc-20160816; b=HSnvrVhU/G0X758KT1Pd97I5J3jt7nVxIQ2RjYOmZSDXpC1yRlkkjaZ8W1SY2gkuEW TapV9MuhGjkbeJuI+pNZUKL09vRV/Oo0bjGzgdTvaVdZ8z9t3L9CTjARxJkZc4Zc/MVm oPFI1woY2gAYP8nWzu2C35+usY7QbQd5DAHC+zHH423CUsJ1TmjmYOAlAc2GAh4208uw a4yDNvIkAa4jF3aVWhCUnTBHXOKx2LhSZkZY2aCek62gAbbIA5KDy2teH0oM71ap7q2O j2CX14wTfKNbCW0lLfb9O2HM18BryeKZPLCXQErmxF+7pu7pKPY/Pt19ySCOUv1jMkQF 7iPg== 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=09EgpJLaoCyrESRAGitdJCMy49B8php0UDsrwNSmEP8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=NFngclgdwGFr35hO31LPcLPG9CPpUCcBJIhKpPI1fYK+gRCxXyIjWqgd13pyIowWGu WoAC16YRlTqVqiebXvTqVU3QfPW+JkVaKHgdTPi3K1y0TWqmRElPCvg5wxO759etQS+o k0mRm9ofSNh0NISsWw7O78JsXAB2VIX61yJHWjPmPrlqm6YlTuwcO81slD2HyGYwhZlm uiz3PANKzdz/UWQJfvEmWoNWHyX7590FhIt8P3Uk0YFyTGg54xMKw3bRdjaVdMUuNK6S DPduqbzIPPc4t616W7wbB9gBvlQEcszcqbBxmYZ4wwva34z0pzvBKjtII7yBgrQc2bO8 m7fw==; 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="iD9D7L/B"; 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-a79bc8048b8si408155166b.772.2024.07.16.11.26.56; Tue, 16 Jul 2024 11:26: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=@khirnov.net header.s=mail header.b="iD9D7L/B"; 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 8149868DC01; Tue, 16 Jul 2024 21:14:36 +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 278F868DAA6 for ; Tue, 16 Jul 2024 21:14:05 +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=iD9D7L/B; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C743D4DF1 for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 8oEd2wtRIMKZ for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=llT0CchzE2POUlgEfOP32eanSccoOr7YeY6vkEIBWu4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iD9D7L/BYsTjStUbtFAi9XoPIjI7fY4WvvfhsQDLDU7WTMhspILmbxri8oTI8acei g5ItIGkCKV3ADQzyb05PFOJox/jlbDxiTiByTWfub7rK8Etgl0negtGswEaabej8rp 5THic1onmqQlAPDYUaqB4jgepjHrToP55LONhk1zEvWzowl7JNQRLVVKQwjLwy0GMB ed06ad8fCS0P9qWPpJE6a29pCEsEmOWjOotpdMUl2GBwfjp5jIx7xQk/rRW+da0y41 +dCKHWw39fhTewbnCsTSHYJTwgvppyZ/l1NTwznz6srS1Jg+S7gbAbh7clrNDOdBqo dcXtJPtjklw/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 B91784E18 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 49A093A2DB3 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:39 +0200 Message-ID: <20240716171155.31838-24-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/39] lavc/ffv1dec: move slice_damaged to per-slice context 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: 88hoSgcb82NN --- libavcodec/ffv1.h | 2 +- libavcodec/ffv1dec.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index cef61f38ec..c4803654f2 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -91,6 +91,7 @@ typedef struct FFV1SliceContext { // decoder-only struct { int slice_reset_contexts; + int slice_damaged; }; // encoder-only @@ -131,7 +132,6 @@ typedef struct FFV1Context { int ec; int intra; - int slice_damaged; int key_frame_ok; int context_model; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 92e5b2a80b..bd46930ec7 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -268,11 +268,10 @@ static int decode_slice(AVCodecContext *c, void *arg) ff_progress_frame_await(&f->last_picture, si); if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) { - FFV1Context *fssrc = f->fsrc->slice_context[si]; const FFV1SliceContext *scsrc = &f->fsrc->slices[si]; if (!(p->flags & AV_FRAME_FLAG_KEY)) - fs->slice_damaged |= fssrc->slice_damaged; + sc->slice_damaged |= scsrc->slice_damaged; for (int i = 0; i < f->plane_count; i++) { const PlaneContext *psrc = &scsrc->plane[i]; @@ -302,7 +301,7 @@ static int decode_slice(AVCodecContext *c, void *arg) return AVERROR(ENOMEM); if (decode_slice_header(f, fs, sc, p) < 0) { sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; - fs->slice_damaged = 1; + sc->slice_damaged = 1; return AVERROR_INVALIDDATA; } } @@ -310,7 +309,7 @@ static int decode_slice(AVCodecContext *c, void *arg) return ret; if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) { ff_ffv1_clear_slice_state(f, sc); - } else if (fs->slice_damaged) { + } else if (sc->slice_damaged) { return AVERROR_INVALIDDATA; } @@ -364,7 +363,7 @@ static int decode_slice(AVCodecContext *c, void *arg) v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec; if (v) { av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); - fs->slice_damaged = 1; + sc->slice_damaged = 1; } } @@ -793,7 +792,7 @@ static int read_header(FFV1Context *f) FFV1SliceContext *sc = &f->slices[j]; fs->packed_at_lsb = f->packed_at_lsb; - fs->slice_damaged = 0; + sc->slice_damaged = 0; if (f->version == 2) { int sx = get_symbol(c, state, 0); @@ -965,7 +964,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, } else { av_log(f->avctx, AV_LOG_ERROR, "\n"); } - fs->slice_damaged = 1; + sc->slice_damaged = 1; } if (avctx->debug & FF_DEBUG_PICT_INFO) { av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(buf_p + v - 4)); @@ -989,9 +988,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, sizeof(void*)); for (int i = f->slice_count - 1; i >= 0; i--) { - FFV1Context *fs = f->slice_context[i]; FFV1SliceContext *sc = &f->slices[i]; - if (fs->slice_damaged && f->last_picture.f) { + 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]; @@ -1044,7 +1042,6 @@ static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, fsdst->ec = fsrc->ec; fsdst->intra = fsrc->intra; - fsdst->slice_damaged = fssrc->slice_damaged; fsdst->key_frame_ok = fsrc->key_frame_ok; fsdst->packed_at_lsb = fsrc->packed_at_lsb; @@ -1077,6 +1074,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) const FFV1SliceContext *sc0 = &fsrc->slices[i]; copy_fields(fsdst, fssrc, fsrc); + sc->slice_damaged = sc0->slice_damaged; if (fsrc->version < 3) { sc->slice_x = sc0->slice_x; From patchwork Tue Jul 16 17:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50604 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp493392vqb; Tue, 16 Jul 2024 12:11:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVZUWKQq2jSHDQPdCQTATz3wcUIwepW9NAo0L7p6sxOZQ9aBST4PfH2CSgpA9uaQlctg6nki/nYy++J379R4fuv6OB4PLvy8Tawng== X-Google-Smtp-Source: AGHT+IH87sVAMEfU4kq4uy/sHsx2QzysK108+1kcUKik+otqjEMA4zX/VmYvgFzHJLopGD9WUWBW X-Received: by 2002:a17:906:d214:b0:a77:eddf:a49c with SMTP id a640c23a62f3a-a79ea46aae8mr229490266b.41.1721157110726; Tue, 16 Jul 2024 12:11:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721157110; cv=none; d=google.com; s=arc-20160816; b=f93MU05r/guZkRDi72vZSdxaaiS+YzlRodh9ZSDpFlV0k8PGsy1RpmeAmnR/91AVks ZOLffcorosb2CKJueUu15GM5FOOssoHj+hj21F/I6vEj3oG3lY6QvLa/WtCdV2mR2IfC mvxAXsc/PAPJk5DNTDm6qXEfE1FGWpJnsDOxaPSmqGYcShV3HCfmNmu5YDknIV7kLAko UU0dYb6NueGQIj/MW1awRlug/MSqKhdAtLlU9vZuh1Tmj3nX2iTIpSxyMjUFvLaBF0zr 2KCbonMGkWAGrgcF+ZhAO1fBdWKrJqhmqBIFPbk6XiGCwoxzsloWJQc6+6o2/nbXWsfF aGgA== 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=MPXk8ZjYFNRgR/iHr3SgqMYKvExSUgYKul+XLFpQ8iY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=0nH6am8Kqjif2Zf92RvLMS7VPbvQjpjM1uyyEhlBccl7yfLFFH3jK3iIvCR7eKmMft a11P5meKyQUXJ7hsuA/cRb4teJ3dE0JM5c6u2fDOMa/Tlele6YWYXdVNIU2ZkAI53h91 HnleHa8TU20db8wnai33O3LiDMSHjqV2bXMM8lpCYgiy54FaF8TAbng4Bf/iO1xedq0i bVq2VrK8Vdsi906yNCET2VJMgf/090VJdtcxpLxlnGBqDhvc9ArWvzv6vEe0ltIt/k8Z FcdmtFsbbctsSwo6JAlU7XIcIsqvGC5SQZk8yUKdHAXXHsiU7f2BQELLGnPezzvUo6AZ NOuA==; 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=jjiRNU1j; 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-a79bc58afedsi428215766b.164.2024.07.16.12.11.50; Tue, 16 Jul 2024 12:11: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=jjiRNU1j; 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 D0D9868DB9A; Tue, 16 Jul 2024 21:14:31 +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 B143E68D88A for ; Tue, 16 Jul 2024 21:14:04 +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=jjiRNU1j; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id CC60B4DEE for ; Tue, 16 Jul 2024 19:16:38 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Fyvtr2Z2k-fv for ; Tue, 16 Jul 2024 19:16:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=eS4VyDkyEIAis4vH9lluKZYBkf3SCigSdax73yPRN2k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jjiRNU1jigTBtPBCkNPqidpMR4sWTRQugt0FErehiPuQD9009rMMWqdkT3v7pscjs mgd4IBIrcth68jnQ4gqqET8Nf8pYLLW73idkZt1PJKXN5Hf2EduFEypTd0eT6JCKWf xjsv+lJvwWo6WD74FT9pVtoZWqEapwDV4auwpwNapE259HG9Z8golmcVwqzr52h4iS eGaZk9D5FcSesHbyh5DQpWMOiVji5d73CXrCPlbe+ZHTNTs+6YGFAXHHw9naVM86HD 3Da4Ju4PGCS0gwnzxkJuHZpSTgcK7kZQqzvaMTapxbJOi6CHtqmPbxgwxhwNf2h7Lq 3/Zyux5ju+FGA== 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 0C4064E12 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 55AFD3A2DE0 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:40 +0200 Message-ID: <20240716171155.31838-25-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 25/39] lavc/ffv1dec: stop using per-slice FFV1Context 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: xep8eddT9ojw All remaining accesses to them are for fields that have the same value in the main encoder context. Drop now-unused FFV1Context.slice_contexts. --- libavcodec/ffv1.c | 18 +++--------- libavcodec/ffv1.h | 1 - libavcodec/ffv1dec.c | 54 ++++++++++++++--------------------- libavcodec/ffv1dec_template.c | 16 +++++------ 4 files changed, 33 insertions(+), 56 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 4ef04f6b9b..07cf5564cc 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -102,7 +102,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f) av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) { - int i, max_slice_count = f->num_h_slices * f->num_v_slices; + int max_slice_count = f->num_h_slices * f->num_v_slices; av_assert0(max_slice_count > 0); @@ -112,7 +112,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) f->max_slice_count = max_slice_count; - for (i = 0; i < max_slice_count;) { + for (int i = 0; i < max_slice_count; i++) { FFV1SliceContext *sc = &f->slices[i]; int sx = i % f->num_h_slices; int sy = i / f->num_h_slices; @@ -120,22 +120,15 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) int sxe = f->avctx->width * (sx + 1) / f->num_h_slices; int sys = f->avctx->height * sy / f->num_v_slices; int sye = f->avctx->height * (sy + 1) / f->num_v_slices; - FFV1Context *fs = av_mallocz(sizeof(*fs)); - - if (!fs) - return AVERROR(ENOMEM); - - f->slice_context[i++] = fs; - memcpy(fs, f, sizeof(*fs)); sc->slice_width = sxe - sxs; sc->slice_height = sye - sys; sc->slice_x = sxs; sc->slice_y = sys; - sc->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * + sc->sample_buffer = av_malloc_array((f->width + 6), 3 * MAX_PLANES * sizeof(*sc->sample_buffer)); - sc->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES * + sc->sample_buffer32 = av_malloc_array((f->width + 6), 3 * MAX_PLANES * sizeof(*sc->sample_buffer32)); if (!sc->sample_buffer || !sc->sample_buffer32) return AVERROR(ENOMEM); @@ -213,9 +206,6 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) av_freep(&s->rc_stat2[j]); } - for (i = 0; i < s->max_slice_count; i++) - av_freep(&s->slice_context[i]); - av_freep(&s->slices); return 0; diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index c4803654f2..9d79219921 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -141,7 +141,6 @@ typedef struct FFV1Context { int gob_count; int quant_table_count; - struct FFV1Context *slice_context[MAX_SLICES]; int slice_count; int max_slice_count; int num_v_slices; diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index bd46930ec7..8bb9b83daa 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -116,8 +116,7 @@ static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac) #define RENAME(name) name ## 32 #include "ffv1dec_template.c" -static int decode_plane(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +static int decode_plane(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src, int w, int h, int stride, int plane_index, int pixel_stride) @@ -140,23 +139,23 @@ static int decode_plane(FFV1Context *f, sample[1][-1] = sample[0][0]; sample[0][w] = sample[0][w - 1]; - if (s->avctx->bits_per_raw_sample <= 8) { - int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8); + if (f->avctx->bits_per_raw_sample <= 8) { + int ret = decode_line(f, sc, gb, w, sample, plane_index, 8); if (ret < 0) return ret; for (x = 0; x < w; x++) src[x*pixel_stride + stride * y] = sample[1][x]; } else { - int ret = decode_line(f, s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample); + int ret = decode_line(f, sc, gb, w, sample, plane_index, f->avctx->bits_per_raw_sample); if (ret < 0) return ret; - if (s->packed_at_lsb) { + if (f->packed_at_lsb) { for (x = 0; x < w; x++) { ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x]; } } else { for (x = 0; x < w; x++) { - ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - s->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * s->avctx->bits_per_raw_sample - 16); + ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - f->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * f->avctx->bits_per_raw_sample - 16); } } } @@ -164,7 +163,7 @@ static int decode_plane(FFV1Context *f, return 0; } -static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, +static int decode_slice_header(const FFV1Context *f, FFV1SliceContext *sc, AVFrame *frame) { RangeCoder *c = &sc->c; @@ -237,7 +236,7 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, frame->sample_aspect_ratio = (AVRational){ 0, 1 }; } - if (fs->version > 3) { + if (f->version > 3) { sc->slice_reset_contexts = get_rac(c, state); sc->slice_coding_mode = get_symbol(c, state, 0); if (sc->slice_coding_mode != 1) { @@ -255,13 +254,12 @@ static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, static int decode_slice(AVCodecContext *c, void *arg) { - FFV1Context *fs = *(void **)arg; - FFV1Context *f = fs->avctx->priv_data; + FFV1Context *f = c->priv_data; + FFV1SliceContext *sc = arg; int width, height, x, y, ret; const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; AVFrame * const p = f->picture.f; - const int si = (FFV1Context**)arg - f->slice_context; - FFV1SliceContext *sc = &f->slices[si]; + const int si = sc - f->slices; GetBitContext gb; if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) @@ -299,7 +297,7 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->version > 2) { if (ff_ffv1_init_slice_state(f, sc) < 0) return AVERROR(ENOMEM); - if (decode_slice_header(f, fs, sc, p) < 0) { + if (decode_slice_header(f, sc, p) < 0) { sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; sc->slice_damaged = 1; return AVERROR_INVALIDDATA; @@ -333,29 +331,29 @@ static int decode_slice(AVCodecContext *c, void *arg) const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift); const int cx = x >> f->chroma_h_shift; const int cy = y >> f->chroma_v_shift; - decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); + decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1); if (f->chroma_planes) { - decode_plane(f, fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); - decode_plane(f, fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); + decode_plane(f, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1); + decode_plane(f, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1); } if (f->transparency) - decode_plane(f, fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); + decode_plane(f, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1); } else if (f->colorspace == 0) { - decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); - decode_plane(f, fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); + decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2); + decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2); } else if (f->use32bit) { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame32(f, fs, sc, &gb, planes, width, height, p->linesize); + decode_rgb_frame32(f, sc, &gb, planes, width, height, p->linesize); } else { uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], p->data[1] + ps * x + y * p->linesize[1], p->data[2] + ps * x + y * p->linesize[2], p->data[3] + ps * x + y * p->linesize[3] }; - decode_rgb_frame(f, fs, sc, &gb, planes, width, height, p->linesize); + decode_rgb_frame(f, sc, &gb, planes, width, height, p->linesize); } if (f->ac != AC_GOLOMB_RICE && f->version > 2) { int v; @@ -788,9 +786,7 @@ static int read_header(FFV1Context *f) } for (int j = 0; j < f->slice_count; j++) { - FFV1Context *fs = f->slice_context[j]; FFV1SliceContext *sc = &f->slices[j]; - fs->packed_at_lsb = f->packed_at_lsb; sc->slice_damaged = 0; @@ -936,7 +932,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, buf_p = buf + buf_size; for (int i = f->slice_count - 1; i >= 0; i--) { - FFV1Context *fs = f->slice_context[i]; FFV1SliceContext *sc = &f->slices[i]; int trailer = 3 + 5*!!f->ec; int v; @@ -977,15 +972,14 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, } else sc->c.bytestream_end = buf_p + v; - fs->avctx = avctx; } avctx->execute(avctx, decode_slice, - &f->slice_context[0], + f->slices, NULL, f->slice_count, - sizeof(void*)); + sizeof(*f->slices)); for (int i = f->slice_count - 1; i >= 0; i--) { FFV1SliceContext *sc = &f->slices[i]; @@ -1067,13 +1061,9 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], sizeof(fsrc->quant_tables[0])); for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) { - FFV1Context *fssrc = fsrc->slice_context[i]; - FFV1Context *fsdst = fdst->slice_context[i]; - FFV1SliceContext *sc = &fdst->slices[i]; const FFV1SliceContext *sc0 = &fsrc->slices[i]; - copy_fields(fsdst, fssrc, fsrc); sc->slice_damaged = sc0->slice_damaged; if (fsrc->version < 3) { diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c index 4bb15801c1..64ce74dd03 100644 --- a/libavcodec/ffv1dec_template.c +++ b/libavcodec/ffv1dec_template.c @@ -23,8 +23,7 @@ #include "ffv1_template.c" static av_always_inline int -RENAME(decode_line)(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +RENAME(decode_line)(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, int w, TYPE *sample[2], int plane_index, int bits) { @@ -117,7 +116,7 @@ RENAME(decode_line)(FFV1Context *f, } else diff = get_vlc_symbol(gb, &p->vlc_state[context], bits); - ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", + ff_dlog(f->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n", run_count, run_index, run_mode, x, get_bits_count(gb)); } @@ -130,15 +129,14 @@ RENAME(decode_line)(FFV1Context *f, return 0; } -static int RENAME(decode_rgb_frame)(FFV1Context *f, - FFV1Context *s, FFV1SliceContext *sc, +static int RENAME(decode_rgb_frame)(FFV1Context *f, FFV1SliceContext *sc, GetBitContext *gb, uint8_t *src[4], int w, int h, int stride[4]) { int x, y, p; TYPE *sample[4][2]; - int lbd = s->avctx->bits_per_raw_sample <= 8; - int bits = s->avctx->bits_per_raw_sample > 0 ? s->avctx->bits_per_raw_sample : 8; + int lbd = f->avctx->bits_per_raw_sample <= 8; + int bits = f->avctx->bits_per_raw_sample > 0 ? f->avctx->bits_per_raw_sample : 8; int offset = 1 << bits; int transparency = f->transparency; @@ -162,9 +160,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f, sample[p][1][-1]= sample[p][0][0 ]; sample[p][0][ w]= sample[p][0][w-1]; if (lbd && sc->slice_coding_mode == 0) - ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, 9); + ret = RENAME(decode_line)(f, sc, gb, w, sample[p], (p + 1)/2, 9); else - ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 1)/2, bits + (sc->slice_coding_mode != 1)); + ret = RENAME(decode_line)(f, sc, gb, w, sample[p], (p + 1)/2, bits + (sc->slice_coding_mode != 1)); if (ret < 0) return ret; } From patchwork Tue Jul 16 17:11:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50595 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp472139vqb; Tue, 16 Jul 2024 11:26:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW312OeOfEvEZlR5GGGZb+vo+cW6vzL7Yxo7Xr6UW4wakqhs+jZT2G28c5fBACeA6n3RqMFObkLbZ13l2kf7Yx808vV/QjCI1Docw== X-Google-Smtp-Source: AGHT+IExAucfXoY9rMTCXqN5QJwr/6K0unRK/K8CuUjur5inUJlZy54hu9iz6COPWhPCg18xbSTK X-Received: by 2002:a50:c307:0:b0:59e:bc66:b1f8 with SMTP id 4fb4d7f45d1cf-59eee833901mr2145443a12.7.1721154410526; Tue, 16 Jul 2024 11:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154410; cv=none; d=google.com; s=arc-20160816; b=AgneGThmcPl6AoEOI8ioQlQbnvDFghi1etbBaTtm/Ovm6JeKr0eK3jksIZP1Fwe2Vf COanaTqD3UnaYlvU4KC142ozhYFjSmSAZ1lReBgnGrcOYR6kYrgyApMDULZ3nkC0nSDz lSEJkuNdLlHfiYB7UKBlqNIBuWR2XK2WrtrFwluf9NhZj9QSshLope0H0odMBRoirZQp LaywfzZ3Wq7VAnMFrP+q5XnN1hP9qKCeNphJQ1f0wv+NQ/HQhGnsEx87KwamcXY4ZiJk POUPG2Xmg1Bg7fFR911e/EMtJ2X6yRelOUvvjotFwSy6GagJwBFsUmXDz8O4nuEOyT13 lUQA== 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=fuB9pDdOpfKNYrsAQzZwnx6Zmc1wM+zBmxIs62xKzwc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=kqsBYsqx7Xk5CiW8ioaCKhWDvJQQGpmIgaVK1uWh1VU3TdAjnTlBcJNbFl1OhOe/cl Xe/T2FXigq1sDr/bz/dP9fHQWE3vhOxGLogZ64Z7xhZq7lVVbKb5M3LEQycFNoxvxb2u hw5Qye3cvUs4awzllIHw2gjBO0m8qzWWQITsnz6d2sEZ73BkOXmxMe/p0n+cq++PjsT5 wi488IJTQD2a4uDtNx+sobTLBETXo8395O88vhTQF5S3EbD+pKf4MZO5vwsFtvk5GalW HLZHxe/bclBVq+wnsavRPxHuoxl7DcfvPoi0E+41FU2xmLZMzJEeIXvyn5l6f5ACfhei nXLQ==; 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=K2lXHB+U; 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 4fb4d7f45d1cf-59b26a8daa8si4184796a12.273.2024.07.16.11.26.50; Tue, 16 Jul 2024 11:26: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=K2lXHB+U; 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 5301568DBF4; Tue, 16 Jul 2024 21:14:34 +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 B568D68DAB1 for ; Tue, 16 Jul 2024 21:14:04 +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=K2lXHB+U; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 03CD94E0C for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id z3741LgcSVZp for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150189; bh=xKvfYg1vjjRlXGK0xaPAOiR7sMeXuTwbjchgABeVv90=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K2lXHB+UVVydWk2wmjzPmmgFKzXnAVG+pbOB4JMjd18bqMI6PJrbmIh1q0nuzLq2M CEbxBwCpSrbhJE58tzC+XG1kaWTztX+eVUf4I3CTOXZphDA5mlyR57azyBoqBFBcg/ c1q9FSt0+dwxaFDsZm5vCsbyqwlNHsHIzgZba2IMTVey8srjQtV6mIqc+6XuxD30hd Oz2d8Ze9/xZK3BlQUSTWvoUAg9Cq2FcuSkG6tH0WAD68NvtRG1Cy031kK6tCLvD6i6 TueDVclN6Zr4MJ2/a5jpth2P/7Pl1lplfjAIR5ibdkOw06BPE+V4hhvzEI6drR1QX0 rM3czVqtNrUQA== 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 81FF74E05 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 614393A2E47 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:41 +0200 Message-ID: <20240716171155.31838-26-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 26/39] lavc/ffv1dec: inline copy_fields() into update_thread_context() 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: fHR88oKNOGNy It is now only called from a single place, so there is no point in it being a separate function. --- libavcodec/ffv1dec.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 8bb9b83daa..be4a1a2bf3 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1021,27 +1021,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, } #if HAVE_THREADS -static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc, - const FFV1Context *fsrc) -{ - fsdst->version = fsrc->version; - fsdst->micro_version = fsrc->micro_version; - fsdst->chroma_planes = fsrc->chroma_planes; - fsdst->chroma_h_shift = fsrc->chroma_h_shift; - fsdst->chroma_v_shift = fsrc->chroma_v_shift; - fsdst->transparency = fsrc->transparency; - fsdst->plane_count = fsrc->plane_count; - fsdst->ac = fsrc->ac; - fsdst->colorspace = fsrc->colorspace; - - fsdst->ec = fsrc->ec; - fsdst->intra = fsrc->intra; - fsdst->key_frame_ok = fsrc->key_frame_ok; - - fsdst->packed_at_lsb = fsrc->packed_at_lsb; - fsdst->slice_count = fsrc->slice_count; -} - static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { FFV1Context *fsrc = src->priv_data; @@ -1050,7 +1029,22 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) if (dst == src) return 0; - copy_fields(fdst, fsrc, fsrc); + fdst->version = fsrc->version; + fdst->micro_version = fsrc->micro_version; + fdst->chroma_planes = fsrc->chroma_planes; + fdst->chroma_h_shift = fsrc->chroma_h_shift; + fdst->chroma_v_shift = fsrc->chroma_v_shift; + fdst->transparency = fsrc->transparency; + fdst->plane_count = fsrc->plane_count; + fdst->ac = fsrc->ac; + fdst->colorspace = fsrc->colorspace; + + fdst->ec = fsrc->ec; + fdst->intra = fsrc->intra; + fdst->key_frame_ok = fsrc->key_frame_ok; + + fdst->packed_at_lsb = fsrc->packed_at_lsb; + fdst->slice_count = fsrc->slice_count; fdst->use32bit = fsrc->use32bit; memcpy(fdst->state_transition, fsrc->state_transition, sizeof(fdst->state_transition)); From patchwork Tue Jul 16 17:11:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50586 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp467086vqb; Tue, 16 Jul 2024 11:15:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUEkDtXVYOV7FHxk/USGJmZe+F1565UruI0WOwYBJrg0zEuXwt7L1n30hRNIOH05W3Iq9FaMi8vF54V9f6gD+oVWF6noRBpJcKVwA== X-Google-Smtp-Source: AGHT+IEc2jnZYRaWnIE52ebEYjwELjjjYCRaU1SjGfFlEFHb+w9huRBgfXClJsjevBNeQ+ysOLnP X-Received: by 2002:a05:6512:15a5:b0:52c:8275:6292 with SMTP id 2adb3069b0e04-52edf8dcef2mr886302e87.34.1721153709728; Tue, 16 Jul 2024 11:15:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153709; cv=none; d=google.com; s=arc-20160816; b=KlTWVCEINtbHEXebZ5wHK6veMhU2gORenTHs07b+B9FaaggpGvfzBKRrc0I11oE35q jvhggw5BYg7rAloKfl4TY/RLEY3UHWyzHdJQhW8+P4nt5F81mWNurEvwhWAJfRpWN/2R sn1trvR7oosrbkzfuxXgASIvFLKGsA5lufxgYwBxpig7B9b18C0hO4oMKtWN6FH57A/v aKUTCCj0UEZlFlg+WREgN0bLnm533mgq2JSY3YOO90GJpufhABxDxdHhesBOKbFzfkaB FMiHGglG1vOxfEjRju3XtaoLO4vnS8BPbzavTmQeumJQj6P42gj3xkg0lfPrLg71KQiU fRDw== 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=84hn3XHNj4EdpqGCPqD94A7aTwaVKHR6tG0wIrqUaxg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=mVO/i17kedQcjk7BlD1Vp8jWiVaFW0TqxNwbixvReJwdcvhUm6e6Zs/66icU5VOl7t +8m46kpSylakvbRohOY9hRbSmoYzKHw/UDwKcrCYWiZi5CBzngPPd1X0FoK2S6Re97id tJIHyJ9xZGUb+EciSpZODoB8hT7FbeRHQt2MdmOBGbHtaSvk3Se5U8wWcjZmly9Fd3QT fSWC9OAd4Z+FfdZlZPJknw+jYHGDQUmpb8BkVMnV4Ge0qqLqgQ5kkP1xtHnXdrnUkXzZ CPcdp9H8xDUDz52WZIGHKbWnYEG3HqtJqMtH9BcwDZJB8NWKQjhuPSTFguySG9L5J2Lc ja+A==; 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=iNPsNDTr; 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-52ed2528c30si2268785e87.70.2024.07.16.11.15.09; Tue, 16 Jul 2024 11:15:09 -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=iNPsNDTr; 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 1E90168DAE6; Tue, 16 Jul 2024 21:14:17 +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 84AB368D8D0 for ; Tue, 16 Jul 2024 21:14:04 +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=iNPsNDTr; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 49B5B4DE2 for ; Tue, 16 Jul 2024 19:16:38 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id onXbvLXiWgOU for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=SjyoPEshDDy0NzRMc111ie0DjM8B7+YjcLEfldRBcqA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iNPsNDTr6I+zWAerQ3vJUdF9wHqTyToESJMzP9c9hZewIpQGoN60fIBUdIe8Ex/TO wc/xLZYOBiW5Ry1Zt75RODiLqI91U8Ei+MHws2EsVivqUCEO73iYhJelGBjVQWWoLd oJZjn2dtPgyQoB7PMxLuRcVz1VVZcJs4DHZGlPby1yvshgz4w1J/ufMG4lTQJ4hZkS tt27QF9pNVRr9Mc4+BZV2VY/dtbjgp5QJkCno8lhD26AcWG0xOSLwgdzzB7eNQ8Cr3 c6tyKNOoGIVpOXPDKdvy0aDyl+0bCbkWTK3KRVgkny/OABEPpjUUHjAuwRiPiRnOOP rki0yzLvVpA7w== 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 A96374E0A for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6CF3E3A2E5E for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:42 +0200 Message-ID: <20240716171155.31838-27-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 27/39] lavc/ffv1: change FFV1SliceContext.plane into a RefStruct object 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: 6CeNzXFeK/Oy Frame threading in the FFV1 decoder works in a very unusual way - the state that needs to be propagated from the previous frame is not decoded pixels(¹), but each slice's entropy coder state after decoding the slice. For that purpose, the decoder's update_thread_context() callback stores a pointer to the previous frame thread's private data. Then, when decoding each slice, the frame thread uses the standard progress mechanism to wait for the corresponding slice in the previous frame to be completed, then copies the entropy coder state from the previously-stored pointer. This approach is highly dubious, as update_thread_context() should be the only point where frame-thread contexts come into direct contact. There are no guarantees that the stored pointer will be valid at all, or will contain any particular data after update_thread_context() finishes. More specifically, this code can break due to the fact that keyframes reset entropy coder state and thus do not need to wait for the previous frame. As an example, consider a decoder process with 2 frame threads - thread 0 with its context 0, and thread 1 with context 1 - decoding a previous frame P, current frame F, followed by a keyframe K. Then consider concurrent execution consistent with the following sequence of events: * thread 0 starts decoding P * thread 0 reads P's slice header, then calls ff_thread_finish_setup() allowing next frame thread to start * main thread calls update_thread_context() to transfer state from context 0 to context 1; context 1 stores a pointer to context 0's private data * thread 1 starts decoding F * thread 1 reads F's slice header, then calls ff_thread_finish_setup() allowing the next frame thread to start decoding * thread 0 finishes decoding P * thread 0 starts decoding K; since K is a keyframe, it does not wait for F and reallocates the arrays holding entropy coder state * thread 0 finishes decoding K * thread 1 reads entropy coder state from its stored pointer to context 0, however it finds state from K rather than from P This execution is currently prevented by special-casing FFV1 in the generic frame threading code, however that is supremely ugly. It also involves unnecessary copies of the state arrays, when in fact they can only be used by one thread at a time. This commit addresses these deficiencies by changing the array of PlaneContext (each of which contains the allocated state arrays) embedded in FFV1SliceContext into a RefStruct object. This object can then be propagated across frame threads in standard manner. Since the code structure guarantees only one thread accesses it at a time, no copies are necessary. It is also re-created for keyframes, solving the above issue cleanly. Special-casing of FFV1 in the generic frame threading code will be removed in a later commit. (¹) except in the case of a damaged slice, when previous frame's pixels are used directly --- libavcodec/ffv1.c | 30 ++++++++++++++++++++++++------ libavcodec/ffv1.h | 4 +++- libavcodec/ffv1dec.c | 33 +++++++++------------------------ 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 07cf5564cc..9c219b5ddb 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -31,6 +31,7 @@ #include "avcodec.h" #include "ffv1.h" +#include "refstruct.h" av_cold int ff_ffv1_common_init(AVCodecContext *avctx) { @@ -52,6 +53,24 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx) return 0; } +static void planes_free(FFRefStructOpaque opaque, void *obj) +{ + PlaneContext *planes = obj; + + for (int i = 0; i < MAX_PLANES; i++) { + PlaneContext *p = &planes[i]; + + av_freep(&p->state); + av_freep(&p->vlc_state); + } +} + +PlaneContext* ff_ffv1_planes_alloc(void) +{ + return ff_refstruct_alloc_ext(sizeof(PlaneContext) * MAX_PLANES, + 0, NULL, planes_free); +} + av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc) { @@ -132,6 +151,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f) sizeof(*sc->sample_buffer32)); if (!sc->sample_buffer || !sc->sample_buffer32) return AVERROR(ENOMEM); + + sc->plane = ff_ffv1_planes_alloc(); + if (!sc->plane) + return AVERROR(ENOMEM); } return 0; @@ -188,12 +211,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx) av_freep(&sc->sample_buffer); av_freep(&sc->sample_buffer32); - for (i = 0; i < s->plane_count; i++) { - PlaneContext *p = &sc->plane[i]; - - av_freep(&p->state); - av_freep(&p->vlc_state); - } + ff_refstruct_unref(&sc->plane); } av_freep(&avctx->stats_out); diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h index 9d79219921..edc3f6aef0 100644 --- a/libavcodec/ffv1.h +++ b/libavcodec/ffv1.h @@ -81,7 +81,8 @@ typedef struct FFV1SliceContext { int slice_rct_by_coef; int slice_rct_ry_coef; - PlaneContext plane[MAX_PLANES]; + // RefStruct reference, array of MAX_PLANES elements + PlaneContext *plane; PutBitContext pb; RangeCoder c; @@ -153,6 +154,7 @@ int ff_ffv1_common_init(AVCodecContext *avctx); int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc); int ff_ffv1_init_slices_state(FFV1Context *f); int ff_ffv1_init_slice_contexts(FFV1Context *f); +PlaneContext *ff_ffv1_planes_alloc(void); int ff_ffv1_allocate_initial_states(FFV1Context *f); void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc); int ff_ffv1_close(AVCodecContext *avctx); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index be4a1a2bf3..7dc4a537a9 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -38,6 +38,7 @@ #include "mathops.h" #include "ffv1.h" #include "progressframe.h" +#include "refstruct.h" #include "thread.h" static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state, @@ -265,30 +266,11 @@ static int decode_slice(AVCodecContext *c, void *arg) if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) ff_progress_frame_await(&f->last_picture, si); - if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) { + if (f->fsrc) { const FFV1SliceContext *scsrc = &f->fsrc->slices[si]; if (!(p->flags & AV_FRAME_FLAG_KEY)) sc->slice_damaged |= scsrc->slice_damaged; - - for (int i = 0; i < f->plane_count; i++) { - const PlaneContext *psrc = &scsrc->plane[i]; - PlaneContext *pdst = &sc->plane[i]; - - av_free(pdst->state); - av_free(pdst->vlc_state); - memcpy(pdst, psrc, sizeof(*pdst)); - pdst->state = NULL; - pdst->vlc_state = NULL; - - if (f->ac) { - pdst->state = av_malloc_array(CONTEXT_SIZE, psrc->context_count); - memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count); - } else { - pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count); - memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count); - } - } } sc->slice_rct_by_coef = 1; @@ -812,6 +794,11 @@ static int read_header(FFV1Context *f) && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height); } + ff_refstruct_unref(&sc->plane); + sc->plane = ff_ffv1_planes_alloc(); + if (!sc->plane) + return AVERROR(ENOMEM); + for (int i = 0; i < f->plane_count; i++) { PlaneContext *const p = &sc->plane[i]; @@ -828,10 +815,6 @@ static int read_header(FFV1Context *f) if (f->version <= 2) { av_assert0(context_count >= 0); - if (p->context_count < context_count) { - av_freep(&p->state); - av_freep(&p->vlc_state); - } p->context_count = context_count; } } @@ -1060,6 +1043,8 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) sc->slice_damaged = sc0->slice_damaged; + ff_refstruct_replace(&sc->plane, sc0->plane); + if (fsrc->version < 3) { sc->slice_x = sc0->slice_x; sc->slice_y = sc0->slice_y; From patchwork Tue Jul 16 17:11:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50602 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp478682vqb; Tue, 16 Jul 2024 11:41:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXT13JaZmG399oBNxwdec7IJNHqnYZEcAmBi5kBn9ptqGahMjfACJPP1GtnVjGfAEYcQ9kw6Y2uVlTpb82cy9ZE8kTRo8pcOOZxLA== X-Google-Smtp-Source: AGHT+IFYZDo2AZGJ2ewqAoeZNtcjYf4Ys9CyU3hreycFEBzUYA8iKUawVkx4yrW2XsoUUatnrObB X-Received: by 2002:a05:6402:2350:b0:57a:858d:20ca with SMTP id 4fb4d7f45d1cf-59ef00b5f6cmr2056601a12.28.1721155314374; Tue, 16 Jul 2024 11:41:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721155314; cv=none; d=google.com; s=arc-20160816; b=Lm3pliw0RQ29lNp7mFgCaeaVwwnJQvR+qeUPZR4dbDgcVARmB9FQj6c1rJufAs6mfW HnWkiCW4adyn6MFq6hvKKdzkNooBHmtU/qumAMSgixPXFhQMBLmwDkeLcTi5EobJu/sU it9i1vuBX30jJS0AcYKPFcY95lo/Frimxv3h+csObk/ptw4gXsCgEMgK6FoS7vqpsCfY 1vYuzdcuYeSrTU0g+qh3gSxwG7Mo2OckDrSAnpVwjM5kPB77xdlN4NI8AjTYHgb22Q09 HJvQ/csqBN3Mcz5dga95UxCchk01BOfeCZKgk35vaVONhcEIaKHokD+zB5MroT7x1Gbv jSlw== 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=XeJysVv70sfmwvWnrVGlDMXs/12Xp3kMMjAi3BOaHxc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=SSeAc9mV/vi6V8m0b5JYHktZ/qNpu0Qc/J8oAjNvLn3ncqlgq6v+50Qd/DhKmbUp/g CiTxAICQVoIQm7Uo413pzK4ocy/p4PklbjYjfnbWZkNkWHARlEenRJXg2bqVwsoesfpl A+Z89gmef2KbjAiaj7cKs8o8wK1hA8OhZNTyfEzXWZqqkeR8lUquMmY1kspvO2+3FiQc +kU6SJJdVHr2JLfX6BRi5DU0p3s/+K3TzFKUxR/alFBVXWxbyJNvnD87ElUG9FDES/5G IwpG5pF/QgNqOC1UjvXlMK6BmsB+2gdNj3RP0NWdqtRuP4Gd+R4DcV1T6YarY0RUyRWn +vWg==; 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=K1xI7G+7; 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 4fb4d7f45d1cf-59b24a6c446si3997747a12.101.2024.07.16.11.41.54; Tue, 16 Jul 2024 11:41:54 -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=K1xI7G+7; 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 CA82668DB88; Tue, 16 Jul 2024 21:14:29 +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 AEA3768D85D for ; Tue, 16 Jul 2024 21:14:04 +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=K1xI7G+7; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5890B4DA7 for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id xlQsj5s0N1QE for ; Tue, 16 Jul 2024 19:16:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=bHi/u8LgtXxZ1rC5ENGTOjS1mLOhBSSn2ZXhkAZF8fg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=K1xI7G+7PL1He3O1LF+YqlFYmiyRKhzYh6WS3fdf19o/korjJwtUhHF8qNM3T8a+z yJ5QOloeUb/tmh1L26i5kzSIpK9L8fz4C0I1xn0lJ3UGpSPbr+ywhWgDUUJGvY0m9J uwLH3mt+NddNy/kkP8MYsvSyTcut5kMbB9kFCD14GD10uqaxV3vKQEwZY7xxfg3PWA ix4C3lY0/hw9NyeDjLN1YfvXJp6JzJPM8Nvy1/+1oIUeD2mLDF8ydkTBlfaWevG+Ae 5i3V0az0q5Y5BFO6U9wNUkYh+D+4TCjwpu2+35oAgL2PwPju/u57yrKv4LrbNeqd7v fmbDS8ORRYtUg== 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 1D1F24E14 for ; Tue, 16 Jul 2024 19:16:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 78A1E3A2E77 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:43 +0200 Message-ID: <20240716171155.31838-28-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/39] 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: KRfyShVMfJCB 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 | 3 ++- libavcodec/ffv1dec.c | 24 ++++++++++-------------- 3 files changed, 14 insertions(+), 15 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..ae62732650 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,8 @@ typedef struct FFV1Context { int num_h_slices; FFV1SliceContext *slices; + // RefStruct object, per-slice damage flags + uint8_t *slice_damaged; } FFV1Context; int ff_ffv1_common_init(AVCodecContext *avctx); diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 7dc4a537a9..c9ac850d98 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -263,16 +263,9 @@ 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_rct_by_coef = 1; sc->slice_rct_ry_coef = 1; @@ -347,6 +340,8 @@ static int decode_slice(AVCodecContext *c, void *arg) } } + f->slice_damaged[si] = sc->slice_damaged; + ff_progress_frame_report(&f->picture, si); return 0; @@ -767,11 +762,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); @@ -1041,8 +1039,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) { @@ -1053,12 +1049,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 From patchwork Tue Jul 16 17:11:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50594 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp472126vqb; Tue, 16 Jul 2024 11:26:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXDlEuUhyJl/o94FjR60d/2AC/BMG940ZJMAfd+Wr9RMH0bmzBztYGx0IsTx6R6ayKSgnDymkA2NBoadbe4ph5gc718xgOvc0hx2w== X-Google-Smtp-Source: AGHT+IHrpgXeTp3YyAl5ZqYzqAXpwTWE50Yj52bm5iKPCo+k3goe+n5cwTNrKLlAiBeOvUeD04rg X-Received: by 2002:a05:6512:238e:b0:52e:97dd:327b with SMTP id 2adb3069b0e04-52edef1e073mr2206699e87.23.1721154407985; Tue, 16 Jul 2024 11:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154407; cv=none; d=google.com; s=arc-20160816; b=LQs5SPUMoi1pw74WHpM9ROfTMjl1KbvJ/lxksVMNp+Q+Py0qcSxN74IDYpIXAyUjee 6vn5QUgN7j7WKzHSnQRCoHTqMvJ9qQ7v+GyJbPKGqxbA4i6RH8YdCPLVYN3D9HQKzjxc Ufl9ayNlrL3nh4BJ4TFm843IK5Ah/6VOQcw6Dl4Y+0dzwWDmRRpxvGFKxf+RxmbXTv9y YpIVN9RlsqTYNEVrEY8ZfQzifw+mr717VzogiD3x9Nvu1bkL4pQtFLdNnuT3o1ZZZV7E I+IUGoY9E33IBPrsVa0HNu94zXyVfvvOMdjFlBPwEpStx9o4Mgy9OHQrDu+BqioVYZWx fqdQ== 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=+QGcLY/qUBXRI7Qu960TBZ2/4Hmnw5fIeDD00HuC0YI=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=w895R5XSsrV0V0kAhcSX2npbw4d8ex+zoXuLIsIMQy1dE5wP/f3u7EBVSyYXenaJUx Mk0/nII41SDF/atlp6qKFwclr+FPpvdb5iiUjk60Y0cbzINkkR8pd09UrLSH/NyLvLFg xxUNPaf1Cz7Nrro36wCUtCHMz67a/Bfe/9pFZVMXi/siei0Si9al05RzKPW5KD6m1YJN uuSUGeL6SS3o08cnw26uijDJMYm/WhXgUsZ/EKox7beC9IhTCc64MDpbkN9N2AfUdVT/ erKdEUsJKQ9h2F7bVV94e0jnSbwpdfYqRIz3wf7JvjdJLmRKbFQkRHkfO5LuYJDmI+C6 Wwqw==; 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=Oq8+jZFW; 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-52ed255aea9si2226655e87.234.2024.07.16.11.26.47; Tue, 16 Jul 2024 11:26:47 -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=Oq8+jZFW; 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 2DA3268DC0E; Tue, 16 Jul 2024 21:14:38 +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 2A2EF68DACD for ; Tue, 16 Jul 2024 21:14:04 +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=Oq8+jZFW; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 025BD4E29 for ; Tue, 16 Jul 2024 19:24:20 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id w3LHWluH2cpn for ; Tue, 16 Jul 2024 19:24:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150659; bh=36+7gYRJo2/sMHXuXzDjMZHeB9MYGG2weLwxinaUQzo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Oq8+jZFW0nI1w9WqG9zKDzSA3A9JexofHe/rOi88vEYzJrNJ3M8q2X5zQ2xOwPcCq 9oWjJvcUA7W0NtJv6kRO2YUEmlEYSwqYj8bFCk+/5aQ4Hmd1JvvEASNOVYFbPDzbm1 Co4Vv9kuYUz9lOd57Poz/IBS+O+xHsM3PSCWOytLdFjm9yRXaAf+XLEq3yuAMoYMtA YEyMH0N0sJrI9gUc1VFp9FnKQpyUpvQfjdzj9dmOb8AhS3FdO9NCO5Q7b5x/sPgFEH WMut0i6oicyw5usJ+I89MpLRPp7ZahwQsaHB9snpeQQqTUk6us7akOwaT70LHzQcU3 x+mWt3a58cM8Q== 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 381B24E23 for ; Tue, 16 Jul 2024 19:24:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 845E93A2E91 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:44 +0200 Message-ID: <20240716171155.31838-29-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 29/39] lavc/thread: move generic-layer API to avcodec_internal.h 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: MFI8xYsPNiIl thread.h currently contains both API for decoder use and functions internal to lavc generic layer. Move the latter to avcodec_internal.h, which is a more appropriate place for them. --- libavcodec/avcodec_internal.h | 24 ++++++++++++++++++++++++ libavcodec/pthread.c | 1 + libavcodec/thread.h | 25 +------------------------ libavcodec/utils.c | 8 -------- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index 0a024378ae..816f39ae76 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -72,4 +72,28 @@ struct AVCodecInternal *ff_encode_internal_alloc(void); void ff_codec_close(struct AVCodecContext *avctx); +int ff_thread_init(struct AVCodecContext *s); +void ff_thread_free(struct AVCodecContext *s); + +/** + * Wait for decoding threads to finish and reset internal state. + * Called by avcodec_flush_buffers(). + * + * @param avctx The context. + */ +void ff_thread_flush(struct AVCodecContext *avctx); + +/** + * Submit a new frame to a decoding thread. + * Returns the next available frame in picture. *got_picture_ptr + * will be 0 if none is available. + * The return value on success is the size of the consumed packet for + * compatibility with FFCodec.decode. This means the decoder + * has to consume the full packet. + * + * Parameters are the same as FFCodec.decode. + */ +int ff_thread_decode_frame(struct AVCodecContext *avctx, struct AVFrame *frame, + int *got_picture_ptr, struct AVPacket *avpkt); + #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index ca84b81391..d32e56de0d 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -32,6 +32,7 @@ #include "libavutil/thread.h" #include "avcodec.h" +#include "avcodec_internal.h" #include "codec_internal.h" #include "pthread_internal.h" #include "thread.h" diff --git a/libavcodec/thread.h b/libavcodec/thread.h index 5ab12848b4..47c00a0ed2 100644 --- a/libavcodec/thread.h +++ b/libavcodec/thread.h @@ -20,7 +20,7 @@ /** * @file - * Multithreading support functions + * Multithreading API for decoders * @author Alexander Strange */ @@ -31,27 +31,6 @@ #include "avcodec.h" -/** - * Wait for decoding threads to finish and reset internal state. - * Called by avcodec_flush_buffers(). - * - * @param avctx The context. - */ -void ff_thread_flush(AVCodecContext *avctx); - -/** - * Submit a new frame to a decoding thread. - * Returns the next available frame in picture. *got_picture_ptr - * will be 0 if none is available. - * The return value on success is the size of the consumed packet for - * compatibility with FFCodec.decode. This means the decoder - * has to consume the full packet. - * - * Parameters are the same as FFCodec.decode. - */ -int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, - int *got_picture_ptr, AVPacket *avpkt); - int ff_thread_can_start_frame(AVCodecContext *avctx); /** @@ -74,11 +53,9 @@ void ff_thread_finish_setup(AVCodecContext *avctx); */ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags); -int ff_thread_init(AVCodecContext *s); int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx, int (*action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr), int (*main_func)(AVCodecContext *c), void *arg, int *ret, int job_count); -void ff_thread_free(AVCodecContext *s); int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count); int ff_slice_thread_init_progress(AVCodecContext *avctx); void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n); diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 337c00e789..b17fc3c7e2 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -806,14 +806,6 @@ int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes) return FFMAX(0, duration); } -#if !HAVE_THREADS -int ff_thread_init(AVCodecContext *s) -{ - return -1; -} - -#endif - unsigned int av_xiphlacing(unsigned char *s, unsigned int v) { unsigned int n = 0; From patchwork Tue Jul 16 17:11:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50592 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp470142vqb; Tue, 16 Jul 2024 11:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVdPPJksMDilgKwUTo5gu/xY4Kh/g5Di9gXc7v5KYQsPHtIzLRHgZmLA5wcpImva7RBeFQO7taYtpyZyrP9wEXGS0UFuEGeXd7XTQ== X-Google-Smtp-Source: AGHT+IHWkVq9WKoeXCXgRm2ETnjP80SGHYOWiUDt0AZn+FLh1wnaPmXOH2VmPrEd8UuBsexJe5NI X-Received: by 2002:a2e:92cb:0:b0:2ec:4deb:482f with SMTP id 38308e7fff4ca-2eef56c6302mr8740451fa.8.1721154111877; Tue, 16 Jul 2024 11:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154111; cv=none; d=google.com; s=arc-20160816; b=RJN2jZptcwyLST2gsoBMvmyQPTPJxg0P4qmKFpMMvLDwXC5YLI660Hhk8Xl8N9eqGy 9Cm9b0bdyt6RubdLnfPg10OpsPg1FUcYz2Ko1NEUalZMFYy1FXzVg29/s2zr6GAJ0JE1 dHZh/4E7PcAbVElX8G1j4OmJXVyg0DAKQYWTxFcX+HBEBf5rRZxlEzc4q4GHD0A8s3Rs rGIUwfKTmZs+06HSe1reqynFrL2zrAKseM/FYfstgPCWoxHGHgZKD5fYvGmOKomt/9pE OybCkL7iZATazk58k0tPsHsylOypKN81RXtoigKd81vWAcI7/PLmjzwaCPEvRWT5LvnO SjaA== 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=TPw7v9wXHMtL3RoCkj8tlVw24ClFQtFt5WZCWbNf72g=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=FitvP0lgJGbeH5Z8oCwh/amL7WtjBB46jTJp3SdQUIzOXu5BOdF1nG17Qjjhdtd+YB Ay50FlJrMUoRDNAol3tE3c2pqhM894+RT8h9CK8P0Luv6DC8DoXfamTYGCMGDVxrbmva gbPQfv2U/APesu9atPqvBJhRzc01cgdKzy8SXimhn2TH63Jfq2fh5YL2RO513iBx/rek W/IK+UJ9k/uQqIlYBZawDQGlmQZbCiklk07xAIxcKRkQxeiWI2VXBYcV2Xkur8Dc+jLn YfdBSJBBC52hUAk3JIm+49wojc6Ry4aprKAWQfUM9TaknNgkW8U80cO1SSRhiI1EG61j g2rw==; 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=P++5IPOD; 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 38308e7fff4ca-2eee179ce43si20056721fa.38.2024.07.16.11.21.51; Tue, 16 Jul 2024 11:21:51 -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=P++5IPOD; 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 1557C68D504; Tue, 16 Jul 2024 21:14:22 +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 8503E68DA6E for ; Tue, 16 Jul 2024 21:14:04 +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=P++5IPOD; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 28B994E08 for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 3pGJaxPViwmv for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=9eQCjMMRjJ96MuKQP3MZfPaUaH8SscxNArllW77p49A=; h=From:To:Subject:Date:In-Reply-To:References:From; b=P++5IPODK8ICT6pAk2h2jtNECMoy8uFM78e11bS30uNej9c3dP/AnsajpOXVkit2s xkTxIzgI6g7MAdlGn4XGfGo90sEvXHN7QXnKTXfuyDL9CGDXT6ZXnz4WQeyI1CI9VK G21Wb5BeLOMJI3sloHI+fZhnxCJnzRgskn6QHE/OQDxqoMQS1uvTI/xK49ZP+MCE6e NvxZgbDbKXDh1wyKANPeEgL8Uncmtvd7Iqd2htSijAaToGnNNuELCess4rU75+FwMw uJwidNJbJU7i7WgD/O/aBh52awxrLlvouMcso/BAgh+gQ7RZV213joIN8pwUcfj08t 2A0OnYX7xcLIg== 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 BFCFA4E0B for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8FEB43A2E98 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:45 +0200 Message-ID: <20240716171155.31838-30-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 30/39] lavc/internal: document the precise meaning of AVCodecInternal.draining 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: OFVr96t+p66i Also, set draining=1 in case a bitstream filter returns an internally-triggered EOF. While no bitstream filters currently inserted by decoders will do that, that may change in the future and it is better to cover this case. --- libavcodec/decode.c | 12 +++++------- libavcodec/internal.h | 6 +++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 791940648d..6ad74bd94b 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -213,8 +213,6 @@ static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) int ret; ret = av_bsf_receive_packet(avci->bsf, pkt); - if (ret == AVERROR_EOF) - avci->draining = 1; if (ret < 0) return ret; @@ -247,14 +245,14 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) if (ret == AVERROR(EAGAIN) && (!AVPACKET_IS_EMPTY(avci->buffer_pkt) || dc->draining_started)) { ret = av_bsf_send_packet(avci->bsf, avci->buffer_pkt); - if (ret < 0) { - av_packet_unref(avci->buffer_pkt); - return ret; - } + if (ret >= 0) + continue; - continue; + av_packet_unref(avci->buffer_pkt); } + if (ret == AVERROR_EOF) + avci->draining = 1; return ret; } } diff --git a/libavcodec/internal.h b/libavcodec/internal.h index bc20a797ae..d7b0b9f880 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -123,7 +123,11 @@ typedef struct AVCodecInternal { void *hwaccel_priv_data; /** - * checks API usage: after codec draining, flush is required to resume operation + * decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must + * not be used by decoders that use the decode() callback, as they + * do not call ff_decode_get_packet() directly. + * + * encoding: a flush frame has been submitted to avcodec_send_frame(). */ int draining; From patchwork Tue Jul 16 17:11:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50577 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp449929vqb; Tue, 16 Jul 2024 10:41:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXyziK+L2ODBQVq7KlzT5AX9pfxVNI2lEskRdcd9hlr2jYa7boLKJs2eoCWZrokoDohOEtS9VeCXSCF00CceEg6Rsg8uRX+DJeeug== X-Google-Smtp-Source: AGHT+IHN8C/zLoKp0RVUfAxL5CPskBezq54doX6B5jCbcilkMtAdcM+5TMKi4ggw2DAw5cXD5E7q X-Received: by 2002:a05:6512:1289:b0:52c:8339:d09b with SMTP id 2adb3069b0e04-52edef0eb19mr1919364e87.1.1721151708452; Tue, 16 Jul 2024 10:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721151708; cv=none; d=google.com; s=arc-20160816; b=nfiloJdcOPZvqdsz4GOI0Ak9a2Dj3Uca0afwOYWXJlnw9sxkp38PhRB0ileDB8258t At1oZ26Krst+s/jQqN4HJnt86KwvlEojT96mcFh8Gp58NWK3LroyQqtm+nPHtRj+uczH qt+DA/q8RKEtOlfchv1r/R1LFu6HVh+QWMmknC+UBmOSO+NUgj7bbv8o4MDLJ7BkcZgl 0SyMJqHrrNDVEKN0tUg/z80WWad+wTPziShUqJdinOqMIVbT3XBsF9JgVSE5tOAs5QnB 9AtkUylHIT7slHbp9871nhkUWEhzQDu1ab/rCjmgE/SExnWFvAnmGtf+oFf629c+BFMt 4n4Q== 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=oNXkj8h9S80N0HyZGwVgeFUqsGJgyBhGmR4BCMb+p5Y=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=kDrUss/tfyKq/0yWQBudAhskENVFGMPmFJcUPgnBjP75Ie85DUoYEfujYrFovN+qGA K6FFR3AgBwz0B9BlEUnzmjcwzMnuhhzfdzM37QC8HWPBf8Qlf0yNInC5XH+GO1XEewfU Uon6Wex1snyzAoJDIZ7QIFR72wLqA2GV82tMST9wotiNY+s6S8/j0ZMB62hkNN303fzy sJdNXHrDEENvNZFcBtxoY9HEdCEAMXaViRnz8J9lzc51Xu/JdGSk97altycPuE8i7hKL bSzCUymTFxp+Tw89/1E31q1DQunE9kyxgmzLkA2Xf9roxcMVJYDiSq6n5A158k1g176Q pn/A==; 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=LcnVBgQ8; 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-52ed258264esi2268627e87.644.2024.07.16.10.41.47; Tue, 16 Jul 2024 10:41:48 -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=LcnVBgQ8; 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 2448668DB02; Tue, 16 Jul 2024 20:16:51 +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 4A4D668DA96 for ; Tue, 16 Jul 2024 20:16:37 +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=LcnVBgQ8; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 05B164DF2 for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 7hnKQqxbjb0G for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=u2WMofUF/vO7G9Q+2OQ1yIgBP+zIljGfDuyS4joWr9c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LcnVBgQ8PNS9NMKFYvTiS2GGWok9tjQYpCtcF9hS4nGdy0lJT78p+34gx5cJVqgT+ 0UsmabhWypI1CsGiiHK9yRCi9n02Ue2etJEa7A9kn9rDbIj3DGuEuAMLDKAYr/Ev0s c1YLsth+rpdKHHhOUpQ5l6xfuPsLR3mBDiNKgpC+363QZpqXqgXk0YN68MGK6gPQGY KyngQTgW5PBBsysyi3jF318s4nRYBzlKwQjKsVctA1NhPJFH7jcVsn8OHsGyG6u6LV 7boa4rcUFutDJFT4wo54GrbAhfNqoKcW485UuKNzrNzf6cHMRRVTFgbhpJDGcDm1jN cy8UeLWNyC7Ew== 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 6B8FA4E04 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9C06D3A2F2B for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:46 +0200 Message-ID: <20240716171155.31838-31-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 31/39] lavc/decode: wrap AV_FRAME_FLAG_DISCARD handling in a loop 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: jN6jiCCZpmeH Makes sure discarded frames do not cause EAGAIN to be returned during flushing, which is forbidden. --- libavcodec/decode.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 6ad74bd94b..b17cfba26f 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -613,17 +613,22 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) av_assert0(!frame->buf[0]); if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { + while (1) { frame->pict_type = dc->initial_pict_type; frame->flags |= dc->intra_only_flag; ret = codec->cb.receive_frame(avctx, frame); emms_c(); if (!ret) { - if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) - ret = (frame->flags & AV_FRAME_FLAG_DISCARD) ? AVERROR(EAGAIN) : 0; - else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { + if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { int64_t discarded_samples = 0; ret = discard_samples(avctx, frame, &discarded_samples); } + if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) { + av_frame_unref(frame); + continue; + } + } + break; } } else ret = decode_simple_receive_frame(avctx, frame); From patchwork Tue Jul 16 17:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50603 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp478700vqb; Tue, 16 Jul 2024 11:41:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVZvvx7JUGHwFaQO/NDOoAr1wTsAQLUkrVWsh3OpMC4UEqkkVQL/93MQfIP4nZtZykLLzvzyVNLcqJzcK75/YP+BvDlZmFFH4Oo1A== X-Google-Smtp-Source: AGHT+IEDT9M4b3xIeX6j4Tl1uz8/R47uLR+ESPrVREtg1E5YAeplNfLX3HsKlqZesh/G3Uf2JDfh X-Received: by 2002:a05:6402:1912:b0:582:774c:a6b6 with SMTP id 4fb4d7f45d1cf-59eee05521cmr2333354a12.4.1721155316348; Tue, 16 Jul 2024 11:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721155316; cv=none; d=google.com; s=arc-20160816; b=emuCloxZNUqERDii4O37SZBdAONibCFG1LCwEYO7m5L0mA3whvRK/helVIsRcJ4Z1c 5s+NgJEGRZAixdgLSnCWmY67FEQz0dKyYLu6syQmHkRnApfMOzr0/vhuQTgvzN5UJZdg Y8bNuqKHFcWot0HX1Ico2iwve6/jUp5nYDOjJOZOpS2ciJd6bfvDXVm7rAdvGo8Ncctz kXQ3WYsSmNQeHxr8H22S0Y0G4N39a1PFmpEPmqG6+dfI0STMEPyJf5ay0BdXqov1d984 zVjPSsx+MUQvIrLENP/MT+nJaTYvbZDJJHFMuFl2waFJV02SkgQpDKysqybeiuCdNFar Nf0A== 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=PZlxR+mKjPbaDf6E2/60ah695Xlu0WYlYAw8fTpJCZ0=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=HrkLlivr6UP6QA9GTGBHlDIzJc/frNDZ8HqktSQs1ayP8CLa4f2Sdti94YhhmSF7r2 VWhJ4FgocKLKnEKBWp+b4SqRuj4mRrwpayJqi3Hbi/8qvLHsol/jEWQYYoysbY1ryGp5 4swr3GDlccTzhFEZD3o+oWGnV1JjjE7+zd4MOISTIH+yoNAp5ukze+GjyY/Mn29JBJdu dD3yggnrL8cUH5zeF9mQZLgb0vHQ0oj64pWUShVDm0c7hM88uHO05AYAQpYiYDLCSVvV kTdP8AN/J41F8dm+QYePxLunmEaK8ifGkr8ab4AtW/yTnQ6yugDWJs6snEd4p0pnYICy 5KAg==; 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=fmCO6BZU; 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 4fb4d7f45d1cf-59b24a6c825si4222399a12.70.2024.07.16.11.41.55; Tue, 16 Jul 2024 11:41:56 -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=fmCO6BZU; 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 4093568DB60; Tue, 16 Jul 2024 21:14:27 +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 B4DEB68D8D0 for ; Tue, 16 Jul 2024 21:14:04 +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=fmCO6BZU; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 060A64E2B for ; Tue, 16 Jul 2024 19:24:20 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 5hwGk0pS0u3f for ; Tue, 16 Jul 2024 19:24:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150659; bh=1PoTdoaSKlxqFW/fFLQIizduy4qpxKJ7LD5ExxWb5sk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fmCO6BZUAaYusQSiWXccja+A4BvbRfap1FTcknf00DmkewqDjmBk2JTRndwqwkr8m c0qh1BCkpIvAZx65pZRKNcBVvDMaq4Pynlk8xyyDeZm9o8YRTEyZWbOBL+0cDEPmOK THYqteiz85L0dhaehRCReWbBZvGf73SE3JqM1N3D5pMcE+N+ozuw8eduqQ/9aw0Q9x K0BOKBi6rVpzL0oFoZ0LNsgpfVObUoQ5XAW0UEnpuaSJkrfQ8zTB4VoCGLuaH4Yp8W vaO7r2DgmcmiHxEiGttlosiS9j2cvA602fD6M6Z/Pk1Wy1qmn9FbBDMwutenjGBwj+ DjisTJxnFNMOQ== 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 35B7C4DF4 for ; Tue, 16 Jul 2024 19:24:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A79503A2F6A for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:47 +0200 Message-ID: <20240716171155.31838-32-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 32/39] lavc/decode: reindent 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: MP5AeQlAU6pJ --- libavcodec/decode.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index b17cfba26f..42cee77ec5 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -614,21 +614,21 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) { while (1) { - frame->pict_type = dc->initial_pict_type; - frame->flags |= dc->intra_only_flag; - ret = codec->cb.receive_frame(avctx, frame); - emms_c(); - if (!ret) { - if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { - int64_t discarded_samples = 0; - ret = discard_samples(avctx, frame, &discarded_samples); + frame->pict_type = dc->initial_pict_type; + frame->flags |= dc->intra_only_flag; + ret = codec->cb.receive_frame(avctx, frame); + emms_c(); + if (!ret) { + if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { + int64_t discarded_samples = 0; + ret = discard_samples(avctx, frame, &discarded_samples); + } + if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) { + av_frame_unref(frame); + continue; + } } - if (ret == AVERROR(EAGAIN) || (frame->flags & AV_FRAME_FLAG_DISCARD)) { - av_frame_unref(frame); - continue; - } - } - break; + break; } } else ret = decode_simple_receive_frame(avctx, frame); From patchwork Tue Jul 16 17:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50585 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp467027vqb; Tue, 16 Jul 2024 11:15:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXrG17dEtryndj3isA4Ni7Q94EaEwc067n7OO9pQFYNVOoODikpe7hHob1HFnpMhWhr3AiKR5rQ9a0i6OSSXlhJ6HuFG3tqDpJwYw== X-Google-Smtp-Source: AGHT+IGNsLw+RRjrtLrRQNakWQHMtxRli3y6CPVrv31F8hSpkeZzBUicsevKbrhEISK340+EmWLl X-Received: by 2002:a05:651c:50d:b0:2ee:bd1b:84c with SMTP id 38308e7fff4ca-2eef40b2fbfmr22534681fa.0.1721153719372; Tue, 16 Jul 2024 11:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153719; cv=none; d=google.com; s=arc-20160816; b=lv1q56p4ebFABR7GK27sz1Q3f706jmCayur6vDx1AZMzstxf6tH+miPdEzLU9f1x+d 46IioVD4++nZ2dhVI24szldCDbm1H/M89DG29jvsKp5sQtY3C7Eo8Ka8eCF2O2trEzmo /o7hLC7RaRm213uy5h9C4mBwYAZIrx0kpAv8oPW/ze/1l0PBz0BF1Yo3ATtslPS0wWCy hFYILMbzVaUE7NE9u02infqkPVxaqgx1OYe4qVGvdLhT4qOt6zslKg624MpyuEaYE/GM m0pKfq1rk6O0jsGXzScisI4C3eldpEHQqKs2o8ZQ2ykmrAun2c1puiKkkjarerVQrbIm +9ww== 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=GLaZRDKOVX1AJatoqWcio91aWp8Ds1vqHB6OdEHx3/g=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=QkXN3wPtAhvsD7X36eJku2wmF9ANZ/p7P3uCzV8SLOjGGNzAJ8XoeSNsbjT9niiZbr 6f5kKOMRBicEdcmUttvSPzMp4Z2cmiEXcMGMKSf4RjiPTRNkbZwrUZ3dWfdUata6zxvJ jaKa9bioVnARe3m1ugHAHz23cM1e/U9KpcpuBP/YRnd9RXF155YxDvBg/19FeOFeyiC6 o5hWnT4u+sMqH6fIhrcTwc6MB6cw6BQFFazpik0mZW6f1X7cnwEh+IeIdBIZwJEdhY5e xuQHck3IduLsO8be7NgA6h+RJEq3i3hRvBqTMaJv1y7cDe8KpkZ+mxM/G4V/q1WibWJI GjOA==; 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=Gn4u7Jh7; 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 38308e7fff4ca-2eee190c7dbsi19906261fa.270.2024.07.16.11.15.18; Tue, 16 Jul 2024 11:15:19 -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=Gn4u7Jh7; 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 030BE68DB1E; Tue, 16 Jul 2024 21:14:19 +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 8550268DA94 for ; Tue, 16 Jul 2024 21:14:04 +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=Gn4u7Jh7; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 25FFD4DE7 for ; Tue, 16 Jul 2024 19:16:38 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 0iki0CGVrDgf for ; Tue, 16 Jul 2024 19:16:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150190; bh=UsoRssAsgdAuUu/sM46/yZFYKrERQy60/ULdHKAH9lE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Gn4u7Jh77gWnG4813j4t7Mdcn+w/mWtnI/m0B8WuyEm4yClpbnBM4Xd7o4zJQO3n3 vdUQ1zXve9nCKaHawEc5iI1wfgh5Vb6ATRq+u6mFH7pseZBr996ICJ6ffp81CoO2B6 vZOm1m8FKn4gDJiHsZ/BQWFN4yoV5zsg865oJEp5SBPWTp3iINMNwPUddCGkMQlLFL OgCAGbHpZrhTvozqkWCsnIVrHN1GH3mcsXPbiqSqw5jmkqs3d6ReFG0KLQ7gketHHH Nqxei++trND8j1QW06XsFmu2o1jN/KNOxUwsTSAD/cI0/QrcB1QndENXx2CkZKIDi/ mmznWPoE8nSng== 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 6B6E94DEE for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B387C3A2FF2 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:48 +0200 Message-ID: <20240716171155.31838-33-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 33/39] lavc: convert frame threading to the receive_frame() pattern 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: LTqATXgf6z3m Reorganize the code such that the frame threading code does not call the decoders directly, but instead calls back into the generic decoding code. This avoids duplicating the logic that wraps the decoder invocation and allows receive_frame()-based decoders to use frame threading. Further work by Timo Rothenpieler . --- libavcodec/avcodec.c | 9 +- libavcodec/avcodec_internal.h | 25 +-- libavcodec/decode.c | 40 +++-- libavcodec/internal.h | 7 + libavcodec/pthread_frame.c | 278 +++++++++++++++++++++------------- 5 files changed, 235 insertions(+), 124 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 214dca4566..6065f1b689 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -381,10 +381,13 @@ void avcodec_flush_buffers(AVCodecContext *avctx) avci->draining = 0; avci->draining_done = 0; - av_frame_unref(avci->buffer_frame); - av_packet_unref(avci->buffer_pkt); + if (avci->buffer_frame) + av_frame_unref(avci->buffer_frame); + if (avci->buffer_pkt) + av_packet_unref(avci->buffer_pkt); - if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) + if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME && + !avci->is_frame_mt) ff_thread_flush(avctx); else if (ffcodec(avctx->codec)->flush) ffcodec(avctx->codec)->flush(avctx); diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index 816f39ae76..2f0aaab93b 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -84,16 +84,23 @@ void ff_thread_free(struct AVCodecContext *s); void ff_thread_flush(struct AVCodecContext *avctx); /** - * Submit a new frame to a decoding thread. - * Returns the next available frame in picture. *got_picture_ptr - * will be 0 if none is available. - * The return value on success is the size of the consumed packet for - * compatibility with FFCodec.decode. This means the decoder - * has to consume the full packet. + * Submit available packets for decoding to worker threads, return a + * decoded frame if available. Returns AVERROR(EAGAIN) if none is available. * - * Parameters are the same as FFCodec.decode. + * Parameters are the same as FFCodec.receive_frame. */ -int ff_thread_decode_frame(struct AVCodecContext *avctx, struct AVFrame *frame, - int *got_picture_ptr, struct AVPacket *avpkt); +int ff_thread_receive_frame(AVCodecContext *avctx, AVFrame *frame); + +/** + * Do the actual decoding and obtain a decoded frame from the decoder, if + * available. When frame threading is used, this is invoked by the worker + * threads, otherwise by the top layer directly. + */ +int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame); + +/** + * Get a packet for decoding. This gets invoked by the worker threads. + */ +int ff_thread_get_packet(AVCodecContext *avctx, AVPacket *pkt); #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 42cee77ec5..dd94280f0b 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -207,6 +207,11 @@ fail: return ret; } +#if !HAVE_THREADS +#define ff_thread_get_packet(avctx, pkt) (AVERROR_BUG) +#define ff_thread_receive_frame(avctx, frame) (AVERROR_BUG) +#endif + static int decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) { AVCodecInternal *avci = avctx->internal; @@ -240,6 +245,13 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) if (avci->draining) return AVERROR_EOF; + /* If we are a worker thread, get the next packet from the threading + * context. Otherwise we are the main (user-facing) context, so we get the + * next packet from the input filterchain. + */ + if (avctx->internal->is_frame_mt) + return ff_thread_get_packet(avctx, pkt); + while (1) { int ret = decode_get_packet(avctx, pkt); if (ret == AVERROR(EAGAIN) && @@ -413,15 +425,11 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, return AVERROR_EOF; if (!pkt->data && - !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY || - avctx->active_thread_type & FF_THREAD_FRAME)) + !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) return AVERROR_EOF; got_frame = 0; - if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) { - consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt); - } else { frame->pict_type = dc->initial_pict_type; frame->flags |= dc->intra_only_flag; consumed = codec->cb.decode(avctx, frame, &got_frame, pkt); @@ -436,7 +444,6 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif } - } emms_c(); if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { @@ -603,12 +610,12 @@ static int decode_simple_receive_frame(AVCodecContext *avctx, AVFrame *frame) return 0; } -static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) +int ff_decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) { AVCodecInternal *avci = avctx->internal; DecodeContext *dc = decode_ctx(avci); const FFCodec *const codec = ffcodec(avctx->codec); - int ret, ok; + int ret; av_assert0(!frame->buf[0]); @@ -636,6 +643,20 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (ret == AVERROR_EOF) avci->draining_done = 1; + return ret; +} + +static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) +{ + AVCodecInternal *avci = avctx->internal; + DecodeContext *dc = decode_ctx(avci); + int ret, ok; + + if (avctx->active_thread_type & FF_THREAD_FRAME) + ret = ff_thread_receive_frame(avctx, frame); + else + ret = ff_decode_receive_frame_internal(avctx, frame); + /* preserve ret */ ok = detect_colorspace(avctx, frame); if (ok < 0) { @@ -2151,7 +2172,8 @@ void ff_decode_flush_buffers(AVCodecContext *avctx) dc->pts_correction_last_pts = dc->pts_correction_last_dts = INT64_MIN; - av_bsf_flush(avci->bsf); + if (avci->bsf) + av_bsf_flush(avci->bsf); dc->nb_draining_errors = 0; dc->draining_started = 0; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index d7b0b9f880..98ab2797ce 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -53,6 +53,13 @@ typedef struct AVCodecInternal { */ int is_copy; + /** + * This field is set to 1 when frame threading is being used and the parent + * AVCodecContext of this AVCodecInternal is a worker-thread context (i.e. + * one of those actually doing the decoding), 0 otherwise. + */ + int is_frame_mt; + /** * Audio encoders can set this flag during init to indicate that they * want the small last frame to be padded to a multiple of pad_samples. diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 85a3dce929..019e33b7b2 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -32,6 +32,7 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "internal.h" +#include "packet_internal.h" #include "pthread_internal.h" #include "refstruct.h" #include "thread.h" @@ -64,6 +65,12 @@ enum { INITIALIZED, ///< Thread has been properly set up }; +typedef struct DecodedFrames { + AVFrame **f; + size_t nb_f; + size_t nb_f_allocated; +} DecodedFrames; + typedef struct ThreadFrameProgress { atomic_int progress[2]; } ThreadFrameProgress; @@ -88,8 +95,10 @@ typedef struct PerThreadContext { AVPacket *avpkt; ///< Input packet (for decoding) or output (for encoding). - AVFrame *frame; ///< Output frame (for decoding) or input (for encoding). - int got_frame; ///< The output of got_picture_ptr from the last avcodec_decode_video() call. + /** + * Decoded frames from a single decode iteration. + */ + DecodedFrames df; int result; ///< The result of the last codec decode/encode() call. atomic_int state; @@ -130,14 +139,17 @@ typedef struct FrameThreadContext { pthread_cond_t async_cond; int async_lock; + DecodedFrames df; + int result; + + /** + * Packet to be submitted to the next thread for decoding. + */ + AVPacket *next_pkt; + int next_decoding; ///< The next context to submit a packet to. int next_finished; ///< The next context to return output from. - int delaying; /**< - * Set for the first N packets, where N is the number of threads. - * While it is set, ff_thread_en/decode_frame won't return any results. - */ - /* hwaccel state for thread-unsafe hwaccels is temporarily stored here in * order to transfer its ownership to the next decoding thread without the * need for extra synchronization */ @@ -180,6 +192,52 @@ static void thread_set_name(PerThreadContext *p) ff_thread_setname(name); } +// get a free frame to decode into +static AVFrame *decoded_frames_get_free(DecodedFrames *df) +{ + if (df->nb_f == df->nb_f_allocated) { + AVFrame **tmp = av_realloc_array(df->f, df->nb_f + 1, + sizeof(*df->f)); + if (!tmp) + return NULL; + df->f = tmp; + + df->f[df->nb_f] = av_frame_alloc(); + if (!df->f[df->nb_f]) + return NULL; + + df->nb_f_allocated++; + } + + av_assert0(!df->f[df->nb_f]->buf[0]); + + return df->f[df->nb_f]; +} + +static void decoded_frames_pop(DecodedFrames *df, AVFrame *dst) +{ + AVFrame *tmp_frame = df->f[0]; + av_frame_move_ref(dst, tmp_frame); + memmove(df->f, df->f + 1, (df->nb_f - 1) * sizeof(*df->f)); + df->f[--df->nb_f] = tmp_frame; +} + +static void decoded_frames_flush(DecodedFrames *df) +{ + for (size_t i = 0; i < df->nb_f; i++) + av_frame_unref(df->f[i]); + df->nb_f = 0; +} + +static void decoded_frames_free(DecodedFrames *df) +{ + for (size_t i = 0; i < df->nb_f_allocated; i++) + av_frame_free(&df->f[i]); + av_freep(&df->f); + df->nb_f = 0; + df->nb_f_allocated = 0; +} + /** * Codec worker thread. * @@ -197,6 +255,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg) pthread_mutex_lock(&p->mutex); while (1) { + int ret; + while (atomic_load(&p->state) == STATE_INPUT_READY && !p->die) pthread_cond_wait(&p->input_cond, &p->mutex); @@ -220,18 +280,31 @@ static attribute_align_arg void *frame_worker_thread(void *arg) p->hwaccel_serializing = 1; } - av_frame_unref(p->frame); - p->got_frame = 0; - p->frame->pict_type = p->initial_pict_type; - p->frame->flags |= p->intra_only_flag; - p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt); + ret = 0; + while (ret >= 0) { + AVFrame *frame; - if ((p->result < 0 || !p->got_frame) && p->frame->buf[0]) - av_frame_unref(p->frame); + /* get the frame which will store the output */ + frame = decoded_frames_get_free(&p->df); + if (!frame) { + p->result = AVERROR(ENOMEM); + goto alloc_fail; + } + + /* do the actual decoding */ + ret = ff_decode_receive_frame_internal(avctx, frame); + if (ret == 0) + p->df.nb_f++; + else if (ret < 0 && frame->buf[0]) + av_frame_unref(frame); + + p->result = (ret == AVERROR(EAGAIN)) ? 0 : ret; + } if (atomic_load(&p->state) == STATE_SETTING_UP) ff_thread_finish_setup(avctx); +alloc_fail: if (p->hwaccel_serializing) { /* wipe hwaccel state for thread-unsafe hwaccels to avoid stale * pointers lying around; @@ -426,18 +499,21 @@ static int update_context_from_user(AVCodecContext *dst, const AVCodecContext *s } static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, - AVPacket *avpkt) + AVPacket *in_pkt) { FrameThreadContext *fctx = p->parent; PerThreadContext *prev_thread = fctx->prev_thread; const AVCodec *codec = p->avctx->codec; int ret; - if (!avpkt->size && !(codec->capabilities & AV_CODEC_CAP_DELAY)) - return 0; - pthread_mutex_lock(&p->mutex); + av_packet_unref(p->avpkt); + av_packet_move_ref(p->avpkt, in_pkt); + + if (AVPACKET_IS_EMPTY(p->avpkt)) + p->avctx->internal->draining = 1; + ret = update_context_from_user(p->avctx, user_avctx); if (ret) { pthread_mutex_unlock(&p->mutex); @@ -448,7 +524,6 @@ static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, memory_order_relaxed); if (prev_thread) { - int err; if (atomic_load(&prev_thread->state) == STATE_SETTING_UP) { pthread_mutex_lock(&prev_thread->progress_mutex); while (atomic_load(&prev_thread->state) == STATE_SETTING_UP) @@ -456,10 +531,16 @@ static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, pthread_mutex_unlock(&prev_thread->progress_mutex); } - err = update_context_from_thread(p->avctx, prev_thread->avctx, 0); - if (err) { - pthread_mutex_unlock(&p->mutex); - return err; + /* codecs without delay might not be prepared to be called repeatedly here during + * flushing (vp3/theora), and also don't need to be, since from this point on, they + * will always return EOF anyway */ + if (!p->avctx->internal->draining || + (codec->capabilities & AV_CODEC_CAP_DELAY)) { + ret = update_context_from_thread(p->avctx, prev_thread->avctx, 0); + if (ret) { + pthread_mutex_unlock(&p->mutex); + return ret; + } } } @@ -471,70 +552,47 @@ static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, FFSWAP(void*, p->avctx->internal->hwaccel_priv_data, fctx->stash_hwaccel_priv); } - av_packet_unref(p->avpkt); - ret = av_packet_ref(p->avpkt, avpkt); - if (ret < 0) { - pthread_mutex_unlock(&p->mutex); - av_log(p->avctx, AV_LOG_ERROR, "av_packet_ref() failed in submit_packet()\n"); - return ret; - } - atomic_store(&p->state, STATE_SETTING_UP); pthread_cond_signal(&p->input_cond); pthread_mutex_unlock(&p->mutex); fctx->prev_thread = p; - fctx->next_decoding++; + fctx->next_decoding = (fctx->next_decoding + 1) % p->avctx->thread_count; return 0; } -int ff_thread_decode_frame(AVCodecContext *avctx, - AVFrame *picture, int *got_picture_ptr, - AVPacket *avpkt) +int ff_thread_receive_frame(AVCodecContext *avctx, AVFrame *frame) { FrameThreadContext *fctx = avctx->internal->thread_ctx; - int finished = fctx->next_finished; - PerThreadContext *p; - int err; + int ret = 0; /* release the async lock, permitting blocked hwaccel threads to * go forward while we are in this function */ async_unlock(fctx); - /* - * Submit a packet to the next decoding thread. - */ + /* submit packets to threads while there are no buffered results to return */ + while (!fctx->df.nb_f && !fctx->result) { + PerThreadContext *p; - p = &fctx->threads[fctx->next_decoding]; - err = submit_packet(p, avctx, avpkt); - if (err) - goto finish; - - /* - * If we're still receiving the initial packets, don't return a frame. - */ - - if (fctx->next_decoding > (avctx->thread_count-1-(avctx->codec_id == AV_CODEC_ID_FFV1))) - fctx->delaying = 0; - - if (fctx->delaying) { - *got_picture_ptr=0; - if (avpkt->size) { - err = avpkt->size; + /* get a packet to be submitted to the next thread */ + av_packet_unref(fctx->next_pkt); + ret = ff_decode_get_packet(avctx, fctx->next_pkt); + if (ret < 0 && ret != AVERROR_EOF) goto finish; - } - } - /* - * Return the next available frame from the oldest thread. - * If we're at the end of the stream, then we have to skip threads that - * didn't output a frame/error, because we don't want to accidentally signal - * EOF (avpkt->size == 0 && *got_picture_ptr == 0 && err >= 0). - */ + ret = submit_packet(&fctx->threads[fctx->next_decoding], avctx, + fctx->next_pkt); + if (ret < 0) + goto finish; - do { - p = &fctx->threads[finished++]; + /* do not return any frames until all threads have something to do */ + if (fctx->next_decoding != fctx->next_finished && + !avctx->internal->draining) + continue; + + p = &fctx->threads[fctx->next_finished]; + fctx->next_finished = (fctx->next_finished + 1) % avctx->thread_count; if (atomic_load(&p->state) != STATE_INPUT_READY) { pthread_mutex_lock(&p->progress_mutex); @@ -543,35 +601,26 @@ int ff_thread_decode_frame(AVCodecContext *avctx, pthread_mutex_unlock(&p->progress_mutex); } - av_frame_move_ref(picture, p->frame); - *got_picture_ptr = p->got_frame; - picture->pkt_dts = p->avpkt->dts; - err = p->result; + update_context_from_thread(avctx, p->avctx, 1); + fctx->result = p->result; + p->result = 0; + if (p->df.nb_f) + FFSWAP(DecodedFrames, fctx->df, p->df); + } - /* - * A later call with avkpt->size == 0 may loop over all threads, - * including this one, searching for a frame/error to return before being - * stopped by the "finished != fctx->next_finished" condition. - * Make sure we don't mistakenly return the same frame/error again. - */ - p->got_frame = 0; - p->result = 0; + /* a thread may return multiple frames AND an error + * we first return all the frames, then the error */ + if (fctx->df.nb_f) { + decoded_frames_pop(&fctx->df, frame); + ret = 0; + } else { + ret = fctx->result; + fctx->result = 0; + } - if (finished >= avctx->thread_count) finished = 0; - } while (!avpkt->size && !*got_picture_ptr && err >= 0 && finished != fctx->next_finished); - - update_context_from_thread(avctx, p->avctx, 1); - - if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0; - - fctx->next_finished = finished; - - /* return the size of the consumed packet if no error occurred */ - if (err >= 0) - err = avpkt->size; finish: async_lock(fctx); - return err; + return ret; } void ff_thread_report_progress(ThreadFrame *f, int n, int field) @@ -679,7 +728,6 @@ static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count pthread_cond_wait(&p->output_cond, &p->progress_mutex); pthread_mutex_unlock(&p->progress_mutex); } - p->got_frame = 0; } async_lock(fctx); @@ -732,6 +780,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) } ff_refstruct_unref(&ctx->internal->pool); + av_packet_free(&ctx->internal->in_pkt); av_packet_free(&ctx->internal->last_pkt_props); av_freep(&ctx->internal); av_buffer_unref(&ctx->hw_frames_ctx); @@ -739,7 +788,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) &ctx->nb_decoded_side_data); } - av_frame_free(&p->frame); + decoded_frames_free(&p->df); ff_pthread_free(p, per_thread_offsets); av_packet_free(&p->avpkt); @@ -747,6 +796,9 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) av_freep(&p->avctx); } + decoded_frames_free(&fctx->df); + av_packet_free(&fctx->next_pkt); + av_freep(&fctx->threads); ff_pthread_free(fctx, thread_ctx_offsets); @@ -815,13 +867,17 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, if (err < 0) return err; - if (!(p->frame = av_frame_alloc()) || - !(p->avpkt = av_packet_alloc())) + if (!(p->avpkt = av_packet_alloc())) return AVERROR(ENOMEM); + copy->internal->is_frame_mt = 1; if (!first) copy->internal->is_copy = 1; + copy->internal->in_pkt = av_packet_alloc(); + if (!copy->internal->in_pkt) + return AVERROR(ENOMEM); + copy->internal->last_pkt_props = av_packet_alloc(); if (!copy->internal->last_pkt_props) return AVERROR(ENOMEM); @@ -891,8 +947,11 @@ int ff_frame_thread_init(AVCodecContext *avctx) return err; } + fctx->next_pkt = av_packet_alloc(); + if (!fctx->next_pkt) + return AVERROR(ENOMEM); + fctx->async_lock = 1; - fctx->delaying = 1; if (codec->p.type == AVMEDIA_TYPE_VIDEO) avctx->delay = avctx->thread_count - 1; @@ -933,17 +992,18 @@ void ff_thread_flush(AVCodecContext *avctx) } fctx->next_decoding = fctx->next_finished = 0; - fctx->delaying = 1; fctx->prev_thread = NULL; + + decoded_frames_flush(&fctx->df); + fctx->result = 0; + for (i = 0; i < avctx->thread_count; i++) { PerThreadContext *p = &fctx->threads[i]; - // Make sure decode flush calls with size=0 won't return old frames - p->got_frame = 0; - av_frame_unref(p->frame); + + decoded_frames_flush(&p->df); p->result = 0; - if (ffcodec(avctx->codec)->flush) - ffcodec(avctx->codec)->flush(p->avctx); + avcodec_flush_buffers(p->avctx); } } @@ -1039,3 +1099,15 @@ enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset) return FF_THREAD_IS_COPY; } + +int ff_thread_get_packet(AVCodecContext *avctx, AVPacket *pkt) +{ + PerThreadContext *p = avctx->internal->thread_ctx; + + if (!AVPACKET_IS_EMPTY(p->avpkt)) { + av_packet_move_ref(pkt, p->avpkt); + return 0; + } + + return avctx->internal->draining ? AVERROR_EOF : AVERROR(EAGAIN); +} From patchwork Tue Jul 16 17:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50583 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp466787vqb; Tue, 16 Jul 2024 11:14:50 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXMJDBdQXSYSn/ClLgrg4E3uKyq7igOLxJn0t4ezPAEMAQJdPC+oClw0T7iipiAFIRFUdvQhYf6HoIqO8Hf7C3XZnSAAMC8VUR5sQ== X-Google-Smtp-Source: AGHT+IE4Wlm4TT2a647nQo8uy32YONAB0KJdzo0LMG07QuwQs7TzT7pKTnnIrAxpWKFrVi3ciwOA X-Received: by 2002:a05:6512:33c5:b0:52c:86d6:e8d7 with SMTP id 2adb3069b0e04-52edef10755mr2320472e87.13.1721153690327; Tue, 16 Jul 2024 11:14:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153690; cv=none; d=google.com; s=arc-20160816; b=QqTXCnmFkXfocF7O73mSEfWD6yCNsah2bBiGTn221vjyeaX5pAFIr0syEPTIjJHT1W QmO6k+AwDG5jdUI32H6Rci55PhSspWbbCee37EZuRt26onpIi4WUwS8RTWyEQeQS6fH8 zePgrZ768KbzvZJAupL/a9+msnIVEDUdfazyeG/MmZeT9PbA9voJVzxWFMN9r5I86ho2 GgrrY4ne3tCB3pr6kx+7wqBM1PDGT9AX4526hCnGEM0FtgKsk9Sj/k1JMNV1P9bYo5wk Z79kNff7+O+vgpI8UKZkKwG2PeyeWC39JC4sa8ExBvv4a4RNoOm3GleNAt9NcC7RVkgK wJlw== 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=ITP38/Cn9oLzSIArTBxXuVIXtcMhL0gyttYfpkOPhzg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=U0h5WFFzojR3yIQCcXypBL36ooHGu0OM9mVlZGE2G2XTLJ37ZRo20Eiz7d6FzEN8PL 50qEuACsMsO5jcxQM8z+qwk6Xww3jIMAD8tbjmeDBq4XbfnqRYdZn8rnkgjYs7LGKlVZ F3Tnp2ZZNNNMVzr9iAN33yw2M2vnBIGWBP4bwC6tI17ktFbux7LR7S//efzUZHJRKSxV a70YsDEcCKo/6DwnKeHbjyLPVtGFV+Mks9o/Fu1gqE0zmNBBCntUEY4n6WSZ7y0hAPl9 OT1dPZkLtfNQPnJO/SmxOXIn7ExvcBcCPQdC2KCH1v5Sa4zFLdRDd8OAsMSsblchvZE0 swoA==; 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=J72nH7wW; 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 4fb4d7f45d1cf-59b26a8d765si4096565a12.342.2024.07.16.11.14.49; Tue, 16 Jul 2024 11:14: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=J72nH7wW; 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 05EC768D9FF; Tue, 16 Jul 2024 21:14:14 +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 09FE768D88A for ; Tue, 16 Jul 2024 21:13:59 +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=J72nH7wW; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id A1B7B4DF4 for ; Tue, 16 Jul 2024 19:24:20 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id TD1XvDrejZJE for ; Tue, 16 Jul 2024 19:24:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150659; bh=UGzXlw71G1hMzEVpT+qzDS0zYOBrG4Fb4a57r6iezNU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=J72nH7wWbbvia2l61gMKJtG0tlqdIspz6aAMvlMQfYsmRKPO5kz3E6WjyGh/GZqlW 0poK9a5nAYBeIrGukXhJ9fjxqQ2qUT/R4dZo9DYgsPrJvqQg/wESn/u2E8zy2h6ZKS aj8X7AVS0CDfSEzy52xMkOkFiB4H5G1UsJaXpGX9JwpzISRR9o7Mk/HgH9tfsVfm60 rZ/jMjfi+3P3MSMr1OIA7c1iaisIe4/Qcf7j3dxbKOMunEi4BD2Dr6p/4hTxHEeWVP aCFP81FcMjSfI0tcRVeHTNe/KO3xcxGd3YxZLopi9Cbf8lIfha6ic6iGtx/rScD5tW ms7G0X51hHADQ== 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 3ADDA4E25 for ; Tue, 16 Jul 2024 19:24:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BEEF03A3012 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:49 +0200 Message-ID: <20240716171155.31838-34-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 34/39] lavc/decode: reindent after previous commit 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: Vu3vLU/eQeBe --- libavcodec/decode.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index dd94280f0b..deaecf0c01 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -430,20 +430,20 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, got_frame = 0; - frame->pict_type = dc->initial_pict_type; - frame->flags |= dc->intra_only_flag; - consumed = codec->cb.decode(avctx, frame, &got_frame, pkt); + frame->pict_type = dc->initial_pict_type; + frame->flags |= dc->intra_only_flag; + consumed = codec->cb.decode(avctx, frame, &got_frame, pkt); - if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) - frame->pkt_dts = pkt->dts; - if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { + if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)) + frame->pkt_dts = pkt->dts; + if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { #if FF_API_FRAME_PKT FF_DISABLE_DEPRECATION_WARNINGS - if(!avctx->has_b_frames) - frame->pkt_pos = pkt->pos; + if(!avctx->has_b_frames) + frame->pkt_pos = pkt->pos; FF_ENABLE_DEPRECATION_WARNINGS #endif - } + } emms_c(); if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) { From patchwork Tue Jul 16 17:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50579 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp449958vqb; Tue, 16 Jul 2024 10:41:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUBKnD/tWm+OeTpy5gY8g2dyieW+09Y60Wt5DXBUE0GfjZs+iceitShqSKQvC40xQjxGmWReAkUzvF9pClEKhrHF6YLCfXtQbsx4w== X-Google-Smtp-Source: AGHT+IEgp7gW9JgR/T55Ikk/ipaqqI5ZEhDrsG5tAUV45k3j218hkAjbhUywCqJ6ErQpBA/+5ZL4 X-Received: by 2002:a17:906:413:b0:a77:d773:54ec with SMTP id a640c23a62f3a-a79ea3d73edmr215304166b.8.1721151711715; Tue, 16 Jul 2024 10:41:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721151711; cv=none; d=google.com; s=arc-20160816; b=hMKRgnepsH3I51X2iACjP6vUN/fbt1U6CkTRAldqXWB75pio/1QrHARN+DYLVdwkbi /TjjIZwJX9emf/zN7CG79BwyUIcVuOGMlmRPpVqfwLyTfaSsrgssAphSZz43GSj9OVWd X3b0odt9RZ2/NgopeCQ2cIHAGrNZ+BeFPK2uc8El/EVDyLeUeIpbsvA5TNgSfSgvhjVV JFCfB7ncAM6KhVPAGaZmHUdS3AhT8pcbq6QD0unhyQ8c2IHV2c6fML020DNgw89Qa9re 7FsOY3LhezenvsTvYXbphNNJYtJCCXC9S96n93z5GsocTThrQP0PWFgJBrbXTqUjWrgT r5oQ== 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=dVGENEBGzQlx9RPGtY+4c7MQonenO9YMyDMtAao36G8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=ej0OzBLkcpEssTMB4HO292DM8gmB6PDHV+upu3eEgGWBevyujhIqBNTbJICY/U3jhB SWKXLC/VXCTrwoWKLjgNnRYeqSHjYGrndNL/Pd7MyIHr1pJOuRZQNrFwMZIFwc2W7F7h uN3hHYoMUsXtlcFMEHTf7zTu6swLwUW2eYnFA5fRrvl68nMOY83w3dw5+MpERcoKUN20 IRH5iVsdBXkyEwBPOLCI9hQ4r6my9MuMs/YX4reAfq4GfbCFldLpRhW/8Cb0ci4TyM+E BsKwKt3GXLlQ+5WQTShqogNnm84o2PLg9P0owYIY0K8kl8CgUOancxK4iR+vsn1wp34A cgYw==; 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=RRErsuUq; 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-a79bc7c1f30si391254566b.302.2024.07.16.10.41.51; Tue, 16 Jul 2024 10:41:51 -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=RRErsuUq; 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 8E7F868DB0C; Tue, 16 Jul 2024 20:16: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 4E65C68DA97 for ; Tue, 16 Jul 2024 20:16:37 +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=RRErsuUq; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3FDA04DF6 for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ItsDNYvSJAva for ; Tue, 16 Jul 2024 19:16:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=sneAjab5H4DhVBIahuJaYqKM53TMGKmS6i3RtLH/J5c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RRErsuUq/74Qr5Px2awvNriAPwFHmitI0ZbGSMI6aRXQmTF+NWphz8sgEAAWVRCp1 Ect0SE9QIEoxI8hNFOZ/IHmzWqZRwR7jKth5V4ojxRgOXuMS7KAhAlidNaBeW91glP +JcC4A/+u8zaE+74qXIV6vSHYgUyOsVM/OmZWc6A7awZiHyzx1k4EsxNp0JDB4U4Oa BMKkmzFTtn/tmnCeMSyOr00PEGg7pDwt39hMIXsV1eViwMGq3UbTyzVC1RmC6aEV4f n0iIZwBi9hWQqS59j84f3Z+LoVxdCpFL1++J/MrqhFdWr4L8QqWpG/9rv95TGtEiXK cVajHzjVd3i9w== 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 969394E08 for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id CABEE3A33D7 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:50 +0200 Message-ID: <20240716171155.31838-35-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 35/39] lavc/hevcdec: switch to receive_frame() 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: Tcm94rviHJHT Required by following commits, where we will want to output multiple frames per packet. --- libavcodec/hevc/hevcdec.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 0e4b26dad3..fc87169a1a 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3401,22 +3401,25 @@ static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int f return 0; } -static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe, - int *got_output, AVPacket *avpkt) +static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) { + HEVCContext *s = avctx->priv_data; + AVCodecInternal *avci = avctx->internal; + AVPacket *avpkt = avci->in_pkt; + int ret; uint8_t *sd; size_t sd_size; - HEVCContext *s = avctx->priv_data; - if (!avpkt->size) { - ret = ff_hevc_output_frame(s, rframe, 1); + av_packet_unref(avpkt); + ret = ff_decode_get_packet(avctx, avpkt); + if (ret == AVERROR_EOF) { + ret = ff_hevc_output_frame(s, frame, 1); if (ret < 0) return ret; - - *got_output = ret; - return 0; - } + return (ret > 0) ? 0 : AVERROR_EOF; + } else if (ret < 0) + return ret; sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA, &sd_size); if (sd && sd_size > 0) { @@ -3440,11 +3443,11 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe, return ret; if (s->output_frame->buf[0]) { - av_frame_move_ref(rframe, s->output_frame); - *got_output = 1; + av_frame_move_ref(frame, s->output_frame); + return 0; } - return avpkt->size; + return AVERROR(EAGAIN); } static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) @@ -3721,7 +3724,7 @@ const FFCodec ff_hevc_decoder = { .p.priv_class = &hevc_decoder_class, .init = hevc_decode_init, .close = hevc_decode_free, - FF_CODEC_DECODE_CB(hevc_decode_frame), + FF_CODEC_RECEIVE_FRAME_CB(hevc_receive_frame), .flush = hevc_decode_flush, UPDATE_THREAD_CONTEXT(hevc_update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | From patchwork Tue Jul 16 17:11:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50591 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp470138vqb; Tue, 16 Jul 2024 11:21:51 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWykCzee3ecCIMcP64eul/cDeNcvf7jsArlHE0aL0x9lv733TiUmjLKS1tIhhCkl8FG8q0V1rKYQY6WDXPVmVK74ILpxZfGw1UBew== X-Google-Smtp-Source: AGHT+IGDGD9IJWbpyPoW00qAVOb6rpCGuzdf2+rV322otuLLDitUPL9oce5TOwx/qGYkEzCpWzU9 X-Received: by 2002:a05:6512:4007:b0:52e:9f17:841a with SMTP id 2adb3069b0e04-52edf01817emr2031140e87.6.1721154111461; Tue, 16 Jul 2024 11:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721154111; cv=none; d=google.com; s=arc-20160816; b=qtZu9wMao4ZfVM8FmQdgFzNXjHpUBDFiP+MDo9FsyxVAYLwXORt1f5Evsb8xIzQniF 81qV4z6sPsz/I/CbkaU/kMupmYwFxQ5KXnIzwDBQSf+03PMwlO1m+b0VxeIbzIGleP2j T7akqrAY0zvUoFDByjgNm91fEt8AJHs0NUOpMrAekZ0vp92Et4WssIj/EC6JfsTYA4B4 yt+baGwyjueaLwQS7nIqy+pYkZHybBBFYUkaGqE045y4mZ/yT0Rhq8/QFojPw7MTyoHm XRVriwMO+KLlUa+UT/9+aItW13Rm95uFiOhBEdQoxkeKbcddBS8R1e4Bk3mvqSdVIVf1 7a5g== 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=VxiTeC0xSl5tZzM11c2a88pHeKqcktttcUniue4HnzM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=fQyxHulbgTDXovcDt/uPTvTh6XXMCdYL9c1qv3dMF37DkixxhiQxtnaKYb605TAO7g Lu+z6n8SFqG6qDoUd5iVoicMfoYQb4AuuCdMG3cAUiOnjLgO60O7Jt8kG/+qRr+l4nUL DU/YH1DkdWyPW3U84xpPrabUZZgAuk2J7j/TLXthMERo2Xwg7E4bpYcmmbd/HZ7K4zZC th1oX71Fn6KUPu05SehBWsuhYTFdv5ZzS2tFPO+YNv3XRtbw96lf+c4oB9JfdKNJz/ug LSRe8Hwsz4z980SwPElkdAw4NkQENi/y8vY3azkRmbbhAD/2a6WysV9oVT9Slc+jpzwJ wkLA==; 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=OK1xmX62; 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-52ed2568477si2214719e87.389.2024.07.16.11.21.50; Tue, 16 Jul 2024 11:21:51 -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=OK1xmX62; 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 B45CF68DB09; Tue, 16 Jul 2024 21:14:09 +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 14AC968D8F6 for ; Tue, 16 Jul 2024 21:13:59 +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=OK1xmX62; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id ACF784DEC for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id A2hRHqdFsV0F for ; Tue, 16 Jul 2024 19:16:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150189; bh=bOrP+TnsUk1rlKp+l63UsMyC4gUCi36NyDOQiZ9p7ro=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OK1xmX62OUofuSHCVvoxi3xkt/t+gzPJwWU+pxFqfMpzLb7X077IRJKm0ePVp2aLC tONHhKhCLcBzgT0abn3V0r2DcjLSCEaYaxT5TTo0HV+BOUT8G2Ck7/8jto58lGCKfL AG+JZTdWiNP+8EM6fO78B9RuwnJG1XlArd9eu6KMnzFTG57ZFLxkJCV1oqr5gw5Zoc gnl6je+F77JsUzp2oqhZmSwv2Cqo8xPHtST4pd2Nr5tWanV0V9oWES3LE5kb1hCZI4 jlQSqJotIgs/4+B2KxD9seYbHBFZ5S/IsbuAMxJnOvDlTIyijBtZqnWSluT1mkZpEp GrUnpPnuehNsA== 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 C7EB74E0C for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D69193A33D8 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:51 +0200 Message-ID: <20240716171155.31838-36-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 36/39] lavc: add private container FIFO API 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: ZB9OShObAmzb It provides a FIFO for "container" objects like AVFrame/AVPacket and features an integrated FFRefStructPool-based pool to avoid allocating an freeing them repeatedly. --- libavcodec/container_fifo.c | 195 ++++++++++++++++++++++++++++++++++++ libavcodec/container_fifo.h | 87 ++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 libavcodec/container_fifo.c create mode 100644 libavcodec/container_fifo.h diff --git a/libavcodec/container_fifo.c b/libavcodec/container_fifo.c new file mode 100644 index 0000000000..86ed15627b --- /dev/null +++ b/libavcodec/container_fifo.c @@ -0,0 +1,195 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/error.h" +#include "libavutil/fifo.h" +#include "libavutil/frame.h" +#include "libavutil/mem.h" + +#include "container_fifo.h" +#include "refstruct.h" + +struct ContainerFifo { + AVFifo *fifo; + FFRefStructPool *pool; + + void* (*container_alloc)(void); + void (*container_reset)(void *obj); + void (*container_free) (void *obj); + int (*fifo_write) (void *dst, void *src); + int (*fifo_read) (void *dst, void *src); + +}; + +static int container_fifo_init_entry(FFRefStructOpaque opaque, void *obj) +{ + ContainerFifo *cf = opaque.nc; + void **pobj = obj; + + *pobj = cf->container_alloc(); + if (!*pobj) + return AVERROR(ENOMEM); + + return 0; +} + +static void container_fifo_reset_entry(FFRefStructOpaque opaque, void *obj) +{ + ContainerFifo *cf = opaque.nc; + cf->container_reset(*(void**)obj); +} + +static void container_fifo_free_entry(FFRefStructOpaque opaque, void *obj) +{ + ContainerFifo *cf = opaque.nc; + cf->container_free(*(void**)obj); +} + +ContainerFifo* +ff_container_fifo_alloc(void* (*container_alloc)(void), + void (*container_reset)(void *obj), + void (*container_free) (void *obj), + int (*fifo_write) (void *dst, void *src), + int (*fifo_read) (void *dst, void *src)) +{ + ContainerFifo *cf; + + cf = av_mallocz(sizeof(*cf)); + if (!cf) + return NULL; + + cf->container_alloc = container_alloc; + cf->container_reset = container_reset; + cf->container_free = container_free; + cf->fifo_write = fifo_write; + cf->fifo_read = fifo_read; + + cf->fifo = av_fifo_alloc2(1, sizeof(void*), AV_FIFO_FLAG_AUTO_GROW); + if (!cf->fifo) + goto fail; + + cf->pool = ff_refstruct_pool_alloc_ext(sizeof(void*), 0, cf, + container_fifo_init_entry, + container_fifo_reset_entry, + container_fifo_free_entry, + NULL); + if (!cf->pool) + goto fail; + + return cf; +fail: + ff_container_fifo_free(&cf); + return NULL; +} + +void ff_container_fifo_free(ContainerFifo **pcf) +{ + ContainerFifo *cf; + + if (!*pcf) + return; + + cf = *pcf; + + if (cf->fifo) { + void *obj; + while (av_fifo_read(cf->fifo, &obj, 1) >= 0) + ff_refstruct_unref(&obj); + av_fifo_freep2(&cf->fifo); + } + + ff_refstruct_pool_uninit(&cf->pool); + + av_freep(pcf); +} + +int ff_container_fifo_read(ContainerFifo *cf, void *obj) +{ + void **psrc; + int ret; + + ret = av_fifo_read(cf->fifo, &psrc, 1); + if (ret < 0) + return ret; + + ret = cf->fifo_read(obj, *psrc); + ff_refstruct_unref(&psrc); + + return ret; +} + +int ff_container_fifo_write(ContainerFifo *cf, void *obj) +{ + void **pdst; + int ret; + + pdst = ff_refstruct_pool_get(cf->pool); + if (!pdst) + return AVERROR(ENOMEM); + + ret = cf->fifo_write(*pdst, obj); + if (ret < 0) + goto fail; + + ret = av_fifo_write(cf->fifo, &pdst, 1); + if (ret < 0) + goto fail; + + return 0; +fail: + ff_refstruct_unref(&pdst); + return ret; +} + +size_t ff_container_fifo_can_read(ContainerFifo *cf) +{ + return av_fifo_can_read(cf->fifo); +} + +static void* frame_alloc(void) +{ + return av_frame_alloc(); +} + +static void frame_reset(void *obj) +{ + av_frame_unref(obj); +} + +static void frame_free(void *obj) +{ + AVFrame *frame = obj; + av_frame_free(&frame); +} + +static int frame_ref(void *dst, void *src) +{ + return av_frame_ref(dst, src); +} + +static int frame_move_ref(void *dst, void *src) +{ + av_frame_move_ref(dst, src); + return 0; +} + +ContainerFifo *ff_container_fifo_alloc_avframe(unsigned flags) +{ + return ff_container_fifo_alloc(frame_alloc, frame_reset, frame_free, + frame_ref, frame_move_ref); +} diff --git a/libavcodec/container_fifo.h b/libavcodec/container_fifo.h new file mode 100644 index 0000000000..75a8f9e86b --- /dev/null +++ b/libavcodec/container_fifo.h @@ -0,0 +1,87 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_CONTAINER_FIFO_H +#define AVCODEC_CONTAINER_FIFO_H + +/** + * ContainerFifo is a FIFO for "containers" - dynamically allocated reusable + * structs (e.g. AVFrame or AVPacket). ContainerFifo uses an internal pool of + * such containers to avoid allocating and freeing them repeatedly. + */ +typedef struct ContainerFifo ContainerFifo; + +/** + * Allocate a new ContainerFifo for the container type defined by provided + * callbacks. + * + * @param container_alloc allocate a new container instance and return a pointer + * to it, or NULL on failure + * @param container_reset reset the provided container instance to a clean state + * @param container_free free the provided container instance + * @param fifo_write transfer the contents of src to dst, where src is a + * container instance provided to ff_container_fifo_write() + * @param fifo_read transfer the contents of src to dst in other cases + * + * @note fifo_read() and fifo_write() are different parameters in order to allow + * fifo_write() implementations that make a new reference in dst, leaving + * src untouched (see e.g. ff_container_fifo_alloc_avframe()) + */ +ContainerFifo* +ff_container_fifo_alloc(void* (*container_alloc)(void), + void (*container_reset)(void *obj), + void (*container_free) (void *obj), + int (*fifo_write) (void *dst, void *src), + int (*fifo_read) (void *dst, void *src)); + +/** + * Allocate a ContainerFifo instance for AVFrames. + * Note that ff_container_fifo_write() will call av_frame_ref() on src, making a + * new reference in dst and leaving src untouched. + * + * @param flags unused currently + */ +ContainerFifo *ff_container_fifo_alloc_avframe(unsigned flags); + +/** + * Free a ContainerFifo and everything in it. + */ +void ff_container_fifo_free(ContainerFifo **pf); + +/** + * Write the contents of obj to the FIFO. + * + * The fifo_write() callback previously provided to ff_container_fifo_alloc() + * will be called with obj as src in order to perform the actual transfer. + */ +int ff_container_fifo_write(ContainerFifo *pf, void *obj); + +/** + * Read the next available object from the FIFO into obj. + * + * The fifo_read() callback previously provided to ff_container_fifo_alloc() + * will be called with obj as dst in order to perform the actual transfer. + */ +int ff_container_fifo_read(ContainerFifo *pf, void *obj); + +/** + * @return number of objects available for reading + */ +size_t ff_container_fifo_can_read(ContainerFifo *pf); + +#endif // AVCODEC_CONTAINER_FIFO_H From patchwork Tue Jul 16 17:11:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50580 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp467394vqb; Tue, 16 Jul 2024 11:16:03 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWsmRJIoUhvZtLtZWRFZvEktJaw13JiDGF3b2wLUVSnukGFaT8yhWZl7ytB+Q+RivWW8zh1NW7VglBX9cReDo0WAUsLSkhTdd9t4g== X-Google-Smtp-Source: AGHT+IHx4qgAZsR78x1VZwjkCPRSk7KoEF9B7ERdd0MnKAQE3LqTSgskwwCOhvnvgUot3NR3hJm1 X-Received: by 2002:a17:906:1292:b0:a6f:f7c:5c7a with SMTP id a640c23a62f3a-a79eaa61812mr209856966b.67.1721153763185; Tue, 16 Jul 2024 11:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153763; cv=none; d=google.com; s=arc-20160816; b=owz3faLYU+A6xsIfb5q4dkyKrq4aDloMdWX/qMfsoXFC+1J8YDxGpXewHWAqkmuC+F HiVeIxvb06a9UGhRSQzhAxaoaV3pPowZsv5ZhX/xFtdAd4/PZoywUzBD6zDISFiX3Y1t cg6/SesNWhenYBYa/sk3UbfZ6yvX/T5lsynr4ET/lIxJiaIFvc3Y9IhxkOCEmOG4Oh5v Z03X995xZZwvLUoqIFkOK+CiiSxxjIue3Jia5DUTZi0FUlj9bs7n/5Qddcrhsk/CdCl9 3QEzrRSay3bWnzCgKx1RuaN/YlBHsGrLtI5sG7Gqn1pUhZnhXX61Sytomcxiyxy/rf8G irtQ== 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=yykwLKHOpPYHOhqsIaiGeKkDy7cVb4TqB0pyIipcOvY=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=AJgy3c7g+U1MaGdvg67Qj1goiWxXALkpx5OHEi0GfUwfvHr6FYBIXwPv036CYFiOYY U40T2nA9jWG/X01BnUr1H+D2226U6ScGXcs8Z15rqtYnFhXQaJ8Tt/bh8uSqCZBaEXBN DS8kK5nTW9zthyFfDob/NKZfCoWNLm37HeCjeu39rzQ1/3RuqGJV+BMosQnQNeN6tQH8 ng3XYIKGGSnilVIjkS6f+JL2HACMm6EOZbJ6MLUNKLpVQBGWIzDmmALxt9H+r9HQMOsn p/76QdMYMYf1v4DAPXMnemVAX+p2ABrdsQDMxhMo4rYmioVIx+yPEA/el0nLufSuHIgm pHRA==; 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=jTK7oO0n; 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-a79bc804c60si383601566b.780.2024.07.16.11.16.02; Tue, 16 Jul 2024 11:16: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=jTK7oO0n; 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 41EFC68DB4F; Tue, 16 Jul 2024 21:14:26 +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 9F17B68DA9D for ; Tue, 16 Jul 2024 21:14:04 +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=jTK7oO0n; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id D4E9F4E23 for ; Tue, 16 Jul 2024 19:24:20 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 4nKgPWEy20MG for ; Tue, 16 Jul 2024 19:24:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150659; bh=Xj7luEe9E98aNRUFOLzKpUf+TgK8cTEi00xih3LNp/E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jTK7oO0nmz5es+TNb3AFFI//3yn0bu4RgtkWct36Sg6ppuXcaNl5LdfZaIDs6xms2 KulwssprFSVoVZPmL5DiFg3h5pjuLIeY47SeZAzcYrUbFY/yGbNB1dCvoTn3VzpiGR Wb+gvdpbk+OPUqZAmKI/zQcksbn/DXzXwnhKST1gPwyg59GdqyVTl0ul1dM0eT5w+v BSSjkNyZg5bAVP04upak/x1hchyiYNn0vjp1PbJtuwlNL3pPWY9ofcszx3Egh2btcx HS7N5UD2LLSsX2UAuVcb73+fLp1pVQF3cc2l1jAZ1AS6ZLRs0s6yiAU4MDB5YAix5B NJfDjtR6mk+fQ== 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 345204DF2 for ; Tue, 16 Jul 2024 19:24:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E21F83A33D9 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:52 +0200 Message-ID: <20240716171155.31838-37-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 37/39] lavc/hevcdec: use a ContainerFifo to hold frames scheduled for output 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: 04TSTCjIbgyR Instead of a single AVFrame. Will be useful in future commits, where we will want to produce multiple output frames for a single coded frame. --- libavcodec/Makefile | 2 +- libavcodec/hevc/hevcdec.c | 30 ++++++++++++++++++++---------- libavcodec/hevc/hevcdec.h | 5 +++-- libavcodec/hevc/refs.c | 11 +++-------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 771e2b597e..e67b729bd3 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -431,7 +431,7 @@ OBJS-$(CONFIG_HCA_DECODER) += hcadec.o OBJS-$(CONFIG_HCOM_DECODER) += hcom.o OBJS-$(CONFIG_HDR_DECODER) += hdrdec.o OBJS-$(CONFIG_HDR_ENCODER) += hdrenc.o -OBJS-$(CONFIG_HEVC_DECODER) += aom_film_grain.o h274.o +OBJS-$(CONFIG_HEVC_DECODER) += aom_film_grain.o h274.o container_fifo.o OBJS-$(CONFIG_HEVC_AMF_ENCODER) += amfenc_hevc.o OBJS-$(CONFIG_HEVC_CUVID_DECODER) += cuviddec.o OBJS-$(CONFIG_HEVC_D3D12VA_ENCODER) += d3d12va_encode_hevc.o h265_profile_level.o \ diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index fc87169a1a..5e28bfe54e 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3006,6 +3006,10 @@ static int hevc_frame_start(HEVCContext *s) s->cur_frame->frame_grain->height = s->cur_frame->f->height; if ((ret = ff_thread_get_buffer(s->avctx, s->cur_frame->frame_grain, 0)) < 0) goto fail; + + ret = av_frame_copy_props(s->cur_frame->frame_grain, s->cur_frame->f); + if (ret < 0) + goto fail; } s->cur_frame->f->pict_type = 3 - s->sh.slice_type; @@ -3013,8 +3017,7 @@ static int hevc_frame_start(HEVCContext *s) if (!IS_IRAP(s)) ff_hevc_bump_frame(s); - av_frame_unref(s->output_frame); - ret = ff_hevc_output_frame(s, s->output_frame, 0); + ret = ff_hevc_output_frame(s, 0); if (ret < 0) goto fail; @@ -3411,13 +3414,16 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) uint8_t *sd; size_t sd_size; + if (ff_container_fifo_can_read(s->output_fifo)) + goto do_output; + av_packet_unref(avpkt); ret = ff_decode_get_packet(avctx, avpkt); if (ret == AVERROR_EOF) { - ret = ff_hevc_output_frame(s, frame, 1); + ret = ff_hevc_output_frame(s, 1); if (ret < 0) return ret; - return (ret > 0) ? 0 : AVERROR_EOF; + goto do_output; } else if (ret < 0) return ret; @@ -3442,12 +3448,15 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) if (ret < 0) return ret; - if (s->output_frame->buf[0]) { - av_frame_move_ref(frame, s->output_frame); +do_output: + if (ff_container_fifo_read(s->output_fifo, frame) >= 0) { + if (!(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) + av_frame_remove_side_data(frame, AV_FRAME_DATA_FILM_GRAIN_PARAMS); + return 0; } - return AVERROR(EAGAIN); + return avci->draining ? AVERROR_EOF : AVERROR(EAGAIN); } static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) @@ -3499,7 +3508,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) av_freep(&s->sao_pixel_buffer_h[i]); av_freep(&s->sao_pixel_buffer_v[i]); } - av_frame_free(&s->output_frame); + + ff_container_fifo_free(&s->output_fifo); for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { ff_hevc_unref_frame(&s->DPB[i], ~0); @@ -3537,8 +3547,8 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) s->local_ctx[0].logctx = avctx; s->local_ctx[0].common_cabac_state = &s->cabac; - s->output_frame = av_frame_alloc(); - if (!s->output_frame) + s->output_fifo = ff_container_fifo_alloc_avframe(0); + if (!s->output_fifo) return AVERROR(ENOMEM); for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index da4d83e661..f2705b8de2 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -31,6 +31,7 @@ #include "libavcodec/avcodec.h" #include "libavcodec/bswapdsp.h" #include "libavcodec/cabac.h" +#include "libavcodec/container_fifo.h" #include "libavcodec/dovi_rpu.h" #include "libavcodec/get_bits.h" #include "libavcodec/h2645_parse.h" @@ -457,7 +458,7 @@ typedef struct HEVCContext { /** 1 if the independent slice segment header was successfully parsed */ uint8_t slice_initialized; - AVFrame *output_frame; + ContainerFifo *output_fifo; uint8_t *sao_pixel_buffer_h[3]; uint8_t *sao_pixel_buffer_v[3]; @@ -636,7 +637,7 @@ static av_always_inline int ff_hevc_nal_is_nonref(enum HEVCNALUnitType type) * Find next frame in output order and put a reference to it in frame. * @return 1 if a frame was output, 0 otherwise */ -int ff_hevc_output_frame(HEVCContext *s, AVFrame *frame, int flush); +int ff_hevc_output_frame(HEVCContext *s, int flush); void ff_hevc_bump_frame(HEVCContext *s); diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c index 48fc4d27da..44ee7c837a 100644 --- a/libavcodec/hevc/refs.c +++ b/libavcodec/hevc/refs.c @@ -171,7 +171,7 @@ static void unref_missing_refs(HEVCContext *s) } } -int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) +int ff_hevc_output_frame(HEVCContext *s, int flush) { if (IS_IRAP(s) && s->no_rasl_output_flag == 1) { const static int mask = HEVC_FRAME_FLAG_BUMPING | HEVC_FRAME_FLAG_OUTPUT; @@ -211,7 +211,8 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) if (nb_output) { HEVCFrame *frame = &s->DPB[min_idx]; - ret = av_frame_ref(out, frame->needs_fg ? frame->frame_grain : frame->f); + ret = ff_container_fifo_write(s->output_fifo, + frame->needs_fg ? frame->frame_grain : frame->f); if (frame->flags & HEVC_FRAME_FLAG_BUMPING) ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_BUMPING); else @@ -219,12 +220,6 @@ int ff_hevc_output_frame(HEVCContext *s, AVFrame *out, int flush) if (ret < 0) return ret; - if (frame->needs_fg && (ret = av_frame_copy_props(out, frame->f)) < 0) - return ret; - - if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN)) - av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS); - av_log(s->avctx, AV_LOG_DEBUG, "Output frame with POC %d.\n", frame->poc); return 1; From patchwork Tue Jul 16 17:11:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50587 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp467106vqb; Tue, 16 Jul 2024 11:15:27 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWT1o07ogJv5pRkewSRusqjciuMxvFd+JBV4qz1WWaWiLWb+fW3M6tNSPEeTvAL2qmGRBbIgvKqX5a3tuXA9ptt2+s1D/+G0Is95g== X-Google-Smtp-Source: AGHT+IFR0z6l1Za5Wu0GW0aJ3v+sBZR0ZVXNaRLTHr2PWdDjeSAHnSVZquq/lyBhcN+yC+1UMww+ X-Received: by 2002:a05:6402:5193:b0:57c:7ed7:897a with SMTP id 4fb4d7f45d1cf-59ef03bacaemr2352635a12.27.1721153727441; Tue, 16 Jul 2024 11:15:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153727; cv=none; d=google.com; s=arc-20160816; b=LvV2ifi4e4r1jCozpw5LV1Gck0ugfmdSemBdGChInEuyLpalXrj6acs2MhgEvsx5/z eokcMaPeHPcVqP4TPoYRY9VvCmdIG/6Y9E5ynbw0CQQjy6KTb2lInf5GvpXm5iXjgNov ARjCbMboByJF17M6Zdg71FVOWQSKZiZHQ2GegVNLCAw6JwLO541rzVM79Bi74ih4JIND l1+ux8wb6MZU6AZtAD7XG7LGTNO86JpcRnmTWBIjIpT8poRmKb72s4ZhvGeuqwUZsQOS 0U60D2PbFbgSxcGMarzEiWg54MYiPcR1Lud0U5PzqtvRbybAT7PEu64TiMOUAer47mzG kbbA== 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=eVrbV3ttLxc/QGcX83ZwSEIATQPynkHA8N4xK59xzkA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=E6DkT+OUbOHnItHTeQ2pLIvkT7VzT2UpAyQ/eU+PByUKQqponmUJ69CCyzua/hCppE QmrHQER9RAUFkKLOcyGdcXDIWGkWbZdyeOGeSQxUOX/viYBTlqj0McQRzULakxyIZogD Dsbng4BkQktcK8ZkyCXGsiOMsJOSIMnBo4W8LGnjA4ZWrPZAuPgQnvRkn3hvKRNDQEVN KrPB6wZVTkAZkTptUAb3cijLqbFphKH0ykjDqsLkol0JYBHTa2An8qb+N/+v/T9VjNPi B/TmxUDZ6mZKCJydV81NM6rUTokTJho5u+2Phzks0XaQPhARdFP7i0pVucg/Juz0uj1z Ottg==; 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=CNSmhJnU; 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 4fb4d7f45d1cf-59b24a6c45esi3973993a12.64.2024.07.16.11.15.27; Tue, 16 Jul 2024 11:15:27 -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=CNSmhJnU; 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 1FBD968DA9B; Tue, 16 Jul 2024 21:14:20 +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 8756168DA96 for ; Tue, 16 Jul 2024 21:14:04 +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=CNSmhJnU; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id D233A4DFC for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id U7YloZniHbPg for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150188; bh=vEQWWU6S1+UgnyTwqLct9jFJzGG0yBWOIs+ec+PBZEs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CNSmhJnUgm9uNZalD/UsscxA8RW1k1vtNNF/En6SaYTYP3OtXzxG2nv3ANyLryDVR 6dHXOPci2jNFBqICK4qiYG5jjeX7RtD/faCROgp+Qw7KCs//tB/wAaLFtNrACSgshY UZCXyJJpb6VGHp26OHyA3DUmAR3gXwzFKWzbvjd2H6bJO/8gibU1CHUwgKQc29Ri5g 7DZjTGcUvalAmQf75EZFxcMINEoDtukbXIzo3Ij5xFhErGP3Nofb62KIPSGjqghjFw XLcoslmFXy7cVtIDuNdKaiFko89+6kLweTKo0yBvAC7GtSBLdU31MEwudWOIKFmjFb RtH2ETi8zQ5CQ== 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 EB5F84E0F for ; Tue, 16 Jul 2024 19:16:28 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id EE1E93A3614 for ; Tue, 16 Jul 2024 19:16:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:53 +0200 Message-ID: <20240716171155.31838-38-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 38/39] lavc/hevcdec: simplify output logic 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: 9f5rngDenCDy Current code is written around the "simple" decode API's limitation that a single input packet (AU/coded frame) triggers the output of at most one output frame. However the spec contains two cases where a coded frame may cause multiple frames to be output (cf. C.5.2.2.2): * start of a new sequence * overflowing sps_max_dec_pic_buffering The decoder currently contains rather convoluted logic to handle these cases: * decode/output/per-frame sequence counters, * HEVC_FRAME_FLAG_BUMPING * ff_hevc_bump_frame() * special clauses in ff_hevc_output_frame() However, with the receive_frame() API none of that is necessary, as we can just output multiple frames at once. Previously added ContainerFifo allows that to be done in a straightforward and efficient manner. --- libavcodec/hevc/hevcdec.c | 33 +++++------- libavcodec/hevc/hevcdec.h | 32 ++++-------- libavcodec/hevc/refs.c | 104 +++++++------------------------------- 3 files changed, 42 insertions(+), 127 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 5e28bfe54e..28835f48d6 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -2906,6 +2906,7 @@ static int hevc_frame_start(HEVCContext *s) const HEVCSPS *const sps = pps->sps; int pic_size_in_ctb = ((sps->width >> sps->log2_min_cb_size) + 1) * ((sps->height >> sps->log2_min_cb_size) + 1); + int new_sequence = IS_IDR(s) || IS_BLA(s) || s->last_eos; int ret; ff_refstruct_replace(&s->pps, pps); @@ -2925,7 +2926,7 @@ static int hevc_frame_start(HEVCContext *s) return pix_fmt; s->avctx->pix_fmt = pix_fmt; - s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; + new_sequence = 1; } memset(s->horizontal_bs, 0, s->bs_width * s->bs_height); @@ -2934,11 +2935,8 @@ static int hevc_frame_start(HEVCContext *s) memset(s->is_pcm, 0, (sps->min_pu_width + 1) * (sps->min_pu_height + 1)); memset(s->tab_slice_address, -1, pic_size_in_ctb * sizeof(*s->tab_slice_address)); - if ((IS_IDR(s) || IS_BLA(s))) { - s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; - if (IS_IDR(s)) - ff_hevc_clear_refs(s); - } + if (IS_IDR(s)) + ff_hevc_clear_refs(s); s->slice_idx = 0; s->first_nal_type = s->nal_unit_type; @@ -2962,6 +2960,12 @@ static int hevc_frame_start(HEVCContext *s) if (pps->tiles_enabled_flag) s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << sps->log2_ctb_size; + if (new_sequence) { + ret = ff_hevc_output_frames(s, 0, 0, s->sh.no_output_of_prior_pics_flag); + if (ret < 0) + return ret; + } + ret = export_stream_params_from_sei(s); if (ret < 0) return ret; @@ -3014,10 +3018,8 @@ static int hevc_frame_start(HEVCContext *s) s->cur_frame->f->pict_type = 3 - s->sh.slice_type; - if (!IS_IRAP(s)) - ff_hevc_bump_frame(s); - - ret = ff_hevc_output_frame(s, 0); + ret = ff_hevc_output_frames(s, sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics, + sps->temporal_layer[sps->max_sub_layers - 1].max_dec_pic_buffering, 0); if (ret < 0) goto fail; @@ -3262,8 +3264,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal) break; case HEVC_NAL_EOS_NUT: case HEVC_NAL_EOB_NUT: - s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; - break; case HEVC_NAL_AUD: case HEVC_NAL_FD_NUT: case HEVC_NAL_UNSPEC62: @@ -3420,7 +3420,7 @@ static int hevc_receive_frame(AVCodecContext *avctx, AVFrame *frame) av_packet_unref(avpkt); ret = ff_decode_get_packet(avctx, avpkt); if (ret == AVERROR_EOF) { - ret = ff_hevc_output_frame(s, 1); + ret = ff_hevc_output_frames(s, 0, 0, 0); if (ret < 0) return ret; goto do_output; @@ -3482,7 +3482,6 @@ static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src) dst->poc = src->poc; dst->ctb_count = src->ctb_count; dst->flags = src->flags; - dst->sequence = src->sequence; ff_refstruct_replace(&dst->hwaccel_picture_private, src->hwaccel_picture_private); @@ -3606,8 +3605,6 @@ static int hevc_update_thread_context(AVCodecContext *dst, if ((ret = set_sps(s, s0->ps.sps)) < 0) return ret; - s->seq_decode = s0->seq_decode; - s->seq_output = s0->seq_output; s->poc_tid0 = s0->poc_tid0; s->eos = s0->eos; s->no_rasl_output_flag = s0->no_rasl_output_flag; @@ -3617,10 +3614,6 @@ static int hevc_update_thread_context(AVCodecContext *dst, s->film_grain_warning_shown = s0->film_grain_warning_shown; - if (s0->eos) { - s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK; - } - ret = ff_h2645_sei_ctx_replace(&s->sei.common, &s0->sei.common); if (ret < 0) return ret; diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h index f2705b8de2..4293f1bd66 100644 --- a/libavcodec/hevc/hevcdec.h +++ b/libavcodec/hevc/hevcdec.h @@ -350,10 +350,7 @@ typedef struct DBParams { #define HEVC_FRAME_FLAG_OUTPUT (1 << 0) #define HEVC_FRAME_FLAG_SHORT_REF (1 << 1) #define HEVC_FRAME_FLAG_LONG_REF (1 << 2) -#define HEVC_FRAME_FLAG_BUMPING (1 << 3) - -#define HEVC_SEQUENCE_COUNTER_MASK 0xff -#define HEVC_SEQUENCE_COUNTER_INVALID (HEVC_SEQUENCE_COUNTER_MASK + 1) +#define HEVC_FRAME_FLAG_UNAVAILABLE (1 << 3) typedef struct HEVCFrame { union { @@ -375,12 +372,6 @@ typedef struct HEVCFrame { void *hwaccel_picture_private; ///< RefStruct reference - /** - * A sequence counter, so that old frames are output first - * after a POC reset - */ - uint16_t sequence; - /** * A combination of HEVC_FRAME_FLAG_* */ @@ -519,13 +510,6 @@ typedef struct HEVCContext { uint8_t *checksum_buf; int checksum_buf_size; - /** - * Sequence counters for decoded and output frames, so that old - * frames are output first after a POC reset - */ - uint16_t seq_decode; - uint16_t seq_output; - /** The target for the common_cabac_state of the local contexts. */ HEVCCABACState cabac; @@ -634,12 +618,16 @@ static av_always_inline int ff_hevc_nal_is_nonref(enum HEVCNALUnitType type) } /** - * Find next frame in output order and put a reference to it in frame. - * @return 1 if a frame was output, 0 otherwise + * Find frames in the DPB that are ready for output and either write them to the + * output FIFO or drop their output flag, depending on the value of discard. + * + * @param max_output maximum number of output-pending frames that can be + * present in the DPB before output is triggered + * @param max_dpb maximum number of any frames that can be present in the DPB + * before output is triggered */ -int ff_hevc_output_frame(HEVCContext *s, int flush); - -void ff_hevc_bump_frame(HEVCContext *s); +int ff_hevc_output_frames(HEVCContext *s, unsigned max_output, + unsigned max_dpb, int discard); void ff_hevc_unref_frame(HEVCFrame *frame, int flags); diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c index 44ee7c837a..50aa06b926 100644 --- a/libavcodec/hevc/refs.c +++ b/libavcodec/hevc/refs.c @@ -131,8 +131,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, int poc) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if (frame->f && frame->sequence == s->seq_decode && - frame->poc == poc) { + if (frame->f && frame->poc == poc) { av_log(s->avctx, AV_LOG_ERROR, "Duplicate POC in a sequence: %d.\n", poc); return AVERROR_INVALIDDATA; @@ -152,7 +151,6 @@ int ff_hevc_set_new_ref(HEVCContext *s, int poc) ref->flags = HEVC_FRAME_FLAG_SHORT_REF; ref->poc = poc; - ref->sequence = s->seq_decode; ref->f->crop_left = s->ps.sps->output_window.left_offset; ref->f->crop_right = s->ps.sps->output_window.right_offset; ref->f->crop_top = s->ps.sps->output_window.top_offset; @@ -165,112 +163,49 @@ static void unref_missing_refs(HEVCContext *s) { for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if (frame->sequence == HEVC_SEQUENCE_COUNTER_INVALID) { + if (frame->flags & HEVC_FRAME_FLAG_UNAVAILABLE) { ff_hevc_unref_frame(frame, ~0); } } } -int ff_hevc_output_frame(HEVCContext *s, int flush) +int ff_hevc_output_frames(HEVCContext *s, unsigned max_output, + unsigned max_dpb, int discard) { - if (IS_IRAP(s) && s->no_rasl_output_flag == 1) { - const static int mask = HEVC_FRAME_FLAG_BUMPING | HEVC_FRAME_FLAG_OUTPUT; - for (int i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - HEVCFrame *frame = &s->DPB[i]; - if ((frame->flags & mask) == HEVC_FRAME_FLAG_OUTPUT && - frame->sequence != s->seq_decode) { - if (s->sh.no_output_of_prior_pics_flag == 1) - ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT); - else - frame->flags |= HEVC_FRAME_FLAG_BUMPING; - } - } - } - do { + while (1) { + int nb_dpb = 0; int nb_output = 0; int min_poc = INT_MAX; int i, min_idx, ret; for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if ((frame->flags & HEVC_FRAME_FLAG_OUTPUT) && - frame->sequence == s->seq_output) { + if (frame->flags & HEVC_FRAME_FLAG_OUTPUT) { nb_output++; if (frame->poc < min_poc || nb_output == 1) { min_poc = frame->poc; min_idx = i; } } + nb_dpb += !!frame->flags; } - /* wait for more frames before output */ - if (!flush && s->seq_output == s->seq_decode && s->ps.sps && - nb_output <= s->ps.sps->temporal_layer[s->ps.sps->max_sub_layers - 1].num_reorder_pics) - return 0; - - if (nb_output) { + if (nb_output > max_output || + (nb_output && nb_dpb > max_dpb)) { HEVCFrame *frame = &s->DPB[min_idx]; - ret = ff_container_fifo_write(s->output_fifo, + ret = discard ? 0 : + ff_container_fifo_write(s->output_fifo, frame->needs_fg ? frame->frame_grain : frame->f); - if (frame->flags & HEVC_FRAME_FLAG_BUMPING) - ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_BUMPING); - else - ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT); + ff_hevc_unref_frame(frame, HEVC_FRAME_FLAG_OUTPUT); if (ret < 0) return ret; - av_log(s->avctx, AV_LOG_DEBUG, - "Output frame with POC %d.\n", frame->poc); - return 1; + av_log(s->avctx, AV_LOG_DEBUG, "%s frame with POC %d.\n", + discard ? "Discarded" : "Output", frame->poc); + continue; } - - if (s->seq_output != s->seq_decode) - s->seq_output = (s->seq_output + 1) & HEVC_SEQUENCE_COUNTER_MASK; - else - break; - } while (1); - - return 0; -} - -void ff_hevc_bump_frame(HEVCContext *s) -{ - int dpb = 0; - int min_poc = INT_MAX; - int i; - - for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - HEVCFrame *frame = &s->DPB[i]; - if ((frame->flags) && - frame->sequence == s->seq_output && - frame->poc != s->poc) { - dpb++; - } - } - - if (s->ps.sps && dpb >= s->ps.sps->temporal_layer[s->ps.sps->max_sub_layers - 1].max_dec_pic_buffering) { - for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - HEVCFrame *frame = &s->DPB[i]; - if ((frame->flags) && - frame->sequence == s->seq_output && - frame->poc != s->poc) { - if (frame->flags == HEVC_FRAME_FLAG_OUTPUT && frame->poc < min_poc) { - min_poc = frame->poc; - } - } - } - - for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - HEVCFrame *frame = &s->DPB[i]; - if (frame->flags & HEVC_FRAME_FLAG_OUTPUT && - frame->sequence == s->seq_output && - frame->poc <= min_poc) { - frame->flags |= HEVC_FRAME_FLAG_BUMPING; - } - } - - dpb--; + return 0; } } @@ -384,7 +319,7 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *ref = &s->DPB[i]; - if (ref->f && ref->sequence == s->seq_decode) { + if (ref->f) { if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc)) return ref; } @@ -427,8 +362,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) } frame->poc = poc; - frame->sequence = HEVC_SEQUENCE_COUNTER_INVALID; - frame->flags = 0; + frame->flags = HEVC_FRAME_FLAG_UNAVAILABLE; if (s->avctx->active_thread_type == FF_THREAD_FRAME) ff_progress_frame_report(&frame->tf, INT_MAX); From patchwork Tue Jul 16 17:11:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 50582 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:40f5:b0:482:c625:d099 with SMTP id lb53csp466713vqb; Tue, 16 Jul 2024 11:14:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU9hu5502WpoQk7Ip2KYj4zSt250o2EFglGOPoJ6bBFAXlAZobmnJ8BhITxMW3V581rCiNd13fHIp4x1bqZkY6FsL8F7MQxsE2Gzg== X-Google-Smtp-Source: AGHT+IF9LekpD90gDBWy/s/WS7eorfdlxrRbiAj7m16uKY+StZ3GPZovJm68tppSfw5jkNs8PdfH X-Received: by 2002:a2e:9d85:0:b0:2ec:18e5:e68f with SMTP id 38308e7fff4ca-2eef41d8d0amr21310571fa.33.1721153682314; Tue, 16 Jul 2024 11:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1721153682; cv=none; d=google.com; s=arc-20160816; b=RgGQR7RRqV6c16KYycUrgD9QlrROiTJ4k368JRKcEU6nNno8sofShbFis4yA9VuQpg 1isSNIuN0swa39gVkeE8LimpIGuWdLSjmhpHAoHVJqU9hGO0XWySsY8Z45Opfv8RbrME yV9sLszZGE4qyHwQo8g2ejlWSTx5cYwCxnHclVYHjWrizHb/uXA8A2NiPHm/QAQHRfLH udkhSeqqHBHdAxVBjMVKry30IctxOeBIg1Bu9rGZX8LjzvH/91SeSm1By+sdEhBT5cVz QG45SBlLDIo62NJxajPEMNEJh2ovJu5ZdsPuXnL4DCjVx64CWTXCiewg44TBfL/oo6td fXXQ== 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=BJ33ZgzdqZWXy6CREagfBIyctLy8OTZIh7meAMiP6uQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=NWY13Tz9pI2ETVAi+rC7hyc/KyIPERDzIpP379FqC4eBDdshB8T5hvdWvKYwpd7Mbj /R+oMjgGtML6PJqoIkHBwbf18C0Mhm5V8CZ5nHtcNLwzcosk4Apk2LY/q1PsqVb8XbCk Iudvv9CyUOj/2jW9Jmid5hOjprU30UFonkBZL1P6Rj3a0rT5kSyU26gh166w4LSyjWUw 0aOczSGPZNPDGK8cc6NQAWJcqzbB5x6GJI+SG4YcJ+3hER0FCMXxvkJHiTovdY5CzQob BKSnN5m4YUzOqh9+AyugKY0GTcfLdTLHp1aLryhlzFuw4y+cWhO8a8yRNmgAFwAFVWB+ Llsw==; 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=dIN4pgrh; 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 38308e7fff4ca-2eee179d251si21066021fa.9.2024.07.16.11.14.41; Tue, 16 Jul 2024 11:14:42 -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=dIN4pgrh; 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 C5D8168D86A; Tue, 16 Jul 2024 21:14:11 +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 0CFDA68D8D0 for ; Tue, 16 Jul 2024 21:13:59 +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=dIN4pgrh; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id A2E424E04 for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id R8aGaFE7n-lN for ; Tue, 16 Jul 2024 19:16:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1721150189; bh=n9/Scd7Gf0szI2YeK4eeliC6MI5LN3iYfDnBAgTCiHI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dIN4pgrhw/aJzKEVTsj1A6X6q3Sw5jiAYD1dUgFJ7hkSmjXvvmLx/EtmT3OZVCQ4z lYPXP32IhF4eHsB6T2SyqZeCFOy7vvF/afHm/DyPA4obgqzyUc/3VhcOHIDKEMg9m5 HpiUULD/spVjGM3HrXjV4UnnsrTkApRsSyD9w1xz6UD356Z7qRPDbcQYb7wDmSJilm Rp8Kx4NO7nahwMq48lLWOSR5grwy9glY7ux7PE9jNISlATstmoQrG7e+gA9+5Scsj9 DzRtGPKCoCaxpKDDt1JNJzg2mb8ej+ZIK2iO0f8ANvQUBGjzawFFvwoMxus9WEbwQd WLcvgDOkx4q8g== 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 0D99F4E11 for ; Tue, 16 Jul 2024 19:16:29 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 054F23A3632 for ; Tue, 16 Jul 2024 19:16:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2024 19:11:54 +0200 Message-ID: <20240716171155.31838-39-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716171155.31838-1-anton@khirnov.net> References: <20240716171155.31838-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 39/39] lavc/hevcdec: call ff_thread_finish_setup() even if hwaccel is in use 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: TXcf1nPyiNHo Serializing frame threading for non-threadsafe hwaccels is handled at the generic level, the decoder does not need to care about it. --- libavcodec/hevc/hevcdec.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c index 28835f48d6..622d9eeb84 100644 --- a/libavcodec/hevc/hevcdec.c +++ b/libavcodec/hevc/hevcdec.c @@ -3027,8 +3027,9 @@ static int hevc_frame_start(HEVCContext *s) ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0); if (ret < 0) goto fail; - } else - ff_thread_finish_setup(s->avctx); + } + + ff_thread_finish_setup(s->avctx); return 0;