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/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // The AudioOutputStream can request data from the AudioOutputController via the | 50 // The AudioOutputStream can request data from the AudioOutputController via the |
51 // AudioSourceCallback interface. AudioOutputController uses the SyncReader | 51 // AudioSourceCallback interface. AudioOutputController uses the SyncReader |
52 // passed to it via construction to synchronously fulfill this read request. | 52 // passed to it via construction to synchronously fulfill this read request. |
53 // | 53 // |
54 // Since AudioOutputController uses AudioManager's message loop the controller | 54 // Since AudioOutputController uses AudioManager's message loop the controller |
55 // uses WeakPtr to allow safe cancellation of pending tasks. | 55 // uses WeakPtr to allow safe cancellation of pending tasks. |
56 // | 56 // |
57 | 57 |
58 namespace media { | 58 namespace media { |
59 | 59 |
60 class AudioSilenceDetector; | 60 class AudioPowerMonitor; |
61 | 61 |
62 class MEDIA_EXPORT AudioOutputController | 62 class MEDIA_EXPORT AudioOutputController |
63 : public base::RefCountedThreadSafe<AudioOutputController>, | 63 : public base::RefCountedThreadSafe<AudioOutputController>, |
64 public AudioOutputStream::AudioSourceCallback, | 64 public AudioOutputStream::AudioSourceCallback, |
65 public AudioSourceDiverter, | 65 public AudioSourceDiverter, |
66 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { | 66 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { |
67 public: | 67 public: |
68 // An event handler that receives events from the AudioOutputController. The | 68 // An event handler that receives events from the AudioOutputController. The |
69 // following methods are called on the audio manager thread. | 69 // following methods are called on the audio manager thread. |
70 class MEDIA_EXPORT EventHandler { | 70 class MEDIA_EXPORT EventHandler { |
71 public: | 71 public: |
72 virtual void OnCreated() = 0; | 72 virtual void OnCreated() = 0; |
73 virtual void OnPlaying() = 0; | 73 virtual void OnPlaying() = 0; |
74 virtual void OnAudible(bool is_audible) = 0; | 74 virtual void OnPowerMeasured(float power_in_dbfs) = 0; |
75 virtual void OnPaused() = 0; | 75 virtual void OnPaused() = 0; |
76 virtual void OnError() = 0; | 76 virtual void OnError() = 0; |
77 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) = 0; | 77 virtual void OnDeviceChange(int new_buffer_size, int new_sample_rate) = 0; |
78 | 78 |
79 protected: | 79 protected: |
80 virtual ~EventHandler() {} | 80 virtual ~EventHandler() {} |
81 }; | 81 }; |
82 | 82 |
83 // A synchronous reader interface used by AudioOutputController for | 83 // A synchronous reader interface used by AudioOutputController for |
84 // synchronous reading. | 84 // synchronous reading. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 240 |
241 // When starting stream we wait for data to become available. | 241 // When starting stream we wait for data to become available. |
242 // Number of times left. | 242 // Number of times left. |
243 int number_polling_attempts_left_; | 243 int number_polling_attempts_left_; |
244 | 244 |
245 // Used to auto-cancel the delayed tasks that are created to poll for data | 245 // Used to auto-cancel the delayed tasks that are created to poll for data |
246 // (when starting-up a stream). | 246 // (when starting-up a stream). |
247 base::WeakPtrFactory<AudioOutputController> weak_this_; | 247 base::WeakPtrFactory<AudioOutputController> weak_this_; |
248 | 248 |
249 // Scans audio samples from OnMoreIOData() as input and causes | 249 // Scans audio samples from OnMoreIOData() as input and causes |
250 // EventHandler::OnAudbile() to be called whenever a transition to a period of | 250 // EventHandler::OnPowerMeasured() to be called with power level measurements |
251 // silence or non-silence is detected. | 251 // at regular intervals. |
252 scoped_ptr<AudioSilenceDetector> silence_detector_; | 252 scoped_ptr<AudioPowerMonitor> power_monitor_; |
253 | 253 |
254 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 254 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
255 }; | 255 }; |
256 | 256 |
257 } // namespace media | 257 } // namespace media |
258 | 258 |
259 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 259 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |