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> { | |
tommi (sloooow) - chröme
2012/12/18 13:41:26
Can we avoid reference counting here? Instead use
miu
2012/12/19 00:22:57
With the breaking-out of the mirroring functionali
| |
74 public: | |
75 // Create a consumer of audio data in the format specified by |params|, and | |
76 // connect it as an input to mirroring. When Close() is called, the input | |
77 // is disconnected and the object becomes invalid. | |
78 virtual media::AudioOutputStream* AddInput( | |
79 const media::AudioParameters& params) = 0; | |
80 | |
81 protected: | |
82 friend class base::RefCountedThreadSafe<MirroringDestination>; | |
83 virtual ~MirroringDestination(); | |
84 }; | |
85 | |
69 // Called from UI thread from the owner of this object. | 86 // Called from UI thread from the owner of this object. |
70 AudioRendererHost(media::AudioManager* audio_manager, | 87 AudioRendererHost(int render_process_id, |
88 media::AudioManager* audio_manager, | |
71 MediaObserver* media_observer); | 89 MediaObserver* media_observer); |
72 | 90 |
73 // BrowserMessageFilter implementation. | 91 // BrowserMessageFilter implementation. |
92 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | |
74 virtual void OnChannelClosing() OVERRIDE; | 93 virtual void OnChannelClosing() OVERRIDE; |
75 virtual void OnDestruct() const OVERRIDE; | 94 virtual void OnDestruct() const OVERRIDE; |
76 virtual bool OnMessageReceived(const IPC::Message& message, | 95 virtual bool OnMessageReceived(const IPC::Message& message, |
77 bool* message_was_ok) OVERRIDE; | 96 bool* message_was_ok) OVERRIDE; |
78 | 97 |
79 // AudioOutputController::EventHandler implementations. | 98 // AudioOutputController::EventHandler implementations. |
80 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; | 99 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; |
81 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; | 100 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; |
82 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; | 101 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; |
83 virtual void OnError(media::AudioOutputController* controller, | 102 virtual void OnError(media::AudioOutputController* controller, |
84 int error_code) OVERRIDE; | 103 int error_code) OVERRIDE; |
85 | 104 |
105 // Start/stop mirroring all audio output streams associated with | |
106 // |render_process_id| + |render_view_id| to |destination|. Any call to | |
107 // StartMirroring() must be paired with a later call to StopMirroring() since | |
108 // a reference is held on the MirroringDestination while the mirroring session | |
109 // is active. | |
110 static void StartMirroring( | |
DaleCurtis
2012/12/17 20:00:47
I worry somewhat about what seems to be the boltin
tommi (sloooow) - chröme
2012/12/18 13:41:26
+1. Maybe a Mirror object of sorts per render vie
miu
2012/12/19 00:22:57
Yeah, now that you guys have pointed it out, I agr
| |
111 int render_process_id, int render_view_id, | |
112 const scoped_refptr<MirroringDestination>& destination); | |
113 static void StopMirroring( | |
114 int render_process_id, int render_view_id, | |
115 const scoped_refptr<MirroringDestination>& destination); | |
116 | |
86 private: | 117 private: |
87 friend class AudioRendererHostTest; | 118 friend class AudioRendererHostTest; |
88 friend class BrowserThread; | 119 friend class BrowserThread; |
89 friend class base::DeleteHelper<AudioRendererHost>; | 120 friend class base::DeleteHelper<AudioRendererHost>; |
90 friend class MockAudioRendererHost; | 121 friend class MockAudioRendererHost; |
91 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 122 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
92 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 123 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
93 | 124 |
94 struct AudioEntry; | 125 struct AudioEntry; |
95 typedef std::map<int, AudioEntry*> AudioEntryMap; | 126 typedef std::map<int, AudioEntry*> AudioEntryMap; |
127 typedef std::map<int, scoped_refptr<MirroringDestination> > MirrorSessionMap; | |
128 typedef std::map<int, AudioRendererHost*> ActiveHostMap; | |
96 | 129 |
97 virtual ~AudioRendererHost(); | 130 virtual ~AudioRendererHost(); |
98 | 131 |
99 // Methods called on IO thread ---------------------------------------------- | 132 // Methods called on IO thread ---------------------------------------------- |
100 | 133 |
101 // Audio related IPC message handlers. | 134 // Audio related IPC message handlers. |
102 // Creates an audio output stream with the specified format. If this call is | 135 // 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 | 136 // successful this object would keep an internal entry of the stream for the |
104 // required properties. | 137 // required properties. |
105 void OnCreateStream(int stream_id, | 138 void OnCreateStream(int stream_id, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 // Returns NULL if not found. | 190 // Returns NULL if not found. |
158 AudioEntry* LookupById(int stream_id); | 191 AudioEntry* LookupById(int stream_id); |
159 | 192 |
160 // Search for a AudioEntry having the reference to |controller|. | 193 // Search for a AudioEntry having the reference to |controller|. |
161 // This method is used to look up an AudioEntry after a controller | 194 // This method is used to look up an AudioEntry after a controller |
162 // event is received. | 195 // event is received. |
163 AudioEntry* LookupByController(media::AudioOutputController* controller); | 196 AudioEntry* LookupByController(media::AudioOutputController* controller); |
164 | 197 |
165 media::AudioOutputController* LookupControllerByIdForTesting(int stream_id); | 198 media::AudioOutputController* LookupControllerByIdForTesting(int stream_id); |
166 | 199 |
200 // Global look-up for the AudioRendererHost instance owned by the | |
201 // RenderProcessHost specified by |render_process_id|. | |
202 static AudioRendererHost* FromRenderProcessID(int render_process_id); | |
203 | |
204 // Implementations for StartMirroring() and StopMirroring() that are run on | |
205 // the IO BrowserThread. | |
206 static void DoStartMirroring( | |
207 int render_process_id, int render_view_id, | |
208 const scoped_refptr<MirroringDestination>& destination); | |
209 static void DoStopMirroring( | |
210 int render_process_id, int render_view_id, | |
211 const scoped_refptr<MirroringDestination>& destination); | |
212 | |
213 // ID of the RenderProcessHost that owns this instance. | |
214 const int render_process_id_; | |
215 | |
167 // A map of stream IDs to audio sources. | 216 // A map of stream IDs to audio sources. |
168 AudioEntryMap audio_entries_; | 217 AudioEntryMap audio_entries_; |
169 | 218 |
219 // A map of render view IDs to the destination for active mirroring sessions. | |
220 MirrorSessionMap mirror_sessions_; | |
221 | |
170 media::AudioManager* audio_manager_; | 222 media::AudioManager* audio_manager_; |
171 MediaObserver* media_observer_; | 223 MediaObserver* media_observer_; |
172 | 224 |
225 // Global look-up map for currently-active (i.e., IPC channel is open) | |
226 // AudioRendererHosts. | |
227 static base::LazyInstance<ActiveHostMap>::Leaky g_host_map_; | |
228 | |
173 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 229 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
174 }; | 230 }; |
175 | 231 |
176 } // namespace content | 232 } // namespace content |
177 | 233 |
178 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 234 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
OLD | NEW |