Index: media/audio/pulse/pulse_output.cc |
diff --git a/media/audio/pulse/pulse_output.cc b/media/audio/pulse/pulse_output.cc |
index 7cf66cb10c801ba9f7de12c9aae90d1e7e06dc40..2536b67fec131832946092b52a71dbda415b2958 100644 |
--- a/media/audio/pulse/pulse_output.cc |
+++ b/media/audio/pulse/pulse_output.cc |
@@ -157,8 +157,8 @@ bool PulseAudioOutputStream::Open() { |
pa_buffer_attr pa_buffer_attributes; |
pa_buffer_attributes.maxlength = params_.GetBytesPerBuffer(); |
pa_buffer_attributes.minreq = params_.GetBytesPerBuffer(); |
- pa_buffer_attributes.prebuf = params_.GetBytesPerBuffer(); |
- pa_buffer_attributes.tlength = params_.GetBytesPerBuffer(); |
+ pa_buffer_attributes.prebuf = static_cast<uint32_t>(-1); |
+ pa_buffer_attributes.tlength = static_cast<uint32_t>(-1); |
pa_buffer_attributes.fragsize = static_cast<uint32_t>(-1); |
// Connect playback stream. |
@@ -238,43 +238,33 @@ void PulseAudioOutputStream::Close() { |
} |
void PulseAudioOutputStream::FulfillWriteRequest(size_t requested_bytes) { |
- CHECK_EQ(requested_bytes, static_cast<size_t>(params_.GetBytesPerBuffer())); |
- |
- int frames_filled = 0; |
- if (source_callback_) { |
- uint32 hardware_delay = pulse::GetHardwareLatencyInBytes( |
- pa_stream_, params_.sample_rate(), |
- params_.GetBytesPerFrame()); |
- frames_filled = source_callback_->OnMoreData( |
- audio_bus_.get(), AudioBuffersState(0, hardware_delay)); |
- } |
- |
- // Zero any unfilled data so it plays back as silence. |
- if (frames_filled < audio_bus_->frames()) { |
- audio_bus_->ZeroFramesPartial( |
- frames_filled, audio_bus_->frames() - frames_filled); |
- } |
- |
- // PulseAudio won't always be able to provide a buffer large enough, so we may |
- // need to request multiple buffers and fill them individually. |
- int current_frame = 0; |
- size_t bytes_remaining = requested_bytes; |
+ int bytes_remaining = requested_bytes; |
while (bytes_remaining > 0) { |
void* buffer = NULL; |
- size_t bytes_to_fill = bytes_remaining; |
+ size_t bytes_to_fill = params_.GetBytesPerBuffer(); |
CHECK_GE(pa_stream_begin_write(pa_stream_, &buffer, &bytes_to_fill), 0); |
+ CHECK_EQ(bytes_to_fill, static_cast<size_t>(params_.GetBytesPerBuffer())); |
+ |
+ int frames_filled = 0; |
+ if (source_callback_) { |
+ uint32 hardware_delay = pulse::GetHardwareLatencyInBytes( |
+ pa_stream_, params_.sample_rate(), |
+ params_.GetBytesPerFrame()); |
+ source_callback_->WaitTillDataReady(); |
+ frames_filled = source_callback_->OnMoreData( |
+ audio_bus_.get(), AudioBuffersState(0, hardware_delay)); |
+ } |
- // In case PulseAudio gives us a bigger buffer than we want, cap our size. |
- bytes_to_fill = std::min( |
- std::min(bytes_remaining, bytes_to_fill), |
- static_cast<size_t>(params_.GetBytesPerBuffer())); |
- |
- int frames_to_fill = bytes_to_fill / params_.GetBytesPerFrame();; |
+ // Zero any unfilled data so it plays back as silence. |
+ if (frames_filled < audio_bus_->frames()) { |
+ audio_bus_->ZeroFramesPartial( |
+ frames_filled, audio_bus_->frames() - frames_filled); |
+ } |
// Note: If this ever changes to output raw float the data must be clipped |
// and sanitized since it may come from an untrusted source such as NaCl. |
- audio_bus_->ToInterleavedPartial( |
- current_frame, frames_to_fill, params_.bits_per_sample() / 8, buffer); |
+ audio_bus_->ToInterleaved( |
+ audio_bus_->frames(), params_.bits_per_sample() / 8, buffer); |
media::AdjustVolume(buffer, bytes_to_fill, params_.channels(), |
params_.bits_per_sample() / 8, volume_); |
@@ -286,7 +276,6 @@ void PulseAudioOutputStream::FulfillWriteRequest(size_t requested_bytes) { |
} |
bytes_remaining -= bytes_to_fill; |
- current_frame = frames_to_fill; |
} |
} |