From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0E5BB454A2 for ; Sat, 28 Oct 2023 21:53:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 03FE468C98C; Sun, 29 Oct 2023 00:53:14 +0300 (EEST) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99D7A68C562 for ; Sun, 29 Oct 2023 00:53:07 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6A15640003 for ; Sat, 28 Oct 2023 21:53:06 +0000 (UTC) Date: Sat, 28 Oct 2023 23:53:05 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20231028215305.GG3543730@pb2> References: <20231027170446.63684-1-ffmpeg@haasn.xyz> <20231027214241.GB3543730@pb2> <20231028124638.GF3388@haasn.xyz> MIME-Version: 1.0 In-Reply-To: <20231028124638.GF3388@haasn.xyz> X-GND-Sasl: michael@niedermayer.cc Subject: Re: [FFmpeg-devel] [PATCH 1/8] swscale: fix sws_setColorspaceDetails after sws_init_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 Content-Type: multipart/mixed; boundary="===============2612660554095163354==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============2612660554095163354== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="q33HfhtkU2c6SwDo" Content-Disposition: inline --q33HfhtkU2c6SwDo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Oct 28, 2023 at 12:46:38PM +0200, Niklas Haas wrote: > On Fri, 27 Oct 2023 23:42:41 +0200 Michael Niedermayer wrote: > > On Fri, Oct 27, 2023 at 07:04:39PM +0200, Niklas Haas wrote: > > > From: Niklas Haas > > >=20 > > > More commonly, this fixes the case of sws_setColorspaceDetails after > > > sws_getContext, since the latter implies sws_init_context. > > >=20 > > > The problem here is that sws_init_context sets up the range conversion > > > and fast path tables based on the values of srcRange/dstRange at init > > > time. This may result in locking in a "wrong" path (either using > > > unscaled fast path when range conversion later required, or using > > > scaled slow path when range conversion becomes no longer required). > > >=20 > > > There are two way outs: > > >=20 > > > 1. Always initialize range conversion and unscaled converters, even if > > > they will be unused, and extend the runtime check. > > > 2. Re-do initialization if the values change after > > > sws_setColorspaceDetails. > > >=20 > > > I opted for approach 1 because it was simpler and easier to reason > > > about. > > > --- > > > libswscale/swscale.c | 2 +- > > > libswscale/utils.c | 5 +---- > > > 2 files changed, 2 insertions(+), 5 deletions(-) > > >=20 > > > diff --git a/libswscale/swscale.c b/libswscale/swscale.c > > > index 90e5b299ab..46ba68fe6a 100644 > > > --- a/libswscale/swscale.c > > > +++ b/libswscale/swscale.c > > > @@ -1016,7 +1016,7 @@ static int scale_internal(SwsContext *c, > > > reset_ptr(src2, c->srcFormat); > > > reset_ptr((void*)dst2, c->dstFormat); > > > =20 > > > - if (c->convert_unscaled) { > > > + if (c->convert_unscaled && !c->lumConvertRange && !c->chrConvert= Range) { > > > int offset =3D srcSliceY_internal; > > > int slice_h =3D srcSliceH; > > > =20 > > > diff --git a/libswscale/utils.c b/libswscale/utils.c > > > index e1ad685972..455955e907 100644 > > > --- a/libswscale/utils.c > > > +++ b/libswscale/utils.c > > > @@ -1728,9 +1728,7 @@ static av_cold int sws_init_single_context(SwsC= ontext *c, SwsFilter *srcFilter, > > > } > > > =20 > > > /* unscaled special cases */ > > > - if (unscaled && !usesHFilter && !usesVFilter && > > > - (c->srcRange =3D=3D c->dstRange || isAnyRGB(dstFormat) || > > > - isFloat(srcFormat) || isFloat(dstFormat))){ > > > + if (unscaled && !usesHFilter && !usesVFilter) { > > > ff_get_unscaled_swscale(c); > > > =20 > > > if (c->convert_unscaled) { > > > @@ -1738,7 +1736,6 @@ static av_cold int sws_init_single_context(SwsC= ontext *c, SwsFilter *srcFilter, > > > av_log(c, AV_LOG_INFO, > > > "using unscaled %s -> %s special converter\n", > > > av_get_pix_fmt_name(srcFormat), av_get_pix_fm= t_name(dstFormat)); > > > - return 0; > > > } > > > } > >=20 > > the av_log() message will be wrong if this path is unused >=20 > Indeed. Perhaps the only way to fix that would be to instead try > approach 2 and go through full reinit if any params change after > setColorspaceDetails. >=20 > > also this ties convert_unscaled to never do range conversion, if thats > > intended, i guess thats ok. Otherwise that maybe is a restriction > > we dont want to add. >=20 > In the original code, c->convert_unscaled is set behind a `c->srcRange > =3D=3D c->dstRange` check, so how is that a change in behavior? not "change in behavior" but it may be more complex if a yuv->yuv unscaled convert is added that supports range convert because before convert_unscaled is set only when it can be used afterwards convert_unscaled is always set but sometimes it then can be used with differing yuv ranges sometimes not. what i meant is that the conditions related to convert_unscaled could become more dispersed and duplciated _IF_ specific future code is added also its not just c->srcRange =3D=3D c->dstRange, the condition is more complex thx [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Freedom in capitalist society always remains about the same as it was in ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin --q33HfhtkU2c6SwDo Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCZT2CugAKCRBhHseHBAsP q9ESAJsG+fLuPhqgSFOYF8KBdrr7LYVuGACfQAMNB2/QXy7PhrfWvD5ubYewSYw= =U2ke -----END PGP SIGNATURE----- --q33HfhtkU2c6SwDo-- --===============2612660554095163354== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". --===============2612660554095163354==--