private void HandleVoipDataPacket(VoipDataPacket packet, IConnectedPlayer player) { try { #if DEBUG Plugin.Log?.Debug($"Received a packet {player.userName} ({player.userId}). '{packet.Data?.Length}' | {packet.DataLength}"); #endif if (PlayerReceivers.TryGetValue(player.userId, out VoipReceiver receiver)) { if (receiver != null) { receiver.HandleAudioDataReceived(this, packet); } else { Plugin.Log?.Error($"VoipReceiver is null"); } } else { Plugin.Log?.Debug($"Received a Voip packet from {player.userId} ({player.userName}), but they weren't in the receiver dictionary."); } } catch (Exception ex) { Plugin.Log?.Error($"Error handling VoipDataPacket: {ex.Message}"); Plugin.Log?.Debug(ex); } finally { packet.Release(); } }
public void HandleAudioDataReceived(object sender, VoipDataPacket e) { if (!enabled) { return; } if (e.Data != null && e.DataLength > 0) { //if (e.Data.Length > e.DataLength) // Plugin.Log?.Debug($"Data length is {e.Data.Length}, expected length is {e.DataLength}"); if (e.Data.Length < e.DataLength) { Plugin.Log?.Warn($"Data length of '{e.Data.Length}' is less than the expected length of '{e.DataLength}'"); } float[] floatData = FloatAryPool.Rent(4096); int length = Decoder.Decode(e.Data, 0, e.DataLength, floatData, 0); //Plugin.Log?.Debug($"Playing fragment, length {length}x{Decoder.Channels}"); PlayVoIPFragment(floatData, length * Decoder.Channels, e.Index); FloatAryPool.Return(floatData); } else { Plugin.Log?.Warn($"HandleAudioDataReceived {(e.Data == null ? "Data was null" : $"DataLength: {e.DataLength}")}"); } }
private void VoipSender_OnAudioGenerated(object sender, VoipDataPacket e) { //Plugin.Log?.Debug($"VoipSender_OnAudioGenerated. {e.Data?.Length.ToString() ?? "NULL"} | {e.DataLength}"); Send(e); }