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 29 matching lines...) Expand all Loading... |
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 = 1024; |
44 | 44 |
45 #if defined(DLOPEN_PULSEAUDIO) | 45 #if defined(DLOPEN_PULSEAUDIO) |
46 static const base::FilePath::CharType kPulseLib[] = | 46 static const base::FilePath::CharType kPulseLib[] = |
47 FILE_PATH_LITERAL("libpulse.so.0"); | 47 FILE_PATH_LITERAL("libpulse.so.0"); |
48 #endif | 48 #endif |
49 | 49 |
50 // static | 50 AudioManagerPulse::AudioManagerPulse( |
51 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) { | 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
52 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory)); | 52 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
53 if (ret->Init()) | 53 AudioLogFactory* audio_log_factory) |
54 return ret.release(); | 54 : AudioManagerBase(std::move(task_runner), |
55 | 55 std::move(worker_task_runner), |
56 DVLOG(1) << "PulseAudio is not available on the OS"; | 56 audio_log_factory), |
57 return NULL; | |
58 } | |
59 | |
60 AudioManagerPulse::AudioManagerPulse(AudioLogFactory* audio_log_factory) | |
61 : AudioManagerBase(audio_log_factory), | |
62 input_mainloop_(NULL), | 57 input_mainloop_(NULL), |
63 input_context_(NULL), | 58 input_context_(NULL), |
64 devices_(NULL), | 59 devices_(NULL), |
65 native_input_sample_rate_(0) { | 60 native_input_sample_rate_(0) { |
66 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 61 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
67 } | 62 } |
68 | 63 |
69 AudioManagerPulse::~AudioManagerPulse() { | 64 AudioManagerPulse::~AudioManagerPulse() { |
70 Shutdown(); | 65 Shutdown(); |
71 | |
72 // The Pulse objects are the last things to be destroyed since Shutdown() | 66 // The Pulse objects are the last things to be destroyed since Shutdown() |
73 // needs them. | 67 // needs them. |
74 DestroyPulse(); | 68 DestroyPulse(); |
75 } | 69 } |
76 | 70 |
| 71 bool AudioManagerPulse::Init() { |
| 72 // TODO(alokp): Investigate if InitPulse can happen on the audio thread. |
| 73 // It currently needs to happen on the main thread so that is InitPulse fails, |
| 74 // we can fallback to ALSA implementation. Initializing it on audio thread |
| 75 // would unblock the main thread and make InitPulse consistent with |
| 76 // DestroyPulse which happens on the audio thread. |
| 77 return InitPulse(); |
| 78 } |
| 79 |
77 // Implementation of AudioManager. | 80 // Implementation of AudioManager. |
78 bool AudioManagerPulse::HasAudioOutputDevices() { | 81 bool AudioManagerPulse::HasAudioOutputDevices() { |
79 AudioDeviceNames devices; | 82 AudioDeviceNames devices; |
80 GetAudioOutputDeviceNames(&devices); | 83 GetAudioOutputDeviceNames(&devices); |
81 return !devices.empty(); | 84 return !devices.empty(); |
82 } | 85 } |
83 | 86 |
84 bool AudioManagerPulse::HasAudioInputDevices() { | 87 bool AudioManagerPulse::HasAudioInputDevices() { |
85 AudioDeviceNames devices; | 88 AudioDeviceNames devices; |
86 GetAudioInputDeviceNames(&devices); | 89 GetAudioInputDeviceNames(&devices); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 DCHECK(input_mainloop_); | 213 DCHECK(input_mainloop_); |
211 DCHECK(input_context_); | 214 DCHECK(input_context_); |
212 AutoPulseLock auto_lock(input_mainloop_); | 215 AutoPulseLock auto_lock(input_mainloop_); |
213 pa_operation* operation = pa_context_get_server_info( | 216 pa_operation* operation = pa_context_get_server_info( |
214 input_context_, SampleRateInfoCallback, this); | 217 input_context_, SampleRateInfoCallback, this); |
215 WaitForOperationCompletion(input_mainloop_, operation); | 218 WaitForOperationCompletion(input_mainloop_, operation); |
216 | 219 |
217 return native_input_sample_rate_; | 220 return native_input_sample_rate_; |
218 } | 221 } |
219 | 222 |
220 bool AudioManagerPulse::Init() { | 223 bool AudioManagerPulse::InitPulse() { |
221 DCHECK(!input_mainloop_); | 224 DCHECK(!input_mainloop_); |
222 | 225 |
223 #if defined(DLOPEN_PULSEAUDIO) | 226 #if defined(DLOPEN_PULSEAUDIO) |
224 StubPathMap paths; | 227 StubPathMap paths; |
225 | 228 |
226 // Check if the pulse library is avialbale. | 229 // Check if the pulse library is avialbale. |
227 paths[kModulePulse].push_back(kPulseLib); | 230 paths[kModulePulse].push_back(kPulseLib); |
228 if (!InitializeStubs(paths)) { | 231 if (!InitializeStubs(paths)) { |
229 VLOG(1) << "Failed on loading the Pulse library and symbols"; | 232 VLOG(1) << "Failed on loading the Pulse library and symbols"; |
230 return false; | 233 return false; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 335 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
333 const pa_server_info* info, | 336 const pa_server_info* info, |
334 void* user_data) { | 337 void* user_data) { |
335 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 338 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
336 | 339 |
337 manager->native_input_sample_rate_ = info->sample_spec.rate; | 340 manager->native_input_sample_rate_ = info->sample_spec.rate; |
338 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 341 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
339 } | 342 } |
340 | 343 |
341 } // namespace media | 344 } // namespace media |
OLD | NEW |