internal RemoteVoice(VoiceClient client, RemoteVoiceOptions options, int channelId, int playerId, byte voiceId, VoiceInfo info, byte lastEventNumber) { this.options = options; this.voiceClient = client; this.channelId = channelId; this.playerId = playerId; this.voiceId = voiceId; this.Info = info; this.lastEvNumber = lastEventNumber; if (this.options.Decoder == null) // init fields first for proper logging { voiceClient.frontend.LogError(LogPrefix + ": decoder is null"); disposed = true; return; } #if NETFX_CORE ThreadPool.RunAsync((x) => { decodeThread(this.options.Decoder); }); #else var t = new Thread(() => decodeThread(this.options.Decoder)); t.Name = LogPrefix + " decode"; t.Start(); #endif }
private void onVoiceInfo(int channelId, int playerId, object payload) { Dictionary <int, Dictionary <byte, RemoteVoice> > channelVoices = null; if (!this.remoteVoices.TryGetValue(channelId, out channelVoices)) { channelVoices = new Dictionary <int, Dictionary <byte, RemoteVoice> >(); this.remoteVoices[channelId] = channelVoices; } Dictionary <byte, RemoteVoice> playerVoices = null; if (!channelVoices.TryGetValue(playerId, out playerVoices)) { playerVoices = new Dictionary <byte, RemoteVoice>(); channelVoices[playerId] = playerVoices; } foreach (var el in (object[])payload) { var h = (Dictionary <byte, Object>)el; var voiceId = (byte)h[(byte)EventParam.VoiceId]; if (!playerVoices.ContainsKey(voiceId)) { var eventNumber = (byte)h[(byte)EventParam.EventNumber]; var info = VoiceInfo.CreateFromEventPayload(h); this.frontend.LogInfo("[PV] ch#" + this.channelStr(channelId) + " p#" + this.playerStr(playerId) + " v#" + voiceId + " Info received: " + info.ToString() + " ev=" + eventNumber); // create default decoder RemoteVoiceOptions options = new RemoteVoiceOptions(); // create default decoder // may be overwritten in OnRemoteVoiceInfoAction call options.Decoder = VoiceCodec.CreateDefaultDecoder(channelId, playerId, voiceId, info); if (this.OnRemoteVoiceInfoAction != null) { this.OnRemoteVoiceInfoAction(channelId, playerId, voiceId, info, ref options); } playerVoices[voiceId] = new RemoteVoice(this, options, channelId, playerId, voiceId, info, eventNumber); } else { if (!this.SuppressInfoDuplicateWarning) { this.frontend.LogWarning("[PV] Info duplicate for voice #" + voiceId + " of player " + this.playerStr(playerId) + " at channel " + this.channelStr(channelId)); } } } }
public void OnRemoteVoiceInfo(int channelId, int playerId, byte voiceId, Voice.VoiceInfo voiceInfo, ref Voice.RemoteVoiceOptions options) { options.OnDecodedFrameFloatAction += (frame) => OnAudioFrame(playerId, voiceId, frame); options.OnRemoteVoiceRemoveAction += () => OnRemoteVoiceRemove(playerId, voiceId); var key = new VoiceIdPair(playerId, voiceId); if (this.voiceSpeakers.ContainsKey(key)) { Debug.LogWarningFormat("PUNVoice: Info duplicate for voice #{0} of player {1}", voiceId, playerId); } PhotonVoiceSpeaker speaker = null; PhotonVoiceSpeaker[] speakers = GameObject.FindObjectsOfType <PhotonVoiceSpeaker>(); foreach (var s in speakers) { if (s.photonView.viewID == (int)voiceInfo.UserData) { speaker = s; break; } } if (speaker == null) { // Debug.LogWarning("PUNVoice: No PhotonVoiceMic found for info of voice #" + voiceId + " of player " + playerId); } else { this.linkVoice(playerId, voiceId, voiceInfo, speaker); } // do not expose options to user code if (this.OnRemoteVoiceInfoAction != null) { this.OnRemoteVoiceInfoAction(playerId, voiceId, voiceInfo); } }