// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using UnityEngine; using UnityEngine.Events; namespace Microsoft.MixedReality.WebRTC.Unity { /// /// Unity event corresponding to a new video stream being started. /// [Serializable] public class VideoStreamStartedEvent : UnityEvent { }; /// /// Unity event corresponding to an on-going video stream being stopped. /// [Serializable] public class VideoStreamStoppedEvent : UnityEvent { }; /// /// Endpoint for a WebRTC remote video track. /// /// /// Setting this on a video will enable the corresponding transceiver to receive. /// A remote track will be exposed through once a connection is established. /// The video track can optionally be displayed locally with a . /// [AddComponentMenu("MixedReality-WebRTC/Video Receiver")] public class VideoReceiver : MediaReceiver { /// /// Remote video track receiving data from the remote peer. /// /// This is null until is set to a non-null value /// and a remote track is added to that transceiver. /// public RemoteVideoTrack VideoTrack { get; private set; } /// /// Event raised when the video stream started. /// /// When this event is raised, the followings are true: /// - The property is a valid remote video track. /// - The property is true. /// /// /// This event is raised from the main Unity thread to allow Unity object access. /// public VideoStreamStartedEvent VideoStreamStarted = new VideoStreamStartedEvent(); /// /// Event raised when the video stream stopped. /// /// When this event is raised, the followings are true: /// - The property is null. /// - The property is false. /// /// /// This event is raised from the main Unity thread to allow Unity object access. /// public VideoStreamStoppedEvent VideoStreamStopped = new VideoStreamStoppedEvent(); /// public override MediaKind MediaKind => MediaKind.Video; /// public override MediaTrack Track => VideoTrack; /// protected internal override void OnPaired(MediaTrack track) { var remoteVideoTrack = (RemoteVideoTrack)track; Debug.Assert(VideoTrack == null); VideoTrack = remoteVideoTrack; VideoStreamStarted.Invoke(VideoTrack); } /// protected internal override void OnUnpaired(MediaTrack track) { Debug.Assert(track is RemoteVideoTrack); Debug.Assert(VideoTrack == track); VideoTrack = null; VideoStreamStopped.Invoke(VideoTrack); } } }