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

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

Issue 8276034: This patch will loop through the soundcard and return a list of available devices when the AudioI... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 2 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 | « no previous file | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <CoreAudio/AudioHardware.h> 5 #include <CoreAudio/AudioHardware.h>
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #include "media/audio/fake_audio_input_stream.h" 8 #include "media/audio/fake_audio_input_stream.h"
9 #include "media/audio/fake_audio_output_stream.h" 9 #include "media/audio/fake_audio_output_stream.h"
10 #include "media/audio/mac/audio_input_mac.h" 10 #include "media/audio/mac/audio_input_mac.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, 58 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
59 &property_address, 59 &property_address,
60 0, // inQualifierDataSize 60 0, // inQualifierDataSize
61 NULL, // inQualifierData 61 NULL, // inQualifierData
62 &output_device_id_size, 62 &output_device_id_size,
63 &output_device_id); 63 &output_device_id);
64 return err == kAudioHardwareNoError && 64 return err == kAudioHardwareNoError &&
65 output_device_id != kAudioObjectUnknown; 65 output_device_id != kAudioObjectUnknown;
66 } 66 }
67 67
68 static std::string CFStringToSTLString(const CFStringRef cfstr)
Chris Rogers 2011/10/19 01:31:50 I think it would be a lot better to avoid creating
no longer working on chromium 2011/10/19 17:32:18 Done. Thanks for pointing out, it has a API calle
69 {
scherkus (not reviewing) 2011/10/19 17:38:51 { should go on previous line
no longer working on chromium 2011/10/19 18:13:21 The code has been removed.
70 // The method is currently only for kCFStringEncodingUTF8 encoding.
71 CFIndex buf_len = 1 + CFStringGetMaximumSizeForEncoding(
72 CFStringGetLength(cfstr), kCFStringEncodingUTF8);
73 scoped_array<char> buffer(new char[buf_len]);
74 CFStringGetCString(cfstr, buffer.get(), buf_len, kCFStringEncodingUTF8);
75
76 std::string std_string(buffer.get());
77 return std_string;
78 }
79
80 static void GetAudioDeviceInfo(
81 bool is_input, media::AudioDeviceNames* device_names) {
scherkus (not reviewing) 2011/10/19 17:38:51 nit: should go on previous line then align paramet
no longer working on chromium 2011/10/19 18:13:21 Done.
82 CFStringRef uid = NULL;
83 CFStringRef name = NULL;
84 int device_number = 0;
Chris Rogers 2011/10/19 01:31:50 "device_count" is probably a better name than "dev
no longer working on chromium 2011/10/19 17:32:18 Done.
85 UInt32 size = 0;
Chris Rogers 2011/10/19 01:31:50 Please move variables to closest point of usage.
no longer working on chromium 2011/10/19 17:32:18 Done.
86
87 device_names->clear();
Chris Rogers 2011/10/19 01:31:50 Just to be careful, probably best to check "device
no longer working on chromium 2011/10/19 17:32:18 Done.
88
89 // Query the number of total devices.
90 OSStatus result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
91 &size,
92 NULL);
93 if (result)
Chris Rogers 2011/10/19 01:31:50 Can make this simpler: if (result || !size) then
no longer working on chromium 2011/10/19 17:32:18 Done.
94 return;
95
96 device_number = size / sizeof(AudioDeviceID);
97 if (!device_number)
98 return;
99
100 // Get the array of device id for each device.
101 scoped_ptr_malloc<AudioDeviceID>
102 devices(reinterpret_cast<AudioDeviceID*>(malloc(size)));
scherkus (not reviewing) 2011/10/19 17:38:51 I'm curious -- is malloc required?
no longer working on chromium 2011/10/19 18:13:21 That is how the apple sample code looks like, I th
103 AudioDeviceID* device_ids = devices.get();
104 result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
105 &size,
106 device_ids);
107 if (result)
108 return;
109
110 // Iterate each device to gather information.
111 for(int i = 0; i < device_number; ++i) {
Chris Rogers 2011/10/19 01:31:50 nit: space after "for"
no longer working on chromium 2011/10/19 17:32:18 Done.
112 {
113 int channels = 0;
114 // Get the number of input or output channels of the device, exclude
115 // those devices without any right type of channel.
116 AudioDeviceGetPropertyInfo(device_ids[i],
117 0,
118 is_input,
119 kAudioDevicePropertyStreamConfiguration,
120 &size,
121 NULL);
122 scoped_ptr_malloc<AudioBufferList>
123 buffer(reinterpret_cast<AudioBufferList*>(malloc(size)));
124 AudioBufferList* buffer_list = buffer.get();
125 AudioDeviceGetProperty(device_ids[i],
126 0,
127 is_input,
128 kAudioDevicePropertyStreamConfiguration,
129 &size,
130 buffer_list);
131
132 for(uint32 j = 0; j < buffer_list->mNumberBuffers; ++j)
Chris Rogers 2011/10/19 01:31:50 nit: space after "for"
no longer working on chromium 2011/10/19 17:32:18 Done.
133 channels += buffer_list->mBuffers[j].mNumberChannels;
134
135 if (!channels)
136 continue;
137 }
138
139 size = sizeof(uid);
Chris Rogers 2011/10/19 01:31:50 I'd move this line down just below the comment
no longer working on chromium 2011/10/19 17:32:18 Done.
140 // Get device UID.
141 result = AudioDeviceGetProperty(device_ids[i],
142 0,
143 is_input,
144 kAudioDevicePropertyDeviceUID,
145 &size,
146 &uid);
147 if (result)
148 continue;
149
150 // Get device name.
151 result = AudioDeviceGetProperty(device_ids[i],
152 0,
153 is_input,
154 kAudioObjectPropertyName,
155 &size,
156 &name);
157 if (result)
158 continue;
159
160 media::AudioDeviceName device_name;
161 device_name.device_name = CFStringToSTLString(name);
162 device_name.unique_id = CFStringToSTLString(uid);
163 device_names->push_back(device_name);
164 }
165 }
166
68 AudioManagerMac::AudioManagerMac() 167 AudioManagerMac::AudioManagerMac()
69 : num_output_streams_(0) { 168 : num_output_streams_(0) {
70 } 169 }
71 170
72 AudioManagerMac::~AudioManagerMac() { 171 AudioManagerMac::~AudioManagerMac() {
73 } 172 }
74 173
75 bool AudioManagerMac::HasAudioOutputDevices() { 174 bool AudioManagerMac::HasAudioOutputDevices() {
76 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); 175 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice);
77 } 176 }
78 177
79 bool AudioManagerMac::HasAudioInputDevices() { 178 bool AudioManagerMac::HasAudioInputDevices() {
80 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); 179 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice);
81 } 180 }
82 181
83 void AudioManagerMac::GetAudioInputDeviceNames( 182 void AudioManagerMac::GetAudioInputDeviceNames(
84 media::AudioDeviceNames* device_names) { 183 media::AudioDeviceNames* device_names) {
85 // TODO(xians): query a full list of valid devices. 184 GetAudioDeviceInfo(true, device_names);
86 if (HasAudioInputDevices()) { 185 if (!device_names->empty()) {
87 // Add the default device to the list. 186 // Add the default device to the list.
88 // We use index 0 to make up the unique_id to identify the 187 // We use index 0 to make up the unique_id to identify the
89 // default devices. 188 // default devices.
90 media::AudioDeviceName name; 189 media::AudioDeviceName name;
91 name.device_name = AudioManagerBase::kDefaultDeviceName; 190 name.device_name = AudioManagerBase::kDefaultDeviceName;
92 name.unique_id = "0"; 191 name.unique_id = "0";
93 device_names->push_back(name); 192 device_names->push_front(name);
Chris Rogers 2011/10/19 01:31:50 Probably worth a comment to describe why you're pu
no longer working on chromium 2011/10/19 17:32:18 Done.
94 } 193 }
95 } 194 }
96 195
97 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( 196 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream(
98 const AudioParameters& params) { 197 const AudioParameters& params) {
99 if (!params.IsValid()) 198 if (!params.IsValid())
100 return NULL; 199 return NULL;
101 200
102 // Limit the number of audio streams opened. This is to prevent using 201 // Limit the number of audio streams opened. This is to prevent using
103 // excessive resources for a large number of audio streams. More 202 // excessive resources for a large number of audio streams. More
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 250
152 // Called by the stream when it has been released by calling Close(). 251 // Called by the stream when it has been released by calling Close().
153 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { 252 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) {
154 delete stream; 253 delete stream;
155 } 254 }
156 255
157 // static 256 // static
158 AudioManager* AudioManager::CreateAudioManager() { 257 AudioManager* AudioManager::CreateAudioManager() {
159 return new AudioManagerMac(); 258 return new AudioManagerMac();
160 } 259 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698