OLD | NEW |
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 #include "media/video/capture/linux/video_capture_device_linux.h" | 5 #include "media/video/capture/linux/video_capture_device_linux.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #if defined(OS_OPENBSD) | 9 #if defined(OS_OPENBSD) |
10 #include <sys/videoio.h> | 10 #include <sys/videoio.h> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // Time to wait in milliseconds before v4l2_thread_ reschedules OnCaptureTask | 43 // Time to wait in milliseconds before v4l2_thread_ reschedules OnCaptureTask |
44 // if an event is triggered (select) but no video frame is read. | 44 // if an event is triggered (select) but no video frame is read. |
45 enum { kCaptureSelectWaitMs = 10 }; | 45 enum { kCaptureSelectWaitMs = 10 }; |
46 | 46 |
47 // V4L2 color formats VideoCaptureDeviceLinux support. | 47 // V4L2 color formats VideoCaptureDeviceLinux support. |
48 static const int32 kV4l2Fmts[] = { | 48 static const int32 kV4l2Fmts[] = { |
49 V4L2_PIX_FMT_YUV420, | 49 V4L2_PIX_FMT_YUV420, |
50 V4L2_PIX_FMT_YUYV | 50 V4L2_PIX_FMT_YUYV |
51 }; | 51 }; |
52 | 52 |
53 static VideoCaptureDevice::Format V4l2ColorToVideoCaptureColorFormat( | 53 static VideoCaptureCapability::Format V4l2ColorToVideoCaptureColorFormat( |
54 int32 v4l2_fourcc) { | 54 int32 v4l2_fourcc) { |
55 VideoCaptureDevice::Format result = VideoCaptureDevice::kColorUnknown; | 55 VideoCaptureCapability::Format result = VideoCaptureCapability::kColorUnknown; |
56 switch (v4l2_fourcc) { | 56 switch (v4l2_fourcc) { |
57 case V4L2_PIX_FMT_YUV420: | 57 case V4L2_PIX_FMT_YUV420: |
58 result = VideoCaptureDevice::kI420; | 58 result = VideoCaptureCapability::kI420; |
59 break; | 59 break; |
60 case V4L2_PIX_FMT_YUYV: | 60 case V4L2_PIX_FMT_YUYV: |
61 result = VideoCaptureDevice::kYUY2; | 61 result = VideoCaptureCapability::kYUY2; |
62 break; | 62 break; |
63 } | 63 } |
64 DCHECK_NE(result, VideoCaptureDevice::kColorUnknown); | 64 DCHECK_NE(result, VideoCaptureCapability::kColorUnknown); |
65 return result; | 65 return result; |
66 } | 66 } |
67 | 67 |
68 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { | 68 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
69 int fd = -1; | 69 int fd = -1; |
70 | 70 |
71 // Empty the name list. | 71 // Empty the name list. |
72 device_names->clear(); | 72 device_names->clear(); |
73 | 73 |
74 FilePath path("/dev/"); | 74 FilePath path("/dev/"); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 SetErrorState("Failed to find supported camera format."); | 241 SetErrorState("Failed to find supported camera format."); |
242 return; | 242 return; |
243 } | 243 } |
244 // Set format and frame size now. | 244 // Set format and frame size now. |
245 if (ioctl(device_fd_, VIDIOC_S_FMT, &video_fmt) < 0) { | 245 if (ioctl(device_fd_, VIDIOC_S_FMT, &video_fmt) < 0) { |
246 SetErrorState("Failed to set camera format"); | 246 SetErrorState("Failed to set camera format"); |
247 return; | 247 return; |
248 } | 248 } |
249 | 249 |
250 // Store our current width and height. | 250 // Store our current width and height. |
251 Capability current_settings; | 251 VideoCaptureCapability current_settings; |
252 current_settings.color = V4l2ColorToVideoCaptureColorFormat( | 252 current_settings.color = V4l2ColorToVideoCaptureColorFormat( |
253 video_fmt.fmt.pix.pixelformat); | 253 video_fmt.fmt.pix.pixelformat); |
254 current_settings.width = video_fmt.fmt.pix.width; | 254 current_settings.width = video_fmt.fmt.pix.width; |
255 current_settings.height = video_fmt.fmt.pix.height; | 255 current_settings.height = video_fmt.fmt.pix.height; |
256 current_settings.frame_rate = frame_rate; | 256 current_settings.frame_rate = frame_rate; |
| 257 current_settings.expected_capture_delay = 0; |
| 258 current_settings.interlaced = false; |
257 | 259 |
258 state_ = kAllocated; | 260 state_ = kAllocated; |
259 // Report the resulting frame size to the observer. | 261 // Report the resulting frame size to the observer. |
260 observer_->OnFrameInfo(current_settings); | 262 observer_->OnFrameInfo(current_settings); |
261 } | 263 } |
262 | 264 |
263 void VideoCaptureDeviceLinux::OnDeAllocate() { | 265 void VideoCaptureDeviceLinux::OnDeAllocate() { |
264 DCHECK_EQ(v4l2_thread_.message_loop(), MessageLoop::current()); | 266 DCHECK_EQ(v4l2_thread_.message_loop(), MessageLoop::current()); |
265 | 267 |
266 // If we are in error state or capturing | 268 // If we are in error state or capturing |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 buffer_pool_size_ = 0; | 450 buffer_pool_size_ = 0; |
449 } | 451 } |
450 | 452 |
451 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { | 453 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { |
452 DLOG(ERROR) << reason; | 454 DLOG(ERROR) << reason; |
453 state_ = kError; | 455 state_ = kError; |
454 observer_->OnError(); | 456 observer_->OnError(); |
455 } | 457 } |
456 | 458 |
457 } // namespace media | 459 } // namespace media |
OLD | NEW |