Exemplo n.º 1
0
 protected void LinkSpeaker(Speaker speaker, RemoteVoiceLink remoteVoice)
 {
     if (speaker != null)
     {
         speaker.LogLevel    = this.GlobalSpeakersLogLevel;
         speaker.PlayDelayMs = this.GlobalPlaybackDelay;
         #if UNITY_PS4 || UNITY_SHARLIN
         speaker.PlayStationUserID = this.PlayStationUserID;
         #endif
         if (speaker.OnRemoteVoiceInfo(remoteVoice))
         {
             if (speaker.Actor == null && this.Client.CurrentRoom != null)
             {
                 speaker.Actor = this.Client.CurrentRoom.GetPlayer(remoteVoice.PlayerId);
             }
             if (this.Logger.IsInfoEnabled)
             {
                 this.Logger.LogInfo("Speaker linked with remote voice {0}/{1}", remoteVoice.PlayerId, remoteVoice.VoiceId);
             }
             this.linkedSpeakers.Add(speaker);
             remoteVoice.RemoteVoiceRemoved += delegate
             {
                 this.linkedSpeakers.Remove(speaker);
             };
             if (SpeakerLinked != null)
             {
                 SpeakerLinked(speaker);
             }
         }
     }
     else if (this.Logger.IsWarningEnabled)
     {
         this.Logger.LogWarning("Speaker is null. Remote voice {0}/{1} not linked.", remoteVoice.PlayerId, remoteVoice.VoiceId);
     }
 }
Exemplo n.º 2
0
 protected void LinkSpeaker(Speaker speaker, RemoteVoiceLink remoteVoice)
 {
     if (speaker != null)
     {
         if (speaker.OnRemoteVoiceInfo(remoteVoice))
         {
             if (speaker.Actor == null && this.Client.CurrentRoom != null)
             {
                 speaker.Actor = this.Client.CurrentRoom.GetPlayer(remoteVoice.PlayerId);
             }
             if (this.Logger.IsInfoEnabled)
             {
                 this.Logger.LogInfo("Speaker linked with remote voice {0}/{1}", remoteVoice.PlayerId, remoteVoice.VoiceId);
             }
             if (SpeakerLinked != null)
             {
                 SpeakerLinked(speaker);
             }
         }
     }
     else if (this.Logger.IsWarningEnabled)
     {
         this.Logger.LogWarning("Speaker is null. Remote voice {0}/{1} not linked.", remoteVoice.PlayerId, remoteVoice.VoiceId);
     }
 }
Exemplo n.º 3
0
 internal void OnRemoteVoiceInfo(RemoteVoiceLink stream)
 {
     if (stream == null)
     {
         if (this.Logger.IsErrorEnabled)
         {
             this.Logger.LogError("RemoteVoiceLink is null, cancelled linking");
         }
         return;
     }
     if (this.IsLinked)
     {
         if (this.Logger.IsWarningEnabled)
         {
             this.Logger.LogWarning("Speaker already linked to {0}/{1}, cancelled linking to {2}/{3}",
                                    this.remoteVoiceLink.PlayerId, this.remoteVoiceLink.VoiceId, stream.PlayerId, stream.VoiceId);
         }
         return;
     }
     if (stream.Info.Channels <= 0) // early avoid possible crash due to ArgumentException in AudioClip.Create inside UnityAudioOut.Start
     {
         if (this.Logger.IsErrorEnabled)
         {
             this.Logger.LogError("Received voice info channels is not expected: {0} <= 0, cancelled linking to {1}/{2}", stream.Info.Channels,
                                  stream.PlayerId, stream.VoiceId);
         }
         return;
     }
     this.remoteVoiceLink = stream;
     this.remoteVoiceLink.RemoteVoiceRemoved += this.OnRemoteVoiceRemove;
     this.StartPlaying();
 }
Exemplo n.º 4
0
 protected void LinkSpeaker(Speaker speaker, RemoteVoiceLink remoteVoice)
 {
     if (speaker != null)
     {
         if (!speaker.IgnoreGlobalLogLevel)
         {
             speaker.LogLevel = this.GlobalSpeakersLogLevel;
         }
         speaker.SetPlaybackDelaySettings(this.globalPlaybackDelaySettings);
         #if UNITY_PS4 || UNITY_SHARLIN
         speaker.PlayStationUserID = this.PlayStationUserID;
         #endif
         if (speaker.OnRemoteVoiceInfo(remoteVoice))
         {
             if (speaker.Actor == null)
             {
                 if (this.Client.CurrentRoom == null)
                 {
                     if (this.Logger.IsErrorEnabled)
                     {
                         this.Logger.LogError("RemoteVoiceInfo event received while CurrentRoom is null");
                     }
                 }
                 else
                 {
                     Player player = this.Client.CurrentRoom.GetPlayer(remoteVoice.PlayerId);
                     if (player == null)
                     {
                         if (this.Logger.IsErrorEnabled)
                         {
                             this.Logger.LogError("RemoteVoiceInfo event for actor number {0} received while respective actor not found in the room", remoteVoice.PlayerId);
                         }
                     }
                     else
                     {
                         speaker.Actor = player;
                     }
                 }
             }
             if (this.Logger.IsInfoEnabled)
             {
                 this.Logger.LogInfo("Speaker linked with remote voice {0}/{1}", remoteVoice.PlayerId, remoteVoice.VoiceId);
             }
             this.linkedSpeakers.Add(speaker);
             remoteVoice.RemoteVoiceRemoved += delegate
             {
                 this.linkedSpeakers.Remove(speaker);
             };
             if (SpeakerLinked != null)
             {
                 SpeakerLinked(speaker);
             }
         }
     }
     else if (this.Logger.IsWarningEnabled)
     {
         this.Logger.LogWarning("Speaker is null. Remote voice {0}/{1} not linked.", remoteVoice.PlayerId, remoteVoice.VoiceId);
     }
 }
Exemplo n.º 5
0
        private void OnRemoteVoiceInfo(int channelId, int playerId, byte voiceId, VoiceInfo voiceInfo, ref RemoteVoiceOptions options)
        {
            if (this.Logger.IsInfoEnabled)
            {
                this.Logger.LogInfo("OnRemoteVoiceInfo channel {0} player {1} voice #{2} userData {3}", channelId, playerId, voiceId, voiceInfo.UserData);
            }
            bool duplicate = false;

            for (int i = 0; i < cachedRemoteVoices.Count; i++)
            {
                RemoteVoiceLink remoteVoiceLink = cachedRemoteVoices[i];
                if (remoteVoiceLink.PlayerId == playerId && remoteVoiceLink.VoiceId == voiceId)
                {
                    if (this.Logger.IsWarningEnabled)
                    {
                        this.Logger.LogWarning("Duplicate remote voice info event channel {0} player {1} voice #{2} userData {3}", channelId, playerId, voiceId, voiceInfo.UserData);
                    }
                    duplicate = true;
                    cachedRemoteVoices.RemoveAt(i);
                    break;
                }
            }
            RemoteVoiceLink remoteVoice = new RemoteVoiceLink(voiceInfo, playerId, voiceId, channelId, ref options);

            cachedRemoteVoices.Add(remoteVoice);
            if (RemoteVoiceAdded != null)
            {
                RemoteVoiceAdded(remoteVoice);
            }
            remoteVoice.RemoteVoiceRemoved += delegate
            {
                if (this.Logger.IsInfoEnabled)
                {
                    this.Logger.LogInfo("RemoteVoiceRemoved channel {0} player {1} voice #{2} userData {3}", channelId, playerId, voiceId, voiceInfo.UserData);
                }
                if (!cachedRemoteVoices.Remove(remoteVoice) && this.Logger.IsWarningEnabled)
                {
                    this.Logger.LogWarning("Cached remote voice info not removed for channel {0} player {1} voice #{2} userData {3}", channelId, playerId, voiceId, voiceInfo.UserData);
                }
            };
            if (SpeakerFactory != null)
            {
                Speaker speaker = SpeakerFactory(playerId, voiceId, voiceInfo.UserData);
                if (speaker != null && duplicate && speaker.IsLinked)
                {
                    if (this.Logger.IsWarningEnabled)
                    {
                        this.Logger.LogWarning("Overriding speaker link for channel {0} player {1} voice #{2} userData {3}", channelId, playerId, voiceId, voiceInfo.UserData);
                    }
                    speaker.OnRemoteVoiceRemove();
                }
                LinkSpeaker(speaker, remoteVoice);
            }
        }
Exemplo n.º 6
0
 private void CleanUp()
 {
     if (this.Logger.IsDebugEnabled)
     {
         this.Logger.LogDebug("CleanUp");
     }
     if (this.remoteVoiceLink != null)
     {
         this.remoteVoiceLink.RemoteVoiceRemoved -= this.OnRemoteVoiceRemove;
         this.remoteVoiceLink = null;
     }
     this.Actor = null;
 }
Exemplo n.º 7
0
 internal void OnRemoteVoiceInfo(RemoteVoiceLink stream)
 {
     if (stream == null)
     {
         if (this.Logger.IsErrorEnabled)
         {
             this.Logger.LogError("RemoteVoiceLink is null, cancelled linking");
         }
         return;
     }
     if (this.IsLinked)
     {
         if (this.Logger.IsWarningEnabled)
         {
             this.Logger.LogWarning("Speaker already linked to {0}/{1}, cancelled linking to {2}/{3}",
                                    this.remoteVoiceLink.PlayerId, this.remoteVoiceLink.VoiceId, stream.PlayerId, stream.PlayerId);
         }
         return;
     }
     this.remoteVoiceLink = stream;
     this.remoteVoiceLink.RemoteVoiceRemoved += this.OnRemoteVoiceRemove;
     this.StartPlaying();
 }
Exemplo n.º 8
0
        internal void OnRemoteVoiceRemove()
        {
            bool wasStarted = this.started;

            if (this.audioOutput != null)
            {
                this.audioOutput.Stop();
                this.started = false;
            }
            this.Actor = null;
            if (this.OnRemoteVoiceRemoveAction != null)
            {
                this.OnRemoteVoiceRemoveAction(this);
            }
            if (this.remoteVoiceLink != null)
            {
                this.remoteVoiceLink.RemoteVoiceRemoved -= this.OnRemoteVoiceRemove;
                if (wasStarted)
                {
                    this.remoteVoiceLink.FloatFrameDecoded -= this.OnAudioFrame;
                }
                this.remoteVoiceLink = null;
            }
        }