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 2 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
31 changes: 27 additions & 4 deletions src/dash-adapter.js
Original file line number Diff line number Diff line change
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,26 @@ 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;
if (!isNaN(activeTrackId)) {
for (let i = 0; i < this._shaka.getManifest().periods.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can store const periods = this._shaka.getManifest().periods; and it will make the rest of the access a lot less verbose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (let i = 0; i < this._shaka.getManifest().periods.length; i++) {
const periods = this._shaka.getManifest().periods;
for (let i = 0; i < .periods.length; i++) {

for (let j = 0; j < this._shaka.getManifest().periods[i].variants.length; j++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (let j = 0; j < this._shaka.getManifest().periods[i].variants.length; j++) {
for (let j = 0; j < periods[i].variants.length; j++) {

const variant = this._shaka.getManifest().periods[i].variants[j];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const variant = this._shaka.getManifest().periods[i].variants[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;
}
}