| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/mac_logging.h" | 9 #include "base/mac/mac_logging.h" |
| 10 #include "media/audio/audio_manager_base.h" | 10 #include "media/audio/audio_manager_base.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 if (audio_buffer->mAudioDataByteSize) { | 190 if (audio_buffer->mAudioDataByteSize) { |
| 191 // The AudioQueue API may use a large internal buffer and repeatedly call us | 191 // The AudioQueue API may use a large internal buffer and repeatedly call us |
| 192 // back to back once that internal buffer is filled. When this happens the | 192 // back to back once that internal buffer is filled. When this happens the |
| 193 // renderer client does not have enough time to read data back from the | 193 // renderer client does not have enough time to read data back from the |
| 194 // shared memory before the next write comes along. If HandleInputBuffer() | 194 // shared memory before the next write comes along. If HandleInputBuffer() |
| 195 // is called too frequently, Sleep() at least 5ms to ensure the shared | 195 // is called too frequently, Sleep() at least 5ms to ensure the shared |
| 196 // memory doesn't get trampled. | 196 // memory doesn't get trampled. |
| 197 // TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going | 197 // TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going |
| 198 // away in favor of the AudioUnit based AUAudioInputStream(). Tracked by | 198 // away in favor of the AudioUnit based AUAudioInputStream(). Tracked by |
| 199 // http://crbug.com/161383. | 199 // http://crbug.com/161383. |
| 200 base::TimeDelta elapsed = base::Time::Now() - last_fill_; | 200 base::TimeDelta elapsed = base::TimeTicks::Now() - last_fill_; |
| 201 const base::TimeDelta kMinDelay = base::TimeDelta::FromMilliseconds(5); | 201 const base::TimeDelta kMinDelay = base::TimeDelta::FromMilliseconds(5); |
| 202 if (elapsed < kMinDelay) | 202 if (elapsed < kMinDelay) |
| 203 base::PlatformThread::Sleep(kMinDelay - elapsed); | 203 base::PlatformThread::Sleep(kMinDelay - elapsed); |
| 204 | 204 |
| 205 callback_->OnData(this, | 205 callback_->OnData(this, |
| 206 reinterpret_cast<const uint8*>(audio_buffer->mAudioData), | 206 reinterpret_cast<const uint8*>(audio_buffer->mAudioData), |
| 207 audio_buffer->mAudioDataByteSize, | 207 audio_buffer->mAudioDataByteSize, |
| 208 audio_buffer->mAudioDataByteSize, | 208 audio_buffer->mAudioDataByteSize, |
| 209 0.0); | 209 0.0); |
| 210 | 210 |
| 211 last_fill_ = base::Time::Now(); | 211 last_fill_ = base::TimeTicks::Now(); |
| 212 } | 212 } |
| 213 // Recycle the buffer. | 213 // Recycle the buffer. |
| 214 OSStatus err = QueueNextBuffer(audio_buffer); | 214 OSStatus err = QueueNextBuffer(audio_buffer); |
| 215 if (err != noErr) { | 215 if (err != noErr) { |
| 216 if (err == kAudioQueueErr_EnqueueDuringReset) { | 216 if (err == kAudioQueueErr_EnqueueDuringReset) { |
| 217 // This is the error you get if you try to enqueue a buffer and the | 217 // This is the error you get if you try to enqueue a buffer and the |
| 218 // queue has been closed. Not really a problem if indeed the queue | 218 // queue has been closed. Not really a problem if indeed the queue |
| 219 // has been closed. | 219 // has been closed. |
| 220 // TODO(joth): PCMQueueOutAudioOutputStream uses callback_ to provide an | 220 // TODO(joth): PCMQueueOutAudioOutputStream uses callback_ to provide an |
| 221 // extra guard for this situation, but it seems to introduce more | 221 // extra guard for this situation, but it seems to introduce more |
| 222 // complications than it solves (memory barrier issues accessing it from | 222 // complications than it solves (memory barrier issues accessing it from |
| 223 // multiple threads, looses the means to indicate OnClosed to client). | 223 // multiple threads, looses the means to indicate OnClosed to client). |
| 224 // Should determine if we need to do something equivalent here. | 224 // Should determine if we need to do something equivalent here. |
| 225 return; | 225 return; |
| 226 } | 226 } |
| 227 HandleError(err); | 227 HandleError(err); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| 231 } // namespace media | 231 } // namespace media |
| OLD | NEW |