OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // AudioRendererHost serves audio related requests from AudioRenderer which | 5 // AudioRendererHost serves audio related requests from AudioRenderer which |
6 // lives inside the render process and provide access to audio hardware. | 6 // lives inside the render process and provide access to audio hardware. |
7 // | 7 // |
8 // This class is owned by BrowserRenderProcessHost, and instantiated on UI | 8 // This class is owned by BrowserRenderProcessHost, and instantiated on UI |
9 // thread, but all other operations and method calls happen on IO thread, so we | 9 // thread, but all other operations and method calls happen on IO thread, so we |
10 // need to be extra careful about the lifetime of this object. AudioManager is a | 10 // need to be extra careful about the lifetime of this object. AudioManager is a |
(...skipping 22 matching lines...) Expand all Loading... | |
33 // v v | 33 // v v |
34 | 34 |
35 // A SyncSocket pair is used to signal buffer readiness between processes. | 35 // A SyncSocket pair is used to signal buffer readiness between processes. |
36 | 36 |
37 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 37 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
38 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 38 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
39 | 39 |
40 #include <map> | 40 #include <map> |
41 | 41 |
42 #include "base/gtest_prod_util.h" | 42 #include "base/gtest_prod_util.h" |
43 #include "base/lazy_instance.h" | |
43 #include "base/memory/ref_counted.h" | 44 #include "base/memory/ref_counted.h" |
44 #include "base/memory/scoped_ptr.h" | 45 #include "base/memory/scoped_ptr.h" |
45 #include "base/process.h" | 46 #include "base/process.h" |
46 #include "base/sequenced_task_runner_helpers.h" | 47 #include "base/sequenced_task_runner_helpers.h" |
47 #include "base/shared_memory.h" | 48 #include "base/shared_memory.h" |
48 #include "content/common/content_export.h" | 49 #include "content/common/content_export.h" |
49 #include "content/public/browser/browser_message_filter.h" | 50 #include "content/public/browser/browser_message_filter.h" |
50 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
51 #include "media/audio/audio_io.h" | 52 #include "media/audio/audio_io.h" |
52 #include "media/audio/audio_output_controller.h" | 53 #include "media/audio/audio_output_controller.h" |
53 #include "media/audio/simple_sources.h" | 54 #include "media/audio/simple_sources.h" |
54 | 55 |
55 namespace media { | 56 namespace media { |
56 class AudioManager; | 57 class AudioManager; |
57 class AudioParameters; | 58 class AudioParameters; |
58 } | 59 } |
59 | 60 |
60 namespace content { | 61 namespace content { |
61 | 62 |
62 class MediaObserver; | 63 class MediaObserver; |
63 class ResourceContext; | 64 class ResourceContext; |
64 | 65 |
65 class CONTENT_EXPORT AudioRendererHost | 66 class CONTENT_EXPORT AudioRendererHost |
66 : public BrowserMessageFilter, | 67 : public BrowserMessageFilter, |
67 public media::AudioOutputController::EventHandler { | 68 public media::AudioOutputController::EventHandler { |
68 public: | 69 public: |
70 // Interface to be implemented by audio mirroring destinations. See | |
71 // comments for StartMirroring() and StopMirroring() below. | |
72 class MirroringDestination | |
73 : public base::RefCountedThreadSafe<MirroringDestination> { | |
DaleCurtis
2012/12/05 23:35:14
Do we really need this to be ref counted?
miu
2012/12/11 02:30:45
Yes. AudioRendererHost operates mainly on the IO
| |
74 public: | |
75 // Begin pulling data from |callback|, which is providing data in the format | |
76 // specified by |params|. | |
77 virtual void AddInput( | |
78 media::AudioOutputStream::AudioSourceCallback* callback, | |
79 const media::AudioParameters& params) = 0; | |
80 | |
81 // Stop pulling data from |callback|. After this method returns, the caller | |
82 // can safely destroy the callback. | |
83 virtual void RemoveInput( | |
84 media::AudioOutputStream::AudioSourceCallback* callback) = 0; | |
85 | |
86 protected: | |
87 friend class base::RefCountedThreadSafe<MirroringDestination>; | |
88 virtual ~MirroringDestination(); | |
89 }; | |
90 | |
69 // Called from UI thread from the owner of this object. | 91 // Called from UI thread from the owner of this object. |
70 AudioRendererHost(media::AudioManager* audio_manager, | 92 AudioRendererHost(int render_process_id, |
93 media::AudioManager* audio_manager, | |
71 MediaObserver* media_observer); | 94 MediaObserver* media_observer); |
72 | 95 |
73 // BrowserMessageFilter implementation. | 96 // BrowserMessageFilter implementation. |
97 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
DaleCurtis
2012/12/05 23:35:14
What is a peer_id?
miu
2012/12/11 02:30:45
The process ID (operating system PID?) of the proc
tommi (sloooow) - chröme
2012/12/18 13:41:25
is int32 needed or is int enough?
miu
2012/12/19 00:22:57
The method signature should probably match what's
| |
74 virtual void OnChannelClosing() OVERRIDE; | 98 virtual void OnChannelClosing() OVERRIDE; |
75 virtual void OnDestruct() const OVERRIDE; | 99 virtual void OnDestruct() const OVERRIDE; |
76 virtual bool OnMessageReceived(const IPC::Message& message, | 100 virtual bool OnMessageReceived(const IPC::Message& message, |
77 bool* message_was_ok) OVERRIDE; | 101 bool* message_was_ok) OVERRIDE; |
78 | 102 |
79 // AudioOutputController::EventHandler implementations. | 103 // AudioOutputController::EventHandler implementations. |
80 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; | 104 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; |
81 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; | 105 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; |
82 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; | 106 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; |
83 virtual void OnError(media::AudioOutputController* controller, | 107 virtual void OnError(media::AudioOutputController* controller, |
84 int error_code) OVERRIDE; | 108 int error_code) OVERRIDE; |
85 | 109 |
110 // Start/stop mirroring all audio output streams associated with | |
111 // |render_process_id| + |render_view_id| to |destination|. Any call to | |
112 // StartMirroring() must be paired with a later call to StopMirroring() since | |
113 // a reference is held on the MirroringDestination while the mirroring session | |
114 // is active. | |
115 static void StartMirroring( | |
116 int render_process_id, int render_view_id, | |
117 const scoped_refptr<MirroringDestination>& destination); | |
118 static void StopMirroring( | |
119 int render_process_id, int render_view_id, | |
120 const scoped_refptr<MirroringDestination>& destination); | |
121 | |
86 private: | 122 private: |
87 friend class AudioRendererHostTest; | 123 friend class AudioRendererHostTest; |
88 friend class BrowserThread; | 124 friend class BrowserThread; |
89 friend class base::DeleteHelper<AudioRendererHost>; | 125 friend class base::DeleteHelper<AudioRendererHost>; |
90 friend class MockAudioRendererHost; | 126 friend class MockAudioRendererHost; |
91 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 127 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
92 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 128 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
93 | 129 |
94 struct AudioEntry; | 130 struct AudioEntry; |
95 typedef std::map<int, AudioEntry*> AudioEntryMap; | 131 typedef std::map<int, AudioEntry*> AudioEntryMap; |
132 typedef std::map<int, scoped_refptr<MirroringDestination> > MirrorSessionMap; | |
133 typedef std::map<int, AudioRendererHost*> ActiveHostMap; | |
tommi (sloooow) - chröme
2012/12/18 13:41:25
can you add a note about AudioRendererHost ownersh
miu
2012/12/19 00:22:57
Done. (in audio_mirroring_manager.h)
| |
96 | 134 |
97 virtual ~AudioRendererHost(); | 135 virtual ~AudioRendererHost(); |
98 | 136 |
99 // Methods called on IO thread ---------------------------------------------- | 137 // Methods called on IO thread ---------------------------------------------- |
100 | 138 |
101 // Audio related IPC message handlers. | 139 // Audio related IPC message handlers. |
102 // Creates an audio output stream with the specified format. If this call is | 140 // Creates an audio output stream with the specified format. If this call is |
103 // successful this object would keep an internal entry of the stream for the | 141 // successful this object would keep an internal entry of the stream for the |
104 // required properties. | 142 // required properties. |
105 void OnCreateStream(int stream_id, | 143 void OnCreateStream(int stream_id, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 // Returns NULL if not found. | 195 // Returns NULL if not found. |
158 AudioEntry* LookupById(int stream_id); | 196 AudioEntry* LookupById(int stream_id); |
159 | 197 |
160 // Search for a AudioEntry having the reference to |controller|. | 198 // Search for a AudioEntry having the reference to |controller|. |
161 // This method is used to look up an AudioEntry after a controller | 199 // This method is used to look up an AudioEntry after a controller |
162 // event is received. | 200 // event is received. |
163 AudioEntry* LookupByController(media::AudioOutputController* controller); | 201 AudioEntry* LookupByController(media::AudioOutputController* controller); |
164 | 202 |
165 media::AudioOutputController* LookupControllerByIdForTesting(int stream_id); | 203 media::AudioOutputController* LookupControllerByIdForTesting(int stream_id); |
166 | 204 |
205 // Global look-up for the AudioRendererHost instance owned by the | |
206 // RenderProcessHost specified by |render_process_id|. | |
207 static AudioRendererHost* FromRenderProcessID(int render_process_id); | |
208 | |
209 // Implementations for StartMirroring() and StopMirroring() that are run on | |
210 // the IO BrowserThread. | |
211 static void DoStartMirroring( | |
212 int render_process_id, int render_view_id, | |
213 const scoped_refptr<MirroringDestination>& destination); | |
214 static void DoStopMirroring( | |
215 int render_process_id, int render_view_id, | |
216 const scoped_refptr<MirroringDestination>& destination); | |
217 | |
218 // ID of the RenderProcessHost that owns this instance. | |
219 const int render_process_id_; | |
220 | |
167 // A map of stream IDs to audio sources. | 221 // A map of stream IDs to audio sources. |
168 AudioEntryMap audio_entries_; | 222 AudioEntryMap audio_entries_; |
169 | 223 |
224 // A map of render view IDs to the destination for active mirroring sessions. | |
225 MirrorSessionMap mirror_sessions_; | |
226 | |
170 media::AudioManager* audio_manager_; | 227 media::AudioManager* audio_manager_; |
171 MediaObserver* media_observer_; | 228 MediaObserver* media_observer_; |
172 | 229 |
230 // Global look-up map for currently-active (i.e., IPC channel is open) | |
231 // AudioRendererHosts. | |
232 static base::LazyInstance<ActiveHostMap>::Leaky g_host_map_; | |
233 | |
173 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 234 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
174 }; | 235 }; |
175 | 236 |
176 } // namespace content | 237 } // namespace content |
177 | 238 |
178 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 239 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
OLD | NEW |