OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // A fake implementation of AudioInputStream, useful for testing purpose. | 5 // A fake implementation of AudioInputStream, useful for testing purpose. |
6 | 6 |
7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ | 7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ |
8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ | 8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "media/audio/audio_io.h" | 17 #include "media/audio/audio_io.h" |
18 #include "media/audio/audio_parameters.h" | 18 #include "media/audio/audio_parameters.h" |
19 #include "media/audio/sounds/wav_audio_handler.h" | 19 #include "media/audio/sounds/wav_audio_handler.h" |
| 20 #include "media/base/audio_converter.h" |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 | 23 |
23 class AudioBus; | 24 class AudioBus; |
24 class AudioManagerBase; | 25 class AudioManagerBase; |
25 | 26 |
26 // This class can either generate a beep sound or play audio from a file. | 27 // This class can either generate a beep sound or play audio from a file. |
27 class MEDIA_EXPORT FakeAudioInputStream | 28 class MEDIA_EXPORT FakeAudioInputStream |
28 : public AudioInputStream { | 29 : public AudioInputStream, AudioConverter::InputCallback { |
29 public: | 30 public: |
30 static AudioInputStream* MakeFakeStream( | 31 static AudioInputStream* MakeFakeStream( |
31 AudioManagerBase* manager, const AudioParameters& params); | 32 AudioManagerBase* manager, const AudioParameters& params); |
32 | 33 |
33 bool Open() override; | 34 bool Open() override; |
34 void Start(AudioInputCallback* callback) override; | 35 void Start(AudioInputCallback* callback) override; |
35 void Stop() override; | 36 void Stop() override; |
36 void Close() override; | 37 void Close() override; |
37 double GetMaxVolume() override; | 38 double GetMaxVolume() override; |
38 void SetVolume(double volume) override; | 39 void SetVolume(double volume) override; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 77 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
77 base::TimeTicks last_callback_time_; | 78 base::TimeTicks last_callback_time_; |
78 base::TimeDelta callback_interval_; | 79 base::TimeDelta callback_interval_; |
79 base::TimeDelta interval_from_last_beep_; | 80 base::TimeDelta interval_from_last_beep_; |
80 int beep_duration_in_buffers_; | 81 int beep_duration_in_buffers_; |
81 int beep_generated_in_buffers_; | 82 int beep_generated_in_buffers_; |
82 int beep_period_in_frames_; | 83 int beep_period_in_frames_; |
83 scoped_ptr<media::AudioBus> audio_bus_; | 84 scoped_ptr<media::AudioBus> audio_bus_; |
84 scoped_ptr<uint8[]> wav_file_data_; | 85 scoped_ptr<uint8[]> wav_file_data_; |
85 scoped_ptr<media::WavAudioHandler> wav_audio_handler_; | 86 scoped_ptr<media::WavAudioHandler> wav_audio_handler_; |
| 87 scoped_ptr<media::AudioConverter> file_audio_converter_; |
86 int wav_file_read_pos_; | 88 int wav_file_read_pos_; |
87 | 89 |
88 // Allows us to run tasks on the FakeAudioInputStream instance which are | 90 // Allows us to run tasks on the FakeAudioInputStream instance which are |
89 // bound by its lifetime. | 91 // bound by its lifetime. |
90 base::WeakPtrFactory<FakeAudioInputStream> weak_factory_; | 92 base::WeakPtrFactory<FakeAudioInputStream> weak_factory_; |
91 | 93 |
| 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; |
| 97 |
92 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream); | 98 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream); |
93 }; | 99 }; |
94 | 100 |
95 } // namespace media | 101 } // namespace media |
96 | 102 |
97 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ | 103 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ |
OLD | NEW |