Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: media/audio/pulse/pulse_input.cc

Issue 557693003: Dynamically allocate more memory to AudioBlockFifo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed the comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/base/audio_block_fifo.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 increase capacity to the FIFO to handle larger buffer got
275 // from Pulse.
276 const int increase_blocks_of_buffer = static_cast<int>(
277 (number_of_frames - fifo_.GetUnfilledFrames()) /
278 params_.frames_per_buffer()) + 1;
279 fifo_.IncreaseCapacity(increase_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
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_block_fifo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698