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/alsa/audio_manager_alsa.h" | 5 #include "media/audio/alsa/audio_manager_alsa.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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 media::AudioDeviceNames* device_names) { | 145 media::AudioDeviceNames* device_names) { |
146 static const char kIoHintName[] = "IOID"; | 146 static const char kIoHintName[] = "IOID"; |
147 static const char kNameHintName[] = "NAME"; | 147 static const char kNameHintName[] = "NAME"; |
148 static const char kDescriptionHintName[] = "DESC"; | 148 static const char kDescriptionHintName[] = "DESC"; |
149 | 149 |
150 const char* unwanted_device_type = UnwantedDeviceTypeWhenEnumerating(type); | 150 const char* unwanted_device_type = UnwantedDeviceTypeWhenEnumerating(type); |
151 | 151 |
152 for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) { | 152 for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) { |
153 // Only examine devices of the right type. Valid values are | 153 // Only examine devices of the right type. Valid values are |
154 // "Input", "Output", and NULL which means both input and output. | 154 // "Input", "Output", and NULL which means both input and output. |
155 scoped_ptr_malloc<char> io(wrapper_->DeviceNameGetHint(*hint_iter, | 155 scoped_ptr<char, base::FreeDeleter> io(wrapper_->DeviceNameGetHint( |
156 kIoHintName)); | 156 *hint_iter, kIoHintName)); |
157 if (io != NULL && strcmp(unwanted_device_type, io.get()) == 0) | 157 if (io != NULL && strcmp(unwanted_device_type, io.get()) == 0) |
158 continue; | 158 continue; |
159 | 159 |
160 // Found a device, prepend the default device since we always want | 160 // Found a device, prepend the default device since we always want |
161 // it to be on the top of the list for all platforms. And there is | 161 // it to be on the top of the list for all platforms. And there is |
162 // no duplicate counting here since it is only done if the list is | 162 // no duplicate counting here since it is only done if the list is |
163 // still empty. Note, pulse has exclusively opened the default | 163 // still empty. Note, pulse has exclusively opened the default |
164 // device, so we must open the device via the "default" moniker. | 164 // device, so we must open the device via the "default" moniker. |
165 if (device_names->empty()) { | 165 if (device_names->empty()) { |
166 device_names->push_front(media::AudioDeviceName( | 166 device_names->push_front(media::AudioDeviceName( |
167 AudioManagerBase::kDefaultDeviceName, | 167 AudioManagerBase::kDefaultDeviceName, |
168 AudioManagerBase::kDefaultDeviceId)); | 168 AudioManagerBase::kDefaultDeviceId)); |
169 } | 169 } |
170 | 170 |
171 // Get the unique device name for the device. | 171 // Get the unique device name for the device. |
172 scoped_ptr_malloc<char> unique_device_name( | 172 scoped_ptr<char, base::FreeDeleter> unique_device_name( |
173 wrapper_->DeviceNameGetHint(*hint_iter, kNameHintName)); | 173 wrapper_->DeviceNameGetHint(*hint_iter, kNameHintName)); |
174 | 174 |
175 // Find out if the device is available. | 175 // Find out if the device is available. |
176 if (IsAlsaDeviceAvailable(type, unique_device_name.get())) { | 176 if (IsAlsaDeviceAvailable(type, unique_device_name.get())) { |
177 // Get the description for the device. | 177 // Get the description for the device. |
178 scoped_ptr_malloc<char> desc(wrapper_->DeviceNameGetHint( | 178 scoped_ptr<char, base::FreeDeleter> desc(wrapper_->DeviceNameGetHint( |
179 *hint_iter, kDescriptionHintName)); | 179 *hint_iter, kDescriptionHintName)); |
180 | 180 |
181 media::AudioDeviceName name; | 181 media::AudioDeviceName name; |
182 name.unique_id = unique_device_name.get(); | 182 name.unique_id = unique_device_name.get(); |
183 if (desc) { | 183 if (desc) { |
184 // Use the more user friendly description as name. | 184 // Use the more user friendly description as name. |
185 // Replace '\n' with '-'. | 185 // Replace '\n' with '-'. |
186 char* pret = strchr(desc.get(), '\n'); | 186 char* pret = strchr(desc.get(), '\n'); |
187 if (pret) | 187 if (pret) |
188 *pret = '-'; | 188 *pret = '-'; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 // Loop through the sound cards. | 246 // Loop through the sound cards. |
247 // Don't use snd_device_name_hint(-1,..) since there is a access violation | 247 // Don't use snd_device_name_hint(-1,..) since there is a access violation |
248 // inside this ALSA API with libasound.so.2.0.0. | 248 // inside this ALSA API with libasound.so.2.0.0. |
249 while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) { | 249 while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) { |
250 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); | 250 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); |
251 if (!error) { | 251 if (!error) { |
252 for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) { | 252 for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) { |
253 // Only examine devices that are |stream| capable. Valid values are | 253 // Only examine devices that are |stream| capable. Valid values are |
254 // "Input", "Output", and NULL which means both input and output. | 254 // "Input", "Output", and NULL which means both input and output. |
255 scoped_ptr_malloc<char> io(wrapper_->DeviceNameGetHint(*hint_iter, | 255 scoped_ptr<char, base::FreeDeleter> io(wrapper_->DeviceNameGetHint( |
256 kIoHintName)); | 256 *hint_iter, kIoHintName)); |
257 const char* unwanted_type = UnwantedDeviceTypeWhenEnumerating(stream); | 257 const char* unwanted_type = UnwantedDeviceTypeWhenEnumerating(stream); |
258 if (io != NULL && strcmp(unwanted_type, io.get()) == 0) | 258 if (io != NULL && strcmp(unwanted_type, io.get()) == 0) |
259 continue; // Wrong type, skip the device. | 259 continue; // Wrong type, skip the device. |
260 | 260 |
261 // Found an input device. | 261 // Found an input device. |
262 has_device = true; | 262 has_device = true; |
263 break; | 263 break; |
264 } | 264 } |
265 | 265 |
266 // Destroy the hints now that we're done with it. | 266 // Destroy the hints now that we're done with it. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 AlsaPcmInputStream::kAutoSelectDevice : device_id; | 351 AlsaPcmInputStream::kAutoSelectDevice : device_id; |
352 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { | 352 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { |
353 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 353 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
354 switches::kAlsaInputDevice); | 354 switches::kAlsaInputDevice); |
355 } | 355 } |
356 | 356 |
357 return new AlsaPcmInputStream(this, device_name, params, wrapper_.get()); | 357 return new AlsaPcmInputStream(this, device_name, params, wrapper_.get()); |
358 } | 358 } |
359 | 359 |
360 } // namespace media | 360 } // namespace media |
OLD | NEW |