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

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: update 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 "base/sys_string_conversions.h"
8 #include "media/audio/fake_audio_input_stream.h" 9 #include "media/audio/fake_audio_input_stream.h"
9 #include "media/audio/fake_audio_output_stream.h" 10 #include "media/audio/fake_audio_output_stream.h"
10 #include "media/audio/mac/audio_input_mac.h" 11 #include "media/audio/mac/audio_input_mac.h"
11 #include "media/audio/mac/audio_low_latency_input_mac.h" 12 #include "media/audio/mac/audio_low_latency_input_mac.h"
12 #include "media/audio/mac/audio_low_latency_output_mac.h" 13 #include "media/audio/mac/audio_low_latency_output_mac.h"
13 #include "media/audio/mac/audio_manager_mac.h" 14 #include "media/audio/mac/audio_manager_mac.h"
14 #include "media/audio/mac/audio_output_mac.h" 15 #include "media/audio/mac/audio_output_mac.h"
15 #include "media/base/limits.h" 16 #include "media/base/limits.h"
16 17
17 static const int kMaxInputChannels = 2; 18 static const int kMaxInputChannels = 2;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, 59 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
59 &property_address, 60 &property_address,
60 0, // inQualifierDataSize 61 0, // inQualifierDataSize
61 NULL, // inQualifierData 62 NULL, // inQualifierData
62 &output_device_id_size, 63 &output_device_id_size,
63 &output_device_id); 64 &output_device_id);
64 return err == kAudioHardwareNoError && 65 return err == kAudioHardwareNoError &&
65 output_device_id != kAudioObjectUnknown; 66 output_device_id != kAudioObjectUnknown;
66 } 67 }
67 68
69 static void GetAudioDeviceInfo(
70 bool is_input, media::AudioDeviceNames* device_names) {
scherkus (not reviewing) 2011/10/19 17:38:51 nit: should go on previous line and align paramete
no longer working on chromium 2011/10/19 18:13:21 Done.
71 if (!device_names)
72 return;
73
74 device_names->clear();
75
76 // Query the number of total devices.
77 UInt32 size = 0;
78 OSStatus result = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
79 &size,
80 NULL);
81 if (result || !size)
82 return;
83
84 int device_count = 0;
85 device_count = size / sizeof(AudioDeviceID);
86
87 // Get the array of device id for each device.
88 scoped_ptr_malloc<AudioDeviceID>
89 devices(reinterpret_cast<AudioDeviceID*>(malloc(size)));
90 AudioDeviceID* device_ids = devices.get();
91 result = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
scherkus (not reviewing) 2011/10/19 17:38:51 I'm curious do we need malloc() or does new[] work
no longer working on chromium 2011/10/19 18:13:21 The Apple sample code is using malloc, I am not su
92 &size,
93 device_ids);
94 if (result)
95 return;
96
97 // Iterate each device to gather information.
98 for (int i = 0; i < device_count; ++i) {
99 {
scherkus (not reviewing) 2011/10/19 17:38:51 why do we have the separate scope?
no longer working on chromium 2011/10/19 18:13:21 Because it is in a loop and we need to allocate dy
100 int channels = 0;
101 // Get the number of input or output channels of the device, exclude
102 // those devices without any right type of channel.
103 AudioDeviceGetPropertyInfo(device_ids[i],
104 0,
105 is_input,
106 kAudioDevicePropertyStreamConfiguration,
107 &size,
108 NULL);
109 scoped_ptr_malloc<AudioBufferList>
110 buffer(reinterpret_cast<AudioBufferList*>(malloc(size)));
scherkus (not reviewing) 2011/10/19 17:38:51 ditto
no longer working on chromium 2011/10/19 18:13:21 ditto.
111 AudioBufferList* buffer_list = buffer.get();
112 AudioDeviceGetProperty(device_ids[i],
113 0,
114 is_input,
115 kAudioDevicePropertyStreamConfiguration,
116 &size,
117 buffer_list);
118
119 for (uint32 j = 0; j < buffer_list->mNumberBuffers; ++j)
120 channels += buffer_list->mBuffers[j].mNumberChannels;
121
122 if (!channels)
123 continue;
124 }
125
126 // Get device UID.
127 CFStringRef uid = NULL;
128 size = sizeof(uid);
129 result = AudioDeviceGetProperty(device_ids[i],
130 0,
131 is_input,
132 kAudioDevicePropertyDeviceUID,
133 &size,
134 &uid);
135 if (result)
136 continue;
137
138 // Get device name.
139 CFStringRef name = NULL;
140 result = AudioDeviceGetProperty(device_ids[i],
141 0,
142 is_input,
143 kAudioObjectPropertyName,
144 &size,
145 &name);
146 if (result)
147 continue;
148
149 media::AudioDeviceName device_name;
150 device_name.device_name = base::SysCFStringRefToUTF8(name);
151 device_name.unique_id = base::SysCFStringRefToUTF8(uid);
152 device_names->push_back(device_name);
153 }
154 }
155
68 AudioManagerMac::AudioManagerMac() 156 AudioManagerMac::AudioManagerMac()
69 : num_output_streams_(0) { 157 : num_output_streams_(0) {
70 } 158 }
71 159
72 AudioManagerMac::~AudioManagerMac() { 160 AudioManagerMac::~AudioManagerMac() {
73 } 161 }
74 162
75 bool AudioManagerMac::HasAudioOutputDevices() { 163 bool AudioManagerMac::HasAudioOutputDevices() {
76 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); 164 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice);
77 } 165 }
78 166
79 bool AudioManagerMac::HasAudioInputDevices() { 167 bool AudioManagerMac::HasAudioInputDevices() {
80 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); 168 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice);
81 } 169 }
82 170
83 void AudioManagerMac::GetAudioInputDeviceNames( 171 void AudioManagerMac::GetAudioInputDeviceNames(
84 media::AudioDeviceNames* device_names) { 172 media::AudioDeviceNames* device_names) {
85 // TODO(xians): query a full list of valid devices. 173 GetAudioDeviceInfo(true, device_names);
86 if (HasAudioInputDevices()) { 174 if (!device_names->empty()) {
87 // Add the default device to the list. 175 // Prepend the default device to the list since we always want it to be
88 // We use index 0 to make up the unique_id to identify the 176 // on the top of the list for all platforms. There is no duplicate
89 // default devices. 177 // counting here since the default device has been abstracted out before.
90 media::AudioDeviceName name; 178 media::AudioDeviceName name;
91 name.device_name = AudioManagerBase::kDefaultDeviceName; 179 name.device_name = AudioManagerBase::kDefaultDeviceName;
92 name.unique_id = "0"; 180 name.unique_id = "0";
93 device_names->push_back(name); 181 device_names->push_front(name);
94 } 182 }
95 } 183 }
96 184
97 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( 185 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream(
98 const AudioParameters& params) { 186 const AudioParameters& params) {
99 if (!params.IsValid()) 187 if (!params.IsValid())
100 return NULL; 188 return NULL;
101 189
102 // Limit the number of audio streams opened. This is to prevent using 190 // Limit the number of audio streams opened. This is to prevent using
103 // excessive resources for a large number of audio streams. More 191 // excessive resources for a large number of audio streams. More
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 239
152 // Called by the stream when it has been released by calling Close(). 240 // Called by the stream when it has been released by calling Close().
153 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { 241 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) {
154 delete stream; 242 delete stream;
155 } 243 }
156 244
157 // static 245 // static
158 AudioManager* AudioManager::CreateAudioManager() { 246 AudioManager* AudioManager::CreateAudioManager() {
159 return new AudioManagerMac(); 247 return new AudioManagerMac();
160 } 248 }
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