#include "libavutil/time.h"
#include "avcodec.h"
-#include "mpegvideo.h"
#include "dxva2_internal.h"
void *ff_dxva2_get_surface(const AVFrame *frame)
void *surface = ff_dxva2_get_surface(frame);
unsigned i;
- for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++)
- if (DXVA_CONTEXT_SURFACE(avctx, ctx, i) == surface)
+ for (i = 0; i < DXVA_CONTEXT_COUNT(avctx, ctx); i++) {
+#if CONFIG_D3D11VA
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD && ctx->d3d11va.surface[i] == surface) {
+ D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
+ ID3D11VideoDecoderOutputView_GetDesc(ctx->d3d11va.surface[i], &viewDesc);
+ return viewDesc.Texture2D.ArraySlice;
+ }
+#endif
+#if CONFIG_DXVA2
+ if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD && ctx->dxva2.surface[i] == surface)
return i;
+#endif
+ }
assert(0);
return 0;
{
AVDXVAContext *ctx = avctx->hwaccel_context;
unsigned buffer_count = 0;
+#if CONFIG_D3D11VA
D3D11_VIDEO_DECODER_BUFFER_DESC buffer11[4];
+#endif
+#if CONFIG_DXVA2
DXVA2_DecodeBufferDesc buffer2[4];
+#endif
DECODER_BUFFER_DESC *buffer,*buffer_slice;
int result, runs = 0;
HRESULT hr;
do {
#if CONFIG_D3D11VA
- if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {
+ 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,
ff_dxva2_get_surface(frame),
0, NULL);
+ }
#endif
#if CONFIG_DXVA2
if (avctx->pix_fmt == AV_PIX_FMT_DXVA2_VLD)
ff_dxva2_get_surface(frame),
NULL);
#endif
- if (hr == E_PENDING)
- av_usleep(2000);
- } while (hr == E_PENDING && ++runs < 50);
+ if (hr != E_PENDING || ++runs > 50)
+ break;
+#if CONFIG_D3D11VA
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
+ if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
+ ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
+#endif
+ av_usleep(2000);
+ } while(1);
if (FAILED(hr)) {
av_log(avctx, AV_LOG_ERROR, "Failed to begin frame: 0x%lx\n", hr);
+#if CONFIG_D3D11VA
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
+ if (D3D11VA_CONTEXT(ctx)->context_mutex != INVALID_HANDLE_VALUE)
+ ReleaseMutex(D3D11VA_CONTEXT(ctx)->context_mutex);
+#endif
return -1;
}
end:
#if CONFIG_D3D11VA
- if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD)
+ if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {
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)