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

fix(text): Fix TTML render timing and line break issues #4407

Merged
merged 3 commits into from
Aug 16, 2022

Conversation

JulianDomingo
Copy link
Contributor

@JulianDomingo JulianDomingo commented Aug 13, 2022

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

BEGIN_COMMIT_OVERRIDE
fix(text): Fix TTML render timing and line break issues for native display
END_COMMIT_OVERRIDE

…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
@joeyparrish
Copy link
Member

That is an excellent PR description. Very helpful!

const getCuesToFlatten = (cues) => {
for (const cue of cues) {
if (cue.isContainer) {
flattenedCues =
Copy link
Member

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).

Copy link
Contributor Author

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', () => {
Copy link
Member

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.

Copy link
Contributor Author

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.

const flatCue = cue.clone();
flatCue.nestedCues = [];
flatCue.payload = flattenPayload(cue);
flattenedCues = flattenedCues.concat(flatCue);
Copy link
Member

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.

Copy link
Contributor Author

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!

@joeyparrish joeyparrish merged commit 122f223 into shaka-project:main Aug 16, 2022
joeyparrish pushed a commit that referenced this pull request Aug 16, 2022
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
joeyparrish pushed a commit that referenced this pull request Aug 16, 2022
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
joeyparrish pushed a commit that referenced this pull request Aug 16, 2022
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
joeyparrish pushed a commit that referenced this pull request Aug 16, 2022
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
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ttml subtitle position different with shaka-player 3.2.0 and 4.1.1
2 participants