コード例 #1
0
        /// <summary>
        /// Gathers all data in this payload and returns as a byte array.
        /// </summary>
        /// <returns>A byte array containing the image frame.</returns>
        internal byte[] GetBufferData()
        {
            if (MMALCameraConfig.Debug)
            {
                MMALLog.Logger.Debug("Getting data from buffer");
            }

            MMALCheck(MMALBuffer.mmal_buffer_header_mem_lock(this.Ptr), "Unable to lock buffer header.");

            try
            {
                var ps     = this.Ptr->data + this.Offset;
                var buffer = new byte[(int)this.Ptr->Length];
                Marshal.Copy((IntPtr)ps, buffer, 0, buffer.Length);
                MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);

                return(buffer);
            }
            catch
            {
                // If something goes wrong, unlock the header.
                MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);
                MMALLog.Logger.Warn("Unable to handle data. Returning null.");
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Gathers all data in this payload and returns as a byte array
        /// </summary>
        /// <returns></returns>
        internal byte[] GetBufferData()
        {
            MMALCheck(MMALBuffer.mmal_buffer_header_mem_lock(this.Ptr), "Unable to lock buffer header.");

            try
            {
                var ps     = this.Ptr->data + this.Offset;
                var buffer = Array.CreateInstance(typeof(byte), (int)this.Ptr->Length) as byte[];
                Marshal.Copy((IntPtr)ps, buffer, 0, buffer.Length);
                MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);

                return(buffer);
            }
            catch
            {
                //If something goes wrong, unlock the header.
                MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);
                MMALLog.Logger.Warn("Unable to handle data. Returning null.");
                return(null);
            }
        }
コード例 #3
0
        internal void ReadIntoBuffer(byte[] source, bool eof)
        {
            MMALCheck(MMALBuffer.mmal_buffer_header_mem_lock(this.Ptr), "Unable to lock buffer header.");
            var ptrAlloc = Marshal.AllocHGlobal(source.Length);

            this.Ptr->data      = (byte *)ptrAlloc;
            this.Ptr->allocSize = (uint)source.Length;
            this.Ptr->length    = (uint)source.Length;

            if (eof)
            {
                this.Ptr->flags = (uint)MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS;
            }

            try
            {
                fixed(byte *pSource = source)
                {
                    var ps = pSource;

                    byte *pt = (byte *)ptrAlloc;

                    for (int i = 0; i < source.Length; i++)
                    {
                        *pt = *ps;
                        pt++;
                        ps++;
                    }
                }

                MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);
            }
            catch
            {
                //If something goes wrong, unlock the header.
                MMALBuffer.mmal_buffer_header_mem_unlock(this.Ptr);
                Marshal.FreeHGlobal(ptrAlloc);
                MMALLog.Logger.Warn("Unable to write data to buffer.");
            }
        }