OLD | NEW |
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/cancelable_callback.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
13 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
14 #include "media/audio/audio_manager.h" | 15 #include "media/audio/audio_manager.h" |
15 #include "media/audio/audio_source_diverter.h" | 16 #include "media/audio/audio_source_diverter.h" |
16 #include "media/audio/simple_sources.h" | 17 #include "media/audio/simple_sources.h" |
17 #include "media/base/media_export.h" | 18 #include "media/base/media_export.h" |
18 | 19 |
19 // An AudioOutputController controls an AudioOutputStream and provides data | 20 // An AudioOutputController controls an AudioOutputStream and provides data |
(...skipping 25 matching lines...) Expand all Loading... |
45 // all functionally equivalent and require a Play() call to continue to the next | 46 // all functionally equivalent and require a Play() call to continue to the next |
46 // state. | 47 // state. |
47 // | 48 // |
48 // The AudioOutputStream can request data from the AudioOutputController via the | 49 // The AudioOutputStream can request data from the AudioOutputController via the |
49 // AudioSourceCallback interface. AudioOutputController uses the SyncReader | 50 // AudioSourceCallback interface. AudioOutputController uses the SyncReader |
50 // passed to it via construction to synchronously fulfill this read request. | 51 // passed to it via construction to synchronously fulfill this read request. |
51 // | 52 // |
52 | 53 |
53 namespace media { | 54 namespace media { |
54 | 55 |
55 class AudioSilenceDetector; | 56 class AudioPowerMonitor; |
56 | 57 |
57 class MEDIA_EXPORT AudioOutputController | 58 class MEDIA_EXPORT AudioOutputController |
58 : public base::RefCountedThreadSafe<AudioOutputController>, | 59 : public base::RefCountedThreadSafe<AudioOutputController>, |
59 public AudioOutputStream::AudioSourceCallback, | 60 public AudioOutputStream::AudioSourceCallback, |
60 public AudioSourceDiverter, | 61 public AudioSourceDiverter, |
61 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { | 62 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { |
62 public: | 63 public: |
63 // An event handler that receives events from the AudioOutputController. The | 64 // An event handler that receives events from the AudioOutputController. The |
64 // following methods are called on the audio manager thread. | 65 // following methods are called on the audio manager thread. |
65 class MEDIA_EXPORT EventHandler { | 66 class MEDIA_EXPORT EventHandler { |
66 public: | 67 public: |
67 virtual void OnCreated() = 0; | 68 virtual void OnCreated() = 0; |
68 virtual void OnPlaying() = 0; | 69 virtual void OnPlaying() = 0; |
69 virtual void OnAudible(bool is_audible) = 0; | 70 virtual void OnPowerMeasured(float power_dbfs, bool clipped) = 0; |
70 virtual void OnPaused() = 0; | 71 virtual void OnPaused() = 0; |
71 virtual void OnError() = 0; | 72 virtual void OnError() = 0; |
72 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) = 0; | 73 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) = 0; |
73 | 74 |
74 protected: | 75 protected: |
75 virtual ~EventHandler() {} | 76 virtual ~EventHandler() {} |
76 }; | 77 }; |
77 | 78 |
78 // A synchronous reader interface used by AudioOutputController for | 79 // A synchronous reader interface used by AudioOutputController for |
79 // synchronous reading. | 80 // synchronous reading. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 SyncReader* const sync_reader_; | 228 SyncReader* const sync_reader_; |
228 | 229 |
229 // The message loop of audio manager thread that this object runs on. | 230 // The message loop of audio manager thread that this object runs on. |
230 const scoped_refptr<base::MessageLoopProxy> message_loop_; | 231 const scoped_refptr<base::MessageLoopProxy> message_loop_; |
231 | 232 |
232 // When starting stream we wait for data to become available. | 233 // When starting stream we wait for data to become available. |
233 // Number of times left. | 234 // Number of times left. |
234 int number_polling_attempts_left_; | 235 int number_polling_attempts_left_; |
235 | 236 |
236 // Scans audio samples from OnMoreIOData() as input and causes | 237 // Scans audio samples from OnMoreIOData() as input and causes |
237 // EventHandler::OnAudbile() to be called whenever a transition to a period of | 238 // EventHandler::OnPowerMeasured() to be called with power level measurements |
238 // silence or non-silence is detected. | 239 // at regular intervals. |
239 scoped_ptr<AudioSilenceDetector> silence_detector_; | 240 scoped_ptr<AudioPowerMonitor> power_monitor_; |
| 241 base::CancelableCallback<void(float, bool)> power_monitor_callback_; |
240 | 242 |
241 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 243 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
242 }; | 244 }; |
243 | 245 |
244 } // namespace media | 246 } // namespace media |
245 | 247 |
246 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 248 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |