| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/pulse/pulse_input.h" | 5 #include "media/audio/pulse/pulse_input.h" |
| 6 | 6 |
| 7 #include <pulse/pulseaudio.h> | 7 #include <pulse/pulseaudio.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/audio/pulse/audio_manager_pulse.h" | 10 #include "media/audio/pulse/audio_manager_pulse.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 normalized_volume = volume_ / GetMaxVolume(); | 263 normalized_volume = volume_ / GetMaxVolume(); |
| 264 | 264 |
| 265 do { | 265 do { |
| 266 size_t length = 0; | 266 size_t length = 0; |
| 267 const void* data = NULL; | 267 const void* data = NULL; |
| 268 pa_stream_peek(handle_, &data, &length); | 268 pa_stream_peek(handle_, &data, &length); |
| 269 if (!data || length == 0) | 269 if (!data || length == 0) |
| 270 break; | 270 break; |
| 271 | 271 |
| 272 const int number_of_frames = length / params_.GetBytesPerFrame(); | 272 const int number_of_frames = length / params_.GetBytesPerFrame(); |
| 273 if (number_of_frames > fifo_.GetUnfilledFrames()) { |
| 274 // Dynamically append buffers to the FIFO to handle larger buffer got |
| 275 // from Pulse. |
| 276 const int append_blocks_of_buffer = static_cast<int>( |
| 277 (number_of_frames - fifo_.GetUnfilledFrames()) / |
| 278 params_.frames_per_buffer()) + 1; |
| 279 fifo_.Append(append_blocks_of_buffer); |
| 280 } |
| 281 |
| 273 fifo_.Push(data, number_of_frames, params_.bits_per_sample() / 8); | 282 fifo_.Push(data, number_of_frames, params_.bits_per_sample() / 8); |
| 274 | 283 |
| 275 // Checks if we still have data. | 284 // Checks if we still have data. |
| 276 pa_stream_drop(handle_); | 285 pa_stream_drop(handle_); |
| 277 } while (pa_stream_readable_size(handle_) > 0); | 286 } while (pa_stream_readable_size(handle_) > 0); |
| 278 | 287 |
| 279 while (fifo_.available_blocks()) { | 288 while (fifo_.available_blocks()) { |
| 280 const AudioBus* audio_bus = fifo_.Consume(); | 289 const AudioBus* audio_bus = fifo_.Consume(); |
| 281 | 290 |
| 282 // Compensate the audio delay caused by the FIFO. | 291 // Compensate the audio delay caused by the FIFO. |
| 283 hardware_delay += fifo_.GetAvailableFrames() * params_.GetBytesPerFrame(); | 292 hardware_delay += fifo_.GetAvailableFrames() * params_.GetBytesPerFrame(); |
| 284 callback_->OnData(this, audio_bus, hardware_delay, normalized_volume); | 293 callback_->OnData(this, audio_bus, hardware_delay, normalized_volume); |
| 285 | 294 |
| 286 // Sleep 5ms to wait until render consumes the data in order to avoid | 295 // Sleep 5ms to wait until render consumes the data in order to avoid |
| 287 // back to back OnData() method. | 296 // back to back OnData() method. |
| 288 if (fifo_.available_blocks()) | 297 if (fifo_.available_blocks()) |
| 289 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); | 298 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); |
| 290 } | 299 } |
| 291 | 300 |
| 292 pa_threaded_mainloop_signal(pa_mainloop_, 0); | 301 pa_threaded_mainloop_signal(pa_mainloop_, 0); |
| 293 } | 302 } |
| 294 | 303 |
| 295 } // namespace media | 304 } // namespace media |
| OLD | NEW |