public int AddClip(string path, out ClipEntry pClip) { int it = m_Clips.Count; pClip = new ClipEntry(); m_Clips.Add(pClip); int hr = pClip.Create(m_pController, path); // if we expect both audio and video, then all clips // must have both audio and video. // If the first clip is video only, then switch // to video-only automatically if ((hr == VFW_E_UNSUPPORTED_AUDIO) && (m_Clips.Count == 1)) { // new controller, different options (only one video stream) if (m_pController != null) { Marshal.ReleaseComObject(m_pController); m_pController = null; } m_pController = new GMFBridgeController() as IGMFBridgeController; m_pController.SetNotify(m_hwndApp, m_msgSegment); m_pController.AddStream(true, eFormatType.Uncompressed, false); m_pController.SetBufferMinimum(200); // try again hr = pClip.Create(m_pController, path); } if (hr >= 0) { pClip.SetStartPosition(m_tDuration); m_tDuration += pClip.Duration(); // if this is the first clip, create the render graph if (m_Clips.Count == 1) { m_pRenderGraph = new FilterGraph() as IGraphBuilder; hr = m_pController.CreateRenderGraph(pClip.SinkFilter(), m_pRenderGraph, out m_pRenderGraphSourceFilter); if (hr >= 0 && m_hwndApp != IntPtr.Zero) { IMediaEventEx pME = m_pRenderGraph as IMediaEventEx; if (pME != null) { pME.SetNotifyWindow(m_hwndApp, m_msgEvent, IntPtr.Zero); } } } } else { pClip.Dispose(); m_Clips.RemoveAt(it); } return(hr); }
public int SetClipLimits(ClipEntry pClip, long tStart, long tEnd) { long tDur = pClip.Duration(); int hr = pClip.SetLimits(tStart, tEnd); if (hr < 0 || (tDur == pClip.Duration())) { return(hr); } // this is called from the same message loop as the end-of-segment processing, so it's safe to // access the current segment if (pClip == CurrentClip()) { // send just the stop time to the graph // in the hope that it is not too late hr = pClip.SetStopTime(); } // clip duration has changed: update start position of // all subsequent clips (for current position slider UI) m_tDuration = 0; bool bFound = false; foreach (ClipEntry pThis in m_Clips) { if (pThis == pClip) { bFound = true; m_tDuration = pClip.GetStartPosition() + pClip.Duration(); } else if (bFound) { // following clip: adjust pClip.SetStartPosition(m_tDuration); m_tDuration += pClip.Duration(); } } return(S_OK); }
public int AddClip(string path, out ClipEntry pClip) { int it = m_Clips.Count; pClip = new ClipEntry(); m_Clips.Add(pClip); int hr = pClip.Create(m_pController, path); // if we expect both audio and video, then all clips // must have both audio and video. // If the first clip is video only, then switch // to video-only automatically if ((hr == VFW_E_UNSUPPORTED_AUDIO) && (m_Clips.Count == 1)) { // new controller, different options (only one video stream) if (m_pController != null) { Marshal.ReleaseComObject(m_pController); m_pController = null; } m_pController = new GMFBridgeController() as IGMFBridgeController; m_pController.SetNotify(m_hwndApp, m_msgSegment); m_pController.AddStream(true, eFormatType.Uncompressed, false); m_pController.SetBufferMinimum(200); // try again hr = pClip.Create(m_pController, path); } if (hr >= 0) { pClip.SetStartPosition(m_tDuration); m_tDuration += pClip.Duration(); // if this is the first clip, create the render graph if (m_Clips.Count == 1) { m_pRenderGraph = new FilterGraph() as IGraphBuilder; hr = m_pController.CreateRenderGraph(pClip.SinkFilter(), m_pRenderGraph, out m_pRenderGraphSourceFilter); if (hr >= 0 && m_hwndApp != IntPtr.Zero) { IMediaEventEx pME = m_pRenderGraph as IMediaEventEx; if (pME != null) { pME.SetNotifyWindow(m_hwndApp, m_msgEvent, IntPtr.Zero); } } } } else { pClip.Dispose(); m_Clips.RemoveAt(it); } return hr; }
public int SetClipLimits(ClipEntry pClip, long tStart, long tEnd) { long tDur = pClip.Duration(); int hr = pClip.SetLimits(tStart, tEnd); if (hr < 0 || (tDur == pClip.Duration())) { return hr; } // this is called from the same message loop as the end-of-segment processing, so it's safe to // access the current segment if (pClip == CurrentClip()) { // send just the stop time to the graph // in the hope that it is not too late hr = pClip.SetStopTime(); } // clip duration has changed: update start position of // all subsequent clips (for current position slider UI) m_tDuration = 0; bool bFound = false; foreach (ClipEntry pThis in m_Clips) { if (pThis == pClip) { bFound = true; m_tDuration = pClip.GetStartPosition() + pClip.Duration(); } else if (bFound) { // following clip: adjust pClip.SetStartPosition(m_tDuration); m_tDuration += pClip.Duration(); } } return S_OK; }