Exemplo n.º 1
0
 internal LocalVoiceAudio(VoiceClient voiceClient, IEncoderDataFlow <T> encoder, byte id, VoiceInfo voiceInfo, int channelId)
     : base(voiceClient, encoder, id, voiceInfo, channelId,
            voiceInfo.SamplingRate != 0 ? voiceInfo.FrameSize * voiceInfo.SourceSamplingRate / voiceInfo.SamplingRate : voiceInfo.FrameSize
            )
 {
     if (this.encoder == null)
     {
         this.encoder = VoiceCodec.CreateDefaultEncoder(voiceInfo, this);
     }
     this.channels             = voiceInfo.Channels;
     this.sourceSamplingRateHz = voiceInfo.SourceSamplingRate;
     if (this.sourceSamplingRateHz != voiceInfo.SamplingRate)
     {
         this.resampleSource = true;
         this.voiceClient.frontend.LogWarning("[PV] Local voice #" + this.id + " audio source frequency " + this.sourceSamplingRateHz + " and encoder sampling rate " + voiceInfo.SamplingRate + " do not match. Resampling will occur before encoding.");
     }
 }
        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.transport.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, this.transport);
                    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.transport.LogWarning("[PV] Info duplicate for voice #" + voiceId + " of player " + this.playerStr(playerId) + " at channel " + this.channelStr(channelId));
                    }
                }
            }
        }