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

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

Issue 2380793002: Migrate MediaDevices.enumerateDevices to Mojo (Closed)
Patch Set: rebase Created 4 years, 2 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>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/threading/non_thread_safe.h" 17 #include "base/threading/non_thread_safe.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/common/media/media_devices.h"
20 #include "content/common/media/media_devices.mojom.h"
19 #include "content/public/renderer/render_frame_observer.h" 21 #include "content/public/renderer/render_frame_observer.h"
20 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" 22 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
21 #include "content/renderer/media/media_stream_source.h" 23 #include "content/renderer/media/media_stream_source.h"
24 #include "services/shell/public/cpp/interface_provider.h"
22 #include "third_party/WebKit/public/platform/WebMediaStream.h" 25 #include "third_party/WebKit/public/platform/WebMediaStream.h"
23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 26 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
24 #include "third_party/WebKit/public/platform/WebSourceInfo.h" 27 #include "third_party/WebKit/public/platform/WebSourceInfo.h"
25 #include "third_party/WebKit/public/platform/WebVector.h" 28 #include "third_party/WebKit/public/platform/WebVector.h"
26 #include "third_party/WebKit/public/web/WebMediaDeviceChangeObserver.h" 29 #include "third_party/WebKit/public/web/WebMediaDeviceChangeObserver.h"
27 #include "third_party/WebKit/public/web/WebMediaDevicesRequest.h" 30 #include "third_party/WebKit/public/web/WebMediaDevicesRequest.h"
28 #include "third_party/WebKit/public/web/WebUserMediaClient.h" 31 #include "third_party/WebKit/public/web/WebUserMediaClient.h"
29 #include "third_party/WebKit/public/web/WebUserMediaRequest.h" 32 #include "third_party/WebKit/public/web/WebUserMediaRequest.h"
30 33
31 namespace content { 34 namespace content {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const StreamDeviceInfoArray& device_array) override; 85 const StreamDeviceInfoArray& device_array) override;
83 void OnDeviceOpened(int request_id, 86 void OnDeviceOpened(int request_id,
84 const std::string& label, 87 const std::string& label,
85 const StreamDeviceInfo& device_info) override; 88 const StreamDeviceInfo& device_info) override;
86 void OnDeviceOpenFailed(int request_id) override; 89 void OnDeviceOpenFailed(int request_id) override;
87 void OnDevicesChanged() override; 90 void OnDevicesChanged() override;
88 91
89 // RenderFrameObserver override 92 // RenderFrameObserver override
90 void WillCommitProvisionalLoad() override; 93 void WillCommitProvisionalLoad() override;
91 94
95 void SetMediaDevicesDispatcherForTesting(
96 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher);
97
92 protected: 98 protected:
93 // Called when |source| has been stopped from JavaScript. 99 // Called when |source| has been stopped from JavaScript.
94 void OnLocalSourceStopped(const blink::WebMediaStreamSource& source); 100 void OnLocalSourceStopped(const blink::WebMediaStreamSource& source);
95 101
96 // These methods are virtual for test purposes. A test can override them to 102 // These methods are virtual for test purposes. A test can override them to
97 // test requesting local media streams. The function notifies WebKit that the 103 // test requesting local media streams. The function notifies WebKit that the
98 // |request| have completed. 104 // |request| have completed.
99 virtual void GetUserMediaRequestSucceeded( 105 virtual void GetUserMediaRequestSucceeded(
100 const blink::WebMediaStream& stream, 106 const blink::WebMediaStream& stream,
101 blink::WebUserMediaRequest request_info); 107 blink::WebUserMediaRequest request_info);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 protected: 189 protected:
184 // These methods can be accessed in unit tests. 190 // These methods can be accessed in unit tests.
185 UserMediaRequestInfo* FindUserMediaRequestInfo(int request_id); 191 UserMediaRequestInfo* FindUserMediaRequestInfo(int request_id);
186 UserMediaRequestInfo* FindUserMediaRequestInfo( 192 UserMediaRequestInfo* FindUserMediaRequestInfo(
187 const blink::WebUserMediaRequest& request); 193 const blink::WebUserMediaRequest& request);
188 194
189 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request); 195 void DeleteUserMediaRequestInfo(UserMediaRequestInfo* request);
190 196
191 private: 197 private:
192 typedef std::vector<blink::WebMediaStreamSource> LocalStreamSources; 198 typedef std::vector<blink::WebMediaStreamSource> LocalStreamSources;
193 struct MediaDevicesRequestInfo;
194 typedef ScopedVector<MediaDevicesRequestInfo> MediaDevicesRequests;
195 199
196 // RenderFrameObserver implementation. 200 // RenderFrameObserver implementation.
197 void OnDestruct() override; 201 void OnDestruct() override;
198 202
199 // Creates a WebKit representation of stream sources based on 203 // Creates a WebKit representation of stream sources based on
200 // |devices| from the MediaStreamDispatcher. 204 // |devices| from the MediaStreamDispatcher.
201 void InitializeSourceObject( 205 void InitializeSourceObject(
202 const StreamDeviceInfo& device, 206 const StreamDeviceInfo& device,
203 blink::WebMediaStreamSource::Type type, 207 blink::WebMediaStreamSource::Type type,
204 const blink::WebMediaConstraints& constraints, 208 const blink::WebMediaConstraints& constraints,
(...skipping 15 matching lines...) Expand all
220 // underlying media sources and tracks have been created and started. 224 // underlying media sources and tracks have been created and started.
221 void OnCreateNativeTracksCompleted( 225 void OnCreateNativeTracksCompleted(
222 UserMediaRequestInfo* request, 226 UserMediaRequestInfo* request,
223 MediaStreamRequestResult result, 227 MediaStreamRequestResult result,
224 const blink::WebString& result_name); 228 const blink::WebString& result_name);
225 229
226 void OnStreamGeneratedForCancelledRequest( 230 void OnStreamGeneratedForCancelledRequest(
227 const StreamDeviceInfoArray& audio_array, 231 const StreamDeviceInfoArray& audio_array,
228 const StreamDeviceInfoArray& video_array); 232 const StreamDeviceInfoArray& video_array);
229 233
230 void FinalizeEnumerateDevices(MediaDevicesRequestInfo* request); 234 using EnumerationResult = std::vector<std::vector<MediaDeviceInfo>>;
231 void FinalizeEnumerateSources(MediaDevicesRequestInfo* request); 235 void FinalizeEnumerateDevices(blink::WebMediaDevicesRequest request,
236 const EnumerationResult& result);
237 void FinalizeGetSources(blink::WebMediaStreamTrackSourcesRequest request,
238 const EnumerationResult& result);
232 239
233 void DeleteAllUserMediaRequests(); 240 void DeleteAllUserMediaRequests();
234 241
235 MediaDevicesRequestInfo* FindMediaDevicesRequestInfo(int request_id);
236 MediaDevicesRequestInfo* FindMediaDevicesRequestInfo(
237 const blink::WebMediaDevicesRequest& request);
238 void CancelAndDeleteMediaDevicesRequest(MediaDevicesRequestInfo* request);
239
240 // Returns the source that use a device with |device.session_id| 242 // Returns the source that use a device with |device.session_id|
241 // and |device.device.id|. NULL if such source doesn't exist. 243 // and |device.device.id|. NULL if such source doesn't exist.
242 const blink::WebMediaStreamSource* FindLocalSource( 244 const blink::WebMediaStreamSource* FindLocalSource(
243 const StreamDeviceInfo& device) const; 245 const StreamDeviceInfo& device) const;
244 246
245 // Returns true if we do find and remove the |source|. 247 // Returns true if we do find and remove the |source|.
246 // Otherwise returns false. 248 // Otherwise returns false.
247 bool RemoveLocalSource(const blink::WebMediaStreamSource& source); 249 bool RemoveLocalSource(const blink::WebMediaStreamSource& source);
248 250
249 void StopLocalSource(const blink::WebMediaStreamSource& source, 251 void StopLocalSource(const blink::WebMediaStreamSource& source,
250 bool notify_dispatcher); 252 bool notify_dispatcher);
251 253
254 const ::mojom::MediaDevicesDispatcherHostPtr& GetMediaDevicesDispatcher();
255
252 // Weak ref to a PeerConnectionDependencyFactory, owned by the RenderThread. 256 // Weak ref to a PeerConnectionDependencyFactory, owned by the RenderThread.
253 // It's valid for the lifetime of RenderThread. 257 // It's valid for the lifetime of RenderThread.
254 // TODO(xians): Remove this dependency once audio do not need it for local 258 // TODO(xians): Remove this dependency once audio do not need it for local
255 // audio. 259 // audio.
256 PeerConnectionDependencyFactory* const dependency_factory_; 260 PeerConnectionDependencyFactory* const dependency_factory_;
257 261
258 // UserMediaClientImpl owns MediaStreamDispatcher instead of RenderFrameImpl 262 // UserMediaClientImpl owns MediaStreamDispatcher instead of RenderFrameImpl
259 // (or RenderFrameObserver) to ensure tear-down occurs in the right order. 263 // (or RenderFrameObserver) to ensure tear-down occurs in the right order.
260 const std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher_; 264 const std::unique_ptr<MediaStreamDispatcher> media_stream_dispatcher_;
261 265
266 ::mojom::MediaDevicesDispatcherHostPtr media_devices_dispatcher_;
267
262 LocalStreamSources local_sources_; 268 LocalStreamSources local_sources_;
263 269
264 UserMediaRequests user_media_requests_; 270 UserMediaRequests user_media_requests_;
265 271
266 // Requests to enumerate media devices.
267 MediaDevicesRequests media_devices_requests_;
268
269 blink::WebMediaDeviceChangeObserver media_device_change_observer_; 272 blink::WebMediaDeviceChangeObserver media_device_change_observer_;
270 273
271 // Note: This member must be the last to ensure all outstanding weak pointers 274 // Note: This member must be the last to ensure all outstanding weak pointers
272 // are invalidated first. 275 // are invalidated first.
273 base::WeakPtrFactory<UserMediaClientImpl> weak_factory_; 276 base::WeakPtrFactory<UserMediaClientImpl> weak_factory_;
274 277
275 DISALLOW_COPY_AND_ASSIGN(UserMediaClientImpl); 278 DISALLOW_COPY_AND_ASSIGN(UserMediaClientImpl);
276 }; 279 };
277 280
278 } // namespace content 281 } // namespace content
279 282
280 #endif // CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_ 283 #endif // CONTENT_RENDERER_MEDIA_USER_MEDIA_CLIENT_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/media/mock_media_stream_dispatcher.cc ('k') | content/renderer/media/user_media_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698