| 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/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 163 } |
| 164 device_fd_ = HANDLE_EINTR( | 164 device_fd_ = HANDLE_EINTR( |
| 165 TegraV4L2_Open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); | 165 TegraV4L2_Open(device_path, O_RDWR | O_NONBLOCK | O_CLOEXEC)); |
| 166 if (device_fd_ == -1) { | 166 if (device_fd_ == -1) { |
| 167 DLOG(ERROR) << "Unable to open device " << device_path; | 167 DLOG(ERROR) << "Unable to open device " << device_path; |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool TegraV4L2Device::CanCreateEGLImageFrom(uint32_t v4l2_pixfmt) { | |
| 174 return v4l2_pixfmt == V4L2_PIX_FMT_NV12M; | |
| 175 } | |
| 176 | |
| 177 EGLImageKHR TegraV4L2Device::CreateEGLImage(EGLDisplay egl_display, | 173 EGLImageKHR TegraV4L2Device::CreateEGLImage(EGLDisplay egl_display, |
| 178 EGLContext egl_context, | 174 EGLContext egl_context, |
| 179 GLuint texture_id, | 175 GLuint texture_id, |
| 180 gfx::Size /* frame_buffer_size */, | 176 gfx::Size /* frame_buffer_size */, |
| 181 unsigned int buffer_index, | 177 unsigned int buffer_index, |
| 182 uint32_t v4l2_pixfmt, | 178 size_t /* planes_count */) { |
| 183 size_t /* num_v4l2_planes */) { | |
| 184 DVLOG(3) << "CreateEGLImage()"; | 179 DVLOG(3) << "CreateEGLImage()"; |
| 185 if (!CanCreateEGLImageFrom(v4l2_pixfmt)) { | |
| 186 LOG(ERROR) << "Unsupported V4L2 pixel format"; | |
| 187 return EGL_NO_IMAGE_KHR; | |
| 188 } | |
| 189 | |
| 190 EGLint attr = EGL_NONE; | 180 EGLint attr = EGL_NONE; |
| 191 EGLImageKHR egl_image = | 181 EGLImageKHR egl_image = |
| 192 eglCreateImageKHR(egl_display, | 182 eglCreateImageKHR(egl_display, |
| 193 egl_context, | 183 egl_context, |
| 194 EGL_GL_TEXTURE_2D_KHR, | 184 EGL_GL_TEXTURE_2D_KHR, |
| 195 reinterpret_cast<EGLClientBuffer>(texture_id), | 185 reinterpret_cast<EGLClientBuffer>(texture_id), |
| 196 &attr); | 186 &attr); |
| 197 if (egl_image == EGL_NO_IMAGE_KHR) { | 187 if (egl_image == EGL_NO_IMAGE_KHR) { |
| 198 LOG(ERROR) << "Unable to create EGL image"; | 188 LOG(ERROR) << "Unable to create EGL image"; |
| 199 return egl_image; | 189 return egl_image; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 213 | 203 |
| 214 GLenum TegraV4L2Device::GetTextureTarget() { return GL_TEXTURE_2D; } | 204 GLenum TegraV4L2Device::GetTextureTarget() { return GL_TEXTURE_2D; } |
| 215 | 205 |
| 216 uint32 TegraV4L2Device::PreferredInputFormat() { | 206 uint32 TegraV4L2Device::PreferredInputFormat() { |
| 217 // TODO(posciak): We should support "dontcare" returns here once we | 207 // TODO(posciak): We should support "dontcare" returns here once we |
| 218 // implement proper handling (fallback, negotiation) for this in users. | 208 // implement proper handling (fallback, negotiation) for this in users. |
| 219 CHECK_EQ(type_, kEncoder); | 209 CHECK_EQ(type_, kEncoder); |
| 220 return V4L2_PIX_FMT_YUV420M; | 210 return V4L2_PIX_FMT_YUV420M; |
| 221 } | 211 } |
| 222 | 212 |
| 213 uint32 TegraV4L2Device::PreferredOutputFormat() { |
| 214 // TODO(posciak): We should support "dontcare" returns here once we |
| 215 // implement proper handling (fallback, negotiation) for this in users. |
| 216 CHECK_EQ(type_, kDecoder); |
| 217 return V4L2_PIX_FMT_NV12M; |
| 218 } |
| 219 |
| 223 } // namespace content | 220 } // namespace content |
| OLD | NEW |