/// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.OutputLock)
            {
                var bufferImpl = new MMALBufferImpl(buffer);

                if (bufferImpl.CheckState())
                {
                    if (MMALCameraConfig.Debug)
                    {
                        MMALLog.Logger.Debug($"Putting output port buffer back into queue {((IntPtr)MMALImageFileDecoder.WorkingQueue.Ptr).ToString()}");
                    }

                    bufferImpl.PrintProperties();

                    MMALImageFileDecoder.WorkingQueue.Put(bufferImpl);
                }
                else
                {
                    MMALLog.Logger.Debug($"Invalid output buffer received");
                }

                if (this.Trigger != null && this.Trigger.CurrentCount > 0)
                {
                    this.Trigger.Signal();
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal virtual void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.Debug("In native output callback");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            bufferImpl.PrintProperties();

            var failed = bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED);

            var eos = bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) ||
                      bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS) ||
                      this.ComponentReference.ForceStopProcessing;

            if ((bufferImpl.CheckState() && bufferImpl.Length > 0 && !eos && !failed && !this.Trigger) || (eos && !this.Trigger))
            {
                this.ManagedOutputCallback.Callback(bufferImpl);
            }

            // 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.ReleaseOutputBuffer(bufferImpl);

            // If this buffer signals the end of data stream, allow waiting thread to continue.
            if (eos || failed)
            {
                MMALLog.Logger.Debug($"{this.ComponentReference.Name} {this.Name} End of stream. Signaling completion...");
                this.Trigger = true;
            }
        }
        /// <summary>
        /// The native callback MMAL passes buffer headers to
        /// </summary>
        /// <param name="port">The port the buffer is sent to</param>
        /// <param name="buffer">The buffer header</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.OutputLock)
            {
                var bufferImpl = new MMALBufferImpl(buffer);

                if (MMALCameraConfig.Debug)
                {
                    bufferImpl.PrintProperties();
                }

                if (bufferImpl.Length > 0)
                {
                    this.ManagedOutputCallback(bufferImpl, this);
                }

                //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.ReleaseOutputBuffer(bufferImpl);

                if (this.Timeout.HasValue && DateTime.Now.CompareTo(this.Timeout.Value) > 0)
                {
                    if (this.Trigger != null && this.Trigger.CurrentCount > 0)
                    {
                        this.Trigger.Signal();
                    }
                }
            }
        }
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            var bufferImpl = new MMALBufferImpl(buffer);

            if (bufferImpl.CheckState() && MMALVideoFileDecoder.WorkingQueue != null)
            {
                if (MMALCameraConfig.Debug)
                {
                    MMALLog.Logger.Debug($"Putting output port buffer back into queue {((IntPtr)MMALVideoFileDecoder.WorkingQueue.Ptr).ToString()}");
                }

                bufferImpl.PrintProperties();

                MMALVideoFileDecoder.WorkingQueue.Put(bufferImpl);
            }
            else
            {
                MMALLog.Logger.Debug($"Invalid output buffer received");
            }

            if (port->IsEnabled == 1 && !this.Trigger)
            {
                this.Trigger = true;
            }
        }
        /// <summary>
        /// The native callback MMAL passes buffer headers to
        /// </summary>
        /// <param name="port">The port the buffer is sent to</param>
        /// <param name="buffer">The buffer header</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.OutputLock)
            {
                var bufferImpl = new MMALBufferImpl(buffer);

                if (MMALCameraConfig.Debug)
                {
                    bufferImpl.PrintProperties();
                }

                if (bufferImpl.Length > 0)
                {
                    this.ManagedOutputCallback(bufferImpl, this);
                }

                //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.ReleaseOutputBuffer(bufferImpl);

                //If this buffer signals the end of data stream, allow waiting thread to continue.
                if (bufferImpl.Properties.Any(c => c == MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS ||
                                              c == MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED))
                {
                    MMALLog.Logger.Debug("End of stream. Signaling completion...");

                    if (this.Trigger != null && this.Trigger.CurrentCount > 0)
                    {
                        this.Trigger.Signal();
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"{this.Name}: In native {nameof(VideoPort)} output callback");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            bufferImpl.PrintProperties();

            var eos = (this.PortConfig.Timeout.HasValue && DateTime.Now.CompareTo(this.PortConfig.Timeout.Value) > 0) || this.ComponentReference.ForceStopProcessing;

            if (bufferImpl.CheckState() && bufferImpl.Length > 0 && !eos && !this.Trigger.Task.IsCompleted)
            {
                this.CallbackHandler.Callback(bufferImpl);
            }

            // 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, eos);

            if (eos && !this.Trigger.Task.IsCompleted)
            {
                MMALLog.Logger.LogDebug($"{this.Name}: Timeout exceeded, triggering signal.");
                Task.Run(() => { this.Trigger.SetResult(true); });
            }
        }
Esempio n. 7
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"{this.Name}: In native {nameof(FastStillPort)} output callback.");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            bufferImpl.PrintProperties();

            var failed = bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED);

            if ((bufferImpl.CheckState() && bufferImpl.Length > 0 && !this.ComponentReference.ForceStopProcessing && !failed && !this.Trigger.Task.IsCompleted) ||
                (this.ComponentReference.ForceStopProcessing && !this.Trigger.Task.IsCompleted))
            {
                this.CallbackHandler.Callback(bufferImpl);
            }

            // 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, this.ComponentReference.ForceStopProcessing || failed);

            // If this buffer signals the end of data stream, allow waiting thread to continue.
            if (this.ComponentReference.ForceStopProcessing || failed)
            {
                MMALLog.Logger.LogDebug($"{this.Name}: Signaling completion of continuous still frame capture...");
                Task.Run(() => { this.Trigger.SetResult(true); });
            }
        }
Esempio n. 8
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeControlPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALControlPort.ControlLock)
            {
                if (MMALCameraConfig.Debug)
                {
                    MMALLog.Logger.Debug("In native control callback.");
                }

                var bufferImpl = new MMALBufferImpl(buffer);

                if (bufferImpl.CheckState())
                {
                    if (MMALCameraConfig.Debug)
                    {
                        bufferImpl.ParseEvents();
                        bufferImpl.PrintProperties();
                    }

                    this.ManagedControlCallback.Callback(bufferImpl);

                    if (MMALCameraConfig.Debug)
                    {
                        MMALLog.Logger.Debug("Releasing buffer.");
                    }

                    bufferImpl.Release();
                }
                else
                {
                    MMALLog.Logger.Warn("Received null control buffer.");
                }
            }
        }
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"{this.Name}: In native {nameof(SplitterVideoPort)} output callback");
            }

            base.NativeOutputPortCallback(port, buffer);
        }
Esempio n. 10
0
 public MMAL_CLOCK_EVENT_T(uint id, uint magic, MMAL_BUFFER_HEADER_T *buffer, uint padding0,
                           MMAL_CLOCK_EVENT_DATA data, long padding1)
 {
     this.id       = id;
     this.magic    = magic;
     this.buffer   = buffer;
     this.padding0 = padding0;
     this.data     = data;
     this.padding1 = padding1;
 }
        /// <summary>
        /// The native callback MMAL passes buffer headers to
        /// </summary>
        /// <param name="port">The port the buffer is sent to</param>
        /// <param name="buffer">The buffer header</param>
        internal override void NativeControlPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            var bufferImpl = new MMALBufferImpl(buffer);

            this.ManagedOutputCallback(bufferImpl, this);

            MMALLog.Logger.Debug("Releasing buffer");

            bufferImpl.Release();
        }
Esempio n. 12
0
        internal override void NativeInputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.InputLock)
            {
                var bufferImpl = new MMALBufferImpl(buffer);

                if (MMALCameraConfig.Debug)
                {
                    bufferImpl.PrintProperties();
                }

                this.ReleaseInputBuffer(bufferImpl);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"In native {nameof(FileEncodeOutputPort)} callback");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            bufferImpl.PrintProperties();
            bufferImpl.ParseEvents();

            this.ProcessBuffer(bufferImpl);
        }
Esempio n. 14
0
 public MMAL_BUFFER_HEADER_T(MMAL_BUFFER_HEADER_T *next, IntPtr priv, uint cmd, byte *data, uint allocSize, uint length, uint offset, uint flags, long pts, long dts, IntPtr type, IntPtr userData)
 {
     this.next      = next;
     this.priv      = priv;
     this.cmd       = cmd;
     this.data      = data;
     this.allocSize = allocSize;
     this.length    = length;
     this.offset    = offset;
     this.flags     = flags;
     this.pts       = pts;
     this.dts       = dts;
     this.type      = type;
     this.userData  = userData;
 }
        internal override void NativeInputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.Debug("Releasing input port buffer");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            bufferImpl.Release();

            if (!this.Trigger)
            {
                this.Trigger = true;
            }
        }
        internal override unsafe void NativeInputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.InputLock)
            {
                if (MMALCameraConfig.Debug)
                {
                    MMALLog.Logger.Debug("Releasing input port buffer");
                }

                var bufferImpl = new MMALBufferImpl(buffer);
                bufferImpl.Release();

                if (this.Trigger != null && this.Trigger.CurrentCount > 0)
                {
                    this.Trigger.Signal();
                }
            }
        }
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.Debug($"Putting output port buffer back into queue {((IntPtr)MMALImageFileEncoder.WorkingQueue.Ptr).ToString()}");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            bufferImpl.PrintProperties();

            MMALImageFileEncoder.WorkingQueue.Put(bufferImpl);

            if (port->IsEnabled == 1 && !this.Trigger)
            {
                this.Trigger = true;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.OutputLock)
            {
                if (MMALCameraConfig.Debug)
                {
                    MMALLog.Logger.Debug("In native output callback");
                }

                var bufferImpl = new MMALBufferImpl(buffer);

                if (MMALCameraConfig.Debug)
                {
                    bufferImpl.PrintProperties();
                }

                var triggered = this.Trigger != null && this.Trigger.CurrentCount == 0;
                var failed    = bufferImpl.Properties.Any(c => c == MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED);
                var eos       = bufferImpl.Properties.Any(c => c == MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END ||
                                                          c == MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS) || this.ComponentReference.ForceStopProcessing;

                if ((bufferImpl.CheckState() && bufferImpl.Length > 0 && !eos && !failed && !triggered) || (eos && !triggered))
                {
                    this.ManagedOutputCallback.Callback(bufferImpl);
                }

                // 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.ReleaseOutputBuffer(bufferImpl);

                // If this buffer signals the end of data stream, allow waiting thread to continue.
                if (eos || failed)
                {
                    if (this.Trigger != null && this.Trigger.CurrentCount > 0)
                    {
                        MMALLog.Logger.Debug("End of stream. Signaling completion...");
                        this.Trigger.Signal();
                    }
                }
            }
        }
Esempio n. 19
0
        /// <summary>
        /// The native callback MMAL passes buffer headers to.
        /// </summary>
        /// <param name="port">The port the buffer is sent to.</param>
        /// <param name="buffer">The buffer header.</param>
        internal override void NativeOutputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            lock (MMALPortBase.OutputLock)
            {
                if (MMALCameraConfig.Debug)
                {
                    MMALLog.Logger.Debug("In native output callback");
                }

                var bufferImpl = new MMALBufferImpl(buffer);

                if (MMALCameraConfig.Debug)
                {
                    bufferImpl.PrintProperties();
                }

                var triggered = this.Trigger != null && this.Trigger.CurrentCount == 0;
                var eos       = (this.Timeout.HasValue && DateTime.Now.CompareTo(this.Timeout.Value) > 0) || this.ComponentReference.ForceStopProcessing;

                if (bufferImpl.Ptr != null && (IntPtr)bufferImpl.Ptr != IntPtr.Zero && bufferImpl.Length > 0 && !eos && !triggered)
                {
                    this.ManagedOutputCallback.Callback(bufferImpl);
                }

                // 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.ReleaseOutputBuffer(bufferImpl);

                if (eos)
                {
                    if (this.Trigger != null && this.Trigger.CurrentCount > 0)
                    {
                        MMALLog.Logger.Debug("Timeout exceeded, triggering signal.");
                        this.Trigger.Signal();
                    }
                }
            }
        }
Esempio n. 20
0
        internal virtual unsafe void NativeInputPortCallback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug($"{this.Name}: In native input callback.");
            }

            var bufferImpl = new MMALBufferImpl(buffer);

            if (bufferImpl.CheckState())
            {
                if (bufferImpl.Cmd > 0)
                {
                    if (bufferImpl.Cmd == MMALEvents.MMAL_EVENT_FORMAT_CHANGED)
                    {
                        MMALLog.Logger.LogInformation("EVENT FORMAT CHANGED");
                    }
                }
            }

            bufferImpl.PrintProperties();

            this.ReleaseBuffer(bufferImpl);
        }
Esempio n. 21
0
 public static extern unsafe void mmal_buffer_header_release_continue(MMAL_BUFFER_HEADER_T *header);
Esempio n. 22
0
 public static extern unsafe MMAL_EVENT_FORMAT_CHANGED_T *mmal_event_format_changed_get(MMAL_BUFFER_HEADER_T *buffer);
Esempio n. 23
0
 public static extern unsafe void mmal_buffer_header_reset(MMAL_BUFFER_HEADER_T *header);
Esempio n. 24
0
 public MMAL_QUEUE_T(uint length, MMAL_BUFFER_HEADER_T *first, MMAL_BUFFER_HEADER_T **last)
 {
     this.length = length;
     this.first  = first;
     this.last   = last;
 }
Esempio n. 25
0
 public static extern unsafe void mmal_buffer_header_mem_unlock(MMAL_BUFFER_HEADER_T *header);
Esempio n. 26
0
 public static extern unsafe MMALUtil.MMAL_STATUS_T mmal_buffer_header_mem_lock(MMAL_BUFFER_HEADER_T *header);
Esempio n. 27
0
 public static unsafe extern void mmal_queue_put_back(MMAL_QUEUE_T *ptr, MMAL_BUFFER_HEADER_T *header);
Esempio n. 28
0
 public static extern unsafe void mmal_buffer_header_pre_release_cb_set(MMAL_BUFFER_HEADER_T *header, [MarshalAs(UnmanagedType.FunctionPtr)] MMAL_BH_PRE_RELEASE_CB_T cb, void *userdata);
Esempio n. 29
0
 public static extern unsafe void mmal_buffer_header_copy_header(MMAL_BUFFER_HEADER_T *dest, MMAL_BUFFER_HEADER_T *src);
Esempio n. 30
0
 public static extern unsafe MMALUtil.MMAL_STATUS_T mmal_buffer_header_replicate(MMAL_BUFFER_HEADER_T *header, MMAL_BUFFER_HEADER_T *header2);