private void ChangeBandwitdh(int index) { if (_pc1 == null || _pc2 == null) { return; } ulong? bandwidth = bandwidthOptions.Values.ElementAt(index); RTCRtpSender sender = _pc1.GetSenders().First(); RTCRtpSendParameters parameters = sender.GetParameters(); if (bandwidth == null) { parameters.Encodings[0].maxBitrate = null; parameters.Encodings[0].minBitrate = null; } else { parameters.Encodings[0].maxBitrate = bandwidth * 1000; parameters.Encodings[0].minBitrate = bandwidth * 1000; } RTCErrorType error = sender.SetParameters(parameters); if (error != RTCErrorType.None) { Debug.LogErrorFormat("RTCRtpSender.SetParameters failed {0}", error); } }
private void ChangeBandwitdh(int index) { if (_pc1 == null || _pc2 == null) { return; } ulong? bandwidth = bandwidthOptions.Values.ElementAt(index); RTCRtpSender sender = _pc1.GetSenders().First(); RTCRtpSendParameters parameters = sender.GetParameters(); if (bandwidth == null) { parameters.encodings[0].maxBitrate = null; parameters.encodings[0].minBitrate = null; } else { parameters.encodings[0].maxBitrate = bandwidth * 1000; parameters.encodings[0].minBitrate = bandwidth * 1000; } RTCError error = sender.SetParameters(parameters); if (error.errorType != RTCErrorType.None) { Debug.LogErrorFormat("RTCRtpSender.SetParameters failed {0}", error.errorType); statsField.text += $"Failed change bandwidth to {bandwidth * 1000}{Environment.NewLine}"; bandwidthSelector.value = 0; } }
public void AddTransceiver() { var peer = new RTCPeerConnection(); var stream = Audio.CaptureStream(); var track = stream.GetAudioTracks().First(); Assert.AreEqual(0, peer.GetTransceivers().Count()); var transceiver = peer.AddTransceiver(track); Assert.NotNull(transceiver); Assert.IsNull(transceiver.CurrentDirection); RTCRtpSender sender = transceiver.Sender; Assert.NotNull(sender); Assert.AreEqual(track, sender.Track); RTCRtpSendParameters parameters = sender.GetParameters(); Assert.NotNull(parameters); Assert.NotNull(parameters.encodings); foreach (var encoding in parameters.encodings) { Assert.True(encoding.active); Assert.Null(encoding.maxBitrate); Assert.Null(encoding.minBitrate); Assert.Null(encoding.maxFramerate); Assert.Null(encoding.scaleResolutionDownBy); Assert.IsNotEmpty(encoding.rid); } Assert.IsNotEmpty(parameters.transactionId); Assert.AreEqual(1, peer.GetTransceivers().Count()); Assert.NotNull(peer.GetTransceivers().First()); Assert.NotNull(parameters.codecs); foreach (var codec in parameters.codecs) { Assert.NotNull(codec); Assert.NotZero(codec.payloadType); Assert.IsNotEmpty(codec.mimeType); Assert.IsNotEmpty(codec.sdpFmtpLine); Assert.Null(codec.clockRate); Assert.Null(codec.channels); } Assert.NotNull(parameters.rtcp); Assert.NotNull(parameters.headerExtensions); foreach (var extension in parameters.headerExtensions) { Assert.NotNull(extension); Assert.IsNotEmpty(extension.uri); Assert.NotZero(extension.id); } track.Dispose(); stream.Dispose(); peer.Dispose(); }
private void ChangeFramerate(RTCRtpSender sender, uint framerate) { RTCRtpSendParameters parameters = sender.GetParameters(); parameters.encodings[0].maxFramerate = framerate; RTCError error = sender.SetParameters(parameters); if (error.errorType != RTCErrorType.None) { Debug.LogErrorFormat("RTCRtpSender.SetParameters failed {0}", error.errorType); } }
public void AddTransceiver() { var peer = new RTCPeerConnection(); var width = 256; var height = 256; var format = WebRTC.GetSupportedRenderTextureFormat(UnityEngine.SystemInfo.graphicsDeviceType); var rt = new UnityEngine.RenderTexture(width, height, 0, format); rt.Create(); var track = new VideoStreamTrack(rt); Assert.That(peer.GetTransceivers(), Is.Empty); var transceiver = peer.AddTransceiver(track); Assert.That(transceiver, Is.Not.Null); Assert.That(transceiver.Mid, Is.Null); Assert.That(transceiver.CurrentDirection, Is.Null); RTCRtpSender sender = transceiver.Sender; Assert.That(sender, Is.Not.Null); Assert.That(track, Is.EqualTo(sender.Track)); RTCRtpSendParameters parameters = sender.GetParameters(); Assert.That(parameters, Is.Not.Null); Assert.That(parameters.encodings, Is.Empty); Assert.That(parameters.transactionId, Is.Not.Empty); Assert.That(peer.GetTransceivers(), Has.Count.EqualTo(1)); Assert.That(peer.GetTransceivers().First(), Is.Not.Null); Assert.That(parameters.codecs, Is.Empty); Assert.That(parameters.rtcp, Is.Not.Null); // Some platforms return an empty list Assert.That(parameters.headerExtensions, Is.Not.Null); foreach (var extension in parameters.headerExtensions) { Assert.That(extension, Is.Not.Null); Assert.That(extension.uri, Is.Not.Empty); } track.Dispose(); peer.Dispose(); Object.DestroyImmediate(rt); }
private void ChangeFramerate(int index) { if (_pc1 == null || _pc2 == null) { return; } uint? framerate = framerateOptions.Values.ElementAt(index); RTCRtpSender sender = _pc1.GetSenders().First(); RTCRtpSendParameters parameters = sender.GetParameters(); parameters.encodings[0].maxFramerate = framerate; RTCError error = sender.SetParameters(parameters); if (error.errorType != RTCErrorType.None) { Debug.LogErrorFormat("RTCRtpSender.SetParameters failed {0}", error.errorType); statsField.text += $"Failed maxFramerate to " + $"{framerate}{Environment.NewLine}"; framerateSelector.value = 0; } }
private void ChangeScaleResolutionDown(int index) { if (_pc1 == null || _pc2 == null) { return; } double scale = scaleResolutionDownOptions.Values.ElementAt(index); RTCRtpSender sender = _pc1.GetSenders().First(); RTCRtpSendParameters parameters = sender.GetParameters(); parameters.encodings[0].scaleResolutionDownBy = scale; RTCError error = sender.SetParameters(parameters); if (error.errorType != RTCErrorType.None) { Debug.LogErrorFormat("RTCRtpSender.SetParameters failed {0}", error.errorType); statsField.text += $"Failed scale down video resolution to " + $"{(int)(width / scale)}x{(int)(height / scale)}{Environment.NewLine}"; scaleResolutionDownSelector.value = 0; } }
public void AddTransceiver() { var peer = new RTCPeerConnection(); var stream = Audio.CaptureStream(); var track = stream.GetAudioTracks().First(); Assert.AreEqual(0, peer.GetTransceivers().Count()); var transceiver = peer.AddTransceiver(track); Assert.NotNull(transceiver); Assert.That(() => Assert.NotNull(transceiver.CurrentDirection), Throws.InvalidOperationException); RTCRtpSender sender = transceiver.Sender; Assert.NotNull(sender); Assert.AreEqual(track, sender.Track); RTCRtpSendParameters parameters = sender.GetParameters(); Assert.NotNull(parameters); Assert.IsNotEmpty(parameters.TransactionId); Assert.AreEqual(1, peer.GetTransceivers().Count()); Assert.NotNull(peer.GetTransceivers().First()); }
public void AddTransceiver() { var peer = new RTCPeerConnection(); var stream = Audio.CaptureStream(); var track = stream.GetAudioTracks().First(); Assert.AreEqual(0, peer.GetTransceivers().Count()); var transceiver = peer.AddTransceiver(track); Assert.NotNull(transceiver); Assert.IsNull(transceiver.CurrentDirection); RTCRtpSender sender = transceiver.Sender; Assert.NotNull(sender); Assert.AreEqual(track, sender.Track); RTCRtpSendParameters parameters = sender.GetParameters(); Assert.NotNull(parameters); Assert.NotNull(parameters.Encodings); foreach (var encoding in parameters.Encodings) { Assert.True(encoding.active); Assert.Null(encoding.maxBitrate); Assert.Null(encoding.minBitrate); Assert.Null(encoding.maxFramerate); Assert.Null(encoding.scaleResolutionDownBy); Assert.IsNotEmpty(encoding.rid); } Assert.IsNotEmpty(parameters.TransactionId); Assert.AreEqual(1, peer.GetTransceivers().Count()); Assert.NotNull(peer.GetTransceivers().First()); track.Dispose(); stream.Dispose(); peer.Dispose(); }