Exemplo n.º 1
0
 protected override void OnAudio(Guid IGNOREDBYSERVER, Audio.Codecs.CodecID Codec, byte[] data, int dataLen)
 {
     if (state.User != null)
     {
         EventSink.OnAudio(state, state.User.ID, Codec, data, dataLen);
     }
 }
Exemplo n.º 2
0
 public AudioDataEventArgs(Guid userID, Audio.Codecs.CodecID codec, byte[] data, int dataLen)
 {
     UserID  = userID;
     Codec   = codec;
     Data    = data;
     DataLen = dataLen;
 }
Exemplo n.º 3
0
 internal static void InvokeOnAudio(object sender, Guid userID, Audio.Codecs.CodecID codec, byte[] data, int dataLen)
 {
     if (OnAudioData != null)
     {
         OnAudioData(sender, new AudioDataEventArgs(userID, codec, data, dataLen));
     }
 }
Exemplo n.º 4
0
        protected void Handle_OnAudio(IEnumerable <byte> payload)
        {
            if (payload.Count() < 1)
            {
                throw new ArgumentException("Invalid AudioData length");
            }

            bool hasGuid = payload.First() != 0;
            int  guidLen = hasGuid ? 17 : 1;

            if (payload.Count() < guidLen + 1)
            {
                throw new ArgumentException("Invalid AudioData length");
            }

            Guid userID;

            if (hasGuid)
            {
                userID = new Guid(payload.Skip(1).Take(16).ToArray());
            }
            else
            {
                userID = Guid.Empty;
            }

            Audio.Codecs.CodecID Codec = (Audio.Codecs.CodecID)payload.Skip(guidLen).First();
            OnAudio(userID, Codec, payload.Skip(guidLen + 1).ToArray(), payload.Count() - guidLen - 1);
        }
Exemplo n.º 5
0
        private void HandleAudio(Guid userID, Audio.Codecs.CodecID codecid, byte[] encoded)
        {
            if (isDisposed)
            {
                return;
            }

            var player = GetOrCreateUserPlayer(userID);

            player.Player.HandleAudio(codecid, encoded);
        }
Exemplo n.º 6
0
 internal static void OnAudio(IFeenPhoneNetstate state, Guid userID, Audio.Codecs.CodecID Codec, byte[] data, int dataLen)
 {
     foreach (var feen in AllFeens)
     {
         if (feen != state.Notifier && state.User != null)
         {
             feen.OnAudio(userID, Codec, data, dataLen);
         }
     }
     if (ServerHost.LocalClient != null && ServerHost.LocalClient != state)
     {
         ServerHost.LocalClient.Notifier.OnAudio(userID, Codec, data, dataLen);
     }
 }
Exemplo n.º 7
0
        internal static void WriteAudioData(IPacketWriter Writer, Guid userID, Audio.Codecs.CodecID Codec, byte[] AudioData, int AudioDataLen)
        {
            using (var buffer = FeenPacketBuffer.Acquire())
            {
                buffer.Write(PacketID.Audio);
                buffer.WriteLength(AudioDataLen + (userID == Guid.Empty ? 1 : 17) + 1);
                if (userID == Guid.Empty)
                {
                    buffer.Write(false);
                }
                else
                {
                    buffer.Write(true);
                    buffer.Write(userID.ToByteArray());
                }
                buffer.Write(Codec);
                buffer.Write(AudioData, AudioDataLen);

                if (Writer != null)
                {
                    Writer.Write(buffer);
                }
            }
        }
Exemplo n.º 8
0
 internal void Write(Audio.Codecs.CodecID Codec)
 {
     Write((byte)Codec);
 }
Exemplo n.º 9
0
 internal abstract void SendAudio(Audio.Codecs.CodecID codec, byte[] data, int dataLen);
Exemplo n.º 10
0
 internal override void SendAudio(Audio.Codecs.CodecID codec, byte[] data, int dataLen)
 {
     Server.EventSink.OnAudio(this, Guid.Empty, codec, data, dataLen);
 }
Exemplo n.º 11
0
 public void OnAudio(Guid userID, Audio.Codecs.CodecID Codec, byte[] data, int dataLen)
 {
     EventSource.InvokeOnAudio(this, userID, Codec, data, dataLen);
 }
Exemplo n.º 12
0
        public void HandleAudio(Audio.Codecs.CodecID codecid, byte[] encoded)
        {
            if (isDisposed)
            {
                return;
            }

            Audio.Codecs.INetworkChatCodec remoteCodec = Codecs.SingleOrDefault(m => m.CodecID == codecid);
            if (remoteCodec == null)
            {
                Console.WriteLine("Bad Audio Packet: Codec ID {0}", codecid);
                return;
            }
            if (codecid != LastCodec)
            {
                LastCodec = codecid;
                CodecName = remoteCodec.Name();
            }

            TimeSpan buffered  = waveOut == null ? TimeSpan.Zero : waveProvider.BufferedDuration;
            bool     isPlaying = buffered != TimeSpan.Zero;

            if (waveOut == null || waveProvider.WaveFormat != remoteCodec.RecordFormat || (!isPlaying && ShouldTryRestartOutput))
            {
                Start(remoteCodec);
            }
            else if (!isPlaying)
            {
                UnderRuns++;
            }

            if (buffered <= FrameDropThresholdMs)
            {
                byte[] decoded = remoteCodec.Decode(encoded, encoded.Length);
                int    length  = decoded.Length;

                if (!isPlaying && AudioOutWPF.shouldRampUnderruns)
                {
                    InputResampler.RampPCM16Volume(ref decoded, length, InputResampler.RampDirection.ZeroToFull);
                }

                var volume = LevelManager.LevelScalar;
                if (volume < 1.0f)
                {
                    InputResampler.ScalePCM16VolumeDb(ref decoded, length, volume);
                }

                if (length > 0 && ShouldDropSilence)
                {
                    int dropped = DropSilence(silenceThreshhold, ref decoded, ref length);
                    DroppedSilence += dropped;
                }
                else if (ShouldAddSilence && length > 5)
                {
                    bool silent = true;
                    for (int i = 0; i < 5; i += 2)
                    {
                        if (decoded[i + 1] != 0 || decoded[i] > addSilenceThreshold)
                        {
                            silent = false;
                            break;
                        }
                    }
                    if (silent)
                    {
                        var  silenceBytes = length / 4;
                        var  silence      = new byte[silenceBytes];
                        byte silenceLevel = (byte)(addSilenceThreshold / 2);
                        for (int i = 0; i < silenceBytes - 1; i += 2)
                        {
                            silence[i + 1] = 0;
                            silence[i]     = silenceLevel;
                        }
                        waveProvider.AddSamples(silence, 0, silenceBytes);
                        AddedSilence += length;
                    }
                }

                waveProvider.AddSamples(decoded, 0, length);
            }
            else
            {
                DroppedPackets++;
            }

            if (shouldUpdateDuration)
            {
                BufferedDuration     = buffered;
                shouldUpdateDuration = false;
            }
            LastReceived = DateTime.UtcNow;
        }
 public void OnAudio(Guid userID, Audio.Codecs.CodecID Codec, byte[] data, int dataLen)
 {
     Packet.WriteAudioData(Writer, userID, Codec, data, dataLen);
 }
Exemplo n.º 14
0
 internal override void SendAudio(Audio.Codecs.CodecID codec, byte[] data, int dataLen)
 {
     Packet.WriteAudioData(Writer, Guid.Empty, codec, data, dataLen);
 }
Exemplo n.º 15
0
 public void OnAudio(Guid userID, Audio.Codecs.CodecID Codec, byte[] data, int dataLen)
 {
     // nothing for telnet
 }
Exemplo n.º 16
0
 protected abstract void OnAudio(Guid userID, Audio.Codecs.CodecID Codec, byte[] data, int dataLen);