private void ReceiveAudio(AudioPacket packet, DhtClient client) { if (!RemoteVoices.ContainsKey(client.UserID)) { RemoteVoices[client.UserID] = new RemoteVoice(); } RemoteVoice user = RemoteVoices[client.UserID]; if (!user.Streams.ContainsKey(client.RoutingID)) { user.Streams[client.RoutingID] = new PlayAudio(this, packet.FrameSize, user); Players.SafeAdd(user.Streams[client.RoutingID]); } PlayAudio stream = user.Streams[client.RoutingID]; // reset if user changed quality setting if (stream.FrameSize != packet.FrameSize) { stream.Dispose(); user.Streams[client.RoutingID] = new PlayAudio(this, packet.FrameSize, user); Players.SafeAdd(user.Streams[client.RoutingID]); stream = user.Streams[client.RoutingID]; } StartAudioThread(false); stream.Receive_AudioData(packet.Audio); UpdateVolume(); }
public static AudioPacket Decode(G2Header root) { AudioPacket packet = new AudioPacket(); if (G2Protocol.ReadPayload(root)) { packet.Audio = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); } G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) { continue; } switch (child.Name) { case Packet_FrameSize: packet.FrameSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } return(packet); }
public static AudioPacket Decode(G2Header root) { AudioPacket packet = new AudioPacket(); if (G2Protocol.ReadPayload(root)) packet.Audio = Utilities.ExtractBytes(root.Data, root.PayloadPos, root.PayloadSize); G2Protocol.ResetPacket(root); G2Header child = new G2Header(root.Data); while (G2Protocol.ReadNextChild(root, child) == G2ReadResult.PACKET_GOOD) { if (!G2Protocol.ReadPayload(child)) continue; switch (child.Name) { case Packet_FrameSize: packet.FrameSize = CompactNum.ToInt32(child.Data, child.PayloadPos, child.PayloadSize); break; } } return packet; }
void Comm_ReceiveData(DhtClient client, byte[] data) { G2Header root = new G2Header(data); if (G2Protocol.ReadPacket(root)) { switch (root.Name) { case VoicePacket.Audio: ReceiveAudio(AudioPacket.Decode(root), client); break; } } }
public void Recorder_AudioData(byte[] audio, int maxVolume, int frameSize) { // IM/Chat services keep these connections alive // send audio data, rudp to all users in hearing, tag with audio quality info AudioPacket packet = new AudioPacket() { Audio = audio, FrameSize = frameSize }; int[] windows = new int[0]; // for each user in the speaking foreach (ulong user in SpeakingTo.Keys) { foreach (int window in SpeakingTo[user]) { if (MaxVolume.ContainsKey(window) && maxVolume > MaxVolume[window].Param2) { MaxVolume[window].Param2 = maxVolume; } } foreach (RudpSession session in Network.RudpControl.GetActiveSessions(user)) { session.SendUnreliable(ServiceID, 0, packet); } //Core.Network.LightComm.SendUnreliable(session.Comm.PrimaryAddress, ServiceID, 0, packet); //foreach (RudpSession session in Network.RudpControl.GetActiveSessions(user)) // session.SendData(ServiceID, 0, packet, true); } UpdateVolume(); }
private void ReceiveAudio(AudioPacket packet, DhtClient client) { if (!RemoteVoices.ContainsKey(client.UserID)) RemoteVoices[client.UserID] = new RemoteVoice(); RemoteVoice user = RemoteVoices[client.UserID]; if (!user.Streams.ContainsKey(client.RoutingID)) { user.Streams[client.RoutingID] = new PlayAudio(this, packet.FrameSize, user); Players.SafeAdd(user.Streams[client.RoutingID]); } PlayAudio stream = user.Streams[client.RoutingID]; // reset if user changed quality setting if (stream.FrameSize != packet.FrameSize) { stream.Dispose(); user.Streams[client.RoutingID] = new PlayAudio(this, packet.FrameSize, user); Players.SafeAdd(user.Streams[client.RoutingID]); stream = user.Streams[client.RoutingID]; } StartAudioThread(false); stream.Receive_AudioData(packet.Audio); UpdateVolume(); }
public void Recorder_AudioData(byte[] audio, int maxVolume, int frameSize) { // IM/Chat services keep these connections alive // send audio data, rudp to all users in hearing, tag with audio quality info AudioPacket packet = new AudioPacket() { Audio = audio, FrameSize = frameSize }; int[] windows = new int[0]; // for each user in the speaking foreach (ulong user in SpeakingTo.Keys) { foreach (int window in SpeakingTo[user]) if (MaxVolume.ContainsKey(window) && maxVolume > MaxVolume[window].Param2) MaxVolume[window].Param2 = maxVolume; foreach (RudpSession session in Network.RudpControl.GetActiveSessions(user)) session.SendUnreliable(ServiceID, 0, packet); //Core.Network.LightComm.SendUnreliable(session.Comm.PrimaryAddress, ServiceID, 0, packet); //foreach (RudpSession session in Network.RudpControl.GetActiveSessions(user)) // session.SendData(ServiceID, 0, packet, true); } UpdateVolume(); }