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 | 9 |
10 #include "base/atomic_ref_count.h" | 10 #include "base/atomic_ref_count.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "media/audio/audio_io.h" | 17 #include "media/audio/audio_io.h" |
18 #include "media/audio/audio_manager.h" | 18 #include "media/audio/audio_manager.h" |
19 #include "media/audio/audio_power_monitor.h" | 19 #include "media/audio/audio_power_monitor.h" |
20 #include "media/audio/audio_source_diverter.h" | 20 #include "media/audio/audio_source_diverter.h" |
21 #include "media/audio/simple_sources.h" | 21 #include "media/audio/simple_sources.h" |
22 #include "media/base/media_export.h" | 22 #include "media/base/media_export.h" |
| 23 #include "media/mojo/interfaces/audio_output.mojom.h" |
23 | 24 |
24 // An AudioOutputController controls an AudioOutputStream and provides data | 25 // An AudioOutputController controls an AudioOutputStream and provides data |
25 // to this output stream. It has an important function that it executes | 26 // to this output stream. It has an important function that it executes |
26 // audio operations like play, pause, stop, etc. on a separate thread, | 27 // audio operations like play, pause, stop, etc. on a separate thread, |
27 // namely the audio manager thread. | 28 // namely the audio manager thread. |
28 // | 29 // |
29 // All the public methods of AudioOutputController are non-blocking. | 30 // All the public methods of AudioOutputController are non-blocking. |
30 // The actual operations are performed on the audio manager thread. | 31 // The actual operations are performed on the audio manager thread. |
31 // | 32 // |
32 // Here is a state transition diagram for the AudioOutputController: | 33 // Here is a state transition diagram for the AudioOutputController: |
(...skipping 27 matching lines...) Expand all Loading... |
60 class MEDIA_EXPORT AudioOutputController | 61 class MEDIA_EXPORT AudioOutputController |
61 : public base::RefCountedThreadSafe<AudioOutputController>, | 62 : public base::RefCountedThreadSafe<AudioOutputController>, |
62 public AudioOutputStream::AudioSourceCallback, | 63 public AudioOutputStream::AudioSourceCallback, |
63 public AudioSourceDiverter, | 64 public AudioSourceDiverter, |
64 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { | 65 NON_EXPORTED_BASE(public AudioManager::AudioDeviceListener) { |
65 public: | 66 public: |
66 // An event handler that receives events from the AudioOutputController. The | 67 // An event handler that receives events from the AudioOutputController. The |
67 // following methods are called on the audio manager thread. | 68 // following methods are called on the audio manager thread. |
68 class MEDIA_EXPORT EventHandler { | 69 class MEDIA_EXPORT EventHandler { |
69 public: | 70 public: |
70 virtual void OnCreated() = 0; | 71 virtual void OnCreated( |
| 72 const content::mojom::AudioOutput::CreateStreamCallback& callback) = 0; |
71 virtual void OnPlaying() = 0; | 73 virtual void OnPlaying() = 0; |
72 virtual void OnPaused() = 0; | 74 virtual void OnPaused() = 0; |
73 virtual void OnError() = 0; | 75 virtual void OnError() = 0; |
74 | 76 |
75 protected: | 77 protected: |
76 virtual ~EventHandler() {} | 78 virtual ~EventHandler() {} |
77 }; | 79 }; |
78 | 80 |
79 // A synchronous reader interface used by AudioOutputController for | 81 // A synchronous reader interface used by AudioOutputController for |
80 // synchronous reading. | 82 // synchronous reading. |
(...skipping 21 matching lines...) Expand all Loading... |
102 }; | 104 }; |
103 | 105 |
104 // Factory method for creating an AudioOutputController. | 106 // Factory method for creating an AudioOutputController. |
105 // This also creates and opens an AudioOutputStream on the audio manager | 107 // This also creates and opens an AudioOutputStream on the audio manager |
106 // thread, and if this is successful, the |event_handler| will receive an | 108 // thread, and if this is successful, the |event_handler| will receive an |
107 // OnCreated() call from the same audio manager thread. |audio_manager| must | 109 // OnCreated() call from the same audio manager thread. |audio_manager| must |
108 // outlive AudioOutputController. | 110 // outlive AudioOutputController. |
109 // The |output_device_id| can be either empty (default device) or specify a | 111 // The |output_device_id| can be either empty (default device) or specify a |
110 // specific hardware device for audio output. | 112 // specific hardware device for audio output. |
111 static scoped_refptr<AudioOutputController> Create( | 113 static scoped_refptr<AudioOutputController> Create( |
112 AudioManager* audio_manager, EventHandler* event_handler, | 114 AudioManager* audio_manager, |
113 const AudioParameters& params, const std::string& output_device_id, | 115 EventHandler* event_handler, |
114 SyncReader* sync_reader); | 116 const AudioParameters& params, |
| 117 const std::string& output_device_id, |
| 118 SyncReader* sync_reader, |
| 119 const content::mojom::AudioOutput::CreateStreamCallback& callback); |
115 | 120 |
116 // Indicates whether audio power level analysis will be performed. If false, | 121 // Indicates whether audio power level analysis will be performed. If false, |
117 // ReadCurrentPowerAndClip() can not be called. | 122 // ReadCurrentPowerAndClip() can not be called. |
118 static bool will_monitor_audio_levels() { | 123 static bool will_monitor_audio_levels() { |
119 #if defined(OS_ANDROID) || defined(OS_IOS) | 124 #if defined(OS_ANDROID) || defined(OS_IOS) |
120 return false; | 125 return false; |
121 #else | 126 #else |
122 return true; | 127 return true; |
123 #endif | 128 #endif |
124 } | 129 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 friend class base::RefCountedThreadSafe<AudioOutputController>; | 204 friend class base::RefCountedThreadSafe<AudioOutputController>; |
200 ~AudioOutputController() override; | 205 ~AudioOutputController() override; |
201 | 206 |
202 private: | 207 private: |
203 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, | 208 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, |
204 const AudioParameters& params, | 209 const AudioParameters& params, |
205 const std::string& output_device_id, | 210 const std::string& output_device_id, |
206 SyncReader* sync_reader); | 211 SyncReader* sync_reader); |
207 | 212 |
208 // The following methods are executed on the audio manager thread. | 213 // The following methods are executed on the audio manager thread. |
209 void DoCreate(bool is_for_device_change); | 214 void DoCreate( |
| 215 bool is_for_device_change, |
| 216 const content::mojom::AudioOutput::CreateStreamCallback& callback); |
210 void DoPlay(); | 217 void DoPlay(); |
211 void DoPause(); | 218 void DoPause(); |
212 void DoClose(); | 219 void DoClose(); |
213 void DoSetVolume(double volume); | 220 void DoSetVolume(double volume); |
214 std::string DoGetOutputDeviceId() const; | 221 std::string DoGetOutputDeviceId() const; |
215 void DoSwitchOutputDevice(const std::string& output_device_id); | 222 void DoSwitchOutputDevice(const std::string& output_device_id); |
216 void DoReportError(); | 223 void DoReportError(); |
217 void DoStartDiverting(AudioOutputStream* to_stream); | 224 void DoStartDiverting(AudioOutputStream* to_stream); |
218 void DoStopDiverting(); | 225 void DoStopDiverting(); |
219 | 226 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // be accessed while |error_lock_| is held. | 274 // be accessed while |error_lock_| is held. |
268 bool ignore_errors_during_stop_close_; | 275 bool ignore_errors_during_stop_close_; |
269 base::Lock error_lock_; | 276 base::Lock error_lock_; |
270 | 277 |
271 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 278 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
272 }; | 279 }; |
273 | 280 |
274 } // namespace media | 281 } // namespace media |
275 | 282 |
276 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 283 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
OLD | NEW |