| 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 <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // default playback device. At the moment this feature is supported only on | 45 // default playback device. At the moment this feature is supported only on |
| 46 // some platforms. AudioInputStream::Intialize() will return an error on | 46 // some platforms. AudioInputStream::Intialize() will return an error on |
| 47 // platforms that don't support it. GetInputStreamParameters() must be used | 47 // platforms that don't support it. GetInputStreamParameters() must be used |
| 48 // to get the parameters of the loopback device before creating a loopback | 48 // to get the parameters of the loopback device before creating a loopback |
| 49 // stream, otherwise stream initialization may fail. | 49 // stream, otherwise stream initialization may fail. |
| 50 static const char kLoopbackInputDeviceId[]; | 50 static const char kLoopbackInputDeviceId[]; |
| 51 | 51 |
| 52 ~AudioManagerBase() override; | 52 ~AudioManagerBase() override; |
| 53 | 53 |
| 54 // AudioManager: | 54 // AudioManager: |
| 55 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() override; | |
| 56 scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() override; | |
| 57 base::string16 GetAudioInputDeviceModel() override; | 55 base::string16 GetAudioInputDeviceModel() override; |
| 58 void ShowAudioInputSettings() override; | 56 void ShowAudioInputSettings() override; |
| 59 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override; | 57 void GetAudioInputDeviceNames(AudioDeviceNames* device_names) override; |
| 60 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override; | 58 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override; |
| 61 AudioOutputStream* MakeAudioOutputStream( | 59 AudioOutputStream* MakeAudioOutputStream( |
| 62 const AudioParameters& params, | 60 const AudioParameters& params, |
| 63 const std::string& device_id) override; | 61 const std::string& device_id) override; |
| 64 AudioInputStream* MakeAudioInputStream(const AudioParameters& params, | 62 AudioInputStream* MakeAudioInputStream(const AudioParameters& params, |
| 65 const std::string& device_id) override; | 63 const std::string& device_id) override; |
| 66 AudioOutputStream* MakeAudioOutputStreamProxy( | 64 AudioOutputStream* MakeAudioOutputStreamProxy( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 102 |
| 105 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. | 103 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. |
| 106 virtual AudioInputStream* MakeLowLatencyInputStream( | 104 virtual AudioInputStream* MakeLowLatencyInputStream( |
| 107 const AudioParameters& params, const std::string& device_id) = 0; | 105 const AudioParameters& params, const std::string& device_id) = 0; |
| 108 | 106 |
| 109 // Get number of input or output streams. | 107 // Get number of input or output streams. |
| 110 int input_stream_count() const { return num_input_streams_; } | 108 int input_stream_count() const { return num_input_streams_; } |
| 111 int output_stream_count() const { return num_output_streams_; } | 109 int output_stream_count() const { return num_output_streams_; } |
| 112 | 110 |
| 113 protected: | 111 protected: |
| 114 AudioManagerBase(AudioLogFactory* audio_log_factory); | 112 AudioManagerBase( |
| 113 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 114 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 115 AudioLogFactory* audio_log_factory); |
| 115 | 116 |
| 116 // Shuts down the audio thread and releases all the audio output dispatchers | 117 // Releases all the audio output dispatchers. |
| 117 // on the audio thread. All audio streams should be freed before Shutdown() | 118 // All audio streams should be freed before Shutdown() is called. |
| 118 // is called. This must be called in the destructor of every AudioManagerBase | 119 // Must be called in the destructor of every AudioManagerBase implementation. |
| 119 // implementation. | |
| 120 void Shutdown(); | 120 void Shutdown(); |
| 121 | 121 |
| 122 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } | 122 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } |
| 123 | 123 |
| 124 // Called by each platform specific AudioManager to notify output state change | 124 // Called by each platform specific AudioManager to notify output state change |
| 125 // listeners that a state change has occurred. Must be called from the audio | 125 // listeners that a state change has occurred. Must be called from the audio |
| 126 // thread. | 126 // thread. |
| 127 void NotifyAllOutputDeviceChangeListeners(); | 127 void NotifyAllOutputDeviceChangeListeners(); |
| 128 | 128 |
| 129 // Returns user buffer size as specified on the command line or 0 if no buffer | 129 // Returns user buffer size as specified on the command line or 0 if no buffer |
| (...skipping 14 matching lines...) Expand all Loading... |
| 144 // Returns the ID of the default audio output device. | 144 // Returns the ID of the default audio output device. |
| 145 // Implementations that don't yet support this should return an empty string. | 145 // Implementations that don't yet support this should return an empty string. |
| 146 virtual std::string GetDefaultOutputDeviceID(); | 146 virtual std::string GetDefaultOutputDeviceID(); |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 struct DispatcherParams; | 149 struct DispatcherParams; |
| 150 typedef ScopedVector<DispatcherParams> AudioOutputDispatchers; | 150 typedef ScopedVector<DispatcherParams> AudioOutputDispatchers; |
| 151 | 151 |
| 152 class CompareByParams; | 152 class CompareByParams; |
| 153 | 153 |
| 154 // Called by Shutdown(). | |
| 155 void ShutdownOnAudioThread(); | |
| 156 | |
| 157 // Max number of open output streams, modified by | 154 // Max number of open output streams, modified by |
| 158 // SetMaxOutputStreamsAllowed(). | 155 // SetMaxOutputStreamsAllowed(). |
| 159 int max_num_output_streams_; | 156 int max_num_output_streams_; |
| 160 | 157 |
| 161 // Max number of open input streams. | 158 // Max number of open input streams. |
| 162 int max_num_input_streams_; | 159 int max_num_input_streams_; |
| 163 | 160 |
| 164 // Number of currently open output streams. | 161 // Number of currently open output streams. |
| 165 int num_output_streams_; | 162 int num_output_streams_; |
| 166 | 163 |
| 167 // Number of currently open input streams. | 164 // Number of currently open input streams. |
| 168 int num_input_streams_; | 165 int num_input_streams_; |
| 169 | 166 |
| 170 // Track output state change listeners. | 167 // Track output state change listeners. |
| 171 base::ObserverList<AudioDeviceListener> output_listeners_; | 168 base::ObserverList<AudioDeviceListener> output_listeners_; |
| 172 | 169 |
| 173 // Thread used to interact with audio streams created by this audio manager. | |
| 174 scoped_ptr<base::Thread> audio_thread_; | |
| 175 | |
| 176 // Map of cached AudioOutputDispatcher instances. Must only be touched | 170 // Map of cached AudioOutputDispatcher instances. Must only be touched |
| 177 // from the audio thread (no locking). | 171 // from the audio thread (no locking). |
| 178 AudioOutputDispatchers output_dispatchers_; | 172 AudioOutputDispatchers output_dispatchers_; |
| 179 | 173 |
| 180 // Proxy for creating AudioLog objects. | 174 // Proxy for creating AudioLog objects. |
| 181 AudioLogFactory* const audio_log_factory_; | 175 AudioLogFactory* const audio_log_factory_; |
| 182 | 176 |
| 183 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 177 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
| 184 }; | 178 }; |
| 185 | 179 |
| 186 } // namespace media | 180 } // namespace media |
| 187 | 181 |
| 188 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 182 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| OLD | NEW |