public async Task BeforeConnect() { // Add local video track channel to #1 var settings = new PeerConnection.LocalVideoTrackSettings(); LocalVideoTrack track1 = await pc1_.AddLocalVideoTrackAsync(settings); Assert.NotNull(track1); Assert.AreEqual(pc1_, track1.PeerConnection); // Wait for local SDP re-negotiation on #1. // This will not create an offer, since we're not connected yet. Assert.True(renegotiationEvent1_.Wait(TimeSpan.FromSeconds(60.0))); // Connect Assert.True(pc1_.CreateOffer()); WaitForSdpExchangeCompleted(); Assert.True(pc1_.IsConnected); Assert.True(pc2_.IsConnected); // Remove the track from #1 renegotiationEvent1_.Reset(); pc1_.RemoveLocalVideoTrack(track1); Assert.IsNull(track1.PeerConnection); track1.Dispose(); // Wait for local SDP re-negotiation on #1 Assert.True(renegotiationEvent1_.Wait(TimeSpan.FromSeconds(60.0))); // Confirm remote track was removed from #2 Assert.True(trackRemovedEvent2_.Wait(TimeSpan.FromSeconds(60.0))); // Wait until SDP renegotiation finished WaitForSdpExchangeCompleted(); }
/// <inheritdoc/> public void Dispose() { if (_nativeHandle.IsClosed) { return; } // Remove the track from the peer connection, if any PeerConnection?.RemoveLocalVideoTrack(this); Debug.Assert(PeerConnection == null); // see OnTrackRemoved // Unregister interop callbacks if (_selfHandle != IntPtr.Zero) { LocalVideoTrackInterop.LocalVideoTrack_RegisterI420AFrameCallback(_nativeHandle, null, IntPtr.Zero); LocalVideoTrackInterop.LocalVideoTrack_RegisterArgb32FrameCallback(_nativeHandle, null, IntPtr.Zero); Utils.ReleaseWrapperRef(_selfHandle); _selfHandle = IntPtr.Zero; _interopCallbackArgs = null; } // Currently there is a 1:1 mapping between track and source, so the track owns its // source and must dipose of it. Source?.Dispose(); // Destroy the native object. This may be delayed if a P/Invoke callback is underway, // but will be handled at some point anyway, even if the managed instance is gone. _nativeHandle.Dispose(); }
private void StopLocalVideo() { lock (_isLocalVideoPlayingLock) { if (_isLocalVideoPlaying) { localVideo.MediaPlayer.Pause(); _peerConnection.RemoveLocalVideoTrack(); _isLocalVideoPlaying = false; } } }