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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 const VideoCaptureFormat& buffer_format, | 224 const VideoCaptureFormat& buffer_format, |
225 const scoped_refptr<media::VideoFrame>& frame, | 225 const scoped_refptr<media::VideoFrame>& frame, |
226 base::TimeTicks timestamp) = 0; | 226 base::TimeTicks timestamp) = 0; |
227 | 227 |
228 // An error has occurred that cannot be handled and VideoCaptureDevice must | 228 // An error has occurred that cannot be handled and VideoCaptureDevice must |
229 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. | 229 // be StopAndDeAllocate()-ed. |reason| is a text description of the error. |
230 virtual void OnError(const std::string& reason) = 0; | 230 virtual void OnError(const std::string& reason) = 0; |
231 | 231 |
232 // VideoCaptureDevice requests the |message| to be logged. | 232 // VideoCaptureDevice requests the |message| to be logged. |
233 virtual void OnLog(const std::string& message) {} | 233 virtual void OnLog(const std::string& message) {} |
| 234 |
| 235 // The video stream has been muted. After this callback, no more |
| 236 // OnIncomingCapturedData() will be called. This may happen when |
| 237 // CaptureImage() has called. After the still image captured, the client |
| 238 // will get notified by OnUnmute() and the video stream will be resumed. |
| 239 virtual void OnMute() {} |
| 240 |
| 241 // The video stream has resumed. |
| 242 virtual void OnUnmute() {} |
| 243 }; |
| 244 |
| 245 // Interface for clients that use VideoCaptureDevice for taking still images. |
| 246 class MEDIA_EXPORT ImageClient { |
| 247 public: |
| 248 virtual ~ImageClient() {} |
| 249 |
| 250 // Callback function to notify the client a captured image is available. |
| 251 // |
| 252 // The captured still image is stored at address |data| and is of |length| |
| 253 // bytes. The format of the frame is described by |format|, and is assumed |
| 254 // to be tightly packed. The still image should be rotated |rotation| |
| 255 // degrees clockwise for viewing. |
| 256 // |
| 257 // Note that the content in |data| will not be valid after this callback |
| 258 // returns. Copy the content to use it later. |
| 259 virtual void OnIncomingCapturedData(const uint8* data, |
| 260 size_t length, |
| 261 const ImageCaptureFormat& format, |
| 262 int rotation, |
| 263 base::TimeTicks timestamp) = 0; |
| 264 |
| 265 // Callback function to notify the client about a failure of the image |
| 266 // capture. The VideoCaptureDevice must be StopAndDeAllocate()-ed. |
| 267 // |reason| contains a text description of the error. |
| 268 virtual void OnError(const std::string& reason) = 0; |
234 }; | 269 }; |
235 | 270 |
236 virtual ~VideoCaptureDevice(); | 271 virtual ~VideoCaptureDevice(); |
237 | 272 |
238 // Prepares the camera for use. After this function has been called no other | 273 // Prepares the camera for use. After this function has been called no other |
239 // applications can use the camera. StopAndDeAllocate() must be called before | 274 // applications can use the camera. StopAndDeAllocate() must be called before |
240 // the object is deleted. | 275 // the object is deleted. |
241 virtual void AllocateAndStart(const VideoCaptureParams& params, | 276 virtual void AllocateAndStart(const VideoCaptureParams& params, |
242 scoped_ptr<Client> client) = 0; | 277 scoped_ptr<Client> client) = 0; |
243 | 278 |
244 // Deallocates the camera, possibly asynchronously. | 279 // Deallocates the camera, possibly asynchronously. |
245 // | 280 // |
246 // This call requires the device to do the following things, eventually: put | 281 // 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 | 282 // camera hardware into a state where other applications could use it, free |
248 // the memory associated with capture, and delete the |client| pointer passed | 283 // the memory associated with capture, and delete the |client| pointer passed |
249 // into AllocateAndStart. | 284 // into AllocateAndStart. |
250 // | 285 // |
251 // If deallocation is done asynchronously, then the device implementation must | 286 // If deallocation is done asynchronously, then the device implementation must |
252 // ensure that a subsequent AllocateAndStart() operation targeting the same ID | 287 // ensure that a subsequent AllocateAndStart() operation targeting the same ID |
253 // would be sequenced through the same task runner, so that deallocation | 288 // would be sequenced through the same task runner, so that deallocation |
254 // happens first. | 289 // happens first. |
255 virtual void StopAndDeAllocate() = 0; | 290 virtual void StopAndDeAllocate() = 0; |
256 | 291 |
257 // Gets the power line frequency from the current system time zone if this is | 292 // Gets the power line frequency from the current system time zone if this is |
258 // defined, otherwise returns 0. | 293 // defined, otherwise returns 0. |
259 int GetPowerLineFrequencyForLocation() const; | 294 int GetPowerLineFrequencyForLocation() const; |
260 | 295 |
| 296 // Initializes the device for still image capture for the given image format. |
| 297 // This call is synchronous and returns true iff the initialization is |
| 298 // successful. |
| 299 // |
| 300 // This function must be called between AllocateAndStart() and |
| 301 // StopAndDeAllocate(). |
| 302 virtual bool InitializeImageCapture(const ImageCaptureFormat& image_format, |
| 303 scoped_ptr<ImageClient> client); |
| 304 |
| 305 // Releases resources for image capture. |
| 306 // |
| 307 // The ImageClient passed from InitializeImageCapture will be freed. This |
| 308 // method must be called between InitializeImageCapture() and |
| 309 // StopAndDeAllocate(). |
| 310 virtual void ReleaseImageCapture() {} |
| 311 |
| 312 // Requests one image from the device. |
| 313 // |
| 314 // The image will be returned via the ImageClient::OnIncomingCapturedData() |
| 315 // callback. If the video stream has to be stopped to capture the still image, |
| 316 // the Client::OnMute() and Client::OnUnmute() will be called. |
| 317 // |
| 318 // This function must be called between InitializeImageCapture() and |
| 319 // ReleaseImageCapture(). |
| 320 virtual void CaptureImage() {} |
| 321 |
261 protected: | 322 protected: |
262 static const int kPowerLine50Hz = 50; | 323 static const int kPowerLine50Hz = 50; |
263 static const int kPowerLine60Hz = 60; | 324 static const int kPowerLine60Hz = 60; |
264 }; | 325 }; |
265 | 326 |
266 } // namespace media | 327 } // namespace media |
267 | 328 |
268 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ | 329 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_DEVICE_H_ |
OLD | NEW |