| 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 #include "media/audio/audio_manager_base.h" | 5 #include "media/audio/audio_manager_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "media/audio/audio_device_description.h" |
| 15 #include "media/audio/audio_output_dispatcher_impl.h" | 16 #include "media/audio/audio_output_dispatcher_impl.h" |
| 16 #include "media/audio/audio_output_proxy.h" | 17 #include "media/audio/audio_output_proxy.h" |
| 17 #include "media/audio/audio_output_resampler.h" | 18 #include "media/audio/audio_output_resampler.h" |
| 18 #include "media/audio/fake_audio_input_stream.h" | 19 #include "media/audio/fake_audio_input_stream.h" |
| 19 #include "media/audio/fake_audio_output_stream.h" | 20 #include "media/audio/fake_audio_output_stream.h" |
| 20 #include "media/base/media_switches.h" | 21 #include "media/base/media_switches.h" |
| 21 | 22 |
| 22 namespace media { | 23 namespace media { |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const int kStreamCloseDelaySeconds = 5; | 26 const int kStreamCloseDelaySeconds = 5; |
| 26 | 27 |
| 27 // Default maximum number of output streams that can be open simultaneously | 28 // Default maximum number of output streams that can be open simultaneously |
| 28 // for all platforms. | 29 // for all platforms. |
| 29 const int kDefaultMaxOutputStreams = 16; | 30 const int kDefaultMaxOutputStreams = 16; |
| 30 | 31 |
| 31 // Default maximum number of input streams that can be open simultaneously | 32 // Default maximum number of input streams that can be open simultaneously |
| 32 // for all platforms. | 33 // for all platforms. |
| 33 const int kDefaultMaxInputStreams = 16; | 34 const int kDefaultMaxInputStreams = 16; |
| 34 | 35 |
| 35 const int kMaxInputChannels = 3; | 36 const int kMaxInputChannels = 3; |
| 36 | 37 |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 const char AudioManagerBase::kDefaultDeviceId[] = "default"; | |
| 40 const char AudioManagerBase::kCommunicationsDeviceId[] = "communications"; | |
| 41 const char AudioManagerBase::kLoopbackInputDeviceId[] = "loopback"; | |
| 42 | |
| 43 struct AudioManagerBase::DispatcherParams { | 40 struct AudioManagerBase::DispatcherParams { |
| 44 DispatcherParams(const AudioParameters& input, | 41 DispatcherParams(const AudioParameters& input, |
| 45 const AudioParameters& output, | 42 const AudioParameters& output, |
| 46 const std::string& output_device_id) | 43 const std::string& output_device_id) |
| 47 : input_params(input), | 44 : input_params(input), |
| 48 output_params(output), | 45 output_params(output), |
| 49 output_device_id(output_device_id) {} | 46 output_device_id(output_device_id) {} |
| 50 ~DispatcherParams() {} | 47 ~DispatcherParams() {} |
| 51 | 48 |
| 52 const AudioParameters input_params; | 49 const AudioParameters input_params; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 70 // dispatcher are the same as the request dispatcher. | 67 // dispatcher are the same as the request dispatcher. |
| 71 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && | 68 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && |
| 72 dispatcher_->output_params.Equals(dispatcher_in->output_params) && | 69 dispatcher_->output_params.Equals(dispatcher_in->output_params) && |
| 73 dispatcher_->output_device_id == dispatcher_in->output_device_id); | 70 dispatcher_->output_device_id == dispatcher_in->output_device_id); |
| 74 } | 71 } |
| 75 | 72 |
| 76 private: | 73 private: |
| 77 const DispatcherParams* dispatcher_; | 74 const DispatcherParams* dispatcher_; |
| 78 }; | 75 }; |
| 79 | 76 |
| 80 // static | |
| 81 bool AudioManagerBase::IsDefaultDeviceId(const std::string& device_id) { | |
| 82 return device_id.empty() || device_id == AudioManagerBase::kDefaultDeviceId; | |
| 83 } | |
| 84 | |
| 85 // static | |
| 86 bool AudioManagerBase::UseSessionIdToSelectDevice( | |
| 87 int session_id, | |
| 88 const std::string& device_id) { | |
| 89 return session_id && device_id.empty(); | |
| 90 } | |
| 91 | |
| 92 AudioManagerBase::AudioManagerBase( | 77 AudioManagerBase::AudioManagerBase( |
| 93 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 78 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 94 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 79 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 95 AudioLogFactory* audio_log_factory) | 80 AudioLogFactory* audio_log_factory) |
| 96 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), | 81 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), |
| 97 max_num_output_streams_(kDefaultMaxOutputStreams), | 82 max_num_output_streams_(kDefaultMaxOutputStreams), |
| 98 max_num_input_streams_(kDefaultMaxInputStreams), | 83 max_num_input_streams_(kDefaultMaxInputStreams), |
| 99 num_output_streams_(0), | 84 num_output_streams_(0), |
| 100 num_input_streams_(0), | 85 num_input_streams_(0), |
| 101 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we | 86 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 DLOG(ERROR) << "Number of opened output audio streams " | 123 DLOG(ERROR) << "Number of opened output audio streams " |
| 139 << num_output_streams_ | 124 << num_output_streams_ |
| 140 << " exceed the max allowed number " | 125 << " exceed the max allowed number " |
| 141 << max_num_output_streams_; | 126 << max_num_output_streams_; |
| 142 return NULL; | 127 return NULL; |
| 143 } | 128 } |
| 144 | 129 |
| 145 AudioOutputStream* stream; | 130 AudioOutputStream* stream; |
| 146 switch (params.format()) { | 131 switch (params.format()) { |
| 147 case AudioParameters::AUDIO_PCM_LINEAR: | 132 case AudioParameters::AUDIO_PCM_LINEAR: |
| 148 DCHECK(IsDefaultDeviceId(device_id)) | 133 DCHECK(AudioDeviceDescription::IsDefaultDevice(device_id)) |
| 149 << "AUDIO_PCM_LINEAR supports only the default device."; | 134 << "AUDIO_PCM_LINEAR supports only the default device."; |
| 150 stream = MakeLinearOutputStream(params); | 135 stream = MakeLinearOutputStream(params); |
| 151 break; | 136 break; |
| 152 case AudioParameters::AUDIO_PCM_LOW_LATENCY: | 137 case AudioParameters::AUDIO_PCM_LOW_LATENCY: |
| 153 stream = MakeLowLatencyOutputStream(params, device_id); | 138 stream = MakeLowLatencyOutputStream(params, device_id); |
| 154 break; | 139 break; |
| 155 case AudioParameters::AUDIO_FAKE: | 140 case AudioParameters::AUDIO_FAKE: |
| 156 stream = FakeAudioOutputStream::MakeFakeStream(this, params); | 141 stream = FakeAudioOutputStream::MakeFakeStream(this, params); |
| 157 break; | 142 break; |
| 158 default: | 143 default: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 const std::string& device_id) { | 203 const std::string& device_id) { |
| 219 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 204 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 220 | 205 |
| 221 // If the caller supplied an empty device id to select the default device, | 206 // If the caller supplied an empty device id to select the default device, |
| 222 // we fetch the actual device id of the default device so that the lookup | 207 // we fetch the actual device id of the default device so that the lookup |
| 223 // will find the correct device regardless of whether it was opened as | 208 // will find the correct device regardless of whether it was opened as |
| 224 // "default" or via the specific id. | 209 // "default" or via the specific id. |
| 225 // NOTE: Implementations that don't yet support opening non-default output | 210 // NOTE: Implementations that don't yet support opening non-default output |
| 226 // devices may return an empty string from GetDefaultOutputDeviceID(). | 211 // devices may return an empty string from GetDefaultOutputDeviceID(). |
| 227 std::string output_device_id = | 212 std::string output_device_id = |
| 228 IsDefaultDeviceId(device_id) ? GetDefaultOutputDeviceID() : device_id; | 213 AudioDeviceDescription::IsDefaultDevice(device_id) |
| 214 ? GetDefaultOutputDeviceID() |
| 215 : device_id; |
| 229 | 216 |
| 230 // If we're not using AudioOutputResampler our output parameters are the same | 217 // If we're not using AudioOutputResampler our output parameters are the same |
| 231 // as our input parameters. | 218 // as our input parameters. |
| 232 AudioParameters output_params = params; | 219 AudioParameters output_params = params; |
| 233 if (params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { | 220 if (params.format() == AudioParameters::AUDIO_PCM_LOW_LATENCY) { |
| 234 output_params = | 221 output_params = |
| 235 GetPreferredOutputStreamParameters(output_device_id, params); | 222 GetPreferredOutputStreamParameters(output_device_id, params); |
| 236 | 223 |
| 237 // Ensure we only pass on valid output parameters. | 224 // Ensure we only pass on valid output parameters. |
| 238 if (!output_params.IsValid()) { | 225 if (!output_params.IsValid()) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 361 |
| 375 return 0; | 362 return 0; |
| 376 } | 363 } |
| 377 | 364 |
| 378 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( | 365 std::unique_ptr<AudioLog> AudioManagerBase::CreateAudioLog( |
| 379 AudioLogFactory::AudioComponent component) { | 366 AudioLogFactory::AudioComponent component) { |
| 380 return audio_log_factory_->CreateAudioLog(component); | 367 return audio_log_factory_->CreateAudioLog(component); |
| 381 } | 368 } |
| 382 | 369 |
| 383 } // namespace media | 370 } // namespace media |
| OLD | NEW |