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

This commit is contained in:
theodab
2024-02-20 00:37:33 -08:00
committed by GitHub
parent bb712c0283
commit 03633e47bb
3 changed files with 9 additions and 5 deletions
+4 -2
View File
@@ -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;
+1 -1
View File
@@ -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_ &&
+4 -2
View File
@@ -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}));
});
});