public void SendVoiceRemove(LocalVoice voice, int channelId, int targetPlayerId)
        {
            object content = protocol.buildVoiceRemoveMessage(voice);
            var    sendOpt = new SendOptions()
            {
                Reliability = true,
                Channel     = photonChannelForCodec(voice.Info.Codec),
            };

            var opt = new RaiseEventOptions();

            if (targetPlayerId == -1)
            {
                opt.TargetActors = new int[] { this.LocalPlayer.ActorNumber };
            }
            else if (targetPlayerId != 0)
            {
                opt.TargetActors = new int[] { targetPlayerId };
            }
            if (voice.DebugEchoMode)
            {
                opt.Receivers = ReceiverGroup.All;
            }
            lock (sendLock)
            {
                this.OpRaiseEvent(VoiceEvent.Code, content, opt, sendOpt);
            }
        }
Ejemplo n.º 2
0
 public override void Service(LocalVoice localVoice)
 {
     while (this.reader.Read(this.buffer))
     {
         ((LocalVoiceFramed <T>)localVoice).PushData(this.buffer);
     }
 }
 internal object[] buildVoiceRemoveMessage(LocalVoice v)
 {
     byte[]   ids     = new byte[] { v.id };
     object[] content = new object[] { (byte)0, EventSubcode.VoiceRemove, ids };
     this.transport.LogInfo(v.LogPrefix + " remove sent");
     return(content);
 }
Ejemplo n.º 4
0
 /// <summary>Do the actual data read/push.</summary>
 /// <param name="localVoice">LocalVoice instance to push data to. Must be a LocalVoiceFramed<T> of same T.</param>
 public override void Service(LocalVoice localVoice)
 {
     while (this.reader.Read(buffer))
     {
         var v   = ((LocalVoiceFramed <T>)localVoice);
         var buf = v.BufferFactory.New();
         Array.Copy(buffer, buf, buffer.Length);
         v.PushDataAsync(buf);
     }
 }
 /// <summary>
 /// Removes local voice (outgoing data stream).
 /// <param name="voice">Handler of outgoing stream to be removed.</param>
 /// </summary>
 public void RemoveLocalVoice(LocalVoice voice)
 {
     this.localVoices.Remove(voice.id);
     this.localVoicesPerChannel[voice.channelId].Remove(voice);
     if (this.transport.IsChannelJoined(voice.channelId))
     {
         this.transport.SendVoiceRemove(voice, voice.channelId, 0);
     }
     voice.Dispose();
     this.transport.LogInfo(voice.LogPrefix + " removed");
 }
Ejemplo n.º 6
0
        /// <summary>Do the actual data read/push.</summary>
        /// <param name="localVoice">LocalVoice instance to push data to. Must be a LocalVoiceFramed<T> of same T.</param>
        public override void Service(LocalVoice localVoice)
        {
            var v = ((LocalVoiceFramed <T>)localVoice);

            T[] buf = v.BufferFactory.New();
            while (this.reader.Read(buf))
            {
                v.PushDataAsync(buf);
                buf = v.BufferFactory.New();
            }
            // release unused buffer
            v.BufferFactory.Free(buf, buf.Length);
        }
        /// <summary>Do the actual data read/push.</summary>
        /// <param name="localVoice">LocalVoice instance to push data to. Must be a LocalVoiceFramed<T> of same T.</param>
        public override void Service(LocalVoice localVoice)
        {
            var v = ((LocalVoiceFramed <float>)localVoice);

            float[] buf = v.BufferFactory.New();
            while (this.reader.Read(buffer))
            {
                AudioUtil.Convert(buffer, buf, buf.Length);
                v.PushDataAsync(buf);
                buf = v.BufferFactory.New();
            }
            // release unused buffer
            v.BufferFactory.Free(buf, buf.Length);
        }
Ejemplo n.º 8
0
 public static IEncoder Create(VoiceInfo i, LocalVoice localVoice)
 {
     if (localVoice.GetType() == typeof(LocalVoiceAudioFloat))
     {
         return(new EncoderFloat(i));
     }
     else if (localVoice.GetType() == typeof(LocalVoiceAudioShort))
     {
         return(new EncoderShort(i));
     }
     else
     {
         throw new UnsupportedCodecException(i.Codec, localVoice);
     }
 }
Ejemplo n.º 9
0
        internal static IEncoder CreateDefaultEncoder(VoiceInfo info, LocalVoice localVoice)
        {
            switch (info.Codec)
            {
            case Codec.AudioOpus:
                return(OpusCodec.EncoderFactory.Create(info, localVoice));

#if PHOTON_VOICE_VIDEO_ENABLE
            case Codec.VideoVP8:
                return(new VPxCodec.Encoder(info));
#endif
            default:
                throw new UnsupportedCodecException(info.Codec, localVoice);
            }
        }
        /// <summary>Iterates through copy of all local voices list of given channel.</summary>
        public IEnumerable <LocalVoice> LocalVoicesInChannel(int channelId)
        {
            List <LocalVoice> channelVoices;

            if (this.localVoicesPerChannel.TryGetValue(channelId, out channelVoices))
            {
                var res = new LocalVoice[channelVoices.Count];
                channelVoices.CopyTo(res, 0);
                return(res);
            }
            else
            {
                return(new LocalVoice[0]);
            }
        }
Ejemplo n.º 11
0
        private LocalVoice createLocalVoice(VoiceInfo voiceInfo, int channelId, Func <byte, int, LocalVoice> voiceFactory)
        {
            var newId = getNewVoiceId();

            if (newId != 0)
            {
                LocalVoice v = voiceFactory(newId, channelId);
                if (v != null)
                {
                    addVoice(newId, channelId, v);
                    this.transport.LogInfo(v.LogPrefix + " added enc: " + v.info.ToString());
                    return(v);
                }
            }
            return(null);
        }
Ejemplo n.º 12
0
        /// <summary>Do the actual data read/push.</summary>
        /// <param name="localVoice">LocalVoice instance to push data to. Must be a LocalVoiceFramed<T> of same T.</param>
        public override void Service(LocalVoice localVoice)
        {
            var v = ((LocalVoiceFramed <short>)localVoice);

            short[] buf = v.BufferFactory.New();
            while (this.reader.Read(buffer))
            {
                for (int i = 0; i < buf.Length; i++)
                {
                    buf[i] = (short)(buffer[i] * (float)short.MaxValue);
                }
                v.PushDataAsync(buf);
                buf = v.BufferFactory.New();
            }
            // release unused buffer
            v.BufferFactory.Free(buf, buf.Length);
        }
 public void SetDebugEchoMode(LocalVoice v)
 {
     if (this.State == LoadBalancing.ClientState.Joined)
     {
         if (v.DebugEchoMode)
         {
             SendVoicesInfo(new List <LocalVoice>()
             {
                 v
             }, v.channelId, this.LocalPlayer.ActorNumber);
         }
         else
         {
             SendVoiceRemove(v, v.channelId, this.LocalPlayer.ActorNumber);
         }
     }
 }
        void addVoice(byte newId, int channelId, LocalVoice v)
        {
            localVoices[newId] = v;
            List <LocalVoice> voiceList;

            if (!localVoicesPerChannel.TryGetValue(channelId, out voiceList))
            {
                voiceList = new List <LocalVoice>();
                localVoicesPerChannel[channelId] = voiceList;
            }
            voiceList.Add(v);
            if (this.transport.IsChannelJoined(channelId))
            {
                this.transport.SendVoicesInfo(new List <LocalVoice>()
                {
                    v
                }, channelId, 0);                                                          // broadcast if joined
            }
            v.InterestGroup = this.GlobalInterestGroup;
        }
Ejemplo n.º 15
0
        private LocalVoice createLocalVoice(VoiceInfo voiceInfo, int channelId, Func <byte, int, LocalVoice> voiceFactory)
        {
            if (channelId == ChannelAuto)
            {
                channelId = this.frontend.AssignChannel(voiceInfo);
            }
            var newId = getNewVoiceId();

            if (newId != 0)
            {
                LocalVoice v = voiceFactory(newId, channelId);
                if (v != null)
                {
                    addVoice(newId, channelId, v);
                    this.frontend.LogInfo(v.LogPrefix + " added enc: " + v.info.ToString());
                    return(v);
                }
            }
            return(null);
        }
        public void SendVoiceRemove(LocalVoice voice, int channelId, int targetPlayerId)
        {
            object content = voiceClient.buildVoiceRemoveMessage(voice);
            var    sendOpt = new SendOptions()
            {
                Reliability = true,
                Channel     = (byte)channelId
            };

            var opt = new LoadBalancing.RaiseEventOptions();

            if (targetPlayerId != 0)
            {
                opt.TargetActors = new int[] { targetPlayerId };
            }
            lock (sendLock)
            {
                if (voice.DebugEchoMode)
                {
                    opt.Receivers = ReceiverGroup.All;
                }
                this.OpRaiseEvent(VoiceEventCode.GetCode(channelId), content, opt, sendOpt);
            }
        }
Ejemplo n.º 17
0
        public void SendFrame(ArraySegment <byte> data, byte evNumber, byte voiceId, int channelId, LocalVoice localVoice)
        {
            object[] content = protocol.buildFrameMessage(voiceId, evNumber, data);

            var sendOpt = new SendOptions()
            {
                Reliability = localVoice.Reliable,
                Channel     = photonChannelForCodec(localVoice.info.Codec),
                Encrypt     = localVoice.Encrypt
            };

            var opt = new RaiseEventOptions();

            if (localVoice.DebugEchoMode)
            {
                opt.Receivers = ReceiverGroup.All;
            }
            opt.InterestGroup = localVoice.InterestGroup;
            lock (sendLock)
            {
                this.OpRaiseEvent(VoiceEvent.Code, content, opt, sendOpt);
            }
            this.LoadBalancingPeer.SendOutgoingCommands();
        }
Ejemplo n.º 18
0
 /// <summary>Create a new BufferReaderPushAdapter instance</summary>
 /// <param name="localVoice">LocalVoice instance to push data to.</param>
 /// <param name="reader">DataReader to read from.</param>
 public BufferReaderPushAdapterAsyncPool(LocalVoice localVoice, IDataReader <T> reader) : base(reader)
 {
 }
Ejemplo n.º 19
0
 /// <summary>Create a new BufferReaderPushAdapter instance</summary>
 /// <param name="localVoice">LocalVoice instance to push data to.</param>
 /// <param name="reader">DataReader to read from.</param>
 public BufferReaderPushAdapterAsyncPoolFloatToShort(LocalVoice localVoice, IDataReader <float> reader) : base(reader)
 {
     buffer = new float[((LocalVoiceFramed <short>)localVoice).FrameSize];
 }
 // Methods
 public override void Service(LocalVoice localVoice)
 {
 }
        }                                           // Dummy constructor

        public BufferReaderPushAdapter(LocalVoice localVoice, IDataReader <T> reader)
        {
        }
        public override void SendFrame(ArraySegment <byte> data, byte evNumber, byte voiceId, int channelId, LocalVoice localVoice)
        {
            // this uses a pooled slice, which is released within the send method (here RaiseEvent at the bottom)
            ByteArraySlice frameData = this.LoadBalancingPeer.ByteArraySlicePool.Acquire(data.Count + 2);

            frameData.Buffer[0] = voiceId;
            frameData.Buffer[1] = evNumber;
            Buffer.BlockCopy(data.Array, 0, frameData.Buffer, 2, data.Count);
            frameData.Count = data.Count + 2; // need to set the count, as we manipulated the buffer directly

            SendOptions sendOpt = new SendOptions()
            {
                Reliability = localVoice.Reliable, Channel = this.photonChannelForCodec(localVoice.info.Codec), Encrypt = localVoice.Encrypt
            };

            RaiseEventOptions opt = new RaiseEventOptions();

            if (localVoice.DebugEchoMode)
            {
                opt.Receivers = ReceiverGroup.All;
            }

            opt.InterestGroup = localVoice.InterestGroup;

            this.OpRaiseEvent(VoiceEvent.FrameCode, frameData, opt, sendOpt);

            // each voice has it's own connection? else, we could aggregate voices data in less count of datagrams
            this.LoadBalancingPeer.SendOutgoingCommands();
        }
        public void SendFrame(ArraySegment <byte> data, byte evNumber, byte voiceId, int channelId, LocalVoice localVoice)
        {
            object[] content = new object[] { voiceId, evNumber, data };

            var sendOpt = new SendOptions()
            {
                Reliability = localVoice.Reliable,
                Channel     = (byte)channelId,
                Encrypt     = localVoice.Encrypt
            };

            var opt = new LoadBalancing.RaiseEventOptions();

            if (localVoice.DebugEchoMode)
            {
                opt.Receivers = LoadBalancing.ReceiverGroup.All;
            }
            opt.InterestGroup = localVoice.Group;
            lock (sendLock)
            {
                this.OpRaiseEvent((byte)VoiceEventCode.GetCode(channelId), content, opt, sendOpt);
            }
            this.LoadBalancingPeer.SendOutgoingCommands();
        }
Ejemplo n.º 24
0
 // Methods
 public abstract void Service(LocalVoice localVoice);
        }                                                                                                                // 0x0000000180F1C030-0x0000000180F1C140

        // Methods
        public override void Service(LocalVoice localVoice)
        {
        }                                                              // 0x0000000180F1BDD0-0x0000000180F1C030
        }                                                                // Dummy constructor

        public BufferReaderPushAdapterAsyncPoolShortToFloat(LocalVoice localVoice, IDataReader <short> reader)
        {
        }                                                                                                                // 0x0000000180F1C030-0x0000000180F1C140
Ejemplo n.º 27
0
 /// <summary>Create a new BufferReaderPushAdapter instance</summary>
 /// <param name="localVoice">LocalVoice instance to push data to.</param>
 /// <param name="reader">DataReader to read from.</param>
 public BufferReaderPushAdapterAsyncPoolCopy(LocalVoice localVoice, IDataReader <T> reader) : base(reader)
 {
     buffer = new T[((LocalVoiceFramedBase)localVoice).FrameSize];
 }
        public virtual void SendFrame(ArraySegment <byte> data, FrameFlags flags, byte evNumber, byte voiceId, int channelId, int targetPlayerId, bool reliable, LocalVoice localVoice)
        {
            object[] content = protocol.buildFrameMessage(voiceId, evNumber, data, flags);

            var sendOpt = new SendOptions()
            {
                Reliability = reliable,
                Channel     = photonChannelForCodec(localVoice.Info.Codec),
                Encrypt     = localVoice.Encrypt
            };

            var opt = new RaiseEventOptions();

            if (targetPlayerId == -1)
            {
                opt.TargetActors = new int[] { this.LocalPlayer.ActorNumber };
            }
            else if (targetPlayerId != 0)
            {
                opt.TargetActors = new int[] { targetPlayerId };
            }
            if (localVoice.DebugEchoMode)
            {
                opt.Receivers = ReceiverGroup.All;
            }
            opt.InterestGroup = localVoice.InterestGroup;
            lock (sendLock)
            {
                this.OpRaiseEvent(VoiceEvent.Code, content, opt, sendOpt);
            }
            this.LoadBalancingPeer.SendOutgoingCommands();
        }
Ejemplo n.º 29
0
        }                                                                                                                                    // 0x0000000180F1D2C0-0x0000000180F1D310

        // Methods
        public override void SendFrame(ArraySegment <byte> data, FrameFlags flags, byte evNumber, byte voiceId, int channelId, int targetPlayerId, bool reliable, LocalVoice localVoice)
        {
        }                                                                                                                                                                                          // 0x0000000180F1CFB0-0x0000000180F1D2C0
Ejemplo n.º 30
0
 /// <summary>Create a new BufferReaderPushAdapter instance</summary>
 /// <param name="localVoice">LocalVoice instance to push data to.</param>
 /// <param name="reader">DataReader to read from.</param>
 public BufferReaderPushAdapter(LocalVoice localVoice, IDataReader <T> reader) : base(reader)
 {
     // any buffer will work but only of localVoice.FrameSize avoids additional processing
     buffer = new T[((LocalVoiceFramed <T>)localVoice).FrameSize];
 }