| 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_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback_forward.h" | |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 14 #include "base/sequenced_task_runner_helpers.h" | 13 #include "base/sequenced_task_runner_helpers.h" |
| 15 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 16 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 17 #include "media/audio/audio_device_name.h" | 16 #include "media/audio/audio_device_name.h" |
| 18 #include "media/audio/audio_logging.h" | 17 #include "media/audio/audio_logging.h" |
| 19 #include "media/base/audio_parameters.h" | 18 #include "media/base/audio_parameters.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // Audio worker thread (see GetWorkerTaskRunner()). | 125 // Audio worker thread (see GetWorkerTaskRunner()). |
| 127 virtual void GetAudioInputDeviceNames(AudioDeviceNames* device_names) = 0; | 126 virtual void GetAudioInputDeviceNames(AudioDeviceNames* device_names) = 0; |
| 128 | 127 |
| 129 // Appends a list of available output devices to |device_names|, | 128 // Appends a list of available output devices to |device_names|, |
| 130 // which must initially be empty. | 129 // which must initially be empty. |
| 131 // | 130 // |
| 132 // Not threadsafe; in production this should only be called from the | 131 // Not threadsafe; in production this should only be called from the |
| 133 // Audio worker thread (see GetWorkerTaskRunner()). | 132 // Audio worker thread (see GetWorkerTaskRunner()). |
| 134 virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) = 0; | 133 virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) = 0; |
| 135 | 134 |
| 136 // Log callback used for sending log messages from a stream to the object | |
| 137 // that manages the stream. | |
| 138 using LogCallback = base::Callback<void(const std::string&)>; | |
| 139 | |
| 140 // Factory for all the supported stream formats. |params| defines parameters | 135 // Factory for all the supported stream formats. |params| defines parameters |
| 141 // of the audio stream to be created. | 136 // of the audio stream to be created. |
| 142 // | 137 // |
| 143 // |params.sample_per_packet| is the requested buffer allocation which the | 138 // |params.sample_per_packet| is the requested buffer allocation which the |
| 144 // audio source thinks it can usually fill without blocking. Internally two | 139 // audio source thinks it can usually fill without blocking. Internally two |
| 145 // or three buffers are created, one will be locked for playback and one will | 140 // or three buffers are created, one will be locked for playback and one will |
| 146 // be ready to be filled in the call to AudioSourceCallback::OnMoreData(). | 141 // be ready to be filled in the call to AudioSourceCallback::OnMoreData(). |
| 147 // | 142 // |
| 148 // To create a stream for the default output device, pass an empty string | 143 // To create a stream for the default output device, pass an empty string |
| 149 // for |device_id|, otherwise the specified audio device will be opened. | 144 // for |device_id|, otherwise the specified audio device will be opened. |
| 150 // | 145 // |
| 151 // Returns NULL if the combination of the parameters is not supported, or if | 146 // Returns NULL if the combination of the parameters is not supported, or if |
| 152 // we have reached some other platform specific limit. | 147 // we have reached some other platform specific limit. |
| 153 // | 148 // |
| 154 // |params.format| can be set to AUDIO_PCM_LOW_LATENCY and that has two | 149 // |params.format| can be set to AUDIO_PCM_LOW_LATENCY and that has two |
| 155 // effects: | 150 // effects: |
| 156 // 1- Instead of triple buffered the audio will be double buffered. | 151 // 1- Instead of triple buffered the audio will be double buffered. |
| 157 // 2- A low latency driver or alternative audio subsystem will be used when | 152 // 2- A low latency driver or alternative audio subsystem will be used when |
| 158 // available. | 153 // available. |
| 159 // | 154 // |
| 160 // Do not free the returned AudioOutputStream. It is owned by AudioManager. | 155 // Do not free the returned AudioOutputStream. It is owned by AudioManager. |
| 161 virtual AudioOutputStream* MakeAudioOutputStream( | 156 virtual AudioOutputStream* MakeAudioOutputStream( |
| 162 const AudioParameters& params, | 157 const AudioParameters& params, |
| 163 const std::string& device_id, | 158 const std::string& device_id) = 0; |
| 164 const LogCallback& log_callback) = 0; | |
| 165 | 159 |
| 166 // Creates new audio output proxy. A proxy implements | 160 // Creates new audio output proxy. A proxy implements |
| 167 // AudioOutputStream interface, but unlike regular output stream | 161 // AudioOutputStream interface, but unlike regular output stream |
| 168 // created with MakeAudioOutputStream() it opens device only when a | 162 // created with MakeAudioOutputStream() it opens device only when a |
| 169 // sound is actually playing. | 163 // sound is actually playing. |
| 170 virtual AudioOutputStream* MakeAudioOutputStreamProxy( | 164 virtual AudioOutputStream* MakeAudioOutputStreamProxy( |
| 171 const AudioParameters& params, | 165 const AudioParameters& params, |
| 172 const std::string& device_id) = 0; | 166 const std::string& device_id) = 0; |
| 173 | 167 |
| 174 // Factory to create audio recording streams. | 168 // Factory to create audio recording streams. |
| 175 // |channels| can be 1 or 2. | 169 // |channels| can be 1 or 2. |
| 176 // |sample_rate| is in hertz and can be any value supported by the platform. | 170 // |sample_rate| is in hertz and can be any value supported by the platform. |
| 177 // |bits_per_sample| can be any value supported by the platform. | 171 // |bits_per_sample| can be any value supported by the platform. |
| 178 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, | 172 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, |
| 179 // with 0 suggesting that the implementation use a default value for that | 173 // with 0 suggesting that the implementation use a default value for that |
| 180 // platform. | 174 // platform. |
| 181 // Returns NULL if the combination of the parameters is not supported, or if | 175 // Returns NULL if the combination of the parameters is not supported, or if |
| 182 // we have reached some other platform specific limit. | 176 // we have reached some other platform specific limit. |
| 183 // | 177 // |
| 184 // Do not free the returned AudioInputStream. It is owned by AudioManager. | 178 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
| 185 // When you are done with it, call |Stop()| and |Close()| to release it. | 179 // When you are done with it, call |Stop()| and |Close()| to release it. |
| 186 virtual AudioInputStream* MakeAudioInputStream( | 180 virtual AudioInputStream* MakeAudioInputStream( |
| 187 const AudioParameters& params, | 181 const AudioParameters& params, |
| 188 const std::string& device_id, | 182 const std::string& device_id) = 0; |
| 189 const LogCallback& log_callback) = 0; | |
| 190 | 183 |
| 191 // Returns the task runner used for audio IO. | 184 // Returns the task runner used for audio IO. |
| 192 // TODO(alokp): Rename to task_runner(). | 185 // TODO(alokp): Rename to task_runner(). |
| 193 base::SingleThreadTaskRunner* GetTaskRunner() const { | 186 base::SingleThreadTaskRunner* GetTaskRunner() const { |
| 194 return task_runner_.get(); | 187 return task_runner_.get(); |
| 195 } | 188 } |
| 196 | 189 |
| 197 // Heavyweight tasks should use GetWorkerTaskRunner() instead of | 190 // Heavyweight tasks should use GetWorkerTaskRunner() instead of |
| 198 // GetTaskRunner(). On most platforms they are the same, but some share the | 191 // GetTaskRunner(). On most platforms they are the same, but some share the |
| 199 // UI loop with the audio IO loop. | 192 // UI loop with the audio IO loop. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 friend class base::DeleteHelper<AudioManager>; | 248 friend class base::DeleteHelper<AudioManager>; |
| 256 | 249 |
| 257 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 250 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 258 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; | 251 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; |
| 259 DISALLOW_COPY_AND_ASSIGN(AudioManager); | 252 DISALLOW_COPY_AND_ASSIGN(AudioManager); |
| 260 }; | 253 }; |
| 261 | 254 |
| 262 } // namespace media | 255 } // namespace media |
| 263 | 256 |
| 264 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 257 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| OLD | NEW |