OLD | NEW |
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_output_mac.h" | 5 #include "media/audio/mac/audio_output_mac.h" |
6 | 6 |
7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 UInt32 device_id_size = sizeof(device_id); | 108 UInt32 device_id_size = sizeof(device_id); |
109 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, | 109 OSStatus err = AudioObjectGetPropertyData(kAudioObjectSystemObject, |
110 &property_address, 0, NULL, | 110 &property_address, 0, NULL, |
111 &device_id_size, &device_id); | 111 &device_id_size, &device_id); |
112 if (err != noErr) { | 112 if (err != noErr) { |
113 HandleError(err); | 113 HandleError(err); |
114 return false; | 114 return false; |
115 } | 115 } |
116 // Get the size of the channel layout. | 116 // Get the size of the channel layout. |
117 UInt32 core_layout_size; | 117 UInt32 core_layout_size; |
118 // TODO(annacc): AudioDeviceGetPropertyInfo() is deprecated, but its | 118 property_address.mSelector = kAudioDevicePropertyPreferredChannelLayout; |
119 // replacement, AudioObjectGetPropertyDataSize(), doesn't work yet with | 119 property_address.mScope = kAudioDevicePropertyScopeOutput; |
120 // kAudioDevicePropertyPreferredChannelLayout. | 120 err = AudioObjectGetPropertyDataSize(device_id, &property_address, 0, NULL, |
121 #pragma clang diagnostic push | 121 &core_layout_size); |
122 #pragma clang diagnostic ignored "-Wdeprecated-declarations" | |
123 err = AudioDeviceGetPropertyInfo(device_id, 0, false, | |
124 kAudioDevicePropertyPreferredChannelLayout, | |
125 &core_layout_size, NULL); | |
126 if (err != noErr) { | 122 if (err != noErr) { |
127 HandleError(err); | 123 HandleError(err); |
128 return false; | 124 return false; |
129 } | 125 } |
130 // Get the device's channel layout. This layout may vary in sized based on | 126 // Get the device's channel layout. This layout may vary in sized based on |
131 // the number of channels. Use |core_layout_size| to allocate memory. | 127 // the number of channels. Use |core_layout_size| to allocate memory. |
132 scoped_ptr_malloc<AudioChannelLayout> core_channel_layout; | 128 scoped_ptr_malloc<AudioChannelLayout> core_channel_layout; |
133 core_channel_layout.reset( | 129 core_channel_layout.reset( |
134 reinterpret_cast<AudioChannelLayout*>(malloc(core_layout_size))); | 130 reinterpret_cast<AudioChannelLayout*>(malloc(core_layout_size))); |
135 memset(core_channel_layout.get(), 0, core_layout_size); | 131 memset(core_channel_layout.get(), 0, core_layout_size); |
136 // TODO(annacc): AudioDeviceGetProperty() is deprecated, but its | 132 err = AudioObjectGetPropertyData(device_id, &property_address, 0, NULL, |
137 // replacement, AudioObjectGetPropertyData(), doesn't work yet with | 133 &core_layout_size, |
138 // kAudioDevicePropertyPreferredChannelLayout. | 134 core_channel_layout.get()); |
139 err = AudioDeviceGetProperty(device_id, 0, false, | |
140 kAudioDevicePropertyPreferredChannelLayout, | |
141 &core_layout_size, core_channel_layout.get()); | |
142 if (err != noErr) { | 135 if (err != noErr) { |
143 HandleError(err); | 136 HandleError(err); |
144 return false; | 137 return false; |
145 } | 138 } |
146 #pragma clang diagnostic pop | |
147 | 139 |
148 num_core_channels_ = | 140 num_core_channels_ = |
149 static_cast<int>(core_channel_layout->mNumberChannelDescriptions); | 141 static_cast<int>(core_channel_layout->mNumberChannelDescriptions); |
150 if (num_core_channels_ == 2 && | 142 if (num_core_channels_ == 2 && |
151 ChannelLayoutToChannelCount(source_layout_) > 2) { | 143 ChannelLayoutToChannelCount(source_layout_) > 2) { |
152 should_down_mix_ = true; | 144 should_down_mix_ = true; |
153 format_.mChannelsPerFrame = num_core_channels_; | 145 format_.mChannelsPerFrame = num_core_channels_; |
154 format_.mBytesPerFrame = (format_.mBitsPerChannel >> 3) * | 146 format_.mBytesPerFrame = (format_.mBitsPerChannel >> 3) * |
155 format_.mChannelsPerFrame; | 147 format_.mChannelsPerFrame; |
156 format_.mBytesPerPacket = format_.mBytesPerFrame * format_.mFramesPerPacket; | 148 format_.mBytesPerPacket = format_.mBytesPerFrame * format_.mFramesPerPacket; |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 source_ = source; | 531 source_ = source; |
540 } | 532 } |
541 | 533 |
542 AudioOutputStream::AudioSourceCallback* | 534 AudioOutputStream::AudioSourceCallback* |
543 PCMQueueOutAudioOutputStream::GetSource() { | 535 PCMQueueOutAudioOutputStream::GetSource() { |
544 base::AutoLock lock(source_lock_); | 536 base::AutoLock lock(source_lock_); |
545 return source_; | 537 return source_; |
546 } | 538 } |
547 | 539 |
548 } // namespace media | 540 } // namespace media |
OLD | NEW |