////////////////////////////////////////////////////////////////// // // GetTerminalFromStreamEvent - get the stream from the event and // after this get the terminal from stream - if any // ////////////////////////////////////////////////////////////////// HRESULT GetTerminalFromStreamEvent( IN ITCallMediaEvent * pCallMediaEvent, OUT ITTerminal ** ppTerminal ) { // //do not return bogus value // *ppTerminal = NULL; // // Get the stream for this event. // ITStream * pStream = NULL; HRESULT hr = pCallMediaEvent->get_Stream( &pStream ); if (FAILED(hr)) { DoMessage( _T("GetTerminalFromStreamEvent: get_Stream failed")); return E_FAIL; } // // Enumerate the terminals on this stream. // IEnumTerminal * pEnumTerminal = NULL; hr = pStream->EnumerateTerminals( &pEnumTerminal ); // //not need this anymore // pStream->Release(); if ( FAILED(hr) ) { DoMessage(_T("GetTerminalFromStreamEvent: EnumerateTerminals failed")); return hr; } // // Get the first terminal -- if there aren't any, return E_FAIL so that // we skip this event (this happens when the terminal is on the other // stream). // hr = pEnumTerminal->Next(1, ppTerminal, NULL); // //clean up // pEnumTerminal->Release(); // //map anything but S_OK to failure - even S_FALSE // if ( hr != S_OK ) { return E_FAIL; } return S_OK; }
HRESULT GetVideoRenderTerminalFromStreamEvent( ITCallMediaEvent * pCallMediaEvent, ITTerminal ** ppTerminal, BOOL * pfRenderStream ) { HRESULT hr; // // Get the stream for this event. // ITStream * pStream; hr = pCallMediaEvent->get_Stream( &pStream ); if ( FAILED(hr) || (pStream == NULL) ) { return E_FAIL; } // // Find out if this is a video stream. If not, fail -- // we don't care about this stream. // long lMediaType; hr = pStream->get_MediaType(&lMediaType); if ( FAILED(hr) ) { pStream->Release(); return hr; } if ( lMediaType != TAPIMEDIATYPE_VIDEO ) { pStream->Release(); return E_FAIL; } // // Find out the direction of this stream. We will return this info to the // caller. // TERMINAL_DIRECTION td; hr = pStream->get_Direction(&td); if ( FAILED(hr) ) { pStream->Release(); return hr; } *pfRenderStream = (td == TD_RENDER); // // Enumerate the terminals on this stream. // IEnumTerminal * pEnumTerminal; hr = pStream->EnumerateTerminals( &pEnumTerminal ); pStream->Release(); if ( FAILED(hr) ) { return hr; } // // Search for the first video render terminal and return it. If there are // none, fail -- we don't care about this stream. // while ( S_OK == pEnumTerminal->Next(1, ppTerminal, NULL) ) { if ( SUCCEEDED( (*ppTerminal)->get_Direction(&td) ) ) { if ( td == TD_RENDER ) { // found it; done with enum, but keep ref on terminal pEnumTerminal->Release(); return S_OK; } } // this is not the right one (*ppTerminal)->Release(); } pEnumTerminal->Release(); return E_FAIL; // no terminal found }