[MemSheriff] More sendto parameter issues.
[chromium-blink-merge.git] / media / audio / fake_audio_input_stream.h
blob1fed3052a91522ef5650efd598d6322d817bc387
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.
7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
10 #include <vector>
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h"
16 #include "base/time/time.h"
17 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_parameters.h"
19 #include "media/audio/sounds/wav_audio_handler.h"
21 namespace media {
23 class AudioBus;
24 class AudioManagerBase;
26 // This class can either generate a beep sound or play audio from a file.
27 class MEDIA_EXPORT FakeAudioInputStream
28 : public AudioInputStream {
29 public:
30 static AudioInputStream* MakeFakeStream(
31 AudioManagerBase* manager, const AudioParameters& params);
33 bool Open() override;
34 void Start(AudioInputCallback* callback) override;
35 void Stop() override;
36 void Close() override;
37 double GetMaxVolume() override;
38 void SetVolume(double volume) override;
39 double GetVolume() override;
40 bool IsMuted() override;
41 void SetAutomaticGainControl(bool enabled) override;
42 bool GetAutomaticGainControl() override;
44 // Generate one beep sound. This method is called by
45 // FakeVideoCaptureDevice to test audio/video synchronization.
46 // This is a static method because FakeVideoCaptureDevice is
47 // disconnected from an audio device. This means only one instance of
48 // this class gets to respond, which is okay because we assume there's
49 // only one stream for this testing purpose.
50 // TODO(hclam): Make this non-static. To do this we'll need to fix
51 // crbug.com/159053 such that video capture device is aware of audio
52 // input stream.
53 static void BeepOnce();
55 private:
56 FakeAudioInputStream(AudioManagerBase* manager,
57 const AudioParameters& params);
58 ~FakeAudioInputStream() override;
60 void DoCallback();
62 // Opens this stream reading from a |wav_filename| rather than beeping.
63 void OpenInFileMode(const base::FilePath& wav_filename);
65 // Returns true if the device is playing from a file; false if we're beeping.
66 bool PlayingFromFile();
68 void PlayFileLooping();
69 void PlayBeep();
71 AudioManagerBase* audio_manager_;
72 AudioInputCallback* callback_;
73 scoped_ptr<uint8[]> buffer_;
74 int buffer_size_;
75 AudioParameters params_;
76 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
77 base::TimeTicks last_callback_time_;
78 base::TimeDelta callback_interval_;
79 base::TimeDelta interval_from_last_beep_;
80 int beep_duration_in_buffers_;
81 int beep_generated_in_buffers_;
82 int beep_period_in_frames_;
83 scoped_ptr<media::AudioBus> audio_bus_;
84 scoped_ptr<uint8[]> wav_file_data_;
85 scoped_ptr<media::WavAudioHandler> wav_audio_handler_;
86 int wav_file_read_pos_;
88 // Allows us to run tasks on the FakeAudioInputStream instance which are
89 // bound by its lifetime.
90 base::WeakPtrFactory<FakeAudioInputStream> weak_factory_;
92 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream);
95 } // namespace media
97 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_