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 #include <fcntl.h> | 6 #include <fcntl.h> |
| 7 #include <libdrm/drm_fourcc.h> |
6 #include <linux/videodev2.h> | 8 #include <linux/videodev2.h> |
7 #include <poll.h> | 9 #include <poll.h> |
8 #include <sys/eventfd.h> | 10 #include <sys/eventfd.h> |
9 #include <sys/ioctl.h> | 11 #include <sys/ioctl.h> |
10 #include <sys/mman.h> | 12 #include <sys/mman.h> |
11 | 13 |
12 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/files/scoped_file.h" |
13 #include "base/posix/eintr_wrapper.h" | 16 #include "base/posix/eintr_wrapper.h" |
14 #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" |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 | 21 |
18 namespace { | 22 namespace { |
19 const char kDevice[] = "/dev/mfc-dec"; | 23 const char kDevice[] = "/dev/mfc-dec"; |
20 } | 24 } |
21 | 25 |
22 ExynosV4L2Device::ExynosV4L2Device() | 26 ExynosV4L2Device::ExynosV4L2Device() |
23 : device_fd_(-1), device_poll_interrupt_fd_(-1) {} | 27 : device_fd_(-1), device_poll_interrupt_fd_(-1) {} |
24 | 28 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (device_fd_ == -1) { | 111 if (device_fd_ == -1) { |
108 return false; | 112 return false; |
109 } | 113 } |
110 | 114 |
111 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | 115 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
112 if (device_poll_interrupt_fd_ == -1) { | 116 if (device_poll_interrupt_fd_ == -1) { |
113 return false; | 117 return false; |
114 } | 118 } |
115 return true; | 119 return true; |
116 } | 120 } |
| 121 |
| 122 EGLImageKHR ExynosV4L2Device::CreateEGLImage(EGLDisplay egl_display, |
| 123 GLuint texture_id, |
| 124 gfx::Size frame_buffer_size, |
| 125 unsigned int buffer_index, |
| 126 size_t planes_count) { |
| 127 DVLOG(3) << "CreateEGLImage()"; |
| 128 |
| 129 scoped_ptr<base::ScopedFD[]> dmabuf_fds(new base::ScopedFD[planes_count]); |
| 130 for (size_t i = 0; i < planes_count; ++i) { |
| 131 // Export the DMABUF fd so we can export it as a texture. |
| 132 struct v4l2_exportbuffer expbuf; |
| 133 memset(&expbuf, 0, sizeof(expbuf)); |
| 134 expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 135 expbuf.index = buffer_index; |
| 136 expbuf.plane = i; |
| 137 expbuf.flags = O_CLOEXEC; |
| 138 if (HANDLE_EINTR(Ioctl(VIDIOC_EXPBUF, &expbuf) != 0)) { |
| 139 return EGL_NO_IMAGE_KHR; |
| 140 } |
| 141 dmabuf_fds[i].reset(expbuf.fd); |
| 142 } |
| 143 DCHECK_EQ(planes_count, 2); |
| 144 EGLint attrs[] = { |
| 145 EGL_WIDTH, 0, EGL_HEIGHT, 0, |
| 146 EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0, |
| 147 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0, |
| 148 EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0, |
| 149 EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, }; |
| 150 attrs[1] = frame_buffer_size.width(); |
| 151 attrs[3] = frame_buffer_size.height(); |
| 152 attrs[5] = DRM_FORMAT_NV12; |
| 153 attrs[7] = dmabuf_fds[0].get(); |
| 154 attrs[9] = 0; |
| 155 attrs[11] = frame_buffer_size.width(); |
| 156 attrs[13] = dmabuf_fds[1].get(); |
| 157 attrs[15] = 0; |
| 158 attrs[17] = frame_buffer_size.width(); |
| 159 |
| 160 EGLImageKHR egl_image = eglCreateImageKHR( |
| 161 egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs); |
| 162 if (egl_image == EGL_NO_IMAGE_KHR) { |
| 163 return egl_image; |
| 164 } |
| 165 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); |
| 166 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
| 167 |
| 168 return egl_image; |
| 169 } |
| 170 |
| 171 EGLBoolean ExynosV4L2Device::DestroyEGLImage(EGLDisplay egl_display, |
| 172 EGLImageKHR egl_image) { |
| 173 return eglDestroyImageKHR(egl_display, egl_image); |
| 174 } |
| 175 |
| 176 GLenum ExynosV4L2Device::GetTextureTarget() { return GL_TEXTURE_EXTERNAL_OES; } |
| 177 |
| 178 uint32 ExynosV4L2Device::PreferredOutputFormat() { return V4L2_PIX_FMT_NV12M; } |
| 179 |
117 } // namespace content | 180 } // namespace content |
OLD | NEW |