Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 87 // capabilities are cached during device(s) enumeration and updated as clients | |
| 88 // open the device(s). This call is asynchronous but expected to return fast | |
| 89 // since the capabilities are cached; the reply will be received in | |
| 90 // listener_->DeviceCapabilitiesEnumerated(). | |
|
perkj_chrome
2013/10/29 12:13:36
This is not what we discussed. You want to access
| |
| 91 void EnumerateDeviceCapabilities(const StreamDeviceInfo& device_info); | |
| 92 | |
| 85 private: | 93 private: |
| 86 virtual ~VideoCaptureManager(); | 94 virtual ~VideoCaptureManager(); |
| 87 struct DeviceEntry; | 95 struct DeviceEntry; |
| 88 | 96 |
| 89 // Check to see if |entry| has no clients left on its controller. If so, | 97 // 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| | 98 // remove it from the list of devices, and delete it asynchronously. |entry| |
| 91 // may be freed by this function. | 99 // may be freed by this function. |
| 92 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); | 100 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); |
| 93 | 101 |
| 94 // Helpers to report an event to our Listener. | 102 // Helpers to report an event to our Listener. |
| 95 void OnOpened(MediaStreamType type, int capture_session_id); | 103 void OnOpened(MediaStreamType type, int capture_session_id); |
| 96 void OnClosed(MediaStreamType type, int capture_session_id); | 104 void OnClosed(MediaStreamType type, int capture_session_id); |
| 97 void OnDevicesEnumerated(MediaStreamType stream_type, | 105 void OnDevicesEnumerated(MediaStreamType stream_type, |
| 98 const media::VideoCaptureDevice::Names& names); | 106 const media::VideoCaptureDevice::Names& names); |
| 107 void OnDeviceCapabilitiesEnumerated( | |
| 108 const StreamDeviceInfo& device_info, | |
| 109 const media::VideoCaptureCapabilities& capabilities); | |
| 99 | 110 |
| 100 // Find a DeviceEntry by its device ID and type, if it is already opened. | 111 // Find a DeviceEntry by its device ID and type, if it is already opened. |
| 101 DeviceEntry* GetDeviceEntryForMediaStreamDevice( | 112 DeviceEntry* GetDeviceEntryForMediaStreamDevice( |
| 102 const MediaStreamDevice& device_info); | 113 const MediaStreamDevice& device_info); |
| 103 | 114 |
| 104 // Find a DeviceEntry entry for the indicated session, creating a fresh one | 115 // Find a DeviceEntry entry for the indicated session, creating a fresh one |
| 105 // if necessary. Returns NULL if the session id is invalid. | 116 // if necessary. Returns NULL if the session id is invalid. |
| 106 DeviceEntry* GetOrCreateDeviceEntry(int capture_session_id); | 117 DeviceEntry* GetOrCreateDeviceEntry(int capture_session_id); |
| 107 | 118 |
| 108 // Find the DeviceEntry that owns a particular controller pointer. | 119 // Find the DeviceEntry that owns a particular controller pointer. |
| 109 DeviceEntry* GetDeviceEntryForController( | 120 DeviceEntry* GetDeviceEntryForController( |
| 110 const VideoCaptureController* controller); | 121 const VideoCaptureController* controller); |
| 111 | 122 |
| 112 bool IsOnDeviceThread() const; | 123 bool IsOnDeviceThread() const; |
| 113 | 124 |
| 114 // Queries and returns the available device IDs. | 125 // Queries and returns the available device IDs. |
| 115 media::VideoCaptureDevice::Names GetAvailableDevicesOnDeviceThread( | 126 media::VideoCaptureDevice::Names GetAvailableDevicesOnDeviceThread( |
| 116 MediaStreamType stream_type); | 127 MediaStreamType stream_type); |
| 117 | 128 |
| 129 // Queries and returns the video capture capabilities of a device. | |
| 130 media::VideoCaptureCapabilities GetDeviceCapabilitiesOnDeviceThread( | |
| 131 const StreamDeviceInfo& device_info); | |
| 132 | |
| 118 // Create and Start a new VideoCaptureDevice, storing the result in | 133 // Create and Start a new VideoCaptureDevice, storing the result in |
| 119 // |entry->video_capture_device|. Ownership of |client| passes to | 134 // |entry->video_capture_device|. Ownership of |client| passes to |
| 120 // the device. | 135 // the device. |
| 121 void DoStartDeviceOnDeviceThread( | 136 void DoStartDeviceOnDeviceThread( |
| 122 DeviceEntry* entry, | 137 DeviceEntry* entry, |
| 123 const media::VideoCaptureCapability& capture_params, | 138 const media::VideoCaptureCapability& capture_params, |
| 124 scoped_ptr<media::VideoCaptureDevice::Client> client); | 139 scoped_ptr<media::VideoCaptureDevice::Client> client); |
| 125 | 140 |
| 126 // Stop and destroy the VideoCaptureDevice held in | 141 // Stop and destroy the VideoCaptureDevice held in |
| 127 // |entry->video_capture_device|. | 142 // |entry->video_capture_device|. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 // The capture device. Only used from the device thread. | 179 // The capture device. Only used from the device thread. |
| 165 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 180 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
| 166 }; | 181 }; |
| 167 typedef std::set<DeviceEntry*> DeviceEntries; | 182 typedef std::set<DeviceEntry*> DeviceEntries; |
| 168 DeviceEntries devices_; | 183 DeviceEntries devices_; |
| 169 | 184 |
| 170 // Set to true if using fake video capture devices for testing, false by | 185 // 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. | 186 // default. This is only used for the MEDIA_DEVICE_VIDEO_CAPTURE device type. |
| 172 bool use_fake_device_; | 187 bool use_fake_device_; |
| 173 | 188 |
| 174 // We cache the enumerated video capture devices in | 189 // This class is a convenient wrap of a devices' name and associated video |
| 175 // GetAvailableDevicesOnDeviceThread() and then later look up the requested ID | 190 // capture capabilities. |
| 176 // when a device is created in DoStartDeviceOnDeviceThread(). Used only on the | 191 class DeviceInfo { |
|
miu
2013/10/29 18:43:27
C++ style: struct, not class
| |
| 177 // device thread. | 192 public: |
| 178 media::VideoCaptureDevice::Names video_capture_devices_; | 193 DeviceInfo(); |
| 194 DeviceInfo(const media::VideoCaptureDevice::Name& name, | |
| 195 const media::VideoCaptureCapabilities& capabilities); | |
| 196 ~DeviceInfo(); | |
| 197 | |
| 198 media::VideoCaptureDevice::Name name_; | |
| 199 media::VideoCaptureCapabilities capabilities_; | |
| 200 }; | |
| 201 // Local cache of the enumerated video capture devices' names and capture | |
| 202 // capabilities. This cache is created in GetAvailableDevicesOnDeviceThread() | |
| 203 // and used via requested ID lookup when a device is created in | |
| 204 // DoStartDeviceOnDeviceThread(). The cache is only used in device thread. | |
| 205 // The capabilities are retrieved via EnumerateDeviceCapabilities(). | |
| 206 std::vector<class DeviceInfo> devices_info_cache_; | |
|
miu
2013/10/29 18:43:27
remove "class "
miu
2013/10/29 18:43:27
Consider making this a vector<DeviceInfo*> instead
tommi (sloooow) - chröme
2013/10/29 20:26:24
+1.
base::ScopedVector could come in handy:
https:
| |
| 207 class DeviceInfo* FindDeviceInfoById(const std::string& id); | |
|
miu
2013/10/29 18:43:27
remove "class "
miu
2013/10/29 18:43:27
C++ style: Move this method up (before data member
| |
| 208 | |
| 179 | 209 |
| 180 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 210 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 181 }; | 211 }; |
| 182 | 212 |
| 183 } // namespace content | 213 } // namespace content |
| 184 | 214 |
| 185 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 215 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |