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 CD0F4443F0 for ; Fri, 9 Sep 2022 06:31:25 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2454E68BAF2; Fri, 9 Sep 2022 09:31:22 +0300 (EEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E7DBA68B9F7 for ; Fri, 9 Sep 2022 09:31:14 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662705080; x=1694241080; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:content-transfer-encoding: mime-version; bh=BPZZa+lCUCCkH2cttfzwJ1nuYLYIAFiLUEkKQyL02ZI=; b=eI6BkWhaEy0o5pJ4gkuHqfsCGk0d86o/lm6FELjgbYOYrMu7BkL5/mh1 VoAmbqM5/0v5O03OVZ0ZW1pFXmyllIU4oOmJKJX1LyBO2JzNVhc7w1BpU OOngPfMIzTh0PvFhFcIntHIOXyuY/h8UXNrY/SyW8sx2U8nsIABZHr8Lp csC99fL4FHNH6Siwd0Mw63nmUtt+Y4kHkxZ07Q2m/5zrjlMLJsiDmlfTs VNZG+IVJCOMtS8t9tUpwCNYd+/b4fUBvmRk/WNjnWwQ9F60tFiTiLQrUC 7Z1Ep0MEpY9+2ojez3da7Acx5i/oG+Of2FiE96ubotBvkVNxl6X1Dyj9A g==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="361366718" X-IronPort-AV: E=Sophos;i="5.93,302,1654585200"; d="scan'208";a="361366718" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2022 23:31:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,302,1654585200"; d="scan'208";a="648335889" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga001.jf.intel.com with ESMTP; 08 Sep 2022 23:31:12 -0700 Received: from orsmsx608.amr.corp.intel.com (10.22.229.21) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 8 Sep 2022 23:31:12 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX608.amr.corp.intel.com (10.22.229.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 8 Sep 2022 23:31:11 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Thu, 8 Sep 2022 23:31:11 -0700 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.42) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Thu, 8 Sep 2022 23:31:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FwNZ0kDf3ymsNW7QvdzKXrVBdeJ5hNogLxdt/yNVMNIHG793w1KngIVsvgj57gsDxhG1VgDMQxfcYH6Vu0wA4cnffNSmiJsNXJ9IO4ISE6GmD0o7YUqTryA7DUQmfHsB/cQo5M2oEtRd/qKXkEiDkNEyEWoLtLu8NOIkV574/1s/y6EQp2ynfvLV1SYXN7I9WKxcYBuZcbPorvgfZVnb9uTdGUl7vFZNEInPwVGJeANChNMjrQUlR4z4buaZvqCHON50kbITmEbcJ8XBmnHebeZ6qc7daKLKwdv2xQjSCqAhqYaZto0jKoeEz79pGJGZs8E496KjEe5H0p8hH1Jwog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BPZZa+lCUCCkH2cttfzwJ1nuYLYIAFiLUEkKQyL02ZI=; b=L/V93eOo9xWPx+pp6prbMfNKpudp9fo81PepS4CxdUvT93vsiW+vfRZM7tRPs7rqWZBBCzLmhepyz/nzBw/oKwBelLl7ogUGOWieQNyBOJeq8/pR62c5H6rLZQ2EJ1Ptk+0zLEPYOq+mWtTTf4hqT29KC4+2+7SbqoUHrJCRy2YEJiWIyiOa9y1tiiEBJLKY97RgR39yUxZLxM6IqRxuFmzisAOdSw9ubH811sQbG64iIUHMaXVYYeR81nz5KidLMN6PanBokHrMMfo9zHanzhkSDx/zHSPi9bNnkGxygONeHCDGOUBhkc7sN+7oCmSD9PGuGwQ3ojKAyz3RuS/oXA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from BN9PR11MB5515.namprd11.prod.outlook.com (2603:10b6:408:104::8) by SN7PR11MB6923.namprd11.prod.outlook.com (2603:10b6:806:2aa::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.16; Fri, 9 Sep 2022 06:31:09 +0000 Received: from BN9PR11MB5515.namprd11.prod.outlook.com ([fe80::3804:a5ab:68a9:9304]) by BN9PR11MB5515.namprd11.prod.outlook.com ([fe80::3804:a5ab:68a9:9304%4]) with mapi id 15.20.5612.019; Fri, 9 Sep 2022 06:31:09 +0000 From: "Xiang, Haihao" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [FFmpeg-devel] [PATCH] lavu/pixdesc: favour formats where bit depth exactly matches Thread-Index: AQHYw/7UKNhp7uz9LkmqxbL5iyfCr63Wo2wA Date: Fri, 9 Sep 2022 06:31:09 +0000 Message-ID: <53d25096a99c928cc3f2c158ccf2140ec1569c0a.camel@intel.com> References: <20220909034611.390710-1-philipl@overt.org> In-Reply-To: <20220909034611.390710-1-philipl@overt.org> Accept-Language: en-AS, zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Evolution 3.28.5-0ubuntu0.18.04.2 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: BN9PR11MB5515:EE_|SN7PR11MB6923:EE_ x-ms-office365-filtering-correlation-id: ad280955-c37f-482b-5686-08da922ce1e6 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4fJMs1oy2uiESfXfVOekY7DoUF3No2Pk6VTqWF99+MbkQRVoQZy5prJgua5yhjpuwSdj9rkFjXTilzeVOe/Q1v++xHm2VHSEycVWcDPGiz4fVKbvGxR9viVmTaD5w+OAToF6esL0S8jItkmtiypW2g1q7EOJO7dKbwLEkdrvWfgztOD4gvV/PKiv0QFuJ06OumjhO5qkMUlHmNakzoN7mlV5qkgCKepoj4U42TmPV1ly7b8rPK+J4BO4687w+JX8i3P2wVLdkN+wBrrVxIkYcAfoiN7p2kBdgFQxv+JwBHm9bxjCnXrQZRaktkUXH5L2O6/rB5W8Z7ysdEB4edi61BIXp0HrpcksHp+j1XltLPgfvdGjis5gAcfM3S++J6o9oub+C604MaWOIRxwQGQ35tuNd1tXG5axkTLp+OCGW42K0gJiCi3ARvZRerqSJG05xcM5Msxbv/a3VUKmiH6rH9n3fB77/OBJ2SARkmPUVdaThrur2j4Gd1rp7Y1LXxfIAQ2d7Usk9mUdRnIgQq0XsEC8tBiiDbe4xjKLo4748dfWllTSDKCZLWRMzYIe+VBfNXO8xzyvICuTh7gWscrRXWaUYFBW/DtP9gC0tWJu4icet0w5rXvHjiXHdWrlwcbqd/I4NrfpdS9J2P/udXBWLBtoPW3UpQlCvGfxIhLm+AET/k1VCvRRML0beRucI2K6UilVopBIIaQ+63Ri4YB8lfbQ1BnFt/Y6GtSPm0AoIdY+AIdPw0kjZ8/ND6tFJWNVesDeAGrjfzijLrkW98MUpQ3lGDg6GGbgqiar4qXl1wVZUHGvdmRwJRDfxL3oM07p x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN9PR11MB5515.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(396003)(136003)(39860400002)(376002)(366004)(346002)(66946007)(66476007)(66556008)(66446008)(64756008)(6486002)(4326008)(91956017)(86362001)(76116006)(2616005)(8936002)(5660300002)(71200400001)(6916009)(316002)(8676002)(2906002)(36756003)(41300700001)(6512007)(26005)(38070700005)(6506007)(478600001)(82960400001)(38100700002)(122000001)(186003)(83380400001)(99106002)(309714004); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?T2JaMGdHTm9GY21tNFdOWjRhZkFKUldDN3VUaG5wY1dUbDBxdmlzZUhFR3Yy?= =?utf-8?B?Q0djeWdlUW1jLzUzazlMZmxESG5STG5wVXU4dmNQUTJXNVRIY0M2aytwcjhC?= =?utf-8?B?ZkhlV1BXejJZL2JaaUpzUVN5VmtTTkduRU1ScTNsamx0VXUxUnBCdjRCM0pS?= =?utf-8?B?TDRBNithcWZWaE16eEtDYXlES3JxMmpYVU85MVU5RW5aWWQ2MHV3cW9oZk80?= =?utf-8?B?NFdHQ2xuNHRIbXpqUzU2Sy9aY1V1bElyY2tlMUpvemU1WWxBa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UXFqUTE2bWtKbkhuYzZXUG11bkdUbTZkTFFTRjQx?= =?utf-8?B?OHRxaklLSEdpQzZNOW1ZTUVpWkVKYWhraVl6YVpIeC83RlF5UkF1UjlTQ0FV?= =?utf-8?B?T0E9PQ==?= Content-ID: <5341AFFF74F8EE48A8B6A5AF03656652@namprd11.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5515.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad280955-c37f-482b-5686-08da922ce1e6 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Sep 2022 06:31:09.2063 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: OQ1Ju4th24Yz6CT8omNKQlN0zK7ebluL3PF6KmaUV1fmXONS698iE5VDm8A9FSuf6B6II2Ez7owl6a8HGdkGkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB6923 X-OriginatorOrg: intel.com Subject: Re: [FFmpeg-devel] [PATCH] lavu/pixdesc: favour formats where bit depth exactly matches 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 Cc: "philipl@overt.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Thu, 2022-09-08 at 20:46 -0700, Philip Langdale wrote: > Since introducing the various packed formats used by VAAPI (and p012), > we've noticed that there's actually a gap in how > av_find_best_pix_fmt_of_2 works. It doesn't actually assign any value > to having the same bit depth as the source format, when comparing > against formats with a higher bit depth. This usually doesn't matter, > because av_get_padded_bits_per_pixel() will account for it. > > However, as many of these formats use padding internally, we find that > av_get_padded_bits_per_pixel() actually returns the same value for the > 10 bit, 12, bit, 16 bit flavours, etc. In these tied situations, we end 12 bit, > up just picking the first of the two provided formats, even if the > second one should be preferred because it matches the actual bit depth. > > This bug already existed if you tried to compare yuv420p10 against p016 > and p010, for example, but it simply hadn't come up before so we never > noticed. > > But now, we actually got a situation in the VAAPI VP9 decoder where it > offers both p010 and p012 because Profile 3 could be either depth and > ends up picking p012 for 10 bit content due to the ordering of the > testing. > > In addition, in the process of testing the fix, I realised we have the > same gap when it comes to chroma subsampling - we do not favour a > format that has exactly the same subsampling vs one with less > subsampling when all else is equal. > > To fix this, I'm introducing a small score penalty if the bit depth or > subsampling doesn't exactly match the source format. This will break > the tie in favour of the format with the exact match, but not offset > any of the other scoring penalties we already have. > > I have added a set of tests around these formats which will fail > without this fix. > > Signed-off-by: Philip Langdale > --- > libavutil/pixdesc.c | 16 +++++- > libavutil/tests/pixfmt_best.c | 93 ++++++++++++++++++++++++++++------- > tests/ref/fate/pixfmt_best | 2 +- > 3 files changed, 89 insertions(+), 22 deletions(-) > > diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c > index d7c6ebfdc4..412e257a30 100644 > --- a/libavutil/pixdesc.c > +++ b/libavutil/pixdesc.c > @@ -3004,6 +3004,11 @@ static int get_pix_fmt_score(enum AVPixelFormat > dst_pix_fmt, > if ((ret = get_pix_fmt_depth(&dst_min_depth, &dst_max_depth, > dst_pix_fmt)) < 0) > return -3; > > + // Favour formats where bit depth exactly matches. If all other scoring > is > + // equal, we'd rather use a lower bit depth that matches the source. > + if (src_min_depth != dst_min_depth || src_max_depth != dst_max_depth) > + score -= 64; > + > src_color = get_color_type(src_desc); > dst_color = get_color_type(dst_desc); > if (dst_pix_fmt == AV_PIX_FMT_PAL8) > @@ -3020,14 +3025,21 @@ static int get_pix_fmt_score(enum AVPixelFormat > dst_pix_fmt, > } > > if (consider & FF_LOSS_RESOLUTION) { > + // Apply a large penalty if there's a loss of resolution, but also > apply > + // a small penalty of the dst resolution is higher so that we favour > + // exactly matching formats. > if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w) { > loss |= FF_LOSS_RESOLUTION; > score -= 256 << dst_desc->log2_chroma_w; > - } > + } else if (dst_desc->log2_chroma_w < src_desc->log2_chroma_w) > + score -= 32; > + > if (dst_desc->log2_chroma_h > src_desc->log2_chroma_h) { > loss |= FF_LOSS_RESOLUTION; > score -= 256 << dst_desc->log2_chroma_h; > - } > + } else if (dst_desc->log2_chroma_h < src_desc->log2_chroma_h) > + score -= 32; > + > // don't favor 422 over 420 if downsampling is needed, because 420 > has much better support on the decoder side > if (dst_desc->log2_chroma_w == 1 && src_desc->log2_chroma_w == 0 && > dst_desc->log2_chroma_h == 1 && src_desc->log2_chroma_h == 0 ) { > diff --git a/libavutil/tests/pixfmt_best.c b/libavutil/tests/pixfmt_best.c > index 0542af494f..b5d4d04976 100644 > --- a/libavutil/tests/pixfmt_best.c > +++ b/libavutil/tests/pixfmt_best.c > @@ -39,32 +39,59 @@ static const enum AVPixelFormat pixfmt_list[] = { > AV_PIX_FMT_VAAPI, > }; > > -static enum AVPixelFormat find_best(enum AVPixelFormat pixfmt) > +static const enum AVPixelFormat semiplanar_list[] = { > + AV_PIX_FMT_P016, > + AV_PIX_FMT_P012, > + AV_PIX_FMT_P010, > + AV_PIX_FMT_NV12, > +}; > + > +static const enum AVPixelFormat packed_list[] = { > + AV_PIX_FMT_XV36, > + AV_PIX_FMT_XV30, > + AV_PIX_FMT_VUYX, > + AV_PIX_FMT_Y212, > + AV_PIX_FMT_Y210, > + AV_PIX_FMT_YUYV422, > +}; > + > +typedef enum AVPixelFormat (*find_best_t)(enum AVPixelFormat pixfmt); > + > +#define find_best_wrapper(name, list) \ > +static enum AVPixelFormat find_best_ ## name (enum AVPixelFormat pixfmt) \ > +{ \ > + enum AVPixelFormat best = AV_PIX_FMT_NONE; \ > + int i; \ > + for (i = 0; i < FF_ARRAY_ELEMS(list); i++) \ > + best = av_find_best_pix_fmt_of_2(best, list[i], \ > + pixfmt, 0, NULL); \ > + return best; \ > +} > + > +find_best_wrapper(base, pixfmt_list) > +find_best_wrapper(seminplanar, semiplanar_list) > +find_best_wrapper(packed, packed_list) > + > +static void test(enum AVPixelFormat input, enum AVPixelFormat expected, > + int *pass, int *fail, find_best_t find_best_fn) > { > - enum AVPixelFormat best = AV_PIX_FMT_NONE; > - int i; > - for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++) > - best = av_find_best_pix_fmt_of_2(best, pixfmt_list[i], > - pixfmt, 0, NULL); > - return best; > + enum AVPixelFormat output = find_best_fn(input); > + if (output != expected) { > + printf("Matching %s: got %s, expected %s\n", > + av_get_pix_fmt_name(input), > + av_get_pix_fmt_name(output), > + av_get_pix_fmt_name(expected)); > + ++(*fail); > + } else > + ++(*pass); > } > > int main(void) > { > - enum AVPixelFormat output; > int i, pass = 0, fail = 0; > > -#define TEST(input, expected) do { \ > - output = find_best(input); \ > - if (output != expected) { \ > - printf("Matching %s: got %s, expected %s\n", \ > - av_get_pix_fmt_name(input), \ > - av_get_pix_fmt_name(output), \ > - av_get_pix_fmt_name(expected)); \ > - ++fail; \ > - } else \ > - ++pass; \ > - } while (0) > +#define TEST(input, expected) \ > + test(input, expected, &pass, &fail, find_best_base); > > // Same formats. > for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++) > @@ -137,6 +164,34 @@ int main(void) > // Opaque formats are least unlike each other. > TEST(AV_PIX_FMT_DXVA2_VLD, AV_PIX_FMT_VDPAU); > > +#define TEST_SEMIPLANAR(input, expected) \ > + test(input, expected, &pass, &fail, find_best_seminplanar); > + > + // Same formats. > + for (i = 0; i < FF_ARRAY_ELEMS(semiplanar_list); i++) > + TEST_SEMIPLANAR(semiplanar_list[i], semiplanar_list[i]); > + > + // Formats containing the same data in different layouts. > + TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P, AV_PIX_FMT_NV12); > + TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P10, AV_PIX_FMT_P010); > + TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P12, AV_PIX_FMT_P012); > + TEST_SEMIPLANAR(AV_PIX_FMT_YUV420P16, AV_PIX_FMT_P016); > + > +#define TEST_PACKED(input, expected) \ > + test(input, expected, &pass, &fail, find_best_packed); > + > + // Same formats. > + for (i = 0; i < FF_ARRAY_ELEMS(packed_list); i++) > + TEST_PACKED(packed_list[i], packed_list[i]); > + > + // Formats containing the same data in different layouts. > + TEST_PACKED(AV_PIX_FMT_YUV444P, AV_PIX_FMT_VUYX); > + TEST_PACKED(AV_PIX_FMT_YUV444P10, AV_PIX_FMT_XV30); > + TEST_PACKED(AV_PIX_FMT_YUV444P12, AV_PIX_FMT_XV36); > + TEST_PACKED(AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUYV422); > + TEST_PACKED(AV_PIX_FMT_YUV422P10, AV_PIX_FMT_Y210); > + TEST_PACKED(AV_PIX_FMT_YUV422P12, AV_PIX_FMT_Y212); > + > printf("%d tests passed, %d tests failed.\n", pass, fail); > return !!fail; > } > diff --git a/tests/ref/fate/pixfmt_best b/tests/ref/fate/pixfmt_best > index 783c5fe640..63911e7198 100644 > --- a/tests/ref/fate/pixfmt_best > +++ b/tests/ref/fate/pixfmt_best > @@ -1 +1 @@ > -75 tests passed, 0 tests failed. > +95 tests passed, 0 tests failed. Patchset LGTM and works well for me. BRs Haihao _______________________________________________ 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".