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

Side by Side Diff: content/renderer/media/user_media_client_impl.h

Issue 2622073003: Fix getUserMedia so that failure is reported for invalid audio sources. (Closed)
Patch Set: Change approach to be more conservative. Instead adapt OnAudioSourceStarted to the current design a… Created 3 years, 11 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
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 #ifndef CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ 6 #define CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const blink::WebString& result_name); 112 const blink::WebString& result_name);
113 113
114 virtual void EnumerateDevicesSucceded( 114 virtual void EnumerateDevicesSucceded(
115 blink::WebMediaDevicesRequest* request, 115 blink::WebMediaDevicesRequest* request,
116 blink::WebVector<blink::WebMediaDeviceInfo>& devices); 116 blink::WebVector<blink::WebMediaDeviceInfo>& devices);
117 117
118 // Creates a MediaStreamAudioSource/MediaStreamVideoSource objects. 118 // Creates a MediaStreamAudioSource/MediaStreamVideoSource objects.
119 // These are virtual for test purposes. 119 // These are virtual for test purposes.
120 virtual MediaStreamAudioSource* CreateAudioSource( 120 virtual MediaStreamAudioSource* CreateAudioSource(
121 const StreamDeviceInfo& device, 121 const StreamDeviceInfo& device,
122 const blink::WebMediaConstraints& constraints); 122 const blink::WebMediaConstraints& constraints,
123 const MediaStreamSource::ConstraintsCallback& source_ready);
123 virtual MediaStreamVideoSource* CreateVideoSource( 124 virtual MediaStreamVideoSource* CreateVideoSource(
124 const StreamDeviceInfo& device, 125 const StreamDeviceInfo& device,
125 const MediaStreamSource::SourceStoppedCallback& stop_callback); 126 const MediaStreamSource::SourceStoppedCallback& stop_callback);
126 127
127 // Class for storing information about a WebKit request to create a 128 // Class for storing information about a WebKit request to create a
128 // MediaStream. 129 // MediaStream.
129 class UserMediaRequestInfo 130 class UserMediaRequestInfo
130 : public base::SupportsWeakPtr<UserMediaRequestInfo> { 131 : public base::SupportsWeakPtr<UserMediaRequestInfo> {
131 public: 132 public:
132 typedef base::Callback<void(UserMediaRequestInfo* request_info, 133 typedef base::Callback<void(UserMediaRequestInfo* request_info,
133 MediaStreamRequestResult result, 134 MediaStreamRequestResult result,
134 const blink::WebString& result_name)> 135 const blink::WebString& result_name)>
135 ResourcesReady; 136 ResourcesReady;
136 137
137 UserMediaRequestInfo(int request_id, 138 UserMediaRequestInfo(int request_id,
138 const blink::WebUserMediaRequest& request, 139 const blink::WebUserMediaRequest& request,
139 bool enable_automatic_output_device_selection); 140 bool enable_automatic_output_device_selection);
140 ~UserMediaRequestInfo(); 141 ~UserMediaRequestInfo();
141 int request_id; 142 int request_id;
142 // True if MediaStreamDispatcher has generated the stream, see 143 // True if MediaStreamDispatcher has generated the stream, see
143 // OnStreamGenerated. 144 // OnStreamGenerated.
144 bool generated; 145 bool generated;
145 const bool enable_automatic_output_device_selection; 146 const bool enable_automatic_output_device_selection;
146 blink::WebMediaStream web_stream; 147 blink::WebMediaStream web_stream;
147 blink::WebUserMediaRequest request; 148 blink::WebUserMediaRequest request;
148 149
149 void StartAudioTrack(const blink::WebMediaStreamTrack& track); 150 void StartAudioTrack(const blink::WebMediaStreamTrack& track,
151 bool source_initialized);
150 152
151 blink::WebMediaStreamTrack CreateAndStartVideoTrack( 153 blink::WebMediaStreamTrack CreateAndStartVideoTrack(
152 const blink::WebMediaStreamSource& source, 154 const blink::WebMediaStreamSource& source,
153 const blink::WebMediaConstraints& constraints); 155 const blink::WebMediaConstraints& constraints);
154 156
155 // Triggers |callback| when all sources used in this request have either 157 // Triggers |callback| when all sources used in this request have either
156 // successfully started, or a source has failed to start. 158 // successfully started, or a source has failed to start.
157 void CallbackOnTracksStarted(const ResourcesReady& callback); 159 void CallbackOnTracksStarted(const ResourcesReady& callback);
158 160
159 bool IsSourceUsed(const blink::WebMediaStreamSource& source) const; 161 bool HasPendingSources() const;
160 void RemoveSource(const blink::WebMediaStreamSource& source);
161 162
162 bool HasPendingSources() const; 163 // Called when a local audio source has finished (or failed) initializing.
164 void OnAudioSourceStarted(MediaStreamSource* source,
165 MediaStreamRequestResult result,
166 const blink::WebString& result_name);
163 167
164 private: 168 private:
165 void OnTrackStarted( 169 void OnTrackStarted(
166 MediaStreamSource* source, 170 MediaStreamSource* source,
167 MediaStreamRequestResult result, 171 MediaStreamRequestResult result,
168 const blink::WebString& result_name); 172 const blink::WebString& result_name);
173
174 // Cheks if the sources for all tracks have been started and if so,
175 // invoke the |ready_callback_|. Note that the caller should expect
176 // that |this| might be deleted when the function returns.
169 void CheckAllTracksStarted(); 177 void CheckAllTracksStarted();
170 178
171 ResourcesReady ready_callback_; 179 ResourcesReady ready_callback_;
172 MediaStreamRequestResult request_result_; 180 MediaStreamRequestResult request_result_;
173 blink::WebString request_result_name_; 181 blink::WebString request_result_name_;
174 // Sources used in this request. 182 // Sources used in this request.
175 std::vector<blink::WebMediaStreamSource> sources_; 183 std::vector<blink::WebMediaStreamSource> sources_;
176 std::vector<MediaStreamSource*> sources_waiting_for_callback_; 184 std::vector<MediaStreamSource*> sources_waiting_for_callback_;
177 }; 185 };
178 typedef ScopedVector<UserMediaRequestInfo> UserMediaRequests; 186 typedef ScopedVector<UserMediaRequestInfo> UserMediaRequests;
179 187
180 protected: 188 protected:
181 // These methods can be accessed in unit tests. 189 // These methods can be accessed in unit tests.
182 UserMediaRequestInfo* FindUserMediaRequestInfo(int request_id); 190 UserMediaRequestInfo* FindUserMediaRequestInfo(int request_id);
183 UserMediaRequestInfo* FindUserMediaRequestInfo( 191 UserMediaRequestInfo* FindUserMediaRequestInfo(
184 const blink::WebUserMediaRequest& request); 192 const blink::WebUserMediaRequest& request);
185 193
186 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request); 194 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request);
187 195
188 private: 196 private:
189 typedef std::vector<blink::WebMediaStreamSource> LocalStreamSources; 197 typedef std::vector<blink::WebMediaStreamSource> LocalStreamSources;
190 198
191 // RenderFrameObserver implementation. 199 // RenderFrameObserver implementation.
192 void OnDestruct() override; 200 void OnDestruct() override;
193 201
194 // Creates a WebKit representation of stream sources based on 202 // Creates a WebKit representation of stream sources based on
195 // |devices| from the MediaStreamDispatcher. 203 // |devices| from the MediaStreamDispatcher.
196 void InitializeSourceObject( 204 void InitializeVideoSourceObject(
197 const StreamDeviceInfo& device, 205 const StreamDeviceInfo& device,
198 blink::WebMediaStreamSource::Type type,
199 const blink::WebMediaConstraints& constraints, 206 const blink::WebMediaConstraints& constraints,
200 blink::WebMediaStreamSource* webkit_source); 207 blink::WebMediaStreamSource* webkit_source);
201 208
209 void InitializeAudioSourceObject(
miu 2017/01/11 20:51:11 Please return a bool instead of make the caller pr
tommi (sloooow) - chröme 2017/01/11 22:40:59 Done. Also changed InitializeVideoSourceObject to
210 const StreamDeviceInfo& device,
211 const blink::WebMediaConstraints& constraints,
212 blink::WebMediaStreamSource* webkit_source,
213 bool* source_initialized);
214
202 void CreateVideoTracks( 215 void CreateVideoTracks(
203 const StreamDeviceInfoArray& devices, 216 const StreamDeviceInfoArray& devices,
204 const blink::WebMediaConstraints& constraints, 217 const blink::WebMediaConstraints& constraints,
205 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks, 218 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks,
206 UserMediaRequestInfo* request); 219 UserMediaRequestInfo* request);
207 220
208 void CreateAudioTracks( 221 void CreateAudioTracks(
209 const StreamDeviceInfoArray& devices, 222 const StreamDeviceInfoArray& devices,
210 const blink::WebMediaConstraints& constraints, 223 const blink::WebMediaConstraints& constraints,
211 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks, 224 blink::WebVector<blink::WebMediaStreamTrack>* webkit_tracks,
212 UserMediaRequestInfo* request); 225 UserMediaRequestInfo* request);
213 226
214 // Callback function triggered when all native versions of the 227 // Callback function triggered when all native versions of the
215 // underlying media sources and tracks have been created and started. 228 // underlying media sources and tracks have been created and started.
216 void OnCreateNativeTracksCompleted( 229 void OnCreateNativeTracksCompleted(
217 UserMediaRequestInfo* request, 230 UserMediaRequestInfo* request,
218 MediaStreamRequestResult result, 231 MediaStreamRequestResult result,
219 const blink::WebString& result_name); 232 const blink::WebString& result_name);
220 233
221 void OnStreamGeneratedForCancelledRequest( 234 void OnStreamGeneratedForCancelledRequest(
222 const StreamDeviceInfoArray& audio_array, 235 const StreamDeviceInfoArray& audio_array,
223 const StreamDeviceInfoArray& video_array); 236 const StreamDeviceInfoArray& video_array);
224 237
238 static void OnAudioSourceStartedOnAudioThread(
239 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
240 base::WeakPtr<UserMediaClientImpl> weak_ptr,
241 MediaStreamSource* source,
242 MediaStreamRequestResult result,
243 const blink::WebString& result_name);
244
245 void OnAudioSourceStarted(MediaStreamSource* source,
246 MediaStreamRequestResult result,
247 const blink::WebString& result_name);
248
225 using EnumerationResult = std::vector<MediaDeviceInfoArray>; 249 using EnumerationResult = std::vector<MediaDeviceInfoArray>;
226 void FinalizeEnumerateDevices(blink::WebMediaDevicesRequest request, 250 void FinalizeEnumerateDevices(blink::WebMediaDevicesRequest request,
227 const EnumerationResult& result); 251 const EnumerationResult& result);
228 252
229 void DeleteAllUserMediaRequests(); 253 void DeleteAllUserMediaRequests();
230 254
231 // Returns the source that use a device with |device.session_id| 255 // Returns the source that use a device with |device.session_id|
232 // and |device.device.id|. NULL if such source doesn't exist. 256 // and |device.device.id|. NULL if such source doesn't exist.
233 const blink::WebMediaStreamSource* FindLocalSource( 257 const blink::WebMediaStreamSource* FindLocalSource(
258 const StreamDeviceInfo& device) const {
259 return FindLocalSource(local_sources_, device);
260 }
261 const blink::WebMediaStreamSource* FindPendingLocalSource(
262 const StreamDeviceInfo& device) const {
263 return FindLocalSource(pending_local_sources_, device);
264 }
265 const blink::WebMediaStreamSource* FindLocalSource(
266 const LocalStreamSources& sources,
234 const StreamDeviceInfo& device) const; 267 const StreamDeviceInfo& device) const;
235 268
269 // Looks up a local source and returns it if found. If not found, prepares
270 // a new WebMediaStreamSource with a NULL extraData pointer.
271 blink::WebMediaStreamSource FindOrInitializeSourceObject(
272 const StreamDeviceInfo& device);
273
236 // Returns true if we do find and remove the |source|. 274 // Returns true if we do find and remove the |source|.
237 // Otherwise returns false. 275 // Otherwise returns false.
238 bool RemoveLocalSource(const blink::WebMediaStreamSource& source); 276 bool RemoveLocalSource(const blink::WebMediaStreamSource& source);
239 277
240 void StopLocalSource(const blink::WebMediaStreamSource& source, 278 void StopLocalSource(const blink::WebMediaStreamSource& source,
241 bool notify_dispatcher); 279 bool notify_dispatcher);
242 280
243 const ::mojom::MediaDevicesDispatcherHostPtr& GetMediaDevicesDispatcher(); 281 const ::mojom::MediaDevicesDispatcherHostPtr& GetMediaDevicesDispatcher();
244 282
245 void SelectUserMediaDevice( 283 void SelectUserMediaDevice(
(...skipping 21 matching lines...) Expand all
267 // audio. 305 // audio.
268 PeerConnectionDependencyFactory* const dependency_factory_; 306 PeerConnectionDependencyFactory* const dependency_factory_;
269 307
270 // UserMediaClientImpl owns MediaStreamDispatcher instead of RenderFrameImpl 308 // UserMediaClientImpl owns MediaStreamDispatcher instead of RenderFrameImpl
271 // (or RenderFrameObserver) to ensure tear-down occurs in the right order. 309 // (or RenderFrameObserver) to ensure tear-down occurs in the right order.
272 const std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher_; 310 const std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher_;
273 311
274 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_; 312 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_;
275 313
276 LocalStreamSources local_sources_; 314 LocalStreamSources local_sources_;
315 LocalStreamSources pending_local_sources_;
277 316
278 UserMediaRequests user_media_requests_; 317 UserMediaRequests user_media_requests_;
279 MediaDevicesEventDispatcher::SubscriptionIdList 318 MediaDevicesEventDispatcher::SubscriptionIdList
280 device_change_subscription_ids_; 319 device_change_subscription_ids_;
281 320
282 blink::WebMediaDeviceChangeObserver media_device_change_observer_; 321 blink::WebMediaDeviceChangeObserver media_device_change_observer_;
283 322
284 // Note: This member must be the last to ensure all outstanding weak pointers 323 // Note: This member must be the last to ensure all outstanding weak pointers
285 // are invalidated first. 324 // are invalidated first.
286 base::WeakPtrFactory<UserMediaClientImpl> weak_factory_; 325 base::WeakPtrFactory<UserMediaClientImpl> weak_factory_;
287 326
288 DISALLOW_COPY_AND_ASSIGN(UserMediaClientImpl); 327 DISALLOW_COPY_AND_ASSIGN(UserMediaClientImpl);
289 }; 328 };
290 329
291 } // namespace content 330 } // namespace content
292 331
293 #endif // CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ 332 #endif // CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698