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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // | 147 // |
148 // Changing the output device causes the controller to go through | 148 // Changing the output device causes the controller to go through |
149 // the same state transition back to the current state as a call to | 149 // the same state transition back to the current state as a call to |
150 // OnDeviceChange (unless it is currently diverting, see | 150 // OnDeviceChange (unless it is currently diverting, see |
151 // Start/StopDiverting below, in which case the state transition | 151 // Start/StopDiverting below, in which case the state transition |
152 // will happen when StopDiverting is called). | 152 // will happen when StopDiverting is called). |
153 void SwitchOutputDevice(const std::string& output_device_id, | 153 void SwitchOutputDevice(const std::string& output_device_id, |
154 const base::Closure& callback); | 154 const base::Closure& callback); |
155 | 155 |
156 // AudioSourceCallback implementation. | 156 // AudioSourceCallback implementation. |
157 virtual int OnMoreData(AudioBus* dest, | 157 int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) override; |
158 uint32 total_bytes_delay) override; | 158 void OnError(AudioOutputStream* stream) override; |
159 virtual void OnError(AudioOutputStream* stream) override; | |
160 | 159 |
161 // AudioDeviceListener implementation. When called AudioOutputController will | 160 // AudioDeviceListener implementation. When called AudioOutputController will |
162 // shutdown the existing |stream_|, transition to the kRecreating state, | 161 // shutdown the existing |stream_|, transition to the kRecreating state, |
163 // create a new stream, and then transition back to an equivalent state prior | 162 // create a new stream, and then transition back to an equivalent state prior |
164 // to being called. | 163 // to being called. |
165 virtual void OnDeviceChange() override; | 164 void OnDeviceChange() override; |
166 | 165 |
167 // AudioSourceDiverter implementation. | 166 // AudioSourceDiverter implementation. |
168 virtual const AudioParameters& GetAudioParameters() override; | 167 const AudioParameters& GetAudioParameters() override; |
169 virtual void StartDiverting(AudioOutputStream* to_stream) override; | 168 void StartDiverting(AudioOutputStream* to_stream) override; |
170 virtual void StopDiverting() override; | 169 void StopDiverting() override; |
171 | 170 |
172 // Accessor for AudioPowerMonitor::ReadCurrentPowerAndClip(). See comments in | 171 // Accessor for AudioPowerMonitor::ReadCurrentPowerAndClip(). See comments in |
173 // audio_power_monitor.h for usage. This may be called on any thread. | 172 // audio_power_monitor.h for usage. This may be called on any thread. |
174 std::pair<float, bool> ReadCurrentPowerAndClip(); | 173 std::pair<float, bool> ReadCurrentPowerAndClip(); |
175 | 174 |
176 protected: | 175 protected: |
177 // Internal state of the source. | 176 // Internal state of the source. |
178 enum State { | 177 enum State { |
179 kEmpty, | 178 kEmpty, |
180 kCreated, | 179 kCreated, |
181 kPlaying, | 180 kPlaying, |
182 kPaused, | 181 kPaused, |
183 kClosed, | 182 kClosed, |
184 kError, | 183 kError, |
185 }; | 184 }; |
186 | 185 |
187 // Time constant for AudioPowerMonitor. See AudioPowerMonitor ctor comments | 186 // Time constant for AudioPowerMonitor. See AudioPowerMonitor ctor comments |
188 // for semantics. This value was arbitrarily chosen, but seems to work well. | 187 // for semantics. This value was arbitrarily chosen, but seems to work well. |
189 enum { kPowerMeasurementTimeConstantMillis = 10 }; | 188 enum { kPowerMeasurementTimeConstantMillis = 10 }; |
190 | 189 |
191 friend class base::RefCountedThreadSafe<AudioOutputController>; | 190 friend class base::RefCountedThreadSafe<AudioOutputController>; |
192 virtual ~AudioOutputController(); | 191 ~AudioOutputController() override; |
193 | 192 |
194 private: | 193 private: |
195 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, | 194 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, |
196 const AudioParameters& params, | 195 const AudioParameters& params, |
197 const std::string& output_device_id, | 196 const std::string& output_device_id, |
198 SyncReader* sync_reader); | 197 SyncReader* sync_reader); |
199 | 198 |
200 // The following methods are executed on the audio manager thread. | 199 // The following methods are executed on the audio manager thread. |
201 void DoCreate(bool is_for_device_change); | 200 void DoCreate(bool is_for_device_change); |
202 void DoPlay(); | 201 void DoPlay(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Flags when we've asked for a stream to start but it never did. | 250 // Flags when we've asked for a stream to start but it never did. |
252 base::AtomicRefCount on_more_io_data_called_; | 251 base::AtomicRefCount on_more_io_data_called_; |
253 scoped_ptr<base::OneShotTimer<AudioOutputController> > wedge_timer_; | 252 scoped_ptr<base::OneShotTimer<AudioOutputController> > wedge_timer_; |
254 | 253 |
255 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 254 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
256 }; | 255 }; |
257 | 256 |
258 } // namespace media | 257 } // namespace media |
259 | 258 |
260 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 259 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |