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

fix(DASH): Use presentationTimeOffset in EventStream #7282

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2980,14 +2980,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 @@ -1483,6 +1483,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
Loading