forked from video-dev/hls.js
-
Notifications
You must be signed in to change notification settings - Fork 2
/
level-details.ts
142 lines (129 loc) · 3.9 KB
/
level-details.ts
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { Part } from './fragment';
import type { Fragment } from './fragment';
import type { AttrList } from '../utils/attr-list';
const DEFAULT_TARGET_DURATION = 10;
export class LevelDetails {
public PTSKnown: boolean = false;
public alignedSliding: boolean = false;
public averagetargetduration?: number;
public endCC: number = 0;
public endSN: number = 0;
public fragments: Fragment[];
public fragmentHint?: Fragment;
public partList: Part[] | null = null;
// public initSegment: Fragment | null = null;
public live: boolean = true;
public ageHeader: number = 0;
public advancedDateTime?: number;
public updated: boolean = true;
public advanced: boolean = true;
public availabilityDelay?: number; // Manifest reload synchronization
public misses: number = 0;
// public needSidxRanges: boolean = false;
public startCC: number = 0;
public startSN: number = 0;
public startTimeOffset: number | null = null;
public targetduration: number = 0;
public totalduration: number = 0;
public type: string | null = null;
public url: string;
public m3u8: string = '';
public version: number | null = null;
public canBlockReload: boolean = false;
public canSkipUntil: number = 0;
public canSkipDateRanges: boolean = false;
public skippedSegments: number = 0;
public recentlyRemovedDateranges?: string[];
public partHoldBack: number = 0;
public holdBack: number = 0;
public partTarget: number = 0;
public preloadHint?: AttrList;
public renditionReports?: AttrList[];
public tuneInGoal: number = 0;
public deltaUpdateFailed?: boolean;
public driftStartTime: number = 0;
public driftEndTime: number = 0;
public driftStart: number = 0;
public driftEnd: number = 0;
constructor(baseUrl) {
this.fragments = [];
this.url = baseUrl;
}
reloaded(previous: LevelDetails | undefined) {
if (!previous) {
this.advanced = true;
this.updated = true;
return;
}
const partSnDiff = this.lastPartSn - previous.lastPartSn;
const partIndexDiff = this.lastPartIndex - previous.lastPartIndex;
this.updated =
this.endSN !== previous.endSN || !!partIndexDiff || !!partSnDiff;
this.advanced =
this.endSN > previous.endSN ||
partSnDiff > 0 ||
(partSnDiff === 0 && partIndexDiff > 0);
if (this.updated || this.advanced) {
this.misses = Math.floor(previous.misses * 0.6);
} else {
this.misses = previous.misses + 1;
}
this.availabilityDelay = previous.availabilityDelay;
}
get hasProgramDateTime(): boolean {
if (this.fragments.length) {
return Number.isFinite(
this.fragments[this.fragments.length - 1].programDateTime as number
);
}
return false;
}
get levelTargetDuration(): number {
return (
this.averagetargetduration ||
this.targetduration ||
DEFAULT_TARGET_DURATION
);
}
get drift(): number {
const runTime = this.driftEndTime - this.driftStartTime;
if (runTime > 0) {
const runDuration = this.driftEnd - this.driftStart;
return (runDuration * 1000) / runTime;
}
return 1;
}
get edge(): number {
return this.partEnd || this.fragmentEnd;
}
get partEnd(): number {
if (this.partList?.length) {
return this.partList[this.partList.length - 1].end;
}
return this.fragmentEnd;
}
get fragmentEnd(): number {
if (this.fragments?.length) {
return this.fragments[this.fragments.length - 1].end;
}
return 0;
}
get age(): number {
if (this.advancedDateTime) {
return Math.max(Date.now() - this.advancedDateTime, 0) / 1000;
}
return 0;
}
get lastPartIndex(): number {
if (this.partList?.length) {
return this.partList[this.partList.length - 1].index;
}
return -1;
}
get lastPartSn(): number {
if (this.partList?.length) {
return this.partList[this.partList.length - 1].fragment.sn as number;
}
return this.endSN;
}
}