Exemple #1
0
        public int Write(float[] buffer, int offset, int count)
        {
            //Write as much as possible. That's either the amount passed in, or however much space is left in the buffer
            var writeCount = Math.Min(_samples.Capacity - _samples.EstimatedUnreadCount, count);

            if (_samples.Write(new ArraySegment <float>(buffer, offset, writeCount)))
            {
                return(writeCount);
            }

            return(0);
        }
Exemple #2
0
        public void Send(float[] frame)
        {
            if (!_inputQueue.Write(frame))
            {
                Log.Warn("Failed to write microphone samples into input queue");

                //Increment a counter to inform the pipeline that a frame was lost
                Interlocked.Increment(ref _droppedFrames);

                //We failed to process this frame, recycle the buffer
                _inputBufferSource.Put(frame);
            }
            _threadEvent.Set();
        }
Exemple #3
0
        internal static void SendLogMessage(string message, LogLevel level)
        {
#if NCRUNCH
            Console.WriteLine(message);
#else
            var msg = new LogMessage(message, level);

            if (_main == Thread.CurrentThread)
            {
                msg.Log();
            }
            else
            {
                LogsFromOtherThreads.Write(msg);
            }
#endif
        }
Exemple #4
0
        /// <summary>
        /// Push a new encoded audio packet
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="now"></param>
        /// <returns>How delayed this packet is from when it should arrive</returns>
        public float Push(VoicePacket packet, DateTime now)
        {
            Log.Trace("Received frame {0} from network", packet.SequenceNumber);

            // copy the data out of the frame, as the network thread will re-use the array
            var array = _bytePool.Get();
            var frame = packet.EncodedAudioFrame.CopyTo(array);

            // queue the frame onto the transfer buffer
            var copy = new EncodedAudio(packet.SequenceNumber, frame);

            if (!_inputBuffer.Write(copy))
            {
                Log.Warn("Failed to write an encoded audio packet into the input transfer buffer");
            }

            //Copy across the stream metadata
            //N.b. doing this means the metadata is surfaced <buffer length> too early
            Priority   = packet.Priority;
            Positional = packet.Positional;

            // calculate how late the packet is
            if (!_firstFrameArrival.HasValue)
            {
                _firstFrameArrival = now;
                _firstFrameSeq     = packet.SequenceNumber;

                return(0);
            }
            else
            {
                var expectedTime = _firstFrameArrival.Value + TimeSpan.FromTicks(_frameDuration.Ticks * (packet.SequenceNumber - _firstFrameSeq));
                var delay        = now - expectedTime;

                return((float)delay.TotalSeconds);
            }
        }
Exemple #5
0
 void IClient.SendUnreliable(ArraySegment <byte> packet)
 {
     _queuedUnreliableTransmissions.Write(packet);
 }