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

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

Issue 616833004: chrome://media-internals: update MediaInternals when devices capabilities are enumerated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FakeVCDFactory needs to specify capture API for Win. Linux/CrOs MediaInternalsVideoCaptureDeviceTes… Created 6 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 // VideoCaptureManager is used to open/close, start/stop, enumerate available 5 // VideoCaptureManager is used to open/close, start/stop, enumerate available
6 // video capture devices, and manage VideoCaptureController's. 6 // video capture devices, and manage VideoCaptureController's.
7 // All functions are expected to be called from Browser::IO thread. Some helper 7 // All functions are expected to be called from Browser::IO thread. Some helper
8 // functions (*OnDeviceThread) will dispatch operations to the device thread. 8 // functions (*OnDeviceThread) will dispatch operations to the device thread.
9 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. 9 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice.
10 // A device can only be opened once. 10 // A device can only be opened once.
11 11
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
14 14
15 #include <map> 15 #include <map>
16 #include <set> 16 #include <set>
17 #include <string> 17 #include <string>
18 18
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
22 #include "base/process/process_handle.h" 22 #include "base/process/process_handle.h"
23 #include "base/timer/elapsed_timer.h" 23 #include "base/timer/elapsed_timer.h"
24 #include "content/browser/renderer_host/media/media_stream_provider.h" 24 #include "content/browser/renderer_host/media/media_stream_provider.h"
25 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 25 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
26 #include "content/common/content_export.h" 26 #include "content/common/content_export.h"
27 #include "content/common/media/media_stream_options.h" 27 #include "content/common/media/media_stream_options.h"
28 #include "media/video/capture/video_capture_device.h" 28 #include "media/video/capture/video_capture_device.h"
29 #include "media/video/capture/video_capture_device_factory.h" 29 #include "media/video/capture/video_capture_device_factory.h"
30 #include "media/video/capture/video_capture_device_info.h"
30 #include "media/video/capture/video_capture_types.h" 31 #include "media/video/capture/video_capture_types.h"
31 32
32 namespace content { 33 namespace content {
33 class VideoCaptureController; 34 class VideoCaptureController;
34 class VideoCaptureControllerEventHandler; 35 class VideoCaptureControllerEventHandler;
35 36
36 // VideoCaptureManager opens/closes and start/stops video capture devices. 37 // VideoCaptureManager opens/closes and start/stops video capture devices.
37 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { 38 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
38 public: 39 public:
39 // Callback used to signal the completion of a controller lookup. 40 // Callback used to signal the completion of a controller lookup.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 128
128 // Gets a weak reference to the device factory, used for tests. 129 // Gets a weak reference to the device factory, used for tests.
129 media::VideoCaptureDeviceFactory* video_capture_device_factory() const { 130 media::VideoCaptureDeviceFactory* video_capture_device_factory() const {
130 return video_capture_device_factory_.get(); 131 return video_capture_device_factory_.get();
131 } 132 }
132 133
133 private: 134 private:
134 virtual ~VideoCaptureManager(); 135 virtual ~VideoCaptureManager();
135 struct DeviceEntry; 136 struct DeviceEntry;
136 137
137 // This data structure is a convenient wrap of a devices' name and associated
138 // video capture supported formats.
139 struct DeviceInfo {
140 DeviceInfo();
141 DeviceInfo(const media::VideoCaptureDevice::Name& name,
142 const media::VideoCaptureFormats& supported_formats);
143 ~DeviceInfo();
144
145 media::VideoCaptureDevice::Name name;
146 media::VideoCaptureFormats supported_formats;
147 };
148 typedef std::vector<DeviceInfo> DeviceInfos;
149
150 // Checks to see if |entry| has no clients left on its controller. If so, 138 // Checks to see if |entry| has no clients left on its controller. If so,
151 // remove it from the list of devices, and delete it asynchronously. |entry| 139 // remove it from the list of devices, and delete it asynchronously. |entry|
152 // may be freed by this function. 140 // may be freed by this function.
153 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); 141 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry);
154 142
155 // Helpers to report an event to our Listener. 143 // Helpers to report an event to our Listener.
156 void OnOpened(MediaStreamType type, 144 void OnOpened(MediaStreamType type,
157 media::VideoCaptureSessionId capture_session_id); 145 media::VideoCaptureSessionId capture_session_id);
158 void OnClosed(MediaStreamType type, 146 void OnClosed(MediaStreamType type,
159 media::VideoCaptureSessionId capture_session_id); 147 media::VideoCaptureSessionId capture_session_id);
160 void OnDevicesInfoEnumerated(MediaStreamType stream_type, 148 void OnDevicesInfoEnumerated(
161 base::ElapsedTimer* timer, 149 MediaStreamType stream_type,
162 const DeviceInfos& new_devices_info_cache); 150 base::ElapsedTimer* timer,
151 const media::VideoCaptureDeviceInfos& new_devices_info_cache);
163 152
164 // Finds a DeviceEntry by its device ID and type, if it is already opened. 153 // Finds a DeviceEntry by its device ID and type, if it is already opened.
165 DeviceEntry* GetDeviceEntryForMediaStreamDevice( 154 DeviceEntry* GetDeviceEntryForMediaStreamDevice(
166 const MediaStreamDevice& device_info); 155 const MediaStreamDevice& device_info);
167 156
168 // Finds a DeviceEntry entry for the indicated session, creating a fresh one 157 // Finds a DeviceEntry entry for the indicated session, creating a fresh one
169 // if necessary. Returns NULL if the session id is invalid. 158 // if necessary. Returns NULL if the session id is invalid.
170 DeviceEntry* GetOrCreateDeviceEntry( 159 DeviceEntry* GetOrCreateDeviceEntry(
171 media::VideoCaptureSessionId capture_session_id); 160 media::VideoCaptureSessionId capture_session_id);
172 161
173 // Finds the DeviceEntry that owns a particular controller pointer. 162 // Finds the DeviceEntry that owns a particular controller pointer.
174 DeviceEntry* GetDeviceEntryForController( 163 DeviceEntry* GetDeviceEntryForController(
175 const VideoCaptureController* controller) const; 164 const VideoCaptureController* controller) const;
176 165
177 bool IsOnDeviceThread() const; 166 bool IsOnDeviceThread() const;
178 167
179 // Consolidates the cached devices list with the list of currently connected 168 // Consolidates the cached devices list with the list of currently connected
180 // devices in the system |names_snapshot|. Retrieves the supported formats of 169 // devices in the system |names_snapshot|. Retrieves the supported formats of
181 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). 170 // the new devices and sends the new cache to OnDevicesInfoEnumerated().
182 void ConsolidateDevicesInfoOnDeviceThread( 171 void ConsolidateDevicesInfoOnDeviceThread(
183 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, 172 base::Callback<void(const media::VideoCaptureDeviceInfos&)>
173 on_devices_enumerated_callback,
184 MediaStreamType stream_type, 174 MediaStreamType stream_type,
185 const DeviceInfos& old_device_info_cache, 175 const media::VideoCaptureDeviceInfos& old_device_info_cache,
186 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot); 176 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot);
187 177
188 // Creates and Starts a new VideoCaptureDevice, storing the result in 178 // Creates and Starts a new VideoCaptureDevice, storing the result in
189 // |entry->video_capture_device|. Ownership of |client| passes to 179 // |entry->video_capture_device|. Ownership of |client| passes to
190 // the device. 180 // the device.
191 void DoStartDeviceOnDeviceThread( 181 void DoStartDeviceOnDeviceThread(
192 media::VideoCaptureSessionId session_id, 182 media::VideoCaptureSessionId session_id,
193 DeviceEntry* entry, 183 DeviceEntry* entry,
194 const media::VideoCaptureParams& params, 184 const media::VideoCaptureParams& params,
195 scoped_ptr<media::VideoCaptureDevice::Client> client); 185 scoped_ptr<media::VideoCaptureDevice::Client> client);
196 186
197 // Stops and destroys the VideoCaptureDevice held in 187 // Stops and destroys the VideoCaptureDevice held in
198 // |entry->video_capture_device|. 188 // |entry->video_capture_device|.
199 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); 189 void DoStopDeviceOnDeviceThread(DeviceEntry* entry);
200 190
201 DeviceInfo* FindDeviceInfoById(const std::string& id, 191 media::VideoCaptureDeviceInfo* FindDeviceInfoById(
202 DeviceInfos& device_vector); 192 const std::string& id,
193 media::VideoCaptureDeviceInfos& device_vector);
203 194
204 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, 195 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry,
205 gfx::NativeViewId window_id); 196 gfx::NativeViewId window_id);
206 197
207 void SaveDesktopCaptureWindowIdOnDeviceThread( 198 void SaveDesktopCaptureWindowIdOnDeviceThread(
208 media::VideoCaptureSessionId session_id, 199 media::VideoCaptureSessionId session_id,
209 gfx::NativeViewId window_id); 200 gfx::NativeViewId window_id);
210 201
211 // The message loop of media stream device thread, where VCD's live. 202 // The message loop of media stream device thread, where VCD's live.
212 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; 203 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // from the test harness. 244 // from the test harness.
254 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; 245 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_;
255 246
256 // Local cache of the enumerated video capture devices' names and capture 247 // Local cache of the enumerated video capture devices' names and capture
257 // supported formats. A snapshot of the current devices and their capabilities 248 // supported formats. A snapshot of the current devices and their capabilities
258 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and 249 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and
259 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update 250 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update
260 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will 251 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will
261 // use this list if the device is not started, otherwise it will retrieve the 252 // use this list if the device is not started, otherwise it will retrieve the
262 // active device capture format from the VideoCaptureController associated. 253 // active device capture format from the VideoCaptureController associated.
263 DeviceInfos devices_info_cache_; 254 media::VideoCaptureDeviceInfos devices_info_cache_;
264 255
265 // Accessed on the device thread only. 256 // Accessed on the device thread only.
266 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> 257 std::map<media::VideoCaptureSessionId, gfx::NativeViewId>
267 notification_window_ids_; 258 notification_window_ids_;
268 259
269 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); 260 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
270 }; 261 };
271 262
272 } // namespace content 263 } // namespace content
273 264
274 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 265 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/media/media_internals_unittest.cc ('k') | content/browser/renderer_host/media/video_capture_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698