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

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

Issue 91343002: Added supported formats caching to VideoCaptureManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@ nits Created 7 years 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 const DoneCB& done_cb); 76 const DoneCB& done_cb);
77 77
78 // 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
79 // client of the device, the |controller| and its VideoCaptureDevice may be 79 // client of the device, the |controller| and its VideoCaptureDevice may be
80 // destroyed. The client must not access |controller| after calling this 80 // destroyed. The client must not access |controller| after calling this
81 // function. 81 // function.
82 void StopCaptureForClient(VideoCaptureController* controller, 82 void StopCaptureForClient(VideoCaptureController* controller,
83 VideoCaptureControllerID client_id, 83 VideoCaptureControllerID client_id,
84 VideoCaptureControllerEventHandler* client_handler); 84 VideoCaptureControllerEventHandler* client_handler);
85 85
86 // Retrieves the available capture supported formats for a particular device.
87 // The supported formats are cached during device(s) enumeration.
88 void GetDeviceSupportedFormats(int capture_session_id,
89 media::VideoCaptureFormats* supported_formats);
90
86 private: 91 private:
87 virtual ~VideoCaptureManager(); 92 virtual ~VideoCaptureManager();
88 struct DeviceEntry; 93 struct DeviceEntry;
89 94
95 // This data structure is a convenient wrap of a devices' name and associated
96 // video capture supported formats.
97 struct DeviceInfo {
98 DeviceInfo();
99 DeviceInfo(const media::VideoCaptureDevice::Name& name,
100 const media::VideoCaptureFormats& supported_formats);
101 ~DeviceInfo();
102
103 media::VideoCaptureDevice::Name name;
104 media::VideoCaptureFormats supported_formats;
105 };
106 typedef std::vector<DeviceInfo> DeviceInfos;
107
90 // Check to see if |entry| has no clients left on its controller. If so, 108 // Check to see if |entry| has no clients left on its controller. If so,
91 // remove it from the list of devices, and delete it asynchronously. |entry| 109 // remove it from the list of devices, and delete it asynchronously. |entry|
92 // may be freed by this function. 110 // may be freed by this function.
93 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); 111 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry);
94 112
95 // Helpers to report an event to our Listener. 113 // Helpers to report an event to our Listener.
96 void OnOpened(MediaStreamType type, int capture_session_id); 114 void OnOpened(MediaStreamType type, int capture_session_id);
97 void OnClosed(MediaStreamType type, int capture_session_id); 115 void OnClosed(MediaStreamType type, int capture_session_id);
98 void OnDevicesEnumerated(MediaStreamType stream_type, 116 void OnDevicesInfoEnumerated(
99 const media::VideoCaptureDevice::Names& names); 117 MediaStreamType stream_type,
118 const DeviceInfos& new_devices_info_cache);
100 119
101 // Find a DeviceEntry by its device ID and type, if it is already opened. 120 // Find a DeviceEntry by its device ID and type, if it is already opened.
102 DeviceEntry* GetDeviceEntryForMediaStreamDevice( 121 DeviceEntry* GetDeviceEntryForMediaStreamDevice(
103 const MediaStreamDevice& device_info); 122 const MediaStreamDevice& device_info);
104 123
105 // Find a DeviceEntry entry for the indicated session, creating a fresh one 124 // Find a DeviceEntry entry for the indicated session, creating a fresh one
106 // if necessary. Returns NULL if the session id is invalid. 125 // if necessary. Returns NULL if the session id is invalid.
107 DeviceEntry* GetOrCreateDeviceEntry(int capture_session_id); 126 DeviceEntry* GetOrCreateDeviceEntry(int capture_session_id);
108 127
109 // Find the DeviceEntry that owns a particular controller pointer. 128 // Find the DeviceEntry that owns a particular controller pointer.
110 DeviceEntry* GetDeviceEntryForController( 129 DeviceEntry* GetDeviceEntryForController(
111 const VideoCaptureController* controller); 130 const VideoCaptureController* controller);
112 131
113 bool IsOnDeviceThread() const; 132 bool IsOnDeviceThread() const;
114 133
115 // Queries and returns the available device IDs. 134 // Queries the Names of the devices in the system; the formats supported by
116 media::VideoCaptureDevice::Names GetAvailableDevicesOnDeviceThread( 135 // the new devices are also queried, and consolidated with the copy of the
117 MediaStreamType stream_type); 136 // local device info cache passed. The consolidated list of devices and
137 // supported formats is returned.
138 DeviceInfos GetAvailableDevicesInfoOnDeviceThread(
139 MediaStreamType stream_type,
140 const DeviceInfos& old_device_info_cache);
118 141
119 // Create and Start a new VideoCaptureDevice, storing the result in 142 // Create and Start a new VideoCaptureDevice, storing the result in
120 // |entry->video_capture_device|. Ownership of |client| passes to 143 // |entry->video_capture_device|. Ownership of |client| passes to
121 // the device. 144 // the device.
122 void DoStartDeviceOnDeviceThread( 145 void DoStartDeviceOnDeviceThread(
123 DeviceEntry* entry, 146 DeviceEntry* entry,
124 const media::VideoCaptureParams& params, 147 const media::VideoCaptureParams& params,
125 scoped_ptr<media::VideoCaptureDevice::Client> client); 148 scoped_ptr<media::VideoCaptureDevice::Client> client);
126 149
127 // Stop and destroy the VideoCaptureDevice held in 150 // Stop and destroy the VideoCaptureDevice held in
128 // |entry->video_capture_device|. 151 // |entry->video_capture_device|.
129 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); 152 void DoStopDeviceOnDeviceThread(DeviceEntry* entry);
130 153
154 DeviceInfo* FindDeviceInfoById(const std::string& id,
155 DeviceInfos& device_vector);
156
131 // The message loop of media stream device thread, where VCD's live. 157 // The message loop of media stream device thread, where VCD's live.
132 scoped_refptr<base::MessageLoopProxy> device_loop_; 158 scoped_refptr<base::MessageLoopProxy> device_loop_;
133 159
134 // Only accessed on Browser::IO thread. 160 // Only accessed on Browser::IO thread.
135 MediaStreamProviderListener* listener_; 161 MediaStreamProviderListener* listener_;
136 int new_capture_session_id_; 162 int new_capture_session_id_;
137 163
138 // An entry is kept in this map for every session that has been created via 164 // An entry is kept in this map for every session that has been created via
139 // the Open() entry point. The keys are session_id's. This map is used to 165 // the Open() entry point. The keys are session_id's. This map is used to
140 // determine which device to use when StartCaptureForClient() occurs. Used 166 // determine which device to use when StartCaptureForClient() occurs. Used
(...skipping 20 matching lines...) Expand all
161 187
162 // The controller. Only used from the IO thread. 188 // The controller. Only used from the IO thread.
163 scoped_ptr<VideoCaptureController> video_capture_controller; 189 scoped_ptr<VideoCaptureController> video_capture_controller;
164 190
165 // The capture device. Only used from the device thread. 191 // The capture device. Only used from the device thread.
166 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 192 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
167 }; 193 };
168 typedef std::set<DeviceEntry*> DeviceEntries; 194 typedef std::set<DeviceEntry*> DeviceEntries;
169 DeviceEntries devices_; 195 DeviceEntries devices_;
170 196
197 // Local cache of the enumerated video capture devices' names and capture
198 // supported formats. A snapshot of the current devices and their capabilities
199 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming
200 // from EnumerateDevices()--, and this snapshot is used to update this list in
201 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will
202 // use this list if the device is not started, otherwise it will retrieve the
203 // active device capture format from the VideoCaptureController associated.
204 DeviceInfos devices_info_cache_;
205
171 // For unit testing and for performance/quality tests, a test device can be 206 // For unit testing and for performance/quality tests, a test device can be
172 // used instead of a real one. The device can be a simple fake device (a 207 // used instead of a real one. The device can be a simple fake device (a
173 // rolling pacman), or a file that is played in a loop continuously. This only 208 // rolling pacman), or a file that is played in a loop continuously. This only
174 // applies to the MEDIA_DEVICE_VIDEO_CAPTURE device type. 209 // applies to the MEDIA_DEVICE_VIDEO_CAPTURE device type.
175 enum { 210 enum {
176 DISABLED, 211 DISABLED,
177 TEST_PATTERN, 212 TEST_PATTERN,
178 Y4M_FILE 213 Y4M_FILE
179 } artificial_device_source_for_testing_; 214 } artificial_device_source_for_testing_;
180 215
181 // We cache the enumerated video capture devices in
182 // GetAvailableDevicesOnDeviceThread() and then later look up the requested ID
183 // when a device is created in DoStartDeviceOnDeviceThread(). Used only on the
184 // device thread.
185 media::VideoCaptureDevice::Names video_capture_devices_;
186
187 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); 216 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
188 }; 217 };
189 218
190 } // namespace content 219 } // namespace content
191 220
192 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 221 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_host.h ('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