| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 for (int i = 0; i < num_core_channels_; ++i) { | 183 for (int i = 0; i < num_core_channels_; ++i) { |
| 184 AudioChannelLabel label = | 184 AudioChannelLabel label = |
| 185 core_channel_layout->mChannelDescriptions[i].mChannelLabel; | 185 core_channel_layout->mChannelDescriptions[i].mChannelLabel; |
| 186 if (label == kAudioChannelLabel_Unknown) { | 186 if (label == kAudioChannelLabel_Unknown) { |
| 187 continue; | 187 continue; |
| 188 } | 188 } |
| 189 all_channels_unknown = false; | 189 all_channels_unknown = false; |
| 190 switch (label) { | 190 switch (label) { |
| 191 case kAudioChannelLabel_Left: | 191 case kAudioChannelLabel_Left: |
| 192 core_channel_orderings_[LEFT] = i; | 192 core_channel_orderings_[LEFT] = i; |
| 193 channel_remap_[i] = kChannelOrderings[source_layout_][LEFT]; | 193 channel_remap_[i] = ChannelOrder(source_layout_, LEFT); |
| 194 break; | 194 break; |
| 195 case kAudioChannelLabel_Right: | 195 case kAudioChannelLabel_Right: |
| 196 core_channel_orderings_[RIGHT] = i; | 196 core_channel_orderings_[RIGHT] = i; |
| 197 channel_remap_[i] = kChannelOrderings[source_layout_][RIGHT]; | 197 channel_remap_[i] = ChannelOrder(source_layout_, RIGHT); |
| 198 break; | 198 break; |
| 199 case kAudioChannelLabel_Center: | 199 case kAudioChannelLabel_Center: |
| 200 core_channel_orderings_[CENTER] = i; | 200 core_channel_orderings_[CENTER] = i; |
| 201 channel_remap_[i] = kChannelOrderings[source_layout_][CENTER]; | 201 channel_remap_[i] = ChannelOrder(source_layout_, CENTER); |
| 202 break; | 202 break; |
| 203 case kAudioChannelLabel_LFEScreen: | 203 case kAudioChannelLabel_LFEScreen: |
| 204 core_channel_orderings_[LFE] = i; | 204 core_channel_orderings_[LFE] = i; |
| 205 channel_remap_[i] = kChannelOrderings[source_layout_][LFE]; | 205 channel_remap_[i] = ChannelOrder(source_layout_, LFE); |
| 206 break; | 206 break; |
| 207 case kAudioChannelLabel_LeftSurround: | 207 case kAudioChannelLabel_LeftSurround: |
| 208 core_channel_orderings_[SIDE_LEFT] = i; | 208 core_channel_orderings_[SIDE_LEFT] = i; |
| 209 channel_remap_[i] = kChannelOrderings[source_layout_][SIDE_LEFT]; | 209 channel_remap_[i] = ChannelOrder(source_layout_, SIDE_LEFT); |
| 210 break; | 210 break; |
| 211 case kAudioChannelLabel_RightSurround: | 211 case kAudioChannelLabel_RightSurround: |
| 212 core_channel_orderings_[SIDE_RIGHT] = i; | 212 core_channel_orderings_[SIDE_RIGHT] = i; |
| 213 channel_remap_[i] = kChannelOrderings[source_layout_][SIDE_RIGHT]; | 213 channel_remap_[i] = ChannelOrder(source_layout_, SIDE_RIGHT); |
| 214 break; | 214 break; |
| 215 case kAudioChannelLabel_LeftCenter: | 215 case kAudioChannelLabel_LeftCenter: |
| 216 core_channel_orderings_[LEFT_OF_CENTER] = i; | 216 core_channel_orderings_[LEFT_OF_CENTER] = i; |
| 217 channel_remap_[i] = kChannelOrderings[source_layout_][LEFT_OF_CENTER]; | 217 channel_remap_[i] = ChannelOrder(source_layout_, LEFT_OF_CENTER); |
| 218 break; | 218 break; |
| 219 case kAudioChannelLabel_RightCenter: | 219 case kAudioChannelLabel_RightCenter: |
| 220 core_channel_orderings_[RIGHT_OF_CENTER] = i; | 220 core_channel_orderings_[RIGHT_OF_CENTER] = i; |
| 221 channel_remap_[i] = kChannelOrderings[source_layout_][RIGHT_OF_CENTER]; | 221 channel_remap_[i] = ChannelOrder(source_layout_, RIGHT_OF_CENTER); |
| 222 break; | 222 break; |
| 223 case kAudioChannelLabel_CenterSurround: | 223 case kAudioChannelLabel_CenterSurround: |
| 224 core_channel_orderings_[BACK_CENTER] = i; | 224 core_channel_orderings_[BACK_CENTER] = i; |
| 225 channel_remap_[i] = kChannelOrderings[source_layout_][BACK_CENTER]; | 225 channel_remap_[i] = ChannelOrder(source_layout_, BACK_CENTER); |
| 226 break; | 226 break; |
| 227 case kAudioChannelLabel_RearSurroundLeft: | 227 case kAudioChannelLabel_RearSurroundLeft: |
| 228 core_channel_orderings_[BACK_LEFT] = i; | 228 core_channel_orderings_[BACK_LEFT] = i; |
| 229 channel_remap_[i] = kChannelOrderings[source_layout_][BACK_LEFT]; | 229 channel_remap_[i] = ChannelOrder(source_layout_, BACK_LEFT); |
| 230 break; | 230 break; |
| 231 case kAudioChannelLabel_RearSurroundRight: | 231 case kAudioChannelLabel_RearSurroundRight: |
| 232 core_channel_orderings_[BACK_RIGHT] = i; | 232 core_channel_orderings_[BACK_RIGHT] = i; |
| 233 channel_remap_[i] = kChannelOrderings[source_layout_][BACK_RIGHT]; | 233 channel_remap_[i] = ChannelOrder(source_layout_, BACK_RIGHT); |
| 234 break; | 234 break; |
| 235 default: | 235 default: |
| 236 DLOG(WARNING) << "Channel label not supported"; | 236 DLOG(WARNING) << "Channel label not supported"; |
| 237 channel_remap_[i] = kEmptyChannel; | 237 channel_remap_[i] = kEmptyChannel; |
| 238 break; | 238 break; |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 if (all_channels_unknown) { | 242 if (all_channels_unknown) { |
| 243 return true; | 243 return true; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 265 CheckForAdjustedLayout(LEFT_OF_CENTER, SIDE_LEFT); | 265 CheckForAdjustedLayout(LEFT_OF_CENTER, SIDE_LEFT); |
| 266 // Same for RIGHT_OF_CENTER -> SIDE_RIGHT. | 266 // Same for RIGHT_OF_CENTER -> SIDE_RIGHT. |
| 267 CheckForAdjustedLayout(RIGHT_OF_CENTER, SIDE_RIGHT); | 267 CheckForAdjustedLayout(RIGHT_OF_CENTER, SIDE_RIGHT); |
| 268 // For MONO -> STEREO, move audio to LEFT and RIGHT if applicable. | 268 // For MONO -> STEREO, move audio to LEFT and RIGHT if applicable. |
| 269 CheckForAdjustedLayout(CENTER, LEFT); | 269 CheckForAdjustedLayout(CENTER, LEFT); |
| 270 CheckForAdjustedLayout(CENTER, RIGHT); | 270 CheckForAdjustedLayout(CENTER, RIGHT); |
| 271 | 271 |
| 272 // Check if we will need to swizzle from source to device layout (maybe not!). | 272 // Check if we will need to swizzle from source to device layout (maybe not!). |
| 273 should_swizzle_ = false; | 273 should_swizzle_ = false; |
| 274 for (int i = 0; i < num_core_channels_; ++i) { | 274 for (int i = 0; i < num_core_channels_; ++i) { |
| 275 if (kChannelOrderings[source_layout_][i] != core_channel_orderings_[i]) { | 275 if (ChannelOrder(source_layout_, i) != core_channel_orderings_[i]) { |
| 276 should_swizzle_ = true; | 276 should_swizzle_ = true; |
| 277 break; | 277 break; |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 return true; | 281 return true; |
| 282 } | 282 } |
| 283 | 283 |
| 284 void PCMQueueOutAudioOutputStream::Close() { | 284 void PCMQueueOutAudioOutputStream::Close() { |
| 285 // It is valid to call Close() before calling Open(), thus audio_queue_ | 285 // It is valid to call Close() before calling Open(), thus audio_queue_ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 bool PCMQueueOutAudioOutputStream::CheckForAdjustedLayout( | 357 bool PCMQueueOutAudioOutputStream::CheckForAdjustedLayout( |
| 358 Channels input_channel, | 358 Channels input_channel, |
| 359 Channels output_channel) { | 359 Channels output_channel) { |
| 360 if (core_channel_orderings_[output_channel] > kEmptyChannel && | 360 if (core_channel_orderings_[output_channel] > kEmptyChannel && |
| 361 core_channel_orderings_[input_channel] == kEmptyChannel && | 361 core_channel_orderings_[input_channel] == kEmptyChannel && |
| 362 kChannelOrderings[source_layout_][input_channel] > kEmptyChannel && | 362 ChannelOrder(source_layout_, input_channel) > kEmptyChannel && |
| 363 kChannelOrderings[source_layout_][output_channel] == kEmptyChannel) { | 363 ChannelOrder(source_layout_, output_channel) == kEmptyChannel) { |
| 364 channel_remap_[core_channel_orderings_[output_channel]] = | 364 channel_remap_[core_channel_orderings_[output_channel]] = |
| 365 kChannelOrderings[source_layout_][input_channel]; | 365 ChannelOrder(source_layout_, input_channel); |
| 366 return true; | 366 return true; |
| 367 } | 367 } |
| 368 return false; | 368 return false; |
| 369 } | 369 } |
| 370 | 370 |
| 371 // Note to future hackers of this function: Do not add locks to this function | 371 // Note to future hackers of this function: Do not add locks to this function |
| 372 // that are held through any calls made back into AudioQueue APIs, or other | 372 // that are held through any calls made back into AudioQueue APIs, or other |
| 373 // OS audio functions. This is because the OS dispatch may grab external | 373 // OS audio functions. This is because the OS dispatch may grab external |
| 374 // locks, or possibly re-enter this function which can lead to a deadlock. | 374 // locks, or possibly re-enter this function which can lead to a deadlock. |
| 375 void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, | 375 void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 source_ = source; | 541 source_ = source; |
| 542 } | 542 } |
| 543 | 543 |
| 544 AudioOutputStream::AudioSourceCallback* | 544 AudioOutputStream::AudioSourceCallback* |
| 545 PCMQueueOutAudioOutputStream::GetSource() { | 545 PCMQueueOutAudioOutputStream::GetSource() { |
| 546 base::AutoLock lock(source_lock_); | 546 base::AutoLock lock(source_lock_); |
| 547 return source_; | 547 return source_; |
| 548 } | 548 } |
| 549 | 549 |
| 550 } // namespace media | 550 } // namespace media |
| OLD | NEW |