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( |
115 | 113 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
116 // Shuts down the audio thread and releases all the audio output dispatchers | 114 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
117 // on the audio thread. All audio streams should be freed before Shutdown() | 115 AudioLogFactory* audio_log_factory); |
118 // is called. This must be called in the destructor of every AudioManagerBase | |
119 // implementation. | |
120 void Shutdown(); | |
121 | 116 |
122 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } | 117 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } |
123 | 118 |
124 // Called by each platform specific AudioManager to notify output state change | 119 // 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 | 120 // listeners that a state change has occurred. Must be called from the audio |
126 // thread. | 121 // thread. |
127 void NotifyAllOutputDeviceChangeListeners(); | 122 void NotifyAllOutputDeviceChangeListeners(); |
128 | 123 |
129 // Returns user buffer size as specified on the command line or 0 if no buffer | 124 // Returns user buffer size as specified on the command line or 0 if no buffer |
130 // size has been specified. | 125 // size has been specified. |
(...skipping 13 matching lines...) Expand all Loading... |
144 // Returns the ID of the default audio output device. | 139 // Returns the ID of the default audio output device. |
145 // Implementations that don't yet support this should return an empty string. | 140 // Implementations that don't yet support this should return an empty string. |
146 virtual std::string GetDefaultOutputDeviceID(); | 141 virtual std::string GetDefaultOutputDeviceID(); |
147 | 142 |
148 private: | 143 private: |
149 struct DispatcherParams; | 144 struct DispatcherParams; |
150 typedef ScopedVector<DispatcherParams> AudioOutputDispatchers; | 145 typedef ScopedVector<DispatcherParams> AudioOutputDispatchers; |
151 | 146 |
152 class CompareByParams; | 147 class CompareByParams; |
153 | 148 |
154 // Called by Shutdown(). | |
155 void ShutdownOnAudioThread(); | |
156 | |
157 // Max number of open output streams, modified by | 149 // Max number of open output streams, modified by |
158 // SetMaxOutputStreamsAllowed(). | 150 // SetMaxOutputStreamsAllowed(). |
159 int max_num_output_streams_; | 151 int max_num_output_streams_; |
160 | 152 |
161 // Max number of open input streams. | 153 // Max number of open input streams. |
162 int max_num_input_streams_; | 154 int max_num_input_streams_; |
163 | 155 |
164 // Number of currently open output streams. | 156 // Number of currently open output streams. |
165 int num_output_streams_; | 157 int num_output_streams_; |
166 | 158 |
167 // Number of currently open input streams. | 159 // Number of currently open input streams. |
168 int num_input_streams_; | 160 int num_input_streams_; |
169 | 161 |
170 // Track output state change listeners. | 162 // Track output state change listeners. |
171 base::ObserverList<AudioDeviceListener> output_listeners_; | 163 base::ObserverList<AudioDeviceListener> output_listeners_; |
172 | 164 |
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 | 165 // Map of cached AudioOutputDispatcher instances. Must only be touched |
177 // from the audio thread (no locking). | 166 // from the audio thread (no locking). |
178 AudioOutputDispatchers output_dispatchers_; | 167 AudioOutputDispatchers output_dispatchers_; |
179 | 168 |
180 // Proxy for creating AudioLog objects. | 169 // Proxy for creating AudioLog objects. |
181 AudioLogFactory* const audio_log_factory_; | 170 AudioLogFactory* const audio_log_factory_; |
182 | 171 |
183 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 172 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
184 }; | 173 }; |
185 | 174 |
186 } // namespace media | 175 } // namespace media |
187 | 176 |
188 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 177 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
OLD | NEW |