Skip to content

Commit

Permalink
Merge pull request #2595 from aescarcha/secureBufferTimestampOffsetCh…
Browse files Browse the repository at this point in the history
…ange

Wait until buffer is ready when changing timestamp offset
  • Loading branch information
epiclabsDASH committed Jun 6, 2018
2 parents 9689635 + 688d559 commit 640da28
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/streaming/PreBufferSink.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ function PreBufferSink(onAppendedCallback) {
return timeranges;
}

function updateTimestampOffset() {
// Nothing to do
}

/**
* Return the all chunks in the buffer the lie between times start and end.
* Because a chunk cannot be split, this returns the full chunk if any part of its time lies in the requested range.
Expand Down Expand Up @@ -144,7 +148,8 @@ function PreBufferSink(onAppendedCallback) {
remove: remove,
abort: abort,
discharge: discharge,
reset: reset
reset: reset,
updateTimestampOffset: updateTimestampOffset
};

setup();
Expand Down
11 changes: 10 additions & 1 deletion src/streaming/SourceBufferSink.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ function SourceBufferSink(mediaSource, mediaInfo, onAppendedCallback) {
}
}

function updateTimestampOffset(MSETimeOffset) {
if (buffer.timestampOffset !== MSETimeOffset && !isNaN(MSETimeOffset)) {
waitForUpdateEnd(buffer, () => {
buffer.timestampOffset = MSETimeOffset;
});
}
}

function remove(start, end, forceRemoval) {
const sourceBufferSink = this;
// make sure that the given time range is correct. Otherwise we will get InvalidAccessError
Expand Down Expand Up @@ -271,7 +279,8 @@ function SourceBufferSink(mediaSource, mediaInfo, onAppendedCallback) {
append: append,
remove: remove,
abort: abort,
reset: reset
reset: reset,
updateTimestampOffset: updateTimestampOffset
};

setup();
Expand Down
5 changes: 2 additions & 3 deletions src/streaming/controllers/BufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,8 @@ function BufferController(config) {
function updateBufferTimestampOffset(MSETimeOffset) {
// Each track can have its own @presentationTimeOffset, so we should set the offset
// if it has changed after switching the quality or updating an mpd
const sourceBuffer = buffer && buffer.getBuffer ? buffer.getBuffer() : null;
if (sourceBuffer && sourceBuffer.timestampOffset !== MSETimeOffset && !isNaN(MSETimeOffset)) {
sourceBuffer.timestampOffset = MSETimeOffset;
if (buffer && buffer.updateTimestampOffset) {
buffer.updateTimestampOffset(MSETimeOffset);
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/streaming/text/NotFragmentedTextBufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ function NotFragmentedTextBufferController(config) {
return null;
}

function updateTimestampOffset(MSETimeOffset) {
if (buffer.timestampOffset !== MSETimeOffset && !isNaN(MSETimeOffset)) {
buffer.timestampOffset = MSETimeOffset;
}
}

instance = {
getBufferControllerType: getBufferControllerType,
initialize: initialize,
Expand All @@ -203,7 +209,8 @@ function NotFragmentedTextBufferController(config) {
dischargePreBuffer: dischargePreBuffer,
switchInitData: switchInitData,
getRangeAt: getRangeAt,
reset: reset
reset: reset,
updateTimestampOffset: updateTimestampOffset
};

setup();
Expand Down
10 changes: 9 additions & 1 deletion src/streaming/text/TextBufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ function TextBufferController(config) {
return _BufferControllerImpl.getRangeAt(time);
}

function updateTimestampOffset(MSETimeOffset) {
const buffer = getBuffer();
if (buffer.timestampOffset !== MSETimeOffset && !isNaN(MSETimeOffset)) {
buffer.timestampOffset = MSETimeOffset;
}
}

instance = {
getBufferControllerType: getBufferControllerType,
initialize: initialize,
Expand All @@ -163,7 +170,8 @@ function TextBufferController(config) {
dischargePreBuffer: dischargePreBuffer,
switchInitData: switchInitData,
getRangeAt: getRangeAt,
reset: reset
reset: reset,
updateTimestampOffset: updateTimestampOffset
};

setup();
Expand Down
7 changes: 7 additions & 0 deletions test/unit/mocks/MediaSourceBufferMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class MediaSourceBufferMock {
}, 500);
}

updateTimestampOffset(timestampOffset) {
this.timestampOffset = timestampOffset;
setTimeout(() => {
this.updating = false;
}, 500);
}

abort() {
this.aborted = true;
}
Expand Down

0 comments on commit 640da28

Please sign in to comment.