Commit 5659f740 authored by wm4's avatar wm4

dxva: move d3d11 locking/unlocking to functions

I want to make it non-mandatory to set a mutex in the D3D11 device
context, and replacing it with user callbacks seems like the best
solution. This is preparation for it. Also makes the code slightly more
readable.

Merges Libav commit 831cfe10.
Signed-off-by: 's avatarDiego Biurrun <diego@biurrun.de>
parent ab28108a
...@@ -29,6 +29,28 @@ ...@@ -29,6 +29,28 @@
#include "avcodec.h" #include "avcodec.h"
#include "dxva2_internal.h" #include "dxva2_internal.h"
static void ff_dxva2_lock(AVCodecContext *avctx)
{
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE);
}
#endif
}
static void ff_dxva2_unlock(AVCodecContext *avctx)
{
#if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) {
AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
}
#endif
}
static void *get_surface(const AVFrame *frame) static void *get_surface(const AVFrame *frame)
{ {
return frame->data[3]; return frame->data[3];
...@@ -153,14 +175,12 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -153,14 +175,12 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
unsigned type; unsigned type;
do { do {
ff_dxva2_lock(avctx);
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) { 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, hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder,
get_surface(frame), get_surface(frame),
0, NULL); 0, NULL);
}
#endif #endif
#if CONFIG_DXVA2 #if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
...@@ -170,21 +190,13 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -170,21 +190,13 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
#endif #endif
if (hr != E_PENDING || ++runs > 50) if (hr != E_PENDING || ++runs > 50)
break; break;
#if CONFIG_D3D11VA ff_dxva2_unlock(avctx);
if (ff_dxva2_is_d3d11(avctx))
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
#endif
av_usleep(2000); av_usleep(2000);
} while(1); } while(1);
if (FAILED(hr)) { 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", hr);
#if CONFIG_D3D11VA ff_dxva2_unlock(avctx);
if (ff_dxva2_is_d3d11(avctx))
if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
#endif
return -1; return -1;
} }
...@@ -284,16 +296,14 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, ...@@ -284,16 +296,14 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame,
end: end:
#if CONFIG_D3D11VA #if CONFIG_D3D11VA
if (ff_dxva2_is_d3d11(avctx)) { if (ff_dxva2_is_d3d11(avctx))
hr = ID3D11VideoContext_DecoderEndFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder); 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);
}
#endif #endif
#if CONFIG_DXVA2 #if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
hr = IDirectXVideoDecoder_EndFrame(DXVA2_CONTEXT(ctx)->decoder, NULL); hr = IDirectXVideoDecoder_EndFrame(DXVA2_CONTEXT(ctx)->decoder, NULL);
#endif #endif
ff_dxva2_unlock(avctx);
if (FAILED(hr)) { 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", hr);
result = -1; result = -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment