Re: [FFmpeg-devel] [PATCH 1/2] lavc/h265_profile_level: Expand profile compatibility checking

2024-04-24 Thread Xiang, Haihao
On Ma, 2024-04-22 at 22:22 +0100, Mark Thompson wrote:
> 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 = _profiles[i];
> +    desc = _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 _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 _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,
> + 

Re: [FFmpeg-devel] [PATCH 1/2] lavc/h265_profile_level: Expand profile compatibility checking

2024-04-22 Thread Michael Niedermayer
On Mon, Apr 22, 2024 at 10:22:06PM +0100, Mark Thompson wrote:
> 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(-)

breaks

TESTh265-levels
./tests/fate-run.sh fate-h265-levels "fate/fate-suite/" "" "ffmpeg" 'run 
libavcodec/tests/h265_levels' '' '/dev/null' '' '1' '' '' '' '' '' '' '' '' '' 
''
 ffmpeg/libavcodec/tests/h265_levels
Test h265-levels failed. Look at tests/data/fate/h265-levels.err for details.
Assertion profile >= 0 && profile < H265_PROFILE_COUNT failed at 
libavcodec/h265_profile_level.c:166
Aborted (core dumped)
threads=1
make: *** [tests/Makefile:311: fate-h265-levels] Error 134

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 1/2] lavc/h265_profile_level: Expand profile compatibility checking

2024-04-22 Thread Mark Thompson
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 = _profiles[i];
+desc = _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 _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 _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,
+