Chromium Code Reviews| Index: media/audio/mac/audio_output_mac.cc |
| diff --git a/media/audio/mac/audio_output_mac.cc b/media/audio/mac/audio_output_mac.cc |
| index cbc4f9ef90ef490fb0466cafbd4d5c48a6c47e79..98c76986616339b9101417cef5dea9835e6842eb 100644 |
| --- a/media/audio/mac/audio_output_mac.cc |
| +++ b/media/audio/mac/audio_output_mac.cc |
| @@ -96,7 +96,7 @@ void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) { |
| bool PCMQueueOutAudioOutputStream::Open() { |
| // Get the default device id. |
| - unsigned int device_id = 0; |
| + AudioObjectID device_id = 0; |
|
scherkus (not reviewing)
2011/06/07 22:43:22
double checking.. intended change?
annacc
2011/06/07 23:09:45
Yep, acts the same way, just looks prettier.
|
| AudioObjectPropertyAddress property_address = { |
| kAudioHardwarePropertyDefaultOutputDevice, |
| kAudioObjectPropertyScopeGlobal, |
| @@ -112,6 +112,9 @@ bool PCMQueueOutAudioOutputStream::Open() { |
| } |
| // Get the size of the channel layout. |
| UInt32 core_layout_size; |
| + // TODO(annacc): AudioDeviceGetPropertyInfo() is deprecated, but its |
| + // replacement, AudioObjectGetPropertyDataSize(), doesn't work yet with |
| + // kAudioDevicePropertyPreferredChannelLayout. |
| err = AudioDeviceGetPropertyInfo(device_id, 0, false, |
| kAudioDevicePropertyPreferredChannelLayout, |
| &core_layout_size, NULL); |
| @@ -125,6 +128,9 @@ bool PCMQueueOutAudioOutputStream::Open() { |
| core_channel_layout.reset( |
| reinterpret_cast<AudioChannelLayout*>(malloc(core_layout_size))); |
| memset(core_channel_layout.get(), 0, core_layout_size); |
| + // TODO(annacc): AudioDeviceGetProperty() is deprecated, but its |
| + // replacement, AudioObjectGetPropertyData(), doesn't work yet with |
| + // kAudioDevicePropertyPreferredChannelLayout. |
| err = AudioDeviceGetProperty(device_id, 0, false, |
| kAudioDevicePropertyPreferredChannelLayout, |
| &core_layout_size, core_channel_layout.get()); |
| @@ -174,88 +180,104 @@ bool PCMQueueOutAudioOutputStream::Open() { |
| for (int i = 0; i < CHANNELS_MAX; ++i) |
| core_channel_orderings_[i] = kEmptyChannel; |
| + bool allChannelsUnknown = true; |
|
scherkus (not reviewing)
2011/06/07 22:43:22
unix_hacker style: all_channels_unknown
annacc
2011/06/07 23:09:45
Arg, I forget your crazy conventions. :) Thanks.
|
| for (int i = 0; i < num_core_channels_; ++i) { |
| - switch (core_channel_layout->mChannelDescriptions[i].mChannelLabel) { |
| - case kAudioChannelLabel_Left: |
| - core_channel_orderings_[LEFT] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][LEFT]; |
| - break; |
| - case kAudioChannelLabel_Right: |
| - core_channel_orderings_[RIGHT] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][RIGHT]; |
| - break; |
| - case kAudioChannelLabel_Center: |
| - core_channel_orderings_[CENTER] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][CENTER]; |
| - break; |
| - case kAudioChannelLabel_LFEScreen: |
| - core_channel_orderings_[LFE] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][LFE]; |
| - break; |
| - case kAudioChannelLabel_LeftSurround: |
| - core_channel_orderings_[SIDE_LEFT] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][SIDE_LEFT]; |
| - break; |
| - case kAudioChannelLabel_RightSurround: |
| - core_channel_orderings_[SIDE_RIGHT] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][SIDE_RIGHT]; |
| - break; |
| - case kAudioChannelLabel_LeftCenter: |
| - core_channel_orderings_[LEFT_OF_CENTER] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][LEFT_OF_CENTER]; |
| - break; |
| - case kAudioChannelLabel_RightCenter: |
| - core_channel_orderings_[RIGHT_OF_CENTER] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][RIGHT_OF_CENTER]; |
| - break; |
| - case kAudioChannelLabel_CenterSurround: |
| - core_channel_orderings_[BACK_CENTER] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][BACK_CENTER]; |
| - break; |
| - case kAudioChannelLabel_RearSurroundLeft: |
| - core_channel_orderings_[BACK_LEFT] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][BACK_LEFT]; |
| - break; |
| - case kAudioChannelLabel_RearSurroundRight: |
| - core_channel_orderings_[BACK_RIGHT] = i; |
| - channel_remap_[i] = kChannelOrderings[source_layout_][BACK_RIGHT]; |
| - break; |
| - default: |
| - DLOG(WARNING) << "Channel label not supported"; |
| - channel_remap_[i] = kEmptyChannel; |
| - break; |
| + AudioChannelLabel label = |
| + core_channel_layout->mChannelDescriptions[i].mChannelLabel; |
| + if (label != kAudioChannelLabel_Unknown) { |
|
scherkus (not reviewing)
2011/06/07 22:43:22
nit: instead check for opposite condition + contin
annacc
2011/06/07 23:09:45
Done.
|
| + allChannelsUnknown = false; |
| + switch (label) { |
| + case kAudioChannelLabel_Left: |
| + core_channel_orderings_[LEFT] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][LEFT]; |
| + break; |
| + case kAudioChannelLabel_Right: |
| + core_channel_orderings_[RIGHT] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][RIGHT]; |
| + break; |
| + case kAudioChannelLabel_Center: |
| + core_channel_orderings_[CENTER] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][CENTER]; |
| + break; |
| + case kAudioChannelLabel_LFEScreen: |
| + core_channel_orderings_[LFE] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][LFE]; |
| + break; |
| + case kAudioChannelLabel_LeftSurround: |
| + core_channel_orderings_[SIDE_LEFT] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][SIDE_LEFT]; |
| + break; |
| + case kAudioChannelLabel_RightSurround: |
| + core_channel_orderings_[SIDE_RIGHT] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][SIDE_RIGHT]; |
| + break; |
| + case kAudioChannelLabel_LeftCenter: |
| + core_channel_orderings_[LEFT_OF_CENTER] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][LEFT_OF_CENTER]; |
| + break; |
| + case kAudioChannelLabel_RightCenter: |
| + core_channel_orderings_[RIGHT_OF_CENTER] = i; |
| + channel_remap_[i] = |
| + kChannelOrderings[source_layout_][RIGHT_OF_CENTER]; |
| + break; |
| + case kAudioChannelLabel_CenterSurround: |
| + core_channel_orderings_[BACK_CENTER] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][BACK_CENTER]; |
| + break; |
| + case kAudioChannelLabel_RearSurroundLeft: |
| + core_channel_orderings_[BACK_LEFT] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][BACK_LEFT]; |
| + break; |
| + case kAudioChannelLabel_RearSurroundRight: |
| + core_channel_orderings_[BACK_RIGHT] = i; |
| + channel_remap_[i] = kChannelOrderings[source_layout_][BACK_RIGHT]; |
| + break; |
| + case kAudioChannelLabel_Unknown: |
| + channel_remap_[i] = kEmptyChannel; |
| + break; |
| + default: |
| + DLOG(WARNING) << "Channel label not supported"; |
| + channel_remap_[i] = kEmptyChannel; |
| + break; |
| + } |
| } |
| } |
| - // Check if we need to adjust the layout. |
| - // If the device has a BACK_LEFT and no SIDE_LEFT and the source has |
| - // a SIDE_LEFT but no BACK_LEFT, then move (and preserve the channel). |
| - // e.g. CHANNEL_LAYOUT_5POINT1 -> CHANNEL_LAYOUT_5POINT1_BACK |
| - CheckForAdjustedLayout(SIDE_LEFT, BACK_LEFT); |
| - // Same for SIDE_RIGHT -> BACK_RIGHT. |
| - CheckForAdjustedLayout(SIDE_RIGHT, BACK_RIGHT); |
| - // Move BACK_LEFT to SIDE_LEFT. |
| - // e.g. CHANNEL_LAYOUT_5POINT1_BACK -> CHANNEL_LAYOUT_5POINT1 |
| - CheckForAdjustedLayout(BACK_LEFT, SIDE_LEFT); |
| - // Same for BACK_RIGHT -> SIDE_RIGHT. |
| - CheckForAdjustedLayout(BACK_RIGHT, SIDE_RIGHT); |
| - // Move SIDE_LEFT to LEFT_OF_CENTER. |
| - // e.g. CHANNEL_LAYOUT_7POINT1 -> CHANNEL_LAYOUT_7POINT1_WIDE |
| - CheckForAdjustedLayout(SIDE_LEFT, LEFT_OF_CENTER); |
| - // Same for SIDE_RIGHT -> RIGHT_OF_CENTER. |
| - CheckForAdjustedLayout(SIDE_RIGHT, RIGHT_OF_CENTER); |
| - // Move LEFT_OF_CENTER to SIDE_LEFT. |
| - // e.g. CHANNEL_LAYOUT_7POINT1_WIDE -> CHANNEL_LAYOUT_7POINT1 |
| - CheckForAdjustedLayout(LEFT_OF_CENTER, SIDE_LEFT); |
| - // Same for RIGHT_OF_CENTER -> SIDE_RIGHT. |
| - CheckForAdjustedLayout(RIGHT_OF_CENTER, SIDE_RIGHT); |
| - |
| - // Check if we will need to swizzle from source to device layout (maybe not!). |
| + // Check if we need to swizzle or adjust the layout from source to device. |
| should_swizzle_ = false; |
| - for (int i = 0; i < num_core_channels_; ++i) { |
| - if (kChannelOrderings[source_layout_][i] != core_channel_orderings_[i]) { |
| - should_swizzle_ = true; |
| - break; |
| + |
| + if (!allChannelsUnknown) { |
|
scherkus (not reviewing)
2011/06/07 22:43:22
nit: check for opposite condition and return early
annacc
2011/06/07 23:09:45
Done.
|
| + // Check if we need to adjust the layout. |
| + // If the device has a BACK_LEFT and no SIDE_LEFT and the source has |
| + // a SIDE_LEFT but no BACK_LEFT, then move (and preserve the channel). |
| + // e.g. CHANNEL_LAYOUT_5POINT1 -> CHANNEL_LAYOUT_5POINT1_BACK |
| + CheckForAdjustedLayout(SIDE_LEFT, BACK_LEFT); |
| + // Same for SIDE_RIGHT -> BACK_RIGHT. |
| + CheckForAdjustedLayout(SIDE_RIGHT, BACK_RIGHT); |
| + // Move BACK_LEFT to SIDE_LEFT. |
| + // e.g. CHANNEL_LAYOUT_5POINT1_BACK -> CHANNEL_LAYOUT_5POINT1 |
| + CheckForAdjustedLayout(BACK_LEFT, SIDE_LEFT); |
| + // Same for BACK_RIGHT -> SIDE_RIGHT. |
| + CheckForAdjustedLayout(BACK_RIGHT, SIDE_RIGHT); |
| + // Move SIDE_LEFT to LEFT_OF_CENTER. |
| + // e.g. CHANNEL_LAYOUT_7POINT1 -> CHANNEL_LAYOUT_7POINT1_WIDE |
| + CheckForAdjustedLayout(SIDE_LEFT, LEFT_OF_CENTER); |
| + // Same for SIDE_RIGHT -> RIGHT_OF_CENTER. |
| + CheckForAdjustedLayout(SIDE_RIGHT, RIGHT_OF_CENTER); |
| + // Move LEFT_OF_CENTER to SIDE_LEFT. |
| + // e.g. CHANNEL_LAYOUT_7POINT1_WIDE -> CHANNEL_LAYOUT_7POINT1 |
| + CheckForAdjustedLayout(LEFT_OF_CENTER, SIDE_LEFT); |
| + // Same for RIGHT_OF_CENTER -> SIDE_RIGHT. |
| + CheckForAdjustedLayout(RIGHT_OF_CENTER, SIDE_RIGHT); |
| + // For MONO -> STEREO, move audio to LEFT and RIGHT if applicable. |
| + CheckForAdjustedLayout(CENTER, LEFT); |
| + CheckForAdjustedLayout(CENTER, RIGHT); |
| + |
| + for (int i = 0; i < num_core_channels_; ++i) { |
| + if (kChannelOrderings[source_layout_][i] != core_channel_orderings_[i]) { |
| + should_swizzle_ = true; |
| + break; |
| + } |
| } |
| } |