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
3 // found in the LICENSE file.
5 #ifndef MEDIA_AUDIO_FAKE_AUDIO_WORKER_H_
6 #define MEDIA_AUDIO_FAKE_AUDIO_WORKER_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/ref_counted.h"
10 #include "media/base/media_export.h"
13 class SingleThreadTaskRunner
;
18 class AudioParameters
;
20 // A fake audio worker. Using a provided message loop, FakeAudioWorker will
21 // call back the provided callback like a real audio consumer or producer would.
22 class MEDIA_EXPORT FakeAudioWorker
{
24 // |worker_task_runner| is the task runner on which the closure provided to
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.
27 // |params| is used to determine the frequency of callbacks.
29 const scoped_refptr
<base::SingleThreadTaskRunner
>& worker_task_runner
,
30 const AudioParameters
& params
);
33 // Start executing |worker_cb| at a regular intervals. Stop() must be called
34 // by the same thread before destroying FakeAudioWorker.
35 void Start(const base::Closure
& worker_cb
);
37 // Stop executing the closure provided to Start(). Blocks until the worker
38 // loop is not inside a closure invocation. Safe to call multiple times.
39 // Must be called on the same thread that called Start().
43 // All state and implementation is kept within this ref-counted class because
44 // cancellation of posted tasks must happen on the worker thread some time
45 // after the call to Stop() (on the main thread) returns.
47 const scoped_refptr
<Worker
> worker_
;
49 DISALLOW_COPY_AND_ASSIGN(FakeAudioWorker
);
54 #endif // MEDIA_AUDIO_FAKE_AUDIO_WORKER_H_