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 // 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 | |
|
Pawel Osciak
2014/09/23 08:15:57
s/captured/is captured/
So the design is that we
Pawel Osciak
2014/09/23 08:15:58
s/has called/has been called/
Owen Lin
2014/09/24 05:20:03
1. Same as the JS interface.
2. We need preview r
Pawel Osciak
2014/09/25 02:16:20
We should tailor APIs to features/devices they exp
Owen Lin
2014/09/25 05:53:53
Sorry, I still prefer the current design. Let me t
Pawel Osciak
2014/09/29 00:13:36
My suggestion would not be adding new features. Th
| |
| 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 class MEDIA_EXPORT ImageClient { | |
|
Pawel Osciak
2014/09/23 08:15:57
Please add documentation what this class is for.
Owen Lin
2014/09/24 05:20:02
Done.
| |
| 231 public: | |
| 232 virtual ~ImageClient() {} | |
| 233 | |
| 234 // Callback function to notify the client the captured image is available. | |
|
Pawel Osciak
2014/09/23 08:15:57
s/the/a/
Owen Lin
2014/09/24 05:20:03
Done.
| |
| 235 // | |
| 236 // The captured still image is stored at address |data| and of |length| | |
|
Pawel Osciak
2014/09/23 08:15:57
s/of/is of/
Owen Lin
2014/09/24 05:20:02
Done.
| |
| 237 // bytes. The format of the frame is described by |format|, and is assumed | |
| 238 // to be tightly/ packed. The still image should be rotated for |rotation| | |
|
wuchengli
2014/09/23 07:09:22
remove extra / after tightly
Pawel Osciak
2014/09/23 08:15:57
s/should/is/ I think?
s/for//
Owen Lin
2014/09/24 05:20:02
Done.
Owen Lin
2014/09/24 05:20:03
There is no rotation information in the raw data.
Pawel Osciak
2014/09/25 02:16:20
So you mean the image doesn't contain EXIF informa
Owen Lin
2014/09/25 05:53:53
It's YUV so there is no rotation info. The rotatio
Pawel Osciak
2014/09/29 00:13:37
Sorry, what should we do? If there is no rotation
| |
| 239 // degrees clockwise for viewing. | |
| 240 // | |
| 241 // Note that the content in |data| would be freed after this callback. | |
|
Pawel Osciak
2014/09/23 08:15:57
s/would be freed/will not be valid/
s/callback/cal
Owen Lin
2014/09/24 05:20:02
Done.
| |
| 242 // Copy the content to use it later. | |
| 243 virtual void OnIncomingCapturedData(const uint8* data, | |
| 244 int length, | |
|
Pawel Osciak
2014/09/23 08:15:57
s/int/size_t/
Owen Lin
2014/09/24 05:20:02
For consistency with Client::OnIncomingCaptureData
Pawel Osciak
2014/09/25 02:16:21
I don't believe we need this consistency. We have
Owen Lin
2014/09/25 05:53:53
Done.
| |
| 245 const ImageCaptureFormat& format, | |
| 246 int rotation, // Clockwise | |
|
Pawel Osciak
2014/09/23 08:15:57
Perhaps remove the comment, it's already in the do
Owen Lin
2014/09/24 05:20:03
Done.
| |
| 247 base::TimeTicks timestamp) = 0; | |
| 248 | |
| 249 // Callback function to notify client the failure of the image capture. | |
|
Pawel Osciak
2014/09/23 08:15:57
s/client/the client/
s/the failure/about a failure
Owen Lin
2014/09/24 05:20:03
Done.
| |
| 250 // The VideoCaptureDevice must be StopAndDeAllocate()-ed. |reason| is a | |
|
Pawel Osciak
2014/09/23 08:15:57
s/is/contains/
Owen Lin
2014/09/24 05:20:03
Done.
| |
| 251 // text description of the error. | |
| 252 virtual void OnError(const std::string& reason) = 0; | |
| 219 }; | 253 }; |
| 220 | 254 |
| 221 // Creates a VideoCaptureDevice object. | 255 // Creates a VideoCaptureDevice object. |
| 222 // Return NULL if the hardware is not available. | 256 // Return NULL if the hardware is not available. |
| 223 static VideoCaptureDevice* Create( | 257 static VideoCaptureDevice* Create( |
| 224 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 258 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 225 const Name& device_name); | 259 const Name& device_name); |
| 226 virtual ~VideoCaptureDevice(); | 260 virtual ~VideoCaptureDevice(); |
| 227 | 261 |
| 228 // Gets the names of all video capture devices connected to this computer. | 262 // Gets the names of all video capture devices connected to this computer. |
| 229 static void GetDeviceNames(Names* device_names); | 263 static void GetDeviceNames(Names* device_names); |
| 230 | 264 |
| 231 // Gets the supported formats of a particular device attached to the system. | 265 // Gets the supported formats of a particular device attached to the system. |
| 232 // This method should be called before allocating or starting a device. In | 266 // This method should be called before allocating or starting a device. In |
| 233 // case format enumeration is not supported, or there was a problem, the | 267 // case format enumeration is not supported, or there was a problem, the |
| 234 // formats array will be empty. | 268 // formats array will be empty. |
| 235 static void GetDeviceSupportedFormats(const Name& device, | 269 static void GetDeviceSupportedFormats(const Name& device, |
| 236 VideoCaptureFormats* supported_formats); | 270 VideoCaptureFormats* supported_formats); |
| 237 | 271 |
| 272 // Gets the supported formats for still image of a particular device attached | |
|
Pawel Osciak
2014/09/23 08:15:56
Gets formats for still image capture supported by
Owen Lin
2014/09/24 05:20:03
Done.
| |
| 273 // to the system. | |
| 274 static void GetDeviceSupportedImageFormats( | |
| 275 const Name& device, | |
| 276 ImageCaptureFormats* supported_formats); | |
| 277 | |
| 238 // Prepares the camera for use. After this function has been called no other | 278 // Prepares the camera for use. After this function has been called no other |
| 239 // applications can use the camera. StopAndDeAllocate() must be called before | 279 // applications can use the camera. StopAndDeAllocate() must be called before |
| 240 // the object is deleted. | 280 // the object is deleted. |
| 241 virtual void AllocateAndStart(const VideoCaptureParams& params, | 281 virtual void AllocateAndStart(const VideoCaptureParams& params, |
| 242 scoped_ptr<Client> client) = 0; | 282 scoped_ptr<Client> client) = 0; |
| 243 | 283 |
| 244 // Deallocates the camera, possibly asynchronously. | 284 // Deallocates the camera, possibly asynchronously. |
| 245 // | 285 // |
| 246 // This call requires the device to do the following things, eventually: put | 286 // 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 | 287 // camera hardware into a state where other applications could use it, free |
| 248 // the memory associated with capture, and delete the |client| pointer passed | 288 // the memory associated with capture, and delete the |client| pointer passed |
| 249 // into AllocateAndStart. | 289 // into AllocateAndStart. |
| 250 // | 290 // |
| 251 // If deallocation is done asynchronously, then the device implementation must | 291 // If deallocation is done asynchronously, then the device implementation must |
| 252 // ensure that a subsequent AllocateAndStart() operation targeting the same ID | 292 // ensure that a subsequent AllocateAndStart() operation targeting the same ID |
| 253 // would be sequenced through the same task runner, so that deallocation | 293 // would be sequenced through the same task runner, so that deallocation |
| 254 // happens first. | 294 // happens first. |
| 255 virtual void StopAndDeAllocate() = 0; | 295 virtual void StopAndDeAllocate() = 0; |
| 256 | 296 |
| 257 // Gets the power line frequency from the current system time zone if this is | 297 // Gets the power line frequency from the current system time zone if this is |
| 258 // defined, otherwise returns 0. | 298 // defined, otherwise returns 0. |
| 259 int GetPowerLineFrequencyForLocation() const; | 299 int GetPowerLineFrequencyForLocation() const; |
| 260 | 300 |
| 301 // Initializes the device for still image capture for the given image format. | |
| 302 // | |
| 303 // This function must be called between AllocateAndStart() and | |
| 304 // StopAndDeAllocate(). | |
|
Pawel Osciak
2014/09/23 08:15:57
Why do we have this requirement?
Owen Lin
2014/09/24 05:20:02
We need the preview on before taking a picture to
Pawel Osciak
2014/09/29 00:13:36
What will happen if it's called at a wrong time (i
| |
| 305 virtual void InitializeImageCapture(const ImageCaptureFormat& image_format, | |
|
Pawel Osciak
2014/09/23 08:15:57
I think we need to have a bool return in case this
Owen Lin
2014/09/24 05:20:03
Fail will be reported by ImageClient::onError().
Pawel Osciak
2014/09/25 02:16:20
I'm assuming you need Initialize to be asynchronou
Owen Lin
2014/09/25 05:53:53
Good point. Let me make this synchronous.
| |
| 306 scoped_ptr<ImageClient> client) {} | |
| 307 | |
| 308 // Releases resources for image capture. | |
| 309 // | |
| 310 // The ImageClient passed from InitializeImageCapture would be freed. This | |
|
Pawel Osciak
2014/09/23 08:15:57
s/would/will/
| |
| 311 // method must be called between InitializeImageCapture() and | |
|
Pawel Osciak
2014/09/29 00:13:37
What will happen if it's called at a wrong time (i
| |
| 312 // StopAndDeAllocate(). | |
| 313 virtual void ReleaseImageCapture() {} | |
| 314 | |
| 315 // Gets one image from the device asynchronously. | |
|
Pawel Osciak
2014/09/23 08:15:57
Asynchronously to what?
Owen Lin
2014/09/24 05:20:03
Did I misuse it ? Asynchronously to this function.
Pawel Osciak
2014/09/25 02:16:20
You should probably say Request instead of Get.
Owen Lin
2014/09/25 05:53:53
Thanks.
| |
| 316 // | |
| 317 // It will return the image by the ImageClient::OnIncomingCapturedData() | |
|
Pawel Osciak
2014/09/23 08:15:56
s/It will return the image by/The image will be re
Owen Lin
2014/09/25 05:53:53
Done.
| |
| 318 // callback. If the video stream has to be stopped to capture the still image, | |
| 319 // the Client::OnMute() and Client::OnUnmute() will be called. | |
| 320 // | |
| 321 // This function must be called between InitializeImageCapture() and | |
|
Pawel Osciak
2014/09/23 08:15:57
Why this requirement?
Owen Lin
2014/09/24 05:20:03
It's the life time of the image_client instance.
Pawel Osciak
2014/09/29 00:13:36
What will happen if that's not the case (in terms
| |
| 322 // ReleaseImageCapture(). | |
| 323 virtual void CaptureImage() {} | |
| 324 | |
| 261 protected: | 325 protected: |
| 262 static const int kPowerLine50Hz = 50; | 326 static const int kPowerLine50Hz = 50; |
| 263 static const int kPowerLine60Hz = 60; | 327 static const int kPowerLine60Hz = 60; |
| 264 }; | 328 }; |
| 265 | 329 |
| 266 } // namespace media | 330 } // namespace media |
| 267 | 331 |
| 268 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 332 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
| OLD | NEW |