Chromium Code Reviews| 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" |
| 13 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 14 #include "content/common/gpu/media/exynos_v4l2_video_device.h" | 16 #include "content/common/gpu/media/exynos_v4l2_video_device.h" |
| 17 #include "ui/gl/gl_bindings.h" | |
| 15 | 18 |
| 16 namespace content { | 19 namespace content { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 const char kDevice[] = "/dev/mfc-dec"; | 22 const char kDevice[] = "/dev/mfc-dec"; |
| 20 } | 23 } |
| 21 | 24 |
| 22 ExynosV4L2Device::ExynosV4L2Device() | 25 ExynosV4L2Device::ExynosV4L2Device() |
| 23 : device_fd_(-1), device_poll_interrupt_fd_(-1) {} | 26 : device_fd_(-1), device_poll_interrupt_fd_(-1) {} |
| 24 | 27 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 if (device_fd_ == -1) { | 110 if (device_fd_ == -1) { |
| 108 return false; | 111 return false; |
| 109 } | 112 } |
| 110 | 113 |
| 111 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); | 114 device_poll_interrupt_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
| 112 if (device_poll_interrupt_fd_ == -1) { | 115 if (device_poll_interrupt_fd_ == -1) { |
| 113 return false; | 116 return false; |
| 114 } | 117 } |
| 115 return true; | 118 return true; |
| 116 } | 119 } |
| 120 | |
| 121 EGLImageKHR ExynosV4L2Device::CreateEGLImage(EGLDisplay egl_display, | |
| 122 GLuint texture_id, | |
| 123 gfx::Size frame_buffer_size, | |
| 124 unsigned int buffer_index) { | |
| 125 DVLOG(3) << "CreateEGLImage()"; | |
| 126 int dmabuf_fds[2] = {-1, -1}; | |
|
Pawel Osciak
2014/03/27 09:09:50
As I mentioned before, num_planes should be passed
shivdasp
2014/03/27 09:33:22
I think this is do-able quickly.Done.
On 2014/03/2
sheu
2014/03/27 09:40:41
I'd disagree here -- if we're defining a preferred
shivdasp
2014/03/27 10:06:46
I think the num_planes depend upon the output form
Pawel Osciak
2014/03/28 05:33:53
Yes this is exactly what I mean. There is no need
shivdasp
2014/03/28 05:42:38
Okay I will make a change to send in the num_plane
| |
| 127 for (size_t i = 0; i < arraysize(dmabuf_fds); ++i) { | |
| 128 // Export the DMABUF fd so we can export it as a texture. | |
| 129 struct v4l2_exportbuffer expbuf; | |
| 130 memset(&expbuf, 0, sizeof(expbuf)); | |
| 131 expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
| 132 expbuf.index = buffer_index; | |
| 133 expbuf.plane = i; | |
| 134 expbuf.flags = O_CLOEXEC; | |
| 135 if (HANDLE_EINTR(Ioctl(VIDIOC_EXPBUF, &expbuf) != 0)) { | |
| 136 return EGL_NO_IMAGE_KHR; | |
|
Pawel Osciak
2014/03/27 09:09:50
If this fails on any other than the first fd, we w
shivdasp
2014/03/27 09:33:22
I need to understand the usage here. If I understa
sheu
2014/03/27 09:40:41
See above about preferred format.
In the case we
shivdasp
2014/03/27 10:06:46
Using ScopedFD looks easier, let me make that chan
Pawel Osciak
2014/03/28 05:33:53
Yes, sorry, I forgot we had ScopedFD
| |
| 137 } | |
| 138 dmabuf_fds[i] = expbuf.fd; | |
| 139 } | |
| 140 EGLint attrs[] = { | |
| 141 EGL_WIDTH, 0, EGL_HEIGHT, 0, | |
| 142 EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0, | |
| 143 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0, | |
| 144 EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0, | |
| 145 EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, }; | |
| 146 attrs[1] = frame_buffer_size.width(); | |
| 147 attrs[3] = frame_buffer_size.height(); | |
| 148 attrs[5] = DRM_FORMAT_NV12; | |
|
Pawel Osciak
2014/03/27 09:09:50
This shouldn't be hardcoded either actually...
Ho
shivdasp
2014/03/27 09:33:22
How do you propose we remove the hardcoding of DRM
sheu
2014/03/27 09:40:41
See above about preferred format.
Pawel Osciak
2014/03/28 05:33:53
Ok, let's keep it for now and figure it out later.
shivdasp
2014/03/28 05:42:38
I understand there is no more change required here
| |
| 149 attrs[7] = dmabuf_fds[0]; | |
| 150 attrs[9] = 0; | |
| 151 attrs[11] = frame_buffer_size.width(); | |
| 152 attrs[13] = dmabuf_fds[1]; | |
| 153 attrs[15] = 0; | |
| 154 attrs[17] = frame_buffer_size.width(); | |
| 155 | |
| 156 EGLImageKHR egl_image = eglCreateImageKHR( | |
| 157 egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs); | |
| 158 if (egl_image == EGL_NO_IMAGE_KHR) { | |
| 159 close(dmabuf_fds[0]); | |
| 160 close(dmabuf_fds[1]); | |
| 161 return egl_image; | |
| 162 } | |
| 163 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); | |
| 164 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); | |
| 165 | |
| 166 // Close the fds now | |
| 167 close(dmabuf_fds[0]); | |
| 168 close(dmabuf_fds[1]); | |
| 169 return egl_image; | |
| 170 } | |
| 171 | |
| 172 EGLBoolean ExynosV4L2Device::DestroyEGLImage(EGLDisplay egl_display, | |
| 173 EGLImageKHR egl_image) { | |
| 174 return eglDestroyImageKHR(egl_display, egl_image); | |
| 175 } | |
| 176 | |
| 177 GLenum ExynosV4L2Device::GetTextureTarget() { return GL_TEXTURE_EXTERNAL_OES; } | |
| 178 | |
| 179 uint32 ExynosV4L2Device::PreferredOutputFormat() { return V4L2_PIX_FMT_NV12M; } | |
| 180 | |
| 117 } // namespace content | 181 } // namespace content |
| OLD | NEW |