Exemplo n.º 1
0
        public void NonEmptyFifoDoesNotReturnIsEmpty()
        {
            var fifo = new FifoBuffer <int>(5);

            fifo.Write(99);
            Assert.IsFalse(fifo.IsEmpty());
        }
Exemplo n.º 2
0
        public void PeekEmptyFifoReturnsFalse()
        {
            var           fifo = new FifoBuffer <KeyboardEvent>(5);
            KeyboardEvent result;

            Assert.IsFalse(fifo.Peek(out result));
        }
Exemplo n.º 3
0
 public MemoryMappedKeyboard(IKeyboardHub hub)
 {
     _hub         = hub;
     _eventBuffer = new FifoBuffer <KeyboardEvent>(16);
     Blocks       = new List <IAddressableBlock> {
         this
     };
 }
Exemplo n.º 4
0
        public void ReadEmptyFifoReturnsFalse()
        {
            var           fifo = new FifoBuffer <KeyboardEvent>(5);
            KeyboardEvent result;

            Assert.IsFalse(fifo.Read(out result));
            Assert.IsNull(result);
        }
Exemplo n.º 5
0
        public void ReadOneValueEmptiesFifo()
        {
            var fifo = new FifoBuffer <int>(5);

            fifo.Write(99);
            int result;

            Assert.IsTrue(fifo.Read(out result));
            Assert.IsFalse(fifo.Read(out result));
        }
Exemplo n.º 6
0
        public void NonFullFifoDoesntReturnIsFull()
        {
            var fifo = new FifoBuffer <int>(5);

            Assert.IsTrue(fifo.Write(1));
            Assert.IsTrue(fifo.Write(2));
            Assert.IsTrue(fifo.Write(3));
            Assert.IsTrue(fifo.Write(4));
            Assert.IsFalse(fifo.IsFull());
        }
Exemplo n.º 7
0
        public void PeekNonEmptyFifoReturnsTrue()
        {
            var fifo = new FifoBuffer <int>(5);

            fifo.Write(99);
            int result;

            Assert.IsTrue(fifo.Peek(out result));
            Assert.AreEqual(99, result);
        }
Exemplo n.º 8
0
        public void CantOverflowFifo()
        {
            var fifo = new FifoBuffer <int>(5);

            Assert.IsTrue(fifo.Write(1));
            Assert.IsTrue(fifo.Write(2));
            Assert.IsTrue(fifo.Write(3));
            Assert.IsTrue(fifo.Write(4));
            Assert.IsTrue(fifo.Write(5));
            Assert.IsFalse(fifo.Write(6));
        }
Exemplo n.º 9
0
        ComPortStream _streamOut; //Stream from emulator model to SerialPortToStream

        public ComPortToMemoryStream()
            : base(null)
        {
            _fifoIn  = new FifoBuffer();
            _fifoOut = new FifoBuffer();

            _streamIn  = new ComPortStream(_fifoIn, _fifoOut);
            _streamOut = new ComPortStream(_fifoOut, _fifoIn);

            _stream = _streamIn;
        }
Exemplo n.º 10
0
        public void FullFifoReturnIsFull()
        {
            var fifo = new FifoBuffer <int>(5);

            Assert.IsTrue(fifo.Write(1));
            Assert.IsTrue(fifo.Write(2));
            Assert.IsTrue(fifo.Write(3));
            Assert.IsTrue(fifo.Write(4));
            Assert.IsTrue(fifo.Write(5));
            Assert.IsTrue(fifo.IsFull());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Decodes audio data.
        /// </summary>
        /// <returns>Returns a decoded IAudioData buffer or null if no more buffer available.</returns>
        public IAudioData Decode()
        {
            if (m_Disposed)
            {
                throw new ObjectDisposedException(LogSourceName);
            }

            BufferFrame();

            // end of file ? -> yes exit
            if (m_DecodeFifoBuffer.Length == 0)
            {
                return(null);
            }

            var  outBuffer = new FifoBuffer();
            bool l_Loop    = true;

            while (l_Loop)
            {
                M123.RESULT result;
                result = M123.SafeNativeMethods.mpg123_decode(m_DecoderHandle, m_DecodeFifoBuffer, outBuffer, 8192);
                switch (result)
                {
                case M123.RESULT.NEED_MORE:
                    if (outBuffer.Length > 0)
                    {
                        l_Loop = false;
                        break;
                    }
                    BufferFrame();
                    if (m_DecodeFifoBuffer.Length == 0)
                    {
                        return(null);
                    }

                    break;

                case M123.RESULT.NEW_FORMAT: UpdateFormat(); break;

                default: M123.CheckResult(result); throw new InvalidOperationException();
                }
            }
            if (outBuffer.Length > 0)
            {
                var resultData = new AudioData(m_CurrentConfig.SamplingRate, m_CurrentConfig.Format, m_CurrentConfig.ChannelSetup, m_CurrentTimeStamp, 0, -1, outBuffer.ToArray());
                m_CurrentTimeStamp += resultData.Duration;
                return(resultData);
            }
            return(null);
        }
Exemplo n.º 12
0
 /// <summary>Releases unmanaged and - optionally - managed resources.</summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected override void Dispose(bool disposing)
 {
     m_Exit = true;
     if (m_StreamHandle != IntPtr.Zero)
     {
         PAErrorCode l_ErrorCode = PA.SafeNativeMethods.Pa_CloseStream(m_StreamHandle);
         if (l_ErrorCode != PAErrorCode.NoError)
         {
             Trace.WriteLine("Error Pa_CloseStream " + PA.GetErrorText(l_ErrorCode));
         }
         m_StreamHandle = IntPtr.Zero;
     }
     m_CallbackDelegate = null;
     m_StreamData       = null;
 }
Exemplo n.º 13
0
        internal override bool DeviceInitialize()
        {
            base.DeviceInitialize();

            if (!_isInitialized)
            {
                _fifoToDevice = new FifoBuffer();

                InitializeProtected();

                _isInitialized = true;

                StartRead();
            }

            return(true);
        }
Exemplo n.º 14
0
                void ReadCallback(object state)
                {
                    FifoBuffer fifoBuffer = _stream._fifoRead;

                    fifoBuffer.WaitHandle.WaitOne();

                    int bytesRead = Math.Min(fifoBuffer.Available, _count);

                    _bytesRead = fifoBuffer.Read(_buffer, _offset, bytesRead);

                    _completed = true;
                    _mre.Set();

                    if (_callback != null)
                    {
                        _callback(this);
                    }
                }
Exemplo n.º 15
0
        /// <summary>Starts the decoding process.</summary>
        /// <param name="source">The source.</param>
        /// <exception cref="InvalidOperationException">Source: Decoding already started!.</exception>
        public void BeginDecode(IFrameSource source)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(LogSourceName);
            }

            if (initialized)
            {
                throw new InvalidOperationException(string.Format("Source {0}: Decoding already started!", SourceName));
            }

            if (SourceName != null)
            {
                SourceName = source.Name;
            }

            initialized = true;
            M123.Initialize();

            m_Source = source;

            // open new decoder handle
            M123.RESULT result;
            m_DecoderHandle = M123.SafeNativeMethods.mpg123_new(null, out result);
            M123.CheckResult(result);

            // reset formats
            M123.CheckResult(M123.SafeNativeMethods.mpg123_format_none(m_DecoderHandle));

            // allow all mp3 native samplerates
            var mode = useFloatingPoint ? M123.ENC.FLOAT_32 : M123.ENC.SIGNED_16;

            foreach (var sampleRate in M123.SafeNativeMethods.mpg123_rates())
            {
                M123.CheckResult(M123.SafeNativeMethods.mpg123_format(m_DecoderHandle, new IntPtr(sampleRate), M123.CHANNELCOUNT.STEREO, mode));
            }

            // open feed
            result = M123.SafeNativeMethods.mpg123_open_feed(m_DecoderHandle);
            M123.CheckResult(result);
            m_DecodeFifoBuffer = new FifoBuffer();
        }
Exemplo n.º 16
0
        /// <summary>Closes the underlying stream and calls Dispose.</summary>
        public void Close()
        {
            if (m_Disposed)
            {
                throw new ObjectDisposedException(LogSourceName);
            }

            if (m_Initialized)
            {
                M123.Deinitialize();
                m_Initialized = false;
            }
            if (m_Source != null)
            {
                m_Source.Close();
                m_Source           = null;
                m_DecodeFifoBuffer = null;
            }
        }
Exemplo n.º 17
0
        /// <summary>Retrieves the tag as byte array.</summary>
        /// <returns></returns>
        public byte[] ToArray()
        {
            var buffer             = new FifoBuffer();
            ID3v2HeaderFlags flags = ID3v2HeaderFlags.None;

            /* we do not like extended headers so we won't write them
             * if (m_ExtendedHeader != null)
             * {
             *  buffer.Enqueue(m_ExtendedHeader.Data);
             *  flags |= ID3v2HeaderFlags.ExtendedHeader;
             * }
             */
            foreach (ID3v2Frame frame in frames)
            {
                buffer.Enqueue(frame.RawData);
            }
            int bodySize = buffer.Length;

            // no one likes footers so we won't write them
            var header = new ID3v2Header(Header.Version, Header.Revision, flags, bodySize);

            buffer.Prepend(header.Data);
            return(buffer.ToArray());
        }
Exemplo n.º 18
0
        internal FifoBuffer _fifoToDevice;  //From emulator to device

        public ComPortToStream()
        {
            _fifoToDevice = new FifoBuffer();
            _buffer       = new byte[512];
        }
Exemplo n.º 19
0
 public ComPortStream(FifoBuffer fifoRead, FifoBuffer fifoWrite)
 {
     _fifoRead  = fifoRead;
     _fifoWrite = fifoWrite;
 }
Exemplo n.º 20
0
        internal void LoadPost(WebServerClient client)
        {
            if (!Headers.TryGetValue("content-type", out string contentType))
            {
                return;
            }

            string contentTypeShort = contentType.BeforeFirst(';').Trim().ToLower();

            switch (contentTypeShort)
            {
            case "application/x-www-form-urlencoded": break;

            case "application/octet-stream": break;

            case "multipart/form-data": break;

            default: throw new WebServerException(WebError.UnknownContent, 0, "Unknown content type!");
            }
            int size = 0;

            {
                if (Headers.TryGetValue("content-length", out string sizeStr))
                {
                    int.TryParse(sizeStr, out size);
                }
            }

            // if (size > 20 * 1024 * 1024) throw new CaveWebException(CaveWebError.MaximumSizeExceeded, "Maximum transfer size exceeded!");
            if (Headers.ContainsKey("expect"))
            {
                if (Headers["expect"].Contains("100-continue"))
                {
                    string @continue = $"{Protocol} {(int)HttpStatusCode.Continue} {HttpStatusCode.Continue}";
                    if (Server.VerboseMode)
                    {
                        Trace.TraceInformation($"Request {ID} {@continue}");
                    }

                    client.Writer.WriteLine(@continue);
                    client.Writer.WriteLine();
                }
            }
            byte[] data = null;
            if (Headers.TryGetValue("transfer-encoding", out string transferEncoding))
            {
                switch (transferEncoding.ToLower().Trim())
                {
                case "chunked":
                    var buf = new FifoBuffer();
                    while (true)
                    {
                        string line      = client.Reader.ReadLine();
                        int    chunkSize = Convert.ToInt32(line, 16);
                        if (chunkSize == 0)
                        {
                            break;
                        }

                        byte[] chunkData = client.Reader.ReadBytes(chunkSize);
                        buf.Enqueue(chunkData);
                        client.Reader.ReadLine();
                    }
                    data = buf.ToArray();
                    break;

                default:
                    throw new WebServerException(WebError.UnknownContent, 0, string.Format("Unknown transfer encoding {0}", transferEncoding));
                }
            }
            switch (contentTypeShort)
            {
            case "application/x-www-form-urlencoded":
                if (data != null)
                {
                    DecodeUrl(Encoding.ASCII.GetString(data).Replace('+', ' '), true);
                }
                else
                {
                    DecodeUrl(Encoding.ASCII.GetString(client.Reader.ReadBytes(size)).Replace('+', ' '), true);
                }
                break;

            case "application/octet-stream":
                if (data != null)
                {
                    SetPostData(data);
                }
                else
                {
                    SetPostData(client.Reader.ReadBytes(size));
                }
                break;

            case "multipart/form-data":
                if (data != null)
                {
                    DecodeMultiPartFormData(contentType, new DataReader(new MemoryStream(data), newLineMode: NewLineMode.CRLF));
                }
                else
                {
                    DecodeMultiPartFormData(contentType, client.Reader);
                }
                break;

            default: throw new WebServerException(WebError.UnknownContent, 0, "Unknown content type!");
            }
        }
Exemplo n.º 21
0
        public void EmptyFifoReturnIsEmpty()
        {
            var fifo = new FifoBuffer <KeyboardEvent>(5);

            Assert.IsTrue(fifo.IsEmpty());
        }