Impl(HRESULT &hr, HWND hWnd, IDirect3DDeviceManager9 **pManager, DWORD nAdapterNum, bool WaitVsync){ m_DWM.Initialize() ; hr = m_D3D.InitializeD3D9(hWnd, nAdapterNum, WaitVsync) ; if (FAILED(hr)){ return ; } UINT resetToken = 0; hr = DXVA2CreateDirect3DDeviceManager9(&resetToken, pManager); if (SUCCEEDED(hr)){ IDirect3DDeviceManager9 *p = *pManager ; CDeviceManager dev(m_D3D) ; hr = p->ResetDevice(dev.GetDevice(), resetToken); if (SUCCEEDED(hr)){ _deviceManager = p; } } CDeviceManager dev(m_D3D) ; hr = InitializeDXVAHD(dev.GetDevice()) ; if (FAILED(hr)){ return ; } }
void TvideoCodecQuickSync::setOutputPin(IPin *pPin) { if (!ok) { return; } if (NULL == pPin) { m_QuickSync->SetD3DDeviceManager(NULL); } IDirect3DDeviceManager9 *pDeviceManager = NULL; IMFGetService *pGetService = NULL; HRESULT hr = pPin->QueryInterface(__uuidof(IMFGetService), (void**)&pGetService); if (SUCCEEDED(hr)) { hr = pGetService->GetService(MR_VIDEO_ACCELERATION_SERVICE, IID_IDirect3DDeviceManager9, (void**)&pDeviceManager); } m_QuickSync->SetD3DDeviceManager((SUCCEEDED(hr)) ? pDeviceManager : NULL); if (pDeviceManager) { pDeviceManager->Release(); } if (pGetService) { pGetService->Release(); } }
bool CDeinterlacer_DXVA::Initialize() { TRACE(TEXT("CDeinterlacer_DXVA::Initialize()\n")); HRESULT hr; if (!m_pDeviceManager) { if (!m_hD3D9Lib) { m_hD3D9Lib = ::LoadLibrary(TEXT("d3d9.dll")); if (!m_hD3D9Lib) { TRACE(TEXT("Failed to load d3d9.dll\n")); return false; } } if (!m_hDXVA2Lib) { m_hDXVA2Lib = ::LoadLibrary(TEXT("dxva2.dll")); if (!m_hDXVA2Lib) { TRACE(TEXT("Failed to load dxva2.dll\n")); return false; } } if (!m_pDirect3D9) { auto pDirect3DCreate9 = reinterpret_cast<decltype(Direct3DCreate9)*>(::GetProcAddress(m_hD3D9Lib, "Direct3DCreate9")); if (!pDirect3DCreate9) { TRACE(TEXT("Failed to get Direct3DCreate9() address\n")); return false; } m_pDirect3D9 = pDirect3DCreate9(D3D_SDK_VERSION); if (!m_pDirect3D9) { TRACE(TEXT("Failed to create IDirect3D9\n")); return false; } } if (!m_pDirect3DDevice9) { D3DPRESENT_PARAMETERS d3dpp = {}; d3dpp.BackBufferWidth = 640; d3dpp.BackBufferHeight = 480; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = nullptr; d3dpp.Windowed = TRUE; d3dpp.EnableAutoDepthStencil = FALSE; d3dpp.Flags = D3DPRESENTFLAG_VIDEO | D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; d3dpp.FullScreen_RefreshRateInHz = 0; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; IDirect3DDevice9 *pDirect3DDevice9; hr = m_pDirect3D9->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, nullptr, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDirect3DDevice9); if (hr != D3D_OK) { TRACE(TEXT("IDirect3D9::CreateDevice() failed (%x)\n"), hr); return false; } m_pDirect3DDevice9 = pDirect3DDevice9; } auto pDXVA2CreateDirect3DDeviceManager9 = reinterpret_cast<decltype(DXVA2CreateDirect3DDeviceManager9)*>( ::GetProcAddress(m_hDXVA2Lib, "DXVA2CreateDirect3DDeviceManager9")); if (!pDXVA2CreateDirect3DDeviceManager9) { TRACE(TEXT("Failed to get DXVA2CreateDirect3DDeviceManager9() address\n")); return false; } IDirect3DDeviceManager9 *pDeviceManager; hr = pDXVA2CreateDirect3DDeviceManager9(&m_ResetToken, &pDeviceManager); if (FAILED(hr)) { TRACE(TEXT("DXVA2CreateDirect3DDeviceManager9() failed (%x)\n"), hr); return false; } hr = pDeviceManager->ResetDevice(m_pDirect3DDevice9, m_ResetToken); if (FAILED(hr)) { TRACE(TEXT("IDirect3DDeviceManager9::ResetDevice() failed (%x)\n"), hr); pDeviceManager->Release(); return false; } m_pDeviceManager = pDeviceManager; } if (!m_pVideoProcessorService) { IDirectXVideoProcessorService *pVideoProcessorService; if (m_hDevice) { hr = m_pDeviceManager->GetVideoService(m_hDevice, IID_PPV_ARGS(&pVideoProcessorService)); if (FAILED(hr)) { TRACE(TEXT("IDirect3DDeviceManager9::GetVideoService() failed (%x)\n"), hr); return false; } } else { HANDLE hDevice; hr = m_pDeviceManager->OpenDeviceHandle(&hDevice); if (FAILED(hr)) { TRACE(TEXT("IDirect3DDeviceManager9::OpenDeviceHandle() failed (%x)\n"), hr); return false; } hr = m_pDeviceManager->GetVideoService(hDevice, IID_PPV_ARGS(&pVideoProcessorService)); m_pDeviceManager->CloseDeviceHandle(hDevice); if (FAILED(hr)) { TRACE(TEXT("IDirect3DDeviceManager9::GetVideoService() failed (%x)\n"), hr); return false; } } m_pVideoProcessorService = pVideoProcessorService; } m_fOpenFailed = false; return true; }