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 // VideoCaptureDevice is the abstract base class for realizing video capture | 5 // VideoCaptureDevice is the abstract base class for realizing video capture |
6 // device support in Chromium. It provides the interface for OS dependent | 6 // device support in Chromium. It provides the interface for OS dependent |
7 // implementations. | 7 // implementations. |
8 // The class is created and functions are invoked on a thread owned by | 8 // The class is created and functions are invoked on a thread owned by |
9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS | 9 // VideoCaptureManager. Capturing is done on other threads, depending on the OS |
10 // specific implementation. | 10 // specific implementation. |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 const VideoCaptureFormat& buffer_format, | 209 const VideoCaptureFormat& buffer_format, |
210 const scoped_refptr<media::VideoFrame>& frame, | 210 const scoped_refptr<media::VideoFrame>& frame, |
211 base::TimeTicks timestamp) = 0; | 211 base::TimeTicks timestamp) = 0; |
212 | 212 |
213 // An error has occurred that cannot be handled and VideoCaptureDevice must | 213 // An error has occurred that cannot be handled and VideoCaptureDevice must |
214 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. | 214 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. |
215 virtual void OnError(const std::string& reason) = 0; | 215 virtual void OnError(const std::string& reason) = 0; |
216 | 216 |
217 // VideoCaptureDevice requests the |message| to be logged. | 217 // VideoCaptureDevice requests the |message| to be logged. |
218 virtual void OnLog(const std::string& message) {} | 218 virtual void OnLog(const std::string& message) {} |
219 | |
220 // The video stream has been muted. After this callback, no more | |
221 // OnIncomingCapturedData() will be called. This may happen when | |
222 // CaptureImage() has called. After the still image captured, the client | |
223 // will get notified by OnUnmute() and the video stream will be resumed. | |
224 virtual void OnMute() {} | |
225 | |
226 // The video stream has resumed. | |
227 virtual void OnUnmute() {} | |
228 }; | |
229 | |
230 // Interface for clients that use VideoCaptureDevice for taking still images. | |
231 class MEDIA_EXPORT ImageClient { | |
232 public: | |
233 virtual ~ImageClient() {} | |
234 | |
235 // Callback function to notify the client a captured image is available. | |
236 // | |
237 // The captured still image is stored at address |data| and is of |length| | |
238 // bytes. The format of the frame is described by |format|, and is assumed | |
239 // to be tightly packed. The still image should be rotated |rotation| | |
240 // degrees clockwise for viewing. | |
241 // | |
242 // Note that the content in |data| will not be valid after this callback | |
243 // returns. Copy the content to use it later. | |
244 virtual void OnIncomingCapturedData(const uint8* data, | |
245 int length, | |
246 const ImageCaptureFormat& format, | |
247 int rotation, | |
248 base::TimeTicks timestamp) = 0; | |
249 | |
250 // Callback function to notify the client about a failure of the image | |
251 // capture. The VideoCaptureDevice must be StopAndDeAllocate()-ed. | |
252 // |reason| contains a text description of the error. | |
253 virtual void OnError(const std::string& reason) = 0; | |
219 }; | 254 }; |
220 | 255 |
221 // Creates a VideoCaptureDevice object. | 256 // Creates a VideoCaptureDevice object. |
222 // Return NULL if the hardware is not available. | 257 // Return NULL if the hardware is not available. |
223 static VideoCaptureDevice* Create( | 258 static VideoCaptureDevice* Create( |
224 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 259 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
225 const Name& device_name); | 260 const Name& device_name); |
226 virtual ~VideoCaptureDevice(); | 261 virtual ~VideoCaptureDevice(); |
227 | 262 |
228 // Gets the names of all video capture devices connected to this computer. | 263 // Gets the names of all video capture devices connected to this computer. |
229 static void GetDeviceNames(Names* device_names); | 264 static void GetDeviceNames(Names* device_names); |
230 | 265 |
231 // Gets the supported formats of a particular device attached to the system. | 266 // Gets formats for still image capture supported by a particular |device| |
267 // attached to the system. | |
232 // This method should be called before allocating or starting a device. In | 268 // This method should be called before allocating or starting a device. In |
Pawel Osciak
2014/09/29 00:13:37
What will happen if it's called at a wrong time (i
| |
233 // case format enumeration is not supported, or there was a problem, the | 269 // case format enumeration is not supported, or there was a problem, the |
234 // formats array will be empty. | 270 // formats array will be empty. |
235 static void GetDeviceSupportedFormats(const Name& device, | 271 static void GetDeviceSupportedFormats(const Name& device, |
236 VideoCaptureFormats* supported_formats); | 272 VideoCaptureFormats* supported_formats); |
237 | 273 |
274 // Gets the supported formats for still image of a particular device attached | |
275 // to the system. | |
276 static void GetDeviceSupportedImageFormats( | |
277 const Name& device, | |
278 ImageCaptureFormats* supported_formats); | |
279 | |
238 // Prepares the camera for use. After this function has been called no other | 280 // Prepares the camera for use. After this function has been called no other |
239 // applications can use the camera. StopAndDeAllocate() must be called before | 281 // applications can use the camera. StopAndDeAllocate() must be called before |
240 // the object is deleted. | 282 // the object is deleted. |
241 virtual void AllocateAndStart(const VideoCaptureParams& params, | 283 virtual void AllocateAndStart(const VideoCaptureParams& params, |
242 scoped_ptr<Client> client) = 0; | 284 scoped_ptr<Client> client) = 0; |
243 | 285 |
244 // Deallocates the camera, possibly asynchronously. | 286 // Deallocates the camera, possibly asynchronously. |
245 // | 287 // |
246 // This call requires the device to do the following things, eventually: put | 288 // This call requires the device to do the following things, eventually: put |
247 // camera hardware into a state where other applications could use it, free | 289 // camera hardware into a state where other applications could use it, free |
248 // the memory associated with capture, and delete the |client| pointer passed | 290 // the memory associated with capture, and delete the |client| pointer passed |
249 // into AllocateAndStart. | 291 // into AllocateAndStart. |
250 // | 292 // |
251 // If deallocation is done asynchronously, then the device implementation must | 293 // If deallocation is done asynchronously, then the device implementation must |
252 // ensure that a subsequent AllocateAndStart() operation targeting the same ID | 294 // ensure that a subsequent AllocateAndStart() operation targeting the same ID |
253 // would be sequenced through the same task runner, so that deallocation | 295 // would be sequenced through the same task runner, so that deallocation |
254 // happens first. | 296 // happens first. |
255 virtual void StopAndDeAllocate() = 0; | 297 virtual void StopAndDeAllocate() = 0; |
256 | 298 |
257 // Gets the power line frequency from the current system time zone if this is | 299 // Gets the power line frequency from the current system time zone if this is |
258 // defined, otherwise returns 0. | 300 // defined, otherwise returns 0. |
259 int GetPowerLineFrequencyForLocation() const; | 301 int GetPowerLineFrequencyForLocation() const; |
260 | 302 |
303 // Initializes the device for still image capture for the given image format. | |
304 // | |
305 // This function must be called between AllocateAndStart() and | |
306 // StopAndDeAllocate(). | |
307 virtual void InitializeImageCapture(const ImageCaptureFormat& image_format, | |
308 scoped_ptr<ImageClient> client) {} | |
309 | |
310 // Releases resources for image capture. | |
311 // | |
312 // The ImageClient passed from InitializeImageCapture will be freed. This | |
313 // method must be called between InitializeImageCapture() and | |
314 // StopAndDeAllocate(). | |
315 virtual void ReleaseImageCapture() {} | |
316 | |
317 // Gets one image from the device asynchronously. | |
318 // | |
319 // The image will be returned via the ImageClient::OnIncomingCapturedData() | |
320 // callback. If the video stream has to be stopped to capture the still image, | |
321 // the Client::OnMute() and Client::OnUnmute() will be called. | |
322 // | |
323 // This function must be called between InitializeImageCapture() and | |
324 // ReleaseImageCapture(). | |
325 virtual void CaptureImage() {} | |
326 | |
261 protected: | 327 protected: |
262 static const int kPowerLine50Hz = 50; | 328 static const int kPowerLine50Hz = 50; |
263 static const int kPowerLine60Hz = 60; | 329 static const int kPowerLine60Hz = 60; |
264 }; | 330 }; |
265 | 331 |
266 } // namespace media | 332 } // namespace media |
267 | 333 |
268 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 334 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |