/** Set playback topology */ FIntPoint FImfVideoPlayer::SetPlaybackTopology( FImfSampleGrabberCallback* SampleGrabberCallback ) { FIntPoint OutDimensions = FIntPoint( ForceInit ); HRESULT HResult = S_OK; IMFPresentationDescriptor* PresentationDesc = NULL; HResult = MediaSource->CreatePresentationDescriptor( &PresentationDesc ); check( SUCCEEDED( HResult ) ); IMFTopology* Topology = NULL; HResult = MFCreateTopology( &Topology ); check( SUCCEEDED( HResult ) ); DWORD StreamCount = 0; HResult = PresentationDesc->GetStreamDescriptorCount( &StreamCount ); check( SUCCEEDED( HResult ) ); for( uint32 i = 0; i < StreamCount; i++ ) { BOOL bSelected = 0; IMFStreamDescriptor* StreamDesc = NULL; HResult = PresentationDesc->GetStreamDescriptorByIndex( i, &bSelected, &StreamDesc ); check( SUCCEEDED( HResult ) ); if( bSelected ) { FIntPoint VideoDimensions = AddStreamToTopology( Topology, PresentationDesc, StreamDesc, SampleGrabberCallback ); if( VideoDimensions != FIntPoint( ForceInit ) ) OutDimensions = VideoDimensions; } StreamDesc->Release( ); } HResult = MediaSession->SetTopology( 0, Topology ); check( SUCCEEDED( HResult ) ); Topology->Release( ); PresentationDesc->Release( ); return OutDimensions; }
CTedPlayer::~CTedPlayer() { HRESULT hr; if(m_pCPM) { m_pCPM->Release(); } for(size_t i = 0; i < m_aTopologies.GetCount(); i++) { CComPtr<IMFCollection> spSourceNodeCollection; IMFTopology* pTopology = m_aTopologies.GetAt(i); hr = pTopology->GetSourceNodeCollection(&spSourceNodeCollection); if(FAILED(hr)) { pTopology->Release(); continue; } DWORD cElements = 0; spSourceNodeCollection->GetElementCount(&cElements); for(DWORD j = 0; j < cElements; j++) { CComPtr<IUnknown> spSourceNodeUnk; CComPtr<IMFTopologyNode> spSourceNode; CComPtr<IMFMediaSource> spSource; hr = spSourceNodeCollection->GetElement(j, &spSourceNodeUnk); if(FAILED(hr)) continue; hr = spSourceNodeUnk->QueryInterface(IID_IMFTopologyNode, (void**) &spSourceNode); if(FAILED(hr)) continue; hr = spSourceNode->GetUnknown(MF_TOPONODE_SOURCE, IID_IMFMediaSource, (void**) &spSource); if(FAILED(hr)) continue; spSource->Shutdown(); } CComPtr<IMFCollection> spOutputNodeCollection; hr = pTopology->GetOutputNodeCollection(&spOutputNodeCollection); if(FAILED(hr)) { pTopology->Release(); continue; } cElements = 0; spOutputNodeCollection->GetElementCount(&cElements); for(DWORD j = 0; j < cElements; j++) { CComPtr<IUnknown> spSinkNodeUnk; CComPtr<IMFTopologyNode> spSinkNode; CComPtr<IUnknown> spStreamSinkUnk; CComPtr<IMFStreamSink> spStreamSink; CComPtr<IMFMediaSink> spSink; hr = spOutputNodeCollection->GetElement(j, &spSinkNodeUnk); if(FAILED(hr)) continue; hr = spSinkNodeUnk->QueryInterface(IID_IMFTopologyNode, (void**) &spSinkNode); if(FAILED(hr)) continue; hr = spSinkNode->GetObject(&spStreamSinkUnk); if(FAILED(hr)) continue; hr = spStreamSinkUnk->QueryInterface(IID_IMFStreamSink, (void**) &spStreamSink); if(FAILED(hr)) continue; hr = spStreamSink->GetMediaSink(&spSink); if(FAILED(hr)) continue; spSink->Shutdown(); } pTopology->Release(); } if(m_spClearSession) { m_spClearSession->Shutdown(); } if(m_spProtectedSession) { m_spProtectedSession->Shutdown(); } }