Skip to content

Commit

Permalink
feat!: Remove small/large gap config, always jump gaps (shaka-project…
Browse files Browse the repository at this point in the history
…#4125)

We get rid of the "small/large" gap concept, to always jump gaps by default

Related to issue shaka-project#3188 (comment)
  • Loading branch information
Álvaro Velad Galván authored Apr 13, 2022
1 parent b83b412 commit 0fd1999
Show file tree
Hide file tree
Showing 20 changed files with 52 additions and 368 deletions.
2 changes: 0 additions & 2 deletions demo/common/message_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ shakaDemo.MessageIds = {
IGNORE_TEXT_FAILURES: 'DEMO_IGNORE_TEXT_FAILURES',
INACCURATE_MANIFEST_TOLERANCE: 'DEMO_INACCURATE_MANIFEST_TOLERANCE',
INITIAL_SEGMENT_LIMIT: 'DEMO_INITIAL_SEGMENT_LIMIT',
JUMP_LARGE_GAPS: 'DEMO_JUMP_LARGE_GAPS',
LANGUAGE_SECTION_HEADER: 'DEMO_LANGUAGE_SECTION_HEADER',
LOG_LEVEL: 'DEMO_LOG_LEVEL',
LOG_LEVEL_DEBUG: 'DEMO_LOG_LEVEL_DEBUG',
Expand All @@ -211,7 +210,6 @@ shakaDemo.MessageIds = {
MAX_FRAMERATE: 'DEMO_MAX_FRAMERATE',
MAX_HEIGHT: 'DEMO_MAX_HEIGHT',
MAX_PIXELS: 'DEMO_MAX_PIXELS',
MAX_SMALL_GAP_SIZE: 'DEMO_MAX_SMALL_GAP_SIZE',
MAX_WIDTH: 'DEMO_MAX_WIDTH',
MIN_BANDWIDTH: 'DEMO_MIN_BANDWIDTH',
MIN_BYTES: 'DEMO_MIN_BYTES',
Expand Down
9 changes: 2 additions & 7 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,6 @@ shakaDemo.Config = class {
.addNumberInput_(MessageIds.GAP_DETECTION_THRESHOLD,
'streaming.gapDetectionThreshold',
/* canBeDecimal= */ true)
.addNumberInput_(MessageIds.MAX_SMALL_GAP_SIZE,
'streaming.smallGapLimit',
/* canBeDecimal= */ true)
.addNumberInput_(MessageIds.BUFFERING_GOAL,
'streaming.bufferingGoal',
/* canBeDecimal= */ true)
Expand Down Expand Up @@ -407,10 +404,8 @@ shakaDemo.Config = class {
this.latestInput_.input().checked = true;
}

this.addBoolInput_(MessageIds.JUMP_LARGE_GAPS,
'streaming.jumpLargeGaps')
.addBoolInput_(MessageIds.FORCE_TRANSMUX_TS,
'streaming.forceTransmuxTS')
this.addBoolInput_(MessageIds.FORCE_TRANSMUX_TS,
'streaming.forceTransmuxTS')
.addBoolInput_(MessageIds.START_AT_SEGMENT_BOUNDARY,
'streaming.startAtSegmentBoundary')
.addBoolInput_(MessageIds.IGNORE_TEXT_FAILURES,
Expand Down
1 change: 0 additions & 1 deletion demo/demo_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ shakaDemo.Utils = class {

// Override config values that are handled manually.
overridden.push('abr.enabled');
overridden.push('streaming.jumpLargeGaps');
overridden.push('drm.advanced');
overridden.push('drm.servers');

Expand Down
2 changes: 0 additions & 2 deletions demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
"DEMO_INVALID_JSON_CONFIG_ERROR": "Invalid JSON configuration",
"DEMO_IRT": "IRT",
"DEMO_JSDELIVR": "jsDelivr",
"DEMO_JUMP_LARGE_GAPS": "Jump Large Gaps",
"DEMO_LANGUAGE_SECTION_HEADER": "Language",
"DEMO_LIBRARIES": "Google Hosted Libraries",
"DEMO_LICENSE": "Apache License",
Expand Down Expand Up @@ -137,7 +136,6 @@
"DEMO_MAX_FRAMERATE": "Max Framerate",
"DEMO_MAX_HEIGHT": "Max Height",
"DEMO_MAX_PIXELS": "Max Pixels",
"DEMO_MAX_SMALL_GAP_SIZE": "Maximum Small Gap Size",
"DEMO_MAX_WIDTH": "Max Width",
"DEMO_METACDN": "MetaCDN",
"DEMO_MICROSOFT": "Microsoft",
Expand Down
8 changes: 0 additions & 8 deletions demo/locales/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,6 @@
"description": "A link in the footer, to Shaka Player in the jsDelivr CDN.",
"message": "[PROPER_NAME:jsDelivr]"
},
"DEMO_JUMP_LARGE_GAPS": {
"description": "The name of a configuration value.",
"message": "Jump Large Gaps"
},
"DEMO_LANGUAGE_SECTION_HEADER": {
"description": "The header for a section of configuration values.",
"message": "Language"
Expand Down Expand Up @@ -551,10 +547,6 @@
"description": "The name of a configuration value.",
"message": "Max Pixels"
},
"DEMO_MAX_SMALL_GAP_SIZE": {
"description": "The name of a configuration value.",
"message": "Maximum Small Gap Size"
},
"DEMO_MAX_WIDTH": {
"description": "The name of a configuration value.",
"message": "Max Width"
Expand Down
6 changes: 0 additions & 6 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,6 @@ shakaDemo.Main = class {
if ('noadaptation' in params) {
this.configure('abr.enabled', false);
}
if ('jumpLargeGaps' in params) {
this.configure('streaming.jumpLargeGaps', true);
}

// Add compiled/uncompiled links.
this.makeVersionLinks_();
Expand Down Expand Up @@ -1357,9 +1354,6 @@ shakaDemo.Main = class {
if (!this.getCurrentConfigValue('abr.enabled')) {
params.push('noadaptation');
}
if (this.getCurrentConfigValue('streaming.jumpLargeGaps')) {
params.push('jumpLargeGaps');
}
params.push('uilang=' + this.getUILocale());

if (this.selectedAsset) {
Expand Down
2 changes: 0 additions & 2 deletions docs/tutorials/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ player.getConfiguration();
failureCallback: Function
ignoreTextStreamFailures: false
alwaysStreamText: false
jumpLargeGaps: false
rebufferingGoal: 2
retryParameters: Object
smallGapLimit: 0.5
startAtSegmentBoundary: false
safeSeekOffset: 5
textDisplayFactory: Function
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorials/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ application:
constructors; these will not be invoked with `new` (deprecated in v3.1.0)
- `drm.initDataTransform` has been removed (no longer needed since the
minimum supported version of iOS is now 13)
- `streaming.smallGapLimit` and `streaming.jumpLargeGaps` have been removed;
all gaps will now be jumped

- Player API changes:
- `shaka.Player.prototype.addTextTrack()` has been replaced by
Expand Down
14 changes: 1 addition & 13 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,6 @@ shaka.extern.ManifestConfiguration;
* alwaysStreamText: boolean,
* startAtSegmentBoundary: boolean,
* gapDetectionThreshold: number,
* smallGapLimit: number,
* jumpLargeGaps: boolean,
* durationBackoff: number,
* forceTransmuxTS: boolean,
* safeSeekOffset: number,
Expand Down Expand Up @@ -894,18 +892,8 @@ shaka.extern.ManifestConfiguration;
* to <code>false</code>.
* @property {number} gapDetectionThreshold
* TThe maximum distance (in seconds) before a gap when we'll automatically
* jump. This value defaults to <code>0.1</code>, except in Edge Legacy, IE,
* jump. This value defaults to <code>0.1</code>, except in Edge Legacy,
* Tizen, Chromecast that value defaults value is <code>0.5</code>
* @property {number} smallGapLimit
* The limit (in seconds) for a gap in the media to be considered "small".
* Small gaps are jumped automatically without events. Large gaps result
* in a Player event and can be jumped.
* @property {boolean} jumpLargeGaps
* If <code>true</code>, jump large gaps in addition to small gaps. A
* <code>largegap</code> event will be raised first. Then, if the app doesn't
* call <code>preventDefault()</code> on the event, the Player will jump the
* gap. If <code>false</code>, then the event will be raised, but the gap
* will not be jumped.
* @property {number} durationBackoff
* By default, we will not allow seeking to exactly the duration of a
* presentation. This field is the number of seconds before duration we will
Expand Down
55 changes: 10 additions & 45 deletions lib/media/gap_jumping_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ goog.require('shaka.media.PresentationTimeline');
goog.require('shaka.media.StallDetector');
goog.require('shaka.media.TimeRangesUtils');
goog.require('shaka.util.EventManager');
goog.require('shaka.util.FakeEvent');
goog.require('shaka.util.IReleasable');
goog.require('shaka.util.Timer');

Expand All @@ -33,10 +32,8 @@ shaka.media.GapJumpingController = class {
* playable region. The gap jumping controller takes ownership over the
* stall detector.
* If no stall detection logic is desired, |null| may be provided.
* @param {function(!Event)} onEvent Called when an event is raised to be sent
* to the application.
*/
constructor(video, timeline, config, stallDetector, onEvent) {
constructor(video, timeline, config, stallDetector) {
/** @private {HTMLMediaElement} */
this.video_ = video;

Expand All @@ -46,9 +43,6 @@ shaka.media.GapJumpingController = class {
/** @private {?shaka.extern.StreamingConfiguration} */
this.config_ = config;

/** @private {?function(!Event)} */
this.onEvent_ = onEvent;

/** @private {shaka.util.EventManager} */
this.eventManager_ = new shaka.util.EventManager();

Expand All @@ -58,9 +52,6 @@ shaka.media.GapJumpingController = class {
/** @private {number} */
this.prevReadyState_ = video.readyState;

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

/**
* The stall detector tries to keep the playhead moving forward. It is
* managed by the gap-jumping controller to avoid conflicts. On some
Expand Down Expand Up @@ -107,7 +98,6 @@ shaka.media.GapJumpingController = class {
this.stallDetector_ = null;
}

this.onEvent_ = null;
this.timeline_ = null;
this.video_ = null;
}
Expand All @@ -128,7 +118,6 @@ shaka.media.GapJumpingController = class {
onSeeking() {
this.seekingEventReceived_ = true;
this.hadSegmentAppended_ = false;
this.didFireLargeGap_ = false;
}


Expand Down Expand Up @@ -165,7 +154,6 @@ shaka.media.GapJumpingController = class {
// When the ready state changes, we have moved on, so we should fire the
// large gap event if we see one.
if (this.video_.readyState != this.prevReadyState_) {
this.didFireLargeGap_ = false;
this.prevReadyState_ = this.video_.readyState;
}

Expand All @@ -175,7 +163,6 @@ shaka.media.GapJumpingController = class {
}


const smallGapLimit = this.config_.smallGapLimit;
const currentTime = this.video_.currentTime;
const buffered = this.video_.buffered;
const gapDetectionThreshold = this.config_.gapDetectionThreshold;
Expand Down Expand Up @@ -203,8 +190,6 @@ shaka.media.GapJumpingController = class {
}

const jumpSize = jumpTo - currentTime;
const isGapSmall = jumpSize <= smallGapLimit;
let jumpLargeGap = false;

// If we jump to exactly the gap start, we may detect a small gap due to
// rounding errors or browser bugs. We can ignore these extremely small
Expand All @@ -213,37 +198,17 @@ shaka.media.GapJumpingController = class {
return;
}

if (!isGapSmall && !this.didFireLargeGap_) {
this.didFireLargeGap_ = true;

// Event firing is synchronous.
const data = new Map()
.set('currentTime', currentTime)
.set('gapSize', jumpSize);
const event = new shaka.util.FakeEvent('largegap', data);
event.cancelable = true;
this.onEvent_(event);

if (this.config_.jumpLargeGaps && !event.defaultPrevented) {
jumpLargeGap = true;
} else {
shaka.log.info('Ignoring large gap at', currentTime, 'size', jumpSize);
}
if (gapIndex == 0) {
shaka.log.info(
'Jumping forward', jumpSize,
'seconds because of gap before start time of', jumpTo);
} else {
shaka.log.info(
'Jumping forward', jumpSize, 'seconds because of gap starting at',
buffered.end(gapIndex - 1), 'and ending at', jumpTo);
}

if (isGapSmall || jumpLargeGap) {
if (gapIndex == 0) {
shaka.log.info(
'Jumping forward', jumpSize,
'seconds because of gap before start time of', jumpTo);
} else {
shaka.log.info(
'Jumping forward', jumpSize, 'seconds because of gap starting at',
buffered.end(gapIndex - 1), 'and ending at', jumpTo);
}

this.video_.currentTime = jumpTo;
}
this.video_.currentTime = jumpTo;
}
};

Expand Down
6 changes: 2 additions & 4 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,15 @@ shaka.media.MediaSourceEngine = class {
*
* @param {shaka.util.ManifestParserUtils.ContentType} contentType
* @param {number} time Playhead time
* @param {number=} smallGapLimit
* @return {boolean}
*/
isBuffered(contentType, time, smallGapLimit) {
isBuffered(contentType, time) {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
if (contentType == ContentType.TEXT) {
return this.textEngine_.isBuffered(time);
} else {
const buffered = this.getBuffered_(contentType);
return shaka.media.TimeRangesUtils.isBuffered(
buffered, time, smallGapLimit);
return shaka.media.TimeRangesUtils.isBuffered(buffered, time);
}
}

Expand Down
7 changes: 2 additions & 5 deletions lib/media/playhead.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ shaka.media.MediaSourcePlayhead = class {
* @param {function()} onSeek
* Called when the user agent seeks to a time within the presentation
* timeline.
* @param {function(!Event)} onEvent
* Called when an event is raised to be sent to the application.
*/
constructor(mediaElement, manifest, config, startTime, onSeek, onEvent) {
constructor(mediaElement, manifest, config, startTime, onSeek) {
/**
* The seek range must be at least this number of seconds long. If it is
* smaller than this, change it to be this big so we don't repeatedly seek
Expand Down Expand Up @@ -199,8 +197,7 @@ shaka.media.MediaSourcePlayhead = class {
mediaElement,
manifest.presentationTimeline,
config,
this.createStallDetector_(mediaElement, config),
onEvent);
this.createStallDetector_(mediaElement, config));

/** @private {shaka.media.VideoWrapper} */
this.videoWrapper_ = new shaka.media.VideoWrapper(
Expand Down
3 changes: 1 addition & 2 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,10 @@ shaka.media.StreamingEngine = class {
*/
seeked() {
const presentationTime = this.playerInterface_.getPresentationTime();
const smallGapLimit = this.config_.smallGapLimit;
const ContentType = shaka.util.ManifestParserUtils.ContentType;
const newTimeIsBuffered = (type) => {
return this.playerInterface_.mediaSourceEngine.isBuffered(
type, presentationTime, smallGapLimit);
type, presentationTime);
};

let streamCleared = false;
Expand Down
13 changes: 4 additions & 9 deletions lib/media/time_ranges_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ shaka.media.TimeRangesUtils = class {


/**
* Determines if the given time is inside a buffered range. This includes
* gaps, meaning that if the playhead is in a gap, it is considered buffered.
* If there is a small gap between the playhead and buffer start, consider it
* as buffered.
* Determines if the given time is inside a buffered range.
*
* @param {TimeRanges} b
* @param {number} time Playhead time
* @param {number=} smallGapLimit Set in configuration
* @return {boolean}
*/
static isBuffered(b, time, smallGapLimit = 0) {
static isBuffered(b, time) {
if (!b || !b.length) {
return false;
}
Expand All @@ -76,9 +72,8 @@ shaka.media.TimeRangesUtils = class {
if (time > b.end(b.length - 1)) {
return false;
}
// Push the time forward by the gap limit so that it is more likely to be in
// the range.
return (time + smallGapLimit >= b.start(0));

return time >= b.start(0);
}


Expand Down
Loading

0 comments on commit 0fd1999

Please sign in to comment.