Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Unified Diff: media/audio/clockless_audio_sink.cc

Issue 22999010: Improve ClocklessAudioSink so it doesn't hog CPU if nothing to do. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/clockless_audio_sink.cc
diff --git a/media/audio/clockless_audio_sink.cc b/media/audio/clockless_audio_sink.cc
index ab56115c27fefe5304dff4d506b257fedc4cc945..ff809d0541dd49fc87f6559bf901563cb5c92cdc 100644
--- a/media/audio/clockless_audio_sink.cc
+++ b/media/audio/clockless_audio_sink.cc
@@ -36,10 +36,16 @@ class ClocklessAudioSinkThread : public base::DelegateSimpleThread::Delegate {
private:
// Call Render() repeatedly, keeping track of the rendering time.
virtual void Run() OVERRIDE {
- base::TimeTicks start = base::TimeTicks::HighResNow();
+ base::TimeTicks start;
while (!stop_event_->IsSignaled()) {
int frames_received = callback_->Render(audio_bus_.get(), 0);
- if (frames_received > 0) {
+ if (frames_received <= 0) {
+ // No data received, so let other threads run to provide data.
+ base::PlatformThread::YieldCurrentThread();
+ } else if (start.is_null()) {
+ // First time we processed some audio, so record the starting time.
+ start = base::TimeTicks::HighResNow();
+ } else {
// Keep track of the last time data was rendered.
playback_time_ = base::TimeTicks::HighResNow() - start;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698