Skip to content

Commit

Permalink
Parse to float instead of int when calculating start time
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Jul 19, 2022
1 parent c4e86d5 commit b903950
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/streaming/controllers/StreamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,8 @@ function StreamController() {
// "t=posix:<time>" : time is absolute start time as number of seconds since 01-01-1970
const period = adapter.getRegularPeriods()[0];
const targetString = targetValue.toString();
const posix = targetString.indexOf('posix:') !== -1 ? targetString.substring(6) === 'now' ? Date.now() / 1000 : parseInt(targetString.substring(6)) : NaN;
let startTime = (isDynamic && !isNaN(posix)) ? timelineConverter.calcPresentationTimeFromWallTime(new Date(posix * 1000), period) : parseInt(targetString) + referenceTime;
const posix = targetString.indexOf('posix:') !== -1 ? targetString.substring(6) === 'now' ? Date.now() / 1000 : parseFloat(targetString.substring(6)) : NaN;
let startTime = (isDynamic && !isNaN(posix)) ? timelineConverter.calcPresentationTimeFromWallTime(new Date(posix * 1000), period) : parseFloat(targetString) + referenceTime;

return startTime;
}
Expand Down
24 changes: 24 additions & 0 deletions test/unit/streaming.controllers.StreamController.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@ describe('StreamController', function () {
eventBus.trigger(Events.TIME_SYNCHRONIZATION_COMPLETED);
});

it('should start static stream at #t with milliseconds', function (done) {
doneFn = done;

let uriStartTime = 10.555;
uriFragmentModelMock.setURIFragmentData({ t: uriStartTime.toString() });

expectedStartTime = staticStreamInfo.start + uriStartTime;

getStreamsInfoStub.returns([staticStreamInfo]);
eventBus.trigger(Events.TIME_SYNCHRONIZATION_COMPLETED);
});

it('should start static stream at period start if #t is before period start', function (done) {
doneFn = done;

Expand Down Expand Up @@ -415,6 +427,18 @@ describe('StreamController', function () {
eventBus.trigger(Events.TIME_SYNCHRONIZATION_COMPLETED);
});

it('should start dynamic stream at #t=posix on millisecond level', function (done) {
doneFn = done;

let uriStartTime = dvrWindowRange.start + 10.555;
uriFragmentModelMock.setURIFragmentData({ t: 'posix:' + uriStartTime.toString() });

expectedStartTime = uriStartTime;

getStreamsInfoStub.returns([dynamicStreamInfo]);
eventBus.trigger(Events.TIME_SYNCHRONIZATION_COMPLETED);
});

it('should start dynamic stream at DVR window start if #t=posix is before DVR window range', function (done) {
doneFn = done;

Expand Down

0 comments on commit b903950

Please sign in to comment.