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

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

Issue 235353002: Extract VideoCaptureDeviceFactory out of VideoCaptureDevice and use for File and FakeVCD. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | 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 // 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/process/process_handle.h" 21 #include "base/process/process_handle.h"
22 #include "content/browser/renderer_host/media/media_stream_provider.h" 22 #include "content/browser/renderer_host/media/media_stream_provider.h"
23 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 23 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
24 #include "content/common/content_export.h" 24 #include "content/common/content_export.h"
25 #include "content/common/media/media_stream_options.h" 25 #include "content/common/media/media_stream_options.h"
26 #include "media/video/capture/video_capture_device.h" 26 #include "media/video/capture/video_capture_device.h"
27 #include "media/video/capture/video_capture_device_factory.h"
27 #include "media/video/capture/video_capture_types.h" 28 #include "media/video/capture/video_capture_types.h"
28 29
29 namespace content { 30 namespace content {
30 class VideoCaptureController; 31 class VideoCaptureController;
31 class VideoCaptureControllerEventHandler; 32 class VideoCaptureControllerEventHandler;
32 33
33 // VideoCaptureManager opens/closes and start/stops video capture devices. 34 // VideoCaptureManager opens/closes and start/stops video capture devices.
34 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { 35 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider {
35 public: 36 public:
36 // Callback used to signal the completion of a controller lookup. 37 // Callback used to signal the completion of a controller lookup.
(...skipping 11 matching lines...) Expand all
48 49
49 virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE; 50 virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE;
50 51
51 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; 52 virtual int Open(const StreamDeviceInfo& device) OVERRIDE;
52 53
53 virtual void Close(int capture_session_id) OVERRIDE; 54 virtual void Close(int capture_session_id) OVERRIDE;
54 55
55 // Used by unit test to make sure a fake device is used instead of a real 56 // Used by unit test to make sure a fake device is used instead of a real
56 // video capture device. Due to timing requirements, the function must be 57 // video capture device. Due to timing requirements, the function must be
57 // called before EnumerateDevices and Open. 58 // called before EnumerateDevices and Open.
58 void UseFakeDevice(); 59 void UseFakeDevice(scoped_ptr<media::VideoCaptureDeviceFactory> factory);
perkj_chrome 2014/04/15 09:34:01 Why not just inject the factory in the ctor? Tests
mcasas 2014/04/15 13:47:09 Extended the ctor to accept a Factory. Some highe
59 60
60 // Called by VideoCaptureHost to locate a capture device for |capture_params|, 61 // Called by VideoCaptureHost to locate a capture device for |capture_params|,
61 // adding the Host as a client of the device's controller if successful. The 62 // adding the Host as a client of the device's controller if successful. The
62 // value of |session_id| controls which device is selected; 63 // value of |session_id| controls which device is selected;
63 // this value should be a session id previously returned by Open(). 64 // this value should be a session id previously returned by Open().
64 // 65 //
65 // If the device is not already started (i.e., no other client is currently 66 // If the device is not already started (i.e., no other client is currently
66 // capturing from this device), this call will cause a VideoCaptureController 67 // capturing from this device), this call will cause a VideoCaptureController
67 // and VideoCaptureDevice to be created, possibly asynchronously. 68 // and VideoCaptureDevice to be created, possibly asynchronously.
68 // 69 //
(...skipping 27 matching lines...) Expand all
96 // |capture_session_id| is not found. Returns true and |formats_in_use| 97 // |capture_session_id| is not found. Returns true and |formats_in_use|
97 // otherwise. |formats_in_use| is empty if the device is not in use. 98 // otherwise. |formats_in_use| is empty if the device is not in use.
98 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, 99 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id,
99 media::VideoCaptureFormats* formats_in_use); 100 media::VideoCaptureFormats* formats_in_use);
100 101
101 // Sets the platform-dependent window ID for the desktop capture notification 102 // Sets the platform-dependent window ID for the desktop capture notification
102 // UI for the given session. 103 // UI for the given session.
103 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, 104 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id,
104 gfx::NativeViewId window_id); 105 gfx::NativeViewId window_id);
105 106
107 // Gets a weak reference to the device factory, used for tests.
108 media::VideoCaptureDeviceFactory* video_capture_device_factory() const {
109 return video_capture_device_factory_.get();
110 }
111
106 private: 112 private:
107 virtual ~VideoCaptureManager(); 113 virtual ~VideoCaptureManager();
108 struct DeviceEntry; 114 struct DeviceEntry;
109 115
110 // This data structure is a convenient wrap of a devices' name and associated 116 // This data structure is a convenient wrap of a devices' name and associated
111 // video capture supported formats. 117 // video capture supported formats.
112 struct DeviceInfo { 118 struct DeviceInfo {
113 DeviceInfo(); 119 DeviceInfo();
114 DeviceInfo(const media::VideoCaptureDevice::Name& name, 120 DeviceInfo(const media::VideoCaptureDevice::Name& name,
115 const media::VideoCaptureFormats& supported_formats); 121 const media::VideoCaptureFormats& supported_formats);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 219
214 // The controller. Only used from the IO thread. 220 // The controller. Only used from the IO thread.
215 scoped_ptr<VideoCaptureController> video_capture_controller; 221 scoped_ptr<VideoCaptureController> video_capture_controller;
216 222
217 // The capture device. Only used from the device thread. 223 // The capture device. Only used from the device thread.
218 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 224 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
219 }; 225 };
220 typedef std::set<DeviceEntry*> DeviceEntries; 226 typedef std::set<DeviceEntry*> DeviceEntries;
221 DeviceEntries devices_; 227 DeviceEntries devices_;
222 228
229 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_;
230
223 // Local cache of the enumerated video capture devices' names and capture 231 // Local cache of the enumerated video capture devices' names and capture
224 // supported formats. A snapshot of the current devices and their capabilities 232 // supported formats. A snapshot of the current devices and their capabilities
225 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming 233 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming
226 // from EnumerateDevices()--, and this snapshot is used to update this list in 234 // from EnumerateDevices()--, and this snapshot is used to update this list in
227 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will 235 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will
228 // use this list if the device is not started, otherwise it will retrieve the 236 // use this list if the device is not started, otherwise it will retrieve the
229 // active device capture format from the VideoCaptureController associated. 237 // active device capture format from the VideoCaptureController associated.
230 DeviceInfos devices_info_cache_; 238 DeviceInfos devices_info_cache_;
231 239
232 // For unit testing and for performance/quality tests, a test device can be 240 // A test device can be used for unit testing and for performance/quality
233 // used instead of a real one. The device can be a simple fake device (a 241 // measurements. This device is usually injected from the test harness, but
234 // rolling pacman), or a file that is played in a loop continuously. This only 242 // can also come from MediaStreamManager in normal operation, via command line
235 // applies to the MEDIA_DEVICE_VIDEO_CAPTURE device type. 243 // flag. Supported test devices include a simple fake device (a rolling
236 enum { 244 // pacman), or a file that is played in a loop continuously. Test device is
237 DISABLED, 245 // only and always of type MEDIA_DEVICE_VIDEO_CAPTURE.
238 TEST_PATTERN, 246 bool use_testing_device_source_;
perkj_chrome 2014/04/15 09:34:01 We want to get rid of this type of things in the p
mcasas 2014/04/15 13:47:09 Done.
239 Y4M_FILE
240 } artificial_device_source_for_testing_;
241 247
242 // Accessed on the device thread only. 248 // Accessed on the device thread only.
243 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> 249 std::map<media::VideoCaptureSessionId, gfx::NativeViewId>
244 notification_window_ids_; 250 notification_window_ids_;
245 251
246 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); 252 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
247 }; 253 };
248 254
249 } // namespace content 255 } // namespace content
250 256
251 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 257 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698