| 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 <vector> | |
| 9 | |
| 10 #include "media/base/audio_renderer_sink.h" | 8 #include "media/base/audio_renderer_sink.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 12 | 10 |
| 13 namespace media { | 11 namespace media { |
| 14 | 12 |
| 15 // Fake RenderCallback which will fill each request with a sine wave. Sine | 13 // Fake RenderCallback which will fill each request with a sine wave. Sine |
| 16 // state is kept across callbacks. State can be reset to default via reset(). | 14 // state is kept across callbacks. State can be reset to default via reset(). |
| 17 class FakeAudioRenderCallback : public AudioRendererSink::RenderCallback { | 15 class FakeAudioRenderCallback : public AudioRendererSink::RenderCallback { |
| 18 public: | 16 public: |
| 19 // The function used to fulfill Render() is f(x) = sin(2 * PI * x * |step|), | 17 // The function used to fulfill Render() is f(x) = sin(2 * PI * x * |step|), |
| 20 // where x = [|number_of_frames| * m, |number_of_frames| * (m + 1)] and m = | 18 // where x = [|number_of_frames| * m, |number_of_frames| * (m + 1)] and m = |
| 21 // the number of Render() calls fulfilled thus far. | 19 // the number of Render() calls fulfilled thus far. |
| 22 explicit FakeAudioRenderCallback(double step); | 20 explicit FakeAudioRenderCallback(double step); |
| 23 virtual ~FakeAudioRenderCallback(); | 21 virtual ~FakeAudioRenderCallback(); |
| 24 | 22 |
| 25 // Renders a sine wave into the provided audio data buffer. If |half_fill_| | 23 // Renders a sine wave into the provided audio data buffer. If |half_fill_| |
| 26 // is set, will only fill half the buffer. | 24 // is set, will only fill half the buffer. |
| 27 int Render(const std::vector<float*>& audio_data, int number_of_frames, | 25 int Render(AudioBus* audio_bus, int number_of_frames, |
| 28 int audio_delay_milliseconds) OVERRIDE; | 26 int audio_delay_milliseconds) OVERRIDE; |
| 29 MOCK_METHOD0(OnRenderError, void()); | 27 MOCK_METHOD0(OnRenderError, void()); |
| 30 | 28 |
| 31 // Toggles only filling half the requested amount during Render(). | 29 // Toggles only filling half the requested amount during Render(). |
| 32 void set_half_fill(bool half_fill) { half_fill_ = half_fill; } | 30 void set_half_fill(bool half_fill) { half_fill_ = half_fill; } |
| 33 | 31 |
| 34 // Reset the sine state to initial value. | 32 // Reset the sine state to initial value. |
| 35 void reset() { x_ = 0; } | 33 void reset() { x_ = 0; } |
| 36 | 34 |
| 37 private: | 35 private: |
| 38 bool half_fill_; | 36 bool half_fill_; |
| 39 double x_; | 37 double x_; |
| 40 double step_; | 38 double step_; |
| 41 | 39 |
| 42 DISALLOW_COPY_AND_ASSIGN(FakeAudioRenderCallback); | 40 DISALLOW_COPY_AND_ASSIGN(FakeAudioRenderCallback); |
| 43 }; | 41 }; |
| 44 | 42 |
| 45 } // namespace media | 43 } // namespace media |
| 46 | 44 |
| 47 #endif // MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ | 45 #endif // MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_ |
| OLD | NEW |