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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/clockless_audio_sink.h" 5 #include "media/audio/clockless_audio_sink.h"
6 6
7 #include "base/threading/simple_thread.h" 7 #include "base/threading/simple_thread.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "media/base/audio_renderer_sink.h" 9 #include "media/base/audio_renderer_sink.h"
10 10
(...skipping 18 matching lines...) Expand all
29 // Generate a signal to stop calling Render(). 29 // Generate a signal to stop calling Render().
30 base::TimeDelta Stop() { 30 base::TimeDelta Stop() {
31 stop_event_->Signal(); 31 stop_event_->Signal();
32 thread_->Join(); 32 thread_->Join();
33 return playback_time_; 33 return playback_time_;
34 } 34 }
35 35
36 private: 36 private:
37 // Call Render() repeatedly, keeping track of the rendering time. 37 // Call Render() repeatedly, keeping track of the rendering time.
38 virtual void Run() OVERRIDE { 38 virtual void Run() OVERRIDE {
39 base::TimeTicks start = base::TimeTicks::HighResNow(); 39 base::TimeTicks start;
40 while (!stop_event_->IsSignaled()) { 40 while (!stop_event_->IsSignaled()) {
41 int frames_received = callback_->Render(audio_bus_.get(), 0); 41 int frames_received = callback_->Render(audio_bus_.get(), 0);
42 if (frames_received > 0) { 42 if (frames_received <= 0) {
43 // No data received, so let other threads run to provide data.
44 base::PlatformThread::YieldCurrentThread();
45 } else if (start.is_null()) {
46 // First time we processed some audio, so record the starting time.
47 start = base::TimeTicks::HighResNow();
48 } else {
43 // Keep track of the last time data was rendered. 49 // Keep track of the last time data was rendered.
44 playback_time_ = base::TimeTicks::HighResNow() - start; 50 playback_time_ = base::TimeTicks::HighResNow() - start;
45 } 51 }
46 } 52 }
47 } 53 }
48 54
49 AudioRendererSink::RenderCallback* callback_; 55 AudioRendererSink::RenderCallback* callback_;
50 scoped_ptr<AudioBus> audio_bus_; 56 scoped_ptr<AudioBus> audio_bus_;
51 scoped_ptr<base::WaitableEvent> stop_event_; 57 scoped_ptr<base::WaitableEvent> stop_event_;
52 scoped_ptr<base::DelegateSimpleThread> thread_; 58 scoped_ptr<base::DelegateSimpleThread> thread_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 void ClocklessAudioSink::Pause() { 98 void ClocklessAudioSink::Pause() {
93 Stop(); 99 Stop();
94 } 100 }
95 101
96 bool ClocklessAudioSink::SetVolume(double volume) { 102 bool ClocklessAudioSink::SetVolume(double volume) {
97 // Audio is always muted. 103 // Audio is always muted.
98 return volume == 0.0; 104 return volume == 0.0;
99 } 105 }
100 106
101 } // namespace media 107 } // namespace media
OLDNEW
« 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