// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using UnityEngine; namespace Microsoft.MixedReality.WebRTC.Unity { /// /// Base class for media producers generating frames by receiving them from a remote peer. /// public abstract class MediaReceiver : MonoBehaviour { /// /// Media kind of the receiver. /// public abstract MediaKind MediaKind { get; } /// /// Remote track associated with this receiver. /// null if this object is not receiving at this time. /// /// /// This is always a or a /// public abstract MediaTrack Track { get; } /// /// Is the media source currently producing frames received from the remote peer? /// This is true while the remote media track exists, which is notified by /// events on the or . /// public bool IsLive => Track != null; /// /// Transceiver this receiver is paired with, if any. /// /// This is null until a remote description is applied which pairs the media line /// this receiver is associated with to a transceiver, or until the peer connection of this /// receiver's media line creates the receiver right before creating an SDP offer. /// public Transceiver Transceiver => MediaLine?.Transceiver; /// /// Media line this receiver is paired with, if any. /// /// /// Note that this is set to the connected only if the owning /// is awake. This will be automatically reset if the /// owning the is destroyed. /// public MediaLine MediaLine { get; private set; } /// /// Internal callback invoked when the media receiver is assigned to a media line. /// /// The new media line this receiver is assigned to. protected internal virtual void OnAddedToMediaLine(MediaLine mediaLine) { Debug.Assert(MediaLine == null); MediaLine = mediaLine; } /// /// Internal callback invoked when the media receiver is de-assigned from a media line. /// /// The old media line this receiver was assigned to. protected internal virtual void OnRemovedFromMediaLine(MediaLine mediaLine) { Debug.Assert(MediaLine == mediaLine); MediaLine = null; } /// /// Internal callback invoked when the receiver is paired with a media track. /// /// /// This will be called on the Unity update thread. /// /// The media track this receiver is paired with. protected internal virtual void OnPaired(MediaTrack track) { } /// /// Internal callback invoked when the receiver is unpaired from a media track. /// /// /// This will be called on the Unity update thread. /// /// The media track this receiver was paired with. protected internal virtual void OnUnpaired(MediaTrack track) { } protected void OnDestroy() { MediaLine?.OnReceiverDestroyed(); } } }