From patchwork Mon Apr 22 21:22:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 48227 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:2d06:b0:1a9:af23:56c1 with SMTP id tw6csp32570pzb; Mon, 22 Apr 2024 14:21:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWpkLnhKA7rDqaONMTi1G6WBLUZ7eBZ9kwDdL+uZzIApeda8JddgWi+Z4P4tb8q64B6lBd9/96goN9wQRrr3B1wOrGI2R/dFfbdAw== X-Google-Smtp-Source: AGHT+IEpbPu3qMkz+AGRuvUNpSDPNgrf827YRDsK1fa0QPouJtTp7nALFxD6xN3okHb+/Wf+U+d6 X-Received: by 2002:a2e:2e18:0:b0:2da:e75:e755 with SMTP id u24-20020a2e2e18000000b002da0e75e755mr8828876lju.8.1713820911693; Mon, 22 Apr 2024 14:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1713820911; cv=none; d=google.com; s=arc-20160816; b=ckVIj5eAoeot5ZuZoQlhdlx+Hm7dLYbQlsbhl1apv5Uo4F/V0NQaQh+3z7OUFrWphr eTvbyo9yA+7R0bXweF6NnFC7VqExpdOg2pdYeVzcCCAoPa8N9IZZyfYyNzYuzHN1sd3Z GbZxFHl3NReFqn5AsiVn8OqUheYZPD29M0PK7/xPdVIlqSd6cjED0tY2pzFZjGzFcCvl zhQwp5mcpmJSZ87TL/QHwaO8XdUGAFKMxp3BjX5bA1TDGs8xD4ZRQDbkqKmoAGiQ1kB+ Fqu0C29i0d1i3FCwdg3YZzQtFXOueNky3sWmZneiUC6dv1L1Sk3Cqsw6OCXguDzssqYs kVIg== 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:in-reply-to:references:to:from:content-language :user-agent:mime-version:date:message-id:dkim-signature:delivered-to; bh=SmLLWnb4YzpVhg+N0kZn34EZQ3mhmoD/yGnpEs8U9wo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=iP6RKNQKLV1SL2GCo1Kt4QsGi4RiVuOp9UR7OSlcfLRpUai2rXgFThAZwjDBQMQO2r /kUVPkwbLgkIE0steCJhYjzIkP6RkSm/3Glpo4N+wSh59Vv9HUP8/B/uV5udjvoLI79K AetY5e+5Pbs4+fBcUQwqh3rCU0ER7HBOQgc+Zby+fmz88u76Dn5fkqYBK/TkUtCED9s2 NDkKVGtUw/COIz1JtyWthBZ34hvcgvSqNX2Ur973WtfERDutyTkgYaQYHoZ2jV8xOPBA 4oXCgienk66fzBnCxUQUokJJ6iihq2E+n2tDbcT5AvMeja4Z0neK9M1J/bE7iU5x3D/U E4Cg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20230601.gappssmtp.com header.s=20230601 header.b=LPVkDwUp; 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 r1-20020a50aac1000000b0056e113a5a26si6119353edc.464.2024.04.22.14.21.51; Mon, 22 Apr 2024 14: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=@jkqxz-net.20230601.gappssmtp.com header.s=20230601 header.b=LPVkDwUp; 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 B9FEB68D388; Tue, 23 Apr 2024 00:21:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ADCF968D0E0 for ; Tue, 23 Apr 2024 00:21:42 +0300 (EEST) Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-41a70466b77so9047725e9.0 for ; Mon, 22 Apr 2024 14:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20230601.gappssmtp.com; s=20230601; t=1713820902; x=1714425702; darn=ffmpeg.org; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=VBr0pdvv1yYPHBRbYHAhP+G55t6hR6qhs6xEtwdfq4E=; b=LPVkDwUpi/Ug/gUV6fQxrcTjv7ATVsGgIomSVpjaH+w4zOpeesOIwGVfyueVWD3RrP yfXHonk0DTUEEx0lo0sjb4F6rSqt6bkw4GzvPBXQD2j2schf+2NR1+ixWvfKtEcEnfgM GgoU3ERRhStS9L0RDYZqlZKw8yN3p/ukbu8FxQrNc5ogxrE5JTvXUS55wmdzWIGVuCdS DKl1DLvS7t/TGa2bUEkVNqkNd6wJ69l6P2k9JK8LEE+AVNZ4TLALXCE25mTYRsqy9PyD HU409AZ7tW8dxPJNR2aKnc5aavGU55nHB6zDfYoqlnIW30ZFFm62BdoZfZR5Dt+tRzcy 1rcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713820902; x=1714425702; h=content-transfer-encoding:in-reply-to:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VBr0pdvv1yYPHBRbYHAhP+G55t6hR6qhs6xEtwdfq4E=; b=j31gbzpWGidBmEx/YUpRRDdBhGZwaMmS0jrULN79+iJ0BCsFvYxmKeozZwkZL/xJSz k14DRBomPeFYPOesWV1jdnM5kleMvvptYdVaN6OqUrxMGTzPZq2D2hJDD04SynvpSV0f zT4FKwQ2vxf/GwNcL/VGdTw1KRTq8vwbRjP4lp72vBjUTDDBdlGrUonYtoA33M8PKVbt iaPFaE5kIVlaSMUgsGNzVM62Khwdq7BYijxzpSpiA48s9yK0o2MZPN0I7+rWfIPuMtWp G9pHeX4s3vh+OBZ9naxAkRbsWhJ12RKWg3K4vBwuzTf+FHU5tpiBPtWewHZZLGDynQDW v/yw== X-Gm-Message-State: AOJu0YzCyNd08jwY75lZeAkgKbFugwebfCWTkMaZjGTJNQY+iny4bVHM Fb5TR6JnjAek1hmo4nKEAW6paETFgFWjbkhNeZ/JDdSo2OSYrRQNgd5+9V4Pk74p3xicavYHqsI 1 X-Received: by 2002:a05:600c:46c8:b0:414:d95:cc47 with SMTP id q8-20020a05600c46c800b004140d95cc47mr10796088wmo.30.1713820902028; Mon, 22 Apr 2024 14:21:42 -0700 (PDT) Received: from [192.168.0.15] (cpc92302-cmbg19-2-0-cust1183.5-4.cable.virginm.net. [82.1.212.160]) by smtp.gmail.com with ESMTPSA id t6-20020a05600c450600b0041a3e724fc5sm6004402wmo.19.2024.04.22.14.21.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Apr 2024 14:21:41 -0700 (PDT) Message-ID: <1bcdfb6e-8d63-4d1f-9cd9-631e79c03f5f@jkqxz.net> Date: Mon, 22 Apr 2024 22:22:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US From: Mark Thompson To: ffmpeg-devel@ffmpeg.org References: <20240318042111.21983-1-fei.w.wang@intel.com> <90d041b98b5d9ba69b093d9dcae168130389b364.camel@intel.com> <1fa0491e-4609-49ae-bad4-820ea63a52b0@jkqxz.net> <6aca0a524bb0862d07f6469097a4c1b1a991e222.camel@intel.com> <4bccfe20-83a0-4c8f-a6d3-974faf064dbc@jkqxz.net> In-Reply-To: <4bccfe20-83a0-4c8f-a6d3-974faf064dbc@jkqxz.net> Subject: [FFmpeg-devel] [PATCH 1/2] lavc/h265_profile_level: Expand profile compatibility checking 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: 7+BwOD23DM3+ Replace existing get_profile() with find_profile(), which finds the lowest compatible profile rather than requiring an exact match. --- libavcodec/h265_profile_level.c | 73 +++++++++++++++++++++------------ libavcodec/h265_profile_level.h | 70 ++++++++++++++++++++++++++++++- libavcodec/vaapi_hevc.c | 2 +- libavcodec/vdpau_hevc.c | 2 +- 4 files changed, 117 insertions(+), 30 deletions(-) diff --git a/libavcodec/h265_profile_level.c b/libavcodec/h265_profile_level.c index 7ff9681f65..4bc72414cb 100644 --- a/libavcodec/h265_profile_level.c +++ b/libavcodec/h265_profile_level.c @@ -119,41 +119,60 @@ static const H265ProfileDescriptor h265_profiles[] = { 5, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 4000, 4400, 6.000, 0.5, 6 }, }; +_Static_assert(H265_PROFILE_COUNT == FF_ARRAY_ELEMS(h265_profiles), + "Incorrect H.265 profiles table."); -const H265ProfileDescriptor *ff_h265_get_profile(const H265RawProfileTierLevel *ptl) + +const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl, + int profile) { - int i; + const H265ProfileDescriptor *desc; + + av_assert0(profile >= 0 && profile < H265_PROFILE_COUNT); if (ptl->general_profile_space) - return NULL; + return 0; - for (i = 0; i < FF_ARRAY_ELEMS(h265_profiles); i++) { - const H265ProfileDescriptor *profile = &h265_profiles[i]; + desc = &h265_profiles[profile]; - if (ptl->general_profile_idc && - ptl->general_profile_idc != profile->profile_idc) - continue; - if (!ptl->general_profile_compatibility_flag[profile->profile_idc]) - continue; + if (ptl->general_profile_idc && + ptl->general_profile_idc != desc->profile_idc) + return 0; + if (!ptl->general_profile_compatibility_flag[desc->profile_idc]) + return 0; -#define check_flag(name) \ - if (profile->name < 2) { \ - if (profile->name != ptl->general_ ## name ## _constraint_flag) \ - continue; \ - } - check_flag(max_14bit); - check_flag(max_12bit); - check_flag(max_10bit); - check_flag(max_8bit); - check_flag(max_422chroma); - check_flag(max_420chroma); - check_flag(max_monochrome); - check_flag(intra); - check_flag(one_picture_only); - check_flag(lower_bit_rate); +#define check_flag(flag) \ + if (desc->flag < 2 && \ + desc->flag > ptl->general_ ## flag ## _constraint_flag) \ + return 0; + check_flag(max_14bit); + check_flag(max_12bit); + check_flag(max_10bit); + check_flag(max_8bit); + check_flag(max_422chroma); + check_flag(max_420chroma); + check_flag(max_monochrome); + check_flag(intra); + check_flag(one_picture_only); + check_flag(lower_bit_rate); #undef check_flag - return profile; + return 1; +} + + +const H265ProfileDescriptor *ff_h265_get_profile(int profile) +{ + av_assert0(profile >= 0 && profile < H265_PROFILE_COUNT); + + return &h265_profiles[profile]; +} + +const H265ProfileDescriptor *ff_h265_find_profile(const H265RawProfileTierLevel *ptl) +{ + for (int p = 0; p < H265_PROFILE_COUNT; p++) { + if (ff_h265_profile_compatible(ptl, p)) + return &h265_profiles[p]; } return NULL; @@ -171,7 +190,7 @@ const H265LevelDescriptor *ff_h265_guess_level(const H265RawProfileTierLevel *pt int i; if (ptl) - profile = ff_h265_get_profile(ptl); + profile = ff_h265_find_profile(ptl); else profile = NULL; if (!profile) { diff --git a/libavcodec/h265_profile_level.h b/libavcodec/h265_profile_level.h index cd30ac5c50..f403f63211 100644 --- a/libavcodec/h265_profile_level.h +++ b/libavcodec/h265_profile_level.h @@ -24,6 +24,49 @@ #include "cbs_h265.h" +// Enumeration of all H.265 profiles. +// The list is ordered to match table A.10; numeric values are an index +// into the latest version of this table and have no codec meaning. +enum { + H265_PROFILE_MONOCHROME, + H265_PROFILE_MONOCHROME_10, + H265_PROFILE_MONOCHROME_12, + H265_PROFILE_MONOCHROME_16, + H265_PROFILE_MAIN, + H265_PROFILE_SCREEN_EXTENDED_MAIN, + H265_PROFILE_MAIN_10, + H265_PROFILE_SCREEN_EXTENDED_MAIN_10, + H265_PROFILE_MAIN_12, + H265_PROFILE_MAIN_STILL_PICTURE, + H265_PROFILE_MAIN_10_STILL_PICTURE, + H265_PROFILE_MAIN_422_10, + H265_PROFILE_MAIN_422_12, + H265_PROFILE_MAIN_444, + H265_PROFILE_HIGH_THROUGHPUT_444, + H265_PROFILE_SCREEN_EXTENDED_MAIN_444, + H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444, + H265_PROFILE_MAIN_444_10, + H265_PROFILE_HIGH_THROUGHPUT_444_10, + H265_PROFILE_SCREEN_EXTENDED_MAIN_444_10, + H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_10, + H265_PROFILE_MAIN_444_12, + H265_PROFILE_HIGH_THROUGHPUT_444_14, + H265_PROFILE_SCREEN_EXTENDED_HIGH_THROUGHPUT_444_14, + H265_PROFILE_MAIN_INTRA, + H265_PROFILE_MAIN_10_INTRA, + H265_PROFILE_MAIN_12_INTRA, + H265_PROFILE_MAIN_422_10_INTRA, + H265_PROFILE_MAIN_422_12_INTRA, + H265_PROFILE_MAIN_444_INTRA, + H265_PROFILE_MAIN_444_10_INTRA, + H265_PROFILE_MAIN_444_12_INTRA, + H265_PROFILE_MAIN_444_16_INTRA, + H265_PROFILE_MAIN_444_STILL_PICTURE, + H265_PROFILE_MAIN_444_16_STILL_PICTURE, + H265_PROFILE_HIGH_THROUGHPUT_444_16_INTRA, + H265_PROFILE_COUNT, +}; + typedef struct H265LevelDescriptor { char name[4]; // Large enough for all current levels like "4.1" uint8_t level_idc; @@ -70,7 +113,32 @@ typedef struct H265ProfileDescriptor { } H265ProfileDescriptor; -const H265ProfileDescriptor *ff_h265_get_profile(const H265RawProfileTierLevel *ptl); +/** + * Test whether the PTL structure is compatible with the given profile. + * + * @param ptl PTL structure to check. + * @param profile Profile to test compatibility with. Must be a valid + * H265_PROFILE_* value. + * @return Nonzero if compatible, zero if incompatible. + */ +const int ff_h265_profile_compatible(const H265RawProfileTierLevel *ptl, + int profile); + +/** + * Return profile descriptor for the given profile. + * + * @param profile Profile number; must be a valid H265_PROFILE_* value. + * @return Profile descriptor. + */ +const H265ProfileDescriptor *ff_h265_get_profile(int profile); + +/** + * Find the first profile compatible with the given PTL structure. + * + * @param ptl PTL structure to search for. + * @return First compatible profile, or NULL if no compatible profiles. + */ +const H265ProfileDescriptor *ff_h265_find_profile(const H265RawProfileTierLevel *ptl); /** diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c index 3bdd2dd1b8..77f55ff8b1 100644 --- a/libavcodec/vaapi_hevc.c +++ b/libavcodec/vaapi_hevc.c @@ -604,7 +604,7 @@ VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx) /* convert PTLCommon to H265RawProfileTierLevel */ ptl_convert(general_ptl, &h265_raw_ptl); - profile = ff_h265_get_profile(&h265_raw_ptl); + profile = ff_h265_find_profile(&h265_raw_ptl); if (!profile) { av_log(avctx, AV_LOG_WARNING, "HEVC profile is not found.\n"); goto end; diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c index 4cd7ce5621..a59a030b1c 100644 --- a/libavcodec/vdpau_hevc.c +++ b/libavcodec/vdpau_hevc.c @@ -478,7 +478,7 @@ static int vdpau_hevc_parse_rext_profile(AVCodecContext *avctx, VdpDecoderProfil /* convert PTLCommon to H265RawProfileTierLevel */ ptl_convert(general_ptl, &h265_raw_ptl); - profile = ff_h265_get_profile(&h265_raw_ptl); + profile = ff_h265_find_profile(&h265_raw_ptl); if (!profile) { av_log(avctx, AV_LOG_WARNING, "HEVC profile is not found.\n"); if (avctx->hwaccel_flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH) {