diff options
author | wm4 <nfxjfg@googlemail.com> | 2017-06-06 18:51:10 +0200 |
---|---|---|
committer | wm4 <nfxjfg@googlemail.com> | 2017-06-27 18:05:02 +0200 |
commit | 5659f7404731415c7e1cfdf4d8b0afeb6b1132de (patch) | |
tree | 6bbee7408b14f925736887c5f16c96c0feae4a7e | |
parent | ab28108a361196134704071b7b34c42fc7d747c7 (diff) | |
download | ffmpeg-5659f7404731415c7e1cfdf4d8b0afeb6b1132de.tar.gz |
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 831cfe10b40414915fe7b6088158421fe02e2b2d.
Signed-off-by: Diego Biurrun <diego@biurrun.de>
-rw-r--r-- | libavcodec/dxva2.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c index 6b214c1877..9138216745 100644 --- a/libavcodec/dxva2.c +++ b/libavcodec/dxva2.c @@ -29,6 +29,28 @@ #include "avcodec.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) { return frame->data[3]; @@ -153,14 +175,12 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, unsigned type; do { + ff_dxva2_lock(avctx); #if CONFIG_D3D11VA - if (ff_dxva2_is_d3d11(avctx)) { - if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) - WaitForSingleObjectEx(D3D11VA_CONTEXT(ctx)->context_mutex, INFINITE, FALSE); + if (ff_dxva2_is_d3d11(avctx)) hr = ID3D11VideoContext_DecoderBeginFrame(D3D11VA_CONTEXT(ctx)->video_context, D3D11VA_CONTEXT(ctx)->decoder, get_surface(frame), 0, NULL); - } #endif #if CONFIG_DXVA2 if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) @@ -170,21 +190,13 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, #endif if (hr != E_PENDING || ++runs > 50) break; -#if CONFIG_D3D11VA - if (ff_dxva2_is_d3d11(avctx)) - if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) - ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); -#endif + ff_dxva2_unlock(avctx); av_usleep(2000); } while(1); if (FAILED(hr)) { av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%x\n", hr); -#if CONFIG_D3D11VA - if (ff_dxva2_is_d3d11(avctx)) - if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) - ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); -#endif + ff_dxva2_unlock(avctx); return -1; } @@ -284,16 +296,14 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, AVFrame *frame, end: #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); - if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE) - ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex); - } #endif #if CONFIG_DXVA2 if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD) hr = IDirectXVideoDecoder_EndFrame(DXVA2_CONTEXT(ctx)->decoder, NULL); #endif + ff_dxva2_unlock(avctx); if (FAILED(hr)) { av_log(avctx, AV_LOG_ERROR, "Failed to end frame: 0x%x\n", hr); result = -1; |