Skip to content

Commit 0153a4c

Browse files
committed
perf(dash-wasm): share the UTF-8 decoder
1 parent bc2ab3d commit 0153a4c

14 files changed

Lines changed: 38 additions & 72 deletions

File tree

‎src/parsers/manifest/dash/wasm-parser/ts/generators/AdaptationSet.ts‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,29 +256,27 @@ export function generateAdaptationSetAttrParser(
256256
adaptationAttrs: IAdaptationSetAttributes,
257257
linearMemory: WebAssembly.Memory,
258258
): IAttributeParser {
259-
const textDecoder = new TextDecoder();
260259
return function onAdaptationSetAttribute(attr: number, ptr: number, len: number) {
261260
const dataView = new DataView(linearMemory.buffer);
262261
switch (attr) {
263262
case AttributeName.Id:
264-
adaptationAttrs.id = parseString(textDecoder, linearMemory.buffer, ptr, len);
263+
adaptationAttrs.id = parseString(linearMemory.buffer, ptr, len);
265264
break;
266265
case AttributeName.Group:
267266
adaptationAttrs.group = dataView.getFloat64(ptr, true);
268267
break;
269268
case AttributeName.Language:
270-
adaptationAttrs.lang = parseString(textDecoder, linearMemory.buffer, ptr, len);
269+
adaptationAttrs.lang = parseString(linearMemory.buffer, ptr, len);
271270
break;
272271
case AttributeName.ContentType:
273272
adaptationAttrs.contentType = parseString(
274-
textDecoder,
275273
linearMemory.buffer,
276274
ptr,
277275
len,
278276
);
279277
break;
280278
case AttributeName.Par:
281-
adaptationAttrs.par = parseString(textDecoder, linearMemory.buffer, ptr, len);
279+
adaptationAttrs.par = parseString(linearMemory.buffer, ptr, len);
282280
break;
283281
case AttributeName.MinBandwidth:
284282
adaptationAttrs.minBandwidth = dataView.getFloat64(ptr, true);
@@ -322,42 +320,37 @@ export function generateAdaptationSetAttrParser(
322320
break;
323321
case AttributeName.AudioSamplingRate:
324322
adaptationAttrs.audioSamplingRate = parseString(
325-
textDecoder,
326323
linearMemory.buffer,
327324
ptr,
328325
len,
329326
);
330327
break;
331328
case AttributeName.Codecs:
332-
adaptationAttrs.codecs = parseString(textDecoder, linearMemory.buffer, ptr, len);
329+
adaptationAttrs.codecs = parseString(linearMemory.buffer, ptr, len);
333330
break;
334331
case AttributeName.SupplementalCodecs:
335332
adaptationAttrs["scte214:supplementalCodecs"] = parseString(
336-
textDecoder,
337333
linearMemory.buffer,
338334
ptr,
339335
len,
340336
);
341337
break;
342338
case AttributeName.Profiles:
343339
adaptationAttrs.profiles = parseString(
344-
textDecoder,
345340
linearMemory.buffer,
346341
ptr,
347342
len,
348343
);
349344
break;
350345
case AttributeName.SegmentProfiles:
351346
adaptationAttrs.segmentProfiles = parseString(
352-
textDecoder,
353347
linearMemory.buffer,
354348
ptr,
355349
len,
356350
);
357351
break;
358352
case AttributeName.MimeType:
359353
adaptationAttrs.mimeType = parseString(
360-
textDecoder,
361354
linearMemory.buffer,
362355
ptr,
363356
len,

‎src/parsers/manifest/dash/wasm-parser/ts/generators/BaseURL.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ export function generateBaseUrlAttrParser(
2929
baseUrlAttrs: IBaseUrlIntermediateRepresentation,
3030
linearMemory: WebAssembly.Memory,
3131
): IAttributeParser {
32-
const textDecoder = new TextDecoder();
3332
return function onMPDAttribute(attr: AttributeName, ptr: number, len: number) {
3433
if (attr === AttributeName.Text) {
35-
baseUrlAttrs.value = parseString(textDecoder, linearMemory.buffer, ptr, len);
34+
baseUrlAttrs.value = parseString(linearMemory.buffer, ptr, len);
3635
}
3736
};
3837
}

‎src/parsers/manifest/dash/wasm-parser/ts/generators/ContentComponent.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,22 @@ export function generateContentComponentAttrParser(
2929
ccAttrs: IContentComponentAttributes,
3030
linearMemory: WebAssembly.Memory,
3131
): IAttributeParser {
32-
const textDecoder = new TextDecoder();
3332
return function onMPDAttribute(attr: number, ptr: number, len: number) {
3433
switch (attr) {
3534
case AttributeName.Id:
36-
ccAttrs.id = parseString(textDecoder, linearMemory.buffer, ptr, len);
35+
ccAttrs.id = parseString(linearMemory.buffer, ptr, len);
3736
break;
3837

3938
case AttributeName.Language:
40-
ccAttrs.lang = parseString(textDecoder, linearMemory.buffer, ptr, len);
39+
ccAttrs.lang = parseString(linearMemory.buffer, ptr, len);
4140
break;
4241

4342
case AttributeName.ContentType:
44-
ccAttrs.contentType = parseString(textDecoder, linearMemory.buffer, ptr, len);
43+
ccAttrs.contentType = parseString(linearMemory.buffer, ptr, len);
4544
break;
4645

4746
case AttributeName.Par:
48-
ccAttrs.par = parseString(textDecoder, linearMemory.buffer, ptr, len);
47+
ccAttrs.par = parseString(linearMemory.buffer, ptr, len);
4948
break;
5049
}
5150
};

‎src/parsers/manifest/dash/wasm-parser/ts/generators/ContentProtection.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,32 @@ export function generateContentProtectionAttrParser(
3232
): IAttributeParser {
3333
const cpAttrs = cp.attributes;
3434
const cpChildren = cp.children;
35-
const textDecoder = new TextDecoder();
3635
return function onContentProtectionAttribute(attr: number, ptr: number, len: number) {
3736
switch (attr) {
3837
case AttributeName.SchemeIdUri:
39-
cpAttrs.schemeIdUri = parseString(textDecoder, linearMemory.buffer, ptr, len);
38+
cpAttrs.schemeIdUri = parseString(linearMemory.buffer, ptr, len);
4039
break;
4140
case AttributeName.ContentProtectionValue:
42-
cpAttrs.value = parseString(textDecoder, linearMemory.buffer, ptr, len);
41+
cpAttrs.value = parseString(linearMemory.buffer, ptr, len);
4342
break;
4443
case AttributeName.ContentProtectionKeyId: {
45-
const kid = parseString(textDecoder, linearMemory.buffer, ptr, len);
44+
const kid = parseString(linearMemory.buffer, ptr, len);
4645
cpAttrs["cenc:default_KID"] = hexToBytes(kid.replace(/-/g, ""));
4746
break;
4847
}
4948
case AttributeName.ContentProtectionCencPSSH:
5049
try {
51-
const b64 = parseString(textDecoder, linearMemory.buffer, ptr, len);
50+
const b64 = parseString(linearMemory.buffer, ptr, len);
5251
cpChildren["cenc:pssh"].push({ value: base64ToBytes(b64) });
5352
} catch (_) {
5453
/* TODO log error? register as warning? */
5554
}
5655
break;
5756
case AttributeName.ContentProtectionRef:
58-
cpAttrs.ref = parseString(textDecoder, linearMemory.buffer, ptr, len);
57+
cpAttrs.ref = parseString(linearMemory.buffer, ptr, len);
5958
break;
6059
case AttributeName.ContentProtectionRefId:
61-
cpAttrs.refId = parseString(textDecoder, linearMemory.buffer, ptr, len);
60+
cpAttrs.refId = parseString(linearMemory.buffer, ptr, len);
6261
break;
6362
}
6463
};

‎src/parsers/manifest/dash/wasm-parser/ts/generators/EventStream.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ export function generateEventStreamAttrParser(
6767
esAttrs: IEventStreamAttributes,
6868
linearMemory: WebAssembly.Memory,
6969
): IAttributeParser {
70-
const textDecoder = new TextDecoder();
7170
return function onEventStreamAttribute(attr: number, ptr: number, len: number) {
7271
const dataView = new DataView(linearMemory.buffer);
7372
switch (attr) {
7473
case AttributeName.SchemeIdUri:
75-
esAttrs.schemeIdUri = parseString(textDecoder, linearMemory.buffer, ptr, len);
74+
esAttrs.schemeIdUri = parseString(linearMemory.buffer, ptr, len);
7675
break;
7776
case AttributeName.SchemeValue:
78-
esAttrs.value = parseString(textDecoder, linearMemory.buffer, ptr, len);
77+
esAttrs.value = parseString(linearMemory.buffer, ptr, len);
7978
break;
8079
case AttributeName.TimeScale:
8180
esAttrs.timescale = dataView.getFloat64(ptr, true);
@@ -86,12 +85,12 @@ export function generateEventStreamAttrParser(
8685
const keySize = dataView.getUint32(offset);
8786
offset += 4;
8887

89-
xmlNs.key = parseString(textDecoder, linearMemory.buffer, offset, keySize);
88+
xmlNs.key = parseString(linearMemory.buffer, offset, keySize);
9089
offset += keySize;
9190

9291
const valSize = dataView.getUint32(offset);
9392
offset += 4;
94-
xmlNs.value = parseString(textDecoder, linearMemory.buffer, offset, valSize);
93+
xmlNs.value = parseString(linearMemory.buffer, offset, valSize);
9594

9695
if (esAttrs.namespaces === undefined) {
9796
esAttrs.namespaces = [xmlNs];
@@ -115,7 +114,6 @@ function generateEventAttrParser(
115114
linearMemory: WebAssembly.Memory,
116115
fullMpd: ArrayBufferLike,
117116
): IAttributeParser {
118-
const textDecoder = new TextDecoder();
119117
return function onEventStreamAttribute(attr: number, ptr: number, len: number) {
120118
const dataView = new DataView(linearMemory.buffer);
121119
switch (attr) {
@@ -126,7 +124,7 @@ function generateEventAttrParser(
126124
eventAttr.duration = dataView.getFloat64(ptr, true);
127125
break;
128126
case AttributeName.Id:
129-
eventAttr.id = parseString(textDecoder, linearMemory.buffer, ptr, len);
127+
eventAttr.id = parseString(linearMemory.buffer, ptr, len);
130128
break;
131129
case AttributeName.EventStreamEltRange: {
132130
const rangeStart = dataView.getFloat64(ptr, true);

‎src/parsers/manifest/dash/wasm-parser/ts/generators/Initialization.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export default function generateInitializationAttrParser(
77
initialization: IInitializationIntermediateRepresentation,
88
linearMemory: WebAssembly.Memory,
99
): IAttributeParser {
10-
const textDecoder = new TextDecoder();
1110
return function onInitializationAttribute(attr, ptr, len) {
1211
switch (attr) {
1312
case AttributeName.InitializationRange: {
@@ -21,7 +20,6 @@ export default function generateInitializationAttrParser(
2120

2221
case AttributeName.InitializationMedia:
2322
initialization.attributes.sourceURL = parseString(
24-
textDecoder,
2523
linearMemory.buffer,
2624
ptr,
2725
len,

‎src/parsers/manifest/dash/wasm-parser/ts/generators/Label.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ export function generateLabelElementParser(
77
adaptationSet: IAdaptationSetChildren,
88
linearMemory: WebAssembly.Memory,
99
): IAttributeParser {
10-
const textDecoder = new TextDecoder();
1110
return function onMPDAttribute(attr: AttributeName, ptr: number, len: number) {
1211
if (attr === AttributeName.Text) {
1312
adaptationSet.Label.push({
14-
value: parseString(textDecoder, linearMemory.buffer, ptr, len),
13+
value: parseString(linearMemory.buffer, ptr, len),
1514
});
1615
}
1716
};

‎src/parsers/manifest/dash/wasm-parser/ts/generators/MPD.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,29 @@ export function generateMPDAttrParser(
121121
linearMemory: WebAssembly.Memory,
122122
): IAttributeParser {
123123
let dataView;
124-
const textDecoder = new TextDecoder();
125124
return function onMPDAttribute(attr: number, ptr: number, len: number) {
126125
switch (attr) {
127126
case AttributeName.Id:
128-
mpdAttrs.id = parseString(textDecoder, linearMemory.buffer, ptr, len);
127+
mpdAttrs.id = parseString(linearMemory.buffer, ptr, len);
129128
break;
130129
case AttributeName.Profiles:
131-
mpdAttrs.profiles = parseString(textDecoder, linearMemory.buffer, ptr, len);
130+
mpdAttrs.profiles = parseString(linearMemory.buffer, ptr, len);
132131
break;
133132
case AttributeName.Type:
134-
mpdAttrs.type = parseString(textDecoder, linearMemory.buffer, ptr, len);
133+
mpdAttrs.type = parseString(linearMemory.buffer, ptr, len);
135134
break;
136135
case AttributeName.AvailabilityStartTime: {
137-
const startTime = parseString(textDecoder, linearMemory.buffer, ptr, len);
136+
const startTime = parseString(linearMemory.buffer, ptr, len);
138137
mpdAttrs.availabilityStartTime = new Date(startTime).getTime() / 1000;
139138
break;
140139
}
141140
case AttributeName.AvailabilityEndTime: {
142-
const endTime = parseString(textDecoder, linearMemory.buffer, ptr, len);
141+
const endTime = parseString(linearMemory.buffer, ptr, len);
143142
mpdAttrs.availabilityEndTime = new Date(endTime).getTime() / 1000;
144143
break;
145144
}
146145
case AttributeName.PublishTime: {
147-
const publishTime = parseString(textDecoder, linearMemory.buffer, ptr, len);
146+
const publishTime = parseString(linearMemory.buffer, ptr, len);
148147
mpdAttrs.publishTime = new Date(publishTime).getTime() / 1000;
149148
break;
150149
}
@@ -177,7 +176,7 @@ export function generateMPDAttrParser(
177176
mpdAttrs.maxSubsegmentDuration = dataView.getFloat64(ptr, true);
178177
break;
179178
case AttributeName.Location: {
180-
const location = parseString(textDecoder, linearMemory.buffer, ptr, len);
179+
const location = parseString(linearMemory.buffer, ptr, len);
181180
mpdChildren.Location.push({ value: location });
182181
break;
183182
}
@@ -188,12 +187,12 @@ export function generateMPDAttrParser(
188187
const keySize = dataView.getUint32(offset);
189188
offset += 4;
190189

191-
xmlNs.key = parseString(textDecoder, linearMemory.buffer, offset, keySize);
190+
xmlNs.key = parseString(linearMemory.buffer, offset, keySize);
192191
offset += keySize;
193192

194193
const valSize = dataView.getUint32(offset);
195194
offset += 4;
196-
xmlNs.value = parseString(textDecoder, linearMemory.buffer, offset, valSize);
195+
xmlNs.value = parseString(linearMemory.buffer, offset, valSize);
197196

198197
if (mpdAttrs.namespaces === undefined) {
199198
mpdAttrs.namespaces = [xmlNs];

‎src/parsers/manifest/dash/wasm-parser/ts/generators/Period.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ export function generatePeriodAttrParser(
164164
periodAttrs: IPeriodAttributes,
165165
linearMemory: WebAssembly.Memory,
166166
): IAttributeParser {
167-
const textDecoder = new TextDecoder();
168167
return function onPeriodAttribute(attr, ptr, len) {
169168
switch (attr) {
170169
case AttributeName.Id:
171-
periodAttrs.id = parseString(textDecoder, linearMemory.buffer, ptr, len);
170+
periodAttrs.id = parseString(linearMemory.buffer, ptr, len);
172171
break;
173172
case AttributeName.Start:
174173
periodAttrs.start = new DataView(linearMemory.buffer).getFloat64(ptr, true);
@@ -182,15 +181,13 @@ export function generatePeriodAttrParser(
182181
break;
183182
case AttributeName.XLinkHref:
184183
periodAttrs["xlink:href"] = parseString(
185-
textDecoder,
186184
linearMemory.buffer,
187185
ptr,
188186
len,
189187
);
190188
break;
191189
case AttributeName.XLinkActuate:
192190
periodAttrs["xlink:actuate"] = parseString(
193-
textDecoder,
194191
linearMemory.buffer,
195192
ptr,
196193
len,
@@ -213,12 +210,12 @@ export function generatePeriodAttrParser(
213210
const keySize = dataView.getUint32(offset);
214211
offset += 4;
215212

216-
xmlNs.key = parseString(textDecoder, linearMemory.buffer, offset, keySize);
213+
xmlNs.key = parseString(linearMemory.buffer, offset, keySize);
217214
offset += keySize;
218215

219216
const valSize = dataView.getUint32(offset);
220217
offset += 4;
221-
xmlNs.value = parseString(textDecoder, linearMemory.buffer, offset, valSize);
218+
xmlNs.value = parseString(linearMemory.buffer, offset, valSize);
222219

223220
if (periodAttrs.namespaces === undefined) {
224221
periodAttrs.namespaces = [xmlNs];

‎src/parsers/manifest/dash/wasm-parser/ts/generators/Representation.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,14 @@ export function generateRepresentationAttrParser(
179179
representationAttrs: IRepresentationAttributes,
180180
linearMemory: WebAssembly.Memory,
181181
): IAttributeParser {
182-
const textDecoder = new TextDecoder();
183182
return function onRepresentationAttribute(attr: number, ptr: number, len: number) {
184183
const dataView = new DataView(linearMemory.buffer);
185184
switch (attr) {
186185
case AttributeName.Id:
187-
representationAttrs.id = parseString(textDecoder, linearMemory.buffer, ptr, len);
186+
representationAttrs.id = parseString(linearMemory.buffer, ptr, len);
188187
break;
189188
case AttributeName.AudioSamplingRate:
190189
representationAttrs.audioSamplingRate = parseString(
191-
textDecoder,
192190
linearMemory.buffer,
193191
ptr,
194192
len,
@@ -199,15 +197,13 @@ export function generateRepresentationAttrParser(
199197
break;
200198
case AttributeName.Codecs:
201199
representationAttrs.codecs = parseString(
202-
textDecoder,
203200
linearMemory.buffer,
204201
ptr,
205202
len,
206203
);
207204
break;
208205
case AttributeName.SupplementalCodecs:
209206
representationAttrs["scte214:supplementalCodecs"] = parseString(
210-
textDecoder,
211207
linearMemory.buffer,
212208
ptr,
213209
len,
@@ -234,15 +230,13 @@ export function generateRepresentationAttrParser(
234230
break;
235231
case AttributeName.MimeType:
236232
representationAttrs.mimeType = parseString(
237-
textDecoder,
238233
linearMemory.buffer,
239234
ptr,
240235
len,
241236
);
242237
break;
243238
case AttributeName.Profiles:
244239
representationAttrs.profiles = parseString(
245-
textDecoder,
246240
linearMemory.buffer,
247241
ptr,
248242
len,
@@ -253,7 +247,6 @@ export function generateRepresentationAttrParser(
253247
break;
254248
case AttributeName.SegmentProfiles:
255249
representationAttrs.segmentProfiles = parseString(
256-
textDecoder,
257250
linearMemory.buffer,
258251
ptr,
259252
len,

0 commit comments

Comments
 (0)