OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef MEDIA_AUDIO_FAKE_AUDIO_CONSUMER_H_ | 5 #ifndef MEDIA_AUDIO_FAKE_AUDIO_WORKER_H_ |
6 #define MEDIA_AUDIO_FAKE_AUDIO_CONSUMER_H_ | 6 #define MEDIA_AUDIO_FAKE_AUDIO_WORKER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "media/base/media_export.h" | 10 #include "media/base/media_export.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class SingleThreadTaskRunner; | 13 class SingleThreadTaskRunner; |
14 } | 14 } |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 class AudioBus; | 17 class AudioBus; |
18 class AudioParameters; | 18 class AudioParameters; |
19 | 19 |
20 // A fake audio consumer. Using a provided message loop, FakeAudioConsumer will | 20 // A fake audio worker. Using a provided message loop, FakeAudioWorker will |
21 // simulate a real time consumer of audio data. | 21 // call back the provided callback like a real audio consumer or producer would. |
22 class MEDIA_EXPORT FakeAudioConsumer { | 22 class MEDIA_EXPORT FakeAudioWorker { |
23 public: | 23 public: |
24 // |worker_task_runner| is the task runner on which the ReadCB provided to | 24 // |worker_task_runner| is the task runner on which the WorkerCB provided to |
25 // Start() will be executed on. This may or may not be the be for the same | 25 // Start() will be executed on. This may or may not be the be for the same |
26 // thread that invokes the Start/Stop methods. | 26 // thread that invokes the Start/Stop methods. |
27 // |params| is used to determine the frequency of callbacks. | 27 // |params| is used to determine the frequency of callbacks. |
28 FakeAudioConsumer( | 28 FakeAudioWorker( |
29 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, | 29 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
30 const AudioParameters& params); | 30 const AudioParameters& params); |
31 ~FakeAudioConsumer(); | 31 ~FakeAudioWorker(); |
32 | 32 |
33 // Start executing |read_cb| at a regular intervals. Stop() must be called by | 33 // Start executing |worker_cb| at a regular intervals. Stop() must be called |
34 // the same thread before destroying FakeAudioConsumer. | 34 // by the same thread before destroying FakeAudioWorker. |
35 typedef base::Callback<void(AudioBus* audio_bus)> ReadCB; | 35 typedef base::Callback<void()> WorkerCB; |
DaleCurtis
2015/02/18 19:04:49
Delete typedef in favor of base::Closure.
phoglund_chromium
2015/02/19 15:44:11
Done.
| |
36 void Start(const ReadCB& read_cb); | 36 void Start(const WorkerCB& worker_cb); |
37 | 37 |
38 // Stop executing the ReadCB provided to Start(). Blocks until the worker | 38 // Stop executing the WorkerCB provided to Start(). Blocks until the worker |
39 // loop is not inside a ReadCB invocation. Safe to call multiple times. Must | 39 // loop is not inside a WorkerCB invocation. Safe to call multiple times. |
40 // be called on the same thread that called Start(). | 40 // Must be called on the same thread that called Start(). |
41 void Stop(); | 41 void Stop(); |
42 | 42 |
43 private: | 43 private: |
44 // All state and implementation is kept within this ref-counted class because | 44 // All state and implementation is kept within this ref-counted class because |
45 // cancellation of posted tasks must happen on the worker thread some time | 45 // cancellation of posted tasks must happen on the worker thread some time |
46 // after the call to Stop() (on the main thread) returns. | 46 // after the call to Stop() (on the main thread) returns. |
47 class Worker; | 47 class Worker; |
48 const scoped_refptr<Worker> worker_; | 48 const scoped_refptr<Worker> worker_; |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(FakeAudioConsumer); | 50 DISALLOW_COPY_AND_ASSIGN(FakeAudioWorker); |
51 }; | 51 }; |
52 | 52 |
53 } // namespace media | 53 } // namespace media |
54 | 54 |
55 #endif // MEDIA_AUDIO_FAKE_AUDIO_CONSUMER_H_ | 55 #endif // MEDIA_AUDIO_FAKE_AUDIO_WORKER_H_ |
OLD | NEW |