hls.js 1.6.0-beta.2.0.canary.10942 → 1.6.0-beta.3.0.canary.10943
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hls.js +37 -25
- package/dist/hls.js.map +1 -1
- package/dist/hls.light.js +37 -25
- package/dist/hls.light.js.map +1 -1
- package/dist/hls.light.min.js +1 -1
- package/dist/hls.light.min.js.map +1 -1
- package/dist/hls.light.mjs +39 -25
- package/dist/hls.light.mjs.map +1 -1
- package/dist/hls.min.js +1 -1
- package/dist/hls.min.js.map +1 -1
- package/dist/hls.mjs +39 -25
- package/dist/hls.mjs.map +1 -1
- package/dist/hls.worker.js +1 -1
- package/package.json +1 -1
- package/src/controller/latency-controller.ts +34 -22
@@ -2,6 +2,7 @@ import { ErrorDetails } from '../errors';
|
|
2
2
|
import { Events } from '../events';
|
3
3
|
import type { HlsConfig } from '../config';
|
4
4
|
import type Hls from '../hls';
|
5
|
+
import type { LevelDetails } from '../loader/level-details';
|
5
6
|
import type { ComponentAPI } from '../types/component-api';
|
6
7
|
import type {
|
7
8
|
ErrorData,
|
@@ -10,7 +11,7 @@ import type {
|
|
10
11
|
} from '../types/events';
|
11
12
|
|
12
13
|
export default class LatencyController implements ComponentAPI {
|
13
|
-
private hls: Hls;
|
14
|
+
private hls: Hls | null;
|
14
15
|
private readonly config: HlsConfig;
|
15
16
|
private media: HTMLMediaElement | null = null;
|
16
17
|
private currentTime: number = 0;
|
@@ -24,6 +25,10 @@ export default class LatencyController implements ComponentAPI {
|
|
24
25
|
this.registerListeners();
|
25
26
|
}
|
26
27
|
|
28
|
+
private get levelDetails(): LevelDetails | null {
|
29
|
+
return this.hls?.latestLevelDetails || null;
|
30
|
+
}
|
31
|
+
|
27
32
|
get latency(): number {
|
28
33
|
return this._latency || 0;
|
29
34
|
}
|
@@ -33,15 +38,15 @@ export default class LatencyController implements ComponentAPI {
|
|
33
38
|
if (config.liveMaxLatencyDuration !== undefined) {
|
34
39
|
return config.liveMaxLatencyDuration;
|
35
40
|
}
|
36
|
-
const levelDetails = this.
|
41
|
+
const levelDetails = this.levelDetails;
|
37
42
|
return levelDetails
|
38
43
|
? config.liveMaxLatencyDurationCount * levelDetails.targetduration
|
39
44
|
: 0;
|
40
45
|
}
|
41
46
|
|
42
47
|
get targetLatency(): number | null {
|
43
|
-
const levelDetails = this.
|
44
|
-
if (levelDetails === null) {
|
48
|
+
const levelDetails = this.levelDetails;
|
49
|
+
if (levelDetails === null || this.hls === null) {
|
45
50
|
return null;
|
46
51
|
}
|
47
52
|
const { holdBack, partHoldBack, targetduration } = levelDetails;
|
@@ -82,7 +87,7 @@ export default class LatencyController implements ComponentAPI {
|
|
82
87
|
if (liveEdge === null || targetLatency === null) {
|
83
88
|
return null;
|
84
89
|
}
|
85
|
-
const levelDetails = this.
|
90
|
+
const levelDetails = this.levelDetails;
|
86
91
|
if (levelDetails === null) {
|
87
92
|
return null;
|
88
93
|
}
|
@@ -97,7 +102,7 @@ export default class LatencyController implements ComponentAPI {
|
|
97
102
|
}
|
98
103
|
|
99
104
|
get drift(): number {
|
100
|
-
const levelDetails = this.
|
105
|
+
const levelDetails = this.levelDetails;
|
101
106
|
if (levelDetails === null) {
|
102
107
|
return 1;
|
103
108
|
}
|
@@ -105,7 +110,7 @@ export default class LatencyController implements ComponentAPI {
|
|
105
110
|
}
|
106
111
|
|
107
112
|
get edgeStalled(): number {
|
108
|
-
const levelDetails = this.
|
113
|
+
const levelDetails = this.levelDetails;
|
109
114
|
if (levelDetails === null) {
|
110
115
|
return 0;
|
111
116
|
}
|
@@ -117,7 +122,7 @@ export default class LatencyController implements ComponentAPI {
|
|
117
122
|
|
118
123
|
private get forwardBufferLength(): number {
|
119
124
|
const { media } = this;
|
120
|
-
const levelDetails = this.
|
125
|
+
const levelDetails = this.levelDetails;
|
121
126
|
if (!media || !levelDetails) {
|
122
127
|
return 0;
|
123
128
|
}
|
@@ -132,24 +137,31 @@ export default class LatencyController implements ComponentAPI {
|
|
132
137
|
public destroy(): void {
|
133
138
|
this.unregisterListeners();
|
134
139
|
this.onMediaDetaching();
|
135
|
-
// @ts-ignore
|
136
140
|
this.hls = null;
|
137
141
|
}
|
138
142
|
|
139
143
|
private registerListeners() {
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
144
|
+
const { hls } = this;
|
145
|
+
if (!hls) {
|
146
|
+
return;
|
147
|
+
}
|
148
|
+
hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this);
|
149
|
+
hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this);
|
150
|
+
hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this);
|
151
|
+
hls.on(Events.LEVEL_UPDATED, this.onLevelUpdated, this);
|
152
|
+
hls.on(Events.ERROR, this.onError, this);
|
145
153
|
}
|
146
154
|
|
147
155
|
private unregisterListeners() {
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
156
|
+
const { hls } = this;
|
157
|
+
if (!hls) {
|
158
|
+
return;
|
159
|
+
}
|
160
|
+
hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this);
|
161
|
+
hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this);
|
162
|
+
hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this);
|
163
|
+
hls.off(Events.LEVEL_UPDATED, this.onLevelUpdated, this);
|
164
|
+
hls.off(Events.ERROR, this.onError, this);
|
153
165
|
}
|
154
166
|
|
155
167
|
private onMediaAttached(
|
@@ -189,7 +201,7 @@ export default class LatencyController implements ComponentAPI {
|
|
189
201
|
return;
|
190
202
|
}
|
191
203
|
this.stallCount++;
|
192
|
-
if (this.hls.
|
204
|
+
if (this.hls && this.levelDetails?.live) {
|
193
205
|
this.hls.logger.warn(
|
194
206
|
'[latency-controller]: Stall detected, adjusting target latency',
|
195
207
|
);
|
@@ -198,7 +210,7 @@ export default class LatencyController implements ComponentAPI {
|
|
198
210
|
|
199
211
|
private onTimeupdate = () => {
|
200
212
|
const { media } = this;
|
201
|
-
const levelDetails = this.
|
213
|
+
const levelDetails = this.levelDetails;
|
202
214
|
if (!media || !levelDetails) {
|
203
215
|
return;
|
204
216
|
}
|
@@ -251,7 +263,7 @@ export default class LatencyController implements ComponentAPI {
|
|
251
263
|
};
|
252
264
|
|
253
265
|
private estimateLiveEdge(): number | null {
|
254
|
-
const levelDetails = this.
|
266
|
+
const levelDetails = this.levelDetails;
|
255
267
|
if (levelDetails === null) {
|
256
268
|
return null;
|
257
269
|
}
|