Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 5 |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <libdrm/drm_fourcc.h> | 7 #include <libdrm/drm_fourcc.h> |
| 8 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
| 9 #include <poll.h> | 9 #include <poll.h> |
| 10 #include <sys/eventfd.h> | 10 #include <sys/eventfd.h> |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 // Auto-generated for dlopen libv4l2 libraries | 22 // Auto-generated for dlopen libv4l2 libraries |
| 23 #include "content/common/gpu/media/v4l2_stubs.h" | 23 #include "content/common/gpu/media/v4l2_stubs.h" |
| 24 #include "third_party/v4l-utils/lib/include/libv4l2.h" | 24 #include "third_party/v4l-utils/lib/include/libv4l2.h" |
| 25 | 25 |
| 26 using content_common_gpu_media::kModuleV4l2; | 26 using content_common_gpu_media::kModuleV4l2; |
| 27 using content_common_gpu_media::InitializeStubs; | 27 using content_common_gpu_media::InitializeStubs; |
| 28 using content_common_gpu_media::StubPathMap; | 28 using content_common_gpu_media::StubPathMap; |
| 29 | 29 |
| 30 static const base::FilePath::CharType kV4l2Lib[] = | 30 static const base::FilePath::CharType kV4l2Lib[] = |
| 31 FILE_PATH_LITERAL("/usr/lib/libv4l2.so"); | 31 FILE_PATH_LITERAL("/usr/lib/libv4l2.so"); |
| 32 #else | |
| 33 #define v4l2_close close | |
| 34 #define v4l2_ioctl ioctl | |
| 35 #endif | 32 #endif |
| 36 | 33 |
| 37 namespace content { | 34 namespace content { |
| 38 | 35 |
| 39 namespace { | 36 namespace { |
| 40 const char kDecoderDevice[] = "/dev/video-dec"; | 37 const char kDecoderDevice[] = "/dev/video-dec"; |
| 41 const char kEncoderDevice[] = "/dev/video-enc"; | 38 const char kEncoderDevice[] = "/dev/video-enc"; |
| 42 const char kImageProcessorDevice[] = "/dev/gsc0"; | 39 const char kImageProcessorDevice[] = "/dev/gsc0"; |
| 43 } | 40 } |
| 44 | 41 |
| 45 GenericV4L2Device::GenericV4L2Device(Type type) | 42 GenericV4L2Device::GenericV4L2Device(Type type) |
| 46 : type_(type), | 43 : type_(type), |
| 47 device_fd_(-1), | 44 device_fd_(-1), |
| 48 device_poll_interrupt_fd_(-1) {} | 45 device_poll_interrupt_fd_(-1), |
| 46 use_libv4l2_(false) {} | |
| 49 | 47 |
| 50 GenericV4L2Device::~GenericV4L2Device() { | 48 GenericV4L2Device::~GenericV4L2Device() { |
| 51 if (device_poll_interrupt_fd_ != -1) { | 49 if (device_poll_interrupt_fd_ != -1) { |
| 52 close(device_poll_interrupt_fd_); | 50 close(device_poll_interrupt_fd_); |
| 53 device_poll_interrupt_fd_ = -1; | 51 device_poll_interrupt_fd_ = -1; |
| 54 } | 52 } |
| 55 if (device_fd_ != -1) { | 53 if (device_fd_ != -1) { |
| 56 v4l2_close(device_fd_); | 54 Close(); |
| 57 device_fd_ = -1; | 55 device_fd_ = -1; |
| 58 } | 56 } |
| 59 } | 57 } |
| 60 | 58 |
| 59 void GenericV4L2Device::Close() { | |
| 60 #if defined(USE_LIBV4L2) | |
| 61 if (use_libv4l2_) { | |
| 62 v4l2_close(device_fd_); | |
| 63 return; | |
| 64 } | |
| 65 #endif | |
| 66 close(device_fd_); | |
|
Pawel Osciak
2015/04/21 05:02:42
Perhaps this would be a good time to start using b
wuchengli
2015/04/21 06:12:10
Good idea. Done.
| |
| 67 } | |
| 68 | |
| 61 int GenericV4L2Device::Ioctl(int request, void* arg) { | 69 int GenericV4L2Device::Ioctl(int request, void* arg) { |
| 62 return HANDLE_EINTR(v4l2_ioctl(device_fd_, request, arg)); | 70 #if defined(USE_LIBV4L2) |
| 71 if (use_libv4l2_) | |
| 72 return HANDLE_EINTR(v4l2_ioctl(device_fd_, request, arg)); | |
| 73 #endif | |
| 74 return HANDLE_EINTR(ioctl(device_fd_, request, arg)); | |
| 63 } | 75 } |
| 64 | 76 |
| 65 bool GenericV4L2Device::Poll(bool poll_device, bool* event_pending) { | 77 bool GenericV4L2Device::Poll(bool poll_device, bool* event_pending) { |
| 66 struct pollfd pollfds[2]; | 78 struct pollfd pollfds[2]; |
| 67 nfds_t nfds; | 79 nfds_t nfds; |
| 68 int pollfd = -1; | 80 int pollfd = -1; |
| 69 | 81 |
| 70 pollfds[0].fd = device_poll_interrupt_fd_; | 82 pollfds[0].fd = device_poll_interrupt_fd_; |
| 71 pollfds[0].events = POLLIN | POLLERR; | 83 pollfds[0].events = POLLIN | POLLERR; |
| 72 nfds = 1; | 84 nfds = 1; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 break; | 158 break; |
| 147 } | 159 } |
| 148 | 160 |
| 149 DVLOG(2) << "Initialize(): opening device: " << device_path; | 161 DVLOG(2) << "Initialize(): opening device: " << device_path; |
| 150 // Open the video device. | 162 // Open the video device. |
| 151 device_fd_ = HANDLE_EINTR(open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); | 163 device_fd_ = HANDLE_EINTR(open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); |
| 152 if (device_fd_ == -1) { | 164 if (device_fd_ == -1) { |
| 153 return false; | 165 return false; |
| 154 } | 166 } |
| 155 #if defined(USE_LIBV4L2) | 167 #if defined(USE_LIBV4L2) |
| 156 if (HANDLE_EINTR(v4l2_fd_open(device_fd_, V4L2_DISABLE_CONVERSION)) == -1) { | 168 if (HANDLE_EINTR(v4l2_fd_open(device_fd_, V4L2_DISABLE_CONVERSION)) >= 0) { |
|
Pawel Osciak
2015/04/21 05:02:42
I'd prefer != -1.
wuchengli
2015/04/21 06:12:10
Done. I was confused when I discussed with you. !=
| |
| 157 v4l2_close(device_fd_); | 169 DVLOG(2) << "Found a libv4l2 plugin for " << device_path; |
|
Pawel Osciak
2015/04/21 05:02:42
v4l2_fd_open succeeding is not exactly equivalent
wuchengli
2015/04/21 06:12:10
Done.
| |
| 158 return false; | 170 use_libv4l2_ = true; |
| 159 } | 171 } |
| 160 #endif | 172 #endif |
| 161 | 173 |
| 162 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | 174 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
| 163 if (device_poll_interrupt_fd_ == -1) { | 175 if (device_poll_interrupt_fd_ == -1) { |
| 164 return false; | 176 return false; |
| 165 } | 177 } |
| 166 return true; | 178 return true; |
| 167 } | 179 } |
| 168 | 180 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 StubPathMap paths; | 301 StubPathMap paths; |
| 290 paths[kModuleV4l2].push_back(kV4l2Lib); | 302 paths[kModuleV4l2].push_back(kV4l2Lib); |
| 291 | 303 |
| 292 return InitializeStubs(paths); | 304 return InitializeStubs(paths); |
| 293 #else | 305 #else |
| 294 return true; | 306 return true; |
| 295 #endif | 307 #endif |
| 296 } | 308 } |
| 297 | 309 |
| 298 } // namespace content | 310 } // namespace content |
| OLD | NEW |