Combine DXVA2 native decode with opengl glsl in different thread

For the developers that use FFmpeg in Windows software.
Post Reply
luzhigang
Posts: 1
Joined: Tue Dec 06, 2016 7:45 am

Combine DXVA2 native decode with opengl glsl in different thread

Post by luzhigang » Thu Sep 07, 2017 8:57 am

Background:
  • In order to play 4K resolution video in windows.Now I am using the DXVA2 native to decode,then use opengl glsl to render.
  • After DXVA2 decode, pass the decoded frame direct into opengl without copy the decoded frame back to cpu memory.
Problem:
Because of the IDirect3DSurface9_LockRect and IDirect3DSurface9_UnLockRect, can't pass the decoded frame to other function/thread,So I must to use opengl render immediately after decode.

static int dxva2_retrieve_data(AVCodecContext *s, AVFrame *frame)
{
LPDIRECT3DSURFACE9 surface = (LPDIRECT3DSURFACE9)frame->data[3];
InputStream *ist = (InputStream *)s->opaque;
DXVA2Context *ctx = (DXVA2Context*)ist->hwaccel_ctx;
D3DSURFACE_DESC surfaceDesc;
D3DLOCKED_RECT LockedRect;
HRESULT hr;
int ret;

IDirect3DSurface9_GetDesc(surface, &surfaceDesc);
hr = IDirect3DSurface9_LockRect(surface, &LockedRect, NULL, D3DLOCK_READONLY);
if (FAILED(hr)) {
av_log(NULL, AV_LOG_ERROR, "Unable to lock DXVA2 surface\n");
return AVERROR_UNKNOWN;
}
picture->data[0] = (uint8_t*)LockedRect.pBits;
picture->data[1] = (uint8_t*)LockedRect.pBits + LockedRect.Pitch * surfaceDesc.Height;
frameWidth = frame->width;
frameHeight = frame->height;
//opengl draw start
Draw();
//opengl draw end
picture->data[0] = nullptr;
picture->data[1] = nullptr;
IDirect3DSurface9_UnlockRect(surface);
return 0;
}

Expected:
  • How can I seperate the DXVA2 decode and opengl render to different thread.
  • Is there method to copy/save the decoded frame in gpu? So that I also can seperate DXVA2 decode and opengl render.

Post Reply