OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "media/capture/video/linux/v4l2_capture_delegate.h" | 5 #include "media/capture/video/linux/v4l2_capture_delegate.h" |
6 | 6 |
7 #include <poll.h> | 7 #include <poll.h> |
8 #include <sys/fcntl.h> | 8 #include <sys/fcntl.h> |
9 #include <sys/ioctl.h> | 9 #include <sys/ioctl.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 supported_formats.push_back(format.fourcc); | 150 supported_formats.push_back(format.fourcc); |
151 | 151 |
152 // Duplicate MJPEG on top of the list depending on |prefer_mjpeg|. | 152 // Duplicate MJPEG on top of the list depending on |prefer_mjpeg|. |
153 if (prefer_mjpeg) | 153 if (prefer_mjpeg) |
154 supported_formats.push_front(V4L2_PIX_FMT_MJPEG); | 154 supported_formats.push_front(V4L2_PIX_FMT_MJPEG); |
155 | 155 |
156 return supported_formats; | 156 return supported_formats; |
157 } | 157 } |
158 | 158 |
159 V4L2CaptureDelegate::V4L2CaptureDelegate( | 159 V4L2CaptureDelegate::V4L2CaptureDelegate( |
160 const VideoCaptureDevice::Name& device_name, | 160 const VideoCaptureDeviceDescriptor& device_descriptor, |
161 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | 161 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
162 int power_line_frequency) | 162 int power_line_frequency) |
163 : v4l2_task_runner_(v4l2_task_runner), | 163 : v4l2_task_runner_(v4l2_task_runner), |
164 device_name_(device_name), | 164 device_descriptor_(device_descriptor), |
165 power_line_frequency_(power_line_frequency), | 165 power_line_frequency_(power_line_frequency), |
166 is_capturing_(false), | 166 is_capturing_(false), |
167 timeout_count_(0), | 167 timeout_count_(0), |
168 rotation_(0) {} | 168 rotation_(0) {} |
169 | 169 |
170 void V4L2CaptureDelegate::AllocateAndStart( | 170 void V4L2CaptureDelegate::AllocateAndStart( |
171 int width, | 171 int width, |
172 int height, | 172 int height, |
173 float frame_rate, | 173 float frame_rate, |
174 std::unique_ptr<VideoCaptureDevice::Client> client) { | 174 std::unique_ptr<VideoCaptureDevice::Client> client) { |
175 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); | 175 DCHECK(v4l2_task_runner_->BelongsToCurrentThread()); |
176 DCHECK(client); | 176 DCHECK(client); |
177 client_ = std::move(client); | 177 client_ = std::move(client); |
178 | 178 |
179 // Need to open camera with O_RDWR after Linux kernel 3.3. | 179 // Need to open camera with O_RDWR after Linux kernel 3.3. |
180 device_fd_.reset(HANDLE_EINTR(open(device_name_.id().c_str(), O_RDWR))); | 180 device_fd_.reset( |
| 181 HANDLE_EINTR(open(device_descriptor_.device_id.c_str(), O_RDWR))); |
181 if (!device_fd_.is_valid()) { | 182 if (!device_fd_.is_valid()) { |
182 SetErrorState(FROM_HERE, "Failed to open V4L2 device driver file."); | 183 SetErrorState(FROM_HERE, "Failed to open V4L2 device driver file."); |
183 return; | 184 return; |
184 } | 185 } |
185 | 186 |
186 v4l2_capability cap = {}; | 187 v4l2_capability cap = {}; |
187 if (!((HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCAP, &cap)) == 0) && | 188 if (!((HANDLE_EINTR(ioctl(device_fd_.get(), VIDIOC_QUERYCAP, &cap)) == 0) && |
188 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) && | 189 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) && |
189 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)))) { | 190 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)))) { |
190 device_fd_.reset(); | 191 device_fd_.reset(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; | 438 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; |
438 return false; | 439 return false; |
439 } | 440 } |
440 start_ = static_cast<uint8_t*>(start); | 441 start_ = static_cast<uint8_t*>(start); |
441 length_ = buffer.length; | 442 length_ = buffer.length; |
442 payload_size_ = 0; | 443 payload_size_ = 0; |
443 return true; | 444 return true; |
444 } | 445 } |
445 | 446 |
446 } // namespace media | 447 } // namespace media |
OLD | NEW |