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. 4 // 5 // A fake implementation of AudioInputStream, useful for testing purpose. 6 7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ 8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ 9 10 #include <vector> 11 12 #include "base/memory/scoped_ptr.h" 13 #include "base/synchronization/lock.h" 14 #include "base/threading/thread.h" 15 #include "base/time/time.h" 16 #include "media/audio/audio_io.h" 17 #include "media/audio/audio_parameters.h" 18 19 namespace media { 20 21 class AudioManagerBase; 22 23 class MEDIA_EXPORT FakeAudioInputStream 24 : public AudioInputStream { 25 public: 26 static AudioInputStream* MakeFakeStream(AudioManagerBase* manager, 27 const AudioParameters& params); 28 29 virtual bool Open() OVERRIDE; 30 virtual void Start(AudioInputCallback* callback) OVERRIDE; 31 virtual void Stop() OVERRIDE; 32 virtual void Close() OVERRIDE; 33 virtual double GetMaxVolume() OVERRIDE; 34 virtual void SetVolume(double volume) OVERRIDE; 35 virtual double GetVolume() OVERRIDE; 36 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; 37 virtual bool GetAutomaticGainControl() OVERRIDE; 38 39 // Generate one beep sound. This method is called by 40 // FakeVideoCaptureDevice to test audio/video synchronization. 41 // This is a static method because FakeVideoCaptureDevice is 42 // disconnected from an audio device. This means only one instance of 43 // this class gets to respond, which is okay because we assume there's 44 // only one stream for this testing purpose. 45 // TODO(hclam): Make this non-static. To do this we'll need to fix 46 // crbug.com/159053 such that video capture device is aware of audio 47 // input stream. 48 static void BeepOnce(); 49 50 private: 51 FakeAudioInputStream(AudioManagerBase* manager, 52 const AudioParameters& params); 53 54 virtual ~FakeAudioInputStream(); 55 56 void DoCallback(); 57 58 AudioManagerBase* audio_manager_; 59 AudioInputCallback* callback_; 60 scoped_ptr<uint8[]> buffer_; 61 int buffer_size_; 62 AudioParameters params_; 63 base::Thread thread_; 64 base::TimeTicks last_callback_time_; 65 base::TimeDelta callback_interval_; 66 int beep_duration_in_buffers_; 67 int beep_generated_in_buffers_; 68 int beep_period_in_frames_; 69 int frames_elapsed_; 70 71 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream); 72 }; 73 74 } // namespace media 75 76 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ 77