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 22 matching lines...) Expand all Loading... |
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 // Define bounds for the output buffer size. |
39 static const int kMinimumOutputBufferSize = 512; | 39 static const int kMinimumOutputBufferSize = 512; |
40 static const int kMaximumOutputBufferSize = 8192; | 40 static const int kMaximumOutputBufferSize = 8192; |
41 | 41 |
42 // Default input buffer size. | 42 // Default input buffer size. |
43 static const int kDefaultInputBufferSize = 1024; | 43 static const int kDefaultInputBufferSize = 512; |
44 | 44 |
45 static const base::FilePath::CharType kPulseLib[] = | 45 static const base::FilePath::CharType kPulseLib[] = |
46 FILE_PATH_LITERAL("libpulse.so.0"); | 46 FILE_PATH_LITERAL("libpulse.so.0"); |
47 | 47 |
48 // static | 48 // static |
49 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) { | 49 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) { |
50 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory)); | 50 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory)); |
51 if (ret->Init()) | 51 if (ret->Init()) |
52 return ret.release(); | 52 return ret.release(); |
53 | 53 |
54 DVLOG(1) << "PulseAudio is not available on the OS"; | 54 DVLOG(1) << "PulseAudio is not available on the OS"; |
55 return NULL; | 55 return NULL; |
56 } | 56 } |
57 | 57 |
58 AudioManagerPulse::AudioManagerPulse(AudioLogFactory* audio_log_factory) | 58 AudioManagerPulse::AudioManagerPulse(AudioLogFactory* audio_log_factory) |
59 : AudioManagerBase(audio_log_factory), | 59 : AudioManagerBase(audio_log_factory), |
60 input_mainloop_(NULL), | 60 input_mainloop_(NULL), |
61 input_context_(NULL), | 61 input_context_(NULL), |
62 devices_(NULL), | 62 devices_(NULL), |
63 native_input_sample_rate_(0) { | 63 native_input_sample_rate_(0) { |
| 64 DVLOG(1) << __FUNCTION__; |
64 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 65 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
65 } | 66 } |
66 | 67 |
67 AudioManagerPulse::~AudioManagerPulse() { | 68 AudioManagerPulse::~AudioManagerPulse() { |
| 69 DVLOG(1) << __FUNCTION__; |
68 Shutdown(); | 70 Shutdown(); |
69 | 71 |
70 // The Pulse objects are the last things to be destroyed since Shutdown() | 72 // The Pulse objects are the last things to be destroyed since Shutdown() |
71 // needs them. | 73 // needs them. |
72 DestroyPulse(); | 74 DestroyPulse(); |
73 } | 75 } |
74 | 76 |
75 // Implementation of AudioManager. | 77 // Implementation of AudioManager. |
76 bool AudioManagerPulse::HasAudioOutputDevices() { | 78 bool AudioManagerPulse::HasAudioOutputDevices() { |
77 AudioDeviceNames devices; | 79 AudioDeviceNames devices; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::GetInputStreamParameters( |
130 const std::string& device_id) { | 132 const std::string& device_id) { |
| 133 DVLOG(1) << "AudioManagerPulse::GetInputStreamParameters"; |
131 int user_buffer_size = GetUserBufferSize(); | 134 int user_buffer_size = GetUserBufferSize(); |
132 int buffer_size = user_buffer_size ? | 135 int buffer_size = user_buffer_size ? |
133 user_buffer_size : kDefaultInputBufferSize; | 136 user_buffer_size : kDefaultInputBufferSize; |
134 | 137 |
135 // TODO(xians): add support for querying native channel layout for pulse. | 138 // TODO(xians): add support for querying native channel layout for pulse. |
136 return AudioParameters( | 139 return AudioParameters( |
137 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 140 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
138 GetNativeSampleRate(), 16, buffer_size); | 141 GetNativeSampleRate(), 16, buffer_size); |
139 } | 142 } |
140 | 143 |
(...skipping 20 matching lines...) Expand all Loading... |
161 | 164 |
162 AudioInputStream* AudioManagerPulse::MakeLowLatencyInputStream( | 165 AudioInputStream* AudioManagerPulse::MakeLowLatencyInputStream( |
163 const AudioParameters& params, const std::string& device_id) { | 166 const AudioParameters& params, const std::string& device_id) { |
164 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 167 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
165 return MakeInputStream(params, device_id); | 168 return MakeInputStream(params, device_id); |
166 } | 169 } |
167 | 170 |
168 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( | 171 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( |
169 const std::string& output_device_id, | 172 const std::string& output_device_id, |
170 const AudioParameters& input_params) { | 173 const AudioParameters& input_params) { |
| 174 DVLOG(1) << "AudioManagerPulse::GetPreferredOutputStreamParameters"; |
171 // TODO(tommi): Support |output_device_id|. | 175 // TODO(tommi): Support |output_device_id|. |
172 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; | 176 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; |
173 | 177 |
174 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 178 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
175 int buffer_size = kMinimumOutputBufferSize; | 179 int buffer_size = kMinimumOutputBufferSize; |
176 int bits_per_sample = 16; | 180 int bits_per_sample = 16; |
177 int input_channels = 0; | 181 int input_channels = 0; |
178 int sample_rate; | 182 int sample_rate; |
179 if (input_params.IsValid()) { | 183 if (input_params.IsValid()) { |
180 bits_per_sample = input_params.bits_per_sample(); | 184 bits_per_sample = input_params.bits_per_sample(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 340 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
337 const pa_server_info* info, | 341 const pa_server_info* info, |
338 void* user_data) { | 342 void* user_data) { |
339 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 343 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
340 | 344 |
341 manager->native_input_sample_rate_ = info->sample_spec.rate; | 345 manager->native_input_sample_rate_ = info->sample_spec.rate; |
342 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 346 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
343 } | 347 } |
344 | 348 |
345 } // namespace media | 349 } // namespace media |
OLD | NEW |