protected BaseClient([NotNull] ICommsNetworkState network) { if (network == null) { throw new ArgumentNullException("network"); } Log = Logs.Create(LogCategory.Network, GetType().Name); const int poolSize = 32; const int byteBufferSize = 1024; const int channelListSize = 8; var byteArrayPool = new ReadonlyLockedValue <Pool <byte[]> >(new Pool <byte[]>(poolSize, () => new byte[byteBufferSize])); var channelListPool = new ConcurrentPool <List <RemoteChannel> >(poolSize, () => new List <RemoteChannel>(channelListSize)); _sendQueue = new SendQueue <TPeer>(this, byteArrayPool); _serverNegotiator = new ConnectionNegotiator <TPeer>(_sendQueue, network.PlayerName, network.CodecSettings); _lossSimulator = new PacketDelaySimulator(); _events = new EventQueue(byteArrayPool, channelListPool); _peers = new SlaveClientCollection <TPeer>(_sendQueue, _serverNegotiator, _events, network.Rooms, network.PlayerName, network.CodecSettings); _peers.OnClientJoined += OnAddedClient; _peers.OnClientIntroducedP2P += OnMetClient; _voiceReceiver = new VoiceReceiver <TPeer>(_serverNegotiator, _peers, _events, network.Rooms, channelListPool); _voiceSender = new VoiceSender <TPeer>(_sendQueue, _serverNegotiator, _peers, _events, network.PlayerChannels, network.RoomChannels); _textReceiver = new TextReceiver <TPeer>(_events, network.Rooms, _peers); _textSender = new TextSender <TPeer>(_sendQueue, _serverNegotiator, _peers); }
private void ApplyChannelDeltas([NotNull] ReadonlyLockedValue <List <OpenChannel> > .Unlocker openChannels) { //Count the number of channels and check if that means that all channels are currently closing var allClosing = AreAllChannelsClosing(openChannels); using (var delta = _deltas.Lock()) { for (var i = 0; i < delta.Value.Count; i++) { ApplyChannelDelta(delta.Value[i], openChannels); //Check if this delta means that all channels are in a closing state if (!allClosing) { allClosing |= AreAllChannelsClosing(openChannels); } } delta.Value.Clear(); } var postAllClosing = AreAllChannelsClosing(openChannels); //If at some point all channels were closing, but they're not in the final state we need to increment the channelSessionId now if (!postAllClosing && allClosing) { unchecked { _channelSessionId++; } } }
public EncoderPipeline([NotNull] WaveFormat inputFormat, [NotNull] IVoiceEncoder encoder, [NotNull] ICommsNetwork net) { if (inputFormat == null) { throw new ArgumentNullException("inputFormat"); } if (encoder == null) { throw new ArgumentNullException("encoder"); } if (net == null) { throw new ArgumentNullException("net"); } _net = net; _inputFormat = inputFormat; _encoder = new ReadonlyLockedValue <IVoiceEncoder>(encoder); //Create buffers to store the encoder input (1 frame of floats) and output (twice equivalent amount of bytes) _plainSamples = new float[encoder.FrameSize]; _encodedBytes = new byte[encoder.FrameSize * sizeof(float) * 2]; //Input buffer to store raw data from microphone _input = new BufferedSampleProvider(_inputFormat, encoder.FrameSize * 2); //Resample data from microphone rate -> encoder rate _resampler = new Resampler(_input, encoder.SampleRate); //Provides encoder sized and encoder rate frames of data _output = new SampleToFrameProvider(_resampler, (uint)encoder.FrameSize); }
private static int Drop <T>([NotNull] ReadonlyLockedValue <List <T> > l) { using (var ll = l.Lock()) { var dropped = ll.Value.Count; ll.Value.Clear(); return(dropped); } }
private void ApplyChannelDelta(ChannelDelta d, ReadonlyLockedValue <List <OpenChannel> > .Unlocker openChannels) { if (d.Open) { OpenChannel(d.Type, d.Properties, d.RecipientId, d.RecipientName); } else { CloseChannel(d.Type, d.Properties, d.RecipientId); } }
public SendQueue([NotNull] IClient <TPeer> client, [NotNull] ReadonlyLockedValue <Pool <byte[]> > bytePool) { if (client == null) { throw new ArgumentNullException("client"); } if (bytePool == null) { throw new ArgumentNullException("bytePool"); } _client = client; _sendBufferPool = bytePool; }
public EventQueue([NotNull] ReadonlyLockedValue <Pool <byte[]> > byteArrayPool, [NotNull] IRecycler <List <RemoteChannel> > channelsListPool) { if (byteArrayPool == null) { throw new ArgumentNullException("byteArrayPool"); } if (channelsListPool == null) { throw new ArgumentNullException("channelsListPool"); } _byteArrayPool = byteArrayPool; _channelsListPool = channelsListPool; }
private static bool AreAllChannelsClosing([NotNull] ReadonlyLockedValue <List <OpenChannel> > .Unlocker openChannels) { if (openChannels.Value.Count == 0) { return(false); } for (var index = 0; index < openChannels.Value.Count; index++) { var c = openChannels.Value[index]; if (!c.IsClosing) { return(false); } } return(true); }