| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "media/audio/mac/audio_output_mac.h" | 6 #include "media/audio/mac/audio_output_mac.h" |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/audio/audio_util.h" | 10 #include "media/audio/audio_util.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void PCMQueueOutAudioOutputStream::GetVolume(double* left_level, | 162 void PCMQueueOutAudioOutputStream::GetVolume(double* left_level, |
| 163 double* right_level) { | 163 double* right_level) { |
| 164 if (!audio_queue_) | 164 if (!audio_queue_) |
| 165 return; | 165 return; |
| 166 *left_level = volume_; | 166 *left_level = volume_; |
| 167 *right_level = volume_; | 167 *right_level = volume_; |
| 168 } | 168 } |
| 169 | 169 |
| 170 // Reorder PCM from AAC layout to Core Audio layout. | 170 // Reorder PCM from AAC layout to Core Audio layout. |
| 171 // TODO(fbarchard): Switch layout when ffmpeg is updated. | 171 // TODO(fbarchard): Switch layout when ffmpeg is updated. |
| 172 const int kNumSurroundChannels = 6; | 172 namespace { |
| 173 template<class Format> | 173 template<class Format> |
| 174 static void SwizzleLayout(Format *b, size_t filled) { | 174 static void SwizzleLayout(Format *b, size_t filled) { |
| 175 static const int kNumSurroundChannels = 6; |
| 175 Format aac[kNumSurroundChannels]; | 176 Format aac[kNumSurroundChannels]; |
| 176 for (size_t i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { | 177 for (size_t i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { |
| 177 memcpy(aac, b, sizeof(aac)); | 178 memcpy(aac, b, sizeof(aac)); |
| 178 b[0] = aac[1]; // L | 179 b[0] = aac[1]; // L |
| 179 b[1] = aac[2]; // R | 180 b[1] = aac[2]; // R |
| 180 b[2] = aac[0]; // C | 181 b[2] = aac[0]; // C |
| 181 b[3] = aac[5]; // LFE | 182 b[3] = aac[5]; // LFE |
| 182 b[4] = aac[3]; // Ls | 183 b[4] = aac[3]; // Ls |
| 183 b[5] = aac[4]; // Rs | 184 b[5] = aac[4]; // Rs |
| 184 } | 185 } |
| 185 } | 186 } |
| 187 } // namespace |
| 186 | 188 |
| 187 // Note to future hackers of this function: Do not add locks here because we | 189 // Note to future hackers of this function: Do not add locks here because we |
| 188 // call out to third party source that might do crazy things including adquire | 190 // call out to third party source that might do crazy things including adquire |
| 189 // external locks or somehow re-enter here because its legal for them to call | 191 // external locks or somehow re-enter here because its legal for them to call |
| 190 // some audio functions. | 192 // some audio functions. |
| 191 void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, | 193 void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, |
| 192 AudioQueueRef queue, | 194 AudioQueueRef queue, |
| 193 AudioQueueBufferRef buffer) { | 195 AudioQueueBufferRef buffer) { |
| 194 PCMQueueOutAudioOutputStream* audio_stream = | 196 PCMQueueOutAudioOutputStream* audio_stream = |
| 195 static_cast<PCMQueueOutAudioOutputStream*>(p_this); | 197 static_cast<PCMQueueOutAudioOutputStream*>(p_this); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 211 if (!filled) { | 213 if (!filled) { |
| 212 CHECK(audio_stream->silence_bytes_ <= static_cast<int>(capacity)); | 214 CHECK(audio_stream->silence_bytes_ <= static_cast<int>(capacity)); |
| 213 filled = audio_stream->silence_bytes_; | 215 filled = audio_stream->silence_bytes_; |
| 214 memset(buffer->mAudioData, 0, filled); | 216 memset(buffer->mAudioData, 0, filled); |
| 215 } else if (filled > capacity) { | 217 } else if (filled > capacity) { |
| 216 // User probably overran our buffer. | 218 // User probably overran our buffer. |
| 217 audio_stream->HandleError(0); | 219 audio_stream->HandleError(0); |
| 218 return; | 220 return; |
| 219 } | 221 } |
| 220 | 222 |
| 221 // Handle channel order for PCM 5.1 audio. | 223 // Handle channel order for 5.1 audio. |
| 222 if (audio_stream->format_.mChannelsPerFrame == 6) { | 224 if (audio_stream->format_.mChannelsPerFrame == 6) { |
| 223 if (audio_stream->format_.mBitsPerChannel == 8) { | 225 if (audio_stream->format_.mBitsPerChannel == 8) { |
| 224 SwizzleLayout(reinterpret_cast<uint8*>(buffer->mAudioData), filled); | 226 SwizzleLayout(reinterpret_cast<uint8*>(buffer->mAudioData), filled); |
| 225 } else if (audio_stream->format_.mBitsPerChannel == 16) { | 227 } else if (audio_stream->format_.mBitsPerChannel == 16) { |
| 226 SwizzleLayout(reinterpret_cast<int16*>(buffer->mAudioData), filled); | 228 SwizzleLayout(reinterpret_cast<int16*>(buffer->mAudioData), filled); |
| 227 } else if (audio_stream->format_.mBitsPerChannel == 32) { | 229 } else if (audio_stream->format_.mBitsPerChannel == 32) { |
| 228 SwizzleLayout(reinterpret_cast<int32*>(buffer->mAudioData), filled); | 230 SwizzleLayout(reinterpret_cast<int32*>(buffer->mAudioData), filled); |
| 229 } | 231 } |
| 230 } | 232 } |
| 231 | 233 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 return; | 268 return; |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 err = AudioQueueStart(audio_queue_, NULL); | 271 err = AudioQueueStart(audio_queue_, NULL); |
| 270 if (err != noErr) { | 272 if (err != noErr) { |
| 271 HandleError(err); | 273 HandleError(err); |
| 272 return; | 274 return; |
| 273 } | 275 } |
| 274 } | 276 } |
| 275 | 277 |
| OLD | NEW |