Exemplo n.º 1
0
        internal void ReleaseOutputBuffer(MMALBufferImpl bufferImpl)
        {
            bufferImpl.Release();
            bufferImpl.Dispose();
            try
            {
                if (!this.Enabled)
                {
                    MMALLog.Logger.Warn("Port not enabled.");
                }

                if (this.BufferPool == null)
                {
                    MMALLog.Logger.Warn("Buffer pool null.");
                }

                if (this.Enabled && this.BufferPool != null)
                {
                    var newBuffer = MMALQueueImpl.GetBuffer(this.BufferPool.Queue.Ptr);

                    if (newBuffer != null)
                    {
                        this.SendBuffer(newBuffer);
                    }
                    else
                    {
                        MMALLog.Logger.Warn("Buffer null. Continuing.");
                    }
                }
            }
            catch (Exception e)
            {
                MMALLog.Logger.Warn($"Unable to send buffer header. {e.Message}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Represents the native callback method for a connection between two ports.
        /// </summary>
        /// <param name="connection">The native pointer to a MMAL_CONNECTION_T struct.</param>
        /// <returns>The value of all flags set against this connection.</returns>
        internal virtual int NativeConnectionCallback(MMAL_CONNECTION_T *connection)
        {
            lock (MMALConnectionImpl.ConnectionLock)
            {
                if (MMALCameraConfig.Debug)
                {
                    MMALLog.Logger.Debug("Inside native connection callback");
                }

                var queue      = new MMALQueueImpl(connection->Queue);
                var bufferImpl = queue.GetBuffer();

                if (bufferImpl != null)
                {
                    if (MMALCameraConfig.Debug)
                    {
                        bufferImpl.PrintProperties();
                    }

                    if (bufferImpl.Length > 0)
                    {
                        ConnectionCallbackProvider.FindCallback(this).InputCallback(bufferImpl);
                    }

                    this.InputPort.SendBuffer(bufferImpl);
                }
                else
                {
                    queue      = new MMALQueueImpl(connection->Pool->Queue);
                    bufferImpl = queue.GetBuffer();

                    if (bufferImpl != null)
                    {
                        if (MMALCameraConfig.Debug)
                        {
                            bufferImpl.PrintProperties();
                        }

                        if (bufferImpl.Length > 0)
                        {
                            ConnectionCallbackProvider.FindCallback(this).OutputCallback(bufferImpl);
                        }

                        this.OutputPort.SendBuffer(bufferImpl);
                    }
                    else
                    {
                        MMALLog.Logger.Debug("Buffer could not be obtained by connection callback");
                    }
                }
            }

            return((int)connection->Flags);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Represents the native callback method for a connection between two ports.
        /// </summary>
        /// <param name="connection">The native pointer to a MMAL_CONNECTION_T struct.</param>
        /// <returns>The value of all flags set against this connection.</returns>
        protected virtual int NativeConnectionCallback(MMAL_CONNECTION_T *connection)
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.LogDebug("Inside native connection callback");
            }

            var queue      = new MMALQueueImpl(connection->Queue);
            var bufferImpl = queue.GetBuffer();

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

                if (bufferImpl.Length > 0)
                {
                    this.CallbackHandler.InputCallback(bufferImpl);
                }

                this.InputPort.SendBuffer(bufferImpl);
            }
            else
            {
                queue      = new MMALQueueImpl(connection->Pool->Queue);
                bufferImpl = queue.GetBuffer();

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

                    if (bufferImpl.Length > 0)
                    {
                        this.CallbackHandler.OutputCallback(bufferImpl);
                    }

                    this.OutputPort.SendBuffer(bufferImpl);
                }
                else
                {
                    MMALLog.Logger.LogInformation("Buffer could not be obtained by connection callback");
                }
            }

            return((int)connection->Flags);
        }
Exemplo n.º 4
0
        internal void ReleaseInputBuffer(MMALBufferImpl bufferImpl)
        {
            bufferImpl.Release();

            if (this.Enabled && this.BufferPool != null)
            {
                var newBuffer = MMALQueueImpl.GetBuffer(this.BufferPool.Queue.Ptr);

                //Populate the new input buffer with user provided image data.
                var result = this.ManagedInputCallback(newBuffer, this);
                bufferImpl.ReadIntoBuffer(result.BufferFeed, result.EOF);

                try
                {
                    if (this.Trigger != null && this.Trigger.CurrentCount > 0 && result.EOF)
                    {
                        MMALLog.Logger.Debug("Received EOF. Releasing.");

                        this.Trigger.Signal();
                        newBuffer.Release();
                    }

                    if (newBuffer != null)
                    {
                        this.SendBuffer(newBuffer);
                    }
                    else
                    {
                        MMALLog.Logger.Warn("Buffer null. Continuing.");
                    }
                }
                catch (Exception ex)
                {
                    MMALLog.Logger.Warn($"Buffer handling failed. {ex.Message}");
                }
            }
        }