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

Unified Diff: content/renderer/media/audio_ipc_factory.h

Issue 2821203005: Add a mojo implementation of AudioOutputIPC. (Closed)
Patch Set: Fix test issues Created 3 years, 7 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: content/renderer/media/audio_ipc_factory.h
diff --git a/content/renderer/media/audio_ipc_factory.h b/content/renderer/media/audio_ipc_factory.h
new file mode 100644
index 0000000000000000000000000000000000000000..355fd2f529be6f2bb0a74e2e74c2d717a6e4e894
--- /dev/null
+++ b/content/renderer/media/audio_ipc_factory.h
@@ -0,0 +1,85 @@
+// Copyright 2017 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 CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_
+#define CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_
+
+#include <memory>
+
+#include "base/containers/flat_map.h"
+#include "base/memory/ref_counted.h"
+#include "content/common/media/renderer_audio_output_stream_factory.mojom.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace media {
+class AudioOutputIPC;
+}
+
+namespace content {
+
+class AudioMessageFilter;
+
+// This is a factory for AudioOutputIPC objects. It has two modes, using either
+// AudioMessageFilter or Mojo RendererAudioOutputStreamFactory objects.
+class AudioIPCFactory {
+ public:
+ AudioIPCFactory(
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
+ AudioMessageFilter* audio_message_filter);
+ ~AudioIPCFactory();
+
+ // The following functions may be called on any thread:
o1ka 2017/05/11 10:58:40 All public functions? Then move it to the class-le
Max Morin 2017/05/11 15:31:17 Done.
+
+ static AudioIPCFactory* get() { return instance_; }
+
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() const {
o1ka 2017/05/11 10:58:40 Return a pointer?
Max Morin 2017/05/11 15:31:17 I prefer this, since it clearly show the ownership
o1ka 2017/05/15 13:27:08 It's up to the caller do decide if there is a need
Max Morin 2017/05/16 15:51:35 In general, converting from * to an owning pointer
+ return io_task_runner_;
+ }
+
+ // Indicates whether mojo factories are used. In this case, frames have to
+ // call Register/UnregisterRemoteFactory.
+ bool UsingMojoFactories() const;
+
+ // Enables |this| to create MojoAudioOutputIPCs for the specified frame.
+ // Should only be called when UsingMojoFactories().
+ void RegisterRemoteFactory(
+ int frame_id,
+ mojom::RendererAudioOutputStreamFactoryPtr factory);
+
+ // Every call to the above method must be matched by a call to this one when
+ // the frame is destroyed.
+ void MaybeDeregisterRemoteFactory(int frame_id);
+
+ // The returned object may only be used on |io_task_runner()|.
+ std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC(
+ int frame_id) const;
+
+ private:
+ using StreamFactoryMap =
+ base::flat_map<int, mojom::RendererAudioOutputStreamFactoryPtr>;
+
+ mojom::RendererAudioOutputStreamFactory* GetRemoteFactory(int frame_id) const;
+
+ void RegisterRemoteFactoryOnIOThread(
+ int frame_id,
+ mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info);
+
+ // Maps frame id to the corresponding factory.
+ StreamFactoryMap factory_ptrs_;
+
+ // If this is non-null, it will be used rather than using mojo implementation.
+ AudioMessageFilter* audio_message_filter_;
o1ka 2017/05/11 10:58:40 const?
Max Morin 2017/05/11 15:31:17 Done.
+
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+
+ // Global instance, set in constructor and unset in destructor.
+ static AudioIPCFactory* instance_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_

Powered by Google App Engine
This is Rietveld 408576698