Example #1
0
        public AudioCodec(AudioFormat format, int bitrate, short frameSize, byte complexity)
        {
            if (format == null)
                throw new ArgumentNullException ("format");

            this.settings = new AudioCodecArgs (format, bitrate, frameSize, complexity);
        }
Example #2
0
        public AudioCodec(AudioCodecArgs args)
        {
            if (args == null)
                throw new ArgumentNullException ("args");

            this.settings = args;
        }
Example #3
0
        public AudioSource Create(string name, IUserInfo owner, AudioCodecArgs audioArgs)
        {
            if (name == null)
                throw new ArgumentNullException ("name");
            if (owner == null)
                throw new ArgumentNullException ("owner");
            if (audioArgs == null)
                throw new ArgumentNullException ("audioArgs");

            if (OwnedSources.Contains (owner.UserId))
            {
                if (OwnedSources[owner.UserId].Any (s => s.Name == name))
                    throw new ArgumentException ("Duplicate source name", "name");
            }

            int id = 1;
            if (Sources.Keys.Any())
                id = Sources.Keys.Max() + 1;

            var source = new AudioSource (name, id, owner.UserId, audioArgs);

            Sources.Add (source.Id, source);
            OwnedSources.Add (owner.UserId, source);

            return source;
        }
Example #4
0
 public static void AssertAreEqual(AudioCodecArgs expected, AudioCodecArgs actual)
 {
     Assert.AreEqual(expected.WaveEncoding, actual.WaveEncoding);
     Assert.AreEqual(expected.Channels, actual.Channels);
     Assert.AreEqual(expected.BitsPerSample, actual.BitsPerSample);
     Assert.AreEqual(expected.Bitrate, actual.Bitrate);
     Assert.AreEqual(expected.Complexity, actual.Complexity);
     Assert.AreEqual(expected.FrameSize, actual.FrameSize);
     Assert.AreEqual(expected.SampleRate, actual.SampleRate);
 }
Example #5
0
 public static void AssertAreEqual(AudioCodecArgs expected, AudioCodecArgs actual)
 {
     Assert.AreEqual (expected.WaveEncoding, actual.WaveEncoding);
     Assert.AreEqual (expected.Channels, actual.Channels);
     Assert.AreEqual (expected.BitsPerSample, actual.BitsPerSample);
     Assert.AreEqual (expected.Bitrate, actual.Bitrate);
     Assert.AreEqual (expected.Complexity, actual.Complexity);
     Assert.AreEqual (expected.FrameSize, actual.FrameSize);
     Assert.AreEqual (expected.SampleRate, actual.SampleRate);
 }
Example #6
0
        public RequestSourceMessage(string name, AudioCodecArgs args)
            : this()
        {
            if (name == null)
                throw new ArgumentNullException ("name");
            if (args == null)
                throw new ArgumentNullException ("args");

            this.Name = name;
            AudioSettings = args;
        }
Example #7
0
        public void Ctor()
        {
            var args = new AudioCodecArgs(Format, Bitrate, FrameSize, Complexity);

            Assert.AreEqual(Format.WaveEncoding, args.WaveEncoding);
            Assert.AreEqual(Format.Channels, args.Channels);
            Assert.AreEqual(Format.BitsPerSample, args.BitsPerSample);
            Assert.AreEqual(Bitrate, args.Bitrate);
            Assert.AreEqual(Format.SampleRate, args.SampleRate);
            Assert.AreEqual(FrameSize, args.FrameSize);
            Assert.AreEqual(Complexity, args.Complexity);
        }
Example #8
0
        public RequestSourceMessage(string name, AudioCodecArgs args)
            : this()
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            this.Name     = name;
            AudioSettings = args;
        }
        public void RequestSourceBelowMinBitrate()
        {
            permissions.EnablePermissions(user.UserId, PermissionName.RequestSource);

            var audioArgs = new AudioCodecArgs(AudioFormat.Mono16bitLPCM, 1, AudioSourceTests.FrameSize, 10);

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (server, new RequestSourceMessage("Name", audioArgs)));

            var result = client.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.Succeeded, result.SourceResult);
            Assert.AreEqual("Name", result.SourceName);
            Assert.AreEqual("Name", result.Source.Name);

            audioArgs.Bitrate = minBitrate;
            AudioCodecArgsTests.AssertAreEqual(audioArgs, result.Source.CodecSettings);

            client.AssertNoMessage();
        }
        public AudioSource GetSourceFromRequest(MockServerConnection serverConnection, ConnectionBuffer clientConnection)
        {
            permissions.EnablePermissions(userManager.GetUser(serverConnection).UserId, PermissionName.RequestSource);

            var audioArgs = new AudioCodecArgs(AudioFormat.Mono16bitLPCM, 64000, AudioSourceTests.FrameSize, 10);

            handler.RequestSourceMessage(new MessageEventArgs <RequestSourceMessage> (serverConnection,
                                                                                      new RequestSourceMessage("Name", audioArgs)));

            var result = clientConnection.DequeueAndAssertMessage <SourceResultMessage>();

            Assert.AreEqual(SourceResult.Succeeded, result.SourceResult);
            Assert.AreEqual("Name", result.SourceName);
            Assert.AreEqual("Name", result.Source.Name);

            AudioCodecArgsTests.AssertAreEqual(audioArgs, result.Source.CodecSettings);

            clientConnection.AssertNoMessage();

            return(result.Source);
        }
Example #11
0
        public void SerializeDeserialize()
        {
            var stream = new MemoryStream(new byte[20480], true);
            var writer = new StreamValueWriter(stream);
            var reader = new StreamValueReader(stream);

            var args = new AudioCodecArgs(Format, Bitrate, FrameSize, Complexity);

            args.Serialize(null, writer);
            long length = stream.Position;

            stream.Position = 0;

            args = new AudioCodecArgs(null, reader);
            Assert.AreEqual(length, stream.Position);
            Assert.AreEqual(Format.WaveEncoding, args.WaveEncoding);
            Assert.AreEqual(Format.Channels, args.Channels);
            Assert.AreEqual(Format.BitsPerSample, args.BitsPerSample);
            Assert.AreEqual(Bitrate, args.Bitrate);
            Assert.AreEqual(Format.SampleRate, args.SampleRate);
            Assert.AreEqual(FrameSize, args.FrameSize);
            Assert.AreEqual(Complexity, args.Complexity);
        }
Example #12
0
        public AudioSource Create(string name, IUserInfo owner, AudioCodecArgs audioArgs)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (audioArgs == null)
            {
                throw new ArgumentNullException("audioArgs");
            }

            if (OwnedSources.Contains(owner.UserId))
            {
                if (OwnedSources[owner.UserId].Any(s => s.Name == name))
                {
                    throw new ArgumentException("Duplicate source name", "name");
                }
            }

            int id = 1;

            if (Sources.Keys.Any())
            {
                id = Sources.Keys.Max() + 1;
            }

            var source = new AudioSource(name, id, owner.UserId, audioArgs);

            Sources.Add(source.Id, source);
            OwnedSources.Add(owner.UserId, source);

            return(source);
        }
Example #13
0
        public void SerializeDeserialize()
        {
            var stream = new MemoryStream(new byte[20480], true);
            var writer = new StreamValueWriter (stream);
            var reader = new StreamValueReader (stream);

            var args = new AudioCodecArgs (Format, Bitrate, FrameSize, Complexity);

            args.Serialize (null, writer);
            long length = stream.Position;
            stream.Position = 0;

            args = new AudioCodecArgs (null, reader);
            Assert.AreEqual (length, stream.Position);
            Assert.AreEqual (Format.WaveEncoding, args.WaveEncoding);
            Assert.AreEqual (Format.Channels, args.Channels);
            Assert.AreEqual (Format.BitsPerSample, args.BitsPerSample);
            Assert.AreEqual (Bitrate, args.Bitrate);
            Assert.AreEqual (Format.SampleRate, args.SampleRate);
            Assert.AreEqual (FrameSize, args.FrameSize);
            Assert.AreEqual (Complexity, args.Complexity);
        }
Example #14
0
 public void Ctor()
 {
     var args = new AudioCodecArgs (Format, Bitrate, FrameSize, Complexity);
     Assert.AreEqual (Format.WaveEncoding, args.WaveEncoding);
     Assert.AreEqual (Format.Channels, args.Channels);
     Assert.AreEqual (Format.BitsPerSample, args.BitsPerSample);
     Assert.AreEqual (Bitrate, args.Bitrate);
     Assert.AreEqual (Format.SampleRate, args.SampleRate);
     Assert.AreEqual (FrameSize, args.FrameSize);
     Assert.AreEqual (Complexity, args.Complexity);
 }
Example #15
0
 public override void ReadPayload(ISerializationContext context, IValueReader reader)
 {
     this.Name = reader.ReadString();
     AudioSettings = new AudioCodecArgs (context, reader);
 }
Example #16
0
        internal void RequestSourceMessage(MessageEventArgs <RequestSourceMessage> e)
        {
            var request = (RequestSourceMessage)e.Message;

            SourceResult result = SourceResult.FailedUnknown;

            IUserInfo requestingUser = context.Users[e.Connection];

            if (requestingUser == null)
            {
                return;
            }

            if (!context.GetPermission(PermissionName.RequestSource, requestingUser))
            {
                result = SourceResult.FailedPermissions;
            }

            if (String.IsNullOrEmpty(request.Name) ||
                AudioCodecArgs.IsInvalidBitrate(request.AudioSettings.Bitrate) ||
                AudioCodecArgs.IsInvalidComplexity(request.AudioSettings.Complexity) ||
                AudioCodecArgs.IsInvalidFrequency(request.AudioSettings.SampleRate) ||
                AudioCodecArgs.IsInvalidFrameSize(request.AudioSettings.SampleRate, request.AudioSettings.Channels, request.AudioSettings.FrameSize))
            {
                result = SourceResult.FailedInvalidArguments;
            }

            AudioSource source = null;

            try
            {
                if (result == SourceResult.FailedUnknown)
                {
                    int bitrate = context.Settings.DefaultAudioBitrate;
                    if (request.AudioSettings.Bitrate != 0)
                    {
                        bitrate = request.AudioSettings.Bitrate.Trim(context.Settings.MinimumAudioBitrate, context.Settings.MaximumAudioBitrate);
                    }

                    if (manager.IsSourceNameTaken(requestingUser, request.Name))
                    {
                        result = SourceResult.FailedDuplicateSourceName;
                    }
                    else
                    {
                        source = manager.Create(request.Name, requestingUser,
                                                new AudioCodecArgs(request.AudioSettings)
                        {
                            Bitrate = bitrate
                        });
                        result = SourceResult.Succeeded;
                    }
                }
            }
            catch (OverflowException)
            {
                result = SourceResult.FailedLimit;
            }
            finally
            {
                e.Connection.SendAsync(new SourceResultMessage(request.Name, result, source));
                if (result == SourceResult.Succeeded)
                {
                    foreach (IConnection connection in context.Connections)
                    {
                        if (connection == e.Connection)
                        {
                            continue;
                        }

                        connection.SendAsync(new SourceResultMessage(request.Name, SourceResult.NewSource, source));
                    }
                }
            }
        }
Example #17
0
 public override void ReadPayload(ISerializationContext context, IValueReader reader)
 {
     this.Name     = reader.ReadString();
     AudioSettings = new AudioCodecArgs(context, reader);
 }
        public AudioSource GetSourceFromRequest(MockServerConnection serverConnection, ConnectionBuffer clientConnection)
        {
            permissions.EnablePermissions (userManager.GetUser (serverConnection).UserId,	PermissionName.RequestSource);

            var audioArgs = new AudioCodecArgs (AudioFormat.Mono16bitLPCM, 64000, AudioSourceTests.FrameSize, 10);
            handler.RequestSourceMessage (new MessageEventArgs<RequestSourceMessage> (serverConnection,
                new RequestSourceMessage ("Name", audioArgs)));

            var result = clientConnection.DequeueAndAssertMessage<SourceResultMessage>();
            Assert.AreEqual (SourceResult.Succeeded, result.SourceResult);
            Assert.AreEqual ("Name", result.SourceName);
            Assert.AreEqual ("Name", result.Source.Name);

            AudioCodecArgsTests.AssertAreEqual (audioArgs, result.Source.CodecSettings);

            clientConnection.AssertNoMessage();

            return result.Source;
        }
        public void RequestSourceExceedMaxBitrate()
        {
            permissions.EnablePermissions (user.UserId, PermissionName.RequestSource);

            var audioArgs = new AudioCodecArgs (AudioFormat.Mono16bitLPCM, 200000, AudioSourceTests.FrameSize, 10);
            handler.RequestSourceMessage (new MessageEventArgs<RequestSourceMessage> (server, new RequestSourceMessage ("Name", audioArgs)));

            var result = client.DequeueAndAssertMessage<SourceResultMessage>();
            Assert.AreEqual (SourceResult.Succeeded, result.SourceResult);
            Assert.AreEqual ("Name", result.SourceName);
            Assert.AreEqual ("Name", result.Source.Name);

            audioArgs.Bitrate = maxBitrate;
            AudioCodecArgsTests.AssertAreEqual (audioArgs, result.Source.CodecSettings);

            client.AssertNoMessage();
        }