1 // Copyright 2013 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. 4 5 #ifndef MEDIA_BASE_FAKE_AUDIO_RENDERER_SINK_H_ 6 #define MEDIA_BASE_FAKE_AUDIO_RENDERER_SINK_H_ 7 8 #include "media/audio/audio_parameters.h" 9 #include "media/base/audio_renderer_sink.h" 10 11 namespace media { 12 13 class FakeAudioRendererSink : public AudioRendererSink { 14 public: 15 enum State { 16 kUninitialized, 17 kInitialized, 18 kStarted, 19 kPaused, 20 kPlaying, 21 kStopped 22 }; 23 24 FakeAudioRendererSink(); 25 26 virtual void Initialize(const AudioParameters& params, 27 RenderCallback* callback) OVERRIDE; 28 virtual void Start() OVERRIDE; 29 virtual void Stop() OVERRIDE; 30 virtual void Pause() OVERRIDE; 31 virtual void Play() OVERRIDE; 32 virtual bool SetVolume(double volume) OVERRIDE; 33 34 // Attempts to call Render() on the callback provided to 35 // Initialize() with |dest| and |audio_delay_milliseconds|. 36 // Returns true and sets |frames_written| to the return value of the 37 // Render() call. 38 // Returns false if this object is in a state where calling Render() 39 // should not occur. (i.e., in the kPaused or kStopped state.) The 40 // value of |frames_written| is undefined if false is returned. 41 bool Render(AudioBus* dest, int audio_delay_milliseconds, 42 int* frames_written); 43 void OnRenderError(); 44 45 State state() const { return state_; } 46 47 protected: 48 virtual ~FakeAudioRendererSink(); 49 50 private: 51 void ChangeState(State new_state); 52 53 State state_; 54 RenderCallback* callback_; 55 56 DISALLOW_COPY_AND_ASSIGN(FakeAudioRendererSink); 57 }; 58 59 } // namespace media 60 61 #endif // MEDIA_BASE_FAKE_AUDIO_RENDERER_SINK_H_ 62