@@ -226,13 +226,24 @@ export interface InitDataTrack {
226
226
supplemental : string | undefined ;
227
227
}
228
228
229
- type HdlrType = ElementaryStreamTypes . AUDIO | ElementaryStreamTypes . VIDEO ;
229
+ type HdlrMetadata = 'meta' ;
230
+ type HdlrType =
231
+ | ElementaryStreamTypes . AUDIO
232
+ | ElementaryStreamTypes . VIDEO
233
+ | HdlrMetadata ;
234
+
235
+ type StsdData = {
236
+ codec : string ;
237
+ encrypted : boolean ;
238
+ supplemental : string | undefined ;
239
+ } ;
230
240
231
241
export interface InitData extends Array < any > {
232
242
[ index : number ] :
233
243
| {
234
244
timescale : number ;
235
245
type : HdlrType ;
246
+ stsd : StsdData ;
236
247
default ?: {
237
248
duration : number ;
238
249
flags : number ;
@@ -266,10 +277,20 @@ export function parseInitSegment(initSegment: Uint8Array): InitData {
266
277
} [ hdlrType ] ;
267
278
if ( type ) {
268
279
// Parse codec details
269
- const stsd = findBox ( trak , [ 'mdia' , 'minf' , 'stbl' , 'stsd' ] ) [ 0 ] ;
270
- const stsdData = parseStsd ( stsd ) ;
271
- result [ trackId ] = { timescale, type } ;
272
- result [ type ] = { timescale, id : trackId , ...stsdData } ;
280
+ const stsdBox = findBox ( trak , [ 'mdia' , 'minf' , 'stbl' , 'stsd' ] ) [ 0 ] ;
281
+ const stsd = parseStsd ( stsdBox ) ;
282
+ if ( type ) {
283
+ // Add 'audio', 'video', and 'audiovideo' track records that will map to SourceBuffers
284
+ result [ trackId ] = { timescale, type, stsd } ;
285
+ result [ type ] = { timescale, id : trackId , ...stsd } ;
286
+ } else {
287
+ // Add 'meta' and other track records required by `offsetStartDTS`
288
+ result [ trackId ] = {
289
+ timescale,
290
+ type : hdlrType as HdlrType ,
291
+ stsd,
292
+ } ;
293
+ }
273
294
}
274
295
}
275
296
}
@@ -291,11 +312,7 @@ export function parseInitSegment(initSegment: Uint8Array): InitData {
291
312
return result ;
292
313
}
293
314
294
- function parseStsd ( stsd : Uint8Array ) : {
295
- codec : string ;
296
- encrypted : boolean ;
297
- supplemental : string | undefined ;
298
- } {
315
+ function parseStsd ( stsd : Uint8Array ) : StsdData {
299
316
const sampleEntries = stsd . subarray ( 8 ) ;
300
317
const sampleEntriesEnd = sampleEntries . subarray ( 8 + 78 ) ;
301
318
const fourCC = bin2str ( sampleEntries . subarray ( 4 , 8 ) ) ;
@@ -818,6 +835,7 @@ export function computeRawDurationFromSamples(trun): number {
818
835
return duration ;
819
836
}
820
837
838
+ // TODO: Remove `offsetStartDTS` in favor of using `timestampOffset` (issue #5715)
821
839
export function offsetStartDTS (
822
840
initData : InitData ,
823
841
fmp4 : Uint8Array ,
0 commit comments