Browse Source

feat: let back buffer be configurable

Introduces a new config option BACK_BUFFER_LENGTH that defaults to 30,
the previous value.
When set, we trim the back buffer according to the provided value.
pull/875/head
Lars Erik G-K 5 years ago
committed by Gary Katsevman
parent
commit
8c96e6c614
  1. 1
      src/config.js
  2. 6
      src/segment-loader.js
  3. 3
      src/videojs-http-streaming.js
  4. 32
      test/configuration.test.js

1
src/config.js

@ -1,6 +1,7 @@
export default {
GOAL_BUFFER_LENGTH: 30,
MAX_GOAL_BUFFER_LENGTH: 60,
BACK_BUFFER_LENGTH: 30,
GOAL_BUFFER_LENGTH_RATE: 1,
// 0.5 MB/s
INITIAL_BANDWIDTH: 4194304,

6
src/segment-loader.js

@ -53,7 +53,7 @@ export const illegalMediaSwitch = (loaderType, startingMedia, trackInfo) => {
};
/**
* Calculates a time value that is safe to remove from the back buffer without interupting
* Calculates a time value that is safe to remove from the back buffer without interrupting
* playback.
*
* @param {TimeRange} seekable
@ -63,7 +63,7 @@ export const illegalMediaSwitch = (loaderType, startingMedia, trackInfo) => {
* @param {number} targetDuration
* The target duration of the current playlist
* @return {number}
* Time that is safe to remove from the back buffer without interupting playback
* Time that is safe to remove from the back buffer without interrupting playback
*/
export const safeBackBufferTrimTime = (seekable, currentTime, targetDuration) => {
// 30 seconds before the playhead provides a safe default for trimming.
@ -71,7 +71,7 @@ export const safeBackBufferTrimTime = (seekable, currentTime, targetDuration) =>
// Choosing a reasonable default is particularly important for high bitrate content and
// VOD videos/live streams with large windows, as the buffer may end up overfilled and
// throw an APPEND_BUFFER_ERR.
let trimTime = currentTime - 30;
let trimTime = currentTime - Config.BACK_BUFFER_LENGTH;
if (seekable.length) {
// Some live playlists may have a shorter window of content than the full allowed back

3
src/videojs-http-streaming.js

@ -48,10 +48,11 @@ const Vhs = {
xhr: xhrFactory()
};
// Define getter/setters for config properites
// Define getter/setters for config properties
[
'GOAL_BUFFER_LENGTH',
'MAX_GOAL_BUFFER_LENGTH',
'BACK_BUFFER_LENGTH',
'GOAL_BUFFER_LENGTH_RATE',
'BUFFER_LOW_WATER_LINE',
'MAX_BUFFER_LOW_WATER_LINE',

32
test/configuration.test.js

@ -152,6 +152,34 @@ QUnit.test('MAX_GOAL_BUFFER_LENGTH set warning and invalid', function(assert) {
assert.equal(Config.MAX_GOAL_BUFFER_LENGTH, 60, 'default');
});
QUnit.test('BACK_BUFFER_LENGTH get warning', function(assert) {
assert.equal(
Vhs.BACK_BUFFER_LENGTH,
Config.BACK_BUFFER_LENGTH,
'Vhs.BACK_BUFFER_LENGTH returns the default'
);
assert.equal(this.env.log.warn.calls, 1, 'logged a warning');
});
QUnit.test('BACK_BUFFER_LENGTH set warning', function(assert) {
Vhs.BACK_BUFFER_LENGTH = 10;
assert.equal(this.env.log.warn.calls, 1, 'logged a warning');
assert.equal(Config.BACK_BUFFER_LENGTH, 10, 'returns what we set it to');
});
QUnit.test('BACK_BUFFER_LENGTH set warning and invalid', function(assert) {
Vhs.BACK_BUFFER_LENGTH = 'nope';
assert.equal(this.env.log.warn.calls, 2, 'logged two warnings');
assert.equal(Config.BACK_BUFFER_LENGTH, 30, 'default');
Vhs.BACK_BUFFER_LENGTH = -1;
assert.equal(this.env.log.warn.calls, 2, 'logged two warnings');
assert.equal(Config.BACK_BUFFER_LENGTH, 30, 'default');
});
QUnit.test('GOAL_BUFFER_LENGTH_RATE get warning', function(assert) {
assert.equal(
Vhs.GOAL_BUFFER_LENGTH_RATE,
@ -390,7 +418,7 @@ options.forEach((opt) => {
assert.deepEqual(
vhs.options_[opt.name],
opt.test,
`${opt.name} should be equal to sourchHandler option`
`${opt.name} should be equal to sourceHandler option`
);
});
@ -412,7 +440,7 @@ options.forEach((opt) => {
assert.deepEqual(
vhs.options_[opt.name],
opt.test,
`${opt.name} should be equal to sourchHandler option`
`${opt.name} should be equal to sourceHandler option`
);
});
});
Loading…
Cancel
Save