Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: media/audio/linux/audio_manager_linux.cc

Issue 7060011: Adding GetAudioInputDeviceNames to AudioManager, this function is supposed to do device enumerati... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/linux/audio_manager_linux.cc
===================================================================
--- media/audio/linux/audio_manager_linux.cc (revision 86276)
+++ media/audio/linux/audio_manager_linux.cc (working copy)
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/nix/xdg_util.h"
#include "base/process_util.h"
+#include "base/stringprintf.h"
#include "media/audio/audio_output_dispatcher.h"
#include "media/audio/fake_audio_input_stream.h"
#include "media/audio/fake_audio_output_stream.h"
@@ -30,8 +31,79 @@
}
bool AudioManagerLinux::HasAudioInputDevices() {
awong 2011/05/23 17:36:15 It's slightly confusing to me that you don't popul
xians 2011/05/24 13:50:27 Sorry that I forgot to reply this. We cant do this
- // TODO(satish): Make this actually query audio devices.
- return true;
+ if (!initialized()) {
+ return false;
+ }
+
+ // Constants specified by the ALSA API for device hints.
+ static const int kGetAllDevices = -1;
+ static const char kPcmInterfaceName[] = "pcm";
+ static const char kIoHintName[] = "IOID";
+ static const char kNameHintName[] = "NAME";
+ // Since "default", "pulse" and "dmix" devices are virtual devices mapped to
awong 2011/05/23 17:36:15 Newline before comment.
xians 2011/05/23 20:15:59 Done.
+ // real devices, we remove them from the list to avoiding duplicate counting.
+ // In addition, note that we support no more than 2 channels for recording,
+ // hence surround devices are not stored in the list. Finally, output and
+ // null devices are not considered as valid devices for recording.
+ static const char kOutputDevice[] = "Output";
+ static const char KNotWantedDefaultDevice[] = "default";
+ static const char kNotWantedNullDevice[] = "null";
+ static const char kNotWantedPulseDevice[] = "pulse";
+ static const char kNotWantedDmixDevice[] = "dmix";
+ static const char kNotWantedSurroundDevice[] = "surround";
+ 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) {
+ // NOTE: Do not early return from inside this if statement. The
awong 2011/05/23 17:36:15 This function is long anyways. Throw the whole bod
xians 2011/05/23 20:15:59 I made a helper function to do this. But I am actu
+ // hints above need to be freed.
+ for (void** hint_iter = hints; *hint_iter != NULL; hint_iter++) {
+ // Only examine devices that are input capable.. Valid values are
+ // "Input", "Output", and NULL which means both input and output.
+ scoped_ptr_malloc<char> io(wrapper_->DeviceNameGetHint(*hint_iter,
+ kIoHintName));
+ // Wrong device type, skip it.
+ if (io != NULL &&
+ strncmp(kOutputDevice, io.get(), strlen(kOutputDevice)) == 0)
+ continue;
+
+ scoped_ptr_malloc<char> hint_device_name(
+ wrapper_->DeviceNameGetHint(*hint_iter, kNameHintName));
+ // Now check if if it is a valid device.
+ if (hint_device_name != NULL &&
+ strncmp(KNotWantedDefaultDevice,
+ hint_device_name.get(),
+ strlen(KNotWantedDefaultDevice)) != 0 &&
+ strncmp(kNotWantedNullDevice,
+ hint_device_name.get(),
+ strlen(kNotWantedNullDevice)) != 0 &&
+ strncmp(kNotWantedPulseDevice,
+ hint_device_name.get(),
+ strlen(kNotWantedPulseDevice)) != 0 &&
+ strncmp(kNotWantedDmixDevice,
+ hint_device_name.get(),
+ strlen(kNotWantedDmixDevice)) != 0 &&
+ strncmp(kNotWantedSurroundDevice,
+ hint_device_name.get(),
+ strlen(kNotWantedSurroundDevice)) != 0) {
+ // Found a real and valid device.
+ has_device = true;
+ break;
+ }
+ }
+ } else {
+ LOG(ERROR) << "Unable to get device hints: " << wrapper_->StrError(error);
+ }
+ // Destory the hint now that we're done with it.
awong 2011/05/23 17:36:15 Newline before comment.
xians 2011/05/23 20:15:59 Done.
+ wrapper_->DeviceNameFreeHint(hints);
+ hints = NULL;
+ return has_device;
}
AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream(
@@ -147,6 +219,21 @@
base::LaunchApp(CommandLine(FilePath(command)), false, false, NULL);
}
+void AudioManagerLinux::GetAudioInputDeviceNames(
+ AudioInputDeviceNames* device_names) {
+ // TODO(xians): query a full list of valid devices.
+ if (HasAudioInputDevices()) {
+ // Add the default device to the list.
+ // We use (device_name)_(index) to make up the unique_ids to identify the
+ // devices. For default device, the index is 0, so its unique_id is
+ // Default_0.
+ AudioInputDeviceName name;
+ name.device_name = AudioManagerBase::kDefaultDeviceName;
+ name.unique_id = StringPrintf("%s_0", AudioManagerBase::kDefaultDeviceName);
+ device_names->push_back(name);
+ }
+}
+
// static
AudioManager* AudioManager::CreateAudioManager() {
return new AudioManagerLinux();

Powered by Google App Engine
This is Rietveld 408576698