HRESULT recChannel_t::unmap(void) { __CONTEXT("recChannel_t::unmap"); IBaseFilter * pFilter = NULL; int hr =0; hr = pGraph->FindFilterByName(L"Video Renderer",&pFilter); if (!hr) { IVideoWindow *pWindowInfo = NULL; hr = pFilter->QueryInterface(IID_IVideoWindow, (void **)&pWindowInfo); errorCheck(hr); pWindowInfo->put_Visible(OAFALSE); pWindowInfo->put_AutoShow(OAFALSE); pWindowInfo->Release(); } pControl->StopWhenReady(); #ifdef _WINDOWS if (fControl) { fControl->CWnd::ShowWindow(SW_HIDE); } #endif mapping = false; return 0; }
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(); }
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(); }
HRESULT recChannel_t::set_window_title(char * newTitle) { __CONTEXT("recChannel_t::set_window_title"); int hr = 0; memset(title,0,100); strcpy(title,newTitle); IVideoWindow * pWindow = NULL; pGraph->QueryInterface(IID_IVideoWindow,(void **) &pWindow); wchar_t wtext[100]; lText(wtext,title); pWindow->put_Caption(wtext); pWindow->Release(); return hr; }
void CHogVideo::Cleanup() { this->UnHog(); if (m_pEvent) { IMediaEvent *pEvent = (IMediaEvent*)m_pEvent; pEvent->Release(); m_pEvent = NULL; } if (m_pVideoWindow) { IVideoWindow *pVideoWindow = (IVideoWindow*)m_pVideoWindow; pVideoWindow->Release(); m_pVideoWindow = NULL; } if (m_pMediaControl) { IMediaControl *pMediaControl = (IMediaControl*)m_pMediaControl; pMediaControl->Release(); m_pMediaControl = NULL; } if (m_pGraph) { IGraphBuilder *pGraph = (IGraphBuilder*)m_pGraph; pGraph->Release(); m_pGraph = NULL; } if (m_bCOMInitialized) { CoUninitialize(); m_bCOMInitialized = false; } }
void Video::play( char *fileName, DWORD ) { WCHAR wPath[100]; HRESULT hr; IMediaControl *pMC; if(!init_success) return; MultiByteToWideChar( CP_ACP, 0, fileName, -1, wPath, 100 ); if( (hr = pGraph->RenderFile(wPath, NULL)) == 0) { // use full screen video interface // try to change display mode IVideoWindow *iVideoWindow = NULL; if( (hr = pGraph->QueryInterface(IID_IVideoWindow, (void **) &iVideoWindow)) == 0) { #ifdef CREATE_DUMMY_WINDOW if(hwnd) { HRESULT hr2 = iVideoWindow->put_MessageDrain((OAHWND) hwnd); hr2 = 0; } #endif #ifdef FULL_SCREEN_VIDEO IFilter *iFilter; if( pGraph->FindFilterByName(L"Video Renderer", &iFilter) == 0) { IBasicVideo *iBasicVideo; if( iFilter->QueryInterface(IID_IBasicVideo, (void **)&iBasicVideo) == 0) { IFullScreenVideo *iFullScreenVideo; IDirectDrawVideo *iDirectDrawVideo; if( iFilter->QueryInterface(IID_IFullScreenVideo, (void **)&iFullScreenVideo) == 0) { iFullScreenVideo->Release(); } else if( iFilter->QueryInterface(IID_IDirectDrawVideo, (void **)&iDirectDrawVideo) == 0) { HRESULT hr2; hr2 = iDirectDrawVideo->UseWhenFullScreen(OATRUE); iDirectDrawVideo->Release(); } iBasicVideo->Release(); } iFilter->Release(); } hr=iVideoWindow->put_FullScreenMode(OATRUE); #endif /* // code to find all filter in the filter graph { IEnumFilters *iEnumFilters; pGraph->EnumFilters(&iEnumFilters); ULONG filterCount = 16; IFilter *iFilters[16]; iEnumFilters->Next(filterCount, iFilters, &filterCount); for( ULONG j = 0; j < filterCount; ++j ) { FILTER_INFO filterInfo; iFilters[j]->QueryFilterInfo(&filterInfo); filterInfo.pGraph->Release(); iFilters[j]->Release(); } iEnumFilters->Release(); }*/ iVideoWindow->HideCursor(OATRUE); iVideoWindow->put_Visible( OAFALSE ); iVideoWindow->put_AutoShow( OAFALSE ); LONG windowStyle; iVideoWindow->get_WindowStyle( &windowStyle); windowStyle &= ~WS_BORDER & ~WS_CAPTION & ~WS_SIZEBOX & ~WS_THICKFRAME & ~WS_HSCROLL & ~WS_VSCROLL & ~WS_VISIBLE; iVideoWindow->put_WindowStyle( windowStyle); } else iVideoWindow = NULL; if( (hr = pGraph->QueryInterface(IID_IMediaControl, (void **) &pMC)) == 0) { pMC->Run(); // sometimes it returns 1, but still ok state = PLAYING; pMC->Release(); } if( iVideoWindow ) { iVideoWindow->put_Visible( OAFALSE ); LONG windowStyle; iVideoWindow->get_WindowStyle( &windowStyle); windowStyle &= ~WS_BORDER & ~WS_CAPTION & ~WS_SIZEBOX & ~WS_THICKFRAME & ~WS_HSCROLL & ~WS_VSCROLL & ~WS_VISIBLE; iVideoWindow->put_WindowStyle( windowStyle); LONG maxWidth; LONG maxHeight; hr=iVideoWindow->GetMaxIdealImageSize( &maxWidth, &maxHeight); #ifdef FULL_SCREEN_VIDEO #else iVideoWindow->put_BorderColor( RGB(0,0,0) ); iVideoWindow->put_WindowState(SW_MAXIMIZE); IBaseFilter *iFilter; if( pGraph->FindFilterByName((const WCHAR *)L"Video Renderer", &iFilter) == 0) { IBasicVideo *iBasicVideo; if( iFilter->QueryInterface(IID_IBasicVideo, (void **)&iBasicVideo) == 0) { LONG screenWidth; LONG screenHeight; LONG videoWidth; LONG videoHeight; if( iVideoWindow->get_Width(&screenWidth) == 0 && iVideoWindow->get_Height(&screenHeight) == 0 && iBasicVideo->GetVideoSize(&videoWidth, &videoHeight) == 0) { // zoom in by 2 if possible if( screenWidth >= videoWidth * 2 && screenHeight >= videoHeight * 2) { videoWidth *= 2; videoHeight *= 2; } // center the video client area iBasicVideo->SetDestinationPosition( (screenWidth-videoWidth)/2, (screenHeight-videoHeight)/2, videoWidth, videoHeight); } iBasicVideo->Release(); } iFilter->Release(); } #endif iVideoWindow->HideCursor(OATRUE); iVideoWindow->SetWindowForeground(OATRUE); } if(iVideoWindow) { iVideoWindow->Release(); iVideoWindow = NULL; } } if( hr && !skip_on_fail_flag) err.run("video.play error %d", hr ); }
void recChannel_t::refresh_channel(bool all) { __CONTEXT("recChannel_t::refresh_channel"); pControl->Stop(); #ifdef _WINDOWS if (fControl) { fControl->CWnd::ShowWindow(SW_HIDE); } #endif if (pSource!=NULL) { pGraph->RemoveFilter(pSource); camInfo->setFree(true); } // Enumerate the filters in the graph. IEnumFilters *pEnum = NULL; int hr = pGraph->EnumFilters(&pEnum); if (SUCCEEDED(hr)) { IBaseFilter *pFilter = NULL; while (S_OK == pEnum->Next(1, &pFilter, NULL)) { CLSID filterId; pFilter->GetClassID(&filterId); if(filterId == CLSID_VideoRenderer || filterId == CLSID_VideoMixingRenderer) { IVideoWindow *pWindowInfo = NULL; pFilter->QueryInterface(IID_IVideoWindow, (void **)&pWindowInfo); pWindowInfo->get_Height(&windowInfo.heigth); pWindowInfo->get_Left(&windowInfo.left); pWindowInfo->get_Top(&windowInfo.top); pWindowInfo->get_Width(&windowInfo.width); pWindowInfo->put_AutoShow(OAFALSE); pWindowInfo->put_Visible(OAFALSE); if (all) { pGraph->RemoveFilter(pFilter); pFilter->Release(); pEnum->Reset(); pWindowInfo->Release(); } }else{ pGraph->RemoveFilter(pFilter); pFilter->Release(); pEnum->Reset(); } } pEnum->Release(); } if (all) { pGraph->Release(); hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); errorCheck(hr); } hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); errorCheck(hr); }
HRESULT OnTapiEvent( TAPI_EVENT TapiEvent, IDispatch * pEvent ) { HRESULT hr; switch ( TapiEvent ) { case TE_CALLNOTIFICATION: { // // TE_CALLNOTIFICATION means that the application is being notified // of a new call. // // Note that we don't answer to call at this point. The application // should wait for a CS_OFFERING CallState message before answering // the call. // ITCallNotificationEvent * pNotify; hr = pEvent->QueryInterface( IID_ITCallNotificationEvent, (void **)&pNotify ); if (S_OK != hr) { DoMessage( L"Incoming call, but failed to get the interface"); } else { CALL_PRIVILEGE cp; ITCallInfo * pCall; // // get the call // hr = pNotify->get_Call( &pCall ); pNotify->Release(); if ( SUCCEEDED(hr) ) { // // check to see if we own the call // hr = pCall->get_Privilege( &cp ); if ( FAILED(hr) || (CP_OWNER != cp) ) { // // just ignore it if we don't own it // pCall->Release(); pEvent->Release(); // we addrefed it CTAPIEventNotification::Event() return S_OK; } // // Get the ITBasicCallControl interface // // // If we're already in a call, disconnect the new call. Otherwise, // save it in our global variable. // ITBasicCallControl * pCallControl; hr = pCall->QueryInterface( IID_ITBasicCallControl, (void**)&pCallControl ); pCall->Release(); if ( SUCCEEDED(hr) ) { if (gpCall == NULL) { gpCall = pCallControl; // // update UI // EnableButton( IDC_ANSWER ); DisableButton( IDC_DISCONNECT ); SetStatusMessage(L"Incoming Owner Call"); } else { // // Reject this call since we're already in a call // hr = pCallControl->Disconnect(DC_REJECTED); pCallControl->Release(); if (FAILED(hr)) { break; } } } } } break; } case TE_CALLSTATE: { // TE_CALLSTATE is a call state event. pEvent is // an ITCallStateEvent CALL_STATE cs; ITCallStateEvent * pCallStateEvent; ITCallInfo * pCall; ITBasicCallControl * pCallControl; // Get the interface hr = pEvent->QueryInterface( IID_ITCallStateEvent, (void **)&pCallStateEvent ); if ( FAILED(hr) ) { break; } // get the CallInfo interface hr = pCallStateEvent->get_Call( &pCall ); if ( FAILED(hr) ) { pCallStateEvent->Release(); break; } //get the ITBasicCallControl interface and compare it to our existing call hr = pCall->QueryInterface( IID_ITBasicCallControl,(void**)&pCallControl ); pCall->Release(); if (FAILED(hr)) { pCallStateEvent->Release(); break; } //ignore call state events for other calls if (pCallControl != gpCall) { pCallControl->Release(); pCallStateEvent->Release(); break; } pCallControl->Release(); // // This is a call state event for our call // // get the CallState that we are being notified of. hr = pCallStateEvent->get_State( &cs ); // Release the interface pCallStateEvent->Release(); if ( FAILED(hr) ) { break; } // if it's offering, update our UI if (CS_OFFERING == cs) { if (gfAutoAnswer) { PostMessage(ghDlg, WM_COMMAND, IDC_ANSWER, 0); } else { SetStatusMessage(L"Click the Answer button"); } } else if (CS_DISCONNECTED == cs) { PostMessage(ghDlg, WM_COMMAND, IDC_DISCONNECTED, 0); } else if (CS_CONNECTED == cs) { // nothing to do -- we handle connection synchronously } break; } case TE_CALLMEDIA: { // TE_CALLMEDIA is a media event. pEvent is // an ITCallMediaEvent CALL_MEDIA_EVENT cme; ITCallMediaEvent * pCallMediaEvent; // Get the interface hr = pEvent->QueryInterface( IID_ITCallMediaEvent, (void **)&pCallMediaEvent ); if ( FAILED(hr) ) { break; } // get the CALL_MEDIA_EVENT that we are being notified of. hr = pCallMediaEvent->get_Event( &cme ); if ( SUCCEEDED(hr) ) { switch ( cme ) { case CME_STREAM_NOT_USED: case CME_STREAM_INACTIVE: case CME_NEW_STREAM: break; case CME_STREAM_FAIL: DoMessage( L"Call media event: stream failed"); break; case CME_TERMINAL_FAIL: DoMessage( L"Call media event: terminal failed"); break; case CME_STREAM_ACTIVE: { // // Find out if this stream has a video render terminal. If not, // we don't need to do anything with this stream. Also note // if this is the video capture stream or the video render // stream. // ITTerminal * pTerminal; BOOL fRenderStream; hr = GetVideoRenderTerminalFromStreamEvent( pCallMediaEvent, &pTerminal, &fRenderStream ); if ( SUCCEEDED(hr) ) { // Get the video window interface for the terminal IVideoWindow *pVideoWindow = NULL; hr = pTerminal->QueryInterface( IID_IVideoWindow, (void**)&pVideoWindow ); pTerminal->Release(); if ( SUCCEEDED(hr) ) { // Put this window in our dialog HostWindow(pVideoWindow, fRenderStream); pVideoWindow->Release(); } } break; } default: break; } } // We no longer need this interface. pCallMediaEvent->Release(); break; } default: break; } pEvent->Release(); // we addrefed it CTAPIEventNotification::Event() return S_OK; }