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

feat(text): Add time context to modifyCueCallback #6252

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions externs/shaka/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ shaka.extern.TextParser.TimeContext;

/**
* A callback used for editing cues before appending.
* Provides the cue, and the URI of the captions file the cue was parsed from.
* Provides the cue, the URI of the captions file the cue was parsed from, and
* the time context that was used when generating that cue.
* You can edit the cue object passed in.
* @typedef {function(!shaka.text.Cue, ?string)}
* @typedef {function(!shaka.text.Cue, ?string,
* !shaka.extern.TextParser.TimeContext)}
* @exportDoc
*/
shaka.extern.TextParser.ModifyCueCallback;
Expand Down
2 changes: 1 addition & 1 deletion lib/text/text_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ shaka.text.TextEngine = class {
const allCues = this.parser_.parseMedia(
shaka.util.BufferUtils.toUint8(buffer), time, uri);
for (const cue of allCues) {
this.modifyCueCallback_(cue, uri || null);
this.modifyCueCallback_(cue, uri || null, time);
}
const cuesToAppend = allCues.filter((cue) => {
return cue.startTime >= this.appendWindowStart_ &&
Expand Down
6 changes: 4 additions & 2 deletions test/text/text_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ describe('TextEngine', () => {
shaka.test.Util.spyFunc(modifyCueCallback));
mockParseMedia.and.returnValue([cue1, cue2]);
await textEngine.appendBuffer(dummyData, 0, 3, 'uri');
expect(modifyCueCallback).toHaveBeenCalledWith(cue1, 'uri');
expect(modifyCueCallback).toHaveBeenCalledWith(cue2, 'uri');
expect(modifyCueCallback).toHaveBeenCalledWith(
cue1, 'uri', jasmine.objectContaining({periodStart: 0}));
expect(modifyCueCallback).toHaveBeenCalledWith(
cue2, 'uri', jasmine.objectContaining({periodStart: 0}));
});
});

Expand Down
Loading