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

Side by Side Diff: media/audio/mac/audio_manager_mac.cc

Issue 24072002: Implement GetAudioOutputDeviceNames for Mac OS X. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failures on platforms without output enumeration. Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/mac/audio_manager_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/mac/audio_manager_mac.h" 5 #include "media/audio/mac/audio_manager_mac.h"
6 6
7 #include <CoreAudio/AudioHardware.h> 7 #include <CoreAudio/AudioHardware.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Returns true if the default input device is the same as 74 // Returns true if the default input device is the same as
75 // the default output device. 75 // the default output device.
76 bool AudioManagerMac::HasUnifiedDefaultIO() { 76 bool AudioManagerMac::HasUnifiedDefaultIO() {
77 AudioDeviceID input_id, output_id; 77 AudioDeviceID input_id, output_id;
78 if (!GetDefaultInputDevice(&input_id) || !GetDefaultOutputDevice(&output_id)) 78 if (!GetDefaultInputDevice(&input_id) || !GetDefaultOutputDevice(&output_id))
79 return false; 79 return false;
80 80
81 return input_id == output_id; 81 return input_id == output_id;
82 } 82 }
83 83
84 // Retrieves information on audio devices, and prepends the default
85 // device to the list if the list is non-empty.
84 static void GetAudioDeviceInfo(bool is_input, 86 static void GetAudioDeviceInfo(bool is_input,
85 media::AudioDeviceNames* device_names) { 87 media::AudioDeviceNames* device_names) {
86 // Query the number of total devices. 88 // Query the number of total devices.
87 AudioObjectPropertyAddress property_address = { 89 AudioObjectPropertyAddress property_address = {
88 kAudioHardwarePropertyDevices, 90 kAudioHardwarePropertyDevices,
89 kAudioObjectPropertyScopeGlobal, 91 kAudioObjectPropertyScopeGlobal,
90 kAudioObjectPropertyElementMaster 92 kAudioObjectPropertyElementMaster
91 }; 93 };
92 UInt32 size = 0; 94 UInt32 size = 0;
93 OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, 95 OSStatus result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 device_names->push_back(device_name); 168 device_names->push_back(device_name);
167 169
168 // We are responsible for releasing the returned CFObject. See the 170 // We are responsible for releasing the returned CFObject. See the
169 // comment in the AudioHardware.h for constant 171 // comment in the AudioHardware.h for constant
170 // kAudioDevicePropertyDeviceUID. 172 // kAudioDevicePropertyDeviceUID.
171 if (uid) 173 if (uid)
172 CFRelease(uid); 174 CFRelease(uid);
173 if (name) 175 if (name)
174 CFRelease(name); 176 CFRelease(name);
175 } 177 }
178
179 if (!device_names->empty()) {
180 // Prepend the default device to the list since we always want it to be
181 // on the top of the list for all platforms. There is no duplicate
182 // counting here since the default device has been abstracted out before.
183 media::AudioDeviceName name;
184 name.device_name = AudioManagerBase::kDefaultDeviceName;
185 name.unique_id = AudioManagerBase::kDefaultDeviceId;
tommi (sloooow) - chröme 2013/09/09 16:09:23 nit: one space after =
Jói 2013/09/09 16:15:44 Done.
186 device_names->push_front(name);
187 }
176 } 188 }
177 189
178 static AudioDeviceID GetAudioDeviceIdByUId(bool is_input, 190 static AudioDeviceID GetAudioDeviceIdByUId(bool is_input,
179 const std::string& device_id) { 191 const std::string& device_id) {
180 AudioObjectPropertyAddress property_address = { 192 AudioObjectPropertyAddress property_address = {
181 kAudioHardwarePropertyDevices, 193 kAudioHardwarePropertyDevices,
182 kAudioObjectPropertyScopeGlobal, 194 kAudioObjectPropertyScopeGlobal,
183 kAudioObjectPropertyElementMaster 195 kAudioObjectPropertyElementMaster
184 }; 196 };
185 AudioDeviceID audio_device_id = kAudioObjectUnknown; 197 AudioDeviceID audio_device_id = kAudioObjectUnknown;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 if (!GetDefaultOutputDevice(&device_id)) 401 if (!GetDefaultOutputDevice(&device_id))
390 return kFallbackSampleRate; 402 return kFallbackSampleRate;
391 403
392 return HardwareSampleRateForDevice(device_id); 404 return HardwareSampleRateForDevice(device_id);
393 } 405 }
394 406
395 void AudioManagerMac::GetAudioInputDeviceNames( 407 void AudioManagerMac::GetAudioInputDeviceNames(
396 media::AudioDeviceNames* device_names) { 408 media::AudioDeviceNames* device_names) {
397 DCHECK(device_names->empty()); 409 DCHECK(device_names->empty());
398 GetAudioDeviceInfo(true, device_names); 410 GetAudioDeviceInfo(true, device_names);
399 if (!device_names->empty()) { 411 }
400 // Prepend the default device to the list since we always want it to be 412
401 // on the top of the list for all platforms. There is no duplicate 413 void AudioManagerMac::GetAudioOutputDeviceNames(
402 // counting here since the default device has been abstracted out before. 414 media::AudioDeviceNames* device_names) {
403 media::AudioDeviceName name; 415 DCHECK(device_names->empty());
404 name.device_name = AudioManagerBase::kDefaultDeviceName; 416 GetAudioDeviceInfo(false, device_names);
405 name.unique_id = AudioManagerBase::kDefaultDeviceId;
406 device_names->push_front(name);
407 }
408 } 417 }
409 418
410 AudioParameters AudioManagerMac::GetInputStreamParameters( 419 AudioParameters AudioManagerMac::GetInputStreamParameters(
411 const std::string& device_id) { 420 const std::string& device_id) {
412 // Due to the sharing of the input and output buffer sizes, we need to choose 421 // Due to the sharing of the input and output buffer sizes, we need to choose
413 // the input buffer size based on the output sample rate. See 422 // the input buffer size based on the output sample rate. See
414 // http://crbug.com/154352. 423 // http://crbug.com/154352.
415 const int buffer_size = ChooseBufferSize( 424 const int buffer_size = ChooseBufferSize(
416 AUAudioOutputStream::HardwareSampleRate()); 425 AUAudioOutputStream::HardwareSampleRate());
417 426
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 current_sample_rate_ = new_sample_rate; 614 current_sample_rate_ = new_sample_rate;
606 current_output_device_ = new_output_device; 615 current_output_device_ = new_output_device;
607 NotifyAllOutputDeviceChangeListeners(); 616 NotifyAllOutputDeviceChangeListeners();
608 } 617 }
609 618
610 AudioManager* CreateAudioManager() { 619 AudioManager* CreateAudioManager() {
611 return new AudioManagerMac(); 620 return new AudioManagerMac();
612 } 621 }
613 622
614 } // namespace media 623 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/audio_manager_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698