问题描述
我使用硬件加速从DXVA2
视频解码器中获得了IDirect3DSurface9
.
I got a IDirect3DSurface9
from DXVA2
video decoder using hardware acceleration.
我尝试通过其句柄在我的窗口"上渲染此硬件IDirect3DSurface9
.以下是我的摘要代码.
I'm try to Render this hardware IDirect3DSurface9
on My Window via its handle. The following is my summary code.
首先,我打电话给dxva2_init(AVCodecContext *s, HWND hwnd)
; hwnd
是窗口的句柄
The first, I call dxva2_init(AVCodecContext *s, HWND hwnd)
; with hwnd
is window's handle
int dxva2_init(AVCodecContext *s, HWND hwnd)
{
InputStream *ist = (InputStream *)s->opaque;
int loglevel = (ist->hwaccel_id == HWACCEL_AUTO) ? AV_LOG_VERBOSE : AV_LOG_ERROR;
DXVA2Context *ctx;
int ret;
if (!ist->hwaccel_ctx) {
ret = dxva2_alloc(s);
if (ret < 0)
return ret;
}
ctx = (DXVA2Context *)ist->hwaccel_ctx;
ctx->deviceHandle = hwnd;
if (s->codec_id == AV_CODEC_ID_H264 &&
(s->profile & ~FF_PROFILE_H264_CONSTRAINED) > FF_PROFILE_H264_HIGH) {
av_log(NULL, loglevel, "Unsupported H.264 profile for DXVA2 HWAccel: %d\n", s->profile);
return AVERROR(EINVAL);
}
if (ctx->decoder)
dxva2_destroy_decoder(s);
ret = dxva2_create_decoder(s);
if (ret < 0) {
av_log(NULL, loglevel, "Error creating the DXVA2 decoder\n");
return ret;
}
return 0;
}
解码成功后,我得到一个IDirect3DSurface9
,并通过以下函数对其进行渲染.
After Decoding successful, I got got a IDirect3DSurface9
, and I Render it by following function.
int dxva2_render(AVCodecContext *s, AVFrame *frame)
{
LPDIRECT3DSURFACE9 surface = (LPDIRECT3DSURFACE9)frame->data[3];
InputStream *ist = (InputStream *)s->opaque;
DXVA2Context *ctx = (DXVA2Context *)ist->hwaccel_ctx;
try
{
lockRenderCS.Enter();
HRESULT hr = ctx->d3d9device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0);
if (hr != D3D_OK)
return 0;
hr = ctx->d3d9device->BeginScene();
if (hr != D3D_OK)
return 0;
hr = ctx->d3d9device->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
if (hr != D3D_OK)
return 0;
hr = ctx->d3d9device->StretchRect(surface, NULL, pBackBuffer, NULL, D3DTEXF_LINEAR);
if (hr != D3D_OK)
return 0;
hr = ctx->d3d9device->EndScene();
if (hr != D3D_OK)
return 0;
hr = ctx->d3d9device->Present(NULL, NULL, NULL, NULL);
if (hr != D3D_OK)
return 0;
}
finally
{
lockRenderCS.Leave();
}
return 0;
}
注意:上面的所有D3D函数:Clear(), BeginScene(), GetBackBuffer(), StretchRect(), EndScene(), Present()
均返回成功.但是该框架未显示在我的窗口"中.
Note: All D3D function above: Clear(), BeginScene(), GetBackBuffer(), StretchRect(), EndScene(), Present()
were return Successful. But the frame was not display on My Window.
我猜想,我想念一些与DXVA2Context
集成的My Window Handle的代码.在此代码中,我仅在函数dxva2_init()
中分配:ctx->deviceHandle = hwnd;
.
I Guess that, I miss some code for integrated My Window Handle with DXVA2Context
. In this code I only assign: ctx->deviceHandle = hwnd;
in function dxva2_init()
.
我搜索了很多次,但是到目前为止,我仍然找不到解决方案,有人可以帮助我吗?
I search many times, but so far I still cannot find the solution, Anyone can help me?
非常感谢!
推荐答案
我可以提供完整代码.
没有完整的代码,我建议您检查对StretchRect的使用,就像这样:
Without full code, i suggest you to check your use of StretchRect, just like that :
IDirect3DDevice9 :: StretchRect
- 驱动程序支持各不相同.请参阅下面的驱动程序支持部分,以了解哪些驱动程序支持哪些源格式和目标格式.
- 必须在默认内存池中创建源表面和目标表面.
- 如果指定了过滤,则必须设置适当的过滤器上限(请参阅D3DCAPS9中的StretchRectFilterCaps).
- 等...
- Driver support varies. See the section on driver support (below) to see which drivers support which source and destination formats.
- The source and destination surfaces must be created in the default memory pool.
- If filtering is specified, you must set the appropriate filter caps (see StretchRectFilterCaps in D3DCAPS9).
- etc...
例如,我们对您的d3d9device/surface9(创建/初始化/参数/等...)一无所知.
The idea behind this, we don't know nothing about your d3d9device/surface9 (creation/initialization/parameter/etc...), for example.
此外,您可以从我的项目中研究此代码以进行dxva2解码:
Also, you can study this code from my project to do dxva2 decoding :
这篇关于从DXVA2渲染IDirect3DSurface9?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!