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