[FFmpeg-devel,RFC,2/2] lavc/vaapi_decode: find exact va_profile for HEVC_REXT

Submitted by Linjie Fu on April 3, 2019, 4:10 a.m.

Details

Message ID 20190403041022.18216-1-linjie.fu@intel.com
State New
Headers show

Commit Message

Linjie Fu April 3, 2019, 4:10 a.m.
Use the profile constraint flags to determine the exact va_profile for
HEVC_REXT.

Directly cast PTLCommon to H265RawProfileTierLevel, and use ff_h265_get_profile
to get the exact profile.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
---
[v2]: use constraint flags to determine the exact profile, expose the
codec-specific stuff at the beginning.
[RFC]: is it acceptable to cast PTLCommon to H265RawProfileTierLevel for
convenience? The members in PTLCommon should be strictly matched in
H265RawProfileTierLevel.

 libavcodec/vaapi_decode.c | 74 +++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 15 deletions(-)

Comments

Michael Niedermayer April 3, 2019, 10:38 p.m.
On Wed, Apr 03, 2019 at 12:10:22PM +0800, Linjie Fu wrote:
> Use the profile constraint flags to determine the exact va_profile for
> HEVC_REXT.
> 
> Directly cast PTLCommon to H265RawProfileTierLevel, and use ff_h265_get_profile
> to get the exact profile.
> 
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> ---
> [v2]: use constraint flags to determine the exact profile, expose the
> codec-specific stuff at the beginning.
> [RFC]: is it acceptable to cast PTLCommon to H265RawProfileTierLevel for
> convenience? The members in PTLCommon should be strictly matched in
> H265RawProfileTierLevel.
> 
>  libavcodec/vaapi_decode.c | 74 +++++++++++++++++++++++++++++++--------
>  1 file changed, 59 insertions(+), 15 deletions(-)

breaks build:

CC	libavcodec/vaapi_decode.o
libavcodec/vaapi_decode.c: In function ‘vaapi_decode_find_exact_profile’:
libavcodec/vaapi_decode.c:421:16: error: ‘VAProfileHEVCMain422_10’ undeclared (first use in this function)
         return VAProfileHEVCMain422_10;
                ^
libavcodec/vaapi_decode.c:421:16: note: each undeclared identifier is reported only once for each function it appears in
libavcodec/vaapi_decode.c:423:16: error: ‘VAProfileHEVCMain444’ undeclared (first use in this function)
         return VAProfileHEVCMain444;
                ^
libavcodec/vaapi_decode.c:425:16: error: ‘VAProfileHEVCMain444_10’ undeclared (first use in this function)
         return VAProfileHEVCMain444_10;
                ^
libavcodec/vaapi_decode.c: At top level:
libavcodec/vaapi_decode.c:409:18: warning: ‘vaapi_decode_find_exact_profile’ defined but not used [-Wunused-function]
 static VAProfile vaapi_decode_find_exact_profile(AVCodecContext *avctx)
                  ^
make: *** [libavcodec/vaapi_decode.o] Error 1
make: Target `all' not remade because of errors.

[...]
Linjie Fu April 4, 2019, 2:42 a.m.
> -----Original Message-----

> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf

> Of Michael Niedermayer

> Sent: Thursday, April 4, 2019 06:38

> To: FFmpeg development discussions and patches <ffmpeg-

> devel@ffmpeg.org>

> Subject: Re: [FFmpeg-devel] [PATCH, RFC 2/2] lavc/vaapi_decode: find exact

> va_profile for HEVC_REXT

> 

> On Wed, Apr 03, 2019 at 12:10:22PM +0800, Linjie Fu wrote:

> > Use the profile constraint flags to determine the exact va_profile for

> > HEVC_REXT.

> >

> > Directly cast PTLCommon to H265RawProfileTierLevel, and use

> ff_h265_get_profile

> > to get the exact profile.

> >

> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>

> > ---

> > [v2]: use constraint flags to determine the exact profile, expose the

> > codec-specific stuff at the beginning.

> > [RFC]: is it acceptable to cast PTLCommon to H265RawProfileTierLevel for

> > convenience? The members in PTLCommon should be strictly matched in

> > H265RawProfileTierLevel.

> >

> >  libavcodec/vaapi_decode.c | 74 +++++++++++++++++++++++++++++++--

> ------

> >  1 file changed, 59 insertions(+), 15 deletions(-)

> 

> breaks build:

> 

> CC	libavcodec/vaapi_decode.o

> libavcodec/vaapi_decode.c: In function ‘vaapi_decode_find_exact_profile’:

> libavcodec/vaapi_decode.c:421:16: error: ‘VAProfileHEVCMain422_10’

> undeclared (first use in this function)

>          return VAProfileHEVCMain422_10;

>                 ^

> libavcodec/vaapi_decode.c:421:16: note: each undeclared identifier is

> reported only once for each function it appears in

> libavcodec/vaapi_decode.c:423:16: error: ‘VAProfileHEVCMain444’

> undeclared (first use in this function)

>          return VAProfileHEVCMain444;

>                 ^

> libavcodec/vaapi_decode.c:425:16: error: ‘VAProfileHEVCMain444_10’

> undeclared (first use in this function)

>          return VAProfileHEVCMain444_10;

>                 ^

> libavcodec/vaapi_decode.c: At top level:

> libavcodec/vaapi_decode.c:409:18: warning:

> ‘vaapi_decode_find_exact_profile’ defined but not used [-Wunused-

> function]

>  static VAProfile vaapi_decode_find_exact_profile(AVCodecContext *avctx)

>                   ^

> make: *** [libavcodec/vaapi_decode.o] Error 1

> make: Target `all' not remade because of errors.

> 

Thanks, will move the VA version check into the vaapi_decode_find_exact_profile()
to fix the compile issue and avoid function not used warning.

Patch hide | download patch | download mbox

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 69512e1d45..6967a63186 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -24,6 +24,8 @@ 
 #include "decode.h"
 #include "internal.h"
 #include "vaapi_decode.h"
+#include "hevcdec.h"
+#include "h265_profile_level.h"
 
 
 int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx,
@@ -401,6 +403,29 @@  static const struct {
 #undef MAP
 };
 
+/*
+ * Find exact va_profile for HEVC Range Extension
+ */
+static VAProfile vaapi_decode_find_exact_profile(AVCodecContext *avctx)
+{
+    const HEVCContext *h = avctx->priv_data;
+    const HEVCSPS *sps = h->ps.sps;
+    const PTL *ptl = &(sps->ptl);
+    const PTLCommon *general_ptl = &(ptl->general_ptl);
+    const H265ProfileDescriptor *profile;
+
+    /* PTLCommon should match the member sequence in H265RawProfileTierLevel*/
+    profile = ff_h265_get_profile((H265RawProfileTierLevel *)general_ptl);
+
+    if (!strcmp(profile->name, "Main 4:2:2 10"))
+        return VAProfileHEVCMain422_10;
+    else if (!strcmp(profile->name, "Main 4:4:4"))
+        return VAProfileHEVCMain444;
+    else if (!strcmp(profile->name, "Main 4:4:4 10"))
+        return VAProfileHEVCMain444_10;
+
+    return VAProfileNone;
+}
 /*
  * Set *va_config and the frames_ref fields from the current codec parameters
  * in avctx.
@@ -447,24 +472,43 @@  static int vaapi_decode_make_config(AVCodecContext *avctx,
     matched_va_profile = VAProfileNone;
     exact_match = 0;
 
-    for (i = 0; i < FF_ARRAY_ELEMS(vaapi_profile_map); i++) {
-        int profile_match = 0;
-        if (avctx->codec_id != vaapi_profile_map[i].codec_id)
-            continue;
-        if (avctx->profile == vaapi_profile_map[i].codec_profile ||
-            vaapi_profile_map[i].codec_profile == FF_PROFILE_UNKNOWN)
-            profile_match = 1;
-        for (j = 0; j < profile_count; j++) {
-            if (vaapi_profile_map[i].va_profile == profile_list[j]) {
-                exact_match = profile_match;
+    if (avctx->profile == FF_PROFILE_HEVC_REXT) {
+        /* find the exact va_profile for HEVC_REXT */
+#if VA_CHECK_VERSION(1, 2, 0)
+        VAProfile va_profile = vaapi_decode_find_exact_profile(avctx);
+        for (i = 0; i < profile_count; i++) {
+            if (va_profile == profile_list[i]) {
+                exact_match = 1;
+                matched_va_profile = va_profile;
+                matched_ff_profile = FF_PROFILE_HEVC_REXT;
                 break;
             }
         }
-        if (j < profile_count) {
-            matched_va_profile = vaapi_profile_map[i].va_profile;
-            matched_ff_profile = vaapi_profile_map[i].codec_profile;
-            if (exact_match)
-                break;
+#else
+        av_log(avctx, AV_LOG_WARNING, "The profile is "
+                            "not supported with this VA version.\n");
+#endif
+    } else {
+        /* find the exact va_profile according to codec_id and profile */
+        for (i = 0; i < FF_ARRAY_ELEMS(vaapi_profile_map); i++) {
+            int profile_match = 0;
+            if (avctx->codec_id != vaapi_profile_map[i].codec_id)
+                continue;
+            if (avctx->profile == vaapi_profile_map[i].codec_profile ||
+                vaapi_profile_map[i].codec_profile == FF_PROFILE_UNKNOWN)
+                profile_match = 1;
+            for (j = 0; j < profile_count; j++) {
+                if (vaapi_profile_map[i].va_profile == profile_list[j]) {
+                    exact_match = profile_match;
+                    break;
+                }
+            }
+            if (j < profile_count) {
+                matched_va_profile = vaapi_profile_map[i].va_profile;
+                matched_ff_profile = vaapi_profile_map[i].codec_profile;
+                if (exact_match)
+                    break;
+            }
         }
     }
     av_freep(&profile_list);