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 #ifndef MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ | 5 #ifndef MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ |
6 #define MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ | 6 #define MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "media/base/audio_converter.h" | 11 #include "media/base/audio_converter.h" |
12 #include "media/base/audio_renderer_sink.h" | 12 #include "media/base/audio_renderer_sink.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 // Fake RenderCallback which will fill each request with a sine wave. Sine | 17 // Fake RenderCallback which will fill each request with a sine wave. Sine |
18 // state is kept across callbacks. State can be reset to default via reset(). | 18 // state is kept across callbacks. State can be reset to default via reset(). |
19 // Also provide an interface to AudioTransformInput. | 19 // Also provide an interface to AudioTransformInput. |
20 class FakeAudioRenderCallback | 20 class FakeAudioRenderCallback |
21 : public AudioRendererSink::RenderCallback, | 21 : public AudioRendererSink::RenderCallback, |
22 public AudioConverter::InputCallback { | 22 public AudioConverter::InputCallback { |
23 public: | 23 public: |
24 // The function used to fulfill Render() is f(x) = sin(2 * PI * x * |step|), | 24 // The function used to fulfill Render() is f(x) = sin(2 * PI * x * |step|), |
25 // where x = [|number_of_frames| * m, |number_of_frames| * (m + 1)] and m = | 25 // where x = [|number_of_frames| * m, |number_of_frames| * (m + 1)] and m = |
26 // the number of Render() calls fulfilled thus far. | 26 // the number of Render() calls fulfilled thus far. |
27 explicit FakeAudioRenderCallback(double step); | 27 FakeAudioRenderCallback(double step, int sample_rate); |
28 ~FakeAudioRenderCallback() override; | 28 ~FakeAudioRenderCallback() override; |
29 | 29 |
30 // Renders a sine wave into the provided audio data buffer. If |half_fill_| | 30 // Renders a sine wave into the provided audio data buffer. If |half_fill_| |
31 // is set, will only fill half the buffer. | 31 // is set, will only fill half the buffer. |
32 int Render(base::TimeDelta delay, | 32 int Render(base::TimeDelta delay, |
33 base::TimeTicks delay_timestamp, | 33 base::TimeTicks delay_timestamp, |
34 int prior_frames_skipped, | 34 int prior_frames_skipped, |
35 AudioBus* audio_bus) override; | 35 AudioBus* audio_bus) override; |
36 MOCK_METHOD0(OnRenderError, void()); | 36 MOCK_METHOD0(OnRenderError, void()); |
37 | 37 |
38 // AudioTransform::ProvideAudioTransformInput implementation. | 38 // AudioTransform::ProvideAudioTransformInput implementation. |
39 double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override; | 39 double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override; |
40 | 40 |
41 // Toggles only filling half the requested amount during Render(). | 41 // Toggles only filling half the requested amount during Render(). |
42 void set_half_fill(bool half_fill) { half_fill_ = half_fill; } | 42 void set_half_fill(bool half_fill) { half_fill_ = half_fill; } |
43 | 43 |
44 // Reset the sine state to initial value. | 44 // Reset the sine state to initial value. |
45 void reset() { x_ = 0; } | 45 void reset() { x_ = 0; } |
46 | 46 |
47 // Returns the last |frames_delayed| provided to Render() or -1 if | 47 // Returns the last |delay| provided to Render() or base::TimeDelta::Max() |
48 // no Render() call occurred. | 48 // if no Render() call occurred. |
49 int last_frames_delayed() const { return last_frames_delayed_; } | 49 base::TimeDelta last_delay() const { return last_delay_; } |
50 | 50 |
51 // Set volume information used by ProvideAudioTransformInput(). | 51 // Set volume information used by ProvideAudioTransformInput(). |
52 void set_volume(double volume) { volume_ = volume; } | 52 void set_volume(double volume) { volume_ = volume; } |
53 | 53 |
54 int last_channel_count() const { return last_channel_count_; } | 54 int last_channel_count() const { return last_channel_count_; } |
55 | 55 |
56 private: | 56 private: |
57 int RenderInternal(AudioBus* audio_bus, | 57 int RenderInternal(AudioBus* audio_bus, base::TimeDelta delay, double volume); |
58 uint32_t frames_delayed, | |
59 double volume); | |
60 | 58 |
61 bool half_fill_; | 59 bool half_fill_; |
62 double x_; | 60 double x_; |
63 double step_; | 61 double step_; |
64 int last_frames_delayed_; | 62 base::TimeDelta last_delay_; |
65 int last_channel_count_; | 63 int last_channel_count_; |
66 double volume_; | 64 double volume_; |
| 65 int sample_rate_; |
67 | 66 |
68 DISALLOW_COPY_AND_ASSIGN(FakeAudioRenderCallback); | 67 DISALLOW_COPY_AND_ASSIGN(FakeAudioRenderCallback); |
69 }; | 68 }; |
70 | 69 |
71 } // namespace media | 70 } // namespace media |
72 | 71 |
73 #endif // MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ | 72 #endif // MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ |
OLD | NEW |