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

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

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

Powered by Google App Engine
This is Rietveld 408576698