| 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 25 matching lines...) Expand all Loading... |
| 36 enum { kCaptureSelectWaitMs = 10 }; | 36 enum { kCaptureSelectWaitMs = 10 }; |
| 37 // MJPEG is preferred if the width or height is larger than this. | 37 // MJPEG is preferred if the width or height is larger than this. |
| 38 enum { kMjpegWidth = 640 }; | 38 enum { kMjpegWidth = 640 }; |
| 39 enum { kMjpegHeight = 480 }; | 39 enum { kMjpegHeight = 480 }; |
| 40 // Typical framerate, in fps | 40 // Typical framerate, in fps |
| 41 enum { kTypicalFramerate = 30 }; | 41 enum { kTypicalFramerate = 30 }; |
| 42 | 42 |
| 43 // V4L2 color formats VideoCaptureDeviceLinux support. | 43 // V4L2 color formats VideoCaptureDeviceLinux support. |
| 44 static const int32 kV4l2RawFmts[] = { | 44 static const int32 kV4l2RawFmts[] = { |
| 45 V4L2_PIX_FMT_YUV420, | 45 V4L2_PIX_FMT_YUV420, |
| 46 V4L2_PIX_FMT_YUYV | 46 V4L2_PIX_FMT_YUYV, |
| 47 V4L2_PIX_FMT_UYVY |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 // USB VID and PID are both 4 bytes long. | 50 // USB VID and PID are both 4 bytes long. |
| 50 static const size_t kVidPidSize = 4; | 51 static const size_t kVidPidSize = 4; |
| 51 | 52 |
| 52 // /sys/class/video4linux/video{N}/device is a symlink to the corresponding | 53 // /sys/class/video4linux/video{N}/device is a symlink to the corresponding |
| 53 // USB device info directory. | 54 // USB device info directory. |
| 54 static const char kVidPathTemplate[] = | 55 static const char kVidPathTemplate[] = |
| 55 "/sys/class/video4linux/%s/device/../idVendor"; | 56 "/sys/class/video4linux/%s/device/../idVendor"; |
| 56 static const char kPidPathTemplate[] = | 57 static const char kPidPathTemplate[] = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 75 VideoPixelFormat VideoCaptureDeviceLinux::V4l2ColorToVideoCaptureColorFormat( | 76 VideoPixelFormat VideoCaptureDeviceLinux::V4l2ColorToVideoCaptureColorFormat( |
| 76 int32 v4l2_fourcc) { | 77 int32 v4l2_fourcc) { |
| 77 VideoPixelFormat result = PIXEL_FORMAT_UNKNOWN; | 78 VideoPixelFormat result = PIXEL_FORMAT_UNKNOWN; |
| 78 switch (v4l2_fourcc) { | 79 switch (v4l2_fourcc) { |
| 79 case V4L2_PIX_FMT_YUV420: | 80 case V4L2_PIX_FMT_YUV420: |
| 80 result = PIXEL_FORMAT_I420; | 81 result = PIXEL_FORMAT_I420; |
| 81 break; | 82 break; |
| 82 case V4L2_PIX_FMT_YUYV: | 83 case V4L2_PIX_FMT_YUYV: |
| 83 result = PIXEL_FORMAT_YUY2; | 84 result = PIXEL_FORMAT_YUY2; |
| 84 break; | 85 break; |
| 86 case V4L2_PIX_FMT_UYVY: |
| 87 result = PIXEL_FORMAT_UYVY; |
| 88 break; |
| 85 case V4L2_PIX_FMT_MJPEG: | 89 case V4L2_PIX_FMT_MJPEG: |
| 86 case V4L2_PIX_FMT_JPEG: | 90 case V4L2_PIX_FMT_JPEG: |
| 87 result = PIXEL_FORMAT_MJPEG; | 91 result = PIXEL_FORMAT_MJPEG; |
| 88 break; | 92 break; |
| 89 default: | 93 default: |
| 90 DVLOG(1) << "Unsupported pixel format " << std::hex << v4l2_fourcc; | 94 DVLOG(1) << "Unsupported pixel format " << std::hex << v4l2_fourcc; |
| 91 } | 95 } |
| 92 return result; | 96 return result; |
| 93 } | 97 } |
| 94 | 98 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 506 |
| 503 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { | 507 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { |
| 504 DCHECK(!v4l2_thread_.IsRunning() || | 508 DCHECK(!v4l2_thread_.IsRunning() || |
| 505 v4l2_thread_.message_loop() == base::MessageLoop::current()); | 509 v4l2_thread_.message_loop() == base::MessageLoop::current()); |
| 506 DVLOG(1) << reason; | 510 DVLOG(1) << reason; |
| 507 state_ = kError; | 511 state_ = kError; |
| 508 client_->OnError(reason); | 512 client_->OnError(reason); |
| 509 } | 513 } |
| 510 | 514 |
| 511 } // namespace media | 515 } // namespace media |
| OLD | NEW |