| Index: media/audio/audio_input_device.cc
|
| ===================================================================
|
| --- media/audio/audio_input_device.cc (revision 186364)
|
| +++ media/audio/audio_input_device.cc (working copy)
|
| @@ -11,6 +11,14 @@
|
| #include "media/audio/audio_manager_base.h"
|
| #include "media/base/audio_bus.h"
|
|
|
| +namespace {
|
| +// The number of shared memory buffer segments indicated to browser process
|
| +// in order to avoid data overwriting. This number can be any positive number,
|
| +// dependent how fast the renderer process can pick up captured data from
|
| +// shared memory.
|
| +int kRequestedSharedMemoryCount = 10;
|
| +}
|
| +
|
| namespace media {
|
|
|
| // Takes care of invoking the capture callback on the audio thread.
|
| @@ -22,13 +30,15 @@
|
| AudioThreadCallback(const AudioParameters& audio_parameters,
|
| base::SharedMemoryHandle memory,
|
| int memory_length,
|
| + int total_segments,
|
| CaptureCallback* capture_callback);
|
| virtual ~AudioThreadCallback();
|
|
|
| virtual void MapSharedMemory() OVERRIDE;
|
|
|
| // Called whenever we receive notifications about pending data.
|
| - virtual void Process(int pending_data) OVERRIDE;
|
| + // The |index| states which buffer segment is used.
|
| + virtual void Process(int pending_data, int index) OVERRIDE;
|
|
|
| private:
|
| CaptureCallback* capture_callback_;
|
| @@ -46,7 +56,8 @@
|
| stream_id_(0),
|
| session_id_(0),
|
| pending_device_ready_(false),
|
| - agc_is_enabled_(false) {
|
| + agc_is_enabled_(false),
|
| + audio_thread_(true) {
|
| CHECK(ipc_);
|
| }
|
|
|
| @@ -104,7 +115,8 @@
|
| void AudioInputDevice::OnStreamCreated(
|
| base::SharedMemoryHandle handle,
|
| base::SyncSocket::Handle socket_handle,
|
| - int length) {
|
| + int length,
|
| + int total_segments) {
|
| DCHECK(message_loop()->BelongsToCurrentThread());
|
| #if defined(OS_WIN)
|
| DCHECK(handle);
|
| @@ -127,8 +139,8 @@
|
|
|
| DCHECK(audio_thread_.IsStopped());
|
| audio_callback_.reset(
|
| - new AudioInputDevice::AudioThreadCallback(audio_parameters_, handle,
|
| - length, callback_));
|
| + new AudioInputDevice::AudioThreadCallback(
|
| + audio_parameters_, handle, length, total_segments, callback_));
|
| audio_thread_.Start(audio_callback_.get(), socket_handle, "AudioInputDevice");
|
|
|
| MessageLoop::current()->PostTask(FROM_HERE,
|
| @@ -196,7 +208,7 @@
|
| stream_id_ = 0;
|
| } else {
|
| ipc_->CreateStream(stream_id_, audio_parameters_, device_id,
|
| - agc_is_enabled_);
|
| + agc_is_enabled_, kRequestedSharedMemoryCount);
|
| }
|
|
|
| pending_device_ready_ = false;
|
| @@ -228,7 +240,8 @@
|
| // and create the stream when getting a OnDeviceReady() callback.
|
| if (!session_id_) {
|
| ipc_->CreateStream(stream_id_, audio_parameters_,
|
| - AudioManagerBase::kDefaultDeviceId, agc_is_enabled_);
|
| + AudioManagerBase::kDefaultDeviceId, agc_is_enabled_,
|
| + kRequestedSharedMemoryCount);
|
| } else {
|
| ipc_->StartDevice(stream_id_, session_id_);
|
| pending_device_ready_ = true;
|
| @@ -302,8 +315,10 @@
|
| const AudioParameters& audio_parameters,
|
| base::SharedMemoryHandle memory,
|
| int memory_length,
|
| + int total_segments,
|
| CaptureCallback* capture_callback)
|
| - : AudioDeviceThread::Callback(audio_parameters, memory, memory_length),
|
| + : AudioDeviceThread::Callback(audio_parameters, memory, memory_length,
|
| + total_segments),
|
| capture_callback_(capture_callback) {
|
| audio_bus_ = AudioBus::Create(audio_parameters_);
|
| }
|
| @@ -315,14 +330,16 @@
|
| shared_memory_.Map(memory_length_);
|
| }
|
|
|
| -void AudioInputDevice::AudioThreadCallback::Process(int pending_data) {
|
| +void AudioInputDevice::AudioThreadCallback::Process(
|
| + int pending_data, int index) {
|
| // The shared memory represents parameters, size of the data buffer and the
|
| // actual data buffer containing audio data. Map the memory into this
|
| // structure and parse out parameters and the data area.
|
| - AudioInputBuffer* buffer =
|
| - reinterpret_cast<AudioInputBuffer*>(shared_memory_.memory());
|
| + uint8* ptr = reinterpret_cast<uint8*>(shared_memory_.memory());
|
| + ptr += index * segment_length_;
|
| + AudioInputBuffer* buffer = reinterpret_cast<AudioInputBuffer*>(ptr);
|
| DCHECK_EQ(buffer->params.size,
|
| - memory_length_ - sizeof(AudioInputBufferParameters));
|
| + segment_length_ - sizeof(AudioInputBufferParameters));
|
| double volume = buffer->params.volume;
|
|
|
| int audio_delay_milliseconds = pending_data / bytes_per_ms_;
|
|
|