void CudaVideoRender::setVideoFile(LPCWSTR a_pVideoFilename) { m_sFileName=a_pVideoFilename; //char* video_file=new char[MAX_PATH]; //WideCharToMultiByte( CP_ACP, 0, a_pVideoFilename, -1, video_file, MAX_PATH, NULL, NULL ); // Find out the video size m_bIsProgressive = loadVideoSource(a_pVideoFilename, m_nVideoWidth, m_nVideoHeight, m_nWindowWidth, m_nWindowHeight ); //delete video_file; // Initialize CUDA //TODO: dont init cuda twice?? cuInit(0); int bTCC = 0; // If we are using TCC driver, then always turn off interop if (bTCC) m_bInterop = false; // Initialize CUDA/D3D9 context and other video memory resources initCudaResources(m_bInterop, bTCC); m_pVideoSource->start(); }
HRESULT CudaVideoRender::reinitCudaResources() { // Free resources cleanup(false); // Reinit VideoSource and Frame Queue m_bIsProgressive = loadVideoSource(m_sFileName, m_nVideoWidth, m_nVideoHeight, m_nWindowWidth, m_nWindowHeight ); //m_bIsProgressive = loadVideoSource(m_sFileName.c_str(), m_nVideoWidth, m_nVideoHeight, m_nWindowWidth, m_nWindowHeight ); /////////////////Change/////////////////////////// initCudaVideo ( ); ///////////////////////////////////////// return S_OK; }
HRESULT reinitCudaResources() { // Free resources cleanup(false); // Reinit VideoSource and Frame Queue g_bIsProgressive = loadVideoSource(sFileName.c_str(), g_nVideoWidth, g_nVideoHeight, g_nWindowWidth, g_nWindowHeight); /////////////////Change/////////////////////////// initCudaVideo(); initD3D9Surface(g_pVideoDecoder->targetWidth(), g_pVideoDecoder->targetHeight()); ///////////////////////////////////////// return S_OK; }
int main(int argc, char *argv[]) { pArgc = &argc; pArgv = argv; sdkCreateTimer(&frame_timer); sdkResetTimer(&frame_timer); sdkCreateTimer(&global_timer); sdkResetTimer(&global_timer); // parse the command line arguments parseCommandLineArguments(argc, argv); // create window (after we know the size of the input file size) WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, sAppName, NULL }; RegisterClassEx(&wc); // Find out the video size g_bIsProgressive = loadVideoSource(sFileName.c_str(), g_nVideoWidth, g_nVideoHeight, g_nWindowWidth, g_nWindowHeight); // figure out the window size we must create to get a *client* area // that is of the size requested by m_dimensions. RECT adjustedWindowSize; DWORD dwWindowStyle; HWND hWnd = NULL; { dwWindowStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; SetRect(&adjustedWindowSize, 0, 0, g_nVideoWidth , g_nVideoHeight); AdjustWindowRect(&adjustedWindowSize, dwWindowStyle, false); g_nWindowWidth = adjustedWindowSize.right - adjustedWindowSize.left; g_nWindowHeight = adjustedWindowSize.bottom - adjustedWindowSize.top; // Create the application's window hWnd = CreateWindow(wc.lpszClassName, sAppName, dwWindowStyle, 0, 0, g_nWindowWidth, g_nWindowHeight, NULL, NULL, wc.hInstance, NULL); } // Initialize CUDA cuInit(0); int bTCC = 0; // If we are using TCC driver, then always turn off interop if (bTCC) { g_bUseInterop = false; } if (g_bUseInterop) { // Initialize Direct3D if (initD3D9(hWnd, argc, argv, &bTCC) == false) { g_bAutoQuit = true; g_bWaived = true; goto ExitApp; } } // Initialize CUDA/D3D9 context and other video memory resources if (initCudaResources(argc, argv, g_bUseInterop, bTCC) == E_FAIL) { g_bAutoQuit = true; g_bException = true; g_bWaived = true; goto ExitApp; } g_pVideoSource->start(); g_bRunning = true; if (!g_bQAReadback && !bTCC) { ShowWindow(hWnd, SW_SHOWDEFAULT); UpdateWindow(hWnd); } // the main loop sdkStartTimer(&frame_timer); sdkStartTimer(&global_timer); sdkResetTimer(&global_timer); if (!g_bUseInterop) { // On this case we drive the display with a while loop (no openGL calls) while (g_pVideoSource->isStarted() && !g_pFrameQueue->isEndOfDecode()) { renderVideoFrame(hWnd, g_bUseInterop); } } else { // Standard windows loop while (!g_bDone) { MSG msg; ZeroMemory(&msg, sizeof(msg)); while (msg.message!=WM_QUIT) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { renderVideoFrame(hWnd, g_bUseInterop); } if (g_bAutoQuit && g_bDone) { break; } } } // while loop } g_pFrameQueue->endDecode(); g_pVideoSource->stop(); printStatistics(); // clean up CUDA and D3D resources ExitApp: cleanup(g_bWaived ? false : true); if (!g_bQAReadback) { // Unregister windows class UnregisterClass(wc.lpszClassName, wc.hInstance); } if (g_bAutoQuit) { PostQuitMessage(0); } if (hWnd) { DestroyWindow(hWnd); } if (g_bWaived) { exit(EXIT_WAIVED); } else { exit(g_bException ? EXIT_FAILURE : EXIT_SUCCESS); } }