| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/timer.h" | |
| 12 | |
| 13 class SkBitmap; | |
| 14 | |
| 15 namespace base { | |
| 16 class TimeDelta; | |
| 17 } // namespace base | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 // Class that wraps interaction with video capturing device. Returns | |
| 22 // frames captured with specified intervals of time via delegate interface. | |
| 23 class Camera { | |
| 24 public: | |
| 25 class Delegate { | |
| 26 public: | |
| 27 virtual ~Delegate() {} | |
| 28 | |
| 29 // Called with specified intervals with decoded frame as a parameter. | |
| 30 virtual void OnVideoFrameCaptured(const SkBitmap& frame) = 0; | |
| 31 }; | |
| 32 | |
| 33 explicit Camera(Delegate* delegate); | |
| 34 ~Camera(); | |
| 35 | |
| 36 // Initializes camera device. Returns true if succeeded, false otherwise. | |
| 37 // Does nothing on subsequent calls until Uninitialize is called. | |
| 38 // Sets the desired width and height of the frame to receive from camera. | |
| 39 bool Initialize(int desired_width, int desired_height); | |
| 40 | |
| 41 // Uninitializes the camera. Can be called anytime, any number of times. | |
| 42 void Uninitialize(); | |
| 43 | |
| 44 // Starts capturing video frames with specified interval. | |
| 45 // Does nothing on subsequent calls until StopCapturing is called. | |
| 46 // Returns true if succeeded, false otherwise. | |
| 47 bool StartCapturing(const base::TimeDelta& interval); | |
| 48 | |
| 49 // Stops capturing video frames. Can be called anytime, any number of | |
| 50 // times. | |
| 51 void StopCapturing(); | |
| 52 | |
| 53 private: | |
| 54 // Tries to open the device with specified name. Returns opened device | |
| 55 // descriptor if succeeds, -1 otherwise. | |
| 56 int OpenDevice(const char* device_name) const; | |
| 57 | |
| 58 // Initializes reading mode for the device. Returns true on success, false | |
| 59 // otherwise. | |
| 60 bool InitializeReadingMode(int fd); | |
| 61 | |
| 62 // Unmaps video buffers stored in |buffers_|. | |
| 63 void UnmapVideoBuffers(); | |
| 64 | |
| 65 // Called by |timer_| to get the frame from video device and send it to | |
| 66 // |delegate_| via its method. | |
| 67 void OnCapture(); | |
| 68 | |
| 69 // Reads a frame from the video device. If retry is needed, returns false. | |
| 70 // Otherwise, returns true despite of success status. | |
| 71 bool ReadFrame(); | |
| 72 | |
| 73 // Transforms raw data received from camera into SkBitmap with desired | |
| 74 // size and notifies the delegate that the image is ready. | |
| 75 void ProcessImage(void* data); | |
| 76 | |
| 77 // Defines a buffer in memory where one frame from the camera is stored. | |
| 78 struct VideoBuffer { | |
| 79 void* start; | |
| 80 size_t length; | |
| 81 }; | |
| 82 | |
| 83 // Delegate that receives the frames from the camera. | |
| 84 Delegate* delegate_; | |
| 85 | |
| 86 // Name of the device file, i.e. "/dev/video0". | |
| 87 std::string device_name_; | |
| 88 | |
| 89 // File descriptor of the opened device. | |
| 90 int device_descriptor_; | |
| 91 | |
| 92 // Vector of buffers where to store video frames from camera. | |
| 93 std::vector<VideoBuffer> buffers_; | |
| 94 | |
| 95 // Timer for getting frames. | |
| 96 base::RepeatingTimer<Camera> timer_; | |
| 97 | |
| 98 // Desired size of the frame to get from camera. If it doesn't match | |
| 99 // camera's supported resolution, higher resolution is selected (if | |
| 100 // available) and frame is cropped. If higher resolution is not available, | |
| 101 // the highest is selected and resized. | |
| 102 int desired_width_; | |
| 103 int desired_height_; | |
| 104 | |
| 105 // Size of the frame that camera will give to us. It may not match the | |
| 106 // desired size. | |
| 107 int frame_width_; | |
| 108 int frame_height_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(Camera); | |
| 111 }; | |
| 112 | |
| 113 } // namespace chromeos | |
| 114 | |
| 115 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_H_ | |
| OLD | NEW |