Skip to content

Commit

Permalink
feat: Add partial info to shaka.media.SegmentReference (#5822)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Oct 30, 2023
1 parent 3f392c0 commit 766b0a1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
53 changes: 53 additions & 0 deletions lib/media/segment_reference.js
Expand Up @@ -289,6 +289,21 @@ shaka.media.SegmentReference = class {

/** @type {boolean} */
this.allPartialSegments = allPartialSegments;

/** @type {boolean} */
this.partial = false;

/** @type {boolean} */
this.lastPartial = false;

for (const partial of this.partialReferences) {
partial.markAsPartial();
}
if (this.allPartialSegments && this.partialReferences.length) {
const lastPartial =
this.partialReferences[this.partialReferences.length - 1];
lastPartial.markAsLastPartial();
}
}

/**
Expand Down Expand Up @@ -450,6 +465,44 @@ shaka.media.SegmentReference = class {
return this.independent;
}

/**
* Mark the reference as partial.
*
* @export
*/
markAsPartial() {
this.partial = true;
}

/**
* Returns true if the segment is partial.
*
* @return {boolean}
* @export
*/
isPartial() {
return this.partial;
}

/**
* Mark the reference as being the last part of the full segment
*
* @export
*/
markAsLastPartial() {
this.lastPartial = true;
}

/**
* Returns true if reference as being the last part of the full segment.
*
* @return {boolean}
* @export
*/
isLastPartial() {
return this.lastPartial;
}

/**
* Mark the reference as byterange optimization.
*
Expand Down
5 changes: 5 additions & 0 deletions test/hls/hls_live_unit.js
Expand Up @@ -688,10 +688,13 @@ describe('HlsParser live', () => {
const partialRef = makeReference(
'test:/partial.mp4', 0, 2, /* syncTime= */ null,
/* baseUri= */ '', /* startByte= */ 0, /* endByte= */ null);
partialRef.partial = true;

const partialRef2 = makeReference(
'test:/partial2.mp4', 2, 4, /* syncTime= */ null,
/* baseUri= */ '', /* startByte= */ 0, /* endByte= */ null);
partialRef2.partial = true;
partialRef2.lastPartial = true;

const ref = makeReference(
'test:/main.mp4', 0, 4, /* syncTime= */ null,
Expand All @@ -702,10 +705,12 @@ describe('HlsParser live', () => {
const partialRef3 = makeReference(
'test:/partial.mp4', 4, 6, /* syncTime= */ null,
/* baseUri= */ '', /* startByte= */ 0, /* endByte= */ null);
partialRef3.partial = true;

const preloadRef = makeReference(
'test:/partial.mp4', 6, 7.5, /* syncTime= */ null,
/* baseUri= */ '', /* startByte= */ 0, /* endByte= */ null);
preloadRef.partial = true;
preloadRef.markAsPreload();
preloadRef.markAsNonIndependent();

Expand Down
11 changes: 7 additions & 4 deletions test/hls/hls_parser_unit.js
Expand Up @@ -2919,10 +2919,13 @@ describe('HlsParser', () => {
'main.mp4',
].join(''), [0, 5, 10, 15, 20, 25], syncTimeBase + 5, (reference) => {
if (reference.startTime == 10) {
reference.partialReferences = [
makeReference(10, 12.5, syncTimeBase + 15),
makeReference(12.5, 15, syncTimeBase + 17.5),
];
const partialRef = makeReference(10, 12.5, syncTimeBase + 15);
partialRef.partial = true;
const partialRef2 = makeReference(12.5, 15, syncTimeBase + 17.5);
partialRef2.partial = true;
partialRef2.lastPartial = true;

reference.partialReferences = [partialRef, partialRef2];
reference.allPartialSegments = true;
}
});
Expand Down

0 comments on commit 766b0a1

Please sign in to comment.