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

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

Issue 1538563002: 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: Code review fix. git cl format. Rebase. 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, uint32 total_bytes_delay) override; 31 int OnMoreData(AudioBus* dest,
32 uint32_t total_bytes_delay,
33 uint32_t frames_skipped) override;
32 void OnError(AudioOutputStream* stream) override; 34 void OnError(AudioOutputStream* stream) override;
33 35
34 // Sets |source_callback_|. If this is not a new object, then Stop() must be 36 // Sets |source_callback_|. If this is not a new object, then Stop() must be
35 // called before Start(). 37 // called before Start().
36 void Start(AudioOutputStream::AudioSourceCallback* callback); 38 void Start(AudioOutputStream::AudioSourceCallback* callback);
37 39
38 // Clears |source_callback_| and flushes the resampler. 40 // Clears |source_callback_| and flushes the resampler.
39 void Stop(); 41 void Stop();
40 42
41 bool started() const { return source_callback_ != nullptr; } 43 bool started() const { return source_callback_ != nullptr; }
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 audio_converter_.AddInput(this); 365 audio_converter_.AddInput(this);
364 } 366 }
365 367
366 void OnMoreDataConverter::Stop() { 368 void OnMoreDataConverter::Stop() {
367 CHECK(source_callback_); 369 CHECK(source_callback_);
368 source_callback_ = nullptr; 370 source_callback_ = nullptr;
369 audio_converter_.RemoveInput(this); 371 audio_converter_.RemoveInput(this);
370 } 372 }
371 373
372 int OnMoreDataConverter::OnMoreData(AudioBus* dest, 374 int OnMoreDataConverter::OnMoreData(AudioBus* dest,
373 uint32 total_bytes_delay) { 375 uint32_t total_bytes_delay,
376 uint32_t frames_skipped) {
374 current_total_bytes_delay_ = total_bytes_delay; 377 current_total_bytes_delay_ = total_bytes_delay;
375 audio_converter_.Convert(dest); 378 audio_converter_.Convert(dest);
376 379
377 // Always return the full number of frames requested, ProvideInput() 380 // Always return the full number of frames requested, ProvideInput()
378 // will pad with silence if it wasn't able to acquire enough data. 381 // will pad with silence if it wasn't able to acquire enough data.
379 return dest->frames(); 382 return dest->frames();
380 } 383 }
381 384
382 double OnMoreDataConverter::ProvideInput(AudioBus* dest, 385 double OnMoreDataConverter::ProvideInput(AudioBus* dest,
383 base::TimeDelta buffer_delay) { 386 base::TimeDelta buffer_delay) {
384 // Adjust playback delay to include |buffer_delay|. 387 // Adjust playback delay to include |buffer_delay|.
385 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since 388 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since
386 // AudioBus is just float data. Use TimeDelta instead. 389 // AudioBus is just float data. Use TimeDelta instead.
387 uint32 new_total_bytes_delay = base::saturated_cast<uint32>( 390 uint32 new_total_bytes_delay = base::saturated_cast<uint32>(
388 io_ratio_ * (current_total_bytes_delay_ + 391 io_ratio_ * (current_total_bytes_delay_ +
389 buffer_delay.InSecondsF() * input_bytes_per_second_)); 392 buffer_delay.InSecondsF() * input_bytes_per_second_));
390 393
391 // Retrieve data from the original callback. 394 // Retrieve data from the original callback.
392 const int frames = source_callback_->OnMoreData(dest, new_total_bytes_delay); 395 const int frames =
396 source_callback_->OnMoreData(dest, new_total_bytes_delay, 0);
393 397
394 // Zero any unfilled frames if anything was filled, otherwise we'll just 398 // Zero any unfilled frames if anything was filled, otherwise we'll just
395 // return a volume of zero and let AudioConverter drop the output. 399 // return a volume of zero and let AudioConverter drop the output.
396 if (frames > 0 && frames < dest->frames()) 400 if (frames > 0 && frames < dest->frames())
397 dest->ZeroFramesPartial(frames, dest->frames() - frames); 401 dest->ZeroFramesPartial(frames, dest->frames() - frames);
398 return frames > 0 ? 1 : 0; 402 return frames > 0 ? 1 : 0;
399 } 403 }
400 404
401 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { 405 void OnMoreDataConverter::OnError(AudioOutputStream* stream) {
402 error_occurred_ = true; 406 error_occurred_ = true;
403 source_callback_->OnError(stream); 407 source_callback_->OnError(stream);
404 } 408 }
405 409
406 } // namespace media 410 } // 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