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 captions going missing when switching streams bug #2672

Merged

Conversation

muhammadharis
Copy link
Contributor

@muhammadharis muhammadharis commented Jun 22, 2020

This fix also pertains to #2648.
What problem does this change fix?
The problem is (somewhat) described by the comment (that is included in the diff) from media_source_engine.js. During video playback, if the user switches the caption stream (e.g. CC1 to CC3 which changes languages), the first caption in the next fragment is missing.

Why did this problem exist?
In fragmented MP4s, the end time of a caption is determined by the start time of the next caption. Thus for the last caption in a fragment, the end time cannot be determined until the next fragment is parsed.

Before this fix: the clearing of the caption stream was being called from a chain of function calls originating from clearBuffer_() on the Media source engine. But clearing a buffer and resetting a caption stream are two independent operations. As a result, the caption parser was being reset (its buffer cleared) during video seeks, and during stream switches. This makes sense for video seeks, because the end time of the last caption in the fragment can't be determined if the entire presentation timestamp changes. However for stream switches, resetting the parser doesn't make sense. Clearing the caption parser during a stream switch would actually get rid of the last caption in that fragment (which wasn't emitted since its end time wasn't determined yet), and we would lose the data, causing the problem.

What is the fix?
For reasons mentioned previously, the fix is to reset (and hence clear) the caption parser during seeks, but not during stream switches.

Copy link
Contributor

@michellezhuogg michellezhuogg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@joeyparrish
Copy link
Member

The missing captions were temporary, right? We would only miss the first caption after changing languages?

Copy link
Member

@joeyparrish joeyparrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Can you please add a regression test? I think something in streaming_engine_unit.js that verifies that we call resetCaptionParser on seek, but not on switch. (I know that test suite is a pain, so please ping me if you need help.)

@muhammadharis
Copy link
Contributor Author

muhammadharis commented Jun 23, 2020

The missing captions were temporary, right? We would only miss the first caption after changing languages?

Yes that is correct.

Can you please add a regression test?

I've updated this diff and added in tests.

@muhammadharis
Copy link
Contributor Author

I think this should be await streamingEngine.start()

Yes I agree. I was trying to follow the convention of the preceding test, but I think using await here makes more sense as well.

@joeyparrish
Copy link
Member

I think this should be await streamingEngine.start()

Yes I agree. I was trying to follow the convention of the preceding test, but I think using await here makes more sense as well.

You would use streamingEngine.start().catch(fail); if you didn't want to actually wait for startup to complete before calling the next steps of the test. For example, if you needed to test what happens when something is called during the async startup process. I'm not 100% sure the previous test needs that, but that would be the only good reason to do it as far as I can tell.

Copy link
Member

@joeyparrish joeyparrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@shaka-bot
Copy link
Collaborator

All tests passed!

@joeyparrish joeyparrish merged commit d383047 into shaka-project:master Jun 23, 2020
@muhammadharis muhammadharis deleted the caption-stream-switch-bug branch June 24, 2020 00:35
joeyparrish pushed a commit that referenced this pull request Jul 27, 2020
During video playback, if the user switches the caption stream (e.g. CC1 to CC3 which changes languages), the first caption in the next fragment is missing.

In fragmented MP4s, the end time of a caption is determined by the start time of the next caption. Thus for the last caption in a fragment, the end time cannot be determined until the next fragment is parsed.

Before this fix: the clearing of the caption stream was being called from a chain of function calls originating from clearBuffer_() on the Media source engine. But clearing a buffer and resetting a caption stream are two independent operations. As a result, the caption parser was being reset (its buffer cleared) during video seeks, and during stream switches. This makes sense for video seeks, because the end time of the last caption in the fragment can't be determined if the entire presentation timestamp changes. However for stream switches, resetting the parser doesn't make sense. Clearing the caption parser during a stream switch would actually get rid of the last caption in that fragment (which wasn't emitted since its end time wasn't determined yet), and we would lose the data, causing the problem.

The fix is to reset (and hence clear) the caption parser during seeks, but not during stream switches.

Issue #2648
@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.

4 participants