-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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(text): Fix TTML render timing and line break issues #4407
fix(text): Fix TTML render timing and line break issues #4407
Conversation
…issues This changes the SimpleTextDisplayer to flatten text payloads only starting at non-container cues. Not doing so poses an issue with 'rolled over' caption lines. E.g., consider: - TTML file N with caption line A from time [1.4, 2.1]. - TTML file N+1 with caption lines A from time [1.4, 2.4] and B from time [2.4, 3.4]. If captions A and B are descendents of two different <p> elements, Shaka currently flattens the text payload from A and B into a single cue that is rendered onto the display from time [1.4, 3.4]. Therefore, caption A's text payload is incorrectly showing during time [2.4, 3.4].\nThe fix updates the SimpleTextDisplayer append() logic to split up individual non-container cues into their own VTTCue object. This will not be done at the TTMLParser level to ensure proper style inheritance still occurs for the (actual) text cues. Closes shaka-project#4381
That is an excellent PR description. Very helpful! |
lib/text/simple_text_displayer.js
Outdated
const getCuesToFlatten = (cues) => { | ||
for (const cue of cues) { | ||
if (cue.isContainer) { | ||
flattenedCues = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a problem with the data flow here. flattenedCues is set to the result of getCuesToFlatten, which itself modifies flattenedCues in multiple ways and then returns flattenedCues. This is very hard to follow.
If getCuesToFlatten is going to be recursive, you shouldn't modify an effectively "global" variable (not truly global, but captured by this closure, so the effect is similar).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the function to not modify and reference a variable outside of the closure by passing a placeholder result array which is returned by the function.
@@ -127,6 +127,33 @@ describe('SimpleTextDisplayer', () => { | |||
[shakaCue]); | |||
}); | |||
|
|||
it('flattens nested cue payloads correctly', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test looks great. So I'm not concerned about the validity of the code change, so much as the clarity and readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, after the updates based on your other comments I think it should be easier to follow.
lib/text/simple_text_displayer.js
Outdated
const flatCue = cue.clone(); | ||
flatCue.nestedCues = []; | ||
flatCue.payload = flattenPayload(cue); | ||
flattenedCues = flattenedCues.concat(flatCue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was surprised to learn that Array.concat can be used for non-arrays, to append elements. For clarity when pushing a single value, I would suggest you use Array.push instead, and we save Array.concat for concatenating two arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Agreed this would be more readable, thanks!
…r' variable which is also the result.
This changes the `SimpleTextDisplayer` to flatten text payloads only starting at non-container cues. Not doing so poses an issue with 'rolled over' caption lines. E.g., consider: - TTML file `N` with caption line `A` from time `[1.4, 2.1]`. - TTML file `N+1` with caption lines `A` from time `[1.4, 2.4]` and `B` from time `[2.4, 3.4]`. If captions `A` and `B` are descendants of two different `<p>` elements, Shaka currently flattens the text payload from `A` and `B` into a single cue that is rendered onto the display from time `[1.4, 3.4]`. Therefore, caption `A`'s text payload is incorrectly showing during time `[2.4, 3.4]`. The fix updates the `SimpleTextDisplayer#append()` logic to split up individual non-container cues into their own `VTTCue` object. This will not be done at the `TTMLTextParser` level to ensure proper style inheritance still occurs for the (actual) text cues. Closes #4381
This changes the `SimpleTextDisplayer` to flatten text payloads only starting at non-container cues. Not doing so poses an issue with 'rolled over' caption lines. E.g., consider: - TTML file `N` with caption line `A` from time `[1.4, 2.1]`. - TTML file `N+1` with caption lines `A` from time `[1.4, 2.4]` and `B` from time `[2.4, 3.4]`. If captions `A` and `B` are descendants of two different `<p>` elements, Shaka currently flattens the text payload from `A` and `B` into a single cue that is rendered onto the display from time `[1.4, 3.4]`. Therefore, caption `A`'s text payload is incorrectly showing during time `[2.4, 3.4]`. The fix updates the `SimpleTextDisplayer#append()` logic to split up individual non-container cues into their own `VTTCue` object. This will not be done at the `TTMLTextParser` level to ensure proper style inheritance still occurs for the (actual) text cues. Closes #4381
This changes the `SimpleTextDisplayer` to flatten text payloads only starting at non-container cues. Not doing so poses an issue with 'rolled over' caption lines. E.g., consider: - TTML file `N` with caption line `A` from time `[1.4, 2.1]`. - TTML file `N+1` with caption lines `A` from time `[1.4, 2.4]` and `B` from time `[2.4, 3.4]`. If captions `A` and `B` are descendants of two different `<p>` elements, Shaka currently flattens the text payload from `A` and `B` into a single cue that is rendered onto the display from time `[1.4, 3.4]`. Therefore, caption `A`'s text payload is incorrectly showing during time `[2.4, 3.4]`. The fix updates the `SimpleTextDisplayer#append()` logic to split up individual non-container cues into their own `VTTCue` object. This will not be done at the `TTMLTextParser` level to ensure proper style inheritance still occurs for the (actual) text cues. Closes #4381
This changes the `SimpleTextDisplayer` to flatten text payloads only starting at non-container cues. Not doing so poses an issue with 'rolled over' caption lines. E.g., consider: - TTML file `N` with caption line `A` from time `[1.4, 2.1]`. - TTML file `N+1` with caption lines `A` from time `[1.4, 2.4]` and `B` from time `[2.4, 3.4]`. If captions `A` and `B` are descendants of two different `<p>` elements, Shaka currently flattens the text payload from `A` and `B` into a single cue that is rendered onto the display from time `[1.4, 3.4]`. Therefore, caption `A`'s text payload is incorrectly showing during time `[2.4, 3.4]`. The fix updates the `SimpleTextDisplayer#append()` logic to split up individual non-container cues into their own `VTTCue` object. This will not be done at the `TTMLTextParser` level to ensure proper style inheritance still occurs for the (actual) text cues. Closes #4381
This changes the
SimpleTextDisplayer
to flatten text payloadsonly starting at non-container cues. Not doing so poses an issue with
'rolled over' caption lines.
E.g., consider:
N
with caption lineA
from time[1.4, 2.1]
.N+1
with caption linesA
from time[1.4, 2.4]
andB
from time[2.4, 3.4]
.If captions
A
andB
are descendants of two different<p>
elements, Shakacurrently flattens the text payload from
A
andB
into a single cue that isrendered onto the display from time
[1.4, 3.4]
. Therefore, captionA
's textpayload is incorrectly showing during time
[2.4, 3.4]
.The fix updates the
SimpleTextDisplayer#append()
logic to split up individualnon-container cues into their own
VTTCue
object. This will not be done at theTTMLTextParser
level to ensure proper style inheritance still occurs for the(actual) text cues.
Closes #4381
BEGIN_COMMIT_OVERRIDE
fix(text): Fix TTML render timing and line break issues for native display
END_COMMIT_OVERRIDE