Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: content/common/gpu/media/exynos_v4l2_video_device.cc

Issue 137023008: Add support for Tegra V4L2 VDA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use scopedFD for dmabuf fds. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 DVLOG(3) << "CreateEGLImage()";
127
128 base::ScopedFD dmabuf_fds[2];
129 for (size_t i = 0; i < arraysize(dmabuf_fds); ++i) {
130 // Export the DMABUF fd so we can export it as a texture.
131 struct v4l2_exportbuffer expbuf;
132 memset(&expbuf, 0, sizeof(expbuf));
133 expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
134 expbuf.index = buffer_index;
135 expbuf.plane = i;
136 expbuf.flags = O_CLOEXEC;
137 if (HANDLE_EINTR(Ioctl(VIDIOC_EXPBUF, &expbuf) != 0)) {
138 return EGL_NO_IMAGE_KHR;
139 }
140 dmabuf_fds[i].reset(expbuf.fd);
141 }
142 EGLint attrs[] = {
143 EGL_WIDTH, 0, EGL_HEIGHT, 0,
144 EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0,
145 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0,
146 EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0,
147 EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, };
148 attrs[1] = frame_buffer_size.width();
149 attrs[3] = frame_buffer_size.height();
150 attrs[5] = DRM_FORMAT_NV12;
151 attrs[7] = dmabuf_fds[0].get();
152 attrs[9] = 0;
153 attrs[11] = frame_buffer_size.width();
154 attrs[13] = dmabuf_fds[1].get();
155 attrs[15] = 0;
156 attrs[17] = frame_buffer_size.width();
157
158 EGLImageKHR egl_image = eglCreateImageKHR(
159 egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs);
160 if (egl_image == EGL_NO_IMAGE_KHR) {
161 return egl_image;
162 }
163 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
164 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image);
165
166 return egl_image;
167 }
168
169 EGLBoolean ExynosV4L2Device::DestroyEGLImage(EGLDisplay egl_display,
170 EGLImageKHR egl_image) {
171 return eglDestroyImageKHR(egl_display, egl_image);
172 }
173
174 GLenum ExynosV4L2Device::GetTextureTarget() { return GL_TEXTURE_EXTERNAL_OES; }
175
176 uint32 ExynosV4L2Device::PreferredOutputFormat() { return V4L2_PIX_FMT_NV12M; }
177
117 } // namespace content 178 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698