public void Push(EncodedAudio frame) { Log.Trace("Buffering encoded audio frame {0}", frame.Sequence); _heap.Add(frame); Interlocked.Increment(ref _count); if (_heap.Count > 30) { Log.Warn(Log.PossibleBugMessage(string.Format("Encoded audio heap is getting very large ({0} items)", _heap.Count), "59EE0102-FF75-467A-A50D-00BF670E9B8C")); } }
/// <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); } }
public void Push(EncodedAudio frame) { _buffer.Push(frame); }