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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 uint32_t v4l2_pixfmt, | 195 uint32_t v4l2_pixfmt, |
198 size_t /* num_v4l2_planes */) { | 196 size_t /* num_v4l2_planes */) { |
199 DVLOG(3) << "CreateEGLImage()"; | 197 DVLOG(3) << "CreateEGLImage()"; |
200 if (!CanCreateEGLImageFrom(v4l2_pixfmt)) { | 198 if (!CanCreateEGLImageFrom(v4l2_pixfmt)) { |
201 LOG(ERROR) << "Unsupported V4L2 pixel format"; | 199 LOG(ERROR) << "Unsupported V4L2 pixel format"; |
202 return EGL_NO_IMAGE_KHR; | 200 return EGL_NO_IMAGE_KHR; |
203 } | 201 } |
204 | 202 |
205 EGLint attr = EGL_NONE; | 203 EGLint attr = EGL_NONE; |
206 EGLImageKHR egl_image = | 204 EGLImageKHR egl_image = |
207 eglCreateImageKHR(egl_display, | 205 eglCreateImageKHR(egl_display, egl_context, EGL_GL_TEXTURE_2D_KHR, |
208 egl_context, | 206 reinterpret_cast<EGLClientBuffer>(texture_id), &attr); |
209 EGL_GL_TEXTURE_2D_KHR, | |
210 reinterpret_cast<EGLClientBuffer>(texture_id), | |
211 &attr); | |
212 if (egl_image == EGL_NO_IMAGE_KHR) { | 207 if (egl_image == EGL_NO_IMAGE_KHR) { |
213 LOG(ERROR) << "Unable to create EGL image"; | 208 LOG(ERROR) << "Unable to create EGL image"; |
214 return egl_image; | 209 return egl_image; |
215 } | 210 } |
216 if (TegraV4L2_UseEglImage(device_fd_, buffer_index, egl_image) != 0) { | 211 if (TegraV4L2_UseEglImage(device_fd_, buffer_index, egl_image) != 0) { |
217 LOG(ERROR) << "Unable to use EGL image"; | 212 LOG(ERROR) << "Unable to use EGL image"; |
218 eglDestroyImageKHR(egl_display, egl_image); | 213 eglDestroyImageKHR(egl_display, egl_image); |
219 egl_image = EGL_NO_IMAGE_KHR; | 214 egl_image = EGL_NO_IMAGE_KHR; |
220 } | 215 } |
221 return egl_image; | 216 return egl_image; |
222 } | 217 } |
223 | 218 |
224 EGLBoolean TegraV4L2Device::DestroyEGLImage(EGLDisplay egl_display, | 219 EGLBoolean TegraV4L2Device::DestroyEGLImage(EGLDisplay egl_display, |
225 EGLImageKHR egl_image) { | 220 EGLImageKHR egl_image) { |
226 return eglDestroyImageKHR(egl_display, egl_image); | 221 return eglDestroyImageKHR(egl_display, egl_image); |
227 } | 222 } |
228 | 223 |
229 GLenum TegraV4L2Device::GetTextureTarget() { return GL_TEXTURE_2D; } | 224 GLenum TegraV4L2Device::GetTextureTarget() { |
| 225 return GL_TEXTURE_2D; |
| 226 } |
230 | 227 |
231 uint32_t TegraV4L2Device::PreferredInputFormat() { | 228 uint32_t TegraV4L2Device::PreferredInputFormat() { |
232 // TODO(posciak): We should support "dontcare" returns here once we | 229 // TODO(posciak): We should support "dontcare" returns here once we |
233 // implement proper handling (fallback, negotiation) for this in users. | 230 // implement proper handling (fallback, negotiation) for this in users. |
234 CHECK_EQ(type_, kEncoder); | 231 CHECK_EQ(type_, kEncoder); |
235 return V4L2_PIX_FMT_YUV420M; | 232 return V4L2_PIX_FMT_YUV420M; |
236 } | 233 } |
237 | 234 |
238 } // namespace content | 235 } // namespace media |
OLD | NEW |