protected void CreateOutputNode( IMFStreamDescriptor pSourceSD, out IMFTopologyNode ppNode ) { IMFTopologyNode pNode = null; IMFMediaTypeHandler pHandler = null; IMFActivate pRendererActivate = null; Guid guidMajorType = Guid.Empty; MFError throwonhr; // Get the stream ID. int streamID = 0; try { HResult hr; hr = pSourceSD.GetStreamIdentifier(out streamID); // Just for debugging, ignore any failures. if (MFError.Failed(hr)) { //TRACE("IMFStreamDescriptor::GetStreamIdentifier" + hr.ToString()); } // Get the media type handler for the stream. throwonhr = pSourceSD.GetMediaTypeHandler(out pHandler); // Get the major media type. throwonhr = pHandler.GetMajorType(out guidMajorType); // Create a downstream node. throwonhr = MFExtern.MFCreateTopologyNode(MFTopologyType.OutputNode, out pNode); // Create an IMFActivate object for the renderer, based on the media type. if (MFMediaType.Audio == guidMajorType) { // Create the audio renderer. //TRACE(string.Format("Stream {0}: audio stream", streamID)); throwonhr = MFExtern.MFCreateAudioRendererActivate(out pRendererActivate); // Set the IActivate object on the output node. throwonhr = pNode.SetObject(pRendererActivate); } else if (MFMediaType.Video == guidMajorType) { // Create the video renderer. //TRACE(string.Format("Stream {0}: video stream", streamID)); //throwonhr = MFExtern.MFCreateVideoRendererActivate(m_hwndVideo, out pRendererActivate); mIMFTopologyNode.GetObject(out pRendererActivate); throwonhr = pNode.SetObject(pRendererActivate); } else { //TRACE(string.Format("Stream {0}: Unknown format", streamID)); //throw new COMException("Unknown format", (int)HResult.E_FAIL); } // Return the IMFTopologyNode pointer to the caller. ppNode = pNode; } catch { // If we failed, release the pNode //SafeRelease(pNode); throw; } finally { // Clean up. //SafeRelease(pHandler); //SafeRelease(pRendererActivate); } }
protected void CreateOutputNode( IMFStreamDescriptor pSourceSD, out IMFTopologyNode ppNode ) { IMFTopologyNode pNode = null; IMFMediaTypeHandler pHandler = null; IMFActivate pRendererActivate = null; Guid guidMajorType = Guid.Empty; int hr = S_Ok; // Get the stream ID. int streamID = 0; try { try { pSourceSD.GetStreamIdentifier(out streamID); // Just for debugging, ignore any failures. } catch { TRACE("IMFStreamDescriptor::GetStreamIdentifier" + hr.ToString()); } // Get the media type handler for the stream. pSourceSD.GetMediaTypeHandler(out pHandler); // Get the major media type. pHandler.GetMajorType(out guidMajorType); // Create a downstream node. MFExtern.MFCreateTopologyNode(MFTopologyType.OutputNode, out pNode); // Create an IMFActivate object for the renderer, based on the media type. if (MFMediaType.Audio == guidMajorType) { // Create the audio renderer. TRACE(string.Format("Stream {0}: audio stream", streamID)); MFExtern.MFCreateAudioRendererActivate(out pRendererActivate); } else if (MFMediaType.Video == guidMajorType) { // Create the video renderer. TRACE(string.Format("Stream {0}: video stream", streamID)); MFExtern.MFCreateVideoRendererActivate(m_hwndVideo, out pRendererActivate); object ppv; pRendererActivate.ActivateObject(typeof(IMFVideoRenderer).GUID, out ppv); var renderer = ppv as IMFVideoRenderer; m_customPresenter = EvrPresenter.CreateNew(); m_customPresenter.NewAllocatorFrame += m_customPresenter_NewAllocatorFrame; m_customPresenter.NewAllocatorSurface += m_customPresenter_NewAllocatorSurface; var presenter = m_customPresenter.VideoPresenter as IMFVideoDisplayControl; hr = presenter.SetVideoWindow(m_hwndVideo); hr = renderer.InitializeRenderer(null, m_customPresenter.VideoPresenter); var settings = presenter as IEVRPresenterSettings; settings.SetBufferCount(5); } else { TRACE(string.Format("Stream {0}: Unknown format", streamID)); throw new COMException("Unknown format", E_Fail); } // Set the IActivate object on the output node. pNode.SetObject(pRendererActivate); // Return the IMFTopologyNode pointer to the caller. ppNode = pNode; } catch { // If we failed, release the pNode SafeRelease(pNode); throw; } finally { // Clean up. SafeRelease(pHandler); SafeRelease(pRendererActivate); } }
protected IMFTopologyNode CreateOutputNode(IMFStreamDescriptor pSourceSD) { IMFTopologyNode pNode = null; IMFMediaTypeHandler pHandler = null; IMFActivate pRendererActivate = null; Guid guidMajorType = Guid.Empty; int hr = 0; // Get the stream ID. int streamID = 0; try { try { hr = pSourceSD.GetStreamIdentifier(out streamID); // Just for debugging, ignore any failures. MFError.ThrowExceptionForHR(hr); } catch { //TRACE("IMFStreamDescriptor::GetStreamIdentifier" + hr.ToString()); } // Get the media type handler for the stream. hr = pSourceSD.GetMediaTypeHandler(out pHandler); MFError.ThrowExceptionForHR(hr); // Get the major media type. hr = pHandler.GetMajorType(out guidMajorType); MFError.ThrowExceptionForHR(hr); // Create a downstream node. hr = MFExtern.MFCreateTopologyNode(MFTopologyType.OutputNode, out pNode); MFError.ThrowExceptionForHR(hr); // Create an IMFActivate object for the renderer, based on the media type. if (MFMediaType.Audio == guidMajorType) { // Create the audio renderer. hr = MFExtern.MFCreateAudioRendererActivate(out pRendererActivate); MFError.ThrowExceptionForHR(hr); object sar; pRendererActivate.ActivateObject(typeof(IMFMediaSink).GUID, out sar); StreamingAudioRenderer = sar as IMFMediaSink; } else if (MFMediaType.Video == guidMajorType) { // Create the video renderer. pRendererActivate = CreateVideoRenderer(); } else { //TRACE(string.Format("Stream {0}: Unknown format", streamID)); throw new COMException("Unknown format"); } // Set the IActivate object on the output node. hr = pNode.SetObject(pRendererActivate); MFError.ThrowExceptionForHR(hr); } catch (Exception ex) { // If we failed, release the pNode COMBase.SafeRelease(pNode); throw; } finally { // Clean up. COMBase.SafeRelease(pHandler); COMBase.SafeRelease(pRendererActivate); } return(pNode); }
/// <summary> /// Create media ouput node /// </summary> /// <param name="pSourceSD"></param> /// <param name="ppNode"></param> protected void CreateOutputNode( IMFStreamDescriptor pSourceSD, out IMFTopologyNode ppNode) { IMFTopologyNode pNode = null; IMFMediaTypeHandler pHandler = null; IMFActivate pRendererActivate = null; Guid guidMajorType = Guid.Empty; int hr = S_Ok; // Get the stream ID. int streamID = 0; try { try { pSourceSD.GetStreamIdentifier(out streamID); // Just for debugging, ignore any failures. } catch { TRACE("IMFStreamDescriptor::GetStreamIdentifier" + hr.ToString()); } // Get the media type handler for the stream. pSourceSD.GetMediaTypeHandler(out pHandler); // Get the major media type. pHandler.GetMajorType(out guidMajorType); // Create a downstream node. MFExtern.MFCreateTopologyNode(MFTopologyType.OutputNode, out pNode); // Create an IMFActivate object for the renderer, based on the media type. if (MFMediaType.Audio == guidMajorType) { // Create the audio renderer. TRACE(string.Format("Stream {0}: Audio Stream", streamID)); MFExtern.MFCreateAudioRendererActivate(out pRendererActivate); } else if (MFMediaType.Video == guidMajorType) { // Create the video renderer. TRACE(string.Format("Stream {0}: Video Stream", streamID)); MFExtern.MFCreateVideoRendererActivate(m_hwndVideo, out pRendererActivate); } else { TRACE(string.Format("Stream {0}: Unknown Format", streamID)); throw new COMException("Unknown Format", E_Fail); } // Set the IActivate object on the output node. pNode.SetObject(pRendererActivate); // Return the IMFTopologyNode pointer to the caller. ppNode = pNode; } catch { // If we failed, release the pNode SafeRelease(pNode); throw; } finally { // Clean up. SafeRelease(pHandler); SafeRelease(pRendererActivate); } }