コード例 #1
0
        PAStreamCallbackResult Callback(IntPtr input, IntPtr output, uint frameCount, ref PAStreamCallbackTimeInfo timeInfo, PAStreamCallbackFlags statusFlags, IntPtr userData)
        {
            int byteCount = (int)frameCount * Configuration.BytesPerTick;

            lock (m_SyncRoot)
            {
                // fill output buffer
                while (m_StreamData.Length < byteCount)
                {
                    if (m_Buffers.Count > 0)
                    {
                        IAudioData audioData = m_Buffers.Dequeue();
                        if (Volume != 1)
                        {
                            audioData = audioData.ChangeVolume(Volume);
                        }

                        m_StreamData.Enqueue(audioData.Data);
                        continue;
                    }
                    int silenceBytes = byteCount - m_StreamData.Length;
                    m_BufferUnderflowCount++;
                    m_BytesQueued += silenceBytes;
                    m_StreamData.Enqueue(new byte[silenceBytes]);
                }
                m_StreamData.Dequeue(byteCount, output);
                m_BytesPassed    += m_InProgressBytes;
                m_InProgressBytes = byteCount;
                return(m_Exit ? PAStreamCallbackResult.Complete : PAStreamCallbackResult.Continue);
            }
        }
コード例 #2
0
        PAStreamCallbackResult Callback(IntPtr input, IntPtr output, uint frameCount, ref PAStreamCallbackTimeInfo timeInfo, PAStreamCallbackFlags statusFlags, IntPtr userData)
        {
            var byteCount = (int)frameCount * Configuration.BytesPerTick;

            lock (syncRoot)
            {
                // fill output buffer
                while (streamData.Length < byteCount)
                {
                    if (buffers.Count > 0)
                    {
                        var audioData = buffers.Dequeue();
                        if (Volume != 1)
                        {
                            audioData = audioData.ChangeVolume(Volume);
                        }

                        streamData.Enqueue(audioData.Data, true);
                        continue;
                    }
                    var silenceBytes = byteCount - streamData.Length;
                    bufferUnderflowCount++;
                    bytesQueued += silenceBytes;
                    streamData.Enqueue(new byte[silenceBytes], true);
                }
                streamData.Dequeue(byteCount, output);
                bytesPassed    += inProgressBytes;
                inProgressBytes = byteCount;
                return(exit ? PAStreamCallbackResult.Complete : PAStreamCallbackResult.Continue);
            }
        }
コード例 #3
0
ファイル: Mpg123.cs プロジェクト: elfen20/cave-media
        /// <summary>
        /// buffers a frame into mpg123.
        /// </summary>
        void BufferFrame()
        {
            for (int i = 0; i < 1;)
            {
                AudioFrame frame = m_Source.GetNextFrame();
                if (frame == null)
                {
                    break;
                }

                Decoding?.Invoke(this, new AudioFrameEventArgs(frame));
                if (frame.IsAudio)
                {
                    m_DecodeFifoBuffer.Enqueue(frame.Data);
                    i++;
                }
            }
        }
コード例 #4
0
ファイル: ID3v2Builder.cs プロジェクト: elfen20/cave-media
        /// <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());
        }
コード例 #5
0
 internal void Add(byte[] buffer)
 {
     m_Buffer.Enqueue(buffer);
 }
コード例 #6
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!");
            }
        }