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" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/time/time.h" | 13 #include "base/time/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/sample_rates.h" | 18 #include "media/audio/sample_rates.h" |
19 #include "media/base/audio_converter.h" | 19 #include "media/base/audio_converter.h" |
20 #include "media/base/limits.h" | 20 #include "media/base/limits.h" |
21 | 21 |
22 namespace media { | 22 namespace media { |
23 | 23 |
24 class OnMoreDataConverter | 24 class OnMoreDataConverter |
25 : public AudioOutputStream::AudioSourceCallback, | 25 : public AudioOutputStream::AudioSourceCallback, |
26 public AudioConverter::InputCallback { | 26 public AudioConverter::InputCallback { |
27 public: | 27 public: |
28 OnMoreDataConverter(const AudioParameters& input_params, | 28 OnMoreDataConverter(const AudioParameters& input_params, |
29 const AudioParameters& output_params); | 29 const AudioParameters& output_params); |
30 virtual ~OnMoreDataConverter(); | 30 ~OnMoreDataConverter() override; |
31 | 31 |
32 // AudioSourceCallback interface. | 32 // AudioSourceCallback interface. |
33 virtual int OnMoreData(AudioBus* dest, | 33 int OnMoreData(AudioBus* dest, uint32 total_bytes_delay) override; |
34 uint32 total_bytes_delay) override; | 34 void OnError(AudioOutputStream* stream) override; |
35 virtual void OnError(AudioOutputStream* stream) override; | |
36 | 35 |
37 // 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 |
38 // called before Start(). | 37 // called before Start(). |
39 void Start(AudioOutputStream::AudioSourceCallback* callback); | 38 void Start(AudioOutputStream::AudioSourceCallback* callback); |
40 | 39 |
41 // Clears |source_callback_| and flushes the resampler. | 40 // Clears |source_callback_| and flushes the resampler. |
42 void Stop(); | 41 void Stop(); |
43 | 42 |
44 bool started() { return source_callback_ != nullptr; } | 43 bool started() { return source_callback_ != nullptr; } |
45 | 44 |
46 private: | 45 private: |
47 // AudioConverter::InputCallback implementation. | 46 // AudioConverter::InputCallback implementation. |
48 virtual double ProvideInput(AudioBus* audio_bus, | 47 double ProvideInput(AudioBus* audio_bus, |
49 base::TimeDelta buffer_delay) override; | 48 base::TimeDelta buffer_delay) override; |
50 | 49 |
51 // Ratio of input bytes to output bytes used to correct playback delay with | 50 // Ratio of input bytes to output bytes used to correct playback delay with |
52 // regard to buffering and resampling. | 51 // regard to buffering and resampling. |
53 const double io_ratio_; | 52 const double io_ratio_; |
54 | 53 |
55 // Source callback. | 54 // Source callback. |
56 AudioOutputStream::AudioSourceCallback* source_callback_; | 55 AudioOutputStream::AudioSourceCallback* source_callback_; |
57 | 56 |
58 // Last |total_bytes_delay| received via OnMoreData(), used to correct | 57 // Last |total_bytes_delay| received via OnMoreData(), used to correct |
59 // playback delay by ProvideInput() and passed on to |source_callback_|. | 58 // playback delay by ProvideInput() and passed on to |source_callback_|. |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 if (frames > 0 && frames < dest->frames()) | 353 if (frames > 0 && frames < dest->frames()) |
355 dest->ZeroFramesPartial(frames, dest->frames() - frames); | 354 dest->ZeroFramesPartial(frames, dest->frames() - frames); |
356 return frames > 0 ? 1 : 0; | 355 return frames > 0 ? 1 : 0; |
357 } | 356 } |
358 | 357 |
359 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { | 358 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { |
360 source_callback_->OnError(stream); | 359 source_callback_->OnError(stream); |
361 } | 360 } |
362 | 361 |
363 } // namespace media | 362 } // namespace media |
OLD | NEW |