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

Side by Side Diff: media/audio/audio_output_controller.h

Issue 14600025: Replace AudioSilenceDetector with an AudioPowerMonitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix subtle shutdown race condition. Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 6 #define MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
7 7
8 #include "base/atomic_ref_count.h" 8 #include "base/atomic_ref_count.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // all functionally equivalent and require a Play() call to continue to the next 45 // all functionally equivalent and require a Play() call to continue to the next
46 // state. 46 // state.
47 // 47 //
48 // The AudioOutputStream can request data from the AudioOutputController via the 48 // The AudioOutputStream can request data from the AudioOutputController via the
49 // AudioSourceCallback interface. AudioOutputController uses the SyncReader 49 // AudioSourceCallback interface. AudioOutputController uses the SyncReader
50 // passed to it via construction to synchronously fulfill this read request. 50 // passed to it via construction to synchronously fulfill this read request.
51 // 51 //
52 52
53 namespace media { 53 namespace media {
54 54
55 class AudioSilenceDetector; 55 class AudioPowerMonitor;
56 56
57 class MEDIA_EXPORT AudioOutputController 57 class MEDIA_EXPORT AudioOutputController
58 : public base::RefCountedThreadSafe<AudioOutputController>, 58 : public base::RefCountedThreadSafe<AudioOutputController>,
59 public AudioOutputStream::AudioSourceCallback, 59 public AudioOutputStream::AudioSourceCallback,
60 public AudioSourceDiverter, 60 public AudioSourceDiverter,
61 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { 61 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) {
62 public: 62 public:
63 // An event handler that receives events from the AudioOutputController. The 63 // An event handler that receives events from the AudioOutputController. The
64 // following methods are called on the audio manager thread. 64 // following methods are called on the audio manager thread.
65 class MEDIA_EXPORT EventHandler { 65 class MEDIA_EXPORT EventHandler {
66 public: 66 public:
67 virtual void OnCreated() = 0; 67 virtual void OnCreated() = 0;
68 virtual void OnPlaying() = 0; 68 virtual void OnPlaying() = 0;
69 virtual void OnAudible(bool is_audible) = 0; 69 virtual void OnPowerMeasured(float power_dbfs, bool clipped) = 0;
70 virtual void OnPaused() = 0; 70 virtual void OnPaused() = 0;
71 virtual void OnError() = 0; 71 virtual void OnError() = 0;
72 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) = 0; 72 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) = 0;
73 73
74 protected: 74 protected:
75 virtual ~EventHandler() {} 75 virtual ~EventHandler() {}
76 }; 76 };
77 77
78 // A synchronous reader interface used by AudioOutputController for 78 // A synchronous reader interface used by AudioOutputController for
79 // synchronous reading. 79 // synchronous reading.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, 169 AudioOutputController(AudioManager* audio_manager, EventHandler* handler,
170 const AudioParameters& params, 170 const AudioParameters& params,
171 const std::string& input_device_id, 171 const std::string& input_device_id,
172 SyncReader* sync_reader); 172 SyncReader* sync_reader);
173 173
174 // The following methods are executed on the audio manager thread. 174 // The following methods are executed on the audio manager thread.
175 void DoCreate(bool is_for_device_change); 175 void DoCreate(bool is_for_device_change);
176 void DoPlay(); 176 void DoPlay();
177 void DoPause(); 177 void DoPause();
178 void DoClose(); 178 void DoClose(const base::Closure& done_callback);
179 void DoSetVolume(double volume); 179 void DoSetVolume(double volume);
180 void DoReportError(); 180 void DoReportError();
181 void DoStartDiverting(AudioOutputStream* to_stream); 181 void DoStartDiverting(AudioOutputStream* to_stream);
182 void DoStopDiverting(); 182 void DoStopDiverting();
183 183
184 // Called at regular intervals during playback to check for a change in 184 // Called at regular intervals during playback to check for a change in
185 // silence and call EventHandler::OnAudible() when state changes occur. 185 // silence and call EventHandler::OnAudible() when state changes occur.
186 void MaybeInvokeAudibleCallback(); 186 void MaybeInvokeAudibleCallback();
187 187
188 // Helper method that stops the physical stream. 188 // Helper method that stops the physical stream.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 SyncReader* const sync_reader_; 227 SyncReader* const sync_reader_;
228 228
229 // The message loop of audio manager thread that this object runs on. 229 // The message loop of audio manager thread that this object runs on.
230 const scoped_refptr<base::MessageLoopProxy> message_loop_; 230 const scoped_refptr<base::MessageLoopProxy> message_loop_;
231 231
232 // When starting stream we wait for data to become available. 232 // When starting stream we wait for data to become available.
233 // Number of times left. 233 // Number of times left.
234 int number_polling_attempts_left_; 234 int number_polling_attempts_left_;
235 235
236 // Scans audio samples from OnMoreIOData() as input and causes 236 // Scans audio samples from OnMoreIOData() as input and causes
237 // EventHandler::OnAudbile() to be called whenever a transition to a period of 237 // EventHandler::OnPowerMeasured() to be called with power level measurements
238 // silence or non-silence is detected. 238 // at regular intervals.
239 scoped_ptr<AudioSilenceDetector> silence_detector_; 239 scoped_ptr<AudioPowerMonitor> power_monitor_;
240 240
241 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); 241 DISALLOW_COPY_AND_ASSIGN(AudioOutputController);
242 }; 242 };
243 243
244 } // namespace media 244 } // namespace media
245 245
246 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ 246 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698