• 大小: 12.01MB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2023-06-16
  • 语言: 其他
  • 标签: ffmpeg  

资源简介

Dxva2解码渲染Demo的VS2013工程,使用ffmpeg和dxva2实现视频的解码和渲染

资源截图

代码片段和文件信息

#include “stdafx.h“
#include “D3D9VideoRenderChannel.h“


int CD3D9VideoRenderChannel::CreateNew(CD3D9VideoRenderChannel **ppv)
{
if (ppv == nullptr)
return 1;

(*ppv) = new CD3D9VideoRenderChannel();
if ((*ppv) == nullptr)
{
return 1;
}

return 0;
}

void CD3D9VideoRenderChannel::Release()
{
delete this;
}

bool CD3D9VideoRenderChannel::IsOpen()
{
return m_bOpened;
}

int CD3D9VideoRenderChannel::OpenVideoDraw(HWND hWnd uint32_t uWidth uint32_t uHeight)
{
if ((hWnd == nullptr) || (uWidth < 0) || (uWidth > 5000) || (uHeight < 0) || (uHeight > 5000))
return 1;

m_hRenderWnd = hWnd;
m_uWidth  = uWidth;
m_uHeight  = uHeight;

CloseVideoDraw();

HRESULT hResult = S_OK;
DWORD dwBehaviorFlags = 0;

do 
{
m_pD3D9 = Direct3DCreate9(D3D_SDK_VERSION);
CHECK_BREAK(m_pD3D9 == nullptr);
D3DDISPLAYMODE sDisplayMode = { 0 };
hResult = m_pD3D9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT &sDisplayMode);
CHECK_BREAK(FAILED(hResult));
D3DCAPS9 sCaps;
hResult = m_pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT D3DDEVTYPE_HAL &sCaps);
CHECK_BREAK(FAILED(hResult));
dwBehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE;
if (sCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
dwBehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE;
}
memset(&m_sPresentParams 0 sizeof(m_sPresentParams));
m_sPresentParams.Windowed = TRUE;
m_sPresentParams.BackBufferFormat = sDisplayMode.Format;
m_sPresentParams.BackBufferCount = 0;
m_sPresentParams.hDeviceWindow = m_hRenderWnd;
m_sPresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
m_sPresentParams.EnableAutoDepthStencil = FALSE;
m_sPresentParams.Flags = D3DPRESENTFLAG_VIDEO;
m_sPresentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
m_sPresentParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
hResult = m_pD3D9->CreateDevice(D3DADAPTER_DEFAULT D3DDEVTYPE_HAL m_hRenderWnd dwBehaviorFlags &m_sPresentParams &m_pD3DDevice9);
CHECK_BREAK(FAILED(hResult));
m_bOpened = true;
} while (false);

if (!m_bOpened)
{
CloseVideoDraw();
}

return m_bOpened ? 0 : 1;
}

void CD3D9VideoRenderChannel::CloseVideoDraw()
{
if (m_pBackBuffer)
{
m_pBackBuffer->Release();
m_pBackBuffer = nullptr;
}
if (m_pD3DDevice9)
{
IDirect3DDevice9_Release(m_pD3DDevice9);
m_pD3DDevice9 = nullptr;
}
if (m_pD3D9)
{
IDirect3D9_Release(m_pD3D9);
m_pD3D9 = nullptr;
}

m_bOpened = false;
}

int CD3D9VideoRenderChannel::ChangeVideoParam(HWND hWnd uint32_t uWidth uint32_t uHeight)
{
CloseVideoDraw();
return OpenVideoDraw(hWnd uWidth uHeight);
}

int CD3D9VideoRenderChannel::RenderData(AVframe *pframe)
{
assert(pframe != nullptr);

int iReturn = 1;

while (m_bOpened)
{
iReturn = 0;
RECT rcViewport;
GetClientRec

评论

共有 条评论