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