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

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

Issue 12316131: Moved AudioUtil static functions to AudioManager interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/mac/mac_logging.h" 12 #include "base/mac/mac_logging.h"
13 #include "base/mac/scoped_cftyperef.h" 13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "media/audio/audio_util.h" 15 #include "media/audio/audio_parameters.h"
16 #include "media/audio/mac/audio_input_mac.h" 16 #include "media/audio/mac/audio_input_mac.h"
17 #include "media/audio/mac/audio_low_latency_input_mac.h" 17 #include "media/audio/mac/audio_low_latency_input_mac.h"
18 #include "media/audio/mac/audio_low_latency_output_mac.h" 18 #include "media/audio/mac/audio_low_latency_output_mac.h"
19 #include "media/audio/mac/audio_output_mac.h" 19 #include "media/audio/mac/audio_output_mac.h"
20 #include "media/audio/mac/audio_synchronized_mac.h" 20 #include "media/audio/mac/audio_synchronized_mac.h"
21 #include "media/audio/mac/audio_unified_mac.h" 21 #include "media/audio/mac/audio_unified_mac.h"
22 #include "media/base/bind_to_loop.h" 22 #include "media/base/bind_to_loop.h"
23 #include "media/base/channel_layout.h"
23 #include "media/base/limits.h" 24 #include "media/base/limits.h"
24 #include "media/base/media_switches.h" 25 #include "media/base/media_switches.h"
25 26
26 namespace media { 27 namespace media {
27 28
28 // Maximum number of output streams that can be open simultaneously. 29 // Maximum number of output streams that can be open simultaneously.
29 static const int kMaxOutputStreams = 50; 30 static const int kMaxOutputStreams = 50;
30 31
32 // Default buffer size in samples for low-latency input and output streams.
33 static const int kDefaultLowLatencyBufferSize = 128;
34
31 static bool HasAudioHardware(AudioObjectPropertySelector selector) { 35 static bool HasAudioHardware(AudioObjectPropertySelector selector) {
32 AudioDeviceID output_device_id = kAudioObjectUnknown; 36 AudioDeviceID output_device_id = kAudioObjectUnknown;
33 const AudioObjectPropertyAddress property_address = { 37 const AudioObjectPropertyAddress property_address = {
34 selector, 38 selector,
35 kAudioObjectPropertyScopeGlobal, // mScope 39 kAudioObjectPropertyScopeGlobal, // mScope
36 kAudioObjectPropertyElementMaster // mElement 40 kAudioObjectPropertyElementMaster // mElement
37 }; 41 };
38 UInt32 output_device_id_size = static_cast<UInt32>(sizeof(output_device_id)); 42 UInt32 output_device_id_size = static_cast<UInt32>(sizeof(output_device_id));
39 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, 43 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
40 &property_address, 44 &property_address,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Prepend the default device to the list since we always want it to be 270 // Prepend the default device to the list since we always want it to be
267 // on the top of the list for all platforms. There is no duplicate 271 // on the top of the list for all platforms. There is no duplicate
268 // counting here since the default device has been abstracted out before. 272 // counting here since the default device has been abstracted out before.
269 media::AudioDeviceName name; 273 media::AudioDeviceName name;
270 name.device_name = AudioManagerBase::kDefaultDeviceName; 274 name.device_name = AudioManagerBase::kDefaultDeviceName;
271 name.unique_id = AudioManagerBase::kDefaultDeviceId; 275 name.unique_id = AudioManagerBase::kDefaultDeviceId;
272 device_names->push_front(name); 276 device_names->push_front(name);
273 } 277 }
274 } 278 }
275 279
280 AudioParameters AudioManagerMac::GetDefaultOutputStreamParameters() {
281 return AudioParameters(
282 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
283 AUAudioOutputStream::HardwareSampleRate(), 16,
284 kDefaultLowLatencyBufferSize);
285 }
286
287 AudioParameters AudioManagerMac::GetDefaultInputStreamParameters(
288 const std::string& device_id) {
289 // TODO(xians): query the native channel layout for the specific device.
290 return AudioParameters(
291 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
292 AUAudioInputStream::HardwareSampleRate(), 16,
293 kDefaultLowLatencyBufferSize);
294 }
295
276 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream( 296 AudioOutputStream* AudioManagerMac::MakeLinearOutputStream(
277 const AudioParameters& params) { 297 const AudioParameters& params) {
278 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); 298 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
279 return new PCMQueueOutAudioOutputStream(this, params); 299 return new PCMQueueOutAudioOutputStream(this, params);
280 } 300 }
281 301
282 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream( 302 AudioOutputStream* AudioManagerMac::MakeLowLatencyOutputStream(
283 const AudioParameters& params) { 303 const AudioParameters& params) {
284 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 304 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
285 305
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 342 }
323 343
324 AudioParameters AudioManagerMac::GetPreferredLowLatencyOutputStreamParameters( 344 AudioParameters AudioManagerMac::GetPreferredLowLatencyOutputStreamParameters(
325 const AudioParameters& input_params) { 345 const AudioParameters& input_params) {
326 if (CommandLine::ForCurrentProcess()->HasSwitch( 346 if (CommandLine::ForCurrentProcess()->HasSwitch(
327 switches::kEnableWebAudioInput)) { 347 switches::kEnableWebAudioInput)) {
328 // TODO(crogers): given the limitations of the AudioOutputStream 348 // TODO(crogers): given the limitations of the AudioOutputStream
329 // back-ends used with kEnableWebAudioInput, we hard-code to stereo. 349 // back-ends used with kEnableWebAudioInput, we hard-code to stereo.
330 // Specifically, this is a limitation of AudioSynchronizedStream which 350 // Specifically, this is a limitation of AudioSynchronizedStream which
331 // can be removed as part of the work to consolidate these back-ends. 351 // can be removed as part of the work to consolidate these back-ends.
352 AudioParameters default_params = GetDefaultOutputStreamParameters();
332 return AudioParameters( 353 return AudioParameters(
333 AudioParameters::AUDIO_PCM_LOW_LATENCY, 354 AudioParameters::AUDIO_PCM_LOW_LATENCY,
334 CHANNEL_LAYOUT_STEREO, input_params.input_channels(), 355 CHANNEL_LAYOUT_STEREO, input_params.input_channels(),
335 GetAudioHardwareSampleRate(), 16, GetAudioHardwareBufferSize()); 356 default_params.sample_rate(), 16, default_params.frames_per_buffer());
336 } 357 }
337 358
338 return AudioManagerBase::GetPreferredLowLatencyOutputStreamParameters( 359 return AudioManagerBase::GetPreferredLowLatencyOutputStreamParameters(
339 input_params); 360 input_params);
340 } 361 }
341 362
342 void AudioManagerMac::CreateDeviceListener() { 363 void AudioManagerMac::CreateDeviceListener() {
343 DCHECK(GetMessageLoop()->BelongsToCurrentThread()); 364 DCHECK(GetMessageLoop()->BelongsToCurrentThread());
344 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind( 365 output_device_listener_.reset(new AudioDeviceListenerMac(base::Bind(
345 &AudioManagerMac::DelayedDeviceChange, base::Unretained(this)))); 366 &AudioManagerMac::DelayedDeviceChange, base::Unretained(this))));
(...skipping 11 matching lines...) Expand all
357 GetMessageLoop()->PostDelayedTask(FROM_HERE, base::Bind( 378 GetMessageLoop()->PostDelayedTask(FROM_HERE, base::Bind(
358 &AudioManagerMac::NotifyAllOutputDeviceChangeListeners, 379 &AudioManagerMac::NotifyAllOutputDeviceChangeListeners,
359 base::Unretained(this)), base::TimeDelta::FromSeconds(2)); 380 base::Unretained(this)), base::TimeDelta::FromSeconds(2));
360 } 381 }
361 382
362 AudioManager* CreateAudioManager() { 383 AudioManager* CreateAudioManager() {
363 return new AudioManagerMac(); 384 return new AudioManagerMac();
364 } 385 }
365 386
366 } // namespace media 387 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698