Remove calls to window.open in OOP PDF js
[chromium-blink-merge.git] / media / audio / fake_audio_input_stream.h
blobfafcca330dd809f5efe73effaab9ba4bfc9a949c
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"
20 #include "media/base/audio_converter.h"
22 namespace media {
24 class AudioBus;
25 class AudioManagerBase;
27 // This class can either generate a beep sound or play audio from a file.
28 class MEDIA_EXPORT FakeAudioInputStream
29 : public AudioInputStream, AudioConverter::InputCallback {
30 public:
31 static AudioInputStream* MakeFakeStream(
32 AudioManagerBase* manager, const AudioParameters& params);
34 bool Open() override;
35 void Start(AudioInputCallback* callback) override;
36 void Stop() override;
37 void Close() override;
38 double GetMaxVolume() override;
39 void SetVolume(double volume) override;
40 double GetVolume() override;
41 bool IsMuted() override;
42 bool SetAutomaticGainControl(bool enabled) override;
43 bool GetAutomaticGainControl() override;
45 // Generate one beep sound. This method is called by
46 // FakeVideoCaptureDevice to test audio/video synchronization.
47 // This is a static method because FakeVideoCaptureDevice is
48 // disconnected from an audio device. This means only one instance of
49 // this class gets to respond, which is okay because we assume there's
50 // only one stream for this testing purpose.
51 // TODO(hclam): Make this non-static. To do this we'll need to fix
52 // crbug.com/159053 such that video capture device is aware of audio
53 // input stream.
54 static void BeepOnce();
56 private:
57 FakeAudioInputStream(AudioManagerBase* manager,
58 const AudioParameters& params);
59 ~FakeAudioInputStream() override;
61 void DoCallback();
63 // Opens this stream reading from a |wav_filename| rather than beeping.
64 void OpenInFileMode(const base::FilePath& wav_filename);
66 // Returns true if the device is playing from a file; false if we're beeping.
67 bool PlayingFromFile();
69 void PlayFile();
70 void PlayBeep();
72 AudioManagerBase* audio_manager_;
73 AudioInputCallback* callback_;
74 scoped_ptr<uint8[]> buffer_;
75 int buffer_size_;
76 AudioParameters params_;
77 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
78 base::TimeTicks last_callback_time_;
79 base::TimeDelta callback_interval_;
80 base::TimeDelta interval_from_last_beep_;
81 int beep_duration_in_buffers_;
82 int beep_generated_in_buffers_;
83 int beep_period_in_frames_;
84 scoped_ptr<media::AudioBus> audio_bus_;
85 scoped_ptr<uint8[]> wav_file_data_;
86 scoped_ptr<media::WavAudioHandler> wav_audio_handler_;
87 scoped_ptr<media::AudioConverter> file_audio_converter_;
88 int wav_file_read_pos_;
90 // Allows us to run tasks on the FakeAudioInputStream instance which are
91 // bound by its lifetime.
92 base::WeakPtrFactory<FakeAudioInputStream> weak_factory_;
94 // If running in file mode, this provides audio data from wav_audio_handler_.
95 double ProvideInput(AudioBus* audio_bus,
96 base::TimeDelta buffer_delay) override;
98 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream);
101 } // namespace media
103 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_