Index: media/audio/pulse/pulse_input.cc |
diff --git a/media/audio/pulse/pulse_input.cc b/media/audio/pulse/pulse_input.cc |
index d5cb94ece22fa09dff7aed7e730d463de037b689..5618c801d75b9e68a37503d9e3b07d40b35b25b8 100644 |
--- a/media/audio/pulse/pulse_input.cc |
+++ b/media/audio/pulse/pulse_input.cc |
@@ -9,13 +9,16 @@ |
#include "base/logging.h" |
#include "media/audio/pulse/audio_manager_pulse.h" |
#include "media/audio/pulse/pulse_util.h" |
-#include "media/base/seekable_buffer.h" |
+#include "media/base/audio_block_fifo.h" |
namespace media { |
using pulse::AutoPulseLock; |
using pulse::WaitForOperationCompletion; |
+// Number of blocks of buffers used in the |fifo_|. |
+const int kNumberOfBlocksBufferInFifo = 2; |
+ |
PulseAudioInputStream::PulseAudioInputStream(AudioManagerPulse* audio_manager, |
const std::string& device_name, |
const AudioParameters& params, |
@@ -35,7 +38,6 @@ PulseAudioInputStream::PulseAudioInputStream(AudioManagerPulse* audio_manager, |
DCHECK(mainloop); |
DCHECK(context); |
CHECK(params_.IsValid()); |
- audio_bus_ = AudioBus::Create(params_); |
} |
PulseAudioInputStream::~PulseAudioInputStream() { |
@@ -54,8 +56,9 @@ bool PulseAudioInputStream::Open() { |
DCHECK(handle_); |
- buffer_.reset(new media::SeekableBuffer(0, 2 * params_.GetBytesPerBuffer())); |
- audio_data_buffer_.reset(new uint8[params_.GetBytesPerBuffer()]); |
+ fifo_.reset(new AudioBlockFifo(params_.channels(), |
DaleCurtis
2014/07/18 18:21:54
Avoid dynamic allocation during construction?
no longer working on chromium
2014/07/21 15:13:30
Done.
|
+ params_.frames_per_buffer(), |
+ kNumberOfBlocksBufferInFifo)); |
return true; |
} |
@@ -74,7 +77,7 @@ void PulseAudioInputStream::Start(AudioInputCallback* callback) { |
// Clean up the old buffer. |
pa_stream_drop(handle_); |
- buffer_->Clear(); |
+ fifo_->Clear(); |
// Start the streaming. |
callback_ = callback; |
@@ -265,23 +268,20 @@ void PulseAudioInputStream::ReadData() { |
if (!data || length == 0) |
break; |
- buffer_->Append(reinterpret_cast<const uint8*>(data), length); |
+ const int number_of_frames = length / params_.GetBytesPerFrame(); |
+ fifo_->Push(data, number_of_frames, params_.bits_per_sample() / 8); |
// Checks if we still have data. |
pa_stream_drop(handle_); |
} while (pa_stream_readable_size(handle_) > 0); |
- int packet_size = params_.GetBytesPerBuffer(); |
- while (buffer_->forward_bytes() >= packet_size) { |
- buffer_->Read(audio_data_buffer_.get(), packet_size); |
- audio_bus_->FromInterleaved(audio_data_buffer_.get(), |
- audio_bus_->frames(), |
- params_.bits_per_sample() / 8); |
- callback_->OnData( |
- this, audio_bus_.get(), hardware_delay, normalized_volume); |
+ while (fifo_->available_blocks()) { |
+ const AudioBus* audio_bus = fifo_->Consume(); |
- if (buffer_->forward_bytes() < packet_size) |
- break; |
+ // Compensate the audio delay caused by the FIFO. |
+ hardware_delay += fifo_->available_frames() * params_.GetBytesPerFrame(); |
+ callback_->OnData( |
+ this, audio_bus, hardware_delay, normalized_volume); |
// TODO(xians): Remove once PPAPI is using circular buffers. |
DVLOG(1) << "OnData is being called consecutively, sleep 5ms to " |