cc: Remove tile and scale specific code from raster source
[chromium-blink-merge.git] / media / base / fake_audio_render_callback.h
blob695365f98a7de89710fbf09fb8edffe30f7f747b
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_
6 #define MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_
8 #include "media/base/audio_converter.h"
9 #include "media/base/audio_renderer_sink.h"
10 #include "testing/gmock/include/gmock/gmock.h"
12 namespace media {
14 // Fake RenderCallback which will fill each request with a sine wave. Sine
15 // state is kept across callbacks. State can be reset to default via reset().
16 // Also provide an interface to AudioTransformInput.
17 class FakeAudioRenderCallback
18 : public AudioRendererSink::RenderCallback,
19 public AudioConverter::InputCallback {
20 public:
21 // The function used to fulfill Render() is f(x) = sin(2 * PI * x * |step|),
22 // where x = [|number_of_frames| * m, |number_of_frames| * (m + 1)] and m =
23 // the number of Render() calls fulfilled thus far.
24 explicit FakeAudioRenderCallback(double step);
25 virtual ~FakeAudioRenderCallback();
27 // Renders a sine wave into the provided audio data buffer. If |half_fill_|
28 // is set, will only fill half the buffer.
29 virtual int Render(AudioBus* audio_bus,
30 int audio_delay_milliseconds) override;
31 MOCK_METHOD0(OnRenderError, void());
33 // AudioTransform::ProvideAudioTransformInput implementation.
34 virtual double ProvideInput(AudioBus* audio_bus,
35 base::TimeDelta buffer_delay) override;
37 // Toggles only filling half the requested amount during Render().
38 void set_half_fill(bool half_fill) { half_fill_ = half_fill; }
40 // Reset the sine state to initial value.
41 void reset() { x_ = 0; }
43 // Returns the last |audio_delay_milliseconds| provided to Render() or -1 if
44 // no Render() call occurred.
45 int last_audio_delay_milliseconds() { return last_audio_delay_milliseconds_; }
47 // Set volume information used by ProvideAudioTransformInput().
48 void set_volume(double volume) { volume_ = volume; }
50 private:
51 bool half_fill_;
52 double x_;
53 double step_;
54 int last_audio_delay_milliseconds_;
55 double volume_;
57 DISALLOW_COPY_AND_ASSIGN(FakeAudioRenderCallback);
60 } // namespace media
62 #endif // MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_