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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions media/starboard/starboard_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ void StarboardRenderer::SetVolume(float volume) {
}
}

// TODO(b/376328722): Revisit playback time reporting.
// Note: Renderer::GetMediaTime() could be called on both main and media
// threads.
TimeDelta StarboardRenderer::GetMediaTime() {
base::AutoLock auto_lock(lock_);

Expand Down Expand Up @@ -675,12 +676,6 @@ void StarboardRenderer::OnNeedData(DemuxerStream::Type type,
return;
}

// If we haven't checked the media time recently, update it now.
if (Time::Now() - last_time_media_time_retrieved_ >
kMediaTimeCheckInterval) {
GetMediaTime();
}

// Delay reading audio more than |audio_write_duration_| ahead of playback
// after the player has received enough audio for preroll, taking into
// account that our estimate of playback time might be behind by
Expand All @@ -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.

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

TimeDelta time_since_last_update =
Time::Now() - last_time_media_time_retrieved_;
time_ahead_of_playback = timestamp_of_last_written_audio_ -
(last_media_time_ + time_since_last_update);
}

auto adjusted_write_duration = AdjustWriteDurationForPlaybackRate(
audio_write_duration_, playback_rate_);
if (time_ahead_of_playback >
Expand Down
Loading