| 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 "content/common/gpu/media/generic_v4l2_device.h" | 6 #include "media/gpu/generic_v4l2_device.h" |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <libdrm/drm_fourcc.h> | 10 #include <libdrm/drm_fourcc.h> |
| 11 #include <linux/videodev2.h> | 11 #include <linux/videodev2.h> |
| 12 #include <poll.h> | 12 #include <poll.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include <sys/eventfd.h> | 14 #include <sys/eventfd.h> |
| 15 #include <sys/ioctl.h> | 15 #include <sys/ioctl.h> |
| 16 #include <sys/mman.h> | 16 #include <sys/mman.h> |
| 17 | 17 |
| 18 #include <memory> | 18 #include <memory> |
| 19 | 19 |
| 20 #include "base/files/scoped_file.h" | 20 #include "base/files/scoped_file.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/posix/eintr_wrapper.h" | 22 #include "base/posix/eintr_wrapper.h" |
| 23 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "media/gpu/generic_v4l2_device.h" |
| 25 #include "ui/gl/egl_util.h" | 26 #include "ui/gl/egl_util.h" |
| 26 #include "ui/gl/gl_bindings.h" | 27 #include "ui/gl/gl_bindings.h" |
| 27 | 28 |
| 28 #if defined(USE_LIBV4L2) | 29 #if defined(USE_LIBV4L2) |
| 29 // Auto-generated for dlopen libv4l2 libraries | 30 // Auto-generated for dlopen libv4l2 libraries |
| 30 #include "content/common/gpu/media/v4l2_stubs.h" | 31 #include "media/gpu/v4l2_stubs.h" |
| 31 #include "third_party/v4l-utils/lib/include/libv4l2.h" | 32 #include "third_party/v4l-utils/lib/include/libv4l2.h" |
| 32 | 33 |
| 33 using content_common_gpu_media::kModuleV4l2; | 34 using media_gpu::kModuleV4l2; |
| 34 using content_common_gpu_media::InitializeStubs; | 35 using media_gpu::InitializeStubs; |
| 35 using content_common_gpu_media::StubPathMap; | 36 using media_gpu::StubPathMap; |
| 36 | 37 |
| 37 static const base::FilePath::CharType kV4l2Lib[] = | 38 static const base::FilePath::CharType kV4l2Lib[] = |
| 38 FILE_PATH_LITERAL("/usr/lib/libv4l2.so"); | 39 FILE_PATH_LITERAL("/usr/lib/libv4l2.so"); |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 namespace content { | 42 namespace media { |
| 42 | 43 |
| 43 namespace { | 44 namespace { |
| 44 const char kDecoderDevice[] = "/dev/video-dec"; | 45 const char kDecoderDevice[] = "/dev/video-dec"; |
| 45 const char kEncoderDevice[] = "/dev/video-enc"; | 46 const char kEncoderDevice[] = "/dev/video-enc"; |
| 46 const char kImageProcessorDevice[] = "/dev/image-proc0"; | 47 const char kImageProcessorDevice[] = "/dev/image-proc0"; |
| 47 const char kJpegDecoderDevice[] = "/dev/jpeg-dec"; | 48 const char kJpegDecoderDevice[] = "/dev/jpeg-dec"; |
| 48 } | 49 } |
| 49 | 50 |
| 50 GenericV4L2Device::GenericV4L2Device(Type type) | 51 GenericV4L2Device::GenericV4L2Device(Type type) |
| 51 : V4L2Device(type), | 52 : V4L2Device(type), use_libv4l2_(false) {} |
| 52 use_libv4l2_(false) { | |
| 53 } | |
| 54 | 53 |
| 55 GenericV4L2Device::~GenericV4L2Device() { | 54 GenericV4L2Device::~GenericV4L2Device() { |
| 56 #if defined(USE_LIBV4L2) | 55 #if defined(USE_LIBV4L2) |
| 57 if (use_libv4l2_ && device_fd_.is_valid()) | 56 if (use_libv4l2_ && device_fd_.is_valid()) |
| 58 v4l2_close(device_fd_.release()); | 57 v4l2_close(device_fd_.release()); |
| 59 #endif | 58 #endif |
| 60 } | 59 } |
| 61 | 60 |
| 62 int GenericV4L2Device::Ioctl(int request, void* arg) { | 61 int GenericV4L2Device::Ioctl(int request, void* arg) { |
| 63 #if defined(USE_LIBV4L2) | 62 #if defined(USE_LIBV4L2) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 | 85 |
| 87 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { | 86 if (HANDLE_EINTR(poll(pollfds, nfds, -1)) == -1) { |
| 88 DPLOG(ERROR) << "poll() failed"; | 87 DPLOG(ERROR) << "poll() failed"; |
| 89 return false; | 88 return false; |
| 90 } | 89 } |
| 91 *event_pending = (pollfd != -1 && pollfds[pollfd].revents & POLLPRI); | 90 *event_pending = (pollfd != -1 && pollfds[pollfd].revents & POLLPRI); |
| 92 return true; | 91 return true; |
| 93 } | 92 } |
| 94 | 93 |
| 95 void* GenericV4L2Device::Mmap(void* addr, | 94 void* GenericV4L2Device::Mmap(void* addr, |
| 96 unsigned int len, | 95 unsigned int len, |
| 97 int prot, | 96 int prot, |
| 98 int flags, | 97 int flags, |
| 99 unsigned int offset) { | 98 unsigned int offset) { |
| 100 return mmap(addr, len, prot, flags, device_fd_.get(), offset); | 99 return mmap(addr, len, prot, flags, device_fd_.get(), offset); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void GenericV4L2Device::Munmap(void* addr, unsigned int len) { | 102 void GenericV4L2Device::Munmap(void* addr, unsigned int len) { |
| 104 munmap(addr, len); | 103 munmap(addr, len); |
| 105 } | 104 } |
| 106 | 105 |
| 107 bool GenericV4L2Device::SetDevicePollInterrupt() { | 106 bool GenericV4L2Device::SetDevicePollInterrupt() { |
| 108 DVLOG(3) << "SetDevicePollInterrupt()"; | 107 DVLOG(3) << "SetDevicePollInterrupt()"; |
| 109 | 108 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 205 |
| 207 bool GenericV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) { | 206 bool GenericV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) { |
| 208 static uint32_t kEGLImageDrmFmtsSupported[] = { | 207 static uint32_t kEGLImageDrmFmtsSupported[] = { |
| 209 DRM_FORMAT_ARGB8888, | 208 DRM_FORMAT_ARGB8888, |
| 210 #if defined(ARCH_CPU_ARMEL) | 209 #if defined(ARCH_CPU_ARMEL) |
| 211 DRM_FORMAT_NV12, | 210 DRM_FORMAT_NV12, |
| 212 #endif | 211 #endif |
| 213 }; | 212 }; |
| 214 | 213 |
| 215 return std::find( | 214 return std::find( |
| 216 kEGLImageDrmFmtsSupported, | 215 kEGLImageDrmFmtsSupported, |
| 217 kEGLImageDrmFmtsSupported + arraysize(kEGLImageDrmFmtsSupported), | 216 kEGLImageDrmFmtsSupported + arraysize(kEGLImageDrmFmtsSupported), |
| 218 V4L2PixFmtToDrmFormat(v4l2_pixfmt)) != | 217 V4L2PixFmtToDrmFormat(v4l2_pixfmt)) != |
| 219 kEGLImageDrmFmtsSupported + arraysize(kEGLImageDrmFmtsSupported); | 218 kEGLImageDrmFmtsSupported + arraysize(kEGLImageDrmFmtsSupported); |
| 220 } | 219 } |
| 221 | 220 |
| 222 EGLImageKHR GenericV4L2Device::CreateEGLImage( | 221 EGLImageKHR GenericV4L2Device::CreateEGLImage( |
| 223 EGLDisplay egl_display, | 222 EGLDisplay egl_display, |
| 224 EGLContext /* egl_context */, | 223 EGLContext /* egl_context */, |
| 225 GLuint texture_id, | 224 GLuint texture_id, |
| 226 const gfx::Size& size, | 225 const gfx::Size& size, |
| 227 unsigned int buffer_index, | 226 unsigned int buffer_index, |
| 228 uint32_t v4l2_pixfmt, | 227 uint32_t v4l2_pixfmt, |
| 229 const std::vector<base::ScopedFD>& dmabuf_fds) { | 228 const std::vector<base::ScopedFD>& dmabuf_fds) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 LOG(ERROR) << "Failed creating EGL image: " << ui::GetLastEGLErrorString(); | 286 LOG(ERROR) << "Failed creating EGL image: " << ui::GetLastEGLErrorString(); |
| 288 return egl_image; | 287 return egl_image; |
| 289 } | 288 } |
| 290 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); | 289 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); |
| 291 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); | 290 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
| 292 | 291 |
| 293 return egl_image; | 292 return egl_image; |
| 294 } | 293 } |
| 295 | 294 |
| 296 EGLBoolean GenericV4L2Device::DestroyEGLImage(EGLDisplay egl_display, | 295 EGLBoolean GenericV4L2Device::DestroyEGLImage(EGLDisplay egl_display, |
| 297 EGLImageKHR egl_image) { | 296 EGLImageKHR egl_image) { |
| 298 return eglDestroyImageKHR(egl_display, egl_image); | 297 return eglDestroyImageKHR(egl_display, egl_image); |
| 299 } | 298 } |
| 300 | 299 |
| 301 GLenum GenericV4L2Device::GetTextureTarget() { return GL_TEXTURE_EXTERNAL_OES; } | 300 GLenum GenericV4L2Device::GetTextureTarget() { |
| 301 return GL_TEXTURE_EXTERNAL_OES; |
| 302 } |
| 302 | 303 |
| 303 uint32_t GenericV4L2Device::PreferredInputFormat() { | 304 uint32_t GenericV4L2Device::PreferredInputFormat() { |
| 304 // TODO(posciak): We should support "dontcare" returns here once we | 305 // TODO(posciak): We should support "dontcare" returns here once we |
| 305 // implement proper handling (fallback, negotiation) for this in users. | 306 // implement proper handling (fallback, negotiation) for this in users. |
| 306 CHECK_EQ(type_, kEncoder); | 307 CHECK_EQ(type_, kEncoder); |
| 307 return V4L2_PIX_FMT_NV12M; | 308 return V4L2_PIX_FMT_NV12M; |
| 308 } | 309 } |
| 309 | 310 |
| 310 // static | 311 // static |
| 311 bool GenericV4L2Device::PostSandboxInitialization() { | 312 bool GenericV4L2Device::PostSandboxInitialization() { |
| 312 #if defined(USE_LIBV4L2) | 313 #if defined(USE_LIBV4L2) |
| 313 StubPathMap paths; | 314 StubPathMap paths; |
| 314 paths[kModuleV4l2].push_back(kV4l2Lib); | 315 paths[kModuleV4l2].push_back(kV4l2Lib); |
| 315 | 316 |
| 316 return InitializeStubs(paths); | 317 return InitializeStubs(paths); |
| 317 #else | 318 #else |
| 318 return true; | 319 return true; |
| 319 #endif | 320 #endif |
| 320 } | 321 } |
| 321 | 322 |
| 322 } // namespace content | 323 } // namespace media |
| OLD | NEW |