Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Unified Diff: media/audio/mac/audio_input_mac.cc

Issue 12062002: Limit OnData() callbacks to every 5ms for mac audio input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/mac/audio_input_mac.cc
diff --git a/media/audio/mac/audio_input_mac.cc b/media/audio/mac/audio_input_mac.cc
index 69791cf11c6d65d7e07ed1fc67036d9e6fc8c6c7..e741b29617540a3fe0278586be9fcd78dbe7b289 100644
--- a/media/audio/mac/audio_input_mac.cc
+++ b/media/audio/mac/audio_input_mac.cc
@@ -197,17 +197,15 @@ void PCMQueueInAudioInputStream::HandleInputBuffer(
// back to back once that internal buffer is filled. When this happens the
// renderer client does not have enough time to read data back from the
// shared memory before the next write comes along. If HandleInputBuffer()
- // is called too frequently, Sleep() to simulate realtime input and ensure
- // the shared memory doesn't get trampled.
+ // is called too frequently, Sleep() at least 5ms to ensure the shared
+ // memory doesn't get trampled.
// TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going
// away in favor of the AudioUnit based AUAudioInputStream(). Tracked by
- // http://crbug.com/161383
+ // http://crbug.com/161383.
base::TimeDelta elapsed = base::Time::Now() - last_fill_;
- base::TimeDelta buffer_length = base::TimeDelta::FromMilliseconds(
- audio_buffer->mAudioDataByteSize * base::Time::kMillisecondsPerSecond /
- static_cast<float>(format_.mBytesPerFrame * format_.mSampleRate));
- if (elapsed < buffer_length)
- base::PlatformThread::Sleep(buffer_length - elapsed);
+ const base::TimeDelta kMinDelay = base::TimeDelta::FromMilliseconds(5);
+ if (elapsed < kMinDelay)
+ base::PlatformThread::Sleep(kMinDelay - elapsed);
callback_->OnData(this,
reinterpret_cast<const uint8*>(audio_buffer->mAudioData),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698