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/file_util.h"
16 #include "base/files/scoped_file.h"
17 #include "base/threading/thread.h"
18 #include "media/video/capture/video_capture_device.h"
19 #include "media/video/capture/video_capture_types.h"
23 class VideoCaptureDeviceLinux
: public VideoCaptureDevice
{
25 static VideoPixelFormat
V4l2ColorToVideoCaptureColorFormat(int32 v4l2_fourcc
);
26 static void GetListOfUsableFourCCs(bool favour_mjpeg
,
27 std::list
<int>* fourccs
);
29 explicit VideoCaptureDeviceLinux(const Name
& device_name
);
30 virtual ~VideoCaptureDeviceLinux();
32 // VideoCaptureDevice implementation.
33 virtual void AllocateAndStart(const VideoCaptureParams
& params
,
34 scoped_ptr
<Client
> client
) OVERRIDE
;
36 virtual void StopAndDeAllocate() OVERRIDE
;
39 void SetRotation(int rotation
);
41 // Once |v4l2_thread_| is started, only called on that thread.
42 void SetRotationOnV4L2Thread(int rotation
);
46 kIdle
, // The device driver is opened but camera is not in use.
47 kCapturing
, // Video is being captured.
48 kError
// Error accessing HW functions.
49 // User needs to recover by destroying the object.
52 // Buffers used to receive video frames from with v4l2.
54 Buffer() : start(0), length(0) {}
59 // Called on the v4l2_thread_.
60 void OnAllocateAndStart(int width
,
63 scoped_ptr
<Client
> client
);
64 void OnStopAndDeAllocate();
67 bool AllocateVideoBuffers();
68 void DeAllocateVideoBuffers();
69 void SetErrorState(const std::string
& reason
);
72 scoped_ptr
<VideoCaptureDevice::Client
> client_
;
74 base::ScopedFD device_fd_
; // File descriptor for the opened camera device.
75 base::Thread v4l2_thread_
; // Thread used for reading data from the device.
77 int buffer_pool_size_
; // Number of allocated buffers.
79 VideoCaptureFormat capture_format_
;
81 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270.
82 // This is only used on |v4l2_thread_| when it is running, or the constructor
86 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux
);
91 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_