Example #1
0
        public long CurrentPosition()
        {
            if ((m_itCurrent == m_Clips.Count) || !m_bActive)
            {
                return(m_tStartPosition);
            }
            double dTime = 0;

            m_pController.GetSegmentTime(out dTime);
            long tNow = (long)(dTime * 10000000);

            ClipEntry ce = (ClipEntry)m_Clips[m_itCurrent];

            // this is relative to the start position within this particular clip.
            // Did we start at the beginning of this clip?
            if (m_tStartPosition > ce.GetStartPosition())
            {
                // no, we started some distance into the clip
                tNow += (m_tStartPosition - ce.GetStartPosition());
            }
            // offset from start of this clip to start of entire sequence
            tNow += ce.GetStartPosition();

            if ((tNow < 0) && m_bLoop)
            {
                // current time is near end of previous loop
                ce    = (ClipEntry)m_Clips[m_Clips.Count - 1];
                tNow += ce.GetStartPosition() + ce.Duration();
            }
            return(tNow);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        private void bnLimits_Click(object sender, EventArgs e)
        {
            int       idx   = listBox1.SelectedIndex;
            ClipEntry pClip = null;

            if (idx != -1)
            {
                pClip = m_pPlayer.GetClipByIndex(idx);
            }

            if (pClip != null)
            {
                // duration, limits dlg -- set clip limits (in seconds)
                long lDur = ((pClip.NativeDuration() + UNITS - 1) / UNITS);
                long tStart, tStop;
                pClip.GetLimits(out tStart, out tStop);
                long lStart = ((tStart + UNITS - 1) / UNITS);
                long lStop  = -1;
                if (tStop != 0)
                {
                    lStop = ((tStop + UNITS - 1) / UNITS);
                }

                fmLimits dlg = new fmLimits((pClip.Duration() + UNITS - 1) / UNITS);
                dlg.tbStart.Text = lStart.ToString();
                dlg.tbStop.Text  = lStop.ToString();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    long tStart2 = int.Parse(dlg.tbStart.Text) * UNITS;
                    long tStop2  = pClip.NativeDuration();
                    if (int.Parse(dlg.tbStop.Text) > 0)
                    {
                        tStop2 = int.Parse(dlg.tbStop.Text) * UNITS;
                    }
                    m_pPlayer.SetClipLimits(pClip, tStart2, tStop2);

                    string sDesc = string.Format("{0} [{1}..{2}]", pClip.Name(), tStart2 / UNITS, tStop2 / UNITS);

                    int n = listBox1.SelectedIndex;

                    listBox1.Items.RemoveAt(n);
                    listBox1.Items.Insert(n, sDesc);
                }
            }
        }
Example #5
0
        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;
        }
Example #6
0
        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;
        }