OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/linux/audio_manager_linux.h" | 5 #include "media/audio/linux/audio_manager_linux.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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/nix/xdg_util.h" | 10 #include "base/nix/xdg_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // TODO(ajwong): Make this actually query audio devices. | 56 // TODO(ajwong): Make this actually query audio devices. |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 bool AudioManagerLinux::HasAudioInputDevices() { | 60 bool AudioManagerLinux::HasAudioInputDevices() { |
61 if (!initialized()) { | 61 if (!initialized()) { |
62 return false; | 62 return false; |
63 } | 63 } |
64 | 64 |
65 // Constants specified by the ALSA API for device hints. | 65 // Constants specified by the ALSA API for device hints. |
66 static const int kGetAllDevices = -1; | |
67 static const char kPcmInterfaceName[] = "pcm"; | 66 static const char kPcmInterfaceName[] = "pcm"; |
68 bool has_device = false; | 67 bool has_device = false; |
69 void** hints = NULL; | 68 void** hints = NULL; |
| 69 int card = -1; |
70 | 70 |
71 // Use the same approach to find the devices as in | 71 // Loop through the sound cards to get Alsa device hints. |
72 // AlsaPcmOutputStream::FindDeviceForChannels | 72 // Don't use snd_device_name_hint(-1,..) since there is a access violation |
73 // Get Alsa device hints. | 73 // inside this ALSA API with libasound.so.2.0.0. |
74 int error = wrapper_->DeviceNameHint(kGetAllDevices, | 74 while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) { |
75 kPcmInterfaceName, | 75 int error = wrapper_->DeviceNameHint(card, |
76 &hints); | 76 kPcmInterfaceName, |
77 if (error == 0) { | 77 &hints); |
78 has_device = HasAnyValidAudioInputDevice(hints); | 78 if (error == 0) { |
79 } else { | 79 has_device = HasAnyValidAudioInputDevice(hints); |
80 LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error); | 80 |
| 81 // Destroy the hints now that we're done with it. |
| 82 wrapper_->DeviceNameFreeHint(hints); |
| 83 hints = NULL; |
| 84 } else { |
| 85 LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error); |
| 86 } |
81 } | 87 } |
82 | 88 |
83 // Destroy the hint now that we're done with it. | |
84 wrapper_->DeviceNameFreeHint(hints); | |
85 return has_device; | 89 return has_device; |
86 } | 90 } |
87 | 91 |
88 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( | 92 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( |
89 const AudioParameters& params) { | 93 const AudioParameters& params) { |
90 // Early return for testing hook. Do this before checking for | 94 // Early return for testing hook. Do this before checking for |
91 // |initialized_|. | 95 // |initialized_|. |
92 if (params.format == AudioParameters::AUDIO_MOCK) { | 96 if (params.format == AudioParameters::AUDIO_MOCK) { |
93 return FakeAudioOutputStream::MakeFakeStream(params); | 97 return FakeAudioOutputStream::MakeFakeStream(params); |
94 } | 98 } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return true; | 244 return true; |
241 } | 245 } |
242 | 246 |
243 return false; | 247 return false; |
244 } | 248 } |
245 | 249 |
246 // static | 250 // static |
247 AudioManager* AudioManager::CreateAudioManager() { | 251 AudioManager* AudioManager::CreateAudioManager() { |
248 return new AudioManagerLinux(); | 252 return new AudioManagerLinux(); |
249 } | 253 } |
OLD | NEW |