/// <summary> /// Internal free-threaded helper callback on track added, which enqueues the /// <see cref="VideoSource.VideoStreamStopped"/> event to be fired from the main /// Unity thread. /// </summary> private void TrackRemoved(WebRTC.PeerConnection.TrackKind trackKind) { if (trackKind == WebRTC.PeerConnection.TrackKind.Video) { // Enqueue invoking the unity event from the main Unity thread, so that listeners // can directly access Unity objects from their handler function. _mainThreadWorkQueue.Enqueue(() => VideoStreamStopped.Invoke()); } }
/// <summary> /// Callback when the Unity component is disabled. This is the proper way to disable the /// video source and get it to stop video capture. /// </summary> protected void OnDisable() { var nativePeer = PeerConnection.Peer; if ((nativePeer != null) && nativePeer.Initialized) { VideoStreamStopped.Invoke(); nativePeer.I420LocalVideoFrameReady -= I420LocalVideoFrameReady; nativePeer.RemoveLocalVideoTrack(); FrameQueue.Clear(); } }
/// <summary> /// Stop the video track playback and remove the track from the peer connection. /// </summary> public void StopTrack() { if (Track != null) { var nativePeer = PeerConnection.Peer; nativePeer.RemoveLocalVideoTrack(Track); Track.Dispose(); Track = null; VideoStreamStopped.Invoke(); } if (Source != null) { Source.Dispose(); Source = null; } _frameQueue.Clear(); }
protected void NotifyVideoStreamStopped() => VideoStreamStopped?.Invoke();