IMFTopologyNode* MediaSource::CreateTopologySourceNode() { IMFTopologyNode* mfTopologyNode = nullptr; IMFStreamDescriptor* mfStreamDescriptor = nullptr; HRESULT hr; DWORD streamDescriptorCount; BOOL isSelected; do { // Iterate through the source streams to find the currently selected one if (!SUCCEEDED(hr = _mfPresentationDescriptor->GetStreamDescriptorCount(&streamDescriptorCount))) break; for (DWORD i = 0; i < streamDescriptorCount; i++) { if (!SUCCEEDED(hr = _mfPresentationDescriptor->GetStreamDescriptorByIndex(i, &isSelected, &mfStreamDescriptor))) break; if (isSelected) { break; } else { mfStreamDescriptor->Release(); mfStreamDescriptor = nullptr; } } if (FAILED(hr) || !mfStreamDescriptor) { throw std::exception("Could not find selected stream in MediaSource"); } // otherwise, we're in good shape :-) if (!SUCCEEDED(hr = MFCreateTopologyNode(MF_TOPOLOGY_SOURCESTREAM_NODE, &mfTopologyNode))) break; if (!SUCCEEDED(hr = mfTopologyNode->SetUnknown(MF_TOPONODE_SOURCE, _mfMediaSource))) break; if (!SUCCEEDED(hr = mfTopologyNode->SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, _mfPresentationDescriptor))) break; if (!SUCCEEDED(hr = mfTopologyNode->SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, mfStreamDescriptor))) break; } while (0); if (FAILED(hr)) { throw std::exception("Could not create topology source node"); } mfStreamDescriptor->Release(); return mfTopologyNode; }
/** 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; }