From 4dec101acc393fbfe9a8ce0237b9efbae3f20139 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 6 Jun 2017 18:51:09 +0200 Subject: dxva: preparations for new hwaccel API The actual hwaccel code will need to access an internal context instead of avctx->hwaccel_context, so add a new DXVA_CONTEXT() macro, that will dispatch between the "old" external and the new internal context. Also, the new API requires a new D3D11 pixfmt, so all places which check for the pixfmt need to be adjusted. Introduce a ff_dxva2_is_d3d11() function, which does the check. Signed-off-by: Diego Biurrun --- libavcodec/dxva2.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'libavcodec/dxva2.c') diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c index b0452b6a9a..fe6dbbc030 100644 --- a/libavcodec/dxva2.c +++ b/libavcodec/dxva2.c @@ -71,7 +71,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, HRESULT hr; #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) + if (ff_dxva2_is_d3d11(avctx)) hr = ID3D11VideoContext_GetDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type, @@ -91,7 +91,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, memcpy(dxva_data, data, size); #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { + if (ff_dxva2_is_d3d11(avctx)) { D3D11_VIDEO_DECODER_BUFFER_DESC *dsc11 = dsc; memset(dsc11, 0, sizeof(*dsc11)); dsc11->BufferType = type; @@ -116,7 +116,7 @@ int ff_dxva2_commit_buffer(AVCodecContext *avctx, } #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) + if (ff_dxva2_is_d3d11(avctx)) hr = ID3D11VideoContext_ReleaseDecoderBuffer(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, type); #endif #if CONFIG_DXVA2 @@ -139,7 +139,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, DECODER_BUFFER_DESC *bs, DECODER_BUFFER_DESC *slice)) { - AVDXVAContext *ctx = avctx->hwaccel_context; + AVDXVAContext *ctx = DXVA_CONTEXT(avctx); unsigned buffer_count = 0; #if CONFIG_D3D11VA D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4]; @@ -154,7 +154,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, do { #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { + if (ff_dxva2_is_d3d11(avctx)) { if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE); hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, @@ -171,7 +171,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, if (hr != E_PENDING || ++runs > 50) break; #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) + if (ff_dxva2_is_d3d11(avctx)) if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); #endif @@ -181,7 +181,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, if (FAILED(hr)) { av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr); #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) + if (ff_dxva2_is_d3d11(avctx)) if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); #endif @@ -189,7 +189,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, } #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { + if (ff_dxva2_is_d3d11(avctx)) { buffer = &buffer11[buffer_count]; type = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS; } @@ -212,7 +212,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, if (qm_size > 0) { #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { + if (ff_dxva2_is_d3d11(avctx)) { buffer = &buffer11[buffer_count]; type = D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX; } @@ -235,7 +235,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, } #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { + if (ff_dxva2_is_d3d11(avctx)) { buffer = &buffer11[buffer_count + 0]; buffer_slice = &buffer11[buffer_count + 1]; } @@ -262,7 +262,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, assert(buffer_count == 1 + (qm_size > 0) + 2); #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) + if (ff_dxva2_is_d3d11(avctx)) hr = ID3D11VideoContext_SubmitDecoderBuffers(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, buffer_count, buffer11); @@ -284,7 +284,7 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, end: #if CONFIG_D3D11VA - if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) { + if (ff_dxva2_is_d3d11(avctx)) { hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder); if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); @@ -301,3 +301,11 @@ end: return result; } + +int ff_dxva2_is_d3d11(const AVCodecContext *avctx) +{ + if (CONFIG_D3D11VA) + return avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD; + else + return 0; +} -- cgit v1.2.3