Skip to content

Commit

Permalink
feat: Support customizing clearBuffers and safeMargin when select var…
Browse files Browse the repository at this point in the history
…iants by label (shaka-project#4770)

Currently, selectVariantsByLabel doesn't support customizing
clearBuffers and safeMargin. This pr is to change the function
signature, so that we'll able to decide if we want to keep some amount
of buffer when we change track.
  • Loading branch information
lindsayrr committed Dec 1, 2022
1 parent 5d6f56a commit c724625
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -88,6 +88,7 @@ ViacomCBS <*@viacomcbs.com>
Vincent Valot <valot.vince@gmail.com>
V-Nova Limited <*@v-nova.com>
Wayne Morgan <wayne.morgan.dev@gmail.com>
Wen Ren <renwen0615@gmail.com>
Raymond Cheng <raycheng100@gmail.com>
Blue Billywig <*@bluebillywig.com>
João Nabais <jlnabais@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -127,6 +127,7 @@ Vignesh Venkatasubramanian <vigneshv@google.com>
Vincent Valot <valot.vince@gmail.com>
Vinod Balakrishnan <vinod.balakrishnan@v-nova.com>
Wayne Morgan <wayne.morgan.dev@gmail.com>
Wen Ren <renwen0615@gmail.com>
Yohann Connell <robinconnell@google.com>
Raymond Cheng <raycheng100@gmail.com>
Janroel Koppen <j.koppen@bluebillywig.com>
Expand Down
20 changes: 16 additions & 4 deletions lib/player.js
Expand Up @@ -4242,9 +4242,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* are expected to have the same variant.audio.
*
* @param {string} label
* @param {boolean=} clearBuffer Optional clear buffer or not when
* switch to new variant
* Defaults to true if not provided
* @param {number=} safeMargin Optional amount of buffer (in seconds) to
* retain when clearing the buffer.
* Defaults to 0 if not provided. Ignored if clearBuffer is false.
* @export
*/
selectVariantsByLabel(label) {
selectVariantsByLabel(label, clearBuffer = true, safeMargin = 0) {
if (this.manifest_ && this.playhead_) {
let firstVariantWithLabel = null;
for (const variant of this.manifest_.variants) {
Expand All @@ -4268,7 +4274,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
new shaka.media.PreferenceBasedCriteria(
firstVariantWithLabel.language, '', 0, label);

this.chooseVariantAndSwitch_();
this.chooseVariantAndSwitch_(clearBuffer, safeMargin);
}
}

Expand Down Expand Up @@ -5713,9 +5719,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* Called after a config change, a key status event, or an explicit language
* change.
*
* @param {boolean=} clearBuffer Optional clear buffer or not when
* switch to new variant
* Defaults to true if not provided
* @param {number=} safeMargin Optional amount of buffer (in seconds) to
* retain when clearing the buffer.
* Defaults to 0 if not provided. Ignored if clearBuffer is false.
* @private
*/
chooseVariantAndSwitch_() {
chooseVariantAndSwitch_(clearBuffer = true, safeMargin = 0) {
goog.asserts.assert(this.config_, 'Must not be destroyed');

// Because we're running this after a config change (manual language
Expand All @@ -5724,7 +5736,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
const chosenVariant = this.chooseVariant_();
if (chosenVariant) {
this.switchVariant_(chosenVariant, /* fromAdaptation= */ true,
/* clearBuffers= */ true, /* safeMargin= */ 0);
clearBuffer, safeMargin);
}
}

Expand Down

0 comments on commit c724625

Please sign in to comment.