| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #endif // defined(DLOPEN_PULSEAUDIO) | 28 #endif // defined(DLOPEN_PULSEAUDIO) |
| 29 | 29 |
| 30 namespace media { | 30 namespace media { |
| 31 | 31 |
| 32 using pulse::AutoPulseLock; | 32 using pulse::AutoPulseLock; |
| 33 using pulse::WaitForOperationCompletion; | 33 using pulse::WaitForOperationCompletion; |
| 34 | 34 |
| 35 // Maximum number of output streams that can be open simultaneously. | 35 // Maximum number of output streams that can be open simultaneously. |
| 36 static const int kMaxOutputStreams = 50; | 36 static const int kMaxOutputStreams = 50; |
| 37 | 37 |
| 38 // Define bounds for the output buffer size. | 38 // Minimum bound for the output buffer size. |
| 39 static const int kMinimumOutputBufferSize = 512; | 39 static const int kMinimumOutputBufferSize = 512; |
| 40 static const int kMaximumOutputBufferSize = 8192; | 40 |
| 41 // Maximum bound for the input and output buffer size |
| 42 static const int kMaximumBufferSize = 8192; |
| 41 | 43 |
| 42 // Default input buffer size. | 44 // Default input buffer size. |
| 43 static const int kDefaultInputBufferSize = 1024; | 45 static const int kDefaultInputBufferSize = 1024; |
| 44 | 46 |
| 45 static const base::FilePath::CharType kPulseLib[] = | 47 static const base::FilePath::CharType kPulseLib[] = |
| 46 FILE_PATH_LITERAL("libpulse.so.0"); | 48 FILE_PATH_LITERAL("libpulse.so.0"); |
| 47 | 49 |
| 48 // static | 50 // static |
| 49 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) { | 51 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) { |
| 50 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory)); | 52 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory)); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 void AudioManagerPulse::GetAudioInputDeviceNames( | 121 void AudioManagerPulse::GetAudioInputDeviceNames( |
| 120 AudioDeviceNames* device_names) { | 122 AudioDeviceNames* device_names) { |
| 121 GetAudioDeviceNames(true, device_names); | 123 GetAudioDeviceNames(true, device_names); |
| 122 } | 124 } |
| 123 | 125 |
| 124 void AudioManagerPulse::GetAudioOutputDeviceNames( | 126 void AudioManagerPulse::GetAudioOutputDeviceNames( |
| 125 AudioDeviceNames* device_names) { | 127 AudioDeviceNames* device_names) { |
| 126 GetAudioDeviceNames(false, device_names); | 128 GetAudioDeviceNames(false, device_names); |
| 127 } | 129 } |
| 128 | 130 |
| 129 AudioParameters AudioManagerPulse::GetInputStreamParameters( | 131 AudioParameters AudioManagerPulse::GetPreferredInputStreamParameters( |
| 130 const std::string& device_id) { | 132 const std::string& input_device_id, |
| 133 const AudioParameters& input_params) { |
| 134 // TODO(xians): add support for querying native channel layout for pulse. |
| 135 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 136 int buffer_size = kDefaultInputBufferSize; |
| 137 int bits_per_sample = 16; |
| 138 int input_channels = 0; |
| 139 int sample_rate = GetNativeSampleRate(); |
| 140 if (input_params.IsValid()) { |
| 141 bits_per_sample = input_params.bits_per_sample(); |
| 142 channel_layout = input_params.channel_layout(); |
| 143 input_channels = input_params.input_channels(); |
| 144 buffer_size = std::min(kMaximumBufferSize, |
| 145 input_params.frames_per_buffer()); |
| 146 sample_rate = input_params.sample_rate(); |
| 147 } |
| 148 |
| 131 int user_buffer_size = GetUserBufferSize(); | 149 int user_buffer_size = GetUserBufferSize(); |
| 132 int buffer_size = user_buffer_size ? | 150 if (user_buffer_size) |
| 133 user_buffer_size : kDefaultInputBufferSize; | 151 buffer_size = user_buffer_size; |
| 134 | 152 |
| 135 // TODO(xians): add support for querying native channel layout for pulse. | |
| 136 return AudioParameters( | 153 return AudioParameters( |
| 137 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 154 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
| 138 GetNativeSampleRate(), 16, buffer_size); | 155 sample_rate, bits_per_sample, buffer_size, AudioParameters::NO_EFFECTS); |
| 139 } | 156 } |
| 140 | 157 |
| 141 AudioOutputStream* AudioManagerPulse::MakeLinearOutputStream( | 158 AudioOutputStream* AudioManagerPulse::MakeLinearOutputStream( |
| 142 const AudioParameters& params) { | 159 const AudioParameters& params) { |
| 143 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 160 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 144 return MakeOutputStream(params, AudioManagerBase::kDefaultDeviceId); | 161 return MakeOutputStream(params, AudioManagerBase::kDefaultDeviceId); |
| 145 } | 162 } |
| 146 | 163 |
| 147 AudioOutputStream* AudioManagerPulse::MakeLowLatencyOutputStream( | 164 AudioOutputStream* AudioManagerPulse::MakeLowLatencyOutputStream( |
| 148 const AudioParameters& params, | 165 const AudioParameters& params, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 168 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( | 185 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( |
| 169 const std::string& output_device_id, | 186 const std::string& output_device_id, |
| 170 const AudioParameters& input_params) { | 187 const AudioParameters& input_params) { |
| 171 // TODO(tommi): Support |output_device_id|. | 188 // TODO(tommi): Support |output_device_id|. |
| 172 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; | 189 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; |
| 173 | 190 |
| 174 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 191 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 175 int buffer_size = kMinimumOutputBufferSize; | 192 int buffer_size = kMinimumOutputBufferSize; |
| 176 int bits_per_sample = 16; | 193 int bits_per_sample = 16; |
| 177 int input_channels = 0; | 194 int input_channels = 0; |
| 178 int sample_rate; | 195 int sample_rate = 0; |
| 179 if (input_params.IsValid()) { | 196 if (input_params.IsValid()) { |
| 180 bits_per_sample = input_params.bits_per_sample(); | 197 bits_per_sample = input_params.bits_per_sample(); |
| 181 channel_layout = input_params.channel_layout(); | 198 channel_layout = input_params.channel_layout(); |
| 182 input_channels = input_params.input_channels(); | 199 input_channels = input_params.input_channels(); |
| 183 buffer_size = | 200 buffer_size = |
| 184 std::min(kMaximumOutputBufferSize, | 201 std::min(kMaximumBufferSize, |
| 185 std::max(buffer_size, input_params.frames_per_buffer())); | 202 std::max(buffer_size, input_params.frames_per_buffer())); |
| 186 sample_rate = input_params.sample_rate(); | 203 sample_rate = input_params.sample_rate(); |
| 187 } else { | 204 } else { |
| 188 sample_rate = GetNativeSampleRate(); | 205 sample_rate = GetNativeSampleRate(); |
| 189 } | 206 } |
| 190 | 207 |
| 191 int user_buffer_size = GetUserBufferSize(); | 208 int user_buffer_size = GetUserBufferSize(); |
| 192 if (user_buffer_size) | 209 if (user_buffer_size) |
| 193 buffer_size = user_buffer_size; | 210 buffer_size = user_buffer_size; |
| 194 | 211 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 353 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
| 337 const pa_server_info* info, | 354 const pa_server_info* info, |
| 338 void* user_data) { | 355 void* user_data) { |
| 339 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 356 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 340 | 357 |
| 341 manager->native_input_sample_rate_ = info->sample_spec.rate; | 358 manager->native_input_sample_rate_ = info->sample_spec.rate; |
| 342 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 359 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 343 } | 360 } |
| 344 | 361 |
| 345 } // namespace media | 362 } // namespace media |
| OLD | NEW |