| 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 #include <dlfcn.h> | 5 #include <dlfcn.h> |
| 6 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <linux/videodev2.h> | 7 #include <linux/videodev2.h> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/common/gpu/media/tegra_v4l2_device.h" | 12 #include "media/gpu/tegra_v4l2_device.h" |
| 13 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace media { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 const char kDecoderDevice[] = "/dev/tegra_avpchannel"; | 18 const char kDecoderDevice[] = "/dev/tegra_avpchannel"; |
| 19 const char kEncoderDevice[] = "/dev/nvhost-msenc"; | 19 const char kEncoderDevice[] = "/dev/nvhost-msenc"; |
| 20 } | 20 } |
| 21 | 21 |
| 22 typedef int32_t (*TegraV4L2Open)(const char* name, int32_t flags); | 22 typedef int32_t (*TegraV4L2Open)(const char* name, int32_t flags); |
| 23 typedef int32_t (*TegraV4L2Close)(int32_t fd); | 23 typedef int32_t (*TegraV4L2Close)(int32_t fd); |
| 24 typedef int32_t (*TegraV4L2Ioctl)(int32_t fd, unsigned long cmd, ...); | 24 typedef int32_t (*TegraV4L2Ioctl)(int32_t fd, unsigned long cmd, ...); |
| 25 typedef int32_t (*TegraV4L2Poll)(int32_t fd, | 25 typedef int32_t (*TegraV4L2Poll)(int32_t fd, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 bool initialized() { return initialized_; } | 86 bool initialized() { return initialized_; } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 bool initialized_; | 89 bool initialized_; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 base::LazyInstance<TegraFunctionSymbolFinder> g_tegra_function_symbol_finder_ = | 92 base::LazyInstance<TegraFunctionSymbolFinder> g_tegra_function_symbol_finder_ = |
| 93 LAZY_INSTANCE_INITIALIZER; | 93 LAZY_INSTANCE_INITIALIZER; |
| 94 | 94 |
| 95 TegraV4L2Device::TegraV4L2Device(Type type) | 95 TegraV4L2Device::TegraV4L2Device(Type type) |
| 96 : V4L2Device(type), | 96 : V4L2Device(type), device_fd_(-1) {} |
| 97 device_fd_(-1) { | |
| 98 } | |
| 99 | 97 |
| 100 TegraV4L2Device::~TegraV4L2Device() { | 98 TegraV4L2Device::~TegraV4L2Device() { |
| 101 if (device_fd_ != -1) { | 99 if (device_fd_ != -1) { |
| 102 TegraV4L2_Close(device_fd_); | 100 TegraV4L2_Close(device_fd_); |
| 103 device_fd_ = -1; | 101 device_fd_ = -1; |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 | 104 |
| 107 int TegraV4L2Device::Ioctl(int flags, void* arg) { | 105 int TegraV4L2Device::Ioctl(int flags, void* arg) { |
| 108 return HANDLE_EINTR(TegraV4L2_Ioctl(device_fd_, flags, arg)); | 106 return HANDLE_EINTR(TegraV4L2_Ioctl(device_fd_, flags, arg)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 uint32_t v4l2_pixfmt, | 196 uint32_t v4l2_pixfmt, |
| 199 const std::vector<base::ScopedFD>& /* dmabuf_fds */) { | 197 const std::vector<base::ScopedFD>& /* dmabuf_fds */) { |
| 200 DVLOG(3) << "CreateEGLImage()"; | 198 DVLOG(3) << "CreateEGLImage()"; |
| 201 if (!CanCreateEGLImageFrom(v4l2_pixfmt)) { | 199 if (!CanCreateEGLImageFrom(v4l2_pixfmt)) { |
| 202 LOG(ERROR) << "Unsupported V4L2 pixel format"; | 200 LOG(ERROR) << "Unsupported V4L2 pixel format"; |
| 203 return EGL_NO_IMAGE_KHR; | 201 return EGL_NO_IMAGE_KHR; |
| 204 } | 202 } |
| 205 | 203 |
| 206 EGLint attr = EGL_NONE; | 204 EGLint attr = EGL_NONE; |
| 207 EGLImageKHR egl_image = | 205 EGLImageKHR egl_image = |
| 208 eglCreateImageKHR(egl_display, | 206 eglCreateImageKHR(egl_display, egl_context, EGL_GL_TEXTURE_2D_KHR, |
| 209 egl_context, | 207 reinterpret_cast<EGLClientBuffer>(texture_id), &attr); |
| 210 EGL_GL_TEXTURE_2D_KHR, | |
| 211 reinterpret_cast<EGLClientBuffer>(texture_id), | |
| 212 &attr); | |
| 213 if (egl_image == EGL_NO_IMAGE_KHR) { | 208 if (egl_image == EGL_NO_IMAGE_KHR) { |
| 214 LOG(ERROR) << "Unable to create EGL image"; | 209 LOG(ERROR) << "Unable to create EGL image"; |
| 215 return egl_image; | 210 return egl_image; |
| 216 } | 211 } |
| 217 if (TegraV4L2_UseEglImage(device_fd_, buffer_index, egl_image) != 0) { | 212 if (TegraV4L2_UseEglImage(device_fd_, buffer_index, egl_image) != 0) { |
| 218 LOG(ERROR) << "Unable to use EGL image"; | 213 LOG(ERROR) << "Unable to use EGL image"; |
| 219 eglDestroyImageKHR(egl_display, egl_image); | 214 eglDestroyImageKHR(egl_display, egl_image); |
| 220 egl_image = EGL_NO_IMAGE_KHR; | 215 egl_image = EGL_NO_IMAGE_KHR; |
| 221 } | 216 } |
| 222 return egl_image; | 217 return egl_image; |
| 223 } | 218 } |
| 224 | 219 |
| 225 EGLBoolean TegraV4L2Device::DestroyEGLImage(EGLDisplay egl_display, | 220 EGLBoolean TegraV4L2Device::DestroyEGLImage(EGLDisplay egl_display, |
| 226 EGLImageKHR egl_image) { | 221 EGLImageKHR egl_image) { |
| 227 return eglDestroyImageKHR(egl_display, egl_image); | 222 return eglDestroyImageKHR(egl_display, egl_image); |
| 228 } | 223 } |
| 229 | 224 |
| 230 GLenum TegraV4L2Device::GetTextureTarget() { return GL_TEXTURE_2D; } | 225 GLenum TegraV4L2Device::GetTextureTarget() { |
| 226 return GL_TEXTURE_2D; |
| 227 } |
| 231 | 228 |
| 232 uint32_t TegraV4L2Device::PreferredInputFormat() { | 229 uint32_t TegraV4L2Device::PreferredInputFormat() { |
| 233 // TODO(posciak): We should support "dontcare" returns here once we | 230 // TODO(posciak): We should support "dontcare" returns here once we |
| 234 // implement proper handling (fallback, negotiation) for this in users. | 231 // implement proper handling (fallback, negotiation) for this in users. |
| 235 CHECK_EQ(type_, kEncoder); | 232 CHECK_EQ(type_, kEncoder); |
| 236 return V4L2_PIX_FMT_YUV420M; | 233 return V4L2_PIX_FMT_YUV420M; |
| 237 } | 234 } |
| 238 | 235 |
| 239 } // namespace content | 236 } // namespace media |
| OLD | NEW |