| 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 <memory> | 10 #include <memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
| 16 #include "media/audio/fake_audio_worker.h" | 16 #include "media/audio/fake_audio_worker.h" |
| 17 #include "media/base/audio_parameters.h" | 17 #include "media/base/audio_parameters.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 class AudioBus; | 21 class AudioBus; |
| 22 class AudioManagerBase; | |
| 23 class SimpleSource; | 22 class SimpleSource; |
| 24 | 23 |
| 25 // This class acts as a fake audio input stream. The default is to generate a | 24 // 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, | 25 // 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 | 26 // in which case the indicated .wav file will be read and played into the |
| 28 // stream. | 27 // stream. |
| 29 class MEDIA_EXPORT FakeAudioInputStream | 28 class MEDIA_EXPORT FakeAudioInputStream |
| 30 : public AudioInputStream { | 29 : public AudioInputStream { |
| 31 public: | 30 public: |
| 32 static AudioInputStream* MakeFakeStream( | 31 static AudioInputStream* MakeFakeStream( |
| 33 AudioManagerBase* manager, const AudioParameters& params); | 32 const scoped_refptr<base::SingleThreadTaskRunner>& audio_task_runner, |
| 33 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
| 34 const AudioParameters& params); |
| 34 | 35 |
| 35 bool Open() override; | 36 bool Open() override; |
| 36 void Start(AudioInputCallback* callback) override; | 37 void Start(AudioInputCallback* callback) override; |
| 37 void Stop() override; | 38 void Stop() override; |
| 38 void Close() override; | 39 void Close() override; |
| 39 double GetMaxVolume() override; | 40 double GetMaxVolume() override; |
| 40 void SetVolume(double volume) override; | 41 void SetVolume(double volume) override; |
| 41 double GetVolume() override; | 42 double GetVolume() override; |
| 42 bool IsMuted() override; | 43 bool IsMuted() override; |
| 43 bool SetAutomaticGainControl(bool enabled) override; | 44 bool SetAutomaticGainControl(bool enabled) override; |
| 44 bool GetAutomaticGainControl() override; | 45 bool GetAutomaticGainControl() override; |
| 45 | 46 |
| 46 // Generate one beep sound. This method is called by FakeVideoCaptureDevice to | 47 // Generate one beep sound. This method is called by FakeVideoCaptureDevice to |
| 47 // test audio/video synchronization. This is a static method because | 48 // test audio/video synchronization. This is a static method because |
| 48 // FakeVideoCaptureDevice is disconnected from an audio device. This means | 49 // 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 // 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 // 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 // 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 // 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 // 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 | 55 // crbug.com/159053 such that video capture device is aware of audio |
| 55 // input stream. | 56 // input stream. |
| 56 static void BeepOnce(); | 57 static void BeepOnce(); |
| 57 | 58 |
| 58 private: | 59 private: |
| 59 FakeAudioInputStream(AudioManagerBase* manager, | 60 FakeAudioInputStream( |
| 60 const AudioParameters& params); | 61 const scoped_refptr<base::SingleThreadTaskRunner>& audio_task_runner, |
| 62 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
| 63 const AudioParameters& params); |
| 61 ~FakeAudioInputStream() override; | 64 ~FakeAudioInputStream() override; |
| 62 | 65 |
| 63 std::unique_ptr<AudioOutputStream::AudioSourceCallback> ChooseSource(); | 66 std::unique_ptr<AudioOutputStream::AudioSourceCallback> ChooseSource(); |
| 64 void ReadAudioFromSource(); | 67 void ReadAudioFromSource(); |
| 65 | 68 |
| 66 AudioManagerBase* audio_manager_; | |
| 67 AudioInputCallback* callback_; | 69 AudioInputCallback* callback_; |
| 68 FakeAudioWorker fake_audio_worker_; | 70 FakeAudioWorker fake_audio_worker_; |
| 69 AudioParameters params_; | 71 const scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; |
| 72 const scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; |
| 73 const AudioParameters params_; |
| 70 | 74 |
| 71 std::unique_ptr<AudioOutputStream::AudioSourceCallback> audio_source_; | 75 std::unique_ptr<AudioOutputStream::AudioSourceCallback> audio_source_; |
| 72 std::unique_ptr<media::AudioBus> audio_bus_; | 76 std::unique_ptr<media::AudioBus> audio_bus_; |
| 73 | 77 |
| 74 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream); | 78 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream); |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 } // namespace media | 81 } // namespace media |
| 78 | 82 |
| 79 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ | 83 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ |
| OLD | NEW |