コード例 #1
0
    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);
        }
    }
コード例 #2
0
    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;
        }
    }
コード例 #3
0
    private void AddTracks()
    {
        foreach (var track in videoStream.GetTracks())
        {
            pc1Senders.Add(_pc1.AddTrack(track, videoStream));
        }

        if (!videoUpdateStarted)
        {
            StartCoroutine(WebRTC.Update());
            videoUpdateStarted = true;
        }

        RTCRtpCodecCapability[] codecs = null;
        if (codecSelector.value == 0)
        {
            codecs = RTCRtpSender.GetCapabilities(TrackKind.Video).codecs;
        }
        else
        {
            RTCRtpCodecCapability preferredCodec = availableCodecs[codecSelector.value - 1];
            codecs = new[] { preferredCodec };
        }
        RTCRtpTransceiver transceiver = _pc1.GetTransceivers().First();
        RTCErrorType      error       = transceiver.SetCodecPreferences(codecs);

        if (error != RTCErrorType.None)
        {
            Debug.LogErrorFormat("RTCRtpTransceiver.SetCodecPreferences failed. {0}", error);
        }
    }
コード例 #4
0
ファイル: Helper.cs プロジェクト: yueyz818/PeerCC
        public static IList <RTCRtpCodecCapability> GetCodecs(string kind)
        {
            var caps    = RTCRtpSender.GetCapabilities(kind == "audio" ? MediaStreamTrackKind.Audio : MediaStreamTrackKind.Video);
            var results = new List <RTCRtpCodecCapability>(caps.Codecs);

            return(results);
        }
コード例 #5
0
ファイル: Helper.cs プロジェクト: Anhtuan1/hololens
        public static IList <RTCRtpCodecCapability> GetCodecs(string kind)
        {
            var caps    = RTCRtpSender.GetCapabilities(kind);
            var results = new List <RTCRtpCodecCapability>(caps.Codecs);

            return(results);
        }
コード例 #6
0
        public IEnumerator TransceiverReturnsSender()
        {
            RTCConfiguration config = default;

            config.iceServers = new[] { new RTCIceServer {
                                            urls = new[] { "stun:stun.l.google.com:19302" }
                                        } };
            var peer1 = new RTCPeerConnection(ref config);
            var peer2 = new RTCPeerConnection(ref config);

            peer1.OnIceCandidate = candidate => { peer2.AddIceCandidate(candidate); };
            peer2.OnIceCandidate = candidate => { peer1.AddIceCandidate(candidate); };

            AudioStreamTrack track1 = new AudioStreamTrack();

            peer1.AddTrack(track1);

            yield return(SignalingOffer(peer1, peer2));

            Assert.That(peer2.GetTransceivers().Count(), Is.EqualTo(1));
            RTCRtpSender sender1 = peer2.GetTransceivers().First().Sender;

            Assert.That(sender1, Is.Not.Null);

            AudioStreamTrack track2  = new AudioStreamTrack();
            RTCRtpSender     sender2 = peer2.AddTrack(track2);

            Assert.That(sender2, Is.Not.Null);
            Assert.That(sender1, Is.EqualTo(sender2));

            track1.Dispose();
            track2.Dispose();
            peer1.Dispose();
            peer2.Dispose();
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="track"></param>
        public RTCRtpTransceiver AddTrack(string connectionId, MediaStreamTrack track)
        {
            // todo:: replace RTCPeerConnection.AddTransceiver(MediaStreamTrack track, RTCRtpTransceiverInit init)
            RTCRtpSender sender = _mapConnectionIdAndPeer[connectionId].AddTrack(track);

            return(_mapConnectionIdAndPeer[connectionId].GetTransceivers().First(t => t.Sender == sender));
        }
コード例 #8
0
        public void TransceiverSetAudioCodecPreferences()
        {
            var peer         = new RTCPeerConnection();
            var capabilities = RTCRtpSender.GetCapabilities(TrackKind.Audio);
            var transceiver  = peer.AddTransceiver(TrackKind.Audio);
            var error        = transceiver.SetCodecPreferences(capabilities.codecs);

            Assert.AreEqual(RTCErrorType.None, error);
        }
コード例 #9
0
        public IEnumerator RemoteOnRemoveTrack()
        {
            RTCConfiguration config = default;

            config.iceServers = new[] { new RTCIceServer {
                                            urls = new[] { "stun:stun.l.google.com:19302" }
                                        } };
            var peer1 = new RTCPeerConnection(ref config);
            var peer2 = new RTCPeerConnection(ref config);

            peer1.OnIceCandidate = candidate => { peer2.AddIceCandidate(candidate); };
            peer2.OnIceCandidate = candidate => { peer1.AddIceCandidate(candidate); };

            var         stream        = new MediaStream();
            MediaStream receiveStream = null;
            var         track         = new AudioStreamTrack();

            stream.AddTrack(track);
            RTCRtpSender sender = peer1.AddTrack(track, stream);

            bool isInvokeNegotiationNeeded1 = false;

            peer1.OnNegotiationNeeded = () => isInvokeNegotiationNeeded1 = true;

            bool isInvokeOnRemoveTrack = false;

            peer2.OnTrack = e =>
            {
                Assert.That(e.Streams, Has.Count.EqualTo(1));
                receiveStream = e.Streams.First();
                receiveStream.OnRemoveTrack = ev => isInvokeOnRemoveTrack = true;
            };

            yield return(SignalingOffer(peer1, peer2));

            peer1.RemoveTrack(sender);

            var op9 = new WaitUntilWithTimeout(() => isInvokeNegotiationNeeded1, 5000);

            yield return(op9);

            Assert.That(op9.IsCompleted, Is.True);

            yield return(SignalingOffer(peer1, peer2));

            var op10 = new WaitUntilWithTimeout(() => isInvokeOnRemoveTrack, 5000);

            yield return(op10);

            Assert.That(op10.IsCompleted, Is.True);

            stream.Dispose();
            receiveStream.Dispose();
            track.Dispose();
            peer1.Dispose();
            peer2.Dispose();
        }
コード例 #10
0
 public void AddTrack()
 {
     sender = offerPc.AddTrack(SendVideoTrack);
     if (videoCodec != null)
     {
         var transceiver = offerPc.GetTransceivers().First(t => t.Sender == sender);
         transceiver.SetCodecPreferences(new[] { videoCodec });
     }
 }
コード例 #11
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();
        }
コード例 #12
0
        public Task <IList <ICodec> > GetCodecsAsync(MediaKind kind)
        {
            IList <ICodec> videoCodecsList = new List <ICodec>();
            IList <ICodec> audioCodecsList = new List <ICodec>();

            if (kind == MediaKind.AudioCodec)
            {
                return(Task.Run(() =>
                {
                    RTCRtpCapabilities audioCapabilities = RTCRtpSender.GetCapabilities(new WebRtcFactory(new WebRtcFactoryConfiguration()), "audio");
                    IReadOnlyList <RTCRtpCodecCapability> audioCodecs = audioCapabilities.Codecs;
                    foreach (var item in audioCodecs)
                    {
                        string payload = item.PreferredPayloadType.ToString();

                        Codec audioCodec = new Codec();
                        audioCodec.SetMediaKind(MediaKind.AudioCodec);
                        audioCodec.SetId(payload);
                        audioCodec.SetDisplayName(item.Name + " " + payload);
                        audioCodec.SetRate((int)item.ClockRate);

                        audioCodecsList.Add(audioCodec);
                    }
                    return audioCodecsList;
                }));
            }

            if (kind == MediaKind.VideoCodec)
            {
                return(Task.Run(() =>
                {
                    RTCRtpCapabilities videoCapabilities = RTCRtpSender.GetCapabilities(new WebRtcFactory(new WebRtcFactoryConfiguration()), "video");
                    IReadOnlyList <RTCRtpCodecCapability> videoCodecs = videoCapabilities.Codecs;
                    foreach (var item in videoCodecs)
                    {
                        string payload = item.PreferredPayloadType.ToString();

                        Codec videoCodec = new Codec();
                        videoCodec.SetMediaKind(MediaKind.VideoCodec);
                        videoCodec.SetId(payload);
                        videoCodec.SetDisplayName(item.Name + " " + payload);
                        videoCodec.SetRate((int)item.ClockRate);

                        videoCodecsList.Add(videoCodec);
                    }

                    return videoCodecsList;
                }));
            }
            else
            {
                return(null);
            }
        }
コード例 #13
0
    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);
        }
    }
コード例 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="track"></param>
        public RTCRtpTransceiver AddTrack(string connectionId, MediaStreamTrack track)
        {
            var          peer        = _mapConnectionIdAndPeer[connectionId];
            RTCRtpSender sender      = peer.peer.AddTrack(track);
            var          transceiver = peer.peer.GetTransceivers().First(t => t.Sender == sender);

            // note:: This line is needed to stream video to other peers with hardware codec.
            // The exchanging SDP is failed if remove the line because the hardware decoder currently is not supported.
            // Please remove the line after supporting the hardware decoder.
            transceiver.Direction = RTCRtpTransceiverDirection.SendOnly;
            return(transceiver);
        }
コード例 #15
0
    private void OnStart()
    {
        var capabilities = RTCRtpSender.GetCapabilities(TrackKind.Video);

        availableCodecs =
            capabilities.codecs.Where(codec => !excludeCodecMimeType.Contains(codec.mimeType)).ToArray();
        var list = availableCodecs
                   .Select(codec => new Dropdown.OptionData {
            text = codec.mimeType + " " + codec.sdpFmtpLine
        })
                   .ToList();

        codecSelector.options.AddRange(list);
        codecSelector.interactable = true;
        startButton.interactable   = false;
    }
コード例 #16
0
        static bool CheckVideoCodecCapabilities()
        {
            var capabilitiesSender = RTCRtpSender.GetCapabilities(TrackKind.Video);

            if (!capabilitiesSender.codecs.Any())
            {
                return(false);
            }
            var capabilitiesReceiver = RTCRtpReceiver.GetCapabilities(TrackKind.Video);

            if (!capabilitiesReceiver.codecs.Any())
            {
                return(false);
            }
            return(true);
        }
コード例 #17
0
        public static bool CheckVideoSendRecvCodecSupport(EncoderType encoderType)
        {
            WebRTC.Initialize(encoderType);
            var capabilitiesSenderCodec = RTCRtpSender.GetCapabilities(TrackKind.Video)
                                          .codecs
                                          .Select(x => x.mimeType)
                                          .Except(excludeCodecMimeType);
            var capabilitiesReceiverCodec = RTCRtpReceiver.GetCapabilities(TrackKind.Video)
                                            .codecs
                                            .Select(x => x.mimeType)
                                            .Except(excludeCodecMimeType);
            var isSupported = capabilitiesSenderCodec.Any(x => capabilitiesReceiverCodec.Contains(x));

            WebRTC.Dispose();
            return(isSupported);
        }
コード例 #18
0
        public IEnumerator TransceiverReturnsSender()
        {
            RTCConfiguration config = default;

            config.iceServers = new[] { new RTCIceServer {
                                            urls = new[] { "stun:stun.l.google.com:19302" }
                                        } };
            var peer1 = new RTCPeerConnection(ref config);
            var peer2 = new RTCPeerConnection(ref config);

            peer1.OnIceCandidate = candidate => { peer2.AddIceCandidate(candidate); };
            peer2.OnIceCandidate = candidate => { peer1.AddIceCandidate(candidate); };

            var obj1    = new GameObject("audio1");
            var source1 = obj1.AddComponent <AudioSource>();

            source1.clip = AudioClip.Create("test1", 480, 2, 48000, false);
            AudioStreamTrack track1 = new AudioStreamTrack(source1);

            peer1.AddTrack(track1);

            yield return(SignalingOffer(peer1, peer2));

            Assert.That(peer2.GetTransceivers().Count(), Is.EqualTo(1));
            RTCRtpSender sender1 = peer2.GetTransceivers().First().Sender;

            Assert.That(sender1, Is.Not.Null);

            var obj2    = new GameObject("audio2");
            var source2 = obj2.AddComponent <AudioSource>();

            source2.clip = AudioClip.Create("test2", 480, 2, 48000, false);
            AudioStreamTrack track2  = new AudioStreamTrack(source2);
            RTCRtpSender     sender2 = peer2.AddTrack(track2);

            Assert.That(sender2, Is.Not.Null);
            Assert.That(sender1, Is.EqualTo(sender2));

            track1.Dispose();
            track2.Dispose();
            peer1.Dispose();
            peer2.Dispose();
            Object.DestroyImmediate(source1.clip);
            Object.DestroyImmediate(source2.clip);
            Object.DestroyImmediate(obj1);
            Object.DestroyImmediate(obj2);
        }
コード例 #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connectionId"></param>
 /// <param name="sender"></param>
 public virtual void SetSender(string connectionId, RTCRtpSender sender)
 {
     if (connectionId == null)
     {
         throw new ArgumentNullException("connectionId is null");
     }
     if (sender == null)
     {
         m_senders.Remove(connectionId);
         OnStoppedStream?.Invoke(connectionId);
     }
     else
     {
         m_senders.Add(connectionId, sender);
         OnStartedStream?.Invoke(connectionId);
     }
 }
コード例 #20
0
        void AddTracks(string connectionId, RTCPeerConnection pc)
        {
            // ToDo: need webrtc package version 2.3
            // foreach (var transceiver in pc.GetTransceivers()
            //     .Where(x => x.Receiver.Track.Kind == TrackKind.Video)
            //     .Select((x, index) => new {x, index})
            //     .Take(m_listVideoStreamTrack.Count))
            // {
            //     RTCRtpSender sender = transceiver.x.Sender;
            //     VideoStreamTrack track = m_listVideoStreamTrack[transceiver.index];
            //     transceiver.x.Sender.ReplaceTrack(track);
            //     transceiver.x.Direction = RTCRtpTransceiverDirection.SendOnly;
            //
            //     if (!m_mapTrackAndSenderList.TryGetValue(track, out List<RTCRtpSender> list))
            //     {
            //         list = new List<RTCRtpSender>();
            //         m_mapTrackAndSenderList.Add(track, list);
            //     }
            //
            //     list.Add(sender);
            // }

            foreach (var track in m_listVideoStreamTrack)
            {
                RTCRtpSender sender = pc.AddTrack(track);
                if (!m_mapTrackAndSenderList.TryGetValue(track, out List <RTCRtpSender> list))
                {
                    list = new List <RTCRtpSender>();
                    m_mapTrackAndSenderList.Add(track, list);
                }

                list.Add(sender);
            }

            foreach (var track in m_audioStream.GetTracks())
            {
                RTCRtpSender sender = pc.AddTrack(track);
                if (!m_mapTrackAndSenderList.TryGetValue(track, out List <RTCRtpSender> list))
                {
                    list = new List <RTCRtpSender>();
                    m_mapTrackAndSenderList.Add(track, list);
                }

                list.Add(sender);
            }
        }
コード例 #21
0
        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);
        }
コード例 #22
0
    private IEnumerator UpdateStats()
    {
        while (true)
        {
            RTCRtpSender sender             = pc1Senders.First();
            RTCStatsReportAsyncOperation op = sender.GetStats();
            yield return(op);

            if (op.IsError)
            {
                Debug.LogErrorFormat("RTCRtpSender.GetStats() is failed {0}", op.Error.errorType);
            }
            else
            {
                UpdateStatsPacketSize(op.Value);
            }

            yield return(new WaitForSeconds(1f));
        }
    }
コード例 #23
0
    private IEnumerator UpdateStatsCoroutine()
    {
        RTCRtpSender sender = pc1Senders.FirstOrDefault();

        if (sender == null)
        {
            yield break;
        }
        RTCStatsReportAsyncOperation op = sender.GetStats();

        yield return(op);

        if (op.IsError)
        {
            Debug.LogErrorFormat("RTCRtpSender.GetStats() is failed {0}", op.Error.errorType);
        }
        else
        {
            UpdateStatsPacketSize(op.Value);
        }
    }
コード例 #24
0
        public void SenderGetAudioCapabilities()
        {
            RTCRtpCapabilities capabilities = RTCRtpSender.GetCapabilities(TrackKind.Audio);

            Assert.NotNull(capabilities);
            Assert.NotNull(capabilities.codecs);
            Assert.IsNotEmpty(capabilities.codecs);
            Assert.NotNull(capabilities.headerExtensions);
            Assert.IsNotEmpty(capabilities.headerExtensions);

            foreach (var codec in capabilities.codecs)
            {
                Assert.NotNull(codec);
                Assert.IsNotEmpty(codec.mimeType);
            }
            foreach (var extensions in capabilities.headerExtensions)
            {
                Assert.NotNull(extensions);
                Assert.IsNotEmpty(extensions.uri);
            }
        }
コード例 #25
0
    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;
        }
    }
コード例 #26
0
        public void ReceiverGetTrackReturnsAudioTrack()
        {
            var peer        = new RTCPeerConnection();
            var transceiver = peer.AddTransceiver(TrackKind.Audio);

            Assert.That(transceiver, Is.Not.Null);
            Assert.That(transceiver.CurrentDirection, Is.Null);

            // The receiver has a audio track
            RTCRtpReceiver receiver = transceiver.Receiver;

            Assert.That(receiver, Is.Not.Null);
            Assert.That(receiver.Track, Is.Not.Null);
            Assert.That(receiver.Track, Is.TypeOf <AudioStreamTrack>());

            // The receiver has no track
            RTCRtpSender sender = transceiver.Sender;

            Assert.That(sender, Is.Not.Null);
            Assert.That(sender.Track, Is.Null);

            peer.Dispose();
        }
コード例 #27
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());
        }
コード例 #28
0
        public static bool CheckVideoSendRecvCodecSupport(EncoderType encoderType)
        {
            // hardware encoder is not supported
            if (encoderType == EncoderType.Hardware &&
                !NativeMethods.GetHardwareEncoderSupport())
            {
                return(false);
            }

            WebRTC.Initialize(encoderType);
            var capabilitiesSenderCodec = RTCRtpSender.GetCapabilities(TrackKind.Video)
                                          .codecs
                                          .Select(x => x.mimeType)
                                          .Except(excludeCodecMimeType);
            var capabilitiesReceiverCodec = RTCRtpReceiver.GetCapabilities(TrackKind.Video)
                                            .codecs
                                            .Select(x => x.mimeType)
                                            .Except(excludeCodecMimeType);
            var isSupported = capabilitiesSenderCodec.Any(x => capabilitiesReceiverCodec.Contains(x));

            WebRTC.Dispose();
            return(isSupported);
        }
コード例 #29
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;
        }
    }
コード例 #30
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());

            track.Dispose();
            stream.Dispose();
            peer.Dispose();
        }