| 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 "content/common/media/audio_output.mojom.h" |
| 17 #include "media/audio/audio_io.h" | 18 #include "media/audio/audio_io.h" |
| 18 #include "media/audio/audio_manager.h" | 19 #include "media/audio/audio_manager.h" |
| 19 #include "media/audio/audio_power_monitor.h" | 20 #include "media/audio/audio_power_monitor.h" |
| 20 #include "media/audio/audio_source_diverter.h" | 21 #include "media/audio/audio_source_diverter.h" |
| 21 #include "media/audio/simple_sources.h" | 22 #include "media/audio/simple_sources.h" |
| 22 #include "media/base/media_export.h" | 23 #include "media/base/media_export.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, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() = 0; |
| 72 virtual void OnCreated( |
| 73 content::mojom::AudioOutputStreamPtr stream, |
| 74 const content::mojom::AudioOutput::CreateStreamCallback& callback) = 0; |
| 71 virtual void OnPlaying() = 0; | 75 virtual void OnPlaying() = 0; |
| 72 virtual void OnPaused() = 0; | 76 virtual void OnPaused() = 0; |
| 73 virtual void OnError() = 0; | 77 virtual void OnError() = 0; |
| 74 | 78 |
| 75 protected: | 79 protected: |
| 76 virtual ~EventHandler() {} | 80 virtual ~EventHandler() {} |
| 77 }; | 81 }; |
| 78 | 82 |
| 79 // A synchronous reader interface used by AudioOutputController for | 83 // A synchronous reader interface used by AudioOutputController for |
| 80 // synchronous reading. | 84 // synchronous reading. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 106 // thread, and if this is successful, the |event_handler| will receive an | 110 // thread, and if this is successful, the |event_handler| will receive an |
| 107 // OnCreated() call from the same audio manager thread. |audio_manager| must | 111 // OnCreated() call from the same audio manager thread. |audio_manager| must |
| 108 // outlive AudioOutputController. | 112 // outlive AudioOutputController. |
| 109 // The |output_device_id| can be either empty (default device) or specify a | 113 // The |output_device_id| can be either empty (default device) or specify a |
| 110 // specific hardware device for audio output. | 114 // specific hardware device for audio output. |
| 111 static scoped_refptr<AudioOutputController> Create( | 115 static scoped_refptr<AudioOutputController> Create( |
| 112 AudioManager* audio_manager, EventHandler* event_handler, | 116 AudioManager* audio_manager, EventHandler* event_handler, |
| 113 const AudioParameters& params, const std::string& output_device_id, | 117 const AudioParameters& params, const std::string& output_device_id, |
| 114 SyncReader* sync_reader); | 118 SyncReader* sync_reader); |
| 115 | 119 |
| 120 // Factory method for creating an AudioOutputController. |
| 121 // This also creates and opens an AudioOutputStream on the audio manager |
| 122 // thread, and if this is successful, the |event_handler| will receive an |
| 123 // OnCreated() call from the same audio manager thread. |audio_manager| must |
| 124 // outlive AudioOutputController. |
| 125 // The |output_device_id| can be either empty (default device) or specify a |
| 126 // specific hardware device for audio output. |
| 127 static scoped_refptr<AudioOutputController> Create( |
| 128 AudioManager* audio_manager, |
| 129 EventHandler* event_handler, |
| 130 const AudioParameters& params, |
| 131 const std::string& output_device_id, |
| 132 SyncReader* sync_reader, |
| 133 content::mojom::AudioOutputStreamPtr stream, |
| 134 const content::mojom::AudioOutput::CreateStreamCallback& callback); |
| 135 |
| 116 // Indicates whether audio power level analysis will be performed. If false, | 136 // Indicates whether audio power level analysis will be performed. If false, |
| 117 // ReadCurrentPowerAndClip() can not be called. | 137 // ReadCurrentPowerAndClip() can not be called. |
| 118 static bool will_monitor_audio_levels() { | 138 static bool will_monitor_audio_levels() { |
| 119 #if defined(OS_ANDROID) || defined(OS_IOS) | 139 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 120 return false; | 140 return false; |
| 121 #else | 141 #else |
| 122 return true; | 142 return true; |
| 123 #endif | 143 #endif |
| 124 } | 144 } |
| 125 | 145 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 ~AudioOutputController() override; | 220 ~AudioOutputController() override; |
| 201 | 221 |
| 202 private: | 222 private: |
| 203 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, | 223 AudioOutputController(AudioManager* audio_manager, EventHandler* handler, |
| 204 const AudioParameters& params, | 224 const AudioParameters& params, |
| 205 const std::string& output_device_id, | 225 const std::string& output_device_id, |
| 206 SyncReader* sync_reader); | 226 SyncReader* sync_reader); |
| 207 | 227 |
| 208 // The following methods are executed on the audio manager thread. | 228 // The following methods are executed on the audio manager thread. |
| 209 void DoCreate(bool is_for_device_change); | 229 void DoCreate(bool is_for_device_change); |
| 230 // The following methods are executed on the audio manager thread. |
| 231 void DoCreateMojo( |
| 232 bool is_for_device_change, |
| 233 const content::mojom::AudioOutput::CreateStreamCallback& callback); |
| 210 void DoPlay(); | 234 void DoPlay(); |
| 211 void DoPause(); | 235 void DoPause(); |
| 212 void DoClose(); | 236 void DoClose(); |
| 213 void DoSetVolume(double volume); | 237 void DoSetVolume(double volume); |
| 214 std::string DoGetOutputDeviceId() const; | 238 std::string DoGetOutputDeviceId() const; |
| 215 void DoSwitchOutputDevice(const std::string& output_device_id); | 239 void DoSwitchOutputDevice(const std::string& output_device_id); |
| 216 void DoReportError(); | 240 void DoReportError(); |
| 217 void DoStartDiverting(AudioOutputStream* to_stream); | 241 void DoStartDiverting(AudioOutputStream* to_stream); |
| 218 void DoStopDiverting(); | 242 void DoStopDiverting(); |
| 219 | 243 |
| 220 // Helper method that stops the physical stream. | 244 // Helper method that stops the physical stream. |
| 221 void StopStream(); | 245 void StopStream(); |
| 222 | 246 |
| 223 // Helper method that stops, closes, and NULLs |*stream_|. | 247 // Helper method that stops, closes, and NULLs |*stream_|. |
| 224 void DoStopCloseAndClearStream(); | 248 void DoStopCloseAndClearStream(); |
| 225 | 249 |
| 226 // Checks if a stream was started successfully but never calls OnMoreData(). | 250 // Checks if a stream was started successfully but never calls OnMoreData(). |
| 227 void WedgeCheck(); | 251 void WedgeCheck(); |
| 228 | 252 |
| 229 AudioManager* const audio_manager_; | 253 AudioManager* const audio_manager_; |
| 230 const AudioParameters params_; | 254 const AudioParameters params_; |
| 231 EventHandler* const handler_; | 255 EventHandler* const handler_; |
| 232 | 256 |
| 233 // Specifies the device id of the output device to open or empty for the | 257 // Specifies the device id of the output device to open or empty for the |
| 234 // default output device. | 258 // default output device. |
| 235 std::string output_device_id_; | 259 std::string output_device_id_; |
| 236 | 260 |
| 237 AudioOutputStream* stream_; | 261 AudioOutputStream* stream_; |
| 238 | 262 |
| 263 content::mojom::AudioOutputStreamPtr stream_ptr_; |
| 264 |
| 239 // When non-NULL, audio is being diverted to this stream. | 265 // When non-NULL, audio is being diverted to this stream. |
| 240 AudioOutputStream* diverting_to_stream_; | 266 AudioOutputStream* diverting_to_stream_; |
| 241 | 267 |
| 242 // The current volume of the audio stream. | 268 // The current volume of the audio stream. |
| 243 double volume_; | 269 double volume_; |
| 244 | 270 |
| 245 // |state_| may only be used on the audio manager thread. | 271 // |state_| may only be used on the audio manager thread. |
| 246 State state_; | 272 State state_; |
| 247 | 273 |
| 248 // SyncReader is used only in low latency mode for synchronous reading. | 274 // SyncReader is used only in low latency mode for synchronous reading. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 267 // be accessed while |error_lock_| is held. | 293 // be accessed while |error_lock_| is held. |
| 268 bool ignore_errors_during_stop_close_; | 294 bool ignore_errors_during_stop_close_; |
| 269 base::Lock error_lock_; | 295 base::Lock error_lock_; |
| 270 | 296 |
| 271 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); | 297 DISALLOW_COPY_AND_ASSIGN(AudioOutputController); |
| 272 }; | 298 }; |
| 273 | 299 |
| 274 } // namespace media | 300 } // namespace media |
| 275 | 301 |
| 276 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ | 302 #endif // MEDIA_AUDIO_AUDIO_OUTPUT_CONTROLLER_H_ |
| OLD | NEW |