OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/openbsd/audio_manager_openbsd.h" | 5 #include "media/audio/openbsd/audio_manager_openbsd.h" |
6 | 6 |
| 7 #include <fcntl.h> |
| 8 |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" |
8 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
9 #include "media/audio/audio_output_dispatcher.h" | 12 #include "media/audio/audio_output_dispatcher.h" |
10 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
11 #include "media/audio/audio_util.h" | 14 #include "media/audio/audio_util.h" |
12 #if defined(USE_PULSEAUDIO) | |
13 #include "media/audio/pulse/pulse_output.h" | 15 #include "media/audio/pulse/pulse_output.h" |
14 #endif | 16 #include "media/audio/pulse/pulse_stubs.h" |
15 #include "media/base/channel_layout.h" | 17 #include "media/base/channel_layout.h" |
16 #include "media/base/limits.h" | 18 #include "media/base/limits.h" |
17 #include "media/base/media_switches.h" | 19 #include "media/base/media_switches.h" |
18 | 20 |
19 #include <fcntl.h> | 21 using media_audio_pulse::kModulePulse; |
| 22 using media_audio_pulse::InitializeStubs; |
| 23 using media_audio_pulse::StubPathMap; |
20 | 24 |
21 namespace media { | 25 namespace media { |
22 | 26 |
23 // Maximum number of output streams that can be open simultaneously. | 27 // Maximum number of output streams that can be open simultaneously. |
24 static const int kMaxOutputStreams = 50; | 28 static const int kMaxOutputStreams = 50; |
25 | 29 |
26 // Default sample rate for input and output streams. | 30 // Default sample rate for input and output streams. |
27 static const int kDefaultSampleRate = 48000; | 31 static const int kDefaultSampleRate = 48000; |
28 | 32 |
| 33 static const base::FilePath::CharType kPulseLib[] = |
| 34 FILE_PATH_LITERAL("libpulse.so.0"); |
| 35 |
29 // Implementation of AudioManager. | 36 // Implementation of AudioManager. |
30 static bool HasAudioHardware() { | 37 static bool HasAudioHardware() { |
31 int fd; | 38 int fd; |
32 const char *file; | 39 const char *file; |
33 | 40 |
34 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') | 41 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') |
35 file = "/dev/audioctl"; | 42 file = "/dev/audioctl"; |
36 | 43 |
37 if ((fd = open(file, O_RDONLY)) < 0) | 44 if ((fd = open(file, O_RDONLY)) < 0) |
38 return false; | 45 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
51 | 58 |
52 AudioParameters AudioManagerOpenBSD::GetInputStreamParameters( | 59 AudioParameters AudioManagerOpenBSD::GetInputStreamParameters( |
53 const std::string& device_id) { | 60 const std::string& device_id) { |
54 static const int kDefaultInputBufferSize = 1024; | 61 static const int kDefaultInputBufferSize = 1024; |
55 | 62 |
56 return AudioParameters( | 63 return AudioParameters( |
57 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 64 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
58 kDefaultSampleRate, 16, kDefaultInputBufferSize); | 65 kDefaultSampleRate, 16, kDefaultInputBufferSize); |
59 } | 66 } |
60 | 67 |
61 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 68 AudioManagerOpenBSD::AudioManagerOpenBSD() |
| 69 : pulse_library_is_initialized_(false) { |
62 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 70 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
| 71 StubPathMap paths; |
| 72 |
| 73 // Check if the pulse library is avialbale. |
| 74 paths[kModulePulse].push_back(kPulseLib); |
| 75 if (!InitializeStubs(paths)) { |
| 76 DLOG(WARNING) << "Failed on loading the Pulse library and symbols"; |
| 77 return; |
| 78 } |
| 79 |
| 80 pulse_library_is_initialized_ = true; |
63 } | 81 } |
64 | 82 |
65 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 83 AudioManagerOpenBSD::~AudioManagerOpenBSD() { |
66 Shutdown(); | 84 Shutdown(); |
67 } | 85 } |
68 | 86 |
69 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( | 87 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( |
70 const AudioParameters& params) { | 88 const AudioParameters& params) { |
71 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format); | 89 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format); |
72 return MakeOutputStream(params); | 90 return MakeOutputStream(params); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 129 |
112 int user_buffer_size = GetUserBufferSize(); | 130 int user_buffer_size = GetUserBufferSize(); |
113 if (user_buffer_size) | 131 if (user_buffer_size) |
114 buffer_size = user_buffer_size; | 132 buffer_size = user_buffer_size; |
115 | 133 |
116 return AudioParameters( | 134 return AudioParameters( |
117 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, | 135 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
118 sample_rate, bits_per_sample, buffer_size); | 136 sample_rate, bits_per_sample, buffer_size); |
119 } | 137 } |
120 | 138 |
121 | |
122 AudioOutputStream* AudioManagerOpenBSD::MakeOutputStream( | 139 AudioOutputStream* AudioManagerOpenBSD::MakeOutputStream( |
123 const AudioParameters& params) { | 140 const AudioParameters& params) { |
124 #if defined(USE_PULSEAUDIO) | 141 if (pulse_library_is_initialized_) |
125 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | |
126 return new PulseAudioOutputStream(params, this); | 142 return new PulseAudioOutputStream(params, this); |
127 } | |
128 #endif | |
129 | 143 |
130 NOTIMPLEMENTED(); | |
131 return NULL; | 144 return NULL; |
132 } | 145 } |
133 | 146 |
134 // TODO(xians): Merge AudioManagerOpenBSD with AudioManagerPulse; | 147 // TODO(xians): Merge AudioManagerOpenBSD with AudioManagerPulse; |
135 // static | 148 // static |
136 AudioManager* CreateAudioManager() { | 149 AudioManager* CreateAudioManager() { |
137 return new AudioManagerOpenBSD(); | 150 return new AudioManagerOpenBSD(); |
138 } | 151 } |
139 | 152 |
140 } // namespace media | 153 } // namespace media |
OLD | NEW |