From 03633e47bb3036c2b5fbd60461c7171c1e4ea0ee Mon Sep 17 00:00:00 2001 From: theodab Date: Tue, 20 Feb 2024 00:37:33 -0800 Subject: [PATCH] feat(text): Add time context to modifyCueCallback (#6252) --- externs/shaka/text.js | 6 ++++-- lib/text/text_engine.js | 2 +- test/text/text_engine_unit.js | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/externs/shaka/text.js b/externs/shaka/text.js index 2f34b7cab..61ec1ee94 100644 --- a/externs/shaka/text.js +++ b/externs/shaka/text.js @@ -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; diff --git a/lib/text/text_engine.js b/lib/text/text_engine.js index 97e85f154..f6d257306 100644 --- a/lib/text/text_engine.js +++ b/lib/text/text_engine.js @@ -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_ && diff --git a/test/text/text_engine_unit.js b/test/text/text_engine_unit.js index 2231279ab..134519785 100644 --- a/test/text/text_engine_unit.js +++ b/test/text/text_engine_unit.js @@ -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})); }); });