| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pulse/audio_manager_pulse.h" | 5 #include "media/audio/pulse/audio_manager_pulse.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #if defined(USE_ALSA) | 12 #if defined(USE_ALSA) |
| 13 #include "media/audio/alsa/audio_manager_alsa.h" | 13 #include "media/audio/alsa/audio_manager_alsa.h" |
| 14 #endif | 14 #endif |
| 15 #include "media/audio/audio_device_description.h" | 15 #include "media/audio/audio_device_description.h" |
| 16 #include "media/audio/pulse/pulse_input.h" | 16 #include "media/audio/pulse/pulse_input.h" |
| 17 #include "media/audio/pulse/pulse_output.h" | 17 #include "media/audio/pulse/pulse_output.h" |
| 18 #include "media/audio/pulse/pulse_util.h" | 18 #include "media/audio/pulse/pulse_util.h" |
| 19 #include "media/base/audio_parameters.h" | 19 #include "media/base/audio_parameters.h" |
| 20 #include "media/base/channel_layout.h" | 20 #include "media/base/channel_layout.h" |
| 21 #include "media/base/limits.h" |
| 21 | 22 |
| 22 namespace media { | 23 namespace media { |
| 23 | 24 |
| 24 using pulse::AutoPulseLock; | 25 using pulse::AutoPulseLock; |
| 25 using pulse::WaitForOperationCompletion; | 26 using pulse::WaitForOperationCompletion; |
| 26 | 27 |
| 27 // Maximum number of output streams that can be open simultaneously. | 28 // Maximum number of output streams that can be open simultaneously. |
| 28 static const int kMaxOutputStreams = 50; | 29 static const int kMaxOutputStreams = 50; |
| 29 | 30 |
| 30 // Define bounds for the output buffer size. | |
| 31 static const int kMinimumOutputBufferSize = 512; | |
| 32 static const int kMaximumOutputBufferSize = 8192; | |
| 33 | |
| 34 // Default input buffer size. | 31 // Default input buffer size. |
| 35 static const int kDefaultInputBufferSize = 1024; | 32 static const int kDefaultInputBufferSize = 1024; |
| 36 | 33 |
| 37 AudioManagerPulse::AudioManagerPulse(std::unique_ptr<AudioThread> audio_thread, | 34 AudioManagerPulse::AudioManagerPulse(std::unique_ptr<AudioThread> audio_thread, |
| 38 AudioLogFactory* audio_log_factory, | 35 AudioLogFactory* audio_log_factory, |
| 39 pa_threaded_mainloop* pa_mainloop, | 36 pa_threaded_mainloop* pa_mainloop, |
| 40 pa_context* pa_context) | 37 pa_context* pa_context) |
| 41 : AudioManagerBase(std::move(audio_thread), audio_log_factory), | 38 : AudioManagerBase(std::move(audio_thread), audio_log_factory), |
| 42 input_mainloop_(pa_mainloop), | 39 input_mainloop_(pa_mainloop), |
| 43 input_context_(pa_context), | 40 input_context_(pa_context), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 154 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 158 return MakeInputStream(params, device_id); | 155 return MakeInputStream(params, device_id); |
| 159 } | 156 } |
| 160 | 157 |
| 161 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( | 158 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( |
| 162 const std::string& output_device_id, | 159 const std::string& output_device_id, |
| 163 const AudioParameters& input_params) { | 160 const AudioParameters& input_params) { |
| 164 // TODO(tommi): Support |output_device_id|. | 161 // TODO(tommi): Support |output_device_id|. |
| 165 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; | 162 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; |
| 166 | 163 |
| 167 int buffer_size = kMinimumOutputBufferSize; | 164 int buffer_size = limits::kMinAudioBufferSize; |
| 168 int bits_per_sample = 16; | 165 int bits_per_sample = 16; |
| 169 | 166 |
| 170 // Query native parameters where applicable; Pulse does not require these to | 167 // Query native parameters where applicable; Pulse does not require these to |
| 171 // be respected though, so prefer the input parameters for channel count. | 168 // be respected though, so prefer the input parameters for channel count. |
| 172 UpdateNativeAudioHardwareInfo(); | 169 UpdateNativeAudioHardwareInfo(); |
| 173 int sample_rate = native_input_sample_rate_; | 170 int sample_rate = native_input_sample_rate_; |
| 174 ChannelLayout channel_layout = GuessChannelLayout(native_channel_count_); | 171 ChannelLayout channel_layout = GuessChannelLayout(native_channel_count_); |
| 175 | 172 |
| 176 if (input_params.IsValid()) { | 173 if (input_params.IsValid()) { |
| 177 bits_per_sample = input_params.bits_per_sample(); | 174 bits_per_sample = input_params.bits_per_sample(); |
| 178 channel_layout = input_params.channel_layout(); | 175 channel_layout = input_params.channel_layout(); |
| 179 buffer_size = | 176 buffer_size = |
| 180 std::min(kMaximumOutputBufferSize, | 177 std::min(static_cast<int>(limits::kMaxAudioBufferSize), |
| 181 std::max(buffer_size, input_params.frames_per_buffer())); | 178 std::max(buffer_size, input_params.frames_per_buffer())); |
| 182 } | 179 } |
| 183 | 180 |
| 184 int user_buffer_size = GetUserBufferSize(); | 181 int user_buffer_size = GetUserBufferSize(); |
| 185 if (user_buffer_size) | 182 if (user_buffer_size) |
| 186 buffer_size = user_buffer_size; | 183 buffer_size = user_buffer_size; |
| 187 | 184 |
| 188 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 185 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 189 sample_rate, bits_per_sample, buffer_size); | 186 sample_rate, bits_per_sample, buffer_size); |
| 190 } | 187 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 const pa_server_info* info, | 245 const pa_server_info* info, |
| 249 void* user_data) { | 246 void* user_data) { |
| 250 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 247 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 251 | 248 |
| 252 manager->native_input_sample_rate_ = info->sample_spec.rate; | 249 manager->native_input_sample_rate_ = info->sample_spec.rate; |
| 253 manager->native_channel_count_ = info->sample_spec.channels; | 250 manager->native_channel_count_ = info->sample_spec.channels; |
| 254 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 251 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 255 } | 252 } |
| 256 | 253 |
| 257 } // namespace media | 254 } // namespace media |
| OLD | NEW |