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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_
6 #define CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_
7
8 #include <memory>
9
10 #include "base/containers/flat_map.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/common/media/renderer_audio_output_stream_factory.mojom.h"
13
14 namespace base {
15 class SingleThreadTaskRunner;
16 }
17
18 namespace media {
19 class AudioOutputIPC;
20 }
21
22 namespace content {
23
24 class AudioMessageFilter;
25
26 // This is a factory for AudioOutputIPC objects. It has two modes, using either
27 // AudioMessageFilter or Mojo RendererAudioOutputStreamFactory objects.
28 class AudioIPCFactory {
29 public:
30 AudioIPCFactory(
31 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
32 AudioMessageFilter* audio_message_filter);
33 ~AudioIPCFactory();
34
35 // 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.
36
37 static AudioIPCFactory* get() { return instance_; }
38
39 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
40 return io_task_runner_;
41 }
42
43 // Indicates whether mojo factories are used. In this case, frames have to
44 // call Register/UnregisterRemoteFactory.
45 bool UsingMojoFactories() const;
46
47 // Enables |this| to create MojoAudioOutputIPCs for the specified frame.
48 // Should only be called when UsingMojoFactories().
49 void RegisterRemoteFactory(
50 int frame_id,
51 mojom::RendererAudioOutputStreamFactoryPtr factory);
52
53 // Every call to the above method must be matched by a call to this one when
54 // the frame is destroyed.
55 void MaybeDeregisterRemoteFactory(int frame_id);
56
57 // The returned object may only be used on |io_task_runner()|.
58 std::unique_ptr<media::AudioOutputIPC> CreateAudioOutputIPC(
59 int frame_id) const;
60
61 private:
62 using StreamFactoryMap =
63 base::flat_map<int, mojom::RendererAudioOutputStreamFactoryPtr>;
64
65 mojom::RendererAudioOutputStreamFactory* GetRemoteFactory(int frame_id) const;
66
67 void RegisterRemoteFactoryOnIOThread(
68 int frame_id,
69 mojom::RendererAudioOutputStreamFactoryPtrInfo factory_ptr_info);
70
71 // Maps frame id to the corresponding factory.
72 StreamFactoryMap factory_ptrs_;
73
74 // If this is non-null, it will be used rather than using mojo implementation.
75 AudioMessageFilter* audio_message_filter_;
o1ka 2017/05/11 10:58:40 const?
Max Morin 2017/05/11 15:31:17 Done.
76
77 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
78
79 // Global instance, set in constructor and unset in destructor.
80 static AudioIPCFactory* instance_;
81 };
82
83 } // namespace content
84
85 #endif // CONTENT_RENDERER_MEDIA_AUDIO_IPC_FACTORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698