| 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_MANAGER_BASE_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <unordered_set> | 10 #include <unordered_set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "media/audio/audio_device_name.h" |
| 19 #include "media/audio/audio_manager.h" | 20 #include "media/audio/audio_manager.h" |
| 20 #include "media/audio/audio_output_dispatcher.h" | 21 #include "media/audio/audio_output_dispatcher.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "base/win/scoped_com_initializer.h" | 24 #include "base/win/scoped_com_initializer.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace media { | 27 namespace media { |
| 27 | 28 |
| 28 class AudioOutputDispatcher; | 29 class AudioOutputDispatcher; |
| 29 | 30 |
| 30 // AudioManagerBase provides AudioManager functions common for all platforms. | 31 // AudioManagerBase provides AudioManager functions common for all platforms. |
| 31 class MEDIA_EXPORT AudioManagerBase : public AudioManager { | 32 class MEDIA_EXPORT AudioManagerBase : public AudioManager { |
| 32 public: | 33 public: |
| 33 ~AudioManagerBase() override; | 34 ~AudioManagerBase() override; |
| 34 | 35 |
| 35 // AudioManager: | 36 // AudioManager: |
| 36 base::string16 GetAudioInputDeviceModel() override; | 37 base::string16 GetAudioInputDeviceModel() override; |
| 37 void ShowAudioInputSettings() override; | 38 void ShowAudioInputSettings() override; |
| 38 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override; | 39 |
| 39 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override; | 40 void GetAudioInputDeviceDescriptions( |
| 41 AudioDeviceDescriptions* device_descriptions) final; |
| 42 void GetAudioOutputDeviceDescriptions( |
| 43 AudioDeviceDescriptions* device_descriptions) final; |
| 44 |
| 40 AudioOutputStream* MakeAudioOutputStream( | 45 AudioOutputStream* MakeAudioOutputStream( |
| 41 const AudioParameters& params, | 46 const AudioParameters& params, |
| 42 const std::string& device_id, | 47 const std::string& device_id, |
| 43 const LogCallback& log_callback) override; | 48 const LogCallback& log_callback) override; |
| 44 AudioInputStream* MakeAudioInputStream( | 49 AudioInputStream* MakeAudioInputStream( |
| 45 const AudioParameters& params, | 50 const AudioParameters& params, |
| 46 const std::string& device_id, | 51 const std::string& device_id, |
| 47 const LogCallback& log_callback) override; | 52 const LogCallback& log_callback) override; |
| 48 AudioOutputStream* MakeAudioOutputStreamProxy( | 53 AudioOutputStream* MakeAudioOutputStreamProxy( |
| 49 const AudioParameters& params, | 54 const AudioParameters& params, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 const AudioParameters& params, | 92 const AudioParameters& params, |
| 88 const std::string& device_id, | 93 const std::string& device_id, |
| 89 const LogCallback& log_callback) = 0; | 94 const LogCallback& log_callback) = 0; |
| 90 | 95 |
| 91 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. | 96 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. |
| 92 virtual AudioInputStream* MakeLowLatencyInputStream( | 97 virtual AudioInputStream* MakeLowLatencyInputStream( |
| 93 const AudioParameters& params, | 98 const AudioParameters& params, |
| 94 const std::string& device_id, | 99 const std::string& device_id, |
| 95 const LogCallback& log_callback) = 0; | 100 const LogCallback& log_callback) = 0; |
| 96 | 101 |
| 97 std::string GetGroupIDOutput(const std::string& output_device_id) override; | |
| 98 std::string GetGroupIDInput(const std::string& input_device_id) override; | |
| 99 | |
| 100 // Get number of input or output streams. | 102 // Get number of input or output streams. |
| 101 int input_stream_count() const { | 103 int input_stream_count() const { |
| 102 return static_cast<int>(input_streams_.size()); | 104 return static_cast<int>(input_streams_.size()); |
| 103 } | 105 } |
| 104 int output_stream_count() const { return num_output_streams_; } | 106 int output_stream_count() const { return num_output_streams_; } |
| 105 | 107 |
| 106 protected: | 108 protected: |
| 107 AudioManagerBase( | 109 AudioManagerBase( |
| 108 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 110 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 109 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 111 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 110 AudioLogFactory* audio_log_factory); | 112 AudioLogFactory* audio_log_factory); |
| 111 | 113 |
| 112 // Releases all the audio output dispatchers. | 114 // Releases all the audio output dispatchers. |
| 113 // All audio streams should be closed before Shutdown() is called. | 115 // All audio streams should be closed before Shutdown() is called. |
| 114 // This must be called in the destructor of every AudioManagerBase | 116 // This must be called in the destructor of every AudioManagerBase |
| 115 // implementation. | 117 // implementation. |
| 116 void Shutdown(); | 118 void Shutdown(); |
| 117 | 119 |
| 118 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } | 120 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } |
| 119 | 121 |
| 120 // Called by each platform specific AudioManager to notify output state change | 122 // Called by each platform specific AudioManager to notify output state change |
| 121 // listeners that a state change has occurred. Must be called from the audio | 123 // listeners that a state change has occurred. Must be called from the audio |
| 122 // thread. | 124 // thread. |
| 123 void NotifyAllOutputDeviceChangeListeners(); | 125 void NotifyAllOutputDeviceChangeListeners(); |
| 124 | 126 |
| 125 // Returns user buffer size as specified on the command line or 0 if no buffer | 127 // Returns user buffer size as specified on the command line or 0 if no buffer |
| 126 // size has been specified. | 128 // size has been specified. |
| 127 int GetUserBufferSize(); | 129 static int GetUserBufferSize(); |
| 128 | 130 |
| 129 // Returns the preferred hardware audio output parameters for opening output | 131 // Returns the preferred hardware audio output parameters for opening output |
| 130 // streams. If the users inject a valid |input_params|, each AudioManager | 132 // streams. If the users inject a valid |input_params|, each AudioManager |
| 131 // will decide if they should return the values from |input_params| or the | 133 // will decide if they should return the values from |input_params| or the |
| 132 // default hardware values. If the |input_params| is invalid, it will return | 134 // default hardware values. If the |input_params| is invalid, it will return |
| 133 // the default hardware audio parameters. | 135 // the default hardware audio parameters. |
| 134 // If |output_device_id| is empty, the implementation must treat that as | 136 // If |output_device_id| is empty, the implementation must treat that as |
| 135 // a request for the default output device. | 137 // a request for the default output device. |
| 136 virtual AudioParameters GetPreferredOutputStreamParameters( | 138 virtual AudioParameters GetPreferredOutputStreamParameters( |
| 137 const std::string& output_device_id, | 139 const std::string& output_device_id, |
| 138 const AudioParameters& input_params) = 0; | 140 const AudioParameters& input_params) = 0; |
| 139 | 141 |
| 142 // Appends a list of available input devices to |device_names|, |
| 143 // which must initially be empty. |
| 144 virtual void GetAudioInputDeviceNames(AudioDeviceNames* device_names); |
| 145 |
| 146 // Appends a list of available output devices to |device_names|, |
| 147 // which must initially be empty. |
| 148 virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names); |
| 149 |
| 140 // Returns the ID of the default audio output device. | 150 // Returns the ID of the default audio output device. |
| 141 // Implementations that don't yet support this should return an empty string. | 151 // Implementations that don't yet support this should return an empty string. |
| 142 virtual std::string GetDefaultOutputDeviceID(); | 152 virtual std::string GetDefaultOutputDeviceID(); |
| 143 | 153 |
| 144 private: | 154 private: |
| 145 struct DispatcherParams; | 155 struct DispatcherParams; |
| 146 typedef ScopedVector<DispatcherParams> AudioOutputDispatchers; | 156 typedef ScopedVector<DispatcherParams> AudioOutputDispatchers; |
| 147 | 157 |
| 148 class CompareByParams; | 158 class CompareByParams; |
| 149 | 159 |
| 160 // These functions assign group ids to devices based on their device ids. |
| 161 // The default implementation is an attempt to do this based on |
| 162 // GetAssociatedOutputDeviceID. Must be called on the audio worker thread |
| 163 // (see GetTaskRunner()). |
| 164 std::string GetGroupIDOutput(const std::string& output_device_id); |
| 165 std::string GetGroupIDInput(const std::string& input_device_id); |
| 166 |
| 150 // Max number of open output streams, modified by | 167 // Max number of open output streams, modified by |
| 151 // SetMaxOutputStreamsAllowed(). | 168 // SetMaxOutputStreamsAllowed(). |
| 152 int max_num_output_streams_; | 169 int max_num_output_streams_; |
| 153 | 170 |
| 154 // Max number of open input streams. | 171 // Max number of open input streams. |
| 155 int max_num_input_streams_; | 172 int max_num_input_streams_; |
| 156 | 173 |
| 157 // Number of currently open output streams. | 174 // Number of currently open output streams. |
| 158 int num_output_streams_; | 175 int num_output_streams_; |
| 159 | 176 |
| 160 // Track output state change listeners. | 177 // Track output state change listeners. |
| 161 base::ObserverList<AudioDeviceListener> output_listeners_; | 178 base::ObserverList<AudioDeviceListener> output_listeners_; |
| 162 | 179 |
| 163 // Contains currently open input streams. | 180 // Contains currently open input streams. |
| 164 std::unordered_set<AudioInputStream*> input_streams_; | 181 std::unordered_set<AudioInputStream*> input_streams_; |
| 165 | 182 |
| 166 // Map of cached AudioOutputDispatcher instances. Must only be touched | 183 // Map of cached AudioOutputDispatcher instances. Must only be touched |
| 167 // from the audio thread (no locking). | 184 // from the audio thread (no locking). |
| 168 AudioOutputDispatchers output_dispatchers_; | 185 AudioOutputDispatchers output_dispatchers_; |
| 169 | 186 |
| 170 // Proxy for creating AudioLog objects. | 187 // Proxy for creating AudioLog objects. |
| 171 AudioLogFactory* const audio_log_factory_; | 188 AudioLogFactory* const audio_log_factory_; |
| 172 | 189 |
| 173 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 190 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
| 174 }; | 191 }; |
| 175 | 192 |
| 176 } // namespace media | 193 } // namespace media |
| 177 | 194 |
| 178 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 195 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| OLD | NEW |