| 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_input_mac.h" | 5 #include "media/audio/mac/audio_input_mac.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "base/mac/mac_logging.h" | 10 #include "base/mac/mac_logging.h" |
| 12 #include "media/audio/mac/audio_manager_mac.h" | 11 #include "media/audio/mac/audio_manager_mac.h" |
| 13 #include "media/base/audio_bus.h" | 12 #include "media/base/audio_bus.h" |
| 14 | 13 |
| 15 namespace media { | 14 namespace media { |
| 16 | 15 |
| 17 PCMQueueInAudioInputStream::PCMQueueInAudioInputStream( | 16 PCMQueueInAudioInputStream::PCMQueueInAudioInputStream( |
| 18 AudioManagerMac* manager, | 17 AudioManagerMac* manager, |
| 19 const AudioParameters& params) | 18 const AudioParameters& params) |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // is called too frequently, Sleep() at least 5ms to ensure the shared | 216 // is called too frequently, Sleep() at least 5ms to ensure the shared |
| 218 // memory doesn't get trampled. | 217 // memory doesn't get trampled. |
| 219 // TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going | 218 // TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going |
| 220 // away in favor of the AudioUnit based AUAudioInputStream(). Tracked by | 219 // away in favor of the AudioUnit based AUAudioInputStream(). Tracked by |
| 221 // http://crbug.com/161383. | 220 // http://crbug.com/161383. |
| 222 base::TimeDelta elapsed = base::TimeTicks::Now() - last_fill_; | 221 base::TimeDelta elapsed = base::TimeTicks::Now() - last_fill_; |
| 223 const base::TimeDelta kMinDelay = base::TimeDelta::FromMilliseconds(5); | 222 const base::TimeDelta kMinDelay = base::TimeDelta::FromMilliseconds(5); |
| 224 if (elapsed < kMinDelay) | 223 if (elapsed < kMinDelay) |
| 225 base::PlatformThread::Sleep(kMinDelay - elapsed); | 224 base::PlatformThread::Sleep(kMinDelay - elapsed); |
| 226 | 225 |
| 227 uint8* audio_data = reinterpret_cast<uint8*>(audio_buffer->mAudioData); | 226 uint8_t* audio_data = reinterpret_cast<uint8_t*>(audio_buffer->mAudioData); |
| 228 audio_bus_->FromInterleaved( | 227 audio_bus_->FromInterleaved( |
| 229 audio_data, audio_bus_->frames(), format_.mBitsPerChannel / 8); | 228 audio_data, audio_bus_->frames(), format_.mBitsPerChannel / 8); |
| 230 callback_->OnData( | 229 callback_->OnData( |
| 231 this, audio_bus_.get(), audio_buffer->mAudioDataByteSize, 0.0); | 230 this, audio_bus_.get(), audio_buffer->mAudioDataByteSize, 0.0); |
| 232 | 231 |
| 233 last_fill_ = base::TimeTicks::Now(); | 232 last_fill_ = base::TimeTicks::Now(); |
| 234 } | 233 } |
| 235 // Recycle the buffer. | 234 // Recycle the buffer. |
| 236 OSStatus err = QueueNextBuffer(audio_buffer); | 235 OSStatus err = QueueNextBuffer(audio_buffer); |
| 237 if (err != noErr) { | 236 if (err != noErr) { |
| 238 if (err == kAudioQueueErr_EnqueueDuringReset) { | 237 if (err == kAudioQueueErr_EnqueueDuringReset) { |
| 239 // This is the error you get if you try to enqueue a buffer and the | 238 // This is the error you get if you try to enqueue a buffer and the |
| 240 // queue has been closed. Not really a problem if indeed the queue | 239 // queue has been closed. Not really a problem if indeed the queue |
| 241 // has been closed. | 240 // has been closed. |
| 242 // TODO(joth): PCMQueueOutAudioOutputStream uses callback_ to provide an | 241 // TODO(joth): PCMQueueOutAudioOutputStream uses callback_ to provide an |
| 243 // extra guard for this situation, but it seems to introduce more | 242 // extra guard for this situation, but it seems to introduce more |
| 244 // complications than it solves (memory barrier issues accessing it from | 243 // complications than it solves (memory barrier issues accessing it from |
| 245 // multiple threads, looses the means to indicate OnClosed to client). | 244 // multiple threads, looses the means to indicate OnClosed to client). |
| 246 // Should determine if we need to do something equivalent here. | 245 // Should determine if we need to do something equivalent here. |
| 247 return; | 246 return; |
| 248 } | 247 } |
| 249 HandleError(err); | 248 HandleError(err); |
| 250 } | 249 } |
| 251 } | 250 } |
| 252 | 251 |
| 253 } // namespace media | 252 } // namespace media |
| OLD | NEW |