Beispiel #1
0
        /// <inheritdoc />
        public virtual void Callback(IBuffer buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"In managed {this.WorkingPort.PortType.GetPortType()} callback");
            }

            var data           = buffer.GetBufferData();
            var eos            = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) || buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS);
            var containsIFrame = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_CONFIG);

            MMALLog.Logger.LogDebug("Attempting to process data.");

            this.CaptureHandler?.Process(new ImageContext
            {
                Data        = data,
                Eos         = eos,
                IFrame      = containsIFrame,
                Resolution  = this.WorkingPort.Resolution,
                Encoding    = this.WorkingPort.EncodingType,
                PixelFormat = this.WorkingPort.PixelFormat,
                Raw         = this.WorkingPort.EncodingType.EncType == MMALEncoding.EncodingType.PixelFormat
            });

            if (eos)
            {
                // Once we have a full frame, perform any post processing as required.
                this.CaptureHandler?.PostProcess();
            }
        }
        public virtual void Callback(IBuffer buffer)
        {
            var data = buffer.GetBufferData();
            var eos  = buffer.AssertProperty(MmalBufferProperties.MmalBufferHeaderFlagFrameEnd) || buffer.AssertProperty(MmalBufferProperties.MmalBufferHeaderFlagEos);

            CaptureHandler?.Process(data);

            if (eos)
            {
                CaptureHandler?.PostProcess();
            }
        }
        /// <inheritdoc />
        public virtual void Callback(IBuffer buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"In managed {this.WorkingPort.PortType.GetPortType()} callback");
            }

            long?pts = null;

            var data           = buffer.GetBufferData();
            var eos            = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) || buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS);
            var containsIFrame = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_CONFIG);

            if (this is IVideoOutputCallbackHandler &&
                !buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_CONFIG) &&
                buffer.Pts != MMALUtil.MMAL_TIME_UNKNOWN &&
                (buffer.Pts != _ptsLastTime || !_ptsLastTime.HasValue))
            {
                if (!_ptsStartTime.HasValue)
                {
                    _ptsStartTime = buffer.Pts;
                }

                _ptsLastTime = buffer.Pts;
                pts          = buffer.Pts - _ptsStartTime.Value;
            }

            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug("Attempting to process data.");
            }

            this.CaptureHandler?.Process(new ImageContext
            {
                Data        = data,
                Eos         = eos,
                IFrame      = containsIFrame,
                Resolution  = this.WorkingPort.Resolution,
                Encoding    = this.WorkingPort.EncodingType,
                PixelFormat = this.WorkingPort.PixelFormat,
                Raw         = this.WorkingPort.EncodingType.EncType == MMALEncoding.EncodingType.PixelFormat,
                Pts         = pts,
                Stride      = MMALUtil.mmal_encoding_width_to_stride(WorkingPort.PixelFormat?.EncodingVal ?? this.WorkingPort.EncodingType.EncodingVal, this.WorkingPort.Resolution.Width)
            });

            if (eos)
            {
                // Once we have a full frame, perform any post processing as required.
                this.CaptureHandler?.PostProcess();
            }
        }
Beispiel #4
0
        /// <summary>
        /// The callback function to carry out.
        /// </summary>
        /// <param name="buffer">The working buffer header.</param>
        public override void Callback(IBuffer buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug("In video output callback");
            }

            if (this.PrepareSplit && buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_CONFIG))
            {
                this.CaptureHandler.Split();
                LastSplit         = DateTime.Now;
                this.PrepareSplit = false;
            }

            // Ensure that if we need to split then this is done before processing the buffer data.
            if (this.Split != null)
            {
                if (!this.LastSplit.HasValue)
                {
                    LastSplit = DateTime.Now;
                }

                if (DateTime.Now.CompareTo(this.CalculateSplit()) > 0)
                {
                    MMALLog.Logger.LogInformation("Preparing to split.");
                    this.PrepareSplit = true;
                    this.WorkingPort.SetParameter(MMALParametersVideo.MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME, true);
                }
            }

            if (this.StoreMotionVectors && buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO))
            {
                // This is data containing Motion vectors. Check if the capture handler supports storing motion vectors.
                if (this.CaptureHandler is IMotionVectorCaptureHandler)
                {
                    var handler = this.CaptureHandler as IMotionVectorCaptureHandler;
                    handler?.ProcessMotionVectors(buffer.GetBufferData());
                }
            }
            else
            {
                // If user has requested to store motion vectors separately, do not store the motion vector data in the same file
                // as image frame data.
                base.Callback(buffer);
            }
        }
Beispiel #5
0
        /// <inheritdoc />
        public virtual void Callback(IBuffer buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"In managed {this.WorkingPort.PortType.GetPortType()} callback");
            }

            if (this.EncodingType != null && this.WorkingPort.EncodingType != this.EncodingType)
            {
                throw new ArgumentException("Port Encoding Type not supported for this handler.");
            }

            var data = buffer.GetBufferData();
            var eos  = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) ||
                       buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS);

            this.CaptureHandler?.Process(data, eos);

            if (eos)
            {
                // Once we have a full frame, perform any post processing as required.
                this.CaptureHandler?.PostProcess();
            }
        }