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

Side by Side Diff: media/audio/audio_output_resampler.cc

Issue 12155003: Use the correct number of WaveOut buffers on XP... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Useless header. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/audio/audio_util.cc » ('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/audio_output_resampler.h" 5 #include "media/audio/audio_output_resampler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "media/audio/audio_io.h" 15 #include "media/audio/audio_io.h"
16 #include "media/audio/audio_output_dispatcher_impl.h" 16 #include "media/audio/audio_output_dispatcher_impl.h"
17 #include "media/audio/audio_output_proxy.h" 17 #include "media/audio/audio_output_proxy.h"
18 #include "media/audio/audio_util.h" 18 #include "media/audio/audio_util.h"
19 #include "media/audio/sample_rates.h" 19 #include "media/audio/sample_rates.h"
20 #include "media/base/audio_converter.h" 20 #include "media/base/audio_converter.h"
21 #include "media/base/limits.h" 21 #include "media/base/limits.h"
22 #include "media/base/media_switches.h" 22 #include "media/base/media_switches.h"
23 23
24 #if defined(OS_WIN)
25 #include "media/audio/win/core_audio_util_win.h"
26 #endif
27
28 namespace media { 24 namespace media {
29 25
30 class OnMoreDataConverter 26 class OnMoreDataConverter
31 : public AudioOutputStream::AudioSourceCallback, 27 : public AudioOutputStream::AudioSourceCallback,
32 public AudioConverter::InputCallback { 28 public AudioConverter::InputCallback {
33 public: 29 public:
34 OnMoreDataConverter(const AudioParameters& input_params, 30 OnMoreDataConverter(const AudioParameters& input_params,
35 const AudioParameters& output_params); 31 const AudioParameters& output_params);
36 virtual ~OnMoreDataConverter(); 32 virtual ~OnMoreDataConverter();
37 33
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Last AudioBuffersState object received via OnMoreData(), used to correct 66 // Last AudioBuffersState object received via OnMoreData(), used to correct
71 // playback delay by ProvideInput() and passed on to |source_callback_|. 67 // playback delay by ProvideInput() and passed on to |source_callback_|.
72 AudioBuffersState current_buffers_state_; 68 AudioBuffersState current_buffers_state_;
73 69
74 const int input_bytes_per_second_; 70 const int input_bytes_per_second_;
75 71
76 // Handles resampling, buffering, and channel mixing between input and output 72 // Handles resampling, buffering, and channel mixing between input and output
77 // parameters. 73 // parameters.
78 AudioConverter audio_converter_; 74 AudioConverter audio_converter_;
79 75
80 // If we're using WaveOut on Windows' we always have to wait for DataReady()
81 // before calling |source_callback_|.
82 bool waveout_wait_hack_;
83
84 DISALLOW_COPY_AND_ASSIGN(OnMoreDataConverter); 76 DISALLOW_COPY_AND_ASSIGN(OnMoreDataConverter);
85 }; 77 };
86 78
87 // Record UMA statistics for hardware output configuration. 79 // Record UMA statistics for hardware output configuration.
88 static void RecordStats(const AudioParameters& output_params) { 80 static void RecordStats(const AudioParameters& output_params) {
89 UMA_HISTOGRAM_ENUMERATION( 81 UMA_HISTOGRAM_ENUMERATION(
90 "Media.HardwareAudioBitsPerChannel", output_params.bits_per_sample(), 82 "Media.HardwareAudioBitsPerChannel", output_params.bits_per_sample(),
91 limits::kMaxBitsPerSample); 83 limits::kMaxBitsPerSample);
92 UMA_HISTOGRAM_ENUMERATION( 84 UMA_HISTOGRAM_ENUMERATION(
93 "Media.HardwareAudioChannelLayout", output_params.channel_layout(), 85 "Media.HardwareAudioChannelLayout", output_params.channel_layout(),
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 272
281 dispatcher_->Shutdown(); 273 dispatcher_->Shutdown();
282 DCHECK(callbacks_.empty()); 274 DCHECK(callbacks_.empty());
283 } 275 }
284 276
285 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params, 277 OnMoreDataConverter::OnMoreDataConverter(const AudioParameters& input_params,
286 const AudioParameters& output_params) 278 const AudioParameters& output_params)
287 : source_callback_(NULL), 279 : source_callback_(NULL),
288 source_bus_(NULL), 280 source_bus_(NULL),
289 input_bytes_per_second_(input_params.GetBytesPerSecond()), 281 input_bytes_per_second_(input_params.GetBytesPerSecond()),
290 audio_converter_(input_params, output_params, false), 282 audio_converter_(input_params, output_params, false) {
291 waveout_wait_hack_(false) {
292 io_ratio_ = 283 io_ratio_ =
293 static_cast<double>(input_params.GetBytesPerSecond()) / 284 static_cast<double>(input_params.GetBytesPerSecond()) /
294 output_params.GetBytesPerSecond(); 285 output_params.GetBytesPerSecond();
295
296 // TODO(dalecurtis): We should require all render side clients to use a
297 // buffer size that's a multiple of the hardware buffer size scaled by the
298 // request_sample_rate / hw_sample_rate. Doing so ensures each hardware
299 // request for audio data results in only a single render side callback and
300 // would allow us to remove this hack. See http://crbug.com/162207.
301 #if defined(OS_WIN)
302 waveout_wait_hack_ =
303 output_params.format() == AudioParameters::AUDIO_PCM_LINEAR ||
304 !CoreAudioUtil::IsSupported();
305 #endif
306 } 286 }
307 287
308 OnMoreDataConverter::~OnMoreDataConverter() {} 288 OnMoreDataConverter::~OnMoreDataConverter() {}
309 289
310 void OnMoreDataConverter::Start( 290 void OnMoreDataConverter::Start(
311 AudioOutputStream::AudioSourceCallback* callback) { 291 AudioOutputStream::AudioSourceCallback* callback) {
312 base::AutoLock auto_lock(source_lock_); 292 base::AutoLock auto_lock(source_lock_);
313 DCHECK(!source_callback_); 293 DCHECK(!source_callback_);
314 source_callback_ = callback; 294 source_callback_ = callback;
315 295
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 source_lock_.AssertAcquired(); 334 source_lock_.AssertAcquired();
355 335
356 // Adjust playback delay to include |buffer_delay|. 336 // Adjust playback delay to include |buffer_delay|.
357 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since 337 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since
358 // AudioBus is just float data. Use TimeDelta instead. 338 // AudioBus is just float data. Use TimeDelta instead.
359 AudioBuffersState new_buffers_state; 339 AudioBuffersState new_buffers_state;
360 new_buffers_state.pending_bytes = 340 new_buffers_state.pending_bytes =
361 io_ratio_ * (current_buffers_state_.total_bytes() + 341 io_ratio_ * (current_buffers_state_.total_bytes() +
362 buffer_delay.InSecondsF() * input_bytes_per_second_); 342 buffer_delay.InSecondsF() * input_bytes_per_second_);
363 343
364 if (waveout_wait_hack_)
365 source_callback_->WaitTillDataReady();
366
367 // Retrieve data from the original callback. 344 // Retrieve data from the original callback.
368 int frames = source_callback_->OnMoreIOData( 345 int frames = source_callback_->OnMoreIOData(
369 source_bus_, dest, new_buffers_state); 346 source_bus_, dest, new_buffers_state);
370 347
371 // |source_bus_| should only be provided once. 348 // |source_bus_| should only be provided once.
372 // TODO(dalecurtis, crogers): This is not a complete fix. If ProvideInput() 349 // TODO(dalecurtis, crogers): This is not a complete fix. If ProvideInput()
373 // is called multiple times, we need to do something more clever here. 350 // is called multiple times, we need to do something more clever here.
374 source_bus_ = NULL; 351 source_bus_ = NULL;
375 352
376 // Zero any unfilled frames if anything was filled, otherwise we'll just 353 // Zero any unfilled frames if anything was filled, otherwise we'll just
(...skipping 11 matching lines...) Expand all
388 source_callback_->OnError(stream, code); 365 source_callback_->OnError(stream, code);
389 } 366 }
390 367
391 void OnMoreDataConverter::WaitTillDataReady() { 368 void OnMoreDataConverter::WaitTillDataReady() {
392 base::AutoLock auto_lock(source_lock_); 369 base::AutoLock auto_lock(source_lock_);
393 if (source_callback_) 370 if (source_callback_)
394 source_callback_->WaitTillDataReady(); 371 source_callback_->WaitTillDataReady();
395 } 372 }
396 373
397 } // namespace media 374 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/audio/audio_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698