public IEnumerator MediaStreamTrackThrowExceptionAfterPeerDisposed() { 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 track = new AudioStreamTrack(); peer1.AddTrack(track); MediaStreamTrack track1 = null; peer2.OnTrack = e => { track1 = e.Track; }; yield return(SignalingOffer(peer1, peer2)); Assert.That(track1, Is.Not.Null); peer2.Dispose(); Assert.That(() => track1.Id, Throws.TypeOf <InvalidOperationException>()); track.Dispose(); track1.Dispose(); }
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(); }
public static Webrtc.PeerConnection.RTCConfiguration ToNative(this RTCConfiguration configuration) { RTCIceServer[] iceServers = configuration.IceServers ?? new RTCIceServer[] { }; var nativeConfiguration = new Webrtc.PeerConnection.RTCConfiguration(iceServers .Select(server => server.ToNative()).ToList()); if (configuration.BundlePolicy.HasValue) { nativeConfiguration.BundlePolicy = configuration.BundlePolicy?.ToNative(); } if (configuration.Certificates is not null) { nativeConfiguration.Certificate = (Webrtc.RtcCertificatePem) (configuration.Certificates?.ElementAt(0).NativeObject); } if (configuration.IceCandidatePoolSize.HasValue) { nativeConfiguration.IceCandidatePoolSize = (int)configuration.IceCandidatePoolSize; } if (configuration.IceTransportPolicy.HasValue) { nativeConfiguration.IceTransportsType = configuration.IceTransportPolicy?.ToNative(); } if (configuration.RtcpMuxPolicy.HasValue) { nativeConfiguration.RtcpMuxPolicy = configuration.RtcpMuxPolicy?.ToNative(); } if (configuration.SdpSemantics.HasValue) { nativeConfiguration.SdpSemantics = configuration.SdpSemantics?.ToNative(); } return(nativeConfiguration); }
public override async Task OnEnteringState() { Debug.Assert(Context.PeerConnection == null); Context.VoipCoordinator.SetActiveIncomingCall(_message, _callRequest.VideoEnabled); var config = new RTCConfiguration { IceServers = WebRtcSettingsUtils.ToRTCIceServer(IceServerSettings.IceServers) }; Context.PeerConnection = new RTCPeerConnection(config); Context.LocalStream = await Context.Media.GetUserMedia(new RTCMediaStreamConstraints { videoEnabled = _callRequest.VideoEnabled, audioEnabled = true }); Context.PeerConnection.AddStream(Context.LocalStream); var tracks = Context.LocalStream.GetVideoTracks(); if (tracks.Count > 0) { #if WIN10 var source = Context.Media.CreateMediaSource(tracks[0], VoipContext.LocalMediaStreamId); #else var source = Context.Media.CreateMediaStreamSource(tracks[0], 30, VoipContext.LocalMediaStreamId); #endif Context.LocalVideoRenderer.SetupRenderer(Context.ForegroundProcessId, source, Context.LocalVideoControlSize); } }
private static Task <RTCPeerConnection> CreatePeerConnection() { RTCConfiguration config = new RTCConfiguration { iceServers = new List <RTCIceServer> { new RTCIceServer { urls = STUN_URL } } }; var pc = new RTCPeerConnection(config); var testPatternSource = new VideoTestPatternSource(); var videoEncoderEndPoint = new VideoEncoderEndPoint(); var audioSource = new AudioExtrasSource(new AudioEncoder(), new AudioSourceOptions { AudioSource = AudioSourcesEnum.Music }); MediaStreamTrack videoTrack = new MediaStreamTrack(videoEncoderEndPoint.GetVideoSourceFormats(), MediaStreamStatusEnum.SendRecv); pc.addTrack(videoTrack); MediaStreamTrack audioTrack = new MediaStreamTrack(audioSource.GetAudioSourceFormats(), MediaStreamStatusEnum.SendRecv); pc.addTrack(audioTrack); testPatternSource.OnVideoSourceRawSample += videoEncoderEndPoint.ExternalVideoSourceRawSample; videoEncoderEndPoint.OnVideoSourceEncodedSample += pc.SendVideo; audioSource.OnAudioSourceEncodedSample += pc.SendAudio; pc.OnVideoFormatsNegotiated += (formats) => videoEncoderEndPoint.SetVideoSourceFormat(formats.First()); pc.onconnectionstatechange += async(state) => { logger.LogDebug($"Peer connection state change to {state}."); if (state == RTCPeerConnectionState.connected) { await audioSource.StartAudio(); await testPatternSource.StartVideo(); } else if (state == RTCPeerConnectionState.failed) { pc.Close("ice disconnection"); } else if (state == RTCPeerConnectionState.closed) { await testPatternSource.CloseVideo(); await audioSource.CloseAudio(); } }; // Diagnostics. pc.OnReceiveReport += (re, media, rr) => logger.LogDebug($"RTCP Receive for {media} from {re}\n{rr.GetDebugSummary()}"); pc.OnSendReport += (media, sr) => logger.LogDebug($"RTCP Send for {media}\n{sr.GetDebugSummary()}"); pc.GetRtpChannel().OnStunMessageReceived += (msg, ep, isRelay) => logger.LogDebug($"STUN {msg.Header.MessageType} received from {ep}."); pc.oniceconnectionstatechange += (state) => logger.LogDebug($"ICE connection state change to {state}."); return(Task.FromResult(pc)); }
public IEnumerator Start() { if (captureCamera == null) { captureCamera = Camera.main; } videoStream = captureCamera.CaptureStream(streamingSize.x, streamingSize.y, RenderTextureDepth.DEPTH_24); audioStream = WebRTC.Audio.CaptureStream(); signaling = new Signaling(urlSignaling); var opCreate = signaling.Create(); yield return(opCreate); if (opCreate.webRequest.isNetworkError) { Debug.LogError($"Network Error: {opCreate.webRequest.error}"); yield break; } var newResData = opCreate.webRequest.DownloadHandlerJson <NewResData>().GetObject(); sessionId = newResData.sessionId; conf = default; conf.iceServers = iceServers; StartCoroutine(WebRTC.WebRTC.Update()); StartCoroutine(LoopPolling()); }
public override async Task OnEnteringState() { Debug.Assert(Context.PeerConnection == null); Context.VoipCoordinator.StartOutgoingCall(_callRequest); var config = new RTCConfiguration { IceServers = WebRtcSettingsUtils.ToRTCIceServer(IceServerSettings.IceServers) }; Context.PeerConnection = new RTCPeerConnection(config); Context.LocalStream = await Context.Media.GetUserMedia(new RTCMediaStreamConstraints { videoEnabled = _callRequest.VideoEnabled, audioEnabled = true }); Context.PeerConnection.AddStream(Context.LocalStream); var sdpOffer = await Context.PeerConnection.CreateOffer(); var sdpString = sdpOffer.Sdp; SdpUtils.SelectCodecs(ref sdpString, Context.AudioCodec, Context.VideoCodec); sdpOffer.Sdp = sdpString; await Context.PeerConnection.SetLocalDescription(sdpOffer); var tracks = Context.LocalStream.GetVideoTracks(); if (tracks.Count > 0) { var source = Context.Media.CreateMediaStreamSource(tracks[0], 30, "LOCAL"); Context.LocalVideoRenderer.SetupRenderer(Context.ForegroundProcessId, source); } Context.SendToPeer(RelayMessageTags.SdpOffer, sdpOffer.Sdp); }
public IEnumerator MediaStreamTrackThrowExceptionAfterPeerDisposed() { 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 obj = new GameObject("audio"); var source = obj.AddComponent <AudioSource>(); source.clip = AudioClip.Create("test", 480, 2, 48000, false); AudioStreamTrack track = new AudioStreamTrack(source); peer1.AddTrack(track); MediaStreamTrack track1 = null; peer2.OnTrack = e => { track1 = e.Track; }; yield return(SignalingOffer(peer1, peer2)); Assert.That(track1, Is.Not.Null); peer2.Dispose(); Assert.That(() => track1.Id, Throws.TypeOf <ObjectDisposedException>()); track.Dispose(); track1.Dispose(); Object.DestroyImmediate(source.clip); Object.DestroyImmediate(obj); }
public static Webrtc.RTCConfiguration ToNative(this RTCConfiguration configuration) { RTCIceServer[] iceServers = configuration.IceServers ?? new RTCIceServer[] { }; var nativeConfiguration = new Webrtc.RTCConfiguration(); if (configuration.BundlePolicy.HasValue) { nativeConfiguration.BundlePolicy = ((RTCBundlePolicy)configuration.BundlePolicy).ToNative(); } if (configuration.Certificates is not null) { nativeConfiguration.Certificate = (Webrtc.RTCCertificate) (configuration.Certificates?.ElementAt(0).NativeObject); } if (configuration.IceCandidatePoolSize.HasValue) { nativeConfiguration.IceCandidatePoolSize = (int)configuration.IceCandidatePoolSize; } nativeConfiguration.IceServers = iceServers.Select(server => server.ToNative()).ToArray(); if (configuration.IceTransportPolicy.HasValue) { nativeConfiguration.IceTransportPolicy = ((RTCIceTransportPolicy)configuration.IceTransportPolicy).ToNative(); } if (configuration.RtcpMuxPolicy.HasValue) { nativeConfiguration.RtcpMuxPolicy = ((RTCRtcpMuxPolicy)configuration.RtcpMuxPolicy).ToNative(); } if (configuration.SdpSemantics.HasValue) { nativeConfiguration.SdpSemantics = ((SdpSemantics)configuration.SdpSemantics).ToNative(); } return(nativeConfiguration); }
public static RTCConfiguration Create(Signaling.OfferConfig serverConfig, MediaOption mediaOption) { var iceServers = serverConfig.IceServers.Select(iceServer => new RTCIceServer() { Urls = iceServer.Urls, Username = iceServer.Username, Credential = iceServer.Credential, }).ToList(); var conf = new RTCConfiguration() { BundlePolicy = RTCBundlePolicy.MaxBundle, IceTransportPolicy = RTCIceTransportPolicy.All, IceServers = iceServers, RtcpMuxPolicy = RTCRtcpMuxPolicy.Require, ContinualGatheringPolicy = RTCContinualGatheringPolicy.Continually, EnableDtlsSrtp = true, SdpSemantics = RTCSdpSemantics.UnifiedPlan, TcpCandidatePolicy = mediaOption.TcpCandidatePolicy, EnableIceRenomination = true, }; if (serverConfig.IceTransportPolicy == "relay") { conf.IceTransportPolicy = RTCIceTransportPolicy.Relay; } return(conf); }
public IEnumerator AddAndRemoveAudioMediaTrack() { RTCConfiguration config = default; config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } }; var audioStream = Audio.CaptureStream(); var test = new MonoBehaviourTest <SignalingPeers>(); test.component.SetStream(audioStream); yield return(test); test.component.Dispose(); Assert.That(audioStream.GetTracks().ToList(), Has.Count.EqualTo(1).And.All.InstanceOf <AudioStreamTrack>()); foreach (var track in audioStream.GetTracks()) { track.Dispose(); } audioStream.Dispose(); }
public PeerConnectionNative(PeerConnection peerConnection, RTCConfiguration configuration, IPeerConnectionFactory peerConnectionFactory) : base(peerConnection) { _peerConnection = peerConnection; Configuration = configuration; PeerConnectionFactory = peerConnectionFactory; }
public PeerChannel(RTCConfiguration rtcConf, MediaOption mediaOption, CoreDispatcher dispatcher) { this.rtcConf = rtcConf; this.mediaOption = mediaOption; this.dispatcher = dispatcher; }
public void CreateDataChannelWithOption() { RTCConfiguration config = default; config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } }; var peer = new RTCPeerConnection(ref config); var options = new RTCDataChannelInit { id = 231, maxRetransmits = 1, maxPacketLifeTime = null, negotiated = false, ordered = false, protocol = "" }; var channel1 = peer.CreateDataChannel("test1", options); Assert.AreEqual("test1", channel1.Label); Assert.AreEqual("", channel1.Protocol); Assert.NotZero(channel1.MaxRetransmitTime); Assert.NotZero(channel1.MaxRetransmits); Assert.False(channel1.Ordered); Assert.False(channel1.Negotiated); // It is return -1 when channel is not connected. Assert.AreEqual(channel1.Id, -1); channel1.Close(); peer.Close(); }
private void InitializeWebRtc() { WebRTC.Initialize(); var config = new RTCConfiguration { iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302" } } } }; _peerConnection = new RTCPeerConnection(ref config); _peerConnection.OnIceConnectionChange = state => Debug.LogError("State changed: " + state); Debug.LogError("PeerConnection created."); var dcInit = new RTCDataChannelInit(true); DataChannel = _peerConnection.CreateDataChannel("dataChannel", ref dcInit); DataChannel.OnOpen = () => Debug.LogError("Data channel opened."); DataChannel.OnClose = () => Debug.LogError("Data channel closed."); DataChannel.OnMessage = bytes => Debug.LogError("Data channel received data: " + Encoding.UTF8.GetString(bytes)); Debug.LogError("Data channel created."); }
public static PeerConnection.RTCConfiguration ToNative(this RTCConfiguration self) { return(new PeerConnection.RTCConfiguration(self.IceServers.ToNative().ToList()) { IceTransportsType = self.IceTransportPolicy.ToNative(), BundlePolicy = self.BundlePolicy.ToNative(), RtcpMuxPolicy = self.RtcpMuxPolicy.ToNative(), TcpCandidatePolicy = self.TcpCandidatePolicy.ToNative(), CandidateNetworkPolicy = self.CandidateNetworkPolicy.ToNative(), AudioJitterBufferMaxPackets = self.AudioJitterBufferMaxPackets, AudioJitterBufferFastAccelerate = self.AudioJitterBufferFastAccelerate, IceConnectionReceivingTimeout = self.IceConnectionReceivingTimeout, KeyType = self.KeyType.ToNative(), ContinualGatheringPolicy = self.ContinualGatheringPolicy.ToNative(), IceCandidatePoolSize = self.IceCandidatePoolSize, PruneTurnPorts = self.ShouldPruneTurnPorts, PresumeWritableWhenFullyRelayed = self.ShouldPresumeWritableWhenFullyRelayed, IceCheckMinInterval = self.IceCheckMinInterval.HasValue ? new Integer(self.IceCheckMinInterval.Value) : null, DisableIPv6OnWifi = self.DisableIPv6OnWiFi, MaxIPv6Networks = self.MaxIPv6Networks, DisableIpv6 = self.DisableIPv6, SdpSemantics = self.SdpSemantics.ToNative(), ActiveResetSrtpParams = self.ActiveResetSrtpParams, UseMediaTransport = self.UseMediaTransport, UseMediaTransportForDataChannels = self.UseMediaTransportForDataChannels, EnableDtlsSrtp = !self.EnableDtlsSrtp ? new Boolean(true) : null, Certificate = self.Certificate?.ToNative() }); }
public void Start() { m_audioStream = Unity.WebRTC.Audio.CaptureStream(); m_conf = default; m_conf.iceServers = iceServers; StartCoroutine(WebRTC.WebRTC.Update()); }
public void DataChannel_CreateDataChannel() { RTCConfiguration config = default; config.iceServers = new RTCIceServer[] { new RTCIceServer { urls = new string[] { "stun:stun.l.google.com:19302" } } }; var peer = new RTCPeerConnection(ref config); var option1 = new RTCDataChannelInit(true); var channel1 = peer.CreateDataChannel("test1", ref option1); Assert.AreEqual("test1", channel1.Label); var option2 = new RTCDataChannelInit(false); var channel2 = peer.CreateDataChannel("test2", ref option2); Assert.AreEqual("test2", channel2.Label); // It is return -1 when channel is not connected. Assert.AreEqual(channel1.Id, -1); Assert.AreEqual(channel2.Id, -1); peer.Close(); }
/// <summary> /// /// </summary> /// <param name="dependencies"></param> public RenderStreamingInternal(ref RenderStreamingDependencies dependencies) { if (dependencies.signaling == null) { throw new ArgumentException("Signaling instance is null."); } if (dependencies.startCoroutine == null) { throw new ArgumentException("Coroutine action instance is null."); } if (s_list.Count == 0) { WebRTC.WebRTC.Initialize(dependencies.encoderType); } _config = dependencies.config; _startCoroutine = dependencies.startCoroutine; _signaling = dependencies.signaling; _signaling.OnStart += OnStart; _signaling.OnCreateConnection += OnCreateConnection; _signaling.OnDestroyConnection += OnDestroyConnection; _signaling.OnOffer += OnOffer; _signaling.OnAnswer += OnAnswer; _signaling.OnIceCandidate += OnIceCandidate; _signaling.Start(); s_list.Add(this); _startCoroutine(WebRTC.WebRTC.Update()); }
public IEnumerator UnitySetUp() { WebRTC.WebRTC.Initialize(); RTCConfiguration config = default; RTCIceCandidate candidate_ = null; 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 => { candidate_ = candidate; }; MediaStream stream = WebRTC.Audio.CaptureStream(); peer1.AddTrack(stream.GetTracks().First()); RTCOfferOptions offerOptions = new RTCOfferOptions(); var op1 = peer1.CreateOffer(ref offerOptions); yield return(op1); m_DescOffer = op1.Desc; var op2 = peer1.SetLocalDescription(ref m_DescOffer); yield return(op2); var op3 = peer2.SetRemoteDescription(ref m_DescOffer); yield return(op3); RTCAnswerOptions answerOptions = new RTCAnswerOptions(); var op4 = peer2.CreateAnswer(ref answerOptions); yield return(op4); m_DescAnswer = op4.Desc; var op5 = peer2.SetLocalDescription(ref m_DescAnswer); yield return(op5); var op6 = peer1.SetRemoteDescription(ref m_DescAnswer); yield return(op6); yield return(new WaitUntil(() => candidate_ != null)); m_candidate = candidate_; stream.Dispose(); peer1.Close(); peer2.Close(); m_Context = SynchronizationContext.Current; signaling1 = CreateSignaling(m_SignalingType, m_Context); signaling2 = CreateSignaling(m_SignalingType, m_Context); }
private RTCPeerConnection(RTCConfiguration configuration) //=> { var x = configuration.ToNative(); NativeObject = WebRTCme.WebRtc.NativePeerConnectionFactory .CreatePeerConnection(x, this); }
public override async Task OnEnteringState() { Debug.Assert(Context.PeerConnection == null); Context.VoipCoordinator.SetActiveIncomingCall(_message, _callRequest.VideoEnabled); var config = new RTCConfiguration { IceServers = WebRtcSettingsUtils.ToRTCIceServer(IceServerSettings.IceServers) }; Context.PeerConnection = new RTCPeerConnection(config); Context.LocalStream = await Context.Media.GetUserMedia(new RTCMediaStreamConstraints { videoEnabled = _callRequest.VideoEnabled, audioEnabled = true }); Context.PeerConnection.AddStream(Context.LocalStream); var tracks = Context.LocalStream.GetVideoTracks(); if (tracks.Count > 0) { var source = Context.Media.CreateMediaStreamSource(tracks[0], 30, "LOCAL"); Context.LocalVideoRenderer.SetupRenderer(Context.ForegroundProcessId, source); } }
private static Task <RTCPeerConnection> CreatePeerConnection() { RTCConfiguration config = new RTCConfiguration { iceServers = new List <RTCIceServer> { new RTCIceServer { urls = STUN_URL } } }; var pc = new RTCPeerConnection(config); pc.createDataChannel("test", null); pc.onconnectionstatechange += async(state) => { logger.LogDebug($"Peer connection state change to {state}."); if (state == RTCPeerConnectionState.failed) { pc.Close("ice disconnection"); } }; // Diagnostics. pc.OnReceiveReport += (re, media, rr) => logger.LogDebug($"RTCP Receive for {media} from {re}\n{rr.GetDebugSummary()}"); pc.OnSendReport += (media, sr) => logger.LogDebug($"RTCP Send for {media}\n{sr.GetDebugSummary()}"); pc.GetRtpChannel().OnStunMessageReceived += (msg, ep, isRelay) => logger.LogDebug($"STUN {msg.Header.MessageType} received from {ep}."); pc.oniceconnectionstatechange += (state) => logger.LogDebug($"ICE connection state change to {state}."); return(Task.FromResult(pc)); }
private static RTCPeerConnection WebSocketOpened(WebSocketContext context) { RTCConfiguration pcConfiguration = new RTCConfiguration { certificates = new List <RTCCertificate> { new RTCCertificate { X_CertificatePath = DTLS_CERTIFICATE_PATH, X_KeyPath = DTLS_KEY_PATH, X_Fingerprint = DTLS_CERTIFICATE_FINGERPRINT } } }; var peerConnection = new RTCPeerConnection(pcConfiguration); // Add local recvonly tracks. This ensures that the SDP answer includes only // the codecs we support. MediaStreamTrack audioTrack = new MediaStreamTrack("0", SDPMediaTypesEnum.audio, false, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.PCMU) }, MediaStreamStatusEnum.RecvOnly); peerConnection.addTrack(audioTrack); MediaStreamTrack videoTrack = new MediaStreamTrack("1", SDPMediaTypesEnum.video, false, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.VP8) }, MediaStreamStatusEnum.RecvOnly); peerConnection.addTrack(videoTrack); return(peerConnection); }
private void CreatePeerConnectionInternal() { if (_factory == null || _isError) { _logger.Error(TAG, "Peerconnection factory is not created"); return; } _logger.Debug(TAG, "Create peer connection."); _queuedRemoteCandidates = new List <IceCandidate>(); var rtcConfig = new RTCConfiguration(); // TCP candidates are only useful when connecting to a server that supports // ICE-TCP. rtcConfig.IceServers = _parameters.IceServers; rtcConfig.TcpCandidatePolicy = TcpCandidatePolicy.Disabled; rtcConfig.BundlePolicy = BundlePolicy.MaxBundle; rtcConfig.RtcpMuxPolicy = RtcpMuxPolicy.Require; rtcConfig.ContinualGatheringPolicy = ContinualGatheringPolicy.Continually; // Use ECDSA encryption. rtcConfig.KeyType = EncryptionKeyType.Ecdsa; // Enable DTLS for normal calls and disable for loopback calls. rtcConfig.EnableDtlsSrtp = _parameters.Loopback; rtcConfig.SdpSemantics = SdpSemantics.UnifiedPlan; _peerConnection = _factory.PeerConnectionWithConfiguration(rtcConfig, _sdpMediaConstraints, _peerConnectionListener); var mediaStreamLabels = new[] { "ARDAMS" }; if (IsVideoCallEnabled) { _peerConnection.AddTrack(CreateVideoTrack(), mediaStreamLabels); // We can add the renderers right away because we don't need to wait for an // answer to get the remote track. _remoteVideoTrack = GetRemoteVideoTrack(); _remoteVideoTrack.IsEnabled = _renderVideo; _remoteVideoTrack.AddRenderer(_remoteRenderer); } _peerConnection.AddTrack(CreateAudioTrack(), mediaStreamLabels); if (IsVideoCallEnabled) { FindVideoSender(); } if (_parameters.AecDump) { var result = _factory.StartAecDumpWithFilePath(_parameters.AecDumpFile, -1); if (!result) { _logger.Error(TAG, "Can not open aecdump file"); } } _logger.Debug(TAG, "Peer connection created."); }
public void Start() { videoStream = captureCamera.CaptureStream(streamingSize.x, streamingSize.y, bitRate); audioStream = Unity.WebRTC.Audio.CaptureStream(); conf = default; conf.iceServers = iceServers; StartCoroutine(WebRTC.WebRTC.Update()); }
private static Task <RTCPeerConnection> CreatePeerConnection() { RTCConfiguration config = new RTCConfiguration { iceServers = new List <RTCIceServer> { new RTCIceServer { urls = STUN_URL } } }; //var pc = new RTCPeerConnection(config); var pc = peer = new RTCPeerConnection(null); var testPatternSource = new VideoTestPatternSource(); testPatternSource.SetFrameRate(60); testPatternSource.SetMaxFrameRate(true); var videoEndPoint = new SIPSorceryMedia.FFmpeg.FFmpegVideoEndPoint(); videoEndPoint.RestrictFormats(format => format.Codec == VideoCodecsEnum.H264); //var videoEndPoint = new SIPSorceryMedia.Windows.WindowsVideoEndPoint(true); //var videoEndPoint = new SIPSorceryMedia.Windows.WindowsEncoderEndPoint(); //var videoEndPoint = new SIPSorceryMedia.Encoders.VideoEncoderEndPoint(); MediaStreamTrack track = new MediaStreamTrack(videoEndPoint.GetVideoSourceFormats(), MediaStreamStatusEnum.SendOnly); pc.addTrack(track); testPatternSource.OnVideoSourceRawSample += TestPatternSource_OnVideoSourceRawSample; pc.OnVideoFormatsNegotiated += (formats) => { videoEndPoint.SetVideoSourceFormat(formats.First()); }; pc.onconnectionstatechange += async(state) => { if (state == RTCPeerConnectionState.failed) { pc.Close("ice disconnection"); } else if (state == RTCPeerConnectionState.closed) { await testPatternSource.CloseVideo(); await videoEndPoint.CloseVideo(); } else if (state == RTCPeerConnectionState.connected) { await videoEndPoint.StartVideo(); await testPatternSource.StartVideo(); } }; return(Task.FromResult(pc)); }
private static RTCConfiguration GetSelectedSdpSemantics() { RTCConfiguration config = default; config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } }; return(config); }
/// <summary> /// /// </summary> /// <param name="conf"></param> /// <param name="hardwareEncoder"></param> /// <param name="signaling"></param> /// <param name="handlers"></param> /// <remarks> To use this method, Need to depend WebRTC package </remarks> public void Run( RTCConfiguration conf, bool?hardwareEncoder = null, ISignaling signaling = null, SignalingHandlerBase[] handlers = null ) { _Run(conf, hardwareEncoder, signaling, handlers); }
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(); }
void Start() { videoStream = GetComponent <Camera>().CaptureStream(streamingSize.x, streamingSize.y, RenderTextureDepth.DEPTH_24); audioStream = Audio.CaptureStream(); conf = default; conf.iceServers = iceServers; StartCoroutine(WebRTC.Update()); }
private static RTCPeerConnection BuildRTCPeerInstance() { RTCConfiguration config = new RTCConfiguration { iceServers = candidates_ice }; return(new RTCPeerConnection(config)); }