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

Avoid calling GetMediaTime() on media thread #4703

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jasonzhangxx
Copy link
Contributor

GetMediaTime() is mostly called on main thread. Instead of calling GetMediaTime() in StarboardRenderer::OnNeedData(), the cl now uses |last_media_time_| and |last_time_media_time_retrieved_| to estimate current media time. As HTMLMediaElement updates media time at least every 250ms, |last_media_time_| and |last_time_media_time_retrieved_| should also be updated at least every 250ms, which should be sufficient to limit audio write ahead.

b/376328722

GetMediaTime() is mostly called on main thread. Instead of calling
GetMediaTime() in StarboardRenderer::OnNeedData(), the cl now uses
|last_media_time_| and |last_time_media_time_retrieved_| to estimate
current media time. As HTMLMediaElement updates media time at least
every 250ms, |last_media_time_| and |last_time_media_time_retrieved_|
should also be updated at least every 250ms, which should be sufficient
to limit audio write ahead.

b/376328722
@jasonzhangxx jasonzhangxx requested a review from a team as a code owner January 15, 2025 23:55
timestamp_of_last_written_audio_ - last_media_time_;
TimeDelta time_ahead_of_playback;
{
base::AutoLock auto_lock(lock_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Now the implementation may write 250ms more audio data when playback is paused. It's probably not an issue, but just bring it up.

@@ -703,8 +698,15 @@ void StarboardRenderer::OnNeedData(DemuxerStream::Type type,
adjusted_write_duration_for_preroll) {
// The estimated time ahead of playback may be negative if no audio has
// been written.
TimeDelta time_ahead_of_playback =
timestamp_of_last_written_audio_ - last_media_time_;
TimeDelta time_ahead_of_playback;
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment above is too far from the calculate and usage of this variable after the change, considering moving it down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants