summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-07 01:38:39 +0000
committerdalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-07 01:38:39 +0000
commitef17522051a56f5fadd6c0735f3b26d25031cff7 (patch)
treed0d24b2a639061b7ce0f02c29722f823c6de3bb4 /media
parent2eeb184a2697116d180e3b13e81735037d02b9f0 (diff)
downloadchromium_src-ef17522051a56f5fadd6c0735f3b26d25031cff7.zip
chromium_src-ef17522051a56f5fadd6c0735f3b26d25031cff7.tar.gz
chromium_src-ef17522051a56f5fadd6c0735f3b26d25031cff7.tar.bz2
Delay delivery of audio input data.
The AudioQueue API may use a large internal buffer and repeatedly call us 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. BUG=157613 TEST=Playback works on older style Mac units. Review URL: https://codereview.chromium.org/11482002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/mac/audio_input_mac.cc21
-rw-r--r--media/audio/mac/audio_input_mac.h5
2 files changed, 24 insertions, 2 deletions
diff --git a/media/audio/mac/audio_input_mac.cc b/media/audio/mac/audio_input_mac.cc
index fd2d9be..69791cf 100644
--- a/media/audio/mac/audio_input_mac.cc
+++ b/media/audio/mac/audio_input_mac.cc
@@ -192,12 +192,31 @@ void PCMQueueInAudioInputStream::HandleInputBuffer(
return;
}
- if (audio_buffer->mAudioDataByteSize)
+ if (audio_buffer->mAudioDataByteSize) {
+ // The AudioQueue API may use a large internal buffer and repeatedly call us
+ // 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.
+ // 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
+ 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);
+
callback_->OnData(this,
reinterpret_cast<const uint8*>(audio_buffer->mAudioData),
audio_buffer->mAudioDataByteSize,
audio_buffer->mAudioDataByteSize,
0.0);
+
+ last_fill_ = base::Time::Now();
+ }
// Recycle the buffer.
OSStatus err = QueueNextBuffer(audio_buffer);
if (err != noErr) {
diff --git a/media/audio/mac/audio_input_mac.h b/media/audio/mac/audio_input_mac.h
index ddef40f..1f9856f1 100644
--- a/media/audio/mac/audio_input_mac.h
+++ b/media/audio/mac/audio_input_mac.h
@@ -9,6 +9,7 @@
#include <AudioToolbox/AudioFormat.h>
#include "base/compiler_specific.h"
+#include "base/time.h"
#include "media/audio/audio_io.h"
#include "media/audio/audio_parameters.h"
@@ -62,7 +63,7 @@ class PCMQueueInAudioInputStream : public AudioInputStream {
UInt32 num_packets,
const AudioStreamPacketDescription* packet_desc);
- static const int kNumberBuffers = 1;
+ static const int kNumberBuffers = 3;
// Manager that owns this stream, used for closing down.
AudioManagerBase* manager_;
@@ -76,6 +77,8 @@ class PCMQueueInAudioInputStream : public AudioInputStream {
uint32 buffer_size_bytes_;
// True iff Start() has been called successfully.
bool started_;
+ // Used to determine if we need to slow down |callback_| calls.
+ base::Time last_fill_;
DISALLOW_COPY_AND_ASSIGN(PCMQueueInAudioInputStream);
};