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_renderer_sink.h"
9 #include "testing/gmock/include/gmock/gmock.h"
13 // Fake RenderCallback which will fill each request with a sine wave. Sine
14 // state is kept across callbacks. State can be reset to default via reset().
15 class FakeAudioRenderCallback
: public AudioRendererSink::RenderCallback
{
17 // The function used to fulfill Render() is f(x) = sin(2 * PI * x * |step|),
18 // where x = [|number_of_frames| * m, |number_of_frames| * (m + 1)] and m =
19 // the number of Render() calls fulfilled thus far.
20 explicit FakeAudioRenderCallback(double step
);
21 virtual ~FakeAudioRenderCallback();
23 // Renders a sine wave into the provided audio data buffer. If |half_fill_|
24 // is set, will only fill half the buffer.
25 int Render(AudioBus
* audio_bus
, int audio_delay_milliseconds
) OVERRIDE
;
26 MOCK_METHOD0(OnRenderError
, void());
28 // Toggles only filling half the requested amount during Render().
29 void set_half_fill(bool half_fill
) { half_fill_
= half_fill
; }
31 // Reset the sine state to initial value.
32 void reset() { x_
= 0; }
34 // Returns the last |audio_delay_milliseconds| provided to Render() or -1 if
35 // no Render() call occurred.
36 int last_audio_delay_milliseconds() { return last_audio_delay_milliseconds_
; }
42 int last_audio_delay_milliseconds_
;
44 DISALLOW_COPY_AND_ASSIGN(FakeAudioRenderCallback
);
49 #endif // MEDIA_BASE_FAKE_AUDIO_RENDER_CALLBACK_H_