示例#1
0
        public unsafe int FillBuffer(ref IMediaSampleImpl _sample)
        {
            IntPtr _ptr;

            _sample.GetPointer(out _ptr);
            int length = _sample.GetSize();

            if (!KinectCamSettigns.Default.Desktop)
            {
                KinectHelper.GenerateFrame(_ptr, length, KinectCamSettigns.Default.Mirrored, KinectCamSettigns.Default.Zoom);
            }
            else
            {
                if (m_hBitmap == IntPtr.Zero)
                {
                    m_hBitmap = CreateCompatibleBitmap(m_hScreenDC, m_nWidth, Math.Abs(m_nHeight));
                }
                IntPtr hOldBitmap = SelectObject(m_hMemDC, m_hBitmap);
                StretchBlt(m_hMemDC, 0, 0, m_nWidth, Math.Abs(m_nHeight), m_hScreenDC, 0, 0, m_nMaxWidth, m_nMaxHeight, TernaryRasterOperations.SRCCOPY);
                SelectObject(m_hMemDC, hOldBitmap);
                GetDIBits(m_hMemDC, m_hBitmap, 0, (uint)Math.Abs(m_nHeight), _ptr, ref m_bmi, 0);
            }

            _sample.SetActualDataLength(_sample.GetSize());
            _sample.SetSyncPoint(true);

            return(NOERROR);
        }
        public unsafe int FillBuffer(ref IMediaSampleImpl _sample)
        {
            IntPtr _ptr;

            _sample.GetPointer(out _ptr);
            int length = _sample.GetSize();

            ShowNextImage(_ptr, length);

            //if (_settings.ShowDesktop)
            //{
            //    if (m_hBitmap == IntPtr.Zero)
            //    {
            //        m_hBitmap = CreateCompatibleBitmap(m_hScreenDC, m_nWidth, Math.Abs(m_nHeight));
            //    }
            //    IntPtr hOldBitmap = SelectObject(m_hMemDC, m_hBitmap);
            //    StretchBlt(m_hMemDC, 0, 0, m_nWidth, Math.Abs(m_nHeight), m_hScreenDC, 0, 0, m_nMaxWidth, m_nMaxHeight, TernaryRasterOperations.SRCCOPY);
            //    SelectObject(m_hMemDC, hOldBitmap);
            //    GetDIBits(m_hMemDC, m_hBitmap, 0, (uint)Math.Abs(m_nHeight), _ptr, ref m_bmi, 0);
            //}

            _sample.SetActualDataLength(_sample.GetSize());
            _sample.SetSyncPoint(true);

            return(NOERROR);
        }
示例#3
0
        public int FillBuffer(ref IMediaSampleImpl _sample)
        {
#if HAMED_LOG_METHOD_INFO
            MethodBase method = new StackTrace().GetFrame(0).GetMethod();
            Console.WriteLine(this.GetType().FullName + " - " + method.Name + " - " + method.ToString());
#endif

            if (m_hBitmap == IntPtr.Zero)
            {
                m_hBitmap = CreateCompatibleBitmap(m_hScreenDC, m_nWidth, Math.Abs(m_nHeight));
            }
            IntPtr _ptr;
            _sample.GetPointer(out _ptr);

            IntPtr hOldBitmap = SelectObject(m_hMemDC, m_hBitmap);

            StretchBlt(m_hMemDC, 0, 0, m_nWidth, Math.Abs(m_nHeight), m_hScreenDC, 0, 0, m_nMaxWidth, m_nMaxHeight, TernaryRasterOperations.SRCCOPY);

            SelectObject(m_hMemDC, hOldBitmap);

            GetDIBits(m_hMemDC, m_hBitmap, 0, (uint)Math.Abs(m_nHeight), _ptr, ref m_bmi, 0);

            _sample.SetActualDataLength(_sample.GetSize());
            _sample.SetSyncPoint(true);
            return(NOERROR);
        }
示例#4
0
        /// <summary>
        /// Fills the buffer.
        /// </summary>
        /// <param name="pSample">The p sample.</param>
        /// <returns></returns>
        public override int FillBuffer(ref IMediaSampleImpl pSample)
        {
            Resource screenResource;
            OutputDuplicateFrameInformation duplicateFrameInformation;

            m_DuplicatedOutput.AcquireNextFrame(10000, out duplicateFrameInformation, out screenResource);

            ResourceRegion region = new ResourceRegion(
                Math.Max(m_CaptureSettings.m_Rect.left, 0),
                Math.Max(m_CaptureSettings.m_Rect.top, 0),
                0,
                Math.Min(m_CaptureSettings.m_Rect.right, m_Output.Description.DesktopBounds.Right),
                Math.Min(m_CaptureSettings.m_Rect.bottom, m_Output.Description.DesktopBounds.Bottom),
                1
                );

            m_Device.ImmediateContext.CopySubresourceRegion(
                screenResource.QueryInterface <SharpDX.Direct3D11.Resource>(),
                0,
                region,
                m_ScreenTexture.QueryInterface <SharpDX.Direct3D11.Resource>(),
                0
                );

            DataBox mapSource = m_Device.ImmediateContext.MapSubresource(m_ScreenTexture, 0, MapMode.Read, MapFlags.None);

            IntPtr pImageDest;

            pSample.GetPointer(out pImageDest);


            var sourcePtr = mapSource.DataPointer;
            var destPtr   = IntPtr.Add(pImageDest, (m_nHeight - 1) * m_nWidth * 4);

            for (int y = 0; y < m_nHeight; y++)
            {
                Utilities.CopyMemory(destPtr, sourcePtr, m_nWidth * 4);

                sourcePtr = IntPtr.Add(sourcePtr, mapSource.RowPitch);
                destPtr   = IntPtr.Subtract(destPtr, m_nWidth * 4);
            }


            pSample.SetActualDataLength(CurrentMediaType.sampleSize);
            pSample.SetSyncPoint(true);

            long _stop = m_lLastSampleTime + m_nAvgTimePerFrame;

            pSample.SetTime(m_lLastSampleTime, _stop);

            m_lLastSampleTime = _stop;

            m_Device.ImmediateContext.UnmapSubresource(m_ScreenTexture, 0);
            screenResource.Dispose();
            m_DuplicatedOutput.ReleaseFrame();

            return(NOERROR);
        }
示例#5
0
        public override int OnReceive(ref IMediaSampleImpl _sample)
        {
            HRESULT hr = (HRESULT)CheckStreaming();

            if (hr != S_OK)
            {
                return(hr);
            }
            return((m_Filter as DumpFilter).OnReceive(ref _sample));
        }
        public int FillBuffer(ref IMediaSampleImpl _sample)
        {
            IntPtr _ptr;

            _sample.GetPointer(out _ptr);

            CapturePipeline.Instance.updateData(_ptr);

            _sample.SetActualDataLength(_sample.GetSize());
            _sample.SetSyncPoint(true);
            return(NOERROR);
        }
示例#7
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);
        }
示例#8
0
        public int OnReceive(ref IMediaSampleImpl _sample)
        {
            lock (m_Lock)
            {
                if (m_Stream == null && m_sFileName != "")
                {
                    m_Stream = new FileStream(m_sFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
                }

                int _length = _sample.GetActualDataLength();
                if (m_Stream != null && _length > 0)
                {
                    byte[] _data = new byte[_length];
                    IntPtr _ptr;
                    _sample.GetPointer(out _ptr);
                    Marshal.Copy(_ptr, _data, 0, _length);
                    m_Stream.Write(_data, 0, _length);
                }
            }
            return(S_OK);
        }
示例#9
0
        public int OnReceive(ref IMediaSampleImpl _sample)
        {
            lock (m_Lock)
            {
                if (m_Stream == null)
                {
                    OpenFile();
                }

                int _length = _sample.GetActualDataLength();
                if (m_Stream != null && _length > 0)
                {
                    byte[] _data = new byte[_length];
                    IntPtr _ptr;
                    _sample.GetPointer(out _ptr);
                    Marshal.Copy(_ptr, _data, 0, _length);
                    m_Stream.Write(_data, 0, _length);
                }
            }
            return(S_OK);
        }
示例#10
0
        public override int FillBuffer(ref IMediaSampleImpl _sample)
        {
            AMMediaType pmt = GetPMT(_sample);

            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);
                    if (m_hSemaphore != null)
                    {
                        hr = (HRESULT)m_pClock.AdvisePeriodic(m_rtClockStart + rtLatency, rtLatency, m_hSemaphore.Handle, out m_dwAdviseToken);
                        //hr.Assert();
                    }
                }
                else
                {
                    if (m_hSemaphore != null && !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);
        }
示例#11
0
        public override int Transform(ref IMediaSampleImpl _input, ref IMediaSampleImpl _sample)
        {
            Console.WriteLine("Transform " + DateTime.Now.Millisecond);

            DateTime starttime = DateTime.Now;

            int    lDataLength = _input.GetActualDataLength();
            IntPtr _ptrIn;
            IntPtr _ptrOut;

            BitmapInfoHeader _bmiIn  = (BitmapInfoHeader)Input.CurrentMediaType;
            BitmapInfoHeader _bmiOut = (BitmapInfoHeader)Output.CurrentMediaType;

            _sample.SetActualDataLength(_bmiOut.GetBitmapSize());

            Console.WriteLine("inlen " + lDataLength + " outlen" + (_bmiIn.Width * _bmiIn.Height * 3) + " " + DateTime.Now.Millisecond);

            _input.GetPointer(out _ptrIn);
            _sample.GetPointer(out _ptrOut);

            Bitmap _bmpOut = converttobitmap(_ptrIn, _ptrOut, lDataLength, _bmiIn.Height, _bmiIn.Width);

            Console.WriteLine("gotbitmap " + DateTime.Now.Millisecond);

            datain += _bmiIn.Height * _bmiIn.Width * 3;
            frames++;
            // Application.DoEvents();

            secondstaken1 += (DateTime.Now - starttime).TotalSeconds;

            long start, end;

            _input.GetTime(out start, out end);

            {
                //_bmpIn.RotateFlip(RotateFlipType.RotateNoneFlipY);
                Graphics _graphics = Graphics.FromImage(_bmpOut);

                _graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                _graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;

                secondstaken2 += (DateTime.Now - starttime).TotalSeconds;

                try
                {
                    double videotime = (start / 10000000.0);

                    DateTime temp = vid.videopos;

                    vid.videopos = temp.AddSeconds(videotime);

                    Bitmap img;

                    // 10 hz
                    if (videotime > (lasthudtime + 0.1))
                    {
                        // get hud
                        img          = vid.gethud(_bmpOut, videotime);
                        lasthudcache = (Bitmap)img.Clone();

                        lasthudtime = videotime;
                        hudframes++;
                    }
                    else
                    {
                        img = (Bitmap)lasthudcache.Clone();
                    }

                    secondstaken3 += (DateTime.Now - starttime).TotalSeconds;

                    //_graphics.DrawImage(_bmpOut, 0, 0);

                    img.RotateFlip(RotateFlipType.RotateNoneFlipY);

                    //img.MakeTransparent();
                    secondstaken4 += (DateTime.Now - starttime).TotalSeconds;

                    _graphics.DrawImage(img, 0, 0, _bmpOut.Width, _bmpOut.Height);

                    secondstaken5 += (DateTime.Now - starttime).TotalSeconds;

                    img.Dispose();
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }

                _graphics.Dispose();
                //  _bmpIn.RotateFlip(RotateFlipType.RotateNoneFlipY);
            }
            secondstaken6 += (DateTime.Now - starttime).TotalSeconds;


            dataout += _bmpOut.Height * _bmpOut.Width * 3;

            _bmpOut.Dispose();

            secondstaken += (DateTime.Now - starttime).TotalSeconds;

            if (time.Second != DateTime.Now.Second)
            {
                vid.textbox = string.Format(
                    @"input: {0}
output: {1}
frames: {2}
hudframes: {3}
pos: {4}
start: {5}
end: {6}
seconds {7}
seconds1 {8}
seconds2 {9}
seconds3 {10}
seconds4 {11}
seconds5 {12}
seconds6 {13}", datain, dataout, frames, hudframes, vid.videopos, start / 10000000.0, end / 10000000.0, secondstaken, secondstaken1, secondstaken2, secondstaken3, secondstaken4, secondstaken5, secondstaken6);

                datain = dataout = frames = hudframes = 0;


                secondstaken = secondstaken1 = secondstaken2 = secondstaken3 = secondstaken4 = secondstaken5 = secondstaken6 = 0;
                time         = DateTime.Now;
            }

            Console.WriteLine("Transform Done " + DateTime.Now.Millisecond);

            return(S_OK);
        }
示例#12
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);
        }