| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // Ratio of input bytes to output bytes used to correct playback delay with | 52 // Ratio of input bytes to output bytes used to correct playback delay with |
| 53 // regard to buffering and resampling. | 53 // regard to buffering and resampling. |
| 54 const double io_ratio_; | 54 const double io_ratio_; |
| 55 | 55 |
| 56 // Source callback. | 56 // Source callback. |
| 57 AudioOutputStream::AudioSourceCallback* source_callback_; | 57 AudioOutputStream::AudioSourceCallback* source_callback_; |
| 58 | 58 |
| 59 // Last |total_bytes_delay| received via OnMoreData(), used to correct | 59 // Last |total_bytes_delay| received via OnMoreData(), used to correct |
| 60 // playback delay by ProvideInput() and passed on to |source_callback_|. | 60 // playback delay by ProvideInput() and passed on to |source_callback_|. |
| 61 uint32 current_total_bytes_delay_; | 61 uint32_t current_total_bytes_delay_; |
| 62 | 62 |
| 63 const int input_bytes_per_second_; | 63 const int input_bytes_per_second_; |
| 64 | 64 |
| 65 // Handles resampling, buffering, and channel mixing between input and output | 65 // Handles resampling, buffering, and channel mixing between input and output |
| 66 // parameters. | 66 // parameters. |
| 67 AudioConverter audio_converter_; | 67 AudioConverter audio_converter_; |
| 68 | 68 |
| 69 // True if OnError() was ever called. Should only be read if the underlying | 69 // True if OnError() was ever called. Should only be read if the underlying |
| 70 // stream has been stopped. | 70 // stream has been stopped. |
| 71 bool error_occurred_; | 71 bool error_occurred_; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Always return the full number of frames requested, ProvideInput() | 380 // Always return the full number of frames requested, ProvideInput() |
| 381 // 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. |
| 382 return dest->frames(); | 382 return dest->frames(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 double OnMoreDataConverter::ProvideInput(AudioBus* dest, | 385 double OnMoreDataConverter::ProvideInput(AudioBus* dest, |
| 386 base::TimeDelta buffer_delay) { | 386 base::TimeDelta buffer_delay) { |
| 387 // Adjust playback delay to include |buffer_delay|. | 387 // Adjust playback delay to include |buffer_delay|. |
| 388 // 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 |
| 389 // AudioBus is just float data. Use TimeDelta instead. | 389 // AudioBus is just float data. Use TimeDelta instead. |
| 390 uint32 new_total_bytes_delay = base::saturated_cast<uint32>( | 390 uint32_t new_total_bytes_delay = base::saturated_cast<uint32_t>( |
| 391 io_ratio_ * (current_total_bytes_delay_ + | 391 io_ratio_ * (current_total_bytes_delay_ + |
| 392 buffer_delay.InSecondsF() * input_bytes_per_second_)); | 392 buffer_delay.InSecondsF() * input_bytes_per_second_)); |
| 393 | 393 |
| 394 // Retrieve data from the original callback. | 394 // Retrieve data from the original callback. |
| 395 const int frames = | 395 const int frames = |
| 396 source_callback_->OnMoreData(dest, new_total_bytes_delay, 0); | 396 source_callback_->OnMoreData(dest, new_total_bytes_delay, 0); |
| 397 | 397 |
| 398 // 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 |
| 399 // return a volume of zero and let AudioConverter drop the output. | 399 // return a volume of zero and let AudioConverter drop the output. |
| 400 if (frames > 0 && frames < dest->frames()) | 400 if (frames > 0 && frames < dest->frames()) |
| 401 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 401 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
| 402 return frames > 0 ? 1 : 0; | 402 return frames > 0 ? 1 : 0; |
| 403 } | 403 } |
| 404 | 404 |
| 405 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 405 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
| 406 error_occurred_ = true; | 406 error_occurred_ = true; |
| 407 source_callback_->OnError(stream); | 407 source_callback_->OnError(stream); |
| 408 } | 408 } |
| 409 | 409 |
| 410 } // namespace media | 410 } // namespace media |
| OLD | NEW |