dxva: DXVA2_ModeHEVC_VLD_Main10 does not support Main
[ffmpeg.git] / libavcodec / dxva2.c
index 9f4a529..9ceb623 100644 (file)
@@ -63,8 +63,7 @@ static const int prof_h264_high[]    = {FF_PROFILE_H264_CONSTRAINED_BASELINE,
                                         FF_PROFILE_UNKNOWN};
 static const int prof_hevc_main[]    = {FF_PROFILE_HEVC_MAIN,
                                         FF_PROFILE_UNKNOWN};
-static const int prof_hevc_main10[]  = {FF_PROFILE_HEVC_MAIN,
-                                        FF_PROFILE_HEVC_MAIN_10,
+static const int prof_hevc_main10[]  = {FF_PROFILE_HEVC_MAIN_10,
                                         FF_PROFILE_UNKNOWN};
 
 static const dxva_mode dxva_modes[] = {
@@ -196,12 +195,59 @@ static int dxva_check_codec_compatibility(AVCodecContext *avctx, const dxva_mode
     return 1;
 }
 
+static void dxva_list_guids_debug(AVCodecContext *avctx, void *service,
+                                 unsigned guid_count, const GUID *guid_list)
+{
+    FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+    int i;
+
+    av_log(avctx, AV_LOG_VERBOSE, "Decoder GUIDs reported as supported:\n");
+
+    for (i = 0; i < guid_count; i++) {
+        const GUID *guid = &guid_list[i];
+
+        av_log(avctx, AV_LOG_VERBOSE,
+             "{%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x}",
+             (unsigned) guid->Data1, guid->Data2, guid->Data3,
+             guid->Data4[0], guid->Data4[1],
+             guid->Data4[2], guid->Data4[3],
+             guid->Data4[4], guid->Data4[5],
+             guid->Data4[6], guid->Data4[7]);
+
+#if CONFIG_D3D11VA
+        if (sctx->pix_fmt == AV_PIX_FMT_D3D11) {
+            DXGI_FORMAT format;
+            // We don't know the maximum valid DXGI_FORMAT, so use 200 as
+            // arbitrary upper bound (that could become outdated).
+            for (format = 0; format < 200; format++) {
+                if (d3d11va_validate_output(service, *guid, &format))
+                    av_log(avctx, AV_LOG_VERBOSE, " %d", (int)format);
+            }
+        }
+#endif
+#if CONFIG_DXVA2
+        if (sctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
+            const D3DFORMAT formats[] = {MKTAG('N', 'V', '1', '2'),
+                                         MKTAG('P', '0', '1', '0')};
+            int i;
+            for (i = 0; i < FF_ARRAY_ELEMS(formats); i++) {
+                if (dxva2_validate_output(service, *guid, &formats[i]))
+                    av_log(avctx, AV_LOG_VERBOSE, " %d", i);
+            }
+        }
+#endif
+        av_log(avctx, AV_LOG_VERBOSE, "\n");
+    }
+}
+
 static int dxva_get_decoder_guid(AVCodecContext *avctx, void *service, void *surface_format,
                                  unsigned guid_count, const GUID *guid_list, GUID *decoder_guid)
 {
     FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
     unsigned i, j;
 
+    dxva_list_guids_debug(avctx, service, guid_count, guid_list);
+
     *decoder_guid = ff_GUID_NULL;
     for (i = 0; dxva_modes[i].guid; i++) {
         const dxva_mode *mode = &dxva_modes[i];
@@ -359,7 +405,6 @@ static int d3d11va_get_decoder_configuration(AVCodecContext *avctx,
                                              const D3D11_VIDEO_DECODER_DESC *desc,
                                              D3D11_VIDEO_DECODER_CONFIG *config)
 {
-    FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
     unsigned cfg_count = 0;
     D3D11_VIDEO_DECODER_CONFIG *cfg_list = NULL;
     HRESULT hr;
@@ -390,19 +435,28 @@ static int d3d11va_get_decoder_configuration(AVCodecContext *avctx,
     return ret;
 }
 
+static DXGI_FORMAT d3d11va_map_sw_to_hw_format(enum AVPixelFormat pix_fmt)
+{
+    switch (pix_fmt) {
+    case AV_PIX_FMT_NV12:       return DXGI_FORMAT_NV12;
+    case AV_PIX_FMT_P010:       return DXGI_FORMAT_P010;
+    case AV_PIX_FMT_YUV420P:    return DXGI_FORMAT_420_OPAQUE;
+    default:                    return DXGI_FORMAT_UNKNOWN;
+    }
+}
+
 static int d3d11va_create_decoder(AVCodecContext *avctx)
 {
     FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
     GUID *guid_list;
     unsigned guid_count, i;
     GUID decoder_guid;
-    DXGI_FORMAT surface_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ?
-                                 DXGI_FORMAT_P010 : DXGI_FORMAT_NV12;
     D3D11_VIDEO_DECODER_DESC desc = { 0 };
     D3D11_VIDEO_DECODER_CONFIG config;
     AVHWFramesContext *frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
     AVD3D11VADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
     AVD3D11VAFramesContext *frames_hwctx = frames_ctx->hwctx;
+    DXGI_FORMAT surface_format = d3d11va_map_sw_to_hw_format(frames_ctx->sw_format);
     D3D11_TEXTURE2D_DESC texdesc;
     HRESULT hr;
     int ret;
@@ -623,7 +677,6 @@ int ff_dxva2_decode_init(AVCodecContext *avctx)
     if (sctx->pix_fmt == AV_PIX_FMT_D3D11) {
         AVD3D11VADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
         AVD3D11VAContext *d3d11_ctx = &sctx->ctx.d3d11va;
-        HRESULT hr;
 
         ff_dxva2_lock(avctx);
         ret = d3d11va_create_decoder(avctx);
@@ -690,7 +743,7 @@ int ff_dxva2_decode_uninit(AVCodecContext *avctx)
     return 0;
 }
 
-static void *get_surface(AVCodecContext *avctx, const AVFrame *frame)
+static void *get_surface(const AVCodecContext *avctx, const AVFrame *frame)
 {
 #if CONFIG_D3D11VA
     if (frame->format == AV_PIX_FMT_D3D11) {
@@ -698,7 +751,7 @@ static void *get_surface(AVCodecContext *avctx, const AVFrame *frame)
         intptr_t index = (intptr_t)frame->data[1];
         if (index < 0 || index >= sctx->nb_d3d11_views ||
             sctx->d3d11_texture != (ID3D11Texture2D *)frame->data[0]) {
-            av_log(avctx, AV_LOG_ERROR, "get_buffer frame is invalid!\n");
+            av_log((void *)avctx, AV_LOG_ERROR, "get_buffer frame is invalid!\n");
             return NULL;
         }
         return sctx->d3d11_views[index];
@@ -759,7 +812,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
 #endif
     if (FAILED(hr)) {
         av_log(avctx, AV_LOG_ERROR, "Failed to get a buffer for %u: 0x%x\n",
-               type, hr);
+               type, (unsigned)hr);
         return -1;
     }
     if (size <= dxva_size) {
@@ -801,7 +854,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
     if (FAILED(hr)) {
         av_log(avctx, AV_LOG_ERROR,
                "Failed to release buffer type %u: 0x%x\n",
-               type, hr);
+               type, (unsigned)hr);
         result = -1;
     }
     return result;
@@ -871,7 +924,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
     } while(1);
 
     if (FAILED(hr)) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr);
+        av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", (unsigned)hr);
         ff_dxva2_unlock(avctx);
         return -1;
     }
@@ -966,7 +1019,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
     }
 #endif
     if (FAILED(hr)) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to execute: 0x%x\n", hr);
+        av_log(avctx, AV_LOG_ERROR, "Failed to execute: 0x%x\n", (unsigned)hr);
         result = -1;
     }
 
@@ -981,7 +1034,7 @@ end:
 #endif
     ff_dxva2_unlock(avctx);
     if (FAILED(hr)) {
-        av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%x\n", hr);
+        av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%x\n", (unsigned)hr);
         result = -1;
     }