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

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

Issue 29423003: Added video capture capabilities retrieval and caching to VideoCaptureManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: xians@ comments. Created 7 years, 1 month 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.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 virtual void Close(int capture_session_id) OVERRIDE; 52 virtual void Close(int capture_session_id) OVERRIDE;
53 53
54 // Used by unit test to make sure a fake device is used instead of a real 54 // Used by unit test to make sure a fake device is used instead of a real
55 // video capture device. Due to timing requirements, the function must be 55 // video capture device. Due to timing requirements, the function must be
56 // called before EnumerateDevices and Open. 56 // called before EnumerateDevices and Open.
57 void UseFakeDevice(); 57 void UseFakeDevice();
58 58
59 // Called by VideoCaptureHost to locate a capture device for |capture_params|, 59 // Called by VideoCaptureHost to locate a capture device for |capture_params|,
60 // adding the Host as a client of the device's controller if successful. The 60 // adding the Host as a client of the device's controller if successful. The
61 // value of |capture_params.session_id| controls which device is selected; 61 // value of |capture_params.session_id| controls which device is selected;
62 // this value should be a session id previously returned by Open(). 62 // this value should be a session id previously returned by Open(). The device
63 // capabilities are reduced to |capture_params|.
63 // 64 //
64 // If the device is not already started (i.e., no other client is currently 65 // If the device is not already started (i.e., no other client is currently
65 // capturing from this device), this call will cause a VideoCaptureController 66 // capturing from this device), this call will cause a VideoCaptureController
66 // and VideoCaptureDevice to be created, possibly asynchronously. 67 // and VideoCaptureDevice to be created, possibly asynchronously.
67 // 68 //
68 // On success, the controller is returned via calling |done_cb|, indicating 69 // On success, the controller is returned via calling |done_cb|, indicating
69 // that the client was successfully added. A NULL controller is passed to 70 // that the client was successfully added. A NULL controller is passed to
70 // the callback on failure. 71 // the callback on failure.
71 void StartCaptureForClient(const media::VideoCaptureParams& capture_params, 72 void StartCaptureForClient(const media::VideoCaptureParams& capture_params,
72 base::ProcessHandle client_render_process, 73 base::ProcessHandle client_render_process,
73 VideoCaptureControllerID client_id, 74 VideoCaptureControllerID client_id,
74 VideoCaptureControllerEventHandler* client_handler, 75 VideoCaptureControllerEventHandler* client_handler,
75 const DoneCB& done_cb); 76 const DoneCB& done_cb);
76 77
77 // Called by VideoCaptureHost to remove |client_handler|. If this is the last 78 // Called by VideoCaptureHost to remove |client_handler|. If this is the last
78 // client of the device, the |controller| and its VideoCaptureDevice may be 79 // client of the device, the |controller| and its VideoCaptureDevice may be
79 // destroyed. The client must not access |controller| after calling this 80 // destroyed. The client must not access |controller| after calling this
80 // function. 81 // function.
81 void StopCaptureForClient(VideoCaptureController* controller, 82 void StopCaptureForClient(VideoCaptureController* controller,
82 VideoCaptureControllerID client_id, 83 VideoCaptureControllerID client_id,
83 VideoCaptureControllerEventHandler* client_handler); 84 VideoCaptureControllerEventHandler* client_handler);
84 85
86 // Retrieve the available capture capabilities for a particular device. The
no longer working on chromium 2013/11/13 16:20:22 nit, Retrieves
87 // capabilities are cached during device(s) enumeration and updated as clients
88 // open/close the device(s).
89 void GetDeviceCapabilities(int capture_session_id,
90 media::VideoCaptureCapabilities* capabilities);
91
85 private: 92 private:
86 virtual ~VideoCaptureManager(); 93 virtual ~VideoCaptureManager();
87 struct DeviceEntry; 94 struct DeviceEntry;
88 95
96 // This data structure is a convenient wrap of a devices' name and associated
97 // video capture capabilities, and a flag that indicates if in use.
98 struct DeviceInfo {
99 DeviceInfo();
100 DeviceInfo(const media::VideoCaptureDevice::Name& name,
101 const media::VideoCaptureCapabilities& capabilities);
102 ~DeviceInfo();
103
104 bool device_in_use;
105 media::VideoCaptureDevice::Name name;
106 media::VideoCaptureCapabilities capabilities;
107 };
108 typedef std::vector<DeviceInfo> DevicesInfo;
109
89 // Check to see if |entry| has no clients left on its controller. If so, 110 // Check to see if |entry| has no clients left on its controller. If so,
90 // remove it from the list of devices, and delete it asynchronously. |entry| 111 // remove it from the list of devices, and delete it asynchronously. |entry|
91 // may be freed by this function. 112 // may be freed by this function.
92 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); 113 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry);
93 114
94 // Helpers to report an event to our Listener. 115 // Helpers to report an event to our Listener.
95 void OnOpened(MediaStreamType type, int capture_session_id); 116 void OnOpened(MediaStreamType type, int capture_session_id);
96 void OnClosed(MediaStreamType type, int capture_session_id); 117 void OnClosed(MediaStreamType type, int capture_session_id);
97 void OnDevicesEnumerated(MediaStreamType stream_type, 118 void OnDeviceNamesAndCapabilitiesEnumerated(
98 const media::VideoCaptureDevice::Names& names); 119 MediaStreamType stream_type,
120 const DevicesInfo& new_devices_info_cache);
99 121
100 // Find a DeviceEntry by its device ID and type, if it is already opened. 122 // Find a DeviceEntry by its device ID and type, if it is already opened.
101 DeviceEntry* GetDeviceEntryForMediaStreamDevice( 123 DeviceEntry* GetDeviceEntryForMediaStreamDevice(
102 const MediaStreamDevice& device_info); 124 const MediaStreamDevice& device_info);
103 125
104 // Find a DeviceEntry entry for the indicated session, creating a fresh one 126 // Find a DeviceEntry entry for the indicated session, creating a fresh one
105 // if necessary. Returns NULL if the session id is invalid. 127 // if necessary. Returns NULL if the session id is invalid.
106 DeviceEntry* GetOrCreateDeviceEntry(int capture_session_id); 128 DeviceEntry* GetOrCreateDeviceEntry(int capture_session_id);
107 129
108 // Find the DeviceEntry that owns a particular controller pointer. 130 // Find the DeviceEntry that owns a particular controller pointer.
109 DeviceEntry* GetDeviceEntryForController( 131 DeviceEntry* GetDeviceEntryForController(
110 const VideoCaptureController* controller); 132 const VideoCaptureController* controller);
111 133
112 bool IsOnDeviceThread() const; 134 bool IsOnDeviceThread() const;
113 135
114 // Queries and returns the available device IDs. 136 // Queries the Names of the devices in the system; the capabilities of the new
115 media::VideoCaptureDevice::Names GetAvailableDevicesOnDeviceThread( 137 // devices are also queried, and consolidated with the copy of the local
116 MediaStreamType stream_type); 138 // device info cache passed. The consolidated list of devices+capabilities is
139 // returned.
140 DevicesInfo GetAvailableDevicesAndCapabilitiesOnDeviceThread(
141 MediaStreamType stream_type,
142 const DevicesInfo& old_device_info_cache);
117 143
118 // Create and Start a new VideoCaptureDevice, storing the result in 144 // Create and Start a new VideoCaptureDevice, storing the result in
119 // |entry->video_capture_device|. Ownership of |client| passes to 145 // |entry->video_capture_device|. Ownership of |client| passes to
120 // the device. 146 // the device.
121 void DoStartDeviceOnDeviceThread( 147 void DoStartDeviceOnDeviceThread(
122 DeviceEntry* entry, 148 DeviceEntry* entry,
123 const media::VideoCaptureCapability& capture_params, 149 const media::VideoCaptureCapability& capture_params,
124 scoped_ptr<media::VideoCaptureDevice::Client> client); 150 scoped_ptr<media::VideoCaptureDevice::Client> client);
125 151
126 // Stop and destroy the VideoCaptureDevice held in 152 // Stop and destroy the VideoCaptureDevice held in
127 // |entry->video_capture_device|. 153 // |entry->video_capture_device|.
128 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); 154 void DoStopDeviceOnDeviceThread(DeviceEntry* entry);
129 155
156 DeviceInfo* FindDeviceInfoById(const std::string& id,
157 DevicesInfo& device_vector);
158
130 // The message loop of media stream device thread, where VCD's live. 159 // The message loop of media stream device thread, where VCD's live.
131 scoped_refptr<base::MessageLoopProxy> device_loop_; 160 scoped_refptr<base::MessageLoopProxy> device_loop_;
132 161
133 // Only accessed on Browser::IO thread. 162 // Only accessed on Browser::IO thread.
134 MediaStreamProviderListener* listener_; 163 MediaStreamProviderListener* listener_;
135 int new_capture_session_id_; 164 int new_capture_session_id_;
136 165
137 // An entry is kept in this map for every session that has been created via 166 // An entry is kept in this map for every session that has been created via
138 // the Open() entry point. The keys are session_id's. This map is used to 167 // the Open() entry point. The keys are session_id's. This map is used to
139 // determine which device to use when StartCaptureForClient() occurs. Used 168 // determine which device to use when StartCaptureForClient() occurs. Used
(...skipping 20 matching lines...) Expand all
160 189
161 // The controller. Only used from the IO thread. 190 // The controller. Only used from the IO thread.
162 scoped_ptr<VideoCaptureController> video_capture_controller; 191 scoped_ptr<VideoCaptureController> video_capture_controller;
163 192
164 // The capture device. Only used from the device thread. 193 // The capture device. Only used from the device thread.
165 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 194 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
166 }; 195 };
167 typedef std::set<DeviceEntry*> DeviceEntries; 196 typedef std::set<DeviceEntry*> DeviceEntries;
168 DeviceEntries devices_; 197 DeviceEntries devices_;
169 198
199 // Local cache of the enumerated video capture devices' names and capture
200 // capabilities. A snapshot of the current devices and their capabilities is
201 // composed in GetAvailableDevicesAndCapabilitiesOnDeviceThread() --coming
202 // from EnumerateDevices()--, and this snapshot is used to update this list in
203 // OnDeviceNamesAndCapabilitiesEnumerated(). The flag |device_in_use_| is
204 // updated in StartCaptureForClient() and StopCaptureForClient() (if the
205 // device is not in use anymore).
206 DevicesInfo devices_info_cache_;
207
170 // Set to true if using fake video capture devices for testing, false by 208 // Set to true if using fake video capture devices for testing, false by
171 // default. This is only used for the MEDIA_DEVICE_VIDEO_CAPTURE device type. 209 // default. This is only used for the MEDIA_DEVICE_VIDEO_CAPTURE device type.
172 bool use_fake_device_; 210 bool use_fake_device_;
173 211
174 // We cache the enumerated video capture devices in
175 // GetAvailableDevicesOnDeviceThread() and then later look up the requested ID
176 // when a device is created in DoStartDeviceOnDeviceThread(). Used only on the
177 // device thread.
178 media::VideoCaptureDevice::Names video_capture_devices_;
179
180 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); 212 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
181 }; 213 };
182 214
183 } // namespace content 215 } // namespace content
184 216
185 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 217 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698