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); }
public AudioCodec(AudioCodecArgs args) { if (args == null) throw new ArgumentNullException ("args"); this.settings = args; }
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; }
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); }
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); }
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 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); }
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); }
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); }
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); }
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); }
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); }
public override void ReadPayload(ISerializationContext context, IValueReader reader) { this.Name = reader.ReadString(); AudioSettings = new AudioCodecArgs (context, reader); }
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)); } } } }
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(); }