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

Side by Side Diff: media/audio/win/audio_low_latency_input_win.cc

Issue 2703253003: WASAPIAudioInputStream: Revert to the previous buffer size calculation. (Closed)
Patch Set: Created 3 years, 10 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 | no next file » | 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/win/audio_low_latency_input_win.h" 5 #include "media/audio/win/audio_low_latency_input_win.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // 1) The recorded buffer size is smaller, or does not match exactly with, 349 // 1) The recorded buffer size is smaller, or does not match exactly with,
350 // the selected packet size used in each callback. 350 // the selected packet size used in each callback.
351 // 2) The selected buffer size is larger than the recorded buffer size in 351 // 2) The selected buffer size is larger than the recorded buffer size in
352 // each event. 352 // each event.
353 // In the case where no resampling is required, a single buffer should be 353 // In the case where no resampling is required, a single buffer should be
354 // enough but in case we get buffers that don't match exactly, we'll go with 354 // enough but in case we get buffers that don't match exactly, we'll go with
355 // two. Same applies if we need to resample and the buffer ratio is perfect. 355 // two. Same applies if we need to resample and the buffer ratio is perfect.
356 // However if the buffer ratio is imperfect, we will need 3 buffers to safely 356 // However if the buffer ratio is imperfect, we will need 3 buffers to safely
357 // be able to buffer up data in cases where a conversion requires two audio 357 // be able to buffer up data in cases where a conversion requires two audio
358 // buffers (and we need to be able to write to the third one). 358 // buffers (and we need to be able to write to the third one).
359 size_t capture_buffer_size =
360 std::max(2 * endpoint_buffer_size_frames_ * frame_size_,
361 2 * packet_size_frames_ * frame_size_);
362 int buffers_required = capture_buffer_size / packet_size_bytes_;
363 if (converter_ && imperfect_buffer_size_conversion_)
364 ++buffers_required;
365
359 DCHECK(!fifo_); 366 DCHECK(!fifo_);
360 const int buffers_required =
361 converter_ && imperfect_buffer_size_conversion_ ? 3 : 2;
362 fifo_.reset(new AudioBlockFifo(format_.nChannels, packet_size_frames_, 367 fifo_.reset(new AudioBlockFifo(format_.nChannels, packet_size_frames_,
363 buffers_required)); 368 buffers_required));
364 369
365 DVLOG(1) << "AudioBlockFifo needs " << buffers_required << " buffers"; 370 DVLOG(1) << "AudioBlockFifo buffer count: " << buffers_required;
366 371
367 LARGE_INTEGER now_count = {}; 372 LARGE_INTEGER now_count = {};
368 bool recording = true; 373 bool recording = true;
369 bool error = false; 374 bool error = false;
370 double volume = GetVolume(); 375 double volume = GetVolume();
371 HANDLE wait_array[2] = {stop_capture_event_.Get(), 376 HANDLE wait_array[2] = {stop_capture_event_.Get(),
372 audio_samples_ready_event_.Get()}; 377 audio_samples_ready_event_.Get()};
373 378
374 base::win::ScopedComPtr<IAudioClock> audio_clock; 379 base::win::ScopedComPtr<IAudioClock> audio_clock;
375 audio_client_->GetService(__uuidof(IAudioClock), audio_clock.ReceiveVoid()); 380 audio_client_->GetService(__uuidof(IAudioClock), audio_clock.ReceiveVoid());
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 OPEN_RESULT_MAX + 1); 827 OPEN_RESULT_MAX + 1);
823 } 828 }
824 829
825 double WASAPIAudioInputStream::ProvideInput(AudioBus* audio_bus, 830 double WASAPIAudioInputStream::ProvideInput(AudioBus* audio_bus,
826 uint32_t frames_delayed) { 831 uint32_t frames_delayed) {
827 fifo_->Consume()->CopyTo(audio_bus); 832 fifo_->Consume()->CopyTo(audio_bus);
828 return 1.0; 833 return 1.0;
829 } 834 }
830 835
831 } // namespace media 836 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698