Ejemplo n.º 1
0
        public AMMediaType GetPMT(IMediaSampleImpl _sample)
        {
            AMMediaType pmt;

            if (S_OK == _sample.GetMediaType(out pmt))
            {
                if (FAILED(SetMediaType(pmt)))
                {
                    ASSERT(false);
                    _sample.SetMediaType(null);
                }
                pmt.Free();
            }
            return(pmt);
        }
        public override int FillBuffer(ref IMediaSampleImpl _sample)
        {
            {
                AMMediaType pmt;
                if (S_OK == _sample.GetMediaType(out pmt))
                {
                    if (FAILED(SetMediaType(pmt)))
                    {
                        ASSERT(false);
                        _sample.SetMediaType(null);
                    }
                    pmt.Free();
                }
            }
            long    _start, _stop;
            HRESULT hr = NOERROR;
            long    rtLatency;

            if (FAILED(GetLatency(out rtLatency)))
            {
                rtLatency = UNITS / 30;
            }
            bool bShouldDeliver = false;

            do
            {
                if (m_dwAdviseToken == 0)
                {
                    m_pClock.GetTime(out m_rtClockStart);
                    hr = (HRESULT)m_pClock.AdvisePeriodic(m_rtClockStart + rtLatency, rtLatency, m_hSemaphore.Handle, out m_dwAdviseToken);
                    hr.Assert();
                }
                else
                {
                    if (!m_hSemaphore.WaitOne())
                    {
                        ASSERT(FALSE);
                    }
                }
                bShouldDeliver = TRUE;
                _start         = m_rtStart;
                _stop          = m_rtStart + 1;
                _sample.SetTime(_start, _stop);
                hr = (HRESULT)(m_Filter as VirtualCamFilter).FillBuffer(ref _sample);
                if (FAILED(hr) || S_FALSE == hr)
                {
                    return(hr);
                }

                m_pClock.GetTime(out m_rtClockStop);
                _sample.GetTime(out _start, out _stop);

                if (rtLatency > 0 && rtLatency * 3 < m_rtClockStop - m_rtClockStart)
                {
                    m_rtClockStop = m_rtClockStart + rtLatency;
                }
                _stop     = _start + (m_rtClockStop - m_rtClockStart);
                m_rtStart = _stop;
                lock (m_csPinLock)
                {
                    _start -= m_rtStreamOffset;
                    _stop  -= m_rtStreamOffset;
                }
                _sample.SetTime(_start, _stop);
                m_rtClockStart = m_rtClockStop;

                bShouldDeliver = ((_start >= 0) && (_stop >= 0));

                if (bShouldDeliver)
                {
                    lock (m_csPinLock)
                        if (m_rtStartAt != -1)
                        {
                            if (m_rtStartAt > _start)
                            {
                                bShouldDeliver = FALSE;
                            }
                            else
                            {
                                if (m_dwStartCookie != 0 && !m_bStartNotified)
                                {
                                    m_bStartNotified = TRUE;
                                    hr = (HRESULT)m_Filter.NotifyEvent(EventCode.StreamControlStarted, Marshal.GetIUnknownForObject(this), (IntPtr)m_dwStartCookie);
                                    if (FAILED(hr))
                                    {
                                        return(hr);
                                    }
                                }
                            }
                        }
                    if (!bShouldDeliver)
                    {
                        continue;
                    }
                    if (m_rtStopAt != -1)
                    {
                        if (m_rtStopAt < _start)
                        {
                            if (!m_bStopNotified)
                            {
                                m_bStopNotified = TRUE;
                                if (m_dwStopCookie != 0)
                                {
                                    hr = (HRESULT)m_Filter.NotifyEvent(EventCode.StreamControlStopped, Marshal.GetIUnknownForObject(this), (IntPtr)m_dwStopCookie);
                                    if (FAILED(hr))
                                    {
                                        return(hr);
                                    }
                                }
                                bShouldDeliver = m_bShouldFlush;
                            }
                            else
                            {
                                bShouldDeliver = FALSE;
                            }
                            // EOS
                            if (!bShouldDeliver)
                            {
                                return(S_FALSE);
                            }
                        }
                    }
                }
            }while (!bShouldDeliver);

            return(NOERROR);
        }
Ejemplo n.º 3
0
        public override int FillBuffer(ref IMediaSampleImpl _sample)
        {
#if HAMED_LOG_FPS_2
            _FPS2Count++;
            if (_FPS2Count == 100)
            {
                DateTime FPS2End = DateTime.Now;
                double   m2      = FPS2End.Subtract(_FPS2Start).TotalMilliseconds;
                int      fps     = (int)(_FPS2Count * 1000 / m2);
                Console.WriteLine("FPS: Avg " + fps + " [100 Frames in " + (int)m2 + "ms]");
                _FPS2Start = FPS2End;
                _FPS2Count = 0;
            }
#endif

#if HAMED_LOG_FPS_1
            DateTime FPSEnd = DateTime.Now;
            double   m      = FPSEnd.Subtract(_FPSStart).TotalMilliseconds;
            if (m != 0)
            {
                int fps = (int)(1000 / m);
                fps *= _FPSCount;
                Console.WriteLine("FPS: " + fps + " [" + _FPSCount + " Frames in " + (int)m + "ms]");
                _FPSStart = FPSEnd;
                _FPSCount = 1;
            }
            else
            {
                _FPSCount++;
            }
#endif
#if HAMED_LOG_METHOD_INFO
            MethodBase method = new StackTrace().GetFrame(0).GetMethod();
            Console.WriteLine(this.GetType().FullName + " - " + method.Name + " - " + method.ToString());
#endif

            {
                AMMediaType pmt;
                if (S_OK == _sample.GetMediaType(out pmt))
                {
                    if (FAILED(SetMediaType(pmt)))
                    {
                        ASSERT(false);
                        _sample.SetMediaType(null);
                    }
                    pmt.Free();
                }
            }
            long    _start, _stop;
            HRESULT hr = NOERROR;
            long    rtLatency;
            if (FAILED(GetLatency(out rtLatency)))
            {
                rtLatency = UNITS / 30;
            }
            bool bShouldDeliver = false;
            do
            {
                if (m_dwAdviseToken == 0)
                {
                    m_pClock.GetTime(out m_rtClockStart);
                    hr = (HRESULT)m_pClock.AdvisePeriodic(m_rtClockStart + rtLatency, rtLatency, m_hSemaphore.Handle, out m_dwAdviseToken);
                    hr.Assert();
                }
                else
                {
                    if (!m_hSemaphore.WaitOne())
                    {
                        ASSERT(FALSE);
                    }
                }
                bShouldDeliver = TRUE;
                _start         = m_rtStart;
                _stop          = m_rtStart + 1;
                _sample.SetTime(_start, _stop);
                hr = (HRESULT)(m_Filter as VirtualCamFilter).FillBuffer(ref _sample);
                if (FAILED(hr) || S_FALSE == hr)
                {
                    return(hr);
                }

                m_pClock.GetTime(out m_rtClockStop);
                _sample.GetTime(out _start, out _stop);

                if (rtLatency > 0 && rtLatency * 3 < m_rtClockStop - m_rtClockStart)
                {
                    m_rtClockStop = m_rtClockStart + rtLatency;
                }
                _stop     = _start + (m_rtClockStop - m_rtClockStart);
                m_rtStart = _stop;
                lock (m_csPinLock)
                {
                    _start -= m_rtStreamOffset;
                    _stop  -= m_rtStreamOffset;
                }
                _sample.SetTime(_start, _stop);
                m_rtClockStart = m_rtClockStop;

                bShouldDeliver = ((_start >= 0) && (_stop >= 0));

                if (bShouldDeliver)
                {
                    lock (m_csPinLock)
                        if (m_rtStartAt != -1)
                        {
                            if (m_rtStartAt > _start)
                            {
                                bShouldDeliver = FALSE;
                            }
                            else
                            {
                                if (m_dwStartCookie != 0 && !m_bStartNotified)
                                {
                                    m_bStartNotified = TRUE;
                                    hr = (HRESULT)m_Filter.NotifyEvent(EventCode.StreamControlStarted, Marshal.GetIUnknownForObject(this), (IntPtr)m_dwStartCookie);
                                    if (FAILED(hr))
                                    {
                                        return(hr);
                                    }
                                }
                            }
                        }
                    if (!bShouldDeliver)
                    {
                        continue;
                    }
                    if (m_rtStopAt != -1)
                    {
                        if (m_rtStopAt < _start)
                        {
                            if (!m_bStopNotified)
                            {
                                m_bStopNotified = TRUE;
                                if (m_dwStopCookie != 0)
                                {
                                    hr = (HRESULT)m_Filter.NotifyEvent(EventCode.StreamControlStopped, Marshal.GetIUnknownForObject(this), (IntPtr)m_dwStopCookie);
                                    if (FAILED(hr))
                                    {
                                        return(hr);
                                    }
                                }
                                bShouldDeliver = m_bShouldFlush;
                            }
                            else
                            {
                                bShouldDeliver = FALSE;
                            }
                            // EOS
                            if (!bShouldDeliver)
                            {
                                return(S_FALSE);
                            }
                        }
                    }
                }
            }while (!bShouldDeliver);

            return(NOERROR);
        }