| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "media/audio/audio_util.h" | 9 #include "media/audio/audio_util.h" |
| 10 #include "media/audio/mac/audio_manager_mac.h" | 10 #include "media/audio/mac/audio_manager_mac.h" |
| 11 | 11 |
| 12 namespace { | |
| 13 | |
| 14 // A custom data structure to store information an AudioQueue buffer. | 12 // A custom data structure to store information an AudioQueue buffer. |
| 15 struct AudioQueueUserData { | 13 struct AudioQueueUserData { |
| 16 AudioQueueUserData() : empty_buffer(false) {} | 14 AudioQueueUserData() : empty_buffer(false) {} |
| 17 bool empty_buffer; | 15 bool empty_buffer; |
| 18 }; | 16 }; |
| 19 | 17 |
| 20 } // namespace | |
| 21 | |
| 22 // Overview of operation: | 18 // Overview of operation: |
| 23 // 1) An object of PCMQueueOutAudioOutputStream is created by the AudioManager | 19 // 1) An object of PCMQueueOutAudioOutputStream is created by the AudioManager |
| 24 // factory: audio_man->MakeAudioStream(). This just fills some structure. | 20 // factory: audio_man->MakeAudioStream(). This just fills some structure. |
| 25 // 2) Next some thread will call Open(), at that point the underliying OS | 21 // 2) Next some thread will call Open(), at that point the underliying OS |
| 26 // queue is created and the audio buffers allocated. | 22 // queue is created and the audio buffers allocated. |
| 27 // 3) Then some thread will call Start(source) At this point the source will be | 23 // 3) Then some thread will call Start(source) At this point the source will be |
| 28 // called to fill the initial buffers in the context of that same thread. | 24 // called to fill the initial buffers in the context of that same thread. |
| 29 // Then the OS queue is started which will create its own thread which | 25 // Then the OS queue is started which will create its own thread which |
| 30 // periodically will call the source for more data as buffers are being | 26 // periodically will call the source for more data as buffers are being |
| 31 // consumed. | 27 // consumed. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 167 } |
| 172 | 168 |
| 173 void PCMQueueOutAudioOutputStream::GetVolume(double* volume) { | 169 void PCMQueueOutAudioOutputStream::GetVolume(double* volume) { |
| 174 if (!audio_queue_) | 170 if (!audio_queue_) |
| 175 return; | 171 return; |
| 176 *volume = volume_; | 172 *volume = volume_; |
| 177 } | 173 } |
| 178 | 174 |
| 179 // Reorder PCM from AAC layout to Core Audio layout. | 175 // Reorder PCM from AAC layout to Core Audio layout. |
| 180 // TODO(fbarchard): Switch layout when ffmpeg is updated. | 176 // TODO(fbarchard): Switch layout when ffmpeg is updated. |
| 181 namespace { | |
| 182 template<class Format> | 177 template<class Format> |
| 183 static void SwizzleLayout(Format* b, uint32 filled) { | 178 static void SwizzleLayout(Format* b, uint32 filled) { |
| 184 static const int kNumSurroundChannels = 6; | 179 static const int kNumSurroundChannels = 6; |
| 185 Format aac[kNumSurroundChannels]; | 180 Format aac[kNumSurroundChannels]; |
| 186 for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { | 181 for (uint32 i = 0; i < filled; i += sizeof(aac), b += kNumSurroundChannels) { |
| 187 memcpy(aac, b, sizeof(aac)); | 182 memcpy(aac, b, sizeof(aac)); |
| 188 b[0] = aac[1]; // L | 183 b[0] = aac[1]; // L |
| 189 b[1] = aac[2]; // R | 184 b[1] = aac[2]; // R |
| 190 b[2] = aac[0]; // C | 185 b[2] = aac[0]; // C |
| 191 b[3] = aac[5]; // LFE | 186 b[3] = aac[5]; // LFE |
| 192 b[4] = aac[3]; // Ls | 187 b[4] = aac[3]; // Ls |
| 193 b[5] = aac[4]; // Rs | 188 b[5] = aac[4]; // Rs |
| 194 } | 189 } |
| 195 } | 190 } |
| 196 } // namespace | |
| 197 | 191 |
| 198 // Note to future hackers of this function: Do not add locks here because we | 192 // Note to future hackers of this function: Do not add locks here because we |
| 199 // call out to third party source that might do crazy things including adquire | 193 // call out to third party source that might do crazy things including adquire |
| 200 // external locks or somehow re-enter here because its legal for them to call | 194 // external locks or somehow re-enter here because its legal for them to call |
| 201 // some audio functions. | 195 // some audio functions. |
| 202 void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, | 196 void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this, |
| 203 AudioQueueRef queue, | 197 AudioQueueRef queue, |
| 204 AudioQueueBufferRef buffer) { | 198 AudioQueueBufferRef buffer) { |
| 205 PCMQueueOutAudioOutputStream* audio_stream = | 199 PCMQueueOutAudioOutputStream* audio_stream = |
| 206 static_cast<PCMQueueOutAudioOutputStream*>(p_this); | 200 static_cast<PCMQueueOutAudioOutputStream*>(p_this); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 HandleError(err); | 280 HandleError(err); |
| 287 return; | 281 return; |
| 288 } | 282 } |
| 289 } | 283 } |
| 290 err = AudioQueueStart(audio_queue_, NULL); | 284 err = AudioQueueStart(audio_queue_, NULL); |
| 291 if (err != noErr) { | 285 if (err != noErr) { |
| 292 HandleError(err); | 286 HandleError(err); |
| 293 return; | 287 return; |
| 294 } | 288 } |
| 295 } | 289 } |
| OLD | NEW |