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 <stdint.h> | 8 #include <stdint.h> |
9 | |
10 #include <memory> | 9 #include <memory> |
10 #include <set> | |
11 | 11 |
12 #include "base/atomic_ref_count.h" | 12 #include "base/atomic_ref_count.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "media/audio/audio_io.h" | 19 #include "media/audio/audio_io.h" |
20 #include "media/audio/audio_manager.h" | 20 #include "media/audio/audio_manager.h" |
21 #include "media/audio/audio_power_monitor.h" | 21 #include "media/audio/audio_power_monitor.h" |
22 #include "media/audio/audio_source_diverter.h" | 22 #include "media/audio/audio_source_diverter.h" |
23 #include "media/audio/simple_sources.h" | 23 #include "media/audio/simple_sources.h" |
24 #include "media/audio/virtual_audio_sink.h" | |
miu
2016/05/06 22:29:50
You can remove this #include now that AudioPushSin
qiangchen
2016/05/10 22:36:53
Done.
| |
24 #include "media/base/media_export.h" | 25 #include "media/base/media_export.h" |
25 | 26 |
26 // An AudioOutputController controls an AudioOutputStream and provides data | 27 // An AudioOutputController controls an AudioOutputStream and provides data |
27 // to this output stream. It has an important function that it executes | 28 // to this output stream. It has an important function that it executes |
28 // audio operations like play, pause, stop, etc. on a separate thread, | 29 // audio operations like play, pause, stop, etc. on a separate thread, |
29 // namely the audio manager thread. | 30 // namely the audio manager thread. |
30 // | 31 // |
31 // All the public methods of AudioOutputController are non-blocking. | 32 // All the public methods of AudioOutputController are non-blocking. |
32 // The actual operations are performed on the audio manager thread. | 33 // The actual operations are performed on the audio manager thread. |
33 // | 34 // |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 // AudioDeviceListener implementation. When called AudioOutputController will | 172 // AudioDeviceListener implementation. When called AudioOutputController will |
172 // shutdown the existing |stream_|, transition to the kRecreating state, | 173 // shutdown the existing |stream_|, transition to the kRecreating state, |
173 // create a new stream, and then transition back to an equivalent state prior | 174 // create a new stream, and then transition back to an equivalent state prior |
174 // to being called. | 175 // to being called. |
175 void OnDeviceChange() override; | 176 void OnDeviceChange() override; |
176 | 177 |
177 // AudioSourceDiverter implementation. | 178 // AudioSourceDiverter implementation. |
178 const AudioParameters& GetAudioParameters() override; | 179 const AudioParameters& GetAudioParameters() override; |
179 void StartDiverting(AudioOutputStream* to_stream) override; | 180 void StartDiverting(AudioOutputStream* to_stream) override; |
180 void StopDiverting() override; | 181 void StopDiverting() override; |
182 void StartDuplicating(AudioPushSink* sink) override; | |
183 void StopDuplicating(AudioPushSink* sink) override; | |
181 | 184 |
182 // Accessor for AudioPowerMonitor::ReadCurrentPowerAndClip(). See comments in | 185 // Accessor for AudioPowerMonitor::ReadCurrentPowerAndClip(). See comments in |
183 // audio_power_monitor.h for usage. This may be called on any thread. | 186 // audio_power_monitor.h for usage. This may be called on any thread. |
184 std::pair<float, bool> ReadCurrentPowerAndClip(); | 187 std::pair<float, bool> ReadCurrentPowerAndClip(); |
185 | 188 |
186 protected: | 189 protected: |
187 // Internal state of the source. | 190 // Internal state of the source. |
188 enum State { | 191 enum State { |
189 kEmpty, | 192 kEmpty, |
190 kCreated, | 193 kCreated, |
(...skipping 20 matching lines...) Expand all Loading... | |
211 void DoCreate(bool is_for_device_change); | 214 void DoCreate(bool is_for_device_change); |
212 void DoPlay(); | 215 void DoPlay(); |
213 void DoPause(); | 216 void DoPause(); |
214 void DoClose(); | 217 void DoClose(); |
215 void DoSetVolume(double volume); | 218 void DoSetVolume(double volume); |
216 std::string DoGetOutputDeviceId() const; | 219 std::string DoGetOutputDeviceId() const; |
217 void DoSwitchOutputDevice(const std::string& output_device_id); | 220 void DoSwitchOutputDevice(const std::string& output_device_id); |
218 void DoReportError(); | 221 void DoReportError(); |
219 void DoStartDiverting(AudioOutputStream* to_stream); | 222 void DoStartDiverting(AudioOutputStream* to_stream); |
220 void DoStopDiverting(); | 223 void DoStopDiverting(); |
224 void DoStartDuplicating(AudioPushSink* sink); | |
225 void DoStopDuplicating(AudioPushSink* sink); | |
221 | 226 |
222 // Helper method that stops the physical stream. | 227 // Helper method that stops the physical stream. |
223 void StopStream(); | 228 void StopStream(); |
224 | 229 |
225 // Helper method that stops, closes, and NULLs |*stream_|. | 230 // Helper method that stops, closes, and NULLs |*stream_|. |
226 void DoStopCloseAndClearStream(); | 231 void DoStopCloseAndClearStream(); |
227 | 232 |
228 // Checks if a stream was started successfully but never calls OnMoreData(). | 233 // Checks if a stream was started successfully but never calls OnMoreData(). |
229 void WedgeCheck(); | 234 void WedgeCheck(); |
230 | 235 |
231 AudioManager* const audio_manager_; | 236 AudioManager* const audio_manager_; |
232 const AudioParameters params_; | 237 const AudioParameters params_; |
233 EventHandler* const handler_; | 238 EventHandler* const handler_; |
234 | 239 |
235 // Specifies the device id of the output device to open or empty for the | 240 // Specifies the device id of the output device to open or empty for the |
236 // default output device. | 241 // default output device. |
237 std::string output_device_id_; | 242 std::string output_device_id_; |
238 | 243 |
239 AudioOutputStream* stream_; | 244 AudioOutputStream* stream_; |
240 | 245 |
241 // When non-NULL, audio is being diverted to this stream. | 246 // When non-NULL, audio is being diverted to this stream. |
242 AudioOutputStream* diverting_to_stream_; | 247 AudioOutputStream* diverting_to_stream_; |
243 | 248 |
249 // The targets for audio stream to be copied to. | |
250 std::set<AudioPushSink*> duplication_targets_; | |
251 | |
244 // The current volume of the audio stream. | 252 // The current volume of the audio stream. |
245 double volume_; | 253 double volume_; |
246 | 254 |
247 // |state_| may only be used on the audio manager thread. | 255 // |state_| may only be used on the audio manager thread. |
248 State state_; | 256 State state_; |
249 | 257 |
250 // SyncReader is used only in low latency mode for synchronous reading. | 258 // SyncReader is used only in low latency mode for synchronous reading. |
251 SyncReader* const sync_reader_; | 259 SyncReader* const sync_reader_; |
252 | 260 |
253 // The message loop of audio manager thread that this object runs on. | 261 // The message loop of audio manager thread that this object runs on. |
(...skipping 15 matching lines...) Expand all Loading... | |
269 // be accessed while |error_lock_| is held. | 277 // be accessed while |error_lock_| is held. |
270 bool ignore_errors_during_stop_close_; | 278 bool ignore_errors_during_stop_close_; |
271 base::Lock error_lock_; | 279 base::Lock error_lock_; |
272 | 280 |
273 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 281 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
274 }; | 282 }; |
275 | 283 |
276 } // namespace media | 284 } // namespace media |
277 | 285 |
278 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 286 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |