| Index: media/audio/audio_input_device.cc
|
| ===================================================================
|
| --- media/audio/audio_input_device.cc (revision 186364)
|
| +++ media/audio/audio_input_device.cc (working copy)
|
| @@ -13,6 +13,12 @@
|
|
|
| namespace media {
|
|
|
| +// 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.
|
| +static const int kRequestedSharedMemoryCount = 10;
|
| +
|
| // Takes care of invoking the capture callback on the audio thread.
|
| // An instance of this class is created for each capture stream in
|
| // OnLowLatencyCreated().
|
| @@ -22,6 +28,7 @@
|
| AudioThreadCallback(const AudioParameters& audio_parameters,
|
| base::SharedMemoryHandle memory,
|
| int memory_length,
|
| + int total_segments,
|
| CaptureCallback* capture_callback);
|
| virtual ~AudioThreadCallback();
|
|
|
| @@ -31,6 +38,7 @@
|
| virtual void Process(int pending_data) OVERRIDE;
|
|
|
| private:
|
| + int current_segment_id_;
|
| CaptureCallback* capture_callback_;
|
| scoped_ptr<AudioBus> audio_bus_;
|
| DISALLOW_COPY_AND_ASSIGN(AudioThreadCallback);
|
| @@ -104,7 +112,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 +136,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 +205,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 +237,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 +312,11 @@
|
| 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),
|
| + current_segment_id_(0),
|
| capture_callback_(capture_callback) {
|
| audio_bus_ = AudioBus::Create(audio_parameters_);
|
| }
|
| @@ -319,16 +332,20 @@
|
| // 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 = static_cast<uint8*>(shared_memory_.memory());
|
| + ptr += current_segment_id_ * 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_;
|
| int16* memory = reinterpret_cast<int16*>(&buffer->audio[0]);
|
| const int bytes_per_sample = sizeof(memory[0]);
|
|
|
| + if (++current_segment_id_ >= total_segments_)
|
| + current_segment_id_ = 0;
|
| +
|
| // Deinterleave each channel and convert to 32-bit floating-point
|
| // with nominal range -1.0 -> +1.0.
|
| audio_bus_->FromInterleaved(memory, audio_bus_->frames(), bytes_per_sample);
|
|
|