| 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::GetInputStreamParameters( |
| 95 const std::string& device_id) { |
| 96 static const int kDefaultInputBufferSize = 1024; |
| 97 |
| 98 // TODO(xians): add support for querying native channel layout for pulse. |
| 99 return AudioParameters( |
| 100 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 101 GetNativeSampleRate(), 16, kDefaultInputBufferSize); |
| 102 } |
| 103 |
| 93 AudioOutputStream* AudioManagerPulse::MakeLinearOutputStream( | 104 AudioOutputStream* AudioManagerPulse::MakeLinearOutputStream( |
| 94 const AudioParameters& params) { | 105 const AudioParameters& params) { |
| 95 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 106 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 96 return MakeOutputStream(params); | 107 return MakeOutputStream(params); |
| 97 } | 108 } |
| 98 | 109 |
| 99 AudioOutputStream* AudioManagerPulse::MakeLowLatencyOutputStream( | 110 AudioOutputStream* AudioManagerPulse::MakeLowLatencyOutputStream( |
| 100 const AudioParameters& params) { | 111 const AudioParameters& params) { |
| 101 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 112 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 102 return MakeOutputStream(params); | 113 return MakeOutputStream(params); |
| 103 } | 114 } |
| 104 | 115 |
| 105 AudioInputStream* AudioManagerPulse::MakeLinearInputStream( | 116 AudioInputStream* AudioManagerPulse::MakeLinearInputStream( |
| 106 const AudioParameters& params, const std::string& device_id) { | 117 const AudioParameters& params, const std::string& device_id) { |
| 107 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 118 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 108 return MakeInputStream(params, device_id); | 119 return MakeInputStream(params, device_id); |
| 109 } | 120 } |
| 110 | 121 |
| 111 AudioInputStream* AudioManagerPulse::MakeLowLatencyInputStream( | 122 AudioInputStream* AudioManagerPulse::MakeLowLatencyInputStream( |
| 112 const AudioParameters& params, const std::string& device_id) { | 123 const AudioParameters& params, const std::string& device_id) { |
| 113 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 124 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 114 return MakeInputStream(params, device_id); | 125 return MakeInputStream(params, device_id); |
| 115 } | 126 } |
| 116 | 127 |
| 128 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( |
| 129 const AudioParameters& input_params) { |
| 130 static const int kDefaultOutputBufferSize = 512; |
| 131 |
| 132 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 133 int buffer_size = kDefaultOutputBufferSize; |
| 134 int bits_per_sample = 16; |
| 135 int input_channels = 0; |
| 136 if (input_params.IsValid()) { |
| 137 bits_per_sample = input_params.bits_per_sample(); |
| 138 channel_layout = input_params.channel_layout(); |
| 139 input_channels = input_params.input_channels(); |
| 140 buffer_size = std::min(buffer_size, input_params.frames_per_buffer()); |
| 141 } |
| 142 return AudioParameters( |
| 143 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
| 144 GetNativeSampleRate(), bits_per_sample, buffer_size); |
| 145 } |
| 146 |
| 117 AudioOutputStream* AudioManagerPulse::MakeOutputStream( | 147 AudioOutputStream* AudioManagerPulse::MakeOutputStream( |
| 118 const AudioParameters& params) { | 148 const AudioParameters& params) { |
| 119 return new PulseAudioOutputStream(params, this); | 149 return new PulseAudioOutputStream(params, this); |
| 120 } | 150 } |
| 121 | 151 |
| 122 AudioInputStream* AudioManagerPulse::MakeInputStream( | 152 AudioInputStream* AudioManagerPulse::MakeInputStream( |
| 123 const AudioParameters& params, const std::string& device_id) { | 153 const AudioParameters& params, const std::string& device_id) { |
| 124 return new PulseAudioInputStream(this, device_id, params, | 154 return new PulseAudioInputStream(this, device_id, params, |
| 125 input_mainloop_, input_context_); | 155 input_mainloop_, input_context_); |
| 126 } | 156 } |
| 127 | 157 |
| 128 AudioParameters AudioManagerPulse::GetPreferredLowLatencyOutputStreamParameters( | |
| 129 const AudioParameters& input_params) { | |
| 130 // TODO(xians): figure out the optimized buffer size for the Pulse IO. | |
| 131 int buffer_size = GetAudioHardwareBufferSize(); | |
| 132 if (input_params.frames_per_buffer() < buffer_size) | |
| 133 buffer_size = input_params.frames_per_buffer(); | |
| 134 | |
| 135 // TODO(dalecurtis): This should include bits per channel and channel layout | |
| 136 // eventually. | |
| 137 return AudioParameters( | |
| 138 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), | |
| 139 input_params.sample_rate(), 16, buffer_size); | |
| 140 } | |
| 141 | |
| 142 int AudioManagerPulse::GetNativeSampleRate() { | 158 int AudioManagerPulse::GetNativeSampleRate() { |
| 143 DCHECK(input_mainloop_); | 159 DCHECK(input_mainloop_); |
| 144 DCHECK(input_context_); | 160 DCHECK(input_context_); |
| 145 AutoPulseLock auto_lock(input_mainloop_); | 161 AutoPulseLock auto_lock(input_mainloop_); |
| 146 pa_operation* operation = pa_context_get_server_info( | 162 pa_operation* operation = pa_context_get_server_info( |
| 147 input_context_, SampleRateInfoCallback, this); | 163 input_context_, SampleRateInfoCallback, this); |
| 148 WaitForOperationCompletion(input_mainloop_, operation); | 164 WaitForOperationCompletion(input_mainloop_, operation); |
| 149 | 165 |
| 150 return native_input_sample_rate_; | 166 return native_input_sample_rate_; |
| 151 } | 167 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 268 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
| 253 const pa_server_info* info, | 269 const pa_server_info* info, |
| 254 void* user_data) { | 270 void* user_data) { |
| 255 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 271 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 256 | 272 |
| 257 manager->native_input_sample_rate_ = info->sample_spec.rate; | 273 manager->native_input_sample_rate_ = info->sample_spec.rate; |
| 258 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 274 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 259 } | 275 } |
| 260 | 276 |
| 261 } // namespace media | 277 } // namespace media |
| OLD | NEW |