Skip to content

Commit

Permalink
Merge pull request #1566 from canalplus/fix/check-source-buffer-remov…
Browse files Browse the repository at this point in the history
…e-arguments-v3

[v3] Fix some issues that may arise on BUFFER_FULL situations
  • Loading branch information
peaBerberian authored Oct 15, 2024
2 parents 54a1399 + 55e184a commit c5348ac
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/core/stream/adaptation/adaptation_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export default function AdaptationStream<T>(
const bufferGoal = createMappedReference(
wantedBufferAhead,
(prev) => {
return prev * getBufferGoalRatio(representation);
return getBufferGoal(representation, prev);
},
terminatingRepStreamCanceller.signal,
);
Expand All @@ -348,10 +348,11 @@ export default function AdaptationStream<T>(
const lastBufferGoalRatio = bufferGoalRatioMap.get(representation.id) ?? 1;
// 70%, 49%, 34.3%, 24%, 16.81%, 11.76%, 8.24% and 5.76%
const newBufferGoalRatio = lastBufferGoalRatio * 0.7;
if (newBufferGoalRatio <= 0.05 || wba * newBufferGoalRatio <= 2) {
throw formattedError;
}
bufferGoalRatioMap.set(representation.id, newBufferGoalRatio);
if (newBufferGoalRatio <= 0.05 || getBufferGoal(representation, wba) <= 2) {
representationStreamCallbacks.error(formattedError);
return;
}

// We wait 4 seconds to let the situation evolve by itself before
// retrying loading segments with a lower buffer goal
Expand Down Expand Up @@ -392,15 +393,25 @@ export default function AdaptationStream<T>(
}

/**
* @param {Object} representation
* Returns how much media data should be pre-buffered for this
* `Representation`, according to the `wantedBufferAhead` setting and previous
* issues encountered with that `Representation`.
* @param {Object} representation - The `Representation` you want to buffer.
* @param {number} wba - The value of `wantedBufferAhead` set by the user.
* @returns {number}
*/
function getBufferGoalRatio(representation: Representation): number {
function getBufferGoal(representation: Representation, wba: number): number {
const oldBufferGoalRatio = bufferGoalRatioMap.get(representation.id);
const bufferGoalRatio = oldBufferGoalRatio !== undefined ? oldBufferGoalRatio : 1;
if (oldBufferGoalRatio === undefined) {
bufferGoalRatioMap.set(representation.id, bufferGoalRatio);
}
return bufferGoalRatio;
if (bufferGoalRatio < 1 && wba === Infinity) {
// When `wba` is equal to `Infinity`, dividing it will still make it equal
// to `Infinity`. To make the `bufferGoalRatio` still have an effect, we
// just starts from a `wba` set to the high value of 5 minutes.
return 5 * 60 * 1000 * bufferGoalRatio;
}
return wba * bufferGoalRatio;
}
}

0 comments on commit c5348ac

Please sign in to comment.