-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBaseStreamTrack.cs
More file actions
101 lines (81 loc) · 3.16 KB
/
BaseStreamTrack.cs
File metadata and controls
101 lines (81 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using Unity.WebRTC;
namespace StreamVideo.Core.StatefulModels.Tracks
{
public delegate void StreamTrackStateChangeHandler(bool isEnabled);
/// <summary>
/// Used for tracks of remote participants
/// </summary>
public abstract class BaseStreamTrack : IStreamTrack
{
public event StreamTrackStateChangeHandler EnabledChanged;
/// <summary>
/// Effective enabled state: true only when the publisher has the track enabled
/// AND the Stream Server (SFU) has not paused it.
/// </summary>
public bool IsEnabled => _publisherEnabled && !_serverPaused;
/// <summary>
/// Whether the Stream Server (SFU) has paused this inbound track (e.g. due to insufficient bandwidth).
/// </summary>
public bool IsPausedByServer => _serverPaused;
public void Dispose() => OnDisposing();
internal BaseStreamTrack(MediaStreamTrack track)
{
InternalTrack = track ?? throw new ArgumentNullException(nameof(track));
_publisherEnabled = track.Enabled;
}
internal virtual void Update()
{
}
internal void SetPublisherEnabled(bool enabled)
{
if (_publisherEnabled == enabled)
{
return;
}
var wasEnabled = IsEnabled;
_publisherEnabled = enabled;
NotifyIfEffectiveStateChanged(wasEnabled);
//StreamTodo: investigate this. In theory we should disable track whenever the remote user disabled it.
//But there's and edge case where:
// 1. host enables video device right after JoinCall
// 2. host is in a call -> disables the camera (this disabled the track on the watcher user) -> leaves the call
// 3. host enters the call -> the camera is enabled right after JoinCall -> the watcher sees only black frames because track is disabled on his side
// Investigate missing implementation Context::StopMediaStreamTrack(webrtc::MediaStreamTrackInterface* track)
// InternalTrack.Enabled = enabled;
}
internal void SetServerPaused(bool paused)
{
if (_serverPaused == paused)
{
return;
}
var wasEnabled = IsEnabled;
_serverPaused = paused;
NotifyIfEffectiveStateChanged(wasEnabled);
}
protected MediaStreamTrack InternalTrack { get; set; }
protected virtual void OnDisposing()
{
}
private bool _publisherEnabled;
private bool _serverPaused;
private void NotifyIfEffectiveStateChanged(bool wasEnabled)
{
if (IsEnabled != wasEnabled)
{
EnabledChanged?.Invoke(IsEnabled);
}
}
}
public abstract class BaseStreamTrack<TTrack> : BaseStreamTrack
where TTrack : MediaStreamTrack
{
protected TTrack Track { get; }
protected BaseStreamTrack(MediaStreamTrack track)
: base(track)
{
Track = (TTrack)track;
}
}
}