summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/linux/alsa_wrapper.cc4
-rw-r--r--media/audio/linux/alsa_wrapper.h1
-rw-r--r--media/audio/linux/audio_manager_linux.cc32
3 files changed, 23 insertions, 14 deletions
diff --git a/media/audio/linux/alsa_wrapper.cc b/media/audio/linux/alsa_wrapper.cc
index 563bccb..69b703e 100644
--- a/media/audio/linux/alsa_wrapper.cc
+++ b/media/audio/linux/alsa_wrapper.cc
@@ -29,6 +29,10 @@ int AlsaWrapper::DeviceNameFreeHint(void** hints) {
return snd_device_name_free_hint(hints);
}
+int AlsaWrapper::CardNext(int* rcard) {
+ return snd_card_next(rcard);
+}
+
int AlsaWrapper::PcmClose(snd_pcm_t* handle) {
return snd_pcm_close(handle);
}
diff --git a/media/audio/linux/alsa_wrapper.h b/media/audio/linux/alsa_wrapper.h
index efe93d0..85cf68a 100644
--- a/media/audio/linux/alsa_wrapper.h
+++ b/media/audio/linux/alsa_wrapper.h
@@ -19,6 +19,7 @@ class MEDIA_EXPORT AlsaWrapper {
virtual int DeviceNameHint(int card, const char* iface, void*** hints);
virtual char* DeviceNameGetHint(const void* hint, const char* id);
virtual int DeviceNameFreeHint(void** hints);
+ virtual int CardNext(int* rcard);
virtual int PcmOpen(snd_pcm_t** handle, const char* name,
snd_pcm_stream_t stream, int mode);
diff --git a/media/audio/linux/audio_manager_linux.cc b/media/audio/linux/audio_manager_linux.cc
index caab797..930c6b2 100644
--- a/media/audio/linux/audio_manager_linux.cc
+++ b/media/audio/linux/audio_manager_linux.cc
@@ -63,25 +63,29 @@ bool AudioManagerLinux::HasAudioInputDevices() {
}
// Constants specified by the ALSA API for device hints.
- static const int kGetAllDevices = -1;
static const char kPcmInterfaceName[] = "pcm";
bool has_device = false;
void** hints = NULL;
-
- // Use the same approach to find the devices as in
- // AlsaPcmOutputStream::FindDeviceForChannels
- // Get Alsa device hints.
- int error = wrapper_->DeviceNameHint(kGetAllDevices,
- kPcmInterfaceName,
- &hints);
- if (error == 0) {
- has_device = HasAnyValidAudioInputDevice(hints);
- } else {
- LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error);
+ int card = -1;
+
+ // Loop through the sound cards to get Alsa device hints.
+ // Don't use snd_device_name_hint(-1,..) since there is a access violation
+ // inside this ALSA API with libasound.so.2.0.0.
+ while (!wrapper_->CardNext(&card) && (card >= 0) && !has_device) {
+ int error = wrapper_->DeviceNameHint(card,
+ kPcmInterfaceName,
+ &hints);
+ if (error == 0) {
+ has_device = HasAnyValidAudioInputDevice(hints);
+
+ // Destroy the hints now that we're done with it.
+ wrapper_->DeviceNameFreeHint(hints);
+ hints = NULL;
+ } else {
+ LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error);
+ }
}
- // Destroy the hint now that we're done with it.
- wrapper_->DeviceNameFreeHint(hints);
return has_device;
}