void play_movie( HWND hwnd ) { IGraphBuilder *pGraph; IMediaControl *pMediaControl; IMediaEvent *pEvent; IBasicVideo *pBasic; IVideoWindow *pVidWin = NULL; RECT grc; long width, height; CoInitialize(NULL); // Create the filter graph manager and query for interfaces. CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin); pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); pGraph->QueryInterface(IID_IBasicVideo, (void**)&pBasic ); // Build the graph. IMPORTANT: Change string to a file on your system. pGraph->RenderFile(L"e:\\alpha\\running.avi", NULL); pBasic->GetVideoSize( &width, &height ); printf( "video frames are %d x %d\n", width, height ); pVidWin->put_Owner((OAHWND)hwnd); pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS); GetClientRect( hwnd, &grc ); pVidWin->SetWindowPosition(10, 10, width, height); printf( "window is %d x %d\n", grc.right, grc.bottom ); // Run the graph. pMediaControl->Run(); // Wait for completion. long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); pVidWin->put_Visible(OAFALSE); pVidWin->put_Owner(NULL); // Clean up. pBasic->Release(); pVidWin->Release(); pMediaControl->Release(); pEvent->Release(); pGraph->Release(); CoUninitialize(); }
/* * Class: sage_DShowMediaPlayer * Method: setVideoHWND0 * Signature: (JJ)V */ JNIEXPORT void JNICALL Java_sage_DShowMediaPlayer_setVideoHWND0 (JNIEnv *env, jobject jo, jlong dataPtr, jlong vhwnd) { CPlayerData* playData = (CPlayerData*) dataPtr; IGraphBuilder* pGraph = playData->GetGraph(); IVideoWindow* pVW = NULL; HRESULT hr = pGraph->QueryInterface(IID_IVideoWindow, (void**)&pVW); if (SUCCEEDED(hr)) { slog((env, "DShowPlayer setVideoHWND(%d)\r\n", (int) vhwnd)); pVW->put_AutoShow(OAFALSE); pVW->put_Owner((OAHWND)vhwnd); pVW->put_MessageDrain((OAHWND)vhwnd); pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); pVW->put_Visible(OATRUE); // We do all of our own aspect ratio control, so don't let DShow do any for us // by setting the aspect ratio mode on the video rendering filter's pin IEnumFilters *pEnum = NULL; hr = pGraph->EnumFilters(&pEnum); if (SUCCEEDED(hr)) { IBaseFilter *currFilt = NULL; while (pEnum->Next(1, &currFilt, NULL) == S_OK) { IPin *overlayPin = NULL; hr = currFilt->FindPin(L"Input0", &overlayPin); if (SUCCEEDED(hr)) { // Right pin name, let's see if it's overlay IMixerPinConfig *pOverlayMix = NULL; hr = overlayPin->QueryInterface(IID_IMixerPinConfig, (void**)&pOverlayMix); if (SUCCEEDED(hr)) { pOverlayMix->SetAspectRatioMode(AM_ARMODE_STRETCHED); SAFE_RELEASE(pOverlayMix); } SAFE_RELEASE(overlayPin); } SAFE_RELEASE(currFilt); } SAFE_RELEASE(pEnum); hr = S_OK; } SAFE_RELEASE(pVW); } HTESTPRINT(hr); }
void Video::PlayMovie(string path) { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; IMediaEvent *pEvent = NULL; IVideoWindow *pVideo = NULL; // Initialize the COM library. CoInitialize(NULL); // Create the filter graph manager and query for interfaces. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); // Build the graph int len; int slength = (int)path.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; pGraph->RenderFile(LPCWSTR(r.c_str()), NULL); // set the owner window pGraph->QueryInterface(IID_IVideoWindow, (void **) &pVideo); pVideo->put_Owner((OAHWND)window); pVideo->put_WindowStyle( WS_CHILD ); pVideo->put_Left(0); pVideo->put_Top(0); pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); pControl->Run(); long evCode; pEvent->WaitForCompletion(-1, &evCode); // release controls pControl->Release(); pEvent->Release(); pGraph->Release(); pVideo->Release(); CoUninitialize(); }
int video_add(string fname) { enigma::VideoStruct* videoStruct = new enigma::VideoStruct(); IGraphBuilder *pGraph = NULL; // Initialize the COM library. HRESULT hr = CoInitialize(NULL); if (FAILED(hr)) { MessageBox(NULL, "Failed to initialize COM library.", "ERROR", MB_ICONERROR | MB_OK); return -1; } // Create the filter graph manager and query for interfaces. hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); if (FAILED(hr)) { MessageBox(NULL, "Failed to create the Filter Graph Manager.", "ERROR", MB_ICONERROR | MB_OK); return -1; } // Build the graph. hr = pGraph->RenderFile(std::wstring(fname.begin(), fname.end()).c_str(), NULL); IVideoWindow *pVidWin = NULL; pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin); pVidWin->put_Owner((OAHWND)enigma::hWnd); pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS); videoStruct->pGraph = pGraph; enigma::videoStructs.push_back(videoStruct); return enigma::videoStructs.size() - 1; }
HRESULT CRTCAVSession::ShowVideo(RTC_VIDEO_DEVICE enDevice, BOOL fShow) { IVideoWindow * pVid = NULL; IRTCClient * pClient = NULL; long lMediaCaps = 0; HWND hWnd = NULL; HRESULT hr; hr = m_pSession->get_Client(&pClient); if (FAILED(hr)) { // get_Client failed return hr; } // Get the media capabilities hr = pClient->get_MediaCapabilities(&lMediaCaps); if (FAILED(hr)) { // get_MediaCapabilities failed SAFE_RELEASE(pClient); return hr; } hr = pClient->get_IVideoWindow( enDevice, &pVid); SAFE_RELEASE(pClient); if (FAILED(hr)) { // get_IVideoWindow failed return hr; } if (enDevice == RTCVD_PREVIEW) { // Determine whether to show the preview video fShow = fShow && (lMediaCaps & RTCMT_VIDEO_SEND); m_fShowPrev = fShow; hWnd = m_hPrevVideoParent; // Show or hide the preview video preview parent window ShowWindow(m_hPrevVideoParent, fShow ? SW_SHOW : SW_HIDE); // Set window region for receive video parent window HRGN hRegion; if (fShow) { // Set the receive video region to make room for the preview // video picture-in-picture POINT rgPoints[6] = { 0, 0, 0, m_lRecvHeight, m_lRecvWidth - m_lPrevWidth, m_lRecvHeight, m_lRecvWidth - m_lPrevWidth, m_lRecvHeight - m_lPrevHeight, m_lRecvWidth, m_lRecvHeight - m_lPrevHeight, m_lRecvWidth, 0 }; hRegion = CreatePolygonRgn(rgPoints, 6, ALTERNATE); } else { // Set the receive video region to be rectangular hRegion = CreateRectRgn(0, 0, m_lRecvWidth, m_lRecvHeight); } SetWindowRgn(m_hRecvVideoParent, hRegion, TRUE); } else { // Determine whether to show the receive video fShow = fShow && (lMediaCaps & RTCMT_VIDEO_RECEIVE); m_fShowRecv = fShow; hWnd = m_hRecvVideoParent; // Always show the video receive parent window ShowWindow(m_hRecvVideoParent, SW_SHOW); } if ( fShow == TRUE ) { // Set the video window style pVid->put_WindowStyle( WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS ); // Set the parent window for the video window pVid->put_Owner( (OAHWND)hWnd ); RECT rc; GetClientRect(hWnd, &rc ); // Position the video window pVid->SetWindowPosition( rc.left, rc.top, rc.right, rc.bottom ); // Make the video window visible pVid->put_Visible(-1); } SAFE_RELEASE(pVid); return S_OK; }