/* Call to render the next GL frame */ void Java_at_tugraz_ist_droned_dcf_video_NativeVideoWrapper_nativeDroneRenderVideoFrame( JNIEnv* env, jobject jobj, jint glHandle ) { renderVideoFrame(sWindowWidth, sWindowHeight, glHandle); }
int Composer::process( Frame **frame ) { Frame *dst, *dsta; bool video = false; int ret = PROCESSWAITINPUT; Profile projectProfile = sampler->getProfile(); if ( sampler->sceneEndReached() ) return PROCESSEND; if ( oneShot) sampler->prepareInputs(); if ( (dst = sampler->getMetronom()->freeVideoFrames.dequeue()) ) { if ( !renderVideoFrame( dst ) ) { dst->release(); dst = NULL; } else { dst->setPts( sampler->currentPTS() ); video = true; } ret = PROCESSCONTINUE; } double ns = projectProfile.getAudioSampleRate() * projectProfile.getVideoFrameDuration() / MICROSECOND; int nSamples = ns; audioSampleDelta += (ns - nSamples); if ( audioSampleDelta >= 1. ) { nSamples += 1; audioSampleDelta -= 1.; } if ( (dsta = sampler->getMetronom()->freeAudioFrames.dequeue()) ) { if ( !renderAudioFrame( dsta, nSamples ) ) { dsta->release(); dsta = NULL; } else { if ( oneShot ) playbackBuffer->releasedAudioFrame( dsta ); else { dsta->setPts( sampler->currentPTSAudio() ); sampler->getMetronom()->audioFrames.enqueue( dsta ); } sampler->shiftCurrentPTSAudio(); ret = PROCESSCONTINUE; } } if ( video ) { sampler->shiftCurrentPTS(); } if ( !oneShot && ret == PROCESSCONTINUE ) sampler->prepareInputs(); if ( video ) { if ( oneShot ) { ret = PROCESSONESHOTVIDEO; *frame = dst; } else { sampler->getMetronom()->videoFrames.enqueue( dst ); } } return ret; }
// The window's message handler static LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_KEYDOWN: switch (wParam) { // use ESC to quit application case VK_ESCAPE: { g_bDone = true; PostQuitMessage(0); return 0; } break; // use space to pause playback case VK_SPACE: { g_bRunning = !g_bRunning; } break; } break; // resize the window // even though we disable resizing (see next event handler below) // we need to be able to handle this event properly because the // windowing system calls it. case WM_SIZE: { // store new window size in our globals. g_nClientAreaWidth = GET_X_LPARAM(lParam); g_nClientAreaHeight = GET_Y_LPARAM(lParam); D3DVIEWPORT9 oViewport; oViewport.X = 0; oViewport.Y = 0; oViewport.Width = g_nClientAreaWidth; oViewport.Height = g_nClientAreaHeight; oViewport.MaxZ = 1.0f; oViewport.MinZ = 0.0f; g_pD3DDevice->SetViewport(&oViewport); D3DMATRIX oViewMatrix = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; // scale viewport to be of window width and height oViewMatrix._11 = 2.0f/g_nClientAreaWidth; oViewMatrix._22 = 2.0f/g_nClientAreaHeight; // translate viewport so that lower left corner represents // (0, 0) and upper right corner is (width, height) oViewMatrix._41 = -1.0f - 1.0f / g_nClientAreaWidth; oViewMatrix._42 = -1.0f + 1.0f / g_nClientAreaHeight; if (0 != g_pD3DDevice) { g_pD3DDevice->SetTransform(D3DTS_VIEW, &oViewMatrix); } renderVideoFrame(hWnd, g_bUseInterop); return 0; // Jump Back } // disallow resizing. case WM_GETMINMAXINFO: { MINMAXINFO *pMinMaxInfo = reinterpret_cast<MINMAXINFO *>(lParam); pMinMaxInfo->ptMinTrackSize.x = g_nWindowWidth; pMinMaxInfo->ptMinTrackSize.y = g_nWindowHeight; pMinMaxInfo->ptMaxTrackSize.x = g_nWindowWidth; pMinMaxInfo->ptMaxTrackSize.y = g_nWindowHeight; return 0; } case WM_DESTROY: g_bDone = true; PostQuitMessage(0); return 0; case WM_PAINT: ValidateRect(hWnd, NULL); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); }
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); } }
void CudaVideoRender::present(int effect){ if (hasNext()) { renderVideoFrame(m_bInterop); } }