Inheritance: System.EventArgs
        /// <summary>
        /// Respond to capture event.
        /// This should return as fast as possible.
        /// </summary>
        public void HandleCapturedFrame(object sender, VideoDataEventArgs e)
        {
            if (e.Frame != null)
            {
                TimedImage ti = new TimedImage(e.CaptureTime, width, height);

                try {
                    if (ProcessorQueue != null)                       // process the source image
                    {
                        foreach (var item in ProcessorQueue)
                        {
                            item.ProcessFrame(e.Frame, e.CaptureTime);
                        }
                    }
                } catch { }

                lock (WaitingFrames) {
                    WaitingFrames.Add(ti);
                    ResampleBuffer(e.Frame, ref ti.Luma, ref ti.Cr, ref ti.Cb, width, height);
                }

                try {
                    if (ProcessorQueue != null)                       // process the YUV buffer
                    {
                        foreach (var item in ProcessorQueue)
                        {
                            item.ProcessFrame(ti);
                        }
                    }
                } catch { }
            }
        }
Exemple #2
0
 protected void OnFrameAvailable(object sender, VideoDataEventArgs e)
 {
     if (FrameAvailable != null)
     {
         FrameAvailable(sender, e);
     }
 }
Exemple #3
0
        /// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary>
        int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
        {
            if (_lastSampleTime < 0.0)
            {
                _lastSampleTime = SampleTime;
                return(0);
            }
            double frame_duration = SampleTime - _lastSampleTime;

            _lastSampleTime = SampleTime;


            // this method *REQUIRES* that the frame be properly consumed and dropped before returning from this method
            // After this method returns, 'pBuffer' will be freed.
            Bitmap frame = null;

            // If primary video size <> capture size, we rescale here (to make sure plug-ins work as expected)
            if (this.Width != TargetFrameSize.Width || this.Height != TargetFrameSize.Height)
            {
                frame = RescaleToTargetSize(pBuffer);
            }
            else
            {
                frame = new Bitmap(this.Width, this.Height, 3 * this.Width, PixelFormat.Format24bppRgb, pBuffer);
            }

            VideoDataEventArgs args = new VideoDataEventArgs();

            args.Frame = frame;
            if (UseAbsoluteTime)
            {
                args.CaptureTime = (DateTime.Now - _startDay).TotalSeconds - m_TimecodeBase - frame_duration;
            }
            else
            {
                args.CaptureTime = SampleTime - m_TimecodeBase;
                if (args.CaptureTime < 0.0)
                {
                    return(0);
                }
            }

            OnFrameAvailable(this, args);
            frame.Dispose();
            return(0);
        }
        /// <summary>
        /// Respond to capture event.
        /// This should return as fast as possible.
        /// </summary>
        public void HandleCapturedFrame(object sender, VideoDataEventArgs e)
        {
            if (e.Frame != null) {
                TimedImage ti = new TimedImage(e.CaptureTime, width, height);

                try {
                    if (ProcessorQueue != null) { // process the source image
                        foreach (var item in ProcessorQueue) {
                            item.ProcessFrame(e.Frame, e.CaptureTime);
                        }
                    }
                } catch { }

                lock (WaitingFrames) {
                    WaitingFrames.Add(ti);
                    ResampleBuffer(e.Frame, ref ti.Luma, ref ti.Cr, ref ti.Cb, width, height);
                }

                try {
                    if (ProcessorQueue != null) { // process the YUV buffer
                        foreach (var item in ProcessorQueue) {
                            item.ProcessFrame(ti);
                        }
                    }
                } catch { }
            }
        }
 protected void OnFrameAvailable(object sender, VideoDataEventArgs e)
 {
     if (FrameAvailable != null) {
         FrameAvailable(sender, e);
     }
 }
        /// <summary> buffer callback, COULD BE FROM FOREIGN THREAD. </summary>
        int ISampleGrabberCB.BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
        {
            if (_lastSampleTime < 0.0) {
                _lastSampleTime = SampleTime;
                return 0;
            }
            double frame_duration = SampleTime - _lastSampleTime;
            _lastSampleTime = SampleTime;

            // this method *REQUIRES* that the frame be properly consumed and dropped before returning from this method
            // After this method returns, 'pBuffer' will be freed.
            Bitmap frame = null;

            // If primary video size <> capture size, we rescale here (to make sure plug-ins work as expected)
            if (this.Width != TargetFrameSize.Width || this.Height != TargetFrameSize.Height) {
                frame = RescaleToTargetSize(pBuffer);
            } else {
                frame = new Bitmap(this.Width, this.Height, 3 * this.Width, PixelFormat.Format24bppRgb, pBuffer);
            }

            VideoDataEventArgs args = new VideoDataEventArgs();
            args.Frame = frame;
            if (UseAbsoluteTime) {
                args.CaptureTime = (DateTime.Now - _startDay).TotalSeconds - m_TimecodeBase - frame_duration;
            } else {
                args.CaptureTime = SampleTime - m_TimecodeBase;
                if (args.CaptureTime < 0.0) return 0;
            }

            OnFrameAvailable(this, args);
            frame.Dispose();
            return 0;
        }