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

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

Issue 1538463002: Revert of Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/audio_output_stream_sink.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/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/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 10 matching lines...) Expand all
21 21
22 class OnMoreDataConverter 22 class OnMoreDataConverter
23 : public AudioOutputStream::AudioSourceCallback, 23 : public AudioOutputStream::AudioSourceCallback,
24 public AudioConverter::InputCallback { 24 public AudioConverter::InputCallback {
25 public: 25 public:
26 OnMoreDataConverter(const AudioParameters& input_params, 26 OnMoreDataConverter(const AudioParameters& input_params,
27 const AudioParameters& output_params); 27 const AudioParameters& output_params);
28 ~OnMoreDataConverter() override; 28 ~OnMoreDataConverter() override;
29 29
30 // AudioSourceCallback interface. 30 // AudioSourceCallback interface.
31 int OnMoreData(AudioBus* dest, 31 int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) override;
32 uint32_t total_bytes_delay,
33 uint32_t frames_skipped) override;
34 void OnError(AudioOutputStream* stream) override; 32 void OnError(AudioOutputStream* stream) override;
35 33
36 // Sets |source_callback_|. If this is not a new object, then Stop() must be 34 // Sets |source_callback_|. If this is not a new object, then Stop() must be
37 // called before Start(). 35 // called before Start().
38 void Start(AudioOutputStream::AudioSourceCallback* callback); 36 void Start(AudioOutputStream::AudioSourceCallback* callback);
39 37
40 // Clears |source_callback_| and flushes the resampler. 38 // Clears |source_callback_| and flushes the resampler.
41 void Stop(); 39 void Stop();
42 40
43 bool started() const { return source_callback_ != nullptr; } 41 bool started() const { return source_callback_ != nullptr; }
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 audio_converter_.AddInput(this); 363 audio_converter_.AddInput(this);
366 } 364 }
367 365
368 void OnMoreDataConverter::Stop() { 366 void OnMoreDataConverter::Stop() {
369 CHECK(source_callback_); 367 CHECK(source_callback_);
370 source_callback_ = nullptr; 368 source_callback_ = nullptr;
371 audio_converter_.RemoveInput(this); 369 audio_converter_.RemoveInput(this);
372 } 370 }
373 371
374 int OnMoreDataConverter::OnMoreData(AudioBus* dest, 372 int OnMoreDataConverter::OnMoreData(AudioBus* dest,
375 uint32_t total_bytes_delay, 373 uint32 total_bytes_delay) {
376 uint32_t frames_skipped) {
377 current_total_bytes_delay_ = total_bytes_delay; 374 current_total_bytes_delay_ = total_bytes_delay;
378 audio_converter_.Convert(dest); 375 audio_converter_.Convert(dest);
379 376
380 // Always return the full number of frames requested, ProvideInput() 377 // Always return the full number of frames requested, ProvideInput()
381 // will pad with silence if it wasn't able to acquire enough data. 378 // will pad with silence if it wasn't able to acquire enough data.
382 return dest->frames(); 379 return dest->frames();
383 } 380 }
384 381
385 double OnMoreDataConverter::ProvideInput(AudioBus* dest, 382 double OnMoreDataConverter::ProvideInput(AudioBus* dest,
386 base::TimeDelta buffer_delay) { 383 base::TimeDelta buffer_delay) {
387 // Adjust playback delay to include |buffer_delay|. 384 // Adjust playback delay to include |buffer_delay|.
388 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since 385 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since
389 // AudioBus is just float data. Use TimeDelta instead. 386 // AudioBus is just float data. Use TimeDelta instead.
390 uint32 new_total_bytes_delay = base::saturated_cast<uint32>( 387 uint32 new_total_bytes_delay = base::saturated_cast<uint32>(
391 io_ratio_ * (current_total_bytes_delay_ + 388 io_ratio_ * (current_total_bytes_delay_ +
392 buffer_delay.InSecondsF() * input_bytes_per_second_)); 389 buffer_delay.InSecondsF() * input_bytes_per_second_));
393 390
394 // Retrieve data from the original callback. 391 // Retrieve data from the original callback.
395 const int frames = 392 const int frames = source_callback_->OnMoreData(dest, new_total_bytes_delay);
396 source_callback_->OnMoreData(dest, new_total_bytes_delay, 0);
397 393
398 // Zero any unfilled frames if anything was filled, otherwise we'll just 394 // Zero any unfilled frames if anything was filled, otherwise we'll just
399 // return a volume of zero and let AudioConverter drop the output. 395 // return a volume of zero and let AudioConverter drop the output.
400 if (frames > 0 && frames < dest->frames()) 396 if (frames > 0 && frames < dest->frames())
401 dest->ZeroFramesPartial(frames, dest->frames() - frames); 397 dest->ZeroFramesPartial(frames, dest->frames() - frames);
402 return frames > 0 ? 1 : 0; 398 return frames > 0 ? 1 : 0;
403 } 399 }
404 400
405 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { 401 void OnMoreDataConverter::OnError(AudioOutputStream* stream) {
406 error_occurred_ = true; 402 error_occurred_ = true;
407 source_callback_->OnError(stream); 403 source_callback_->OnError(stream);
408 } 404 }
409 405
410 } // namespace media 406 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/audio_output_stream_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698