[vlc-devel] [PATCH] DXVA2: don't use the decoder if the profile is not supported

Steve Lhomme robux4 at videolabs.io
Tue Apr 21 13:11:33 CEST 2015


--
replaces patch 8107 and 8392
---
 modules/codec/avcodec/dxva2.c | 161 ++++++++++++++++++++++++++++--------------
 1 file changed, 108 insertions(+), 53 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 410d059..481fac6 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -177,7 +177,8 @@ DEFINE_GUID(DXVA_ModeH263_F,                        0x1b81be08, 0xa0c7, 0x11d3,
 typedef struct {
     const char   *name;
     const GUID   *guid;
-    int          codec;
+    int          codec_id;
+    int          i_profile; // 0 means no profile constraint
 } dxva2_mode_t;
 /* XXX Prefered modes must come first */
 static const dxva2_mode_t dxva2_modes[] = {
@@ -193,64 +194,65 @@ static const dxva2_mode_t dxva2_modes[] = {
     { "MPEG-2 motion compensation",                                                   &DXVA2_ModeMPEG2_MoComp,                0, 0 },
     { "MPEG-2 inverse discrete cosine transform",                                     &DXVA2_ModeMPEG2_IDCT,                  0, 0 },
 
-    { "MPEG-1 variable-length decoder",                                               &DXVA2_ModeMPEG1_VLD,                   0 },
+    /* MPEG-1 http://download.microsoft.com/download/B/1/7/B172A3C8-56F2-4210-80F1-A97BEA9182ED/DXVA_MPEG1_VLD.pdf */
+    { "MPEG-1 variable-length decoder, no D pictures",                                &DXVA2_ModeMPEG1_VLD,                   0, 0 },
 
-    /* H.264 */
-    { "H.264 variable-length decoder, film grain technology",                         &DXVA2_ModeH264_F,                      AV_CODEC_ID_H264 },
-    { "H.264 variable-length decoder, no film grain technology (Intel ClearVideo)",   &DXVADDI_Intel_ModeH264_E,              AV_CODEC_ID_H264 },
-    { "H.264 variable-length decoder, no film grain technology",                      &DXVA2_ModeH264_E,                      AV_CODEC_ID_H264 },
-    { "H.264 variable-length decoder, no film grain technology, FMO/ASO",             &DXVA_ModeH264_VLD_WithFMOASO_NoFGT,    AV_CODEC_ID_H264 },
-    { "H.264 variable-length decoder, no film grain technology, Flash",               &DXVA_ModeH264_VLD_NoFGT_Flash,         AV_CODEC_ID_H264 },
+    /* H.264 http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=3d1c290b-310b-4ea2-bf76-714063a6d7a6 */
+    { "H.264 variable-length decoder, film grain technology",                         &DXVA2_ModeH264_F,                      AV_CODEC_ID_H264, FF_PROFILE_H264_HIGH },
+    { "H.264 variable-length decoder, no film grain technology (Intel ClearVideo)",   &DXVADDI_Intel_ModeH264_E,              AV_CODEC_ID_H264, FF_PROFILE_H264_HIGH },
+    { "H.264 variable-length decoder, no film grain technology",                      &DXVA2_ModeH264_E,                      AV_CODEC_ID_H264, FF_PROFILE_H264_HIGH },
+    { "H.264 variable-length decoder, no film grain technology, FMO/ASO",             &DXVA_ModeH264_VLD_WithFMOASO_NoFGT,    AV_CODEC_ID_H264, FF_PROFILE_H264_HIGH },
+    { "H.264 variable-length decoder, no film grain technology, Flash",               &DXVA_ModeH264_VLD_NoFGT_Flash,         AV_CODEC_ID_H264, FF_PROFILE_H264_HIGH },
 
-    { "H.264 inverse discrete cosine transform, film grain technology",               &DXVA2_ModeH264_D,                      0 },
-    { "H.264 inverse discrete cosine transform, no film grain technology",            &DXVA2_ModeH264_C,                      0 },
-    { "H.264 inverse discrete cosine transform, no film grain technology (Intel)",    &DXVADDI_Intel_ModeH264_C,              0 },
+    { "H.264 inverse discrete cosine transform, film grain technology",               &DXVA2_ModeH264_D,                      0, 0 },
+    { "H.264 inverse discrete cosine transform, no film grain technology",            &DXVA2_ModeH264_C,                      0, 0 },
+    { "H.264 inverse discrete cosine transform, no film grain technology (Intel)",    &DXVADDI_Intel_ModeH264_C,              0, 0 },
 
-    { "H.264 motion compensation, film grain technology",                             &DXVA2_ModeH264_B,                      0 },
-    { "H.264 motion compensation, no film grain technology",                          &DXVA2_ModeH264_A,                      0 },
-    { "H.264 motion compensation, no film grain technology (Intel)",                  &DXVADDI_Intel_ModeH264_A,              0 },
+    { "H.264 motion compensation, film grain technology",                             &DXVA2_ModeH264_B,                      0, 0 },
+    { "H.264 motion compensation, no film grain technology",                          &DXVA2_ModeH264_A,                      0, 0 },
+    { "H.264 motion compensation, no film grain technology (Intel)",                  &DXVADDI_Intel_ModeH264_A,              0, 0 },
 
     /* http://download.microsoft.com/download/2/D/0/2D02E72E-7890-430F-BA91-4A363F72F8C8/DXVA_H264_MVC.pdf */
-    { "H.264 stereo high profile, mbs flag set",                                      &DXVA_ModeH264_VLD_Stereo_Progressive_NoFGT, 0 },
-    { "H.264 stereo high profile",                                                    &DXVA_ModeH264_VLD_Stereo_NoFGT,             0 },
-    { "H.264 multiview high profile",                                                 &DXVA_ModeH264_VLD_Multiview_NoFGT,          0 },
+    { "H.264 stereo high profile, mbs flag set",                                      &DXVA_ModeH264_VLD_Stereo_Progressive_NoFGT, 0, 0 },
+    { "H.264 stereo high profile",                                                    &DXVA_ModeH264_VLD_Stereo_NoFGT,             0, 0 },
+    { "H.264 multiview high profile",                                                 &DXVA_ModeH264_VLD_Multiview_NoFGT,          0, 0 },
 
     /* SVC http://download.microsoft.com/download/C/8/A/C8AD9F1B-57D1-4C10-85A0-09E3EAC50322/DXVA_SVC_2012_06.pdf */
-    { "H.264 scalable video coding, Scalable Baseline Profile",                       &DXVA_ModeH264_VLD_SVC_Scalable_Baseline,            0 },
-    { "H.264 scalable video coding, Scalable Constrained Baseline Profile",           &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_Baseline, 0 },
-    { "H.264 scalable video coding, Scalable High Profile",                           &DXVA_ModeH264_VLD_SVC_Scalable_High,                0 },
-    { "H.264 scalable video coding, Scalable Constrained High Profile",               &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_High_Progressive, 0 },
+    { "H.264 scalable video coding, Scalable Baseline Profile",                       &DXVA_ModeH264_VLD_SVC_Scalable_Baseline,            0, 0 },
+    { "H.264 scalable video coding, Scalable Constrained Baseline Profile",           &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_Baseline, 0, 0 },
+    { "H.264 scalable video coding, Scalable High Profile",                           &DXVA_ModeH264_VLD_SVC_Scalable_High,                0, 0 },
+    { "H.264 scalable video coding, Scalable Constrained High Profile",               &DXVA_ModeH264_VLD_SVC_Restricted_Scalable_High_Progressive, 0, 0 },
 
     /* WMV */
-    { "Windows Media Video 8 motion compensation",                                    &DXVA2_ModeWMV8_B,                      0 },
-    { "Windows Media Video 8 post processing",                                        &DXVA2_ModeWMV8_A,                      0 },
+    { "Windows Media Video 8 motion compensation",                                    &DXVA2_ModeWMV8_B,                      0, 0 },
+    { "Windows Media Video 8 post processing",                                        &DXVA2_ModeWMV8_A,                      0, 0 },
 
-    { "Windows Media Video 9 IDCT",                                                   &DXVA2_ModeWMV9_C,                      0 },
-    { "Windows Media Video 9 motion compensation",                                    &DXVA2_ModeWMV9_B,                      0 },
-    { "Windows Media Video 9 post processing",                                        &DXVA2_ModeWMV9_A,                      0 },
+    { "Windows Media Video 9 IDCT",                                                   &DXVA2_ModeWMV9_C,                      0, 0 },
+    { "Windows Media Video 9 motion compensation",                                    &DXVA2_ModeWMV9_B,                      0, 0 },
+    { "Windows Media Video 9 post processing",                                        &DXVA2_ModeWMV9_A,                      0, 0 },
 
     /* VC-1 */
-    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D,                       AV_CODEC_ID_VC1 },
-    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D,                       AV_CODEC_ID_WMV3 },
-    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D2010,                   AV_CODEC_ID_VC1 },
-    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D2010,                   AV_CODEC_ID_WMV3 },
-    { "VC-1 variable-length decoder 2 (Intel)",                                       &DXVA_Intel_VC1_ClearVideo_2,           0 },
-    { "VC-1 variable-length decoder (Intel)",                                         &DXVA_Intel_VC1_ClearVideo,             0 },
+    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D,                       AV_CODEC_ID_VC1, 0 },
+    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D,                       AV_CODEC_ID_WMV3, 0 },
+    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D2010,                   AV_CODEC_ID_VC1, 0 },
+    { "VC-1 variable-length decoder",                                                 &DXVA2_ModeVC1_D2010,                   AV_CODEC_ID_WMV3, 0 },
+    { "VC-1 variable-length decoder 2 (Intel)",                                       &DXVA_Intel_VC1_ClearVideo_2,           0, 0 },
+    { "VC-1 variable-length decoder (Intel)",                                         &DXVA_Intel_VC1_ClearVideo,             0, 0 },
 
-    { "VC-1 inverse discrete cosine transform",                                       &DXVA2_ModeVC1_C,                       0 },
-    { "VC-1 motion compensation",                                                     &DXVA2_ModeVC1_B,                       0 },
-    { "VC-1 post processing",                                                         &DXVA2_ModeVC1_A,                       0 },
+    { "VC-1 inverse discrete cosine transform",                                       &DXVA2_ModeVC1_C,                       0, 0 },
+    { "VC-1 motion compensation",                                                     &DXVA2_ModeVC1_B,                       0, 0 },
+    { "VC-1 post processing",                                                         &DXVA2_ModeVC1_A,                       0, 0 },
 
     /* Xvid/Divx: TODO */
-    { "MPEG-4 Part 2 nVidia bitstream decoder",                                       &DXVA_nVidia_MPEG4_ASP,                 0 },
-    { "MPEG-4 Part 2 variable-length decoder, Simple Profile",                        &DXVA_ModeMPEG4pt2_VLD_Simple,          0 },
-    { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, no GMC",       &DXVA_ModeMPEG4pt2_VLD_AdvSimple_NoGMC, 0 },
-    { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, GMC",          &DXVA_ModeMPEG4pt2_VLD_AdvSimple_GMC,   0 },
-    { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, Avivo",        &DXVA_ModeMPEG4pt2_VLD_AdvSimple_Avivo, 0 },
+    { "MPEG-4 Part 2 nVidia bitstream decoder",                                       &DXVA_nVidia_MPEG4_ASP,                 0, 0 },
+    { "MPEG-4 Part 2 variable-length decoder, Simple Profile",                        &DXVA_ModeMPEG4pt2_VLD_Simple,          0, 0 },
+    { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, no GMC",       &DXVA_ModeMPEG4pt2_VLD_AdvSimple_NoGMC, 0, 0 },
+    { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, GMC",          &DXVA_ModeMPEG4pt2_VLD_AdvSimple_GMC,   0, 0 },
+    { "MPEG-4 Part 2 variable-length decoder, Simple&Advanced Profile, Avivo",        &DXVA_ModeMPEG4pt2_VLD_AdvSimple_Avivo, 0, 0 },
 
     /* HEVC */
-    { "HEVC Main profile",                                                            &DXVA_ModeHEVC_VLD_Main,                AV_CODEC_ID_HEVC },
-    { "HEVC Main 10 profile",                                                         &DXVA_ModeHEVC_VLD_Main10,              0 },
+    { "HEVC Main profile",                                                            &DXVA_ModeHEVC_VLD_Main,                AV_CODEC_ID_HEVC, FF_PROFILE_HEVC_MAIN },
+    { "HEVC Main 10 profile",                                                         &DXVA_ModeHEVC_VLD_Main10,              AV_CODEC_ID_HEVC, FF_PROFILE_HEVC_MAIN_10 },
 
     /* H.261 */
     { "H.261 decoder, restricted profile A",                                          &DXVA_ModeH261_A,                       0, 0 },
@@ -304,6 +306,7 @@ static const d3d_format_t *D3dFindFormat(D3DFORMAT format)
 struct vlc_va_sys_t
 {
     int          codec_id;
+    int          i_profile;
     int          width;
     int          height;
 
@@ -327,7 +330,7 @@ struct vlc_va_sys_t
 
     /* Video service */
     IDirectXVideoDecoderService  *vs;
-    GUID                         input;
+    const dxva2_mode_t           *p_input;
     const d3d_format_t           *p_render;
 
     /* Video decoder */
@@ -368,13 +371,15 @@ static void D3dDestroyDeviceManager(vlc_va_sys_t *);
 
 static int DxCreateVideoService(vlc_va_t *);
 static void DxDestroyVideoService(vlc_va_sys_t *);
-static int DxFindVideoServiceConversion(vlc_va_t *, GUID *input, const d3d_format_t **output);
+static int DxFindVideoServiceConversion(vlc_va_t *, const dxva2_mode_t **input, const d3d_format_t **output);
 
 static int DxCreateVideoDecoder(vlc_va_t *,
                                 int codec_id, const video_format_t *, bool);
 static void DxDestroyVideoDecoder(vlc_va_sys_t *);
 static int DxResetVideoDecoder(vlc_va_t *);
 
+static bool profile_supported(const dxva2_mode_t *mode, int i_src_profile);
+
 static void CopySurface( picture_t *p_dst, picture_t *p_src )
 {
     picture_sys_t *p_src_sys = p_src->p_sys;
@@ -504,7 +509,7 @@ static int Setup(vlc_va_t *va, AVCodecContext *avctx, vlc_fourcc_t *chroma, pict
     vlc_va_sys_t *sys = va->sys;
 
     if (sys->width == avctx->coded_width && sys->height == avctx->coded_height
-     && sys->decoder != NULL)
+     && sys->decoder != NULL && profile_supported(sys->p_input, avctx->profile))
         goto ok;
 
     /* */
@@ -755,7 +760,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const es_format_t *fmt)
 
     va->sys = sys;
     sys->codec_id = ctx->codec_id;
-    (void) fmt;
+    sys->i_profile = ctx->profile;
 
     sys->b_thread_safe = ctx->thread_safe_callbacks;
     if ( sys->b_thread_safe )
@@ -792,7 +797,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, const es_format_t *fmt)
     }
 
     /* */
-    if (DxFindVideoServiceConversion(va, &sys->input, &sys->p_render)) {
+    if (DxFindVideoServiceConversion(va, &sys->p_input, &sys->p_render)) {
         msg_Err(va, "DxFindVideoServiceConversion failed");
         goto error;
     }
@@ -1049,10 +1054,54 @@ static void DxDestroyVideoService(vlc_va_sys_t *va)
     if (va->vs)
         IDirectXVideoDecoderService_Release(va->vs);
 }
+
+static bool profile_supported(const dxva2_mode_t *mode, int i_src_profile)
+{
+    bool is_supported = !mode->i_profile || i_src_profile <= 0;
+    if (!is_supported)
+    {
+        if (mode->codec_id == AV_CODEC_ID_H264)
+        {
+            if (mode->i_profile == FF_PROFILE_H264_HIGH)
+            {
+                switch (i_src_profile & ~(FF_PROFILE_H264_CONSTRAINED|FF_PROFILE_H264_INTRA))
+                {
+                case FF_PROFILE_H264_BASELINE:
+                case FF_PROFILE_H264_MAIN:
+                case FF_PROFILE_H264_HIGH:
+                    is_supported = true;
+                    break;
+                }
+            }
+        }
+        else if (mode->codec_id == AV_CODEC_ID_HEVC)
+        {
+            switch (mode->i_profile)
+            {
+            case FF_PROFILE_HEVC_MAIN:
+                if (i_src_profile == FF_PROFILE_HEVC_MAIN)
+                    is_supported = true;
+                break;
+            case FF_PROFILE_HEVC_MAIN_10:
+                if ( i_src_profile == FF_PROFILE_HEVC_MAIN ||
+                     i_src_profile == FF_PROFILE_HEVC_MAIN_10 )
+                    is_supported = true;
+                break;
+            }
+        }
+        else if (i_src_profile <= mode->i_profile)
+        {
+            /* ordered profiles numbers like AV_CODEC_ID_MPEG2VIDEO */
+            is_supported = true;
+        }
+    }
+    return is_supported;
+}
+
 /**
  * Find the best suited decoder mode GUID and render format.
  */
-static int DxFindVideoServiceConversion(vlc_va_t *va, GUID *input, const d3d_format_t **output)
+static int DxFindVideoServiceConversion(vlc_va_t *va, const dxva2_mode_t **input, const d3d_format_t **output)
 {
     vlc_va_sys_t *sys = va->sys;
 
@@ -1078,7 +1127,7 @@ static int DxFindVideoServiceConversion(vlc_va_t *va, GUID *input, const d3d_for
     /* Try all supported mode by our priority */
     for (unsigned i = 0; dxva2_modes[i].name; i++) {
         const dxva2_mode_t *mode = &dxva2_modes[i];
-        if (!mode->codec || mode->codec != sys->codec_id)
+        if (!mode->codec_id || mode->codec_id != sys->codec_id)
             continue;
 
         /* */
@@ -1086,6 +1135,12 @@ static int DxFindVideoServiceConversion(vlc_va_t *va, GUID *input, const d3d_for
         for (const GUID *g = &input_list[0]; !is_supported && g < &input_list[input_count]; g++) {
             is_supported = IsEqualGUID(mode->guid, g);
         }
+        if (is_supported)
+        {
+            is_supported = profile_supported(mode, sys->i_profile);
+            if (!is_supported)
+                msg_Warn( va, "Unsupported profile for DXVA2 HWAccel: %d", sys->i_profile );
+        }
         if (!is_supported)
             continue;
 
@@ -1123,7 +1178,7 @@ static int DxFindVideoServiceConversion(vlc_va_t *va, GUID *input, const d3d_for
 
             /* We have our solution */
             msg_Dbg(va, "Using '%s' to decode to '%s'", mode->name, format->name);
-            *input  = *mode->guid;
+            *input  = mode;
             *output = format;
             CoTaskMemFree(output_list);
             CoTaskMemFree(input_list);
@@ -1242,7 +1297,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
     UINT                      cfg_count = 0;
     DXVA2_ConfigPictureDecode *cfg_list = NULL;
     if (FAILED(IDirectXVideoDecoderService_GetDecoderConfigurations(sys->vs,
-                                                                    &sys->input,
+                                                                    sys->p_input->guid,
                                                                     &dsc,
                                                                     NULL,
                                                                     &cfg_count,
@@ -1286,7 +1341,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
     /* Create the decoder */
     IDirectXVideoDecoder *decoder;
     if (FAILED(IDirectXVideoDecoderService_CreateVideoDecoder(sys->vs,
-                                                              &sys->input,
+                                                              sys->p_input->guid,
                                                               &dsc,
                                                               &sys->cfg,
                                                               sys->hw_surface,
@@ -1297,7 +1352,7 @@ static int DxCreateVideoDecoder(vlc_va_t *va, int codec_id,
     }
     sys->decoder = decoder;
 
-    if (IsEqualGUID(&sys->input, &DXVADDI_Intel_ModeH264_E))
+    if (IsEqualGUID(&sys->p_input->guid, &DXVADDI_Intel_ModeH264_E))
         sys->hw.workaround |= FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO;
 
     msg_Dbg(va, "IDirectXVideoDecoderService_CreateVideoDecoder succeed");
-- 
2.3.0




More information about the vlc-devel mailing list