private static HResult CreateSourceStreamNode(IMFMediaSource source, IMFStreamDescriptor streamDescriptor, IMFPresentationDescriptor presentationDescriptor, out IMFTopologyNode node) { HResult hr = S_OK; node = null; hr = MF.CreateTopologyNode(MFTopologyType.SourcestreamNode, out node); if (Failed(hr)) { return(hr); } hr = node.SetUnknown(MF_TOPONODE_SOURCE, source); if (Failed(hr)) { SafeRelease(node); return(hr); } hr = node.SetUnknown(MF_TOPONODE_PRESENTATION_DESCRIPTOR, presentationDescriptor); if (Failed(hr)) { SafeRelease(node); return(hr); } hr = node.SetUnknown(MF_TOPONODE_STREAM_DESCRIPTOR, streamDescriptor); if (Failed(hr)) { SafeRelease(node); return(hr); } return(hr); }
private static HResult CreateOutputNode(IMFStreamDescriptor streamDescriptor, out IMFMediaSinkAlt mediaSink, out IMFTopologyNode node) { HResult hr = S_OK; mediaSink = null; node = null; IMFMediaTypeHandler mediaTypeHandler = null; IMFActivate activate = null; IMFStreamSinkAlt streamSink = null; Guid majorType = Guid.Empty; int streamSinkCount = 0; hr = streamDescriptor.GetMediaTypeHandler(out mediaTypeHandler); if (Failed(hr)) { return(hr); } hr = mediaTypeHandler.GetMajorType(out majorType); if (Failed(hr)) { SafeRelease(mediaTypeHandler); return(hr); } hr = MF.CreateTopologyNode(MFTopologyType.OutputNode, out node); if (Failed(hr)) { SafeRelease(mediaTypeHandler); return(hr); } if (majorType == MFMediaType.Video) { ExternalMediaSink extMediaSink = new ExternalMediaSink(); mediaSink = (IMFMediaSinkAlt)extMediaSink; hr = mediaSink.GetStreamSinkCount(out streamSinkCount); if (Failed(hr)) { mediaSink = null; return(hr); } hr = mediaSink.GetStreamSinkByIndex(0, out streamSink); if (Failed(hr)) { mediaSink = null; return(hr); } hr = node.SetObject(streamSink); if (Failed(hr)) { mediaSink = null; return(hr); } } else if (majorType == MFMediaType.Audio) { hr = MF.CreateAudioRendererActivate(out activate); if (Failed(hr)) { return(hr); } hr = node.SetObject(activate); if (Failed(hr)) { return(hr); } } mediaTypeHandler = null; activate = null; streamSink = null; return(hr); }