Skip to content

Commit

Permalink
fix(DASH): Use presentationTimeOffset in EventStream (#7282)
Browse files Browse the repository at this point in the history
Fixes #7277
  • Loading branch information
tykus160 authored and joeyparrish committed Sep 13, 2024
1 parent 1b03baa commit 8bc639b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2804,14 +2804,19 @@ shaka.dash.DashParser = class {
const schemeIdUri = elem.attributes['schemeIdUri'] || '';
const value = elem.attributes['value'] || '';
const timescale = TXml.parseAttr(elem, 'timescale', parseNumber) || 1;
const presentationTimeOffset =
TXml.parseAttr(elem, 'presentationTimeOffset', parseNumber) || 0;

for (const eventNode of TXml.findChildren(elem, 'Event')) {
const presentationTime =
TXml.parseAttr(eventNode, 'presentationTime', parseNumber) || 0;
const duration =
TXml.parseAttr(eventNode, 'duration', parseNumber) || 0;

let startTime = presentationTime / timescale + periodStart;
// Ensure start time won't be lower than period start.
let startTime = Math.max(
(presentationTime - presentationTimeOffset) / timescale + periodStart,
periodStart);
let endTime = startTime + (duration / timescale);
if (periodDuration != null) {
// An event should not go past the Period, even if the manifest says so.
Expand Down
31 changes: 31 additions & 0 deletions test/dash/dash_parser_live_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,37 @@ describe('DashParser Live', () => {
expect(onTimelineRegionAddedSpy).toHaveBeenCalledWith(
jasmine.objectContaining({id: '4'}));
});

it('will offset events by given presentationTimeOffset', async () => {
const newManifest = [
'<MPD>',
' <Period id="1" duration="PT30S">',
' <EventStream schemeIdUri="http://example.com" timescale="1"',
' presentationTimeOffset="10">',
' <Event presentationTime="10" duration="15"/>',
' <Event presentationTime="25" duration="10"/>',
' </EventStream>',
' <AdaptationSet mimeType="video/mp4">',
' <Representation bandwidth="1">',
' <SegmentTemplate startNumber="1" media="s$Number$.mp4"',
' duration="2" />',
' </Representation>',
' </AdaptationSet>',
' </Period>',
'</MPD>',
].join('\n');

fakeNetEngine.setResponseText('dummy://foo', newManifest);
await parser.start('dummy://foo', playerInterface);

expect(onTimelineRegionAddedSpy).toHaveBeenCalledTimes(2);
expect(onTimelineRegionAddedSpy)
.toHaveBeenCalledWith(
jasmine.objectContaining({startTime: 0, endTime: 15}));
expect(onTimelineRegionAddedSpy)
.toHaveBeenCalledWith(
jasmine.objectContaining({startTime: 15, endTime: 25}));
});
});

it('honors clockSyncUri for in-progress recordings', async () => {
Expand Down

0 comments on commit 8bc639b

Please sign in to comment.