summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2017-06-07 17:11:17 +0200
committerwm4 <nfxjfg@googlemail.com>2017-06-27 18:05:02 +0200
commit70143a3954e1c4412efb2bf1a3a818adea2d3abf (patch)
tree24c14db2eac2c52a929cb18bcb11086f41c91147 /libavcodec
parent5659f7404731415c7e1cfdf4d8b0afeb6b1132de (diff)
downloadffmpeg-70143a3954e1c4412efb2bf1a3a818adea2d3abf.tar.gz
dxva: add support for new dxva2 and d3d11 hwaccel APIs
This also adds support to avconv (which is trivial due to the new hwaccel API being generic enough). The new decoder setup code in dxva2.c is significantly based on work by Steve Lhomme <robux4@gmail.com>, but with heavy changes/rewrites. Merges Libav commit f9e7a2f95a7194a8736cc1416a03a1a0155a3e9f. Also adds untested VP9 support. The check for DXVA2 COBJs is removed. Just update your MinGW to something newer than a 5 year old release. Signed-off-by: Diego Biurrun <diego@biurrun.de>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/allcodecs.c6
-rw-r--r--libavcodec/dxva2.c669
-rw-r--r--libavcodec/dxva2_h264.c22
-rw-r--r--libavcodec/dxva2_hevc.c22
-rw-r--r--libavcodec/dxva2_internal.h43
-rw-r--r--libavcodec/dxva2_mpeg2.c22
-rw-r--r--libavcodec/dxva2_vc1.c44
-rw-r--r--libavcodec/dxva2_vp9.c22
-rw-r--r--libavcodec/h264_slice.c3
-rw-r--r--libavcodec/hevcdec.c4
-rw-r--r--libavcodec/mpeg12dec.c1
-rw-r--r--libavcodec/vc1dec.c1
-rw-r--r--libavcodec/version.h2
-rw-r--r--libavcodec/vp9.c3
14 files changed, 854 insertions, 10 deletions
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 54a9e8c42e..0243f47358 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -66,6 +66,7 @@ static void register_all(void)
REGISTER_HWACCEL(H263_VIDEOTOOLBOX, h263_videotoolbox);
REGISTER_HWACCEL(H264_CUVID, h264_cuvid);
REGISTER_HWACCEL(H264_D3D11VA, h264_d3d11va);
+ REGISTER_HWACCEL(H264_D3D11VA2, h264_d3d11va2);
REGISTER_HWACCEL(H264_DXVA2, h264_dxva2);
REGISTER_HWACCEL(H264_MEDIACODEC, h264_mediacodec);
REGISTER_HWACCEL(H264_MMAL, h264_mmal);
@@ -77,6 +78,7 @@ static void register_all(void)
REGISTER_HWACCEL(H264_VIDEOTOOLBOX, h264_videotoolbox);
REGISTER_HWACCEL(HEVC_CUVID, hevc_cuvid);
REGISTER_HWACCEL(HEVC_D3D11VA, hevc_d3d11va);
+ REGISTER_HWACCEL(HEVC_D3D11VA2, hevc_d3d11va2);
REGISTER_HWACCEL(HEVC_DXVA2, hevc_dxva2);
REGISTER_HWACCEL(HEVC_MEDIACODEC, hevc_mediacodec);
REGISTER_HWACCEL(HEVC_QSV, hevc_qsv);
@@ -90,6 +92,7 @@ static void register_all(void)
REGISTER_HWACCEL(MPEG2_CUVID, mpeg2_cuvid);
REGISTER_HWACCEL(MPEG2_XVMC, mpeg2_xvmc);
REGISTER_HWACCEL(MPEG2_D3D11VA, mpeg2_d3d11va);
+ REGISTER_HWACCEL(MPEG2_D3D11VA2, mpeg2_d3d11va2);
REGISTER_HWACCEL(MPEG2_DXVA2, mpeg2_dxva2);
REGISTER_HWACCEL(MPEG2_MMAL, mpeg2_mmal);
REGISTER_HWACCEL(MPEG2_QSV, mpeg2_qsv);
@@ -105,6 +108,7 @@ static void register_all(void)
REGISTER_HWACCEL(MPEG4_VIDEOTOOLBOX, mpeg4_videotoolbox);
REGISTER_HWACCEL(VC1_CUVID, vc1_cuvid);
REGISTER_HWACCEL(VC1_D3D11VA, vc1_d3d11va);
+ REGISTER_HWACCEL(VC1_D3D11VA2, vc1_d3d11va2);
REGISTER_HWACCEL(VC1_DXVA2, vc1_dxva2);
REGISTER_HWACCEL(VC1_VAAPI, vc1_vaapi);
REGISTER_HWACCEL(VC1_VDPAU, vc1_vdpau);
@@ -115,10 +119,12 @@ static void register_all(void)
REGISTER_HWACCEL(VP8_QSV, vp8_qsv);
REGISTER_HWACCEL(VP9_CUVID, vp9_cuvid);
REGISTER_HWACCEL(VP9_D3D11VA, vp9_d3d11va);
+ REGISTER_HWACCEL(VP9_D3D11VA2, vp9_d3d11va2);
REGISTER_HWACCEL(VP9_DXVA2, vp9_dxva2);
REGISTER_HWACCEL(VP9_MEDIACODEC, vp9_mediacodec);
REGISTER_HWACCEL(VP9_VAAPI, vp9_vaapi);
REGISTER_HWACCEL(WMV3_D3D11VA, wmv3_d3d11va);
+ REGISTER_HWACCEL(WMV3_D3D11VA2, wmv3_d3d11va2);
REGISTER_HWACCEL(WMV3_DXVA2, wmv3_dxva2);
REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi);
REGISTER_HWACCEL(WMV3_VDPAU, wmv3_vdpau);
diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 9138216745..efb5328dcd 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -22,20 +22,450 @@
#include <assert.h>
#include <string.h>
+#include <initguid.h>
+#include "libavutil/common.h"
#include "libavutil/log.h"
#include "libavutil/time.h"
#include "avcodec.h"
#include "dxva2_internal.h"
+/* define all the GUIDs used directly here,
+ to avoid problems with inconsistent dxva2api.h versions in mingw-w64 and different MSVC version */
+DEFINE_GUID(ff_DXVA2_ModeMPEG2_VLD, 0xee27417f, 0x5e28,0x4e65,0xbe,0xea,0x1d,0x26,0xb5,0x08,0xad,0xc9);
+DEFINE_GUID(ff_DXVA2_ModeMPEG2and1_VLD, 0x86695f12, 0x340e,0x4f04,0x9f,0xd3,0x92,0x53,0xdd,0x32,0x74,0x60);
+DEFINE_GUID(ff_DXVA2_ModeH264_E, 0x1b81be68, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
+DEFINE_GUID(ff_DXVA2_ModeH264_F, 0x1b81be69, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
+DEFINE_GUID(ff_DXVADDI_Intel_ModeH264_E, 0x604F8E68, 0x4951,0x4C54,0x88,0xFE,0xAB,0xD2,0x5C,0x15,0xB3,0xD6);
+DEFINE_GUID(ff_DXVA2_ModeVC1_D, 0x1b81beA3, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
+DEFINE_GUID(ff_DXVA2_ModeVC1_D2010, 0x1b81beA4, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
+DEFINE_GUID(ff_DXVA2_ModeHEVC_VLD_Main, 0x5b11d51b, 0x2f4c,0x4452,0xbc,0xc3,0x09,0xf2,0xa1,0x16,0x0c,0xc0);
+DEFINE_GUID(ff_DXVA2_ModeHEVC_VLD_Main10,0x107af0e0, 0xef1a,0x4d19,0xab,0xa8,0x67,0xa1,0x63,0x07,0x3d,0x13);
+DEFINE_GUID(ff_DXVA2_ModeVP9_VLD_Profile0,0x463707f8,0xa1d0,0x4585,0x87,0x6d,0x83,0xaa,0x6d,0x60,0xb8,0x9e);
+DEFINE_GUID(ff_DXVA2_NoEncrypt, 0x1b81beD0, 0xa0c7,0x11d3,0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5);
+DEFINE_GUID(ff_GUID_NULL, 0x00000000, 0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
+DEFINE_GUID(ff_IID_IDirectXVideoDecoderService, 0xfc51a551,0xd5e7,0x11d9,0xaf,0x55,0x00,0x05,0x4e,0x43,0xff,0x02);
+
+typedef struct dxva_mode {
+ const GUID *guid;
+ enum AVCodecID codec;
+} dxva_mode;
+
+static const dxva_mode dxva_modes[] = {
+ /* MPEG-2 */
+ { &ff_DXVA2_ModeMPEG2_VLD, AV_CODEC_ID_MPEG2VIDEO },
+ { &ff_DXVA2_ModeMPEG2and1_VLD, AV_CODEC_ID_MPEG2VIDEO },
+
+ /* H.264 */
+ { &ff_DXVA2_ModeH264_F, AV_CODEC_ID_H264 },
+ { &ff_DXVA2_ModeH264_E, AV_CODEC_ID_H264 },
+ /* Intel specific H.264 mode */
+ { &ff_DXVADDI_Intel_ModeH264_E, AV_CODEC_ID_H264 },
+
+ /* VC-1 / WMV3 */
+ { &ff_DXVA2_ModeVC1_D2010, AV_CODEC_ID_VC1 },
+ { &ff_DXVA2_ModeVC1_D2010, AV_CODEC_ID_WMV3 },
+ { &ff_DXVA2_ModeVC1_D, AV_CODEC_ID_VC1 },
+ { &ff_DXVA2_ModeVC1_D, AV_CODEC_ID_WMV3 },
+
+ /* HEVC/H.265 */
+ { &ff_DXVA2_ModeHEVC_VLD_Main, AV_CODEC_ID_HEVC },
+ { &ff_DXVA2_ModeHEVC_VLD_Main10, AV_CODEC_ID_HEVC },
+
+ /* VP8/9 */
+ { &ff_DXVA2_ModeVP9_VLD_Profile0,AV_CODEC_ID_VP9 },
+
+ { NULL, 0 },
+};
+
+static int dxva_get_decoder_configuration(AVCodecContext *avctx,
+ const void *cfg_list,
+ unsigned cfg_count)
+{
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ unsigned i, best_score = 0;
+ int best_cfg = -1;
+
+ for (i = 0; i < cfg_count; i++) {
+ unsigned score;
+ UINT ConfigBitstreamRaw;
+ GUID guidConfigBitstreamEncryption;
+
+#if CONFIG_D3D11VA
+ if (sctx->pix_fmt == AV_PIX_FMT_D3D11) {
+ D3D11_VIDEO_DECODER_CONFIG *cfg = &((D3D11_VIDEO_DECODER_CONFIG *)cfg_list)[i];
+ ConfigBitstreamRaw = cfg->ConfigBitstreamRaw;
+ guidConfigBitstreamEncryption = cfg->guidConfigBitstreamEncryption;
+ }
+#endif
+#if CONFIG_DXVA2
+ if (sctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
+ DXVA2_ConfigPictureDecode *cfg = &((DXVA2_ConfigPictureDecode *)cfg_list)[i];
+ ConfigBitstreamRaw = cfg->ConfigBitstreamRaw;
+ guidConfigBitstreamEncryption = cfg->guidConfigBitstreamEncryption;
+ }
+#endif
+
+ if (ConfigBitstreamRaw == 1)
+ score = 1;
+ else if (avctx->codec_id == AV_CODEC_ID_H264 && ConfigBitstreamRaw == 2)
+ score = 2;
+ else
+ continue;
+ if (IsEqualGUID(&guidConfigBitstreamEncryption, &ff_DXVA2_NoEncrypt))
+ score += 16;
+ if (score > best_score) {
+ best_score = score;
+ best_cfg = i;
+ }
+ }
+
+ if (!best_score) {
+ av_log(avctx, AV_LOG_VERBOSE, "No valid decoder configuration available\n");
+ return AVERROR(EINVAL);
+ }
+
+ return best_cfg;
+}
+
+#if CONFIG_D3D11VA
+static int d3d11va_validate_output(void *service, GUID guid, const void *surface_format)
+{
+ HRESULT hr;
+ BOOL is_supported = FALSE;
+ hr = ID3D11VideoDevice_CheckVideoDecoderFormat((ID3D11VideoDevice *)service,
+ &guid,
+ *(DXGI_FORMAT *)surface_format,
+ &is_supported);
+ return SUCCEEDED(hr) && is_supported;
+}
+#endif
+
+#if CONFIG_DXVA2
+static int dxva2_validate_output(void *decoder_service, GUID guid, const void *surface_format)
+{
+ HRESULT hr;
+ int ret = 0;
+ unsigned j, target_count;
+ D3DFORMAT *target_list;
+ hr = IDirectXVideoDecoderService_GetDecoderRenderTargets((IDirectXVideoDecoderService *)decoder_service, &guid, &target_count, &target_list);
+ if (SUCCEEDED(hr)) {
+ for (j = 0; j < target_count; j++) {
+ const D3DFORMAT format = target_list[j];
+ if (format == *(D3DFORMAT *)surface_format) {
+ ret = 1;
+ break;
+ }
+ }
+ CoTaskMemFree(target_list);
+ }
+ return ret;
+}
+#endif
+
+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;
+
+ *decoder_guid = ff_GUID_NULL;
+ for (i = 0; dxva_modes[i].guid; i++) {
+ const dxva_mode *mode = &dxva_modes[i];
+ int validate;
+ if (mode->codec != avctx->codec_id)
+ continue;
+
+ for (j = 0; j < guid_count; j++) {
+ if (IsEqualGUID(mode->guid, &guid_list[j]))
+ break;
+ }
+ if (j == guid_count)
+ continue;
+
+#if CONFIG_D3D11VA
+ if (sctx->pix_fmt == AV_PIX_FMT_D3D11)
+ validate = d3d11va_validate_output(service, *mode->guid, surface_format);
+#endif
+#if CONFIG_DXVA2
+ if (sctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
+ validate = dxva2_validate_output(service, *mode->guid, surface_format);
+#endif
+ if (validate) {
+ *decoder_guid = *mode->guid;
+ break;
+ }
+ }
+
+ if (IsEqualGUID(decoder_guid, &ff_GUID_NULL)) {
+ av_log(avctx, AV_LOG_VERBOSE, "No decoder device for codec found\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (IsEqualGUID(decoder_guid, &ff_DXVADDI_Intel_ModeH264_E))
+ sctx->workaround |= FF_DXVA2_WORKAROUND_INTEL_CLEARVIDEO;
+
+ return 0;
+}
+
+static void bufref_free_interface(void *opaque, uint8_t *data)
+{
+ IUnknown_Release((IUnknown *)opaque);
+}
+
+static AVBufferRef *bufref_wrap_interface(IUnknown *iface)
+{
+ return av_buffer_create((uint8_t*)iface, 1, bufref_free_interface, iface, 0);
+}
+
+#if CONFIG_DXVA2
+
+static int dxva2_get_decoder_configuration(AVCodecContext *avctx, const GUID *device_guid,
+ const DXVA2_VideoDesc *desc,
+ DXVA2_ConfigPictureDecode *config)
+{
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ unsigned cfg_count;
+ DXVA2_ConfigPictureDecode *cfg_list;
+ HRESULT hr;
+ int ret;
+
+ hr = IDirectXVideoDecoderService_GetDecoderConfigurations(sctx->dxva2_service, device_guid, desc, NULL, &cfg_count, &cfg_list);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to retrieve decoder configurations\n");
+ return AVERROR(EINVAL);
+ }
+
+ ret = dxva_get_decoder_configuration(avctx, cfg_list, cfg_count);
+ if (ret >= 0)
+ *config = cfg_list[ret];
+ CoTaskMemFree(cfg_list);
+ return ret;
+}
+
+static int dxva2_create_decoder(AVCodecContext *avctx)
+{
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ GUID *guid_list;
+ unsigned guid_count;
+ GUID device_guid;
+ D3DFORMAT surface_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ?
+ MKTAG('P', '0', '1', '0') : MKTAG('N', 'V', '1', '2');
+ DXVA2_VideoDesc desc = { 0 };
+ DXVA2_ConfigPictureDecode config;
+ HRESULT hr;
+ int ret;
+ HANDLE device_handle;
+ AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
+ AVDXVA2FramesContext *frames_hwctx = frames_ctx->hwctx;
+ AVDXVA2DeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
+
+ hr = IDirect3DDeviceManager9_OpenDeviceHandle(device_hwctx->devmgr,
+ &device_handle);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to open a device handle\n");
+ goto fail;
+ }
+
+ hr = IDirect3DDeviceManager9_GetVideoService(device_hwctx->devmgr, device_handle,
+ &ff_IID_IDirectXVideoDecoderService,
+ (void **)&sctx->dxva2_service);
+ IDirect3DDeviceManager9_CloseDeviceHandle(device_hwctx->devmgr, device_handle);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create IDirectXVideoDecoderService\n");
+ goto fail;
+ }
+
+ hr = IDirectXVideoDecoderService_GetDecoderDeviceGuids(sctx->dxva2_service, &guid_count, &guid_list);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to retrieve decoder device GUIDs\n");
+ goto fail;
+ }
+
+ ret = dxva_get_decoder_guid(avctx, sctx->dxva2_service, &surface_format,
+ guid_count, guid_list, &device_guid);
+ CoTaskMemFree(guid_list);
+ if (ret < 0) {
+ goto fail;
+ }
+
+ desc.SampleWidth = avctx->coded_width;
+ desc.SampleHeight = avctx->coded_height;
+ desc.Format = surface_format;
+
+ ret = dxva2_get_decoder_configuration(avctx, &device_guid, &desc, &config);
+ if (ret < 0) {
+ goto fail;
+ }
+
+ hr = IDirectXVideoDecoderService_CreateVideoDecoder(sctx->dxva2_service, &device_guid,
+ &desc, &config, frames_hwctx->surfaces,
+ frames_hwctx->nb_surfaces, &sctx->dxva2_decoder);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create DXVA2 video decoder\n");
+ goto fail;
+ }
+
+ sctx->dxva2_config = config;
+
+ sctx->decoder_ref = bufref_wrap_interface((IUnknown *)sctx->dxva2_decoder);
+ if (!sctx->decoder_ref)
+ return AVERROR(ENOMEM);
+
+ return 0;
+fail:
+ return AVERROR(EINVAL);
+}
+
+#endif
+
+#if CONFIG_D3D11VA
+
+static int d3d11va_get_decoder_configuration(AVCodecContext *avctx,
+ ID3D11VideoDevice *video_device,
+ 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;
+ int i, ret;
+
+ hr = ID3D11VideoDevice_GetVideoDecoderConfigCount(video_device, desc, &cfg_count);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to retrieve decoder configurations\n");
+ return AVERROR(EINVAL);
+ }
+
+ cfg_list = av_malloc_array(cfg_count, sizeof(D3D11_VIDEO_DECODER_CONFIG));
+ if (cfg_list == NULL)
+ return AVERROR(ENOMEM);
+ for (i = 0; i < cfg_count; i++) {
+ hr = ID3D11VideoDevice_GetVideoDecoderConfig(video_device, desc, i, &cfg_list[i]);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Unable to retrieve decoder configurations. (hr=0x%lX)\n", hr);
+ av_free(cfg_list);
+ return AVERROR(EINVAL);
+ }
+ }
+
+ ret = dxva_get_decoder_configuration(avctx, cfg_list, cfg_count);
+ if (ret >= 0)
+ *config = cfg_list[ret];
+ av_free(cfg_list);
+ return ret;
+}
+
+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;
+ D3D11_TEXTURE2D_DESC texdesc;
+ HRESULT hr;
+ int ret;
+
+ if (!frames_hwctx->texture) {
+ av_log(avctx, AV_LOG_ERROR, "AVD3D11VAFramesContext.texture not set.\n");
+ return AVERROR(EINVAL);
+ }
+ ID3D11Texture2D_GetDesc(frames_hwctx->texture, &texdesc);
+
+ guid_count = ID3D11VideoDevice_GetVideoDecoderProfileCount(device_hwctx->video_device);
+ guid_list = av_malloc_array(guid_count, sizeof(*guid_list));
+ if (guid_list == NULL || guid_count == 0) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to get the decoder GUIDs\n");
+ av_free(guid_list);
+ return AVERROR(EINVAL);
+ }
+ for (i = 0; i < guid_count; i++) {
+ hr = ID3D11VideoDevice_GetVideoDecoderProfile(device_hwctx->video_device, i, &guid_list[i]);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to retrieve decoder GUID %d\n", i);
+ av_free(guid_list);
+ return AVERROR(EINVAL);
+ }
+ }
+
+ ret = dxva_get_decoder_guid(avctx, device_hwctx->video_device, &surface_format,
+ guid_count, guid_list, &decoder_guid);
+ av_free(guid_list);
+ if (ret < 0)
+ return AVERROR(EINVAL);
+
+ desc.SampleWidth = avctx->coded_width;
+ desc.SampleHeight = avctx->coded_height;
+ desc.OutputFormat = surface_format;
+ desc.Guid = decoder_guid;
+
+ ret = d3d11va_get_decoder_configuration(avctx, device_hwctx->video_device, &desc, &config);
+ if (ret < 0)
+ return AVERROR(EINVAL);
+
+ sctx->d3d11_views = av_mallocz_array(texdesc.ArraySize, sizeof(sctx->d3d11_views[0]));
+ if (!sctx->d3d11_views)
+ return AVERROR(ENOMEM);
+ sctx->nb_d3d11_views = texdesc.ArraySize;
+
+ for (i = 0; i < sctx->nb_d3d11_views; i++) {
+ D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc = {
+ .DecodeProfile = decoder_guid,
+ .ViewDimension = D3D11_VDOV_DIMENSION_TEXTURE2D,
+ .Texture2D = {
+ .ArraySlice = i,
+ }
+ };
+ hr = ID3D11VideoDevice_CreateVideoDecoderOutputView(device_hwctx->video_device,
+ (ID3D11Resource*) frames_hwctx->texture,
+ &viewDesc,
+ (ID3D11VideoDecoderOutputView**) &sctx->d3d11_views[i]);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Could not create the decoder output view %d\n", i);
+ return AVERROR_UNKNOWN;
+ }
+ }
+
+ hr = ID3D11VideoDevice_CreateVideoDecoder(device_hwctx->video_device, &desc,
+ &config, &sctx->d3d11_decoder);
+ if (FAILED(hr)) {
+ av_log(avctx, AV_LOG_ERROR, "Failed to create D3D11VA video decoder\n");
+ return AVERROR(EINVAL);
+ }
+
+ sctx->d3d11_config = config;
+ sctx->d3d11_texture = frames_hwctx->texture;
+
+ sctx->decoder_ref = bufref_wrap_interface((IUnknown *)sctx->d3d11_decoder);
+ if (!sctx->decoder_ref)
+ return AVERROR(ENOMEM);
+
+ return 0;
+}
+
+#endif
+
static void ff_dxva2_lock(AVCodecContext *avctx)
{
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE);
+ if (sctx->device_ctx) {
+ AVD3D11VADeviceContext *hwctx = sctx->device_ctx->hwctx;
+ hwctx->lock(hwctx->lock_ctx);
+ }
}
#endif
}
@@ -44,15 +474,218 @@ static void ff_dxva2_unlock(AVCodecContext *avctx)
{
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
+ if (sctx->device_ctx) {
+ AVD3D11VADeviceContext *hwctx = sctx->device_ctx->hwctx;
+ hwctx->unlock(hwctx->lock_ctx);
+ }
+ }
+#endif
+}
+
+// This must work before the decoder is created.
+// This somehow needs to be exported to the user.
+static void dxva_adjust_hwframes(AVCodecContext *avctx, AVHWFramesContext *frames_ctx)
+{
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ int surface_alignment, num_surfaces;
+
+ frames_ctx->format = sctx->pix_fmt;
+
+ /* decoding MPEG-2 requires additional alignment on some Intel GPUs,
+ but it causes issues for H.264 on certain AMD GPUs..... */
+ if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO)
+ surface_alignment = 32;
+ /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
+ all coding features have enough room to work with */
+ else if (avctx->codec_id == AV_CODEC_ID_HEVC)
+ surface_alignment = 128;
+ else
+ surface_alignment = 16;
+
+ /* 4 base work surfaces */
+ num_surfaces = 4;
+
+ /* add surfaces based on number of possible refs */
+ if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_HEVC)
+ num_surfaces += 16;
+ else if (avctx->codec_id == AV_CODEC_ID_VP9)
+ num_surfaces += 8;
+ else
+ num_surfaces += 2;
+
+ /* add extra surfaces for frame threading */
+ if (avctx->active_thread_type & FF_THREAD_FRAME)
+ num_surfaces += avctx->thread_count;
+
+ frames_ctx->sw_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ?
+ AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
+ frames_ctx->width = FFALIGN(avctx->coded_width, surface_alignment);
+ frames_ctx->height = FFALIGN(avctx->coded_height, surface_alignment);
+ frames_ctx->initial_pool_size = num_surfaces;
+
+
+#if CONFIG_DXVA2
+ if (frames_ctx->format == AV_PIX_FMT_DXVA2_VLD) {
+ AVDXVA2FramesContext *frames_hwctx = frames_ctx->hwctx;
+
+ frames_hwctx->surface_type = DXVA2_VideoDecoderRenderTarget;
+ }
+#endif
+
+#if CONFIG_D3D11VA
+ if (frames_ctx->format == AV_PIX_FMT_D3D11) {
+ AVD3D11VAFramesContext *frames_hwctx = frames_ctx->hwctx;
+
+ frames_hwctx->BindFlags |= D3D11_BIND_DECODER;
}
#endif
}
-static void *get_surface(const AVFrame *frame)
+int ff_dxva2_decode_init(AVCodecContext *avctx)
{
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ AVHWFramesContext *frames_ctx = NULL;
+ int ret = 0;
+
+ // Old API.
+ if (avctx->hwaccel_context)
+ return 0;
+
+ // (avctx->pix_fmt is not updated yet at this point)
+ sctx->pix_fmt = avctx->hwaccel->pix_fmt;
+
+ if (avctx->codec_id == AV_CODEC_ID_H264 &&
+ (avctx->profile & ~FF_PROFILE_H264_CONSTRAINED) > FF_PROFILE_H264_HIGH) {
+ av_log(avctx, AV_LOG_VERBOSE, "Unsupported H.264 profile for DXVA HWAccel: %d\n",avctx->profile);
+ return AVERROR(ENOTSUP);
+ }
+
+ if (avctx->codec_id == AV_CODEC_ID_HEVC &&
+ avctx->profile != FF_PROFILE_HEVC_MAIN && avctx->profile != FF_PROFILE_HEVC_MAIN_10) {
+ av_log(avctx, AV_LOG_VERBOSE, "Unsupported HEVC profile for DXVA HWAccel: %d\n", avctx->profile);
+ return AVERROR(ENOTSUP);
+ }
+
+ if (!avctx->hw_frames_ctx && !avctx->hw_device_ctx) {
+ av_log(avctx, AV_LOG_ERROR, "Either a hw_frames_ctx or a hw_device_ctx needs to be set for hardware decoding.\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (avctx->hw_frames_ctx) {
+ frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
+ } else {
+ avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);
+ if (!avctx->hw_frames_ctx)
+ return AVERROR(ENOMEM);
+
+ frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
+
+ dxva_adjust_hwframes(avctx, frames_ctx);
+
+ ret = av_hwframe_ctx_init(avctx->hw_frames_ctx);
+ if (ret < 0)
+ goto fail;
+ }
+
+ sctx->device_ctx = frames_ctx->device_ctx;
+
+ if (frames_ctx->format != sctx->pix_fmt ||
+ !((sctx->pix_fmt == AV_PIX_FMT_D3D11 && CONFIG_D3D11VA) ||
+ (sctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD && CONFIG_DXVA2))) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid pixfmt for hwaccel!\n");
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+#if CONFIG_D3D11VA
+ 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);
+ ff_dxva2_unlock(avctx);
+ if (ret < 0)
+ goto fail;
+
+ d3d11_ctx->decoder = sctx->d3d11_decoder;
+ d3d11_ctx->video_context = device_hwctx->video_context;
+ d3d11_ctx->cfg = &sctx->d3d11_config;
+ d3d11_ctx->surface_count = sctx->nb_d3d11_views;
+ d3d11_ctx->surface = sctx->d3d11_views;
+ d3d11_ctx->workaround = sctx->workaround;
+ d3d11_ctx->context_mutex = INVALID_HANDLE_VALUE;
+ }
+#endif
+
+#if CONFIG_DXVA2
+ if (sctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) {
+ AVDXVA2FramesContext *frames_hwctx = frames_ctx->hwctx;
+ struct dxva_context *dxva_ctx = &sctx->ctx.dxva2;
+
+ ff_dxva2_lock(avctx);
+ ret = dxva2_create_decoder(avctx);
+ ff_dxva2_unlock(avctx);
+ if (ret < 0)
+ goto fail;
+
+ dxva_ctx->decoder = sctx->dxva2_decoder;
+ dxva_ctx->cfg = &sctx->dxva2_config;
+ dxva_ctx->surface = frames_hwctx->surfaces;
+ dxva_ctx->surface_count = frames_hwctx->nb_surfaces;
+ dxva_ctx->workaround = sctx->workaround;
+ }
+#endif
+
+ return 0;
+
+fail:
+ ff_dxva2_decode_uninit(avctx);
+ return ret;
+}
+
+int ff_dxva2_decode_uninit(AVCodecContext *avctx)
+{
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ int i;
+
+ av_buffer_unref(&sctx->decoder_ref);
+
+#if CONFIG_D3D11VA
+ for (i = 0; i < sctx->nb_d3d11_views; i++) {
+ if (sctx->d3d11_views[i])
+ ID3D11VideoDecoderOutputView_Release(sctx->d3d11_views[i]);
+ }
+ av_freep(&sctx->d3d11_views);
+#endif
+
+#if CONFIG_DXVA2
+ if (sctx->dxva2_service)
+ IDirectXVideoDecoderService_Release(sctx->dxva2_service);
+#endif
+
+ return 0;
+}
+
+static void *get_surface(AVCodecContext *avctx, const AVFrame *frame)
+{
+#if CONFIG_D3D11VA
+ if (frame->format == AV_PIX_FMT_D3D11) {
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+ 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");
+ return NULL;
+ }
+ return sctx->d3d11_views[index];
+ }
+#endif
return frame->data[3];
}
@@ -60,10 +693,12 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext *avctx,
const AVDXVAContext *ctx,
const AVFrame *frame)
{
- void *surface = get_surface(frame);
+ void *surface = get_surface(avctx, frame);
unsigned i;
#if CONFIG_D3D11VA
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11)
+ return (intptr_t)frame->data[1];
if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {
D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
ID3D11VideoDecoderOutputView_GetDesc((ID3D11VideoDecoderOutputView*) surface, &viewDesc);
@@ -154,6 +789,22 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx,
return result;
}
+static int frame_add_buf(AVFrame *frame, AVBufferRef *ref)
+{
+ int i;
+
+ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
+ if (!frame->buf[i]) {
+ frame->buf[i] = av_buffer_ref(ref);
+ return frame->buf[i] ? 0 : AVERROR(ENOMEM);
+ }
+ }
+
+ // For now we expect that the caller does not use more than
+ // AV_NUM_DATA_POINTERS-1 buffers if the user uses a custom pool.
+ return AVERROR(EINVAL);
+}
+
int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
const void *pp, unsigned pp_size,
const void *qm, unsigned qm_size,
@@ -173,19 +824,26 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
int result, runs = 0;
HRESULT hr;
unsigned type;
+ FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
+
+ if (sctx->decoder_ref) {
+ result = frame_add_buf(frame, sctx->decoder_ref);
+ if (result < 0)
+ return result;
+ }
do {
ff_dxva2_lock(avctx);
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder,
- get_surface(frame),
+ get_surface(avctx, frame),
0, NULL);
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
hr = IDirectXVideoDecoder_BeginFrame(DXVA2_CONTEXT(ctx)->decoder,
- get_surface(frame),
+ get_surface(avctx, frame),
NULL);
#endif
if (hr != E_PENDING || ++runs > 50)
@@ -315,7 +973,8 @@ end:
int ff_dxva2_is_d3d11(const AVCodecContext *avctx)
{
if (CONFIG_D3D11VA)
- return avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD;
+ return avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD ||
+ avctx->pix_fmt == AV_PIX_FMT_D3D11;
else
return 0;
}
diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index 6f5592807a..e3a3f7866e 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -523,10 +523,13 @@ AVHWAccel ff_h264_dxva2_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_H264,
.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_h264_start_frame,
.decode_slice = dxva2_h264_decode_slice,
.end_frame = dxva2_h264_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -536,9 +539,28 @@ AVHWAccel ff_h264_d3d11va_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_H264,
.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_h264_start_frame,
.decode_slice = dxva2_h264_decode_slice,
.end_frame = dxva2_h264_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
+};
+#endif
+
+#if CONFIG_H264_D3D11VA2_HWACCEL
+AVHWAccel ff_h264_d3d11va2_hwaccel = {
+ .name = "h264_d3d11va2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_H264,
+ .pix_fmt = AV_PIX_FMT_D3D11,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
+ .start_frame = dxva2_h264_start_frame,
+ .decode_slice = dxva2_h264_decode_slice,
+ .end_frame = dxva2_h264_end_frame,
+ .frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 1752b78c3f..88f887a1b5 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -427,10 +427,13 @@ AVHWAccel ff_hevc_dxva2_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_HEVC,
.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_hevc_start_frame,
.decode_slice = dxva2_hevc_decode_slice,
.end_frame = dxva2_hevc_end_frame,
.frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -440,9 +443,28 @@ AVHWAccel ff_hevc_d3d11va_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_HEVC,
.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_hevc_start_frame,
.decode_slice = dxva2_hevc_decode_slice,
.end_frame = dxva2_hevc_end_frame,
.frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
+};
+#endif
+
+#if CONFIG_HEVC_D3D11VA2_HWACCEL
+AVHWAccel ff_hevc_d3d11va2_hwaccel = {
+ .name = "hevc_d3d11va2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_HEVC,
+ .pix_fmt = AV_PIX_FMT_D3D11,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
+ .start_frame = dxva2_hevc_start_frame,
+ .decode_slice = dxva2_hevc_decode_slice,
+ .end_frame = dxva2_hevc_end_frame,
+ .frame_priv_data_size = sizeof(struct hevc_dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
diff --git a/libavcodec/dxva2_internal.h b/libavcodec/dxva2_internal.h
index 9bd456119c..352a9db1ab 100644
--- a/libavcodec/dxva2_internal.h
+++ b/libavcodec/dxva2_internal.h
@@ -32,9 +32,11 @@
#if CONFIG_DXVA2
#include "dxva2.h"
+#include "libavutil/hwcontext_dxva2.h"
#endif
#if CONFIG_D3D11VA
#include "d3d11va.h"
+#include "libavutil/hwcontext_d3d11va.h"
#endif
#if HAVE_DXVA_H
/* When targeting WINAPI_FAMILY_PHONE_APP or WINAPI_FAMILY_APP, dxva.h
@@ -46,7 +48,10 @@
#include <dxva.h>
#endif
+#include "libavutil/hwcontext.h"
+
#include "avcodec.h"
+#include "internal.h"
typedef void DECODER_BUFFER_DESC;
@@ -59,7 +64,39 @@ typedef union {
#endif
} AVDXVAContext;
-#define DXVA_CONTEXT(avctx) ((AVDXVAContext *)(avctx)->hwaccel_context)
+typedef struct FFDXVASharedContext {
+ AVBufferRef *decoder_ref;
+
+ // FF_DXVA2_WORKAROUND_* flags
+ uint64_t workaround;
+
+ // E.g. AV_PIX_FMT_D3D11 (same as AVCodecContext.pix_fmt, except during init)
+ enum AVPixelFormat pix_fmt;
+
+ AVHWDeviceContext *device_ctx;
+
+#if CONFIG_D3D11VA
+ ID3D11VideoDecoder *d3d11_decoder;
+ D3D11_VIDEO_DECODER_CONFIG d3d11_config;
+ ID3D11VideoDecoderOutputView **d3d11_views;
+ int nb_d3d11_views;
+ ID3D11Texture2D *d3d11_texture;
+#endif
+
+#if CONFIG_DXVA2
+ IDirectXVideoDecoder *dxva2_decoder;
+ IDirectXVideoDecoderService *dxva2_service;
+ DXVA2_ConfigPictureDecode dxva2_config;
+#endif
+
+ // Legacy (but used by code outside of setup)
+ // In generic mode, DXVA_CONTEXT() will return a pointer to this.
+ AVDXVAContext ctx;
+} FFDXVASharedContext;
+
+#define DXVA_SHARED_CONTEXT(avctx) ((FFDXVASharedContext *)((avctx)->internal->hwaccel_priv_data))
+
+#define DXVA_CONTEXT(avctx) (AVDXVAContext *)((avctx)->hwaccel_context ? (avctx)->hwaccel_context : (&(DXVA_SHARED_CONTEXT(avctx)->ctx)))
#define D3D11VA_CONTEXT(ctx) (&ctx->d3d11va)
#define DXVA2_CONTEXT(ctx) (&ctx->dxva2)
@@ -115,6 +152,10 @@ int ff_dxva2_common_end_frame(AVCodecContext *, AVFrame *,
DECODER_BUFFER_DESC *bs,
DECODER_BUFFER_DESC *slice));
+int ff_dxva2_decode_init(AVCodecContext *avctx);
+
+int ff_dxva2_decode_uninit(AVCodecContext *avctx);
+
int ff_dxva2_is_d3d11(const AVCodecContext *avctx);
#endif /* AVCODEC_DXVA2_INTERNAL_H */
diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c
index 237c898977..b7c69378f0 100644
--- a/libavcodec/dxva2_mpeg2.c
+++ b/libavcodec/dxva2_mpeg2.c
@@ -322,10 +322,13 @@ AVHWAccel ff_mpeg2_dxva2_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG2VIDEO,
.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_mpeg2_start_frame,
.decode_slice = dxva2_mpeg2_decode_slice,
.end_frame = dxva2_mpeg2_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -335,9 +338,28 @@ AVHWAccel ff_mpeg2_d3d11va_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_MPEG2VIDEO,
.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_mpeg2_start_frame,
.decode_slice = dxva2_mpeg2_decode_slice,
.end_frame = dxva2_mpeg2_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
+};
+#endif
+
+#if CONFIG_MPEG2_D3D11VA2_HWACCEL
+AVHWAccel ff_mpeg2_d3d11va2_hwaccel = {
+ .name = "mpeg2_d3d11va2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_MPEG2VIDEO,
+ .pix_fmt = AV_PIX_FMT_D3D11,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
+ .start_frame = dxva2_mpeg2_start_frame,
+ .decode_slice = dxva2_mpeg2_decode_slice,
+ .end_frame = dxva2_mpeg2_end_frame,
+ .frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 43909b634c..e5353cdddc 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -383,10 +383,13 @@ AVHWAccel ff_wmv3_dxva2_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WMV3,
.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_vc1_start_frame,
.decode_slice = dxva2_vc1_decode_slice,
.end_frame = dxva2_vc1_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -396,10 +399,13 @@ AVHWAccel ff_vc1_dxva2_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VC1,
.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_vc1_start_frame,
.decode_slice = dxva2_vc1_decode_slice,
.end_frame = dxva2_vc1_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -409,10 +415,29 @@ AVHWAccel ff_wmv3_d3d11va_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_WMV3,
.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_vc1_start_frame,
.decode_slice = dxva2_vc1_decode_slice,
.end_frame = dxva2_vc1_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
+};
+#endif
+
+#if CONFIG_WMV3_D3D11VA2_HWACCEL
+AVHWAccel ff_wmv3_d3d11va2_hwaccel = {
+ .name = "wmv3_d3d11va2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_WMV3,
+ .pix_fmt = AV_PIX_FMT_D3D11,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
+ .start_frame = dxva2_vc1_start_frame,
+ .decode_slice = dxva2_vc1_decode_slice,
+ .end_frame = dxva2_vc1_end_frame,
+ .frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -422,9 +447,28 @@ AVHWAccel ff_vc1_d3d11va_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VC1,
.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
+ .start_frame = dxva2_vc1_start_frame,
+ .decode_slice = dxva2_vc1_decode_slice,
+ .end_frame = dxva2_vc1_end_frame,
+ .frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
+};
+#endif
+
+#if CONFIG_VC1_D3D11VA2_HWACCEL
+AVHWAccel ff_vc1_d3d11va2_hwaccel = {
+ .name = "vc1_d3d11va2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_VC1,
+ .pix_fmt = AV_PIX_FMT_D3D11,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_vc1_start_frame,
.decode_slice = dxva2_vc1_decode_slice,
.end_frame = dxva2_vc1_end_frame,
.frame_priv_data_size = sizeof(struct dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
diff --git a/libavcodec/dxva2_vp9.c b/libavcodec/dxva2_vp9.c
index df098dc406..6d87fdd9f2 100644
--- a/libavcodec/dxva2_vp9.c
+++ b/libavcodec/dxva2_vp9.c
@@ -314,10 +314,13 @@ AVHWAccel ff_vp9_dxva2_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VP9,
.pix_fmt = AV_PIX_FMT_DXVA2_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_vp9_start_frame,
.decode_slice = dxva2_vp9_decode_slice,
.end_frame = dxva2_vp9_end_frame,
.frame_priv_data_size = sizeof(struct vp9_dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
@@ -327,9 +330,28 @@ AVHWAccel ff_vp9_d3d11va_hwaccel = {
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_VP9,
.pix_fmt = AV_PIX_FMT_D3D11VA_VLD,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
.start_frame = dxva2_vp9_start_frame,
.decode_slice = dxva2_vp9_decode_slice,
.end_frame = dxva2_vp9_end_frame,
.frame_priv_data_size = sizeof(struct vp9_dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
+};
+#endif
+
+#if CONFIG_VP9_D3D11VA2_HWACCEL
+AVHWAccel ff_vp9_d3d11va2_hwaccel = {
+ .name = "vp9_d3d11va2",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_VP9,
+ .pix_fmt = AV_PIX_FMT_D3D11,
+ .init = ff_dxva2_decode_init,
+ .uninit = ff_dxva2_decode_uninit,
+ .start_frame = dxva2_vp9_start_frame,
+ .decode_slice = dxva2_vp9_decode_slice,
+ .end_frame = dxva2_vp9_end_frame,
+ .frame_priv_data_size = sizeof(struct vp9_dxva2_picture_context),
+ .priv_data_size = sizeof(FFDXVASharedContext),
};
#endif
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 23ca32a39d..faa684c938 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -758,7 +758,7 @@ static void init_scan_tables(H264Context *h)
static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
{
#define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
- CONFIG_H264_D3D11VA_HWACCEL + \
+ (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
CONFIG_H264_VAAPI_HWACCEL + \
(CONFIG_H264_VDA_HWACCEL * 2) + \
CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
@@ -834,6 +834,7 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
#endif
#if CONFIG_H264_D3D11VA_HWACCEL
*fmt++ = AV_PIX_FMT_D3D11VA_VLD;
+ *fmt++ = AV_PIX_FMT_D3D11;
#endif
#if CONFIG_H264_VAAPI_HWACCEL
*fmt++ = AV_PIX_FMT_VAAPI;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 0f1469fc0f..f6bc5efa96 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -339,7 +339,7 @@ static void export_stream_params(AVCodecContext *avctx, const HEVCParamSets *ps,
static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
{
- #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + CONFIG_HEVC_D3D11VA_HWACCEL + CONFIG_HEVC_VAAPI_HWACCEL + CONFIG_HEVC_VDPAU_HWACCEL)
+ #define HWACCEL_MAX (CONFIG_HEVC_DXVA2_HWACCEL + CONFIG_HEVC_D3D11VA_HWACCEL * 2 + CONFIG_HEVC_VAAPI_HWACCEL + CONFIG_HEVC_VDPAU_HWACCEL)
enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
switch (sps->pix_fmt) {
@@ -350,6 +350,7 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
#endif
#if CONFIG_HEVC_D3D11VA_HWACCEL
*fmt++ = AV_PIX_FMT_D3D11VA_VLD;
+ *fmt++ = AV_PIX_FMT_D3D11;
#endif
#if CONFIG_HEVC_VAAPI_HWACCEL
*fmt++ = AV_PIX_FMT_VAAPI;
@@ -364,6 +365,7 @@ static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
#endif
#if CONFIG_HEVC_D3D11VA_HWACCEL
*fmt++ = AV_PIX_FMT_D3D11VA_VLD;
+ *fmt++ = AV_PIX_FMT_D3D11;
#endif
#if CONFIG_HEVC_VAAPI_HWACCEL
*fmt++ = AV_PIX_FMT_VAAPI;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 58a5a20864..22c29c1505 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1159,6 +1159,7 @@ static const enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
#endif
#if CONFIG_MPEG2_D3D11VA_HWACCEL
AV_PIX_FMT_D3D11VA_VLD,
+ AV_PIX_FMT_D3D11,
#endif
#if CONFIG_MPEG2_VAAPI_HWACCEL
AV_PIX_FMT_VAAPI,
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 75d336583c..16c601e756 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1150,6 +1150,7 @@ static const enum AVPixelFormat vc1_hwaccel_pixfmt_list_420[] = {
#endif
#if CONFIG_VC1_D3D11VA_HWACCEL
AV_PIX_FMT_D3D11VA_VLD,
+ AV_PIX_FMT_D3D11,
#endif
#if CONFIG_VC1_VAAPI_HWACCEL
AV_PIX_FMT_VAAPI,
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 1eaaf832ca..06615268f3 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
#include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57
-#define LIBAVCODEC_VERSION_MINOR 99
+#define LIBAVCODEC_VERSION_MINOR 100
#define LIBAVCODEC_VERSION_MICRO 102
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
index 4d7310f6d4..7d8aced8c8 100644
--- a/libavcodec/vp9.c
+++ b/libavcodec/vp9.c
@@ -113,7 +113,7 @@ fail:
static int update_size(AVCodecContext *avctx, int w, int h)
{
-#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + CONFIG_VP9_D3D11VA_HWACCEL + CONFIG_VP9_VAAPI_HWACCEL)
+#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + CONFIG_VP9_D3D11VA_HWACCEL * 2 + CONFIG_VP9_VAAPI_HWACCEL)
enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
VP9Context *s = avctx->priv_data;
uint8_t *p;
@@ -132,6 +132,7 @@ static int update_size(AVCodecContext *avctx, int w, int h)
#endif
#if CONFIG_VP9_D3D11VA_HWACCEL
*fmtp++ = AV_PIX_FMT_D3D11VA_VLD;
+ *fmtp++ = AV_PIX_FMT_D3D11;
#endif
#if CONFIG_VP9_VAAPI_HWACCEL
*fmtp++ = AV_PIX_FMT_VAAPI;