linux_aura: Disable the plugin install infobar.
[chromium-blink-merge.git] / media / video / capture / linux / video_capture_device_linux.h
blob5415eb744d996f06159862a6ef04bc6093eb53f0
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
8 // from V4L2.
10 #ifndef MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_
11 #define MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_
13 #include <string>
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"
21 namespace media {
23 class VideoCaptureDeviceLinux : public VideoCaptureDevice {
24 public:
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;
38 protected:
39 void SetRotation(int rotation);
41 // Once |v4l2_thread_| is started, only called on that thread.
42 void SetRotationOnV4L2Thread(int rotation);
44 private:
45 enum InternalState {
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.
53 struct Buffer {
54 Buffer() : start(0), length(0) {}
55 void* start;
56 size_t length;
59 // Called on the v4l2_thread_.
60 void OnAllocateAndStart(int width,
61 int height,
62 int frame_rate,
63 scoped_ptr<Client> client);
64 void OnStopAndDeAllocate();
65 void OnCaptureTask();
67 bool AllocateVideoBuffers();
68 void DeAllocateVideoBuffers();
69 void SetErrorState(const std::string& reason);
71 InternalState state_;
72 scoped_ptr<VideoCaptureDevice::Client> client_;
73 Name device_name_;
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.
76 Buffer* buffer_pool_;
77 int buffer_pool_size_; // Number of allocated buffers.
78 int timeout_count_;
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
83 // thread otherwise.
84 int rotation_;
86 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux);
89 } // namespace media
91 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_