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 // A fake implementation of AudioInputStream, useful for testing purpose.
7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
12 #include "base/callback_forward.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_parameters.h"
16 #include "media/audio/fake_audio_worker.h"
22 class AudioManagerBase
;
25 // This class acts as a fake audio input stream. The default is to generate a
26 // beeping sound unless --use-file-for-fake-audio-capture=<file> is specified,
27 // in which case the indicated .wav file will be read and played into the
29 class MEDIA_EXPORT FakeAudioInputStream
30 : public AudioInputStream
{
32 static AudioInputStream
* MakeFakeStream(
33 AudioManagerBase
* manager
, const AudioParameters
& params
);
36 void Start(AudioInputCallback
* callback
) override
;
38 void Close() override
;
39 double GetMaxVolume() override
;
40 void SetVolume(double volume
) override
;
41 double GetVolume() override
;
42 bool IsMuted() override
;
43 bool SetAutomaticGainControl(bool enabled
) override
;
44 bool GetAutomaticGainControl() override
;
46 // Generate one beep sound. This method is called by FakeVideoCaptureDevice to
47 // test audio/video synchronization. This is a static method because
48 // FakeVideoCaptureDevice is disconnected from an audio device. This means
49 // only one instance of this class gets to respond, which is okay because we
50 // assume there's only one stream for this testing purpose. Furthermore this
51 // method will do nothing if --use-file-for-fake-audio-capture is specified
52 // since the input stream will be playing from a file instead of beeping.
53 // TODO(hclam): Make this non-static. To do this we'll need to fix
54 // crbug.com/159053 such that video capture device is aware of audio
56 static void BeepOnce();
59 FakeAudioInputStream(AudioManagerBase
* manager
,
60 const AudioParameters
& params
);
61 ~FakeAudioInputStream() override
;
63 scoped_ptr
<AudioOutputStream::AudioSourceCallback
> ChooseSource();
64 void ReadAudioFromSource();
66 AudioManagerBase
* audio_manager_
;
67 AudioInputCallback
* callback_
;
68 FakeAudioWorker fake_audio_worker_
;
69 AudioParameters params_
;
71 scoped_ptr
<AudioOutputStream::AudioSourceCallback
> audio_source_
;
72 scoped_ptr
<media::AudioBus
> audio_bus_
;
74 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream
);
79 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_