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

Unified Diff: media/audio/fake_audio_provider.h

Issue 922663002: Moved the fake input stream's processing onto the audio worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving browser test updates to a separate patch (this one is big enough) Created 5 years, 10 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_provider.h
diff --git a/media/audio/fake_audio_provider.h b/media/audio/fake_audio_provider.h
new file mode 100644
index 0000000000000000000000000000000000000000..96dc879cac6428bca0770b7be2814d1fc819a373
--- /dev/null
+++ b/media/audio/fake_audio_provider.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_AUDIO_FAKE_AUDIO_PROVIDER_H_
+#define MEDIA_AUDIO_FAKE_AUDIO_PROVIDER_H_
+
+#include "base/callback_forward.h"
+#include "base/memory/ref_counted.h"
+#include "media/base/media_export.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+class FilePath;
+}
+
+namespace media {
+class AudioBus;
+class AudioParameters;
+
+// A fake audio provider. Using a provided message loop, the FakeAudioProvider
+// will generate real-time audio data.
+class MEDIA_EXPORT FakeAudioProvider {
+ public:
+ // |worker_task_runner| is the task runner on which the InputCB 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.
+ FakeAudioProvider(
+ const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
+ const AudioParameters& params);
+ ~FakeAudioProvider();
+
+ void OpenInBeepMode();
+ void OpenInFileMode(const base::FilePath& path_to_wav_file);
+
+ // Start executing |input_cb| at a regular intervals. Stop() must be called
+ // by the same thread before destroying FakeAudioProvider. The callback will
+ // be called with an audio bus filled with input data.
+ typedef base::Callback<void(AudioBus* audio_bus, int buffer_size)> InputCB;
+ void Start(const InputCB& input_cb);
+
+ // Stop executing the InputCB provided to Start(). Blocks until the worker
+ // loop is not inside a InputCB invocation. Safe to call multiple times.
+ // Must be called on the same thread that called Start().
+ void Stop();
+
+ // TODO(phoglund): See TODO on FakeAudioInputStream::BeepOnce.
+ 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
+
+ private:
+ // All state and implementation is kept within this ref-counted class because
+ // cancellation of posted tasks must happen on the worker thread some time
+ // after the call to Stop() (on the main thread) returns.
+ class Worker;
+ const scoped_refptr<Worker> worker_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeAudioProvider);
+};
+
+} // namespace media
+
+#endif // MEDIA_AUDIO_FAKE_AUDIO_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698