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

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

Details

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

Commit Message

Linjie Fu April 4, 2019, 8: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.
[v3]: move the VA version check to fix the compile issue.
[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 | 73 +++++++++++++++++++++++++++++++--------
 1 file changed, 58 insertions(+), 15 deletions(-)

Comments

Michael Niedermayer April 4, 2019, 4:51 p.m.
On Thu, Apr 04, 2019 at 04:10:35PM +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.
> [v3]: move the VA version check to fix the compile issue.
> [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 | 73 +++++++++++++++++++++++++++++++--------
>  1 file changed, 58 insertions(+), 15 deletions(-)

breaks build with shared libs:

libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ffmpeg_g] Error 1
make: *** Waiting for unfinished jobs....
libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ffplay_g] Error 1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ffprobe_g] Error 1


[...]
Linjie Fu April 8, 2019, 2:02 a.m.
> -----Original Message-----
> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf
> Of Michael Niedermayer
> Sent: Friday, April 5, 2019 00:52
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Subject: Re: [FFmpeg-devel] [PATCH, v3 RFC 2/2] lavc/vaapi_decode: find
> exact va_profile for HEVC_REXT
> 
> On Thu, Apr 04, 2019 at 04:10:35PM +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.
> > [v3]: move the VA version check to fix the compile issue.
> > [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 | 73 +++++++++++++++++++++++++++++++--
> ------
> >  1 file changed, 58 insertions(+), 15 deletions(-)
> 
> breaks build with shared libs:
> 
> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> make: *** [ffmpeg_g] Error 1
> make: *** Waiting for unfinished jobs....
> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> make: *** [ffplay_g] Error 1
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> make: *** [ffprobe_g] Error 1
> 
> 

Hi Michael,

Thanks for the build check and compile error messages.
Actually, I also did the compile check locally and through pre-patch system.

We do shared libs compile with gcc and latest libva and msdk master deps, and it passes the check.
It seems this error occurs with clang.

 Could you provide some details on how to reproduce it? (e.g. compiler, distro, deps, flags, etc.).

Thus we can add into the system to refine the pre-patch check and have this clang compile issue fixed?

Thanks,
Linjie
James Almer April 8, 2019, 1:55 p.m.
On 4/7/2019 11:02 PM, Fu, Linjie wrote:
>> -----Original Message-----
>> From: ffmpeg-devel [mailto:ffmpeg-devel-bounces@ffmpeg.org] On Behalf
>> Of Michael Niedermayer
>> Sent: Friday, April 5, 2019 00:52
>> To: FFmpeg development discussions and patches <ffmpeg-
>> devel@ffmpeg.org>
>> Subject: Re: [FFmpeg-devel] [PATCH, v3 RFC 2/2] lavc/vaapi_decode: find
>> exact va_profile for HEVC_REXT
>>
>> On Thu, Apr 04, 2019 at 04:10:35PM +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.
>>> [v3]: move the VA version check to fix the compile issue.
>>> [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 | 73 +++++++++++++++++++++++++++++++--
>> ------
>>>  1 file changed, 58 insertions(+), 15 deletions(-)
>>
>> breaks build with shared libs:
>>
>> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
>> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>> make: *** [ffmpeg_g] Error 1
>> make: *** Waiting for unfinished jobs....
>> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
>> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'
>> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>> make: *** [ffplay_g] Error 1
>> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>> make: *** [ffprobe_g] Error 1
>>
>>
> 
> Hi Michael,
> 
> Thanks for the build check and compile error messages.
> Actually, I also did the compile check locally and through pre-patch system.
> 
> We do shared libs compile with gcc and latest libva and msdk master deps, and it passes the check.
> It seems this error occurs with clang.
> 
>  Could you provide some details on how to reproduce it? (e.g. compiler, distro, deps, flags, etc.).
> 
> Thus we can add into the system to refine the pre-patch check and have this clang compile issue fixed?
> 
> Thanks,
> Linjie 

You need to add h265_profile_level.o to the build objects related to
this module in libavcodec/Makefile. It's currently only being built for
the hevc vaapi encoder, so if that's disabled, linking will fail.

It's most likely not an issue with shared builds. I'm guessing Michael's
environment for that build had the hevc vaapi encoder disabled.
Linjie Fu April 9, 2019, 2:25 a.m.
> -----Original Message-----

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

> Of James Almer

> Sent: Monday, April 8, 2019 21:56

> To: ffmpeg-devel@ffmpeg.org

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

> exact va_profile for HEVC_REXT

> 

> On 4/7/2019 11:02 PM, Fu, Linjie wrote:

> >> -----Original Message-----

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

> Behalf

> >> Of Michael Niedermayer

> >> Sent: Friday, April 5, 2019 00:52

> >> To: FFmpeg development discussions and patches <ffmpeg-

> >> devel@ffmpeg.org>

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

> >> exact va_profile for HEVC_REXT

> >>

> >> On Thu, Apr 04, 2019 at 04:10:35PM +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.

> >>> [v3]: move the VA version check to fix the compile issue.

> >>> [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 | 73

> +++++++++++++++++++++++++++++++--

> >> ------

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

> >>

> >> breaks build with shared libs:

> >>

> >> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'

> >> clang: error: linker command failed with exit code 1 (use -v to see

> invocation)

> >> make: *** [ffmpeg_g] Error 1

> >> make: *** Waiting for unfinished jobs....

> >> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'

> >> libavcodec/libavcodec.so: undefined reference to `ff_h265_get_profile'

> >> clang: error: linker command failed with exit code 1 (use -v to see

> invocation)

> >> make: *** [ffplay_g] Error 1

> >> clang: error: linker command failed with exit code 1 (use -v to see

> invocation)

> >> make: *** [ffprobe_g] Error 1

> >>

> >>

> >

> > Hi Michael,

> >

> > Thanks for the build check and compile error messages.

> > Actually, I also did the compile check locally and through pre-patch system.

> >

> > We do shared libs compile with gcc and latest libva and msdk master deps,

> and it passes the check.

> > It seems this error occurs with clang.

> >

> >  Could you provide some details on how to reproduce it? (e.g. compiler,

> distro, deps, flags, etc.).

> >

> > Thus we can add into the system to refine the pre-patch check and have

> this clang compile issue fixed?

> >

> > Thanks,

> > Linjie

> 

> You need to add h265_profile_level.o to the build objects related to

> this module in libavcodec/Makefile. It's currently only being built for

> the hevc vaapi encoder, so if that's disabled, linking will fail.

> 

> It's most likely not an issue with shared builds. I'm guessing Michael's

> environment for that build had the hevc vaapi encoder disabled.


Yes, that's the problem and thanks for the comments.
I disabled hevc_vaapi encoder and reproduced this build issue.

With h265_profile_level.o added to the build objects of vaapi_decode,
this issue can be fixed.

Thanks,
Linjie

Patch hide | download patch | download mbox

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index 69512e1d45..47db6c874a 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,33 @@  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 VA_CHECK_VERSION(1, 2, 0)
+    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;
+#else
+    av_log(avctx, AV_LOG_WARNING, "HEVC profile %s is "
+                        "not supported with this VA version.\n", profile->name);
+#endif
+    return VAProfileNone;
+}
 /*
  * Set *va_config and the frames_ref fields from the current codec parameters
  * in avctx.
@@ -447,24 +476,38 @@  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 */
+        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 {
+        /* 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);