| 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" |
| 11 #include "base/nix/xdg_util.h" | 11 #include "base/nix/xdg_util.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "media/audio/audio_util.h" | 14 #include "media/audio/audio_parameters.h" |
| 15 #include "media/audio/linux/audio_manager_linux.h" | 15 #include "media/audio/linux/audio_manager_linux.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_stubs.h" | 18 #include "media/audio/pulse/pulse_stubs.h" |
| 19 #include "media/audio/pulse/pulse_util.h" | 19 #include "media/audio/pulse/pulse_util.h" |
| 20 #include "media/base/channel_layout.h" |
| 20 | 21 |
| 21 using media_audio_pulse::kModulePulse; | 22 using media_audio_pulse::kModulePulse; |
| 22 using media_audio_pulse::InitializeStubs; | 23 using media_audio_pulse::InitializeStubs; |
| 23 using media_audio_pulse::StubPathMap; | 24 using media_audio_pulse::StubPathMap; |
| 24 | 25 |
| 25 namespace media { | 26 namespace media { |
| 26 | 27 |
| 27 using pulse::AutoPulseLock; | 28 using pulse::AutoPulseLock; |
| 28 using pulse::WaitForOperationCompletion; | 29 using pulse::WaitForOperationCompletion; |
| 29 | 30 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 WaitForOperationCompletion(input_mainloop_, operation); | 84 WaitForOperationCompletion(input_mainloop_, operation); |
| 84 | 85 |
| 85 // Append the default device on the top of the list if the list is not empty. | 86 // Append the default device on the top of the list if the list is not empty. |
| 86 if (!device_names->empty()) { | 87 if (!device_names->empty()) { |
| 87 device_names->push_front( | 88 device_names->push_front( |
| 88 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, | 89 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, |
| 89 AudioManagerBase::kDefaultDeviceId)); | 90 AudioManagerBase::kDefaultDeviceId)); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 94 AudioParameters AudioManagerPulse::GetDefaultOutputStreamParameters() { |
| 95 static const int kDefaultOutputBufferSize = 512; |
| 96 |
| 97 return AudioParameters( |
| 98 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 99 GetNativeSampleRate(), kDefaultBitsPerSample, kDefaultOutputBufferSize); |
| 100 } |
| 101 |
| 102 AudioParameters AudioManagerPulse::GetDefaultInputStreamParameters( |
| 103 const std::string& device_id) { |
| 104 static const int kDefaultInputBufferSize = 1024; |
| 105 |
| 106 // TODO(xians): add support for querying native channel layout for pulse. |
| 107 return AudioParameters( |
| 108 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 109 GetNativeSampleRate(), kDefaultBitsPerSample, kDefaultInputBufferSize); |
| 110 } |
| 111 |
| 93 AudioOutputStream* AudioManagerPulse::MakeLinearOutputStream( | 112 AudioOutputStream* AudioManagerPulse::MakeLinearOutputStream( |
| 94 const AudioParameters& params) { | 113 const AudioParameters& params) { |
| 95 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 114 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 96 return MakeOutputStream(params); | 115 return MakeOutputStream(params); |
| 97 } | 116 } |
| 98 | 117 |
| 99 AudioOutputStream* AudioManagerPulse::MakeLowLatencyOutputStream( | 118 AudioOutputStream* AudioManagerPulse::MakeLowLatencyOutputStream( |
| 100 const AudioParameters& params) { | 119 const AudioParameters& params) { |
| 101 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 120 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 102 return MakeOutputStream(params); | 121 return MakeOutputStream(params); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 | 140 |
| 122 AudioInputStream* AudioManagerPulse::MakeInputStream( | 141 AudioInputStream* AudioManagerPulse::MakeInputStream( |
| 123 const AudioParameters& params, const std::string& device_id) { | 142 const AudioParameters& params, const std::string& device_id) { |
| 124 return new PulseAudioInputStream(this, device_id, params, | 143 return new PulseAudioInputStream(this, device_id, params, |
| 125 input_mainloop_, input_context_); | 144 input_mainloop_, input_context_); |
| 126 } | 145 } |
| 127 | 146 |
| 128 AudioParameters AudioManagerPulse::GetPreferredLowLatencyOutputStreamParameters( | 147 AudioParameters AudioManagerPulse::GetPreferredLowLatencyOutputStreamParameters( |
| 129 const AudioParameters& input_params) { | 148 const AudioParameters& input_params) { |
| 130 // TODO(xians): figure out the optimized buffer size for the Pulse IO. | 149 // TODO(xians): figure out the optimized buffer size for the Pulse IO. |
| 131 int buffer_size = GetAudioHardwareBufferSize(); | 150 AudioParameters default_params = GetDefaultOutputStreamParameters(); |
| 132 if (input_params.frames_per_buffer() < buffer_size) | 151 int buffer_size = std::min(input_params.frames_per_buffer(), |
| 133 buffer_size = input_params.frames_per_buffer(); | 152 default_params.frames_per_buffer()); |
| 134 | 153 |
| 135 // TODO(dalecurtis): This should include bits per channel and channel layout | 154 // TODO(dalecurtis): This should include bits per channel and channel layout |
| 136 // eventually. | 155 // eventually. |
| 137 return AudioParameters( | 156 return AudioParameters( |
| 138 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), | 157 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), |
| 139 input_params.sample_rate(), 16, buffer_size); | 158 input_params.sample_rate(), 16, buffer_size); |
| 140 } | 159 } |
| 141 | 160 |
| 142 int AudioManagerPulse::GetNativeSampleRate() { | 161 int AudioManagerPulse::GetNativeSampleRate() { |
| 143 DCHECK(input_mainloop_); | 162 DCHECK(input_mainloop_); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 271 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
| 253 const pa_server_info* info, | 272 const pa_server_info* info, |
| 254 void* user_data) { | 273 void* user_data) { |
| 255 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 274 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 256 | 275 |
| 257 manager->native_input_sample_rate_ = info->sample_spec.rate; | 276 manager->native_input_sample_rate_ = info->sample_spec.rate; |
| 258 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 277 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 259 } | 278 } |
| 260 | 279 |
| 261 } // namespace media | 280 } // namespace media |
| OLD | NEW |