Skip to content

Commit

Permalink
Merge pull request #2 from bbc/bugfix-240
Browse files Browse the repository at this point in the history
Fix Dash-Industry-Forum/dash.js Dash-Industry-Forum#240
  • Loading branch information
wyell committed Jun 15, 2015
2 parents f866bef + 87eac97 commit 3cc0f7c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
1 change: 0 additions & 1 deletion build/test/js/streaming/AbrControllerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe("AbrController", function () {

match = expectedBitrates.filter(function(val, idx/*, arr*/) {
item = actualBitrates[idx];

return (item && (item.qualityIndex === idx) && (item.bitrate === val) && (item.mediaType === dummyMediaInfo.type));
});

Expand Down
4 changes: 2 additions & 2 deletions build/test/js/streaming/FragmentModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ describe("FragmentModel", function () {
});

it("should detect duplicated requests", function () {
expect(fragmentModel.isFragmentLoadedOrPending(initRequest)).toBeTruthy();
expect(fragmentModel.isFragmentLoadedOrPending(mediaRequest)).toBeTruthy();
expect(fragmentModel.isFragmentLoadedOrPendingAndNotDiscarded(initRequest)).toBeTruthy();
expect(fragmentModel.isFragmentLoadedOrPendingAndNotDiscarded(mediaRequest)).toBeTruthy();
});

it("should return pending requests", function () {
Expand Down
2 changes: 1 addition & 1 deletion build/test/js/utils/ObjectsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
getMediaInfo: function() {
return {bitrateList:[]};
}
}
};
},

setup = function() {
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/controllers/AbrController.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ MediaPlayer.dependencies.AbrController = function () {
*/
getQualityForBitrate: function(mediaInfo, bitrate) {
var bitrateList = this.getBitrateList(mediaInfo),
ln = bitrateList.length,
ln = bitrateList ? bitrateList.length : 0,
bitrateInfo;

for (var i = 0; i < ln; i +=1) {
Expand Down
30 changes: 27 additions & 3 deletions src/streaming/models/FragmentModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ MediaPlayer.dependencies.FragmentModel = function () {
notify: undefined,
subscribe: undefined,
unsubscribe: undefined,
videoModel: undefined,
sourceBufferExt: undefined,

setup: function() {
this[MediaPlayer.dependencies.BufferController.eventList.ENAME_BUFFER_LEVEL_OUTRUN] = onBufferLevelOutrun;
Expand All @@ -204,15 +206,15 @@ MediaPlayer.dependencies.FragmentModel = function () {
},

addRequest: function(value) {
if (!value || this.isFragmentLoadedOrPending(value)) return false;
if (!value || this.isFragmentLoadedOrPendingAndNotDiscarded(value)) return false;

pendingRequests.push(value);
addSchedulingInfoMetrics.call(this, value, MediaPlayer.dependencies.FragmentModel.states.PENDING);

return true;
},

isFragmentLoadedOrPending: function(request) {
isFragmentLoadedOrPendingAndNotDiscarded: function(request) {
var isEqualComplete = function(req1, req2) {
return ((req1.action === "complete") && (req1.action === req2.action));
},
Expand All @@ -225,6 +227,28 @@ MediaPlayer.dependencies.FragmentModel = function () {
return isNaN(req1.index) && isNaN(req2.index) && (req1.quality === req2.quality);
},

isDiscarded = function() {
var buffer = this.videoModel.getElement(),
inBuffer = this.sourceBufferExt.getBufferRange(buffer, request.availabilityStartTime) !== null,
req,
d;

// It can take a few moments to get into the buffer
if (!inBuffer) {
d = new Date();
d.setSeconds(d.getSeconds() + 3);
for (var i = 0; i < executedRequests.length; i += 1) {
req = executedRequests[i];

if (isEqualMedia(request, req) && req.requestEndDate <= d) {
return false;
}
}
}

return !inBuffer;
},

check = function(arr) {
var req,
isLoaded = false,
Expand All @@ -244,7 +268,7 @@ MediaPlayer.dependencies.FragmentModel = function () {
return isLoaded;
};

return (check(pendingRequests) || check(loadingRequests) || check(executedRequests));
return (check(pendingRequests) || check(loadingRequests) || (check(executedRequests) && !isDiscarded.call(this)));
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/rules/SchedulingRules/PlaybackTimeRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ MediaPlayer.rules.PlaybackTimeRule = function () {
request = this.adapter.getFragmentRequestForTime(streamProcessor, track, rejected.startTime + (rejected.duration / 2) + EPSILON, {keepIdx: keepIdx, timeThreshold: 0});
}

while (request && streamProcessor.getFragmentModel().isFragmentLoadedOrPending(request)) {
while (request && streamProcessor.getFragmentModel().isFragmentLoadedOrPendingAndNotDiscarded(request)) {
if (request.action === "complete") {
request = null;
this.adapter.setIndexHandlerTime(streamProcessor, NaN);
Expand Down

0 comments on commit 3cc0f7c

Please sign in to comment.