// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Collections.Generic;
using UnityEngine;
namespace Microsoft.MixedReality.WebRTC.Unity
{
///
/// Base class for media track source components producing some media frames locally.
///
///
///
public abstract class MediaTrackSource : MonoBehaviour
{
///
/// Media kind of the track source.
///
public abstract MediaKind MediaKind { get; }
///
/// Indicates if the source is currently producing frames.
///
public abstract bool IsLive { get; }
///
/// List of audio media lines using this source.
///
///
/// Note that a connected will be added to this only if the owning
/// is awake. A will be automatically
/// removed if the owning is destroyed.
///
public IReadOnlyList MediaLines => _mediaLines;
private readonly List _mediaLines = new List();
internal void OnAddedToMediaLine(MediaLine mediaLine)
{
Debug.Assert(!_mediaLines.Contains(mediaLine));
_mediaLines.Add(mediaLine);
}
internal void OnRemovedFromMediaLine(MediaLine mediaLine)
{
bool removed = _mediaLines.Remove(mediaLine);
Debug.Assert(removed);
}
protected void AttachToMediaLines()
{
foreach (var ml in _mediaLines)
{
ml.AttachSource();
}
}
protected void DetachFromMediaLines()
{
foreach (var ml in _mediaLines)
{
ml.DetachSource();
}
}
}
}