Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-8975): adding segment size in target buffer when exceeding maxmax #75

Merged
merged 4 commits into from
Jun 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}