Chromium Code Reviews| 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..6949d14c3c38f6424a1dc133b43f09a3dce24c67 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,56 @@ static void GetAudioDeviceInfo(bool is_input, |
| } |
| } |
| +static AudioDeviceID GetAudioDeviceIdByUId(bool is_input, |
| + const std::string& device_uid) { |
| + AudioObjectPropertyAddress property_address = { |
| + kAudioHardwarePropertyDevices, |
| + kAudioObjectPropertyScopeGlobal, |
| + kAudioObjectPropertyElementMaster |
| + }; |
| + AudioDeviceID audio_device_id = kAudioObjectUnknown; |
| + UInt32 device_size = sizeof(audio_device_id); |
| + OSStatus result = -1; |
| + |
| + if (device_id == AudioManagerBase::kDefaultDeviceId) { |
| + // Default Device. |
| + if (is_input) |
| + property_address.mSelector = kAudioHardwarePropertyDefaultInputDevice; |
|
tommi (sloooow) - chröme
2011/11/17 10:24:16
nit: instead of if/else for this kind of initializ
no longer working on chromium
2011/11/17 14:15:26
Done.
|
| + else |
| + property_address.mSelector = kAudioHardwarePropertyDefaultOutputDevice; |
| + |
| + result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| + &property_address, |
| + 0, |
| + 0, |
| + &device_size, |
| + &audio_device_id); |
| + } else { // Non-default device. |
|
henrika (OOO until Aug 14)
2011/11/17 11:26:15
comment on separate line
no longer working on chromium
2011/11/17 14:15:26
Done.
|
| + base::mac::ScopedCFTypeRef<CFStringRef> |
| + uid(base::SysUTF8ToCFStringRef(device_uid)); |
| + AudioValueTranslation value; |
| + value.mInputData = &uid; |
| + value.mInputDataSize = sizeof(CFStringRef); |
| + value.mOutputData = &audio_device_id; |
| + value.mOutputDataSize = device_size; |
| + UInt32 translation_size = sizeof(AudioValueTranslation); |
| + |
| + property_address.mSelector = kAudioHardwarePropertyDeviceForUID; |
| + result = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
| + &property_address, |
| + 0, //translation_size, |
|
tommi (sloooow) - chröme
2011/11/17 10:24:16
are you going to remove these comments?
no longer working on chromium
2011/11/17 14:15:26
Done.
|
| + 0, //&value, |
| + &translation_size, |
| + &value); |
| + } |
| + |
| + if (result) |
| + DLOG(WARNING) << "Unable to query device " << device_id |
| + << " for AudioDeviceID "; |
|
tommi (sloooow) - chröme
2011/11/17 10:24:16
use {} when the body spans more than one line.
no longer working on chromium
2011/11/17 14:15:26
Done.
|
| + |
| + return audio_device_id; |
| +} |
| + |
| AudioManagerMac::AudioManagerMac() |
| : num_output_streams_(0) { |
| } |
| @@ -211,7 +262,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 +293,7 @@ AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( |
| } |
| AudioInputStream* AudioManagerMac::MakeAudioInputStream( |
| - const AudioParameters& params) { |
| + const AudioParameters& params, const std::string& device_id) { |
| if (!params.IsValid() || (params.channels > kMaxInputChannels)) |
| return NULL; |
| @@ -251,7 +302,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_id); |
|
henrika (OOO until Aug 14)
2011/11/17 11:26:15
Lots of IDs here..
At lest add a comment explainin
no longer working on chromium
2011/11/17 14:15:26
Done.
|
| + if (audio_device_id != kAudioObjectUnknown) |
| + return new AUAudioInputStream(this, params, audio_device_id); |
| } |
| return NULL; |
| } |