Skip to content

Commit

Permalink
feat(FEC-8975): adding segment size in target buffer when exceeding m…
Browse files Browse the repository at this point in the history
…axmax (#75)

adding segment size in target buffer when exceeding maxmax
adding url in frag_loaded
  • Loading branch information
RoyBregman authored Jun 20, 2019
1 parent 3fe4fd2 commit ed04391
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
this._shaka.getNetworkingEngine().registerResponseFilter((type, response) => {
switch (type) {
case shaka.net.NetworkingEngine.RequestType.SEGMENT:
this._trigger(EventType.FRAG_LOADED, {miliSeconds: response.timeMs, bytes: response.data.byteLength});
this._trigger(EventType.FRAG_LOADED, {miliSeconds: response.timeMs, bytes: response.data.byteLength, url: response.uri});
break;
case shaka.net.NetworkingEngine.RequestType.MANIFEST:
this._trigger(EventType.MANIFEST_LOADED, {miliSeconds: response.timeMs});
Expand Down Expand Up @@ -546,15 +546,19 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
*/
_getVideoTracks(): Array<Object> {
let variantTracks = this._shaka.getVariantTracks();
let activeVariantTrack = variantTracks.filter(variantTrack => {
return variantTrack.active;
})[0];
let activeVariantTrack = this._getActiveTrack();
let videoTracks = variantTracks.filter(variantTrack => {
return variantTrack.audioId === activeVariantTrack.audioId;
});
return videoTracks;
}

_getActiveTrack(): Object {
return this._shaka.getVariantTracks().filter(variantTrack => {
return variantTrack.active;
})[0];
}

/**
* Get the original audio tracks
* @function _getAudioTracks
Expand Down Expand Up @@ -906,7 +910,27 @@ export default class DashAdapter extends BaseMediaSourceAdapter {
targetBufferVal = this._videoElement.duration - this._videoElement.currentTime;
}

targetBufferVal = Math.min(targetBufferVal, this._shaka.getConfiguration().streaming.bufferingGoal);
targetBufferVal = Math.min(targetBufferVal, this._shaka.getConfiguration().streaming.bufferingGoal + this._getCurrentSegmentLength());
return targetBufferVal;
}

_getCurrentSegmentLength(): number {
const activeTrack = this._getActiveTrack();
const activeTrackId = activeTrack ? activeTrack.id : NaN;
let segmentLength = 0;
const periods = this._shaka.getManifest().periods;
if (!isNaN(activeTrackId)) {
for (let i = 0; i < periods.length; i++) {
for (let j = 0; j < periods[i].variants.length; j++) {
const variant = periods[i].variants[j];
if (variant.id === activeTrackId) {
const segmentPosition = variant.video.findSegmentPosition(this._videoElement.currentTime);
let seg = variant.video.getSegmentReference(segmentPosition);
segmentLength = seg.endTime - seg.startTime;
}
}
}
}
return segmentLength;
}
}

0 comments on commit ed04391

Please sign in to comment.