Skip to content

Commit

Permalink
fix: Missing AES-128 key of last HLS segment (shaka-project#4519)
Browse files Browse the repository at this point in the history
When fitting the segment references to the timeline, some properties
were lost, including the AES-128 key.  This fixes those missing properties.

Closes shaka-project#4517
  • Loading branch information
devsunb committed Oct 4, 2022
1 parent 4e93311 commit 3d0f752
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -37,6 +37,7 @@ Giorgio Gamberoni <giorgio.gamberoni@gmail.com>
Giuseppe Samela <giuseppe.samela@gmail.com>
Google Inc. <*@google.com>
Itay Kinnrot <Itay.Kinnrot@Kaltura.com>
Jaeseok Lee <devsunb@gmail.com>
Jason Palmer <jason@jason-palmer.com>
Jesper Haug Karsrud <jesper.karsrud@gmail.com>
Johan Sundström <oyasumi@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -57,6 +57,7 @@ Hichem Taoufik <hichem@code-it.fr>
Itay Kinnrot <itay.kinnrot@kaltura.com>
Isaac Ramirez <isaac.ramirez.herrera@gmail.com>
Jacob Trimble <modmaker@google.com>
Jaeseok Lee <devsunb@gmail.com>
Jason Palmer <jason@jason-palmer.com>
Jeffrey Swan <jeffdswan@gmail.com>
Jesper Haug Karsrud <jesper.karsrud@gmail.com>
Expand Down
5 changes: 4 additions & 1 deletion lib/media/segment_index.js
Expand Up @@ -364,7 +364,10 @@ shaka.media.SegmentIndex = class {
lastReference.partialReferences,
lastReference.tilesLayout,
lastReference.tileDuration,
lastReference.syncTime);
lastReference.syncTime,
lastReference.status,
lastReference.hlsAes128Key,
);
}


Expand Down
30 changes: 28 additions & 2 deletions test/media/segment_index_unit.js
Expand Up @@ -207,6 +207,25 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
];
expect(index.references).toEqual(newReferences);
});

it('preserves hls key of the last reference', () => {
// The hls key of the last segment should be preserved.
const references = [
makeReference(uri(0), 0, 5, [],
{method: 'AES-128', firstMediaSequenceNumber: 0}),
makeReference(uri(1), 5, 10, [],
{method: 'AES-128', firstMediaSequenceNumber: 0}),
makeReference(uri(2), 10, 15, [],
{method: 'AES-128', firstMediaSequenceNumber: 0}),
];
const index = new shaka.media.SegmentIndex(references);
expect(index.references).toEqual(references);

index.fit(/* windowStart= */ 0, /* windowEnd= */ 10);
expect(
index.references[index.references.length - 1].hlsAes128Key,
).toEqual({method: 'AES-128', firstMediaSequenceNumber: 0});
});
});

describe('merge', () => {
Expand Down Expand Up @@ -955,9 +974,11 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
* @param {number} startTime
* @param {number} endTime
* @param {!Array.<!shaka.media.SegmentReference>=} partialReferences
* @param {?shaka.extern.HlsAes128Key=} hlsAes128Key
* @return {shaka.media.SegmentReference}
*/
function makeReference(uri, startTime, endTime, partialReferences = []) {
function makeReference(uri, startTime, endTime, partialReferences = [],
hlsAes128Key = null) {
return new shaka.media.SegmentReference(
startTime,
endTime,
Expand All @@ -968,6 +989,11 @@ describe('SegmentIndex', /** @suppress {accessControls} */ () => {
/* timestampOffset= */ 0,
/* appendWindowStart= */ 0,
/* appendWindowEnd= */ Infinity,
/* partialReferences= */ partialReferences);
/* partialReferences= */ partialReferences,
/* tilesLayout= */ undefined,
/* tileDuration= */ undefined,
/* syncTime= */ undefined,
/* status= */ undefined,
/* hlsAes128Key= */ hlsAes128Key);
}
});

0 comments on commit 3d0f752

Please sign in to comment.