Skip to content

Commit

Permalink
[POC} Only load media segments for Representations known to be deciph…
Browse files Browse the repository at this point in the history
…erable

Historically, the RxPlayer load media segments and perform the
license-fetching logic in parallel, as it theoretically lead to faster
playback when all qualities are decipherable.

However, this has always only been a theory and it may have the reverse
effect on devices whose some keys are not obtainable (this also is only
theoretical).

To better know what the impact of loading media segments in parallel or
after the license, I'm here only loading media segments (not the
initialization segment, which can be loaded right away) either if the
Representation is clear or is known to be decipherable.

This is only a Proof-Of-Concept with for now no intent to make it a
feature.
  • Loading branch information
peaBerberian committed Jul 31, 2024
1 parent 8ca7472 commit 7a935f8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/stream/representation/representation_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export default function RepresentationStream<TSegmentDataType>(
includeLastObservation: false,
clearSignal: segmentsLoadingCanceller.signal,
});
content.manifest.addEventListener(
"decipherabilityUpdate",
checkStatus,
segmentsLoadingCanceller.signal,
);
content.manifest.addEventListener(
"manifestUpdate",
checkStatus,
Expand Down Expand Up @@ -256,6 +261,12 @@ export default function RepresentationStream<TSegmentDataType>(

let neededInitSegment: IQueuedSegment | null = null;

// We'll load encrypted media segments only if we're sure they are
// decipherable.
const shouldLoadMediaSegments =
representation.contentProtections === undefined ||
representation.decipherable === true;

// Add initialization segment if required
if (!representation.index.isInitialized()) {
if (initSegmentState.segment === null) {
Expand Down Expand Up @@ -284,11 +295,13 @@ export default function RepresentationStream<TSegmentDataType>(
};
}

const mediaSegmentsToRequest = shouldLoadMediaSegments ? neededSegments : [];

const terminateVal = terminate.getValue();
if (terminateVal === null) {
lastSegmentQueue.setValue({
initSegment: neededInitSegment,
segmentQueue: neededSegments,
segmentQueue: mediaSegmentsToRequest,
});
} else if (terminateVal.urgent) {
log.debug("Stream: Urgent switch, terminate now.", bufferType);
Expand All @@ -303,7 +316,7 @@ export default function RepresentationStream<TSegmentDataType>(
// terminate once either that request is finished or another segment
// is wanted instead, whichever comes first.

const mostNeededSegment = neededSegments[0];
const mostNeededSegment = mediaSegmentsToRequest[0];
const initSegmentRequest = downloadingQueue.getRequestedInitSegment();
const currentSegmentRequest = downloadingQueue.getRequestedMediaSegment();

Expand Down

0 comments on commit 7a935f8

Please sign in to comment.