Skip to content

Commit

Permalink
feat(text): Add time context to modifyCueCallback (#6252)
Browse files Browse the repository at this point in the history
  • Loading branch information
theodab committed Feb 20, 2024
1 parent bb712c0 commit 03633e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions externs/shaka/text.js
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
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
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

0 comments on commit 03633e4

Please sign in to comment.