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 30 matching lines...) Expand all Loading... |
41 static const int kMaximumOutputBufferSize = 8192; | 41 static const int kMaximumOutputBufferSize = 8192; |
42 | 42 |
43 // Default input buffer size. | 43 // Default input buffer size. |
44 static const int kDefaultInputBufferSize = 1024; | 44 static const int kDefaultInputBufferSize = 1024; |
45 | 45 |
46 #if defined(DLOPEN_PULSEAUDIO) | 46 #if defined(DLOPEN_PULSEAUDIO) |
47 static const base::FilePath::CharType kPulseLib[] = | 47 static const base::FilePath::CharType kPulseLib[] = |
48 FILE_PATH_LITERAL("libpulse.so.0"); | 48 FILE_PATH_LITERAL("libpulse.so.0"); |
49 #endif | 49 #endif |
50 | 50 |
51 AudioManagerPulse::AudioManagerPulse( | 51 AudioManagerPulse::AudioManagerPulse(std::unique_ptr<AudioThread> audio_thread, |
52 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 52 AudioLogFactory* audio_log_factory) |
53 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 53 : AudioManagerBase(std::move(audio_thread), audio_log_factory), |
54 AudioLogFactory* audio_log_factory) | |
55 : AudioManagerBase(std::move(task_runner), | |
56 std::move(worker_task_runner), | |
57 audio_log_factory), | |
58 input_mainloop_(NULL), | 54 input_mainloop_(NULL), |
59 input_context_(NULL), | 55 input_context_(NULL), |
60 devices_(NULL), | 56 devices_(NULL), |
61 native_input_sample_rate_(0), | 57 native_input_sample_rate_(0), |
62 native_channel_count_(0) { | 58 native_channel_count_(0) { |
63 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 59 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
64 } | 60 } |
65 | 61 |
66 AudioManagerPulse::~AudioManagerPulse() { | 62 AudioManagerPulse::~AudioManagerPulse() = default; |
67 Shutdown(); | |
68 // The Pulse objects are the last things to be destroyed since Shutdown() | |
69 // needs them. | |
70 DestroyPulse(); | |
71 } | |
72 | 63 |
73 bool AudioManagerPulse::Init() { | 64 bool AudioManagerPulse::Init() { |
74 // TODO(alokp): Investigate if InitPulse can happen on the audio thread. | 65 // TODO(alokp): Investigate if InitPulse can happen on the audio thread. |
75 // It currently needs to happen on the main thread so that is InitPulse fails, | 66 // It currently needs to happen on the main thread so that is InitPulse fails, |
76 // we can fallback to ALSA implementation. Initializing it on audio thread | 67 // we can fallback to ALSA implementation. Initializing it on audio thread |
77 // would unblock the main thread and make InitPulse consistent with | 68 // would unblock the main thread and make InitPulse consistent with |
78 // DestroyPulse which happens on the audio thread. | 69 // DestroyPulse which happens on the audio thread. |
79 return InitPulse(); | 70 return InitPulse(); |
80 } | 71 } |
81 | 72 |
82 // Implementation of AudioManager. | 73 void AudioManagerPulse::ShutdownOnAudioThread() { |
| 74 AudioManagerBase::ShutdownOnAudioThread(); |
| 75 // The Pulse objects are the last things to be destroyed since Shutdown() |
| 76 // needs them. |
| 77 DestroyPulse(); |
| 78 } |
| 79 |
83 bool AudioManagerPulse::HasAudioOutputDevices() { | 80 bool AudioManagerPulse::HasAudioOutputDevices() { |
84 AudioDeviceNames devices; | 81 AudioDeviceNames devices; |
85 GetAudioOutputDeviceNames(&devices); | 82 GetAudioOutputDeviceNames(&devices); |
86 return !devices.empty(); | 83 return !devices.empty(); |
87 } | 84 } |
88 | 85 |
89 bool AudioManagerPulse::HasAudioInputDevices() { | 86 bool AudioManagerPulse::HasAudioInputDevices() { |
90 AudioDeviceNames devices; | 87 AudioDeviceNames devices; |
91 GetAudioInputDeviceNames(&devices); | 88 GetAudioInputDeviceNames(&devices); |
92 return !devices.empty(); | 89 return !devices.empty(); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 const pa_server_info* info, | 346 const pa_server_info* info, |
350 void* user_data) { | 347 void* user_data) { |
351 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 348 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
352 | 349 |
353 manager->native_input_sample_rate_ = info->sample_spec.rate; | 350 manager->native_input_sample_rate_ = info->sample_spec.rate; |
354 manager->native_channel_count_ = info->sample_spec.channels; | 351 manager->native_channel_count_ = info->sample_spec.channels; |
355 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 352 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
356 } | 353 } |
357 | 354 |
358 } // namespace media | 355 } // namespace media |
OLD | NEW |