Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: media/video/capture/linux/video_capture_device_linux.h

Issue 270263008: Add a ChromeOS implementation of VideoCaptureDevice (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_
11 #define MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_ 11 #define MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_
12 12
13 #include <string> 13 #include <string>
14 14
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/files/scoped_file.h" 16 #include "base/files/scoped_file.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "media/video/capture/video_capture_device.h" 18 #include "media/video/capture/video_capture_device.h"
19 #include "media/video/capture/video_capture_types.h" 19 #include "media/video/capture/video_capture_types.h"
20 #include "ui/gfx/display.h"
21 #include "ui/gfx/display_observer.h"
20 22
21 namespace media { 23 namespace media {
22 24
23 class VideoCaptureDeviceLinux : public VideoCaptureDevice { 25 class VideoCaptureDeviceLinux : public gfx::DisplayObserver,
26 public VideoCaptureDevice {
24 public: 27 public:
25 explicit VideoCaptureDeviceLinux(const Name& device_name); 28 explicit VideoCaptureDeviceLinux(const Name& device_name);
26 virtual ~VideoCaptureDeviceLinux(); 29 virtual ~VideoCaptureDeviceLinux();
27 30
28 // VideoCaptureDevice implementation. 31 // VideoCaptureDevice implementation.
29 virtual void AllocateAndStart(const VideoCaptureParams& params, 32 virtual void AllocateAndStart(const VideoCaptureParams& params,
30 scoped_ptr<Client> client) OVERRIDE; 33 scoped_ptr<Client> client) OVERRIDE;
31 34
32 virtual void StopAndDeAllocate() OVERRIDE; 35 virtual void StopAndDeAllocate() OVERRIDE;
33 36
34 private: 37 private:
35 enum InternalState { 38 enum InternalState {
36 kIdle, // The device driver is opened but camera is not in use. 39 kIdle, // The device driver is opened but camera is not in use.
37 kCapturing, // Video is being captured. 40 kCapturing, // Video is being captured.
38 kError // Error accessing HW functions. 41 kError // Error accessing HW functions.
39 // User needs to recover by destroying the object. 42 // User needs to recover by destroying the object.
40 }; 43 };
41 44
42 // Buffers used to receive video frames from with v4l2. 45 // Buffers used to receive video frames from with v4l2.
43 struct Buffer { 46 struct Buffer {
44 Buffer() : start(0), length(0) {} 47 Buffer() : start(0), length(0) {}
45 void* start; 48 void* start;
46 size_t length; 49 size_t length;
47 }; 50 };
48 51
52 // gfx::DisplayObserver:
53 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
54 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
55 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
56
57 // Once v4l2_thread_ is started, only called on that thread.
mcasas 2014/05/09 10:32:16 |v4l2_thread_|
58 void SetDisplayRotation(const gfx::Display& display);
59
49 // Called on the v4l2_thread_. 60 // Called on the v4l2_thread_.
50 void OnAllocateAndStart(int width, 61 void OnAllocateAndStart(int width,
51 int height, 62 int height,
52 int frame_rate, 63 int frame_rate,
53 scoped_ptr<Client> client); 64 scoped_ptr<Client> client);
54 void OnStopAndDeAllocate(); 65 void OnStopAndDeAllocate();
55 void OnCaptureTask(); 66 void OnCaptureTask();
56 67
57 bool AllocateVideoBuffers(); 68 bool AllocateVideoBuffers();
58 void DeAllocateVideoBuffers(); 69 void DeAllocateVideoBuffers();
59 void SetErrorState(const std::string& reason); 70 void SetErrorState(const std::string& reason);
60 71
61 InternalState state_; 72 InternalState state_;
62 scoped_ptr<VideoCaptureDevice::Client> client_; 73 scoped_ptr<VideoCaptureDevice::Client> client_;
63 Name device_name_; 74 Name device_name_;
64 base::ScopedFD device_fd_; // File descriptor for the opened camera device. 75 base::ScopedFD device_fd_; // File descriptor for the opened camera device.
65 base::Thread v4l2_thread_; // Thread used for reading data from the device. 76 base::Thread v4l2_thread_; // Thread used for reading data from the device.
66 Buffer* buffer_pool_; 77 Buffer* buffer_pool_;
67 int buffer_pool_size_; // Number of allocated buffers. 78 int buffer_pool_size_; // Number of allocated buffers.
68 int timeout_count_; 79 int timeout_count_;
69 VideoCaptureFormat capture_format_; 80 VideoCaptureFormat capture_format_;
81 gfx::Display::Rotation display_rotation_;
70 82
71 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux); 83 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceLinux);
72 }; 84 };
73 85
74 } // namespace media 86 } // namespace media
75 87
76 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_ 88 #endif // MEDIA_VIDEO_CAPTURE_LINUX_VIDEO_CAPTURE_DEVICE_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698