Skip to content

Commit

Permalink
Moshe Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Moshe Maor committed Jan 15, 2024
1 parent 1e3fd9b commit 69c6b1c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
42 changes: 31 additions & 11 deletions src/engines/html5/media-source/adapters/native-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {

_waitingEventTriggered: ?boolean = false;

_wasCurrentTimeSetSuccessfully: boolean;

_segmentDuration: number = 0;

_startTimeOfDvrWindowInterval: IntervalID;

_startTimeOfDvrWindow: number = 0;

/**
* A counter to track the number of attempts to recover from media error
* @type {number}
Expand Down Expand Up @@ -253,6 +255,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
this._config = Utils.Object.mergeDeep({}, defaultConfig, this._config);
this._progressiveSources = config.progressiveSources;
this._liveEdge = 0;
this._setStarTimeOfDvrWindowInterval();
}

/**
Expand Down Expand Up @@ -327,7 +330,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
* @returns {Promise<Object>} - The loaded data
*/
load(startTime: ?number): Promise<Object> {
this._wasCurrentTimeSetSuccessfully = false;
this._maybeSetDrmPlayback();
if (!this._loadPromise) {
this._loadPromise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -531,8 +533,8 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
this._handleLiveDurationChange();
}
};
if (!this.isLive()) {
this._setStartTime(startTime);
if (startTime !== undefined && startTime > -1) {
this._videoElement.currentTime = startTime;
}
if (this._videoElement.textTracks.length > 0) {
parseTracksAndResolve();
Expand All @@ -546,7 +548,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
if (typeof startTime === 'number' && startTime > -1) {
this._videoElement.currentTime = startTime;
}
this._wasCurrentTimeSetSuccessfully = true;
}

_onTimeUpdate(): void {
Expand Down Expand Up @@ -637,6 +638,7 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
this._startTimeAttach = NaN;
this._videoDimensions = null;
this._clearHeartbeatTimeout();
clearInterval(this._startTimeOfDvrWindowInterval);
if (this._liveDurationChangeInterval) {
clearInterval(this._liveDurationChangeInterval);
this._liveDurationChangeInterval = null;
Expand Down Expand Up @@ -1241,10 +1243,6 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
return this._videoElement.duration === Infinity;
}

isOnLiveEdge(): boolean {
return this._wasCurrentTimeSetSuccessfully ? super.isOnLiveEdge() : false;
}

/**
* Handling live duration change (as safari doesn't trigger durationchange event on live playback)
* @function _handleLiveDurationChange
Expand Down Expand Up @@ -1287,14 +1285,36 @@ export default class NativeAdapter extends BaseMediaSourceAdapter {
* @returns {Number} - start time of DVR window.
* @public
*/
getStartTimeOfDvrWindow(): number {
_getStartTimeOfDvrWindow(): number {
if (this.isLive() && this._videoElement.seekable.length) {
return this._videoElement.seekable.start(0);
} else {
return 0;
}
}

getStartTimeOfDvrWindow() {
return this._startTimeOfDvrWindow;
}

_setStarTimeOfDvrWindowInterval() {
const intervalTime = 1000;
this._startTimeOfDvrWindowInterval = setInterval(() => {
//get Segment duration
const duration = this._segmentDuration;
if (
!this._waitingEventTriggered && //not in wait
this._getStartTimeOfDvrWindow() && //value is not Zero
duration && //Duration exist
Math.abs(this._getStartTimeOfDvrWindow() - this._startTimeOfDvrWindow) <= duration * 2 //Gap is less than twice the duration
) {
this._startTimeOfDvrWindow += intervalTime / 1000;
} else {
this._startTimeOfDvrWindow = this._getStartTimeOfDvrWindow();
}
}, intervalTime);
}

getDrmInfo(): ?PKDrmDataObject {
return this._drmHandler ? this._drmHandler.getDrmInfo() : null;
}
Expand Down
4 changes: 4 additions & 0 deletions src/engines/html5/media-source/base-media-source-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ export default class BaseMediaSourceAdapter extends FakeEventTarget implements I
}

isOnLiveEdge(): boolean {
if(this.getSegmentDuration()===0){

Check failure on line 224 in src/engines/html5/media-source/base-media-source-adapter.js

View workflow job for this annotation

GitHub Actions / running-tests / running-tests (ubuntu-latest)

Replace `(this.getSegmentDuration()===0)` with `·(this.getSegmentDuration()·===·0)·`
//If no segment duration, we cannot estimate live edge
return true;
}
return this.liveDuration - this._videoElement.currentTime <= this.getSegmentDuration() * CURRENT_OR_NEXT_SEGMENT_COUNT;
}

Expand Down
5 changes: 4 additions & 1 deletion src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2257,7 +2257,10 @@ export default class Player extends FakeEventTarget {
if (!this._firstPlay) {
return outOfDvr;
} else {
return !!this.src && !this.isOnLiveEdge();
return !!this.src && !this.isOnLiveEdge()

Check failure on line 2260 in src/player.js

View workflow job for this annotation

GitHub Actions / running-tests / running-tests (ubuntu-latest)

Replace `!!this.src·&&·!this.isOnLiveEdge()` with `(⏎··········!!this.src·&&⏎··········!this.isOnLiveEdge()·&&`
// Live video can be set with explicit start time,(e.g. startOver)
// in that case we don't want to move to the liveEdge
&& this._sources.startTime === undefined;

Check failure on line 2263 in src/player.js

View workflow job for this annotation

GitHub Actions / running-tests / running-tests (ubuntu-latest)

Replace `&&·this._sources.startTime·===·undefined` with `this._sources.startTime·===·undefined⏎········)`
}
}
return false;
Expand Down

0 comments on commit 69c6b1c

Please sign in to comment.