forked from kuu/hls-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.js
More file actions
256 lines (244 loc) · 5.95 KB
/
types.js
File metadata and controls
256 lines (244 loc) · 5.95 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
const utils = require('./utils');
class Rendition {
constructor({
type, // required
uri, // required if type='SUBTITLES'
groupId, // required
language,
assocLanguage,
name, // required
isDefault,
autoselect,
forced,
instreamId, // required if type=CLOSED-CAPTIONS
characteristics,
channels
}) {
utils.PARAMCHECK(type, groupId, name);
utils.CONDITIONALASSERT([type === 'SUBTITLES', uri], [type === 'CLOSED-CAPTIONS', instreamId], [type === 'CLOSED-CAPTIONS', !uri], [forced, type === 'CLOSED-CAPTIONS']);
this.type = type;
this.uri = uri;
this.groupId = groupId;
this.language = language;
this.assocLanguage = assocLanguage;
this.name = name;
this.isDefault = isDefault;
this.autoselect = autoselect;
this.forced = forced;
this.instreamId = instreamId;
this.characteristics = characteristics;
this.channels = channels;
}
}
class Variant {
constructor({
uri, // required
isIFrameOnly = false,
bandwidth, // required
averageBandwidth,
codecs, // required?
resolution,
frameRate,
hdcpLevel,
audio = [],
video = [],
subtitles = [],
closedCaptions = [],
currentRenditions = {audio: 0, video: 0, subtitles: 0, closedCaptions: 0}
}) {
// utils.PARAMCHECK(uri, bandwidth, codecs);
utils.PARAMCHECK(uri, bandwidth); // the spec states that CODECS is required but not true in the real world
this.uri = uri;
this.isIFrameOnly = isIFrameOnly;
this.bandwidth = bandwidth;
this.averageBandwidth = averageBandwidth;
this.codecs = codecs;
this.resolution = resolution;
this.frameRate = frameRate;
this.hdcpLevel = hdcpLevel;
this.audio = audio;
this.video = video;
this.subtitles = subtitles;
this.closedCaptions = closedCaptions;
this.currentRenditions = currentRenditions;
}
}
class SessionData {
constructor({
id, // required
value,
uri,
language
}) {
utils.PARAMCHECK(id, value || uri);
utils.ASSERT('SessionData cannot have both value and uri, shoud be either.', !(value && uri));
this.id = id;
this.value = value;
this.uri = uri;
this.language = language;
}
}
class Key {
constructor({
method, // required
uri, // required unless method=NONE
iv,
format,
formatVersion
}) {
utils.PARAMCHECK(method);
utils.CONDITIONALPARAMCHECK([method !== 'NONE', uri]);
utils.CONDITIONALASSERT([method === 'NONE', !(uri || iv || format || formatVersion)]);
this.method = method;
this.uri = uri;
this.iv = iv;
this.format = format;
this.formatVersion = formatVersion;
}
}
class MediaInitializationSection {
constructor({
uri, // required
mimeType,
byterange
}) {
utils.PARAMCHECK(uri);
this.uri = uri;
this.mimeType = mimeType;
this.byterange = byterange;
}
}
class DateRange {
constructor({
id, // required
classId, // required if endOnNext is true
start, // required
end,
duration,
plannedDuration,
endOnNext,
attributes = {}
}) {
utils.PARAMCHECK(id, start);
utils.CONDITIONALPARAMCHECK([endOnNext === true, classId]);
utils.CONDITIONALASSERT([end, start <= end], [duration, duration >= 0], [plannedDuration, plannedDuration >= 0]);
this.id = id;
this.classId = classId;
this.start = start;
this.end = end;
this.duration = duration;
this.plannedDuration = plannedDuration;
this.endOnNext = endOnNext;
this.attributes = attributes;
}
}
class Data {
constructor(type) {
utils.PARAMCHECK(type);
this.type = type;
}
}
class Playlist extends Data {
constructor({
isMasterPlaylist, // required
uri,
version,
independentSegments = false,
start,
source
}) {
super('playlist');
utils.PARAMCHECK(isMasterPlaylist);
this.isMasterPlaylist = isMasterPlaylist;
this.uri = uri;
this.version = version;
this.independentSegments = independentSegments;
this.start = start;
this.source = source;
}
}
class MasterPlaylist extends Playlist {
constructor(params = {}) {
params.isMasterPlaylist = true;
super(params);
const {
variants = [],
currentVariant,
sessionDataList = [],
sessionKeyList = []
} = params;
this.variants = variants;
this.currentVariant = currentVariant;
this.sessionDataList = sessionDataList;
this.sessionKeyList = sessionKeyList;
}
}
class MediaPlaylist extends Playlist {
constructor(params = {}) {
params.isMasterPlaylist = false;
super(params);
const {
targetDuration,
mediaSequenceBase = 0,
discontinuitySequenceBase = 0,
endlist = false,
playlistType,
isIFrame,
segments = [],
hash
} = params;
this.targetDuration = targetDuration;
this.mediaSequenceBase = mediaSequenceBase;
this.discontinuitySequenceBase = discontinuitySequenceBase;
this.endlist = endlist;
this.playlistType = playlistType;
this.isIFrame = isIFrame;
this.segments = segments;
this.hash = hash;
}
}
class Segment extends Data {
constructor({
uri, // required
mimeType,
data,
duration,
title,
byterange,
discontinuity,
mediaSequenceNumber,
discontinuitySequence,
key,
map,
programDateTime,
dateRange
}) {
super('segment');
utils.PARAMCHECK(uri, mediaSequenceNumber, discontinuitySequence);
this.uri = uri;
this.mimeType = mimeType;
this.data = data;
this.duration = duration;
this.title = title;
this.byterange = byterange;
this.discontinuity = discontinuity;
this.mediaSequenceNumber = mediaSequenceNumber;
this.discontinuitySequence = discontinuitySequence;
this.key = key;
this.map = map;
this.programDateTime = programDateTime;
this.dateRange = dateRange;
}
}
module.exports = {
Rendition,
Variant,
SessionData,
Key,
MediaInitializationSection,
DateRange,
Playlist,
MasterPlaylist,
MediaPlaylist,
Segment
};