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
3 // found in the LICENSE file.
5 // Linux specific implementation of VideoCaptureDevice.
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
10 #ifndef MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_
11 #define MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_
15 #include "base/threading/thread.h"
16 #include "media/video/capture/video_capture_device.h"
17 #include "media/video/capture/video_capture_types.h"
21 class VideoCaptureDeviceLinux : public VideoCaptureDevice {
23 explicit VideoCaptureDeviceLinux(const Name& device_name);
24 virtual ~VideoCaptureDeviceLinux();
26 // VideoCaptureDevice implementation.
27 virtual void AllocateAndStart(const VideoCaptureCapability& capture_format,
28 scoped_ptr<Client> client) OVERRIDE;
30 virtual void StopAndDeAllocate() OVERRIDE;
34 kIdle, // The device driver is opened but camera is not in use.
35 kCapturing, // Video is being captured.
36 kError // Error accessing HW functions.
37 // User needs to recover by destroying the object.
40 // Buffers used to receive video frames from with v4l2.
42 Buffer() : start(0), length(0) {}
47 // Called on the v4l2_thread_.
48 void OnAllocateAndStart(int width,
51 scoped_ptr<Client> client);
52 void OnStopAndDeAllocate();
55 bool AllocateVideoBuffers();
56 void DeAllocateVideoBuffers();
57 void SetErrorState(const std::string& reason);
60 scoped_ptr<VideoCaptureDevice::Client> client_;
62 int device_fd_; // File descriptor for the opened camera device.
63 base::Thread v4l2_thread_; // Thread used for reading data from the device.
65 int buffer_pool_size_; // Number of allocated buffers.
68 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux);
73 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_