Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1099)

Unified Diff: media/audio/fake_audio_consumer.h

Issue 17122006: Rejigger audio capture pipeline to work with separate main+worker threads (Mac). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace use of scoped_refptr<Worker> with simple DeleteSoon() scheme. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/fake_audio_consumer.h
diff --git a/media/audio/fake_audio_consumer.h b/media/audio/fake_audio_consumer.h
index 57da74fabfffaf0b090c1f8861052128b03116e4..36b4030b1903c00dd73e450cf410ec9932f37dbf 100644
--- a/media/audio/fake_audio_consumer.h
+++ b/media/audio/fake_audio_consumer.h
@@ -5,10 +5,9 @@
#ifndef MEDIA_AUDIO_FAKE_AUDIO_CONSUMER_H_
#define MEDIA_AUDIO_FAKE_AUDIO_CONSUMER_H_
-#include "base/cancelable_callback.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/time.h"
-#include "media/audio/audio_parameters.h"
+#include "base/callback_forward.h"
+#include "base/memory/ref_counted.h"
+#include "media/base/media_export.h"
namespace base {
class MessageLoopProxy;
@@ -16,42 +15,35 @@ class MessageLoopProxy;
namespace media {
class AudioBus;
+class AudioParameters;
// A fake audio consumer. Using a provided message loop, FakeAudioConsumer will
// simulate a real time consumer of audio data.
class MEDIA_EXPORT FakeAudioConsumer {
public:
- // |message_loop| is the loop on which the ReadCB provided to Start() will be
- // executed on. |params| is used to determine the frequency of callbacks.
- FakeAudioConsumer(const scoped_refptr<base::MessageLoopProxy>& message_loop,
+ // |worker_loop| is the loop on which the ReadCB provided to Start() will be
+ // executed on. This may or may not be the be for the same thread that
+ // invokes the Start/Stop methods.
+ // |params| is used to determine the frequency of callbacks.
+ FakeAudioConsumer(const scoped_refptr<base::MessageLoopProxy>& worker_loop,
const AudioParameters& params);
~FakeAudioConsumer();
- // Start executing |read_cb| at a regular interval. Must be called on the
- // message loop provided during construction. Stop() must be called before
- // destroying FakeAudioConsumer.
+ // Start executing |read_cb| at a regular intervals. Stop() must be called by
+ // the same thread before destroying FakeAudioConsumer.
typedef base::Callback<void(AudioBus* audio_bus)> ReadCB;
void Start(const ReadCB& read_cb);
- // Stop executing the ReadCB provided to Start(). Cancels any outstanding
- // callbacks. Safe to call multiple times. Must be called on the message
- // loop provided during construction.
+ // Stop executing the ReadCB provided to Start(). Blocks until the worker
+ // loop is not inside a ReadCB invocation. Safe to call multiple times. Must
+ // be called on the same thread that called Start().
void Stop();
private:
- // Task that regularly calls |read_cb_| according to the playback rate as
- // determined by the audio parameters given during construction. Runs on
- // |message_loop_|.
- void DoRead();
-
- scoped_refptr<base::MessageLoopProxy> message_loop_;
- ReadCB read_cb_;
- scoped_ptr<AudioBus> audio_bus_;
- base::TimeDelta buffer_duration_;
- base::TimeTicks next_read_time_;
-
- // Used to post delayed tasks to the AudioThread that we can cancel.
- base::CancelableClosure read_task_cb_;
+ // All state and implementation is kept within this class because it must hang
+ // around until tasks posted on |worker_loop| have all run (or been canceled).
+ class Worker;
+ Worker* const worker_;
DISALLOW_COPY_AND_ASSIGN(FakeAudioConsumer);
};
« no previous file with comments | « content/browser/renderer_host/media/web_contents_audio_input_stream_unittest.cc ('k') | media/audio/fake_audio_consumer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698