@@ -96,7 +96,8 @@ shaka.dash.SegmentTemplate = class {
96
96
generateSegmentIndex : ( ) => {
97
97
return SegmentTemplate . generateSegmentIndexFromDuration_ (
98
98
shallowCopyOfContext , info , segmentLimit , initSegmentReference ,
99
- periodDurationMap , aesKey , lastSegmentNumber ) ;
99
+ periodDurationMap , aesKey , lastSegmentNumber ,
100
+ context . representation . segmentSequenceCadence ) ;
100
101
} ,
101
102
} ;
102
103
} else {
@@ -253,6 +254,14 @@ shaka.dash.SegmentTemplate = class {
253
254
const index = MpdUtils . inheritAttribute (
254
255
context , SegmentTemplate . fromInheritance_ , 'index' ) ;
255
256
257
+ const k = MpdUtils . inheritAttribute (
258
+ context , SegmentTemplate . fromInheritance_ , 'k' ) ;
259
+
260
+ let numChunks = 0 ;
261
+ if ( k ) {
262
+ numChunks = parseInt ( k , 10 ) ;
263
+ }
264
+
256
265
return {
257
266
segmentDuration : segmentInfo . segmentDuration ,
258
267
timescale : segmentInfo . timescale ,
@@ -265,6 +274,7 @@ shaka.dash.SegmentTemplate = class {
265
274
indexTemplate : index ,
266
275
mimeType : context . representation . mimeType ,
267
276
codecs : context . representation . codecs ,
277
+ numChunks : numChunks ,
268
278
} ;
269
279
}
270
280
@@ -358,12 +368,13 @@ shaka.dash.SegmentTemplate = class {
358
368
* @param {!Object.<string, number> } periodDurationMap
359
369
* @param {shaka.extern.aesKey|undefined } aesKey
360
370
* @param {?number } lastSegmentNumber
371
+ * @param {number } segmentSequenceCadence
361
372
* @return {!Promise.<shaka.media.SegmentIndex> }
362
373
* @private
363
374
*/
364
375
static generateSegmentIndexFromDuration_ (
365
376
context , info , segmentLimit , initSegmentReference , periodDurationMap ,
366
- aesKey , lastSegmentNumber ) {
377
+ aesKey , lastSegmentNumber , segmentSequenceCadence ) {
367
378
goog . asserts . assert ( info . mediaTemplate ,
368
379
'There should be a media template with duration' ) ;
369
380
@@ -483,16 +494,6 @@ shaka.dash.SegmentTemplate = class {
483
494
const segmentMediaTime = segmentPeriodTime +
484
495
info . scaledPresentationTimeOffset ;
485
496
486
- const getUris = ( ) => {
487
- let time = segmentMediaTime * timescale ;
488
- if ( 'BigInt' in window && time > Number . MAX_SAFE_INTEGER ) {
489
- time = BigInt ( segmentMediaTime ) * BigInt ( timescale ) ;
490
- }
491
- const mediaUri = MpdUtils . fillUriTemplate (
492
- template , id , position , /* subNumber= */ null , bandwidth , time ) ;
493
- return ManifestParserUtils . resolveUris ( getBaseUris ( ) , [ mediaUri ] ) ;
494
- } ;
495
-
496
497
// Relative to the presentation.
497
498
const segmentStart = segmentPeriodTime + periodStart ;
498
499
const trueSegmentEnd = segmentStart + segmentDuration ;
@@ -505,6 +506,67 @@ shaka.dash.SegmentTemplate = class {
505
506
goog . asserts . assert ( segmentStart < segmentEnd ,
506
507
'Generated a segment outside of the period!' ) ;
507
508
509
+ const partialSegmentRefs = [ ] ;
510
+
511
+ const numChunks = info . numChunks ;
512
+ if ( numChunks ) {
513
+ const partialDuration = ( segmentEnd - segmentStart ) / numChunks ;
514
+
515
+ for ( let i = 0 ; i < numChunks ; i ++ ) {
516
+ const start = segmentStart + partialDuration * i ;
517
+ const end = start + partialDuration ;
518
+ const subNumber = i + 1 ;
519
+ const getPartialUris = ( ) => {
520
+ let time = segmentMediaTime * timescale ;
521
+ if ( 'BigInt' in window && time > Number . MAX_SAFE_INTEGER ) {
522
+ time = BigInt ( segmentMediaTime ) * BigInt ( timescale ) ;
523
+ }
524
+ const mediaUri = MpdUtils . fillUriTemplate (
525
+ template , id , position , subNumber , bandwidth , time ) ;
526
+ return ManifestParserUtils . resolveUris ( getBaseUris ( ) , [ mediaUri ] ) ;
527
+ } ;
528
+ const partial = new shaka . media . SegmentReference (
529
+ start ,
530
+ end ,
531
+ getPartialUris ,
532
+ /* startByte= */ 0 ,
533
+ /* endByte= */ null ,
534
+ initSegmentReference ,
535
+ timestampOffset ,
536
+ /* appendWindowStart= */ periodStart ,
537
+ /* appendWindowEnd= */ getPeriodEnd ( ) ,
538
+ /* partialReferences= */ [ ] ,
539
+ /* tilesLayout= */ '' ,
540
+ /* tileDuration= */ null ,
541
+ /* syncTime= */ null ,
542
+ shaka . media . SegmentReference . Status . AVAILABLE ,
543
+ aesKey ) ;
544
+ partial . codecs = context . representation . codecs ;
545
+ partial . mimeType = context . representation . mimeType ;
546
+ if ( segmentSequenceCadence == 0 ) {
547
+ if ( i > 0 ) {
548
+ partial . markAsNonIndependent ( ) ;
549
+ }
550
+ } else if ( ( i % segmentSequenceCadence ) != 0 ) {
551
+ partial . markAsNonIndependent ( ) ;
552
+ }
553
+ partialSegmentRefs . push ( partial ) ;
554
+ }
555
+ }
556
+
557
+ const getUris = ( ) => {
558
+ if ( numChunks ) {
559
+ return [ ] ;
560
+ }
561
+ let time = segmentMediaTime * timescale ;
562
+ if ( 'BigInt' in window && time > Number . MAX_SAFE_INTEGER ) {
563
+ time = BigInt ( segmentMediaTime ) * BigInt ( timescale ) ;
564
+ }
565
+ const mediaUri = MpdUtils . fillUriTemplate (
566
+ template , id , position , /* subNumber= */ null , bandwidth , time ) ;
567
+ return ManifestParserUtils . resolveUris ( getBaseUris ( ) , [ mediaUri ] ) ;
568
+ } ;
569
+
508
570
const ref = new shaka . media . SegmentReference (
509
571
segmentStart ,
510
572
segmentEnd ,
@@ -515,7 +577,7 @@ shaka.dash.SegmentTemplate = class {
515
577
timestampOffset ,
516
578
/* appendWindowStart= */ periodStart ,
517
579
/* appendWindowEnd= */ getPeriodEnd ( ) ,
518
- /* partialReferences= */ [ ] ,
580
+ partialSegmentRefs ,
519
581
/* tilesLayout= */ '' ,
520
582
/* tileDuration= */ null ,
521
583
/* syncTime= */ null ,
@@ -1058,7 +1120,8 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
1058
1120
* mediaTemplate: ?string,
1059
1121
* indexTemplate: ?string,
1060
1122
* mimeType: string,
1061
- * codecs: string
1123
+ * codecs: string,
1124
+ * numChunks: number
1062
1125
* }}
1063
1126
*
1064
1127
* @description
@@ -1084,5 +1147,7 @@ shaka.dash.TimelineSegmentIndex = class extends shaka.media.SegmentIndex {
1084
1147
* The mimeType.
1085
1148
* @property {string } codecs
1086
1149
* The codecs.
1150
+ * @property {number } numChunks
1151
+ * The number of chunks in each segment.
1087
1152
*/
1088
1153
shaka . dash . SegmentTemplate . SegmentTemplateInfo ;
0 commit comments