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> |
| 11 #include <sys/ioctl.h> | 11 #include <sys/ioctl.h> |
| 12 #include <sys/mman.h> | 12 #include <sys/mman.h> |
| 13 | 13 |
| 14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/files/scoped_file.h" | 15 #include "base/files/scoped_file.h" |
| 16 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
| 17 #include "content/common/gpu/media/exynos_v4l2_video_device.h" | 17 #include "content/common/gpu/media/exynos_v4l2_video_device.h" |
| 18 #include "ui/gl/gl_bindings.h" | 18 #include "ui/gl/gl_bindings.h" |
| 19 | 19 |
| 20 #ifdef USE_LIBV4L2 | |
| 21 # include<libv4l2.h> | |
|
Pawel Osciak
2014/11/18 08:36:30
No indent please. And space before '<'.
henryhsu
2014/11/19 03:49:47
Done.
| |
| 22 # include "content/common/gpu/media/v4l2_stubs.h" | |
| 23 | |
| 24 using content_common_gpu_media::kModuleV4l2; | |
| 25 using content_common_gpu_media::InitializeStubs; | |
| 26 using content_common_gpu_media::StubPathMap; | |
| 27 | |
| 28 static const base::FilePath::CharType kV4l2Lib[] = | |
| 29 FILE_PATH_LITERAL("libv4l2.so"); | |
| 30 #else | |
| 31 # define V4L2_DISABLE_CONVERSION 0x01 | |
| 32 # define v4l2_close close | |
|
Pawel Osciak
2014/11/18 08:36:30
No indent please.
henryhsu
2014/11/19 03:49:46
Done.
| |
| 33 # define v4l2_ioctl ioctl | |
| 34 # define v4l2_read read | |
|
Pawel Osciak
2014/11/18 08:36:29
We don't use read or write.
henryhsu
2014/11/19 03:49:47
Done.
| |
| 35 # define v4l2_write write | |
| 36 # define v4l2_mmap mmap | |
|
Pawel Osciak
2014/11/18 08:36:30
We don't want to do this if we don't do conversion
henryhsu
2014/11/19 03:49:47
Agree. use mmap first and then add a patch at the
| |
| 37 # define v4l2_munmap munmap | |
|
Pawel Osciak
2014/11/18 08:36:30
Ditto.
henryhsu
2014/11/19 03:49:46
Done.
| |
| 38 int v4l2_fd_open(int fd, int v4l2_flags) { | |
|
Pawel Osciak
2014/11/18 08:36:30
Better just ifdef the call out instead of this and
henryhsu
2014/11/19 03:49:46
Done.
| |
| 39 return 0; | |
| 40 } | |
| 41 #endif | |
| 42 | |
| 20 namespace content { | 43 namespace content { |
| 21 | 44 |
| 22 namespace { | 45 namespace { |
| 23 const char kDecoderDevice[] = "/dev/mfc-dec"; | 46 const char kDecoderDevice[] = "/dev/mfc-dec"; |
| 24 const char kEncoderDevice[] = "/dev/mfc-enc"; | 47 const char kEncoderDevice[] = "/dev/mfc-enc"; |
| 25 const char kImageProcessorDevice[] = "/dev/gsc1"; | 48 const char kImageProcessorDevice[] = "/dev/gsc1"; |
| 26 } | 49 } |
| 27 | 50 |
| 28 ExynosV4L2Device::ExynosV4L2Device(Type type) | 51 ExynosV4L2Device::ExynosV4L2Device(Type type) |
| 29 : type_(type), | 52 : type_(type), |
| 30 device_fd_(-1), | 53 device_fd_(-1), |
| 31 device_poll_interrupt_fd_(-1) {} | 54 device_poll_interrupt_fd_(-1) { |
| 55 #ifdef USE_LIBV4L2 | |
|
Pawel Osciak
2014/11/18 08:36:30
Please extract this to PostSandboxInitialization()
henryhsu
2014/11/19 03:49:46
Done.
| |
| 56 StubPathMap paths; | |
| 57 paths[kModuleV4l2].push_back(kV4l2Lib); | |
| 58 if (!InitializeStubs(paths)) | |
| 59 LOG(ERROR) << "Failed to initialize LIBV4L2 libs"; | |
|
Pawel Osciak
2014/11/18 08:36:30
Shouldn't this be a critical error? Please do this
henryhsu
2014/11/19 03:49:46
Done.
| |
| 60 #endif | |
| 61 } | |
| 32 | 62 |
| 33 ExynosV4L2Device::~ExynosV4L2Device() { | 63 ExynosV4L2Device::~ExynosV4L2Device() { |
| 34 if (device_poll_interrupt_fd_ != -1) { | 64 if (device_poll_interrupt_fd_ != -1) { |
| 35 close(device_poll_interrupt_fd_); | 65 v4l2_close(device_poll_interrupt_fd_); |
|
Pawel Osciak
2014/11/18 08:36:30
We should not use v4l2_* functions on interrupt fd
henryhsu
2014/11/19 03:49:47
Done.
| |
| 36 device_poll_interrupt_fd_ = -1; | 66 device_poll_interrupt_fd_ = -1; |
| 37 } | 67 } |
| 38 if (device_fd_ != -1) { | 68 if (device_fd_ != -1) { |
| 39 close(device_fd_); | 69 v4l2_close(device_fd_); |
| 40 device_fd_ = -1; | 70 device_fd_ = -1; |
| 41 } | 71 } |
| 42 } | 72 } |
| 43 | 73 |
| 44 int ExynosV4L2Device::Ioctl(int request, void* arg) { | 74 int ExynosV4L2Device::Ioctl(int request, void* arg) { |
| 45 return HANDLE_EINTR(ioctl(device_fd_, request, arg)); | 75 return HANDLE_EINTR(v4l2_ioctl(device_fd_, request, arg)); |
| 46 } | 76 } |
| 47 | 77 |
| 48 bool ExynosV4L2Device::Poll(bool poll_device, bool* event_pending) { | 78 bool ExynosV4L2Device::Poll(bool poll_device, bool* event_pending) { |
| 49 struct pollfd pollfds[2]; | 79 struct pollfd pollfds[2]; |
| 50 nfds_t nfds; | 80 nfds_t nfds; |
| 51 int pollfd = -1; | 81 int pollfd = -1; |
| 52 | 82 |
| 53 pollfds[0].fd = device_poll_interrupt_fd_; | 83 pollfds[0].fd = device_poll_interrupt_fd_; |
| 54 pollfds[0].events = POLLIN | POLLERR; | 84 pollfds[0].events = POLLIN | POLLERR; |
| 55 nfds = 1; | 85 nfds = 1; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 68 } | 98 } |
| 69 *event_pending = (pollfd != -1 && pollfds[pollfd].revents & POLLPRI); | 99 *event_pending = (pollfd != -1 && pollfds[pollfd].revents & POLLPRI); |
| 70 return true; | 100 return true; |
| 71 } | 101 } |
| 72 | 102 |
| 73 void* ExynosV4L2Device::Mmap(void* addr, | 103 void* ExynosV4L2Device::Mmap(void* addr, |
| 74 unsigned int len, | 104 unsigned int len, |
| 75 int prot, | 105 int prot, |
| 76 int flags, | 106 int flags, |
| 77 unsigned int offset) { | 107 unsigned int offset) { |
| 78 return mmap(addr, len, prot, flags, device_fd_, offset); | 108 return v4l2_mmap(addr, len, prot, flags, device_fd_, offset); |
| 79 } | 109 } |
| 80 | 110 |
| 81 void ExynosV4L2Device::Munmap(void* addr, unsigned int len) { | 111 void ExynosV4L2Device::Munmap(void* addr, unsigned int len) { |
| 82 munmap(addr, len); | 112 v4l2_munmap(addr, len); |
| 83 } | 113 } |
| 84 | 114 |
| 85 bool ExynosV4L2Device::SetDevicePollInterrupt() { | 115 bool ExynosV4L2Device::SetDevicePollInterrupt() { |
| 86 DVLOG(3) << "SetDevicePollInterrupt()"; | 116 DVLOG(3) << "SetDevicePollInterrupt()"; |
| 87 | 117 |
| 88 const uint64 buf = 1; | 118 const uint64 buf = 1; |
| 89 if (HANDLE_EINTR(write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | 119 if (HANDLE_EINTR( |
| 120 v4l2_write(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | |
| 90 DPLOG(ERROR) << "SetDevicePollInterrupt(): write() failed"; | 121 DPLOG(ERROR) << "SetDevicePollInterrupt(): write() failed"; |
| 91 return false; | 122 return false; |
| 92 } | 123 } |
| 93 return true; | 124 return true; |
| 94 } | 125 } |
| 95 | 126 |
| 96 bool ExynosV4L2Device::ClearDevicePollInterrupt() { | 127 bool ExynosV4L2Device::ClearDevicePollInterrupt() { |
| 97 DVLOG(3) << "ClearDevicePollInterrupt()"; | 128 DVLOG(3) << "ClearDevicePollInterrupt()"; |
| 98 | 129 |
| 99 uint64 buf; | 130 uint64 buf; |
| 100 if (HANDLE_EINTR(read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | 131 if (HANDLE_EINTR( |
| 132 v4l2_read(device_poll_interrupt_fd_, &buf, sizeof(buf))) == -1) { | |
| 101 if (errno == EAGAIN) { | 133 if (errno == EAGAIN) { |
| 102 // No interrupt flag set, and we're reading nonblocking. Not an error. | 134 // No interrupt flag set, and we're reading nonblocking. Not an error. |
| 103 return true; | 135 return true; |
| 104 } else { | 136 } else { |
| 105 DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed"; | 137 DPLOG(ERROR) << "ClearDevicePollInterrupt(): read() failed"; |
| 106 return false; | 138 return false; |
| 107 } | 139 } |
| 108 } | 140 } |
| 109 return true; | 141 return true; |
| 110 } | 142 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 122 device_path = kImageProcessorDevice; | 154 device_path = kImageProcessorDevice; |
| 123 break; | 155 break; |
| 124 } | 156 } |
| 125 | 157 |
| 126 DVLOG(2) << "Initialize(): opening device: " << device_path; | 158 DVLOG(2) << "Initialize(): opening device: " << device_path; |
| 127 // Open the video device. | 159 // Open the video device. |
| 128 device_fd_ = HANDLE_EINTR(open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); | 160 device_fd_ = HANDLE_EINTR(open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); |
| 129 if (device_fd_ == -1) { | 161 if (device_fd_ == -1) { |
| 130 return false; | 162 return false; |
| 131 } | 163 } |
| 164 if (v4l2_fd_open(device_fd_, V4L2_DISABLE_CONVERSION) == -1) { | |
|
Pawel Osciak
2014/11/18 08:36:30
Do we need to HANDLE_EINTR?
henryhsu
2014/11/19 03:49:47
Done.
| |
| 165 v4l2_close(device_fd_); | |
| 166 return false; | |
| 167 } | |
| 132 | 168 |
| 133 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | 169 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
| 134 if (device_poll_interrupt_fd_ == -1) { | 170 if (device_poll_interrupt_fd_ == -1) { |
| 135 return false; | 171 return false; |
| 136 } | 172 } |
| 137 return true; | 173 return true; |
| 138 } | 174 } |
| 139 | 175 |
| 140 EGLImageKHR ExynosV4L2Device::CreateEGLImage(EGLDisplay egl_display, | 176 EGLImageKHR ExynosV4L2Device::CreateEGLImage(EGLDisplay egl_display, |
| 141 EGLContext /* egl_context */, | 177 EGLContext /* egl_context */, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 238 } |
| 203 | 239 |
| 204 uint32 ExynosV4L2Device::PreferredOutputFormat() { | 240 uint32 ExynosV4L2Device::PreferredOutputFormat() { |
| 205 // TODO(posciak): We should support "dontcare" returns here once we | 241 // TODO(posciak): We should support "dontcare" returns here once we |
| 206 // implement proper handling (fallback, negotiation) for this in users. | 242 // implement proper handling (fallback, negotiation) for this in users. |
| 207 CHECK_EQ(type_, kDecoder); | 243 CHECK_EQ(type_, kDecoder); |
| 208 return V4L2_PIX_FMT_NV12M; | 244 return V4L2_PIX_FMT_NV12M; |
| 209 } | 245 } |
| 210 | 246 |
| 211 } // namespace content | 247 } // namespace content |
| OLD | NEW |