Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 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 #ifndef MEDIA_AUDIO_FAKE_AUDIO_PROVIDER_H_ | |
| 6 #define MEDIA_AUDIO_FAKE_AUDIO_PROVIDER_H_ | |
| 7 | |
| 8 #include "base/callback_forward.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "media/base/media_export.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class SingleThreadTaskRunner; | |
| 14 class FilePath; | |
| 15 } | |
| 16 | |
| 17 namespace media { | |
| 18 class AudioBus; | |
| 19 class AudioParameters; | |
| 20 | |
| 21 // A fake audio provider. Using a provided message loop, the FakeAudioProvider | |
| 22 // will generate real-time audio data. | |
| 23 class MEDIA_EXPORT FakeAudioProvider { | |
| 24 public: | |
| 25 // |worker_task_runner| is the task runner on which the InputCB provided to | |
| 26 // Start() will be executed on. This may or may not be the be for the same | |
| 27 // thread that invokes the Start/Stop methods. | |
| 28 // |params| is used to determine the frequency of callbacks. | |
| 29 FakeAudioProvider( | |
| 30 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, | |
| 31 const AudioParameters& params); | |
| 32 ~FakeAudioProvider(); | |
| 33 | |
| 34 void OpenInBeepMode(); | |
| 35 void OpenInFileMode(const base::FilePath& path_to_wav_file); | |
| 36 | |
| 37 // Start executing |input_cb| at a regular intervals. Stop() must be called | |
| 38 // by the same thread before destroying FakeAudioProvider. The callback will | |
| 39 // be called with an audio bus filled with input data. | |
| 40 typedef base::Callback<void(AudioBus* audio_bus, int buffer_size)> InputCB; | |
| 41 void Start(const InputCB& input_cb); | |
| 42 | |
| 43 // Stop executing the InputCB provided to Start(). Blocks until the worker | |
| 44 // loop is not inside a InputCB invocation. Safe to call multiple times. | |
| 45 // Must be called on the same thread that called Start(). | |
| 46 void Stop(); | |
| 47 | |
| 48 // TODO(phoglund): See TODO on FakeAudioInputStream::BeepOnce. | |
| 49 static void BeepOnce(); | |
|
DaleCurtis
2015/02/17 23:27:49
Why static?
phoglund_chromium
2015/02/18 10:22:05
It's static because BeepOnce is called from the fa
| |
| 50 | |
| 51 private: | |
| 52 // All state and implementation is kept within this ref-counted class because | |
| 53 // cancellation of posted tasks must happen on the worker thread some time | |
| 54 // after the call to Stop() (on the main thread) returns. | |
| 55 class Worker; | |
| 56 const scoped_refptr<Worker> worker_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(FakeAudioProvider); | |
| 59 }; | |
| 60 | |
| 61 } // namespace media | |
| 62 | |
| 63 #endif // MEDIA_AUDIO_FAKE_AUDIO_PROVIDER_H_ | |
| OLD | NEW |