| 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 // Linux specific implementation of VideoCaptureDevice. | 5 // Linux specific implementation of VideoCaptureDevice. |
| 6 // V4L2 is used for capturing. V4L2 does not provide its own thread for | 6 // V4L2 is used for capturing. V4L2 does not provide its own thread for |
| 7 // capturing so this implementation uses a Chromium thread for fetching frames | 7 // capturing so this implementation uses a Chromium thread for fetching frames |
| 8 // from V4L2. | 8 // from V4L2. |
| 9 | 9 |
| 10 #ifndef MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_ | 10 #ifndef MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 explicit VideoCaptureDeviceLinux(const Name& device_name); | 23 explicit VideoCaptureDeviceLinux(const Name& device_name); |
| 24 virtual ~VideoCaptureDeviceLinux(); | 24 virtual ~VideoCaptureDeviceLinux(); |
| 25 | 25 |
| 26 // VideoCaptureDevice implementation. | 26 // VideoCaptureDevice implementation. |
| 27 virtual void Allocate(const VideoCaptureCapability& capture_format, | 27 virtual void Allocate(const VideoCaptureCapability& capture_format, |
| 28 EventHandler* observer) OVERRIDE; | 28 EventHandler* observer) OVERRIDE; |
| 29 virtual void Start() OVERRIDE; | 29 virtual void Start() OVERRIDE; |
| 30 virtual void Stop() OVERRIDE; | 30 virtual void Stop() OVERRIDE; |
| 31 virtual void DeAllocate() OVERRIDE; | 31 virtual void DeAllocate() OVERRIDE; |
| 32 virtual const Name& device_name() OVERRIDE; | 32 virtual const Name& device_name() OVERRIDE; |
| 33 virtual void GetDeviceSupportedFormats( |
| 34 scoped_ptr<EventHandler> client) OVERRIDE; |
| 33 | 35 |
| 34 private: | 36 private: |
| 35 enum InternalState { | 37 enum InternalState { |
| 36 kIdle, // The device driver is opened but camera is not in use. | 38 kIdle, // The device driver is opened but camera is not in use. |
| 37 kAllocated, // The camera has been allocated and can be started. | 39 kAllocated, // The camera has been allocated and can be started. |
| 38 kCapturing, // Video is being captured. | 40 kCapturing, // Video is being captured. |
| 39 kError // Error accessing HW functions. | 41 kError // Error accessing HW functions. |
| 40 // User needs to recover by destroying the object. | 42 // User needs to recover by destroying the object. |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 // Buffers used to receive video frames from with v4l2. | 45 // Buffers used to receive video frames from with v4l2. |
| 44 struct Buffer { | 46 struct Buffer { |
| 45 Buffer() : start(0), length(0) {} | 47 Buffer() : start(0), length(0) {} |
| 46 void* start; | 48 void* start; |
| 47 size_t length; | 49 size_t length; |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 // Called on the v4l2_thread_. | 52 // Called on the v4l2_thread_. |
| 51 void OnAllocate(int width, | 53 void OnAllocate(int width, |
| 52 int height, | 54 int height, |
| 53 int frame_rate, | 55 int frame_rate, |
| 54 EventHandler* observer); | 56 EventHandler* observer); |
| 55 void OnStart(); | 57 void OnStart(); |
| 56 void OnStop(); | 58 void OnStop(); |
| 57 void OnDeAllocate(); | 59 void OnDeAllocate(); |
| 58 void OnCaptureTask(); | 60 void OnCaptureTask(); |
| 61 void OnGetDeviceSupportedFormats(EventHandler* observer); |
| 59 | 62 |
| 60 bool AllocateVideoBuffers(); | 63 bool AllocateVideoBuffers(); |
| 61 void DeAllocateVideoBuffers(); | 64 void DeAllocateVideoBuffers(); |
| 62 void SetErrorState(const std::string& reason); | 65 void SetErrorState(const std::string& reason); |
| 63 | 66 |
| 64 InternalState state_; | 67 InternalState state_; |
| 65 VideoCaptureDevice::EventHandler* observer_; | 68 VideoCaptureDevice::EventHandler* observer_; |
| 66 Name device_name_; | 69 Name device_name_; |
| 67 int device_fd_; // File descriptor for the opened camera device. | 70 int device_fd_; // File descriptor for the opened camera device. |
| 68 base::Thread v4l2_thread_; // Thread used for reading data from the device. | 71 base::Thread v4l2_thread_; // Thread used for reading data from the device. |
| 69 Buffer* buffer_pool_; | 72 Buffer* buffer_pool_; |
| 70 int buffer_pool_size_; // Number of allocated buffers. | 73 int buffer_pool_size_; // Number of allocated buffers. |
| 71 int timeout_count_; | 74 int timeout_count_; |
| 72 | 75 |
| 73 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux); | 76 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux); |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 } // namespace media | 79 } // namespace media |
| 77 | 80 |
| 78 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_ | 81 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_ |
| OLD | NEW |