Skip to content

Commit

Permalink
feat(CMCD): Implement new streaming format from CMCDv2 (#7216)
Browse files Browse the repository at this point in the history
This aligns Shaka's implementation with what Apple's native player will
return when CMCD is enabled, see:
https://developer.apple.com/streaming/Whats-new-HLS.pdf
  • Loading branch information
avelad authored Aug 27, 2024
1 parent c5df88b commit 8842648
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,11 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
'https://bit.ly/3clctcj for details.');
}

if (this.cmcdManager_) {
this.cmcdManager_.setLowLatency(
this.manifest_.isLowLatency && this.config_.streaming.lowLatencyMode);
}

shaka.Player.applyPlayRange_(this.manifest_.presentationTimeline,
this.config_.playRangeStart,
this.config_.playRangeEnd);
Expand Down
38 changes: 38 additions & 0 deletions lib/util/cmcd_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ shaka.util.CmcdManager = class {
* @private {boolean}
*/
this.starved_ = false;

/**
* @private {boolean}
*/
this.lowLatency_ = false;
}

/**
Expand All @@ -71,6 +76,7 @@ shaka.util.CmcdManager = class {
this.playbackStarted_ = false;
this.buffering_ = true;
this.starved_ = false;
this.lowLatency_ = false;
}

/**
Expand All @@ -90,6 +96,30 @@ shaka.util.CmcdManager = class {
this.buffering_ = buffering;
}

/**
* Set the low latency
*
* @param {boolean} lowLatency
*/
setLowLatency(lowLatency) {
this.lowLatency_ = lowLatency;

const StreamingFormat = shaka.util.CmcdManager.StreamingFormat;
if (this.lowLatency_) {
if (this.sf_ == StreamingFormat.DASH) {
this.sf_ = StreamingFormat.LOW_LATENCY_DASH;
} else if (this.sf_ == StreamingFormat.HLS) {
this.sf_ = StreamingFormat.LOW_LATENCY_HLS;
}
} else {
if (this.sf_ == StreamingFormat.LOW_LATENCY_DASH) {
this.sf_ = StreamingFormat.DASH;
} else if (this.sf_ == StreamingFormat.LOW_LATENCY_HLS) {
this.sf_ = StreamingFormat.HLS;
}
}
}

/**
* Apply CMCD data to a request.
*
Expand Down Expand Up @@ -624,10 +654,16 @@ shaka.util.CmcdManager = class {

switch (type) {
case AdvancedRequestType.MPD:
if (this.lowLatency_) {
return shaka.util.CmcdManager.StreamingFormat.LOW_LATENCY_DASH;
}
return shaka.util.CmcdManager.StreamingFormat.DASH;

case AdvancedRequestType.MASTER_PLAYLIST:
case AdvancedRequestType.MEDIA_PLAYLIST:
if (this.lowLatency_) {
return shaka.util.CmcdManager.StreamingFormat.LOW_LATENCY_HLS;
}
return shaka.util.CmcdManager.StreamingFormat.HLS;

case AdvancedRequestType.MSS:
Expand Down Expand Up @@ -887,7 +923,9 @@ shaka.util.CmcdManager.StreamType = {
*/
shaka.util.CmcdManager.StreamingFormat = {
DASH: 'd',
LOW_LATENCY_DASH: 'ld',
HLS: 'h',
LOW_LATENCY_HLS: 'lh',
SMOOTH: 's',
OTHER: 'o',
};
Expand Down

0 comments on commit 8842648

Please sign in to comment.