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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.h

Issue 11413078: Tab Audio Capture: Browser-side connect/disconnect functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed WCAIS threading issue (methods called on audio thread). Addressed hclam's review comments. Created 8 years 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 | Annotate | Revision Log
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 namespace media { 55 namespace media {
56 class AudioManager; 56 class AudioManager;
57 class AudioParameters; 57 class AudioParameters;
58 } 58 }
59 59
60 namespace content { 60 namespace content {
61 61
62 class MediaObserver; 62 class MediaObserver;
63 class ResourceContext; 63 class ResourceContext;
64 class WebContentsAudioInputStream;
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:
69 // Called from UI thread from the owner of this object. 70 // Called from UI thread from the owner of this object.
70 AudioRendererHost(media::AudioManager* audio_manager, 71 AudioRendererHost(int render_process_id,
72 media::AudioManager* audio_manager,
71 MediaObserver* media_observer); 73 MediaObserver* media_observer);
72 74
73 // BrowserMessageFilter implementation. 75 // BrowserMessageFilter implementation.
74 virtual void OnChannelClosing() OVERRIDE; 76 virtual void OnChannelClosing() OVERRIDE;
75 virtual void OnDestruct() const OVERRIDE; 77 virtual void OnDestruct() const OVERRIDE;
76 virtual bool OnMessageReceived(const IPC::Message& message, 78 virtual bool OnMessageReceived(const IPC::Message& message,
77 bool* message_was_ok) OVERRIDE; 79 bool* message_was_ok) OVERRIDE;
78 80
79 // AudioOutputController::EventHandler implementations. 81 // AudioOutputController::EventHandler implementations.
80 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE; 82 virtual void OnCreated(media::AudioOutputController* controller) OVERRIDE;
81 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE; 83 virtual void OnPlaying(media::AudioOutputController* controller) OVERRIDE;
82 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE; 84 virtual void OnPaused(media::AudioOutputController* controller) OVERRIDE;
83 virtual void OnError(media::AudioOutputController* controller, 85 virtual void OnError(media::AudioOutputController* controller,
84 int error_code) OVERRIDE; 86 int error_code) OVERRIDE;
85 87
88 // Start/stop mirroring all audio output streams associated with
89 // |render_view_id| to |destination|.
90 void StartMirroring(
Alpha Left Google 2012/11/26 22:59:59 What if StartMirroring and StopMirroring are stati
miu 2012/11/28 05:05:01 Done.
91 int render_view_id,
92 const scoped_refptr<WebContentsAudioInputStream>& destination);
93 void StopMirroring(
94 int render_view_id,
95 const scoped_refptr<WebContentsAudioInputStream>& destination);
96
97 // Return the AudioRendererHost instance for a render process.
98 static scoped_refptr<AudioRendererHost> FromRenderProcessID(
99 int render_process_id);
100
86 private: 101 private:
87 friend class AudioRendererHostTest; 102 friend class AudioRendererHostTest;
88 friend class BrowserThread; 103 friend class BrowserThread;
89 friend class base::DeleteHelper<AudioRendererHost>; 104 friend class base::DeleteHelper<AudioRendererHost>;
90 friend class MockAudioRendererHost; 105 friend class MockAudioRendererHost;
91 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); 106 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream);
92 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); 107 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation);
93 108
94 struct AudioEntry; 109 struct AudioEntry;
95 typedef std::map<int, AudioEntry*> AudioEntryMap; 110 typedef std::map<int, AudioEntry*> AudioEntryMap;
96 111
112 typedef std::map<int, WebContentsAudioInputStream*> MirrorSessionMap;
113
97 virtual ~AudioRendererHost(); 114 virtual ~AudioRendererHost();
98 115
99 // Methods called on IO thread ---------------------------------------------- 116 // Methods called on IO thread ----------------------------------------------
100 117
101 // Audio related IPC message handlers. 118 // Audio related IPC message handlers.
102 // Creates an audio output stream with the specified format. If this call is 119 // 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 120 // successful this object would keep an internal entry of the stream for the
104 // required properties. 121 // required properties.
105 void OnCreateStream(int stream_id, 122 void OnCreateStream(int stream_id,
106 const media::AudioParameters& params, 123 const media::AudioParameters& params,
107 int input_channels); 124 int input_channels);
108 125
126 // Associate |render_view_id| as the producer of audio for the stream
127 // referenced by |stream_id|.
128 void OnAssociateStreamWithProducer(int stream_id, int render_view_id);
129
109 // Play the audio stream referenced by |stream_id|. 130 // Play the audio stream referenced by |stream_id|.
110 void OnPlayStream(int stream_id); 131 void OnPlayStream(int stream_id);
111 132
112 // Pause the audio stream referenced by |stream_id|. 133 // Pause the audio stream referenced by |stream_id|.
113 void OnPauseStream(int stream_id); 134 void OnPauseStream(int stream_id);
114 135
115 // Discard all audio data in stream referenced by |stream_id|. 136 // Discard all audio data in stream referenced by |stream_id|.
116 void OnFlushStream(int stream_id); 137 void OnFlushStream(int stream_id);
117 138
118 // Close the audio stream referenced by |stream_id|. 139 // Close the audio stream referenced by |stream_id|.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // Returns NULL if not found. 174 // Returns NULL if not found.
154 AudioEntry* LookupById(int stream_id); 175 AudioEntry* LookupById(int stream_id);
155 176
156 // Search for a AudioEntry having the reference to |controller|. 177 // Search for a AudioEntry having the reference to |controller|.
157 // This method is used to look up an AudioEntry after a controller 178 // This method is used to look up an AudioEntry after a controller
158 // event is received. 179 // event is received.
159 AudioEntry* LookupByController(media::AudioOutputController* controller); 180 AudioEntry* LookupByController(media::AudioOutputController* controller);
160 181
161 media::AudioOutputController* LookupControllerByIdForTesting(int stream_id); 182 media::AudioOutputController* LookupControllerByIdForTesting(int stream_id);
162 183
184 void DoStartMirroring(
185 int render_view_id,
186 const scoped_refptr<WebContentsAudioInputStream>& destination);
187 void DoStopMirroring(
188 int render_view_id,
189 const scoped_refptr<WebContentsAudioInputStream>& destination);
190
191 // ID of the RenderProcessImpl that owns this instance.
192 const int render_process_id_;
193
163 // A map of stream IDs to audio sources. 194 // A map of stream IDs to audio sources.
164 AudioEntryMap audio_entries_; 195 AudioEntryMap audio_entries_;
165 196
197 // A map of render view IDs to the destination for active mirroring sessions.
198 MirrorSessionMap mirror_sessions_;
199
166 media::AudioManager* audio_manager_; 200 media::AudioManager* audio_manager_;
167 MediaObserver* media_observer_; 201 MediaObserver* media_observer_;
168 202
169 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 203 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
170 }; 204 };
171 205
172 } // namespace content 206 } // namespace content
173 207
174 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 208 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698