Skip to content

Commit

Permalink
feat(hls): Add support for EXT-X-GAP
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Velad committed May 10, 2022
1 parent df23e43 commit 49b6930
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
9 changes: 4 additions & 5 deletions lib/media/segment_reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ shaka.media.SegmentReference = class {
}

/**
* Mark the reference as unavailable.
* Returns if the segment's is missing.
*
* @export
*/
markAsUnavailable() {
this.status = shaka.media.SegmentReference.Status.UNAVAILABLE;
isMissing() {
return this.status == shaka.media.SegmentReference.Status.MISSING;
}
};

Expand All @@ -352,8 +352,7 @@ shaka.media.SegmentReference = class {
*/
shaka.media.SegmentReference.Status = {
AVAILABLE: 0,
UNAVAILABLE: 1,
MISSING: 2,
MISSING: 1,
};


Expand Down
6 changes: 6 additions & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,12 @@ shaka.media.StreamingEngine = class {
mediaState.performingUpdate = true;

try {
if (reference.isMissing()) {
throw new shaka.util.Error(
shaka.util.Error.Severity.RECOVERABLE,
shaka.util.Error.Category.NETWORK,
shaka.util.Error.Code.SEGMENT_MISSING);
}
await this.initSourceBuffer_(mediaState, reference);
this.destroyer_.ensureNotDestroyed();
if (this.fatalError_) {
Expand Down
13 changes: 9 additions & 4 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5521,14 +5521,19 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* @private
*/
tryToRecoverFromError_(error) {
if (error.code !== shaka.util.Error.Code.HTTP_ERROR ||
error.category !== shaka.util.Error.Category.NETWORK) {
if ((error.code != shaka.util.Error.Code.HTTP_ERROR &&
error.code != shaka.util.Error.Code.SEGMENT_MISSING) ||
error.category != shaka.util.Error.Category.NETWORK) {
return false;
}

const maxDisabledTime = this.config_.streaming.maxDisabledTime;
let maxDisabledTime = this.config_.streaming.maxDisabledTime;
if (maxDisabledTime == 0) {
return false;
if (error.code == shaka.util.Error.Code.SEGMENT_MISSING) {
maxDisabledTime = 1;
} else {
return false;
}
}

shaka.log.debug('Recoverable NETWORK HTTP_ERROR, trying to recover...');
Expand Down
6 changes: 6 additions & 0 deletions lib/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ shaka.util.Error.Code = {
*/
'ATTEMPTS_EXHAUSTED': 1010,

/**
* The segment is missing.
* <br> error.data[0] is the URI.
*/
'SEGMENT_MISSING': 1011,


/** The text parser failed to parse a text stream due to an invalid header. */
'INVALID_TEXT_HEADER': 2000,
Expand Down
15 changes: 6 additions & 9 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,9 +1538,6 @@ describe('HlsParser', () => {
expect(variant.video).toBeTruthy();
expect(variant.audio).toBeTruthy();

const available = shaka.media.SegmentReference.Status.AVAILABLE;
const missing = shaka.media.SegmentReference.Status.MISSING;

await variant.video.createSegmentIndex();
goog.asserts.assert(variant.video.segmentIndex != null,
'Null segmentIndex!');
Expand All @@ -1554,13 +1551,13 @@ describe('HlsParser', () => {
expect(thirdVideoReference).not.toBe(null);

if (firstVideoReference) {
expect(firstVideoReference.getStatus()).toBe(available);
expect(firstVideoReference.isMissing()).toBe(false);
}
if (secondVideoReference) {
expect(secondVideoReference.getStatus()).toBe(missing);
expect(secondVideoReference.isMissing()).toBeTruthy();
}
if (thirdVideoReference) {
expect(thirdVideoReference.getStatus()).toBe(available);
expect(thirdVideoReference.isMissing()).toBe(false);
}

await variant.audio.createSegmentIndex();
Expand All @@ -1576,13 +1573,13 @@ describe('HlsParser', () => {
expect(thirdAudioReference).not.toBe(null);

if (firstAudioReference) {
expect(firstAudioReference.getStatus()).toBe(available);
expect(firstAudioReference.isMissing()).toBe(false);
}
if (secondAudioReference) {
expect(secondAudioReference.getStatus()).toBe(missing);
expect(secondAudioReference.isMissing()).toBeTruthy();
}
if (thirdAudioReference) {
expect(thirdAudioReference.getStatus()).toBe(available);
expect(thirdAudioReference.isMissing()).toBe(false);
}
});

Expand Down

0 comments on commit 49b6930

Please sign in to comment.