OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "media/audio/fake_audio_input_stream.h" | 7 #include "media/audio/fake_audio_input_stream.h" |
8 #include "media/audio/fake_audio_output_stream.h" | 8 #include "media/audio/fake_audio_output_stream.h" |
9 #include "media/audio/mac/audio_input_mac.h" | 9 #include "media/audio/mac/audio_input_mac.h" |
10 #include "media/audio/mac/audio_manager_mac.h" | 10 #include "media/audio/mac/audio_manager_mac.h" |
11 #include "media/audio/mac/audio_output_mac.h" | 11 #include "media/audio/mac/audio_output_mac.h" |
12 #include "media/base/limits.h" | 12 #include "media/base/limits.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 const int kMaxInputChannels = 2; | 15 const int kMaxInputChannels = 2; |
16 const int kMaxSamplesPerPacket = media::Limits::kMaxSampleRate; | |
17 | 16 |
18 bool HasAudioHardware(AudioObjectPropertySelector selector) { | 17 bool HasAudioHardware(AudioObjectPropertySelector selector) { |
19 AudioDeviceID output_device_id = kAudioObjectUnknown; | 18 AudioDeviceID output_device_id = kAudioObjectUnknown; |
20 const AudioObjectPropertyAddress property_address = { | 19 const AudioObjectPropertyAddress property_address = { |
21 selector, | 20 selector, |
22 kAudioObjectPropertyScopeGlobal, // mScope | 21 kAudioObjectPropertyScopeGlobal, // mScope |
23 kAudioObjectPropertyElementMaster // mElement | 22 kAudioObjectPropertyElementMaster // mElement |
24 }; | 23 }; |
25 size_t output_device_id_size = sizeof(output_device_id); | 24 size_t output_device_id_size = sizeof(output_device_id); |
26 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 25 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
(...skipping 11 matching lines...) Expand all Loading... |
38 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 37 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
39 } | 38 } |
40 | 39 |
41 bool AudioManagerMac::HasAudioInputDevices() { | 40 bool AudioManagerMac::HasAudioInputDevices() { |
42 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); | 41 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); |
43 } | 42 } |
44 | 43 |
45 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( | 44 AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( |
46 AudioParameters params) { | 45 AudioParameters params) { |
47 if (params.format == AudioParameters::AUDIO_MOCK) | 46 if (params.format == AudioParameters::AUDIO_MOCK) |
48 return FakeAudioOutputStream::MakeFakeStream(); | 47 return FakeAudioOutputStream::MakeFakeStream(params); |
49 else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) | 48 else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) |
50 return NULL; | 49 return NULL; |
51 return new PCMQueueOutAudioOutputStream(this, params); | 50 return new PCMQueueOutAudioOutputStream(this, params); |
52 } | 51 } |
53 | 52 |
54 AudioInputStream* AudioManagerMac::MakeAudioInputStream( | 53 AudioInputStream* AudioManagerMac::MakeAudioInputStream( |
55 AudioParameters params, int samples_per_packet) { | 54 AudioParameters params) { |
56 if (!params.IsValid() || (params.channels > kMaxInputChannels) || | 55 if (!params.IsValid() || (params.channels > kMaxInputChannels)) |
57 (samples_per_packet > kMaxSamplesPerPacket) || (samples_per_packet < 0)) | |
58 return NULL; | 56 return NULL; |
59 | 57 |
60 if (params.format == AudioParameters::AUDIO_MOCK) { | 58 if (params.format == AudioParameters::AUDIO_MOCK) { |
61 return FakeAudioInputStream::MakeFakeStream(params, samples_per_packet); | 59 return FakeAudioInputStream::MakeFakeStream(params); |
62 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { | 60 } else if (params.format == AudioParameters::AUDIO_PCM_LINEAR) { |
63 return new PCMQueueInAudioInputStream(this, params, samples_per_packet); | 61 return new PCMQueueInAudioInputStream(this, params); |
64 } | 62 } |
65 return NULL; | 63 return NULL; |
66 } | 64 } |
67 | 65 |
68 void AudioManagerMac::MuteAll() { | 66 void AudioManagerMac::MuteAll() { |
69 // TODO(cpu): implement. | 67 // TODO(cpu): implement. |
70 } | 68 } |
71 | 69 |
72 void AudioManagerMac::UnMuteAll() { | 70 void AudioManagerMac::UnMuteAll() { |
73 // TODO(cpu): implement. | 71 // TODO(cpu): implement. |
74 } | 72 } |
75 | 73 |
76 // Called by the stream when it has been released by calling Close(). | 74 // Called by the stream when it has been released by calling Close(). |
77 void AudioManagerMac::ReleaseOutputStream( | 75 void AudioManagerMac::ReleaseOutputStream( |
78 PCMQueueOutAudioOutputStream* stream) { | 76 PCMQueueOutAudioOutputStream* stream) { |
79 delete stream; | 77 delete stream; |
80 } | 78 } |
81 | 79 |
82 // Called by the stream when it has been released by calling Close(). | 80 // Called by the stream when it has been released by calling Close(). |
83 void AudioManagerMac::ReleaseInputStream(PCMQueueInAudioInputStream* stream) { | 81 void AudioManagerMac::ReleaseInputStream(PCMQueueInAudioInputStream* stream) { |
84 delete stream; | 82 delete stream; |
85 } | 83 } |
86 | 84 |
87 // static | 85 // static |
88 AudioManager* AudioManager::CreateAudioManager() { | 86 AudioManager* AudioManager::CreateAudioManager() { |
89 return new AudioManagerMac(); | 87 return new AudioManagerMac(); |
90 } | 88 } |
OLD | NEW |