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

Unified Diff: media/audio/mac/audio_manager_mac.cc

Issue 8491044: Link things together and enable the device selection for linux and mac. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: fixing unittests Created 9 years, 1 month 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/mac/audio_manager_mac.cc
diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc
index 152375b095641f57fb8abb949de418bd23fe0ba9..49565a4f29c7ee114f11b6336f25d989326b3ae9 100644
--- a/media/audio/mac/audio_manager_mac.cc
+++ b/media/audio/mac/audio_manager_mac.cc
@@ -5,6 +5,7 @@
#include <CoreAudio/AudioHardware.h>
#include "base/mac/mac_util.h"
+#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
#include "media/audio/fake_audio_input_stream.h"
#include "media/audio/fake_audio_output_stream.h"
@@ -182,6 +183,57 @@ static void GetAudioDeviceInfo(bool is_input,
}
}
+static AudioDeviceID GetAudioDeviceIdByUId(bool is_input,
+ const std::string& device_uid) {
+ AudioObjectPropertyAddress property_address = {
+ kAudioHardwarePropertyDevices,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMaster
+ };
+ AudioDeviceID device_id = kAudioObjectUnknown;
+ UInt32 device_size = sizeof(device_id);
+ OSStatus result = -1;
+
+ if ((device_uid == AudioManagerBase::kDefaultDeviceId) ||
+ device_uid.empty()) {
+ // Default Device.
+ if (is_input)
+ property_address.mSelector = kAudioHardwarePropertyDefaultInputDevice;
+ else
+ property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
+
+ result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
+ &property_address,
+ 0,
+ 0,
+ &device_size,
+ &device_id);
+ } else { // Non-default device.
+ base::mac::ScopedCFTypeRef<CFStringRef>
+ uid(base::SysUTF8ToCFStringRef(device_uid));
+ AudioValueTranslation value;
+ value.mInputData = &uid;
+ value.mInputDataSize = sizeof(CFStringRef);
+ value.mOutputData = &device_id;
+ value.mOutputDataSize = device_size;
+ UInt32 translation_size = sizeof(AudioValueTranslation);
+
+ property_address.mSelector = kAudioHardwarePropertyDeviceForUID;
+ result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
+ &property_address,
+ 0, //translation_size,
+ 0, //&value,
+ &translation_size,
+ &value);
+ }
+
+ if (result)
+ DLOG(WARNING) << "Unable to query device " << device_uid
+ << " for AudioDeviceID ";
+
+ return device_id;
+}
+
AudioManagerMac::AudioManagerMac()
: num_output_streams_(0) {
}
@@ -211,7 +263,7 @@ void AudioManagerMac::GetAudioInputDeviceNames(
// counting here since the default device has been abstracted out before.
media::AudioDeviceName name;
name.device_name = AudioManagerBase::kDefaultDeviceName;
- name.unique_id = "0";
+ name.unique_id = AudioManagerBase::kDefaultDeviceId;
device_names->push_front(name);
}
}
@@ -242,7 +294,7 @@ AudioOutputStream* AudioManagerMac::MakeAudioOutputStream(
}
AudioInputStream* AudioManagerMac::MakeAudioInputStream(
- const AudioParameters& params) {
+ const AudioParameters& params, const std::string& device_uid) {
if (!params.IsValid() || (params.channels > kMaxInputChannels))
return NULL;
@@ -251,7 +303,9 @@ AudioInputStream* AudioManagerMac::MakeAudioInputStream(
} else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) {
return new PCMQueueInAudioInputStream(this, params);
} else if (params.format == AudioParameters::AUDIO_PCM_LOW_LATENCY) {
- return new AUAudioInputStream(this, params);
+ AudioDeviceID audio_device_id = GetAudioDeviceIdByUId(true, device_uid);
+ if (audio_device_id != kAudioObjectUnknown)
+ return new AUAudioInputStream(this, params, audio_device_id);
}
return NULL;
}

Powered by Google App Engine
This is Rietveld 408576698