/// <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(); } }
/// <inheritdoc /> public override void Callback(IBuffer buffer) { base.Callback(buffer); var eos = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) || buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS); if (eos && this.CaptureHandler is IFileStreamCaptureHandler) { ((IFileStreamCaptureHandler)this.CaptureHandler).NewFile(); } }
/// <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(); } }
/// <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); } }
/// <inheritdoc /> public override void Callback(IBuffer buffer) { var componentRef = this.WorkingPort.ComponentReference as IImageEncoder; if (componentRef == null) { throw new ArgumentException($"Working port component is not of type {nameof(IImageEncoder)}"); } base.Callback(buffer); var eos = buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) || buffer.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS); if (eos && this.CaptureHandler is IFileStreamCaptureHandler) { ((IFileStreamCaptureHandler)this.CaptureHandler).NewFile(); } }
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"); } 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(); } }
private void ProcessBuffer(IBuffer bufferImpl) { var eos = bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS) || this.ComponentReference.ForceStopProcessing; if (bufferImpl.CheckState()) { if (bufferImpl.Cmd > 0) { if (bufferImpl.Cmd == MMALEvents.MMAL_EVENT_FORMAT_CHANGED) { Task.Run(() => { this.ProcessFormatChangedEvent(bufferImpl); }); } else { this.ReleaseBuffer(bufferImpl); } } else { if ((bufferImpl.Length > 0 && !eos && !this.Trigger.Task.IsCompleted) || (eos && !this.Trigger.Task.IsCompleted)) { this.CallbackHandler.Callback(bufferImpl); } else { MMALLog.Logger.LogDebug("Buffer length empty."); } // Ensure we release the buffer before any signalling or we will cause a memory leak due to there still being a reference count on the buffer. this.ReleaseBuffer(bufferImpl); } } else { MMALLog.Logger.LogDebug($"Invalid output buffer received"); } // If this buffer signals the end of data stream, allow waiting thread to continue. if (eos) { MMALLog.Logger.LogDebug($"{this.ComponentReference.Name} {this.Name} End of stream. Signaling completion..."); Task.Run(() => { this.Trigger.SetResult(true); }); } }