Index: content/common/gpu/media/exynos_v4l2_video_device.cc |
diff --git a/content/common/gpu/media/exynos_v4l2_video_device.cc b/content/common/gpu/media/exynos_v4l2_video_device.cc |
index ef40cf0e6854e4a7a9b90aa24d038bfb60977432..1cff6f4150b9745d93e935b07a7d29b3f9679e29 100644 |
--- a/content/common/gpu/media/exynos_v4l2_video_device.cc |
+++ b/content/common/gpu/media/exynos_v4l2_video_device.cc |
@@ -2,8 +2,10 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
// |
+ |
#include <fcntl.h> |
#include <linux/videodev2.h> |
+#include <libdrm/drm_fourcc.h> |
sheu
2014/03/27 02:00:23
Header ordering -- this one above.
|
#include <poll.h> |
#include <sys/eventfd.h> |
#include <sys/ioctl.h> |
@@ -12,6 +14,7 @@ |
#include "base/debug/trace_event.h" |
#include "base/posix/eintr_wrapper.h" |
#include "content/common/gpu/media/exynos_v4l2_video_device.h" |
+#include "ui/gl/gl_bindings.h" |
namespace content { |
@@ -33,6 +36,14 @@ ExynosV4L2Device::~ExynosV4L2Device() { |
} |
} |
+ExynosV4L2Device::DeviceOutputRecord::DeviceOutputRecord() |
+ : egl_image(EGL_NO_IMAGE_KHR) { |
+ for (size_t i = 0; i < arraysize(fds); ++i) |
+ fds[i] = -1; |
+} |
+ |
+ExynosV4L2Device::DeviceOutputRecord::~DeviceOutputRecord() {} |
+ |
int ExynosV4L2Device::Ioctl(int request, void* arg) { |
return ioctl(device_fd_, request, arg); |
} |
@@ -114,4 +125,79 @@ bool ExynosV4L2Device::Initialize() { |
} |
return true; |
} |
+ |
+EGLImageKHR ExynosV4L2Device::CreateEGLImage(EGLDisplay egl_display, |
+ GLuint texture_id, |
+ gfx::Size frame_buffer_size, |
+ unsigned int buffer_index, |
+ unsigned int total_buffers) { |
+ DVLOG(3) << "CreateEGLImage() "; |
+ // Initialize the map if it is empty. |
+ if (device_output_buffer_map_.empty()) |
+ device_output_buffer_map_.resize(total_buffers); |
+ |
+ // First get the export buffer |
+ DeviceOutputRecord& output_record = device_output_buffer_map_[buffer_index]; |
+ |
+ for (size_t i = 0; i < arraysize(output_record.fds); ++i) { |
+ // Export the DMABUF fd so we can export it as a texture. |
+ struct v4l2_exportbuffer expbuf; |
+ memset(&expbuf, 0, sizeof(expbuf)); |
+ expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
+ expbuf.index = buffer_index; |
+ expbuf.plane = i; |
+ expbuf.flags = O_CLOEXEC; |
+ if (HANDLE_EINTR(Ioctl(VIDIOC_EXPBUF, &expbuf) != 0)) { |
+ return EGL_NO_IMAGE_KHR; |
+ } |
+ output_record.fds[i] = expbuf.fd; |
+ } |
+ |
+ EGLint attrs[] = { |
+ EGL_WIDTH, 0, EGL_HEIGHT, 0, |
+ EGL_LINUX_DRM_FOURCC_EXT, 0, EGL_DMA_BUF_PLANE0_FD_EXT, 0, |
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0, EGL_DMA_BUF_PLANE0_PITCH_EXT, 0, |
+ EGL_DMA_BUF_PLANE1_FD_EXT, 0, EGL_DMA_BUF_PLANE1_OFFSET_EXT, 0, |
+ EGL_DMA_BUF_PLANE1_PITCH_EXT, 0, EGL_NONE, }; |
+ |
+ attrs[1] = frame_buffer_size.width(); |
+ attrs[3] = frame_buffer_size.height(); |
+ attrs[5] = DRM_FORMAT_NV12; |
+ attrs[7] = output_record.fds[0]; |
+ attrs[9] = 0; |
+ attrs[11] = frame_buffer_size.width(); |
+ attrs[13] = output_record.fds[1]; |
+ attrs[15] = 0; |
+ attrs[17] = frame_buffer_size.width(); |
+ |
+ EGLImageKHR egl_image = eglCreateImageKHR( |
+ egl_display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, attrs); |
+ if (egl_image == EGL_NO_IMAGE_KHR) { |
+ return egl_image; |
+ } |
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id); |
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_image); |
+ return egl_image; |
+} |
+ |
+void ExynosV4L2Device::DestroyEGLImage(unsigned int buffer_index) { |
+ DeviceOutputRecord& output_record = device_output_buffer_map_[buffer_index]; |
+ for (size_t j = 0; j < arraysize(output_record.fds); ++j) { |
+ if (output_record.fds[j] != -1) { |
+ if (close(output_record.fds[j])) { |
+ DVPLOG(1) << __func__ << " close() on a dmabuf fd failed."; |
+ } |
+ } |
+ } |
+ // Clear the map if this is the last buffer. |
+ if (buffer_index == device_output_buffer_map_.size() - 1) |
+ device_output_buffer_map_.clear(); |
sheu
2014/03/27 02:00:23
This is really brittle.
shivdasp
2014/03/27 02:41:04
Seems this is not needed now after reading your pr
|
+} |
+ |
+GLenum ExynosV4L2Device::GetTextureTarget() { return GL_TEXTURE_EXTERNAL_OES; } |
+ |
+uint32 ExynosV4L2Device::GetCapturePixelFormat() { return V4L2_PIX_FMT_NV12M; } |
+ |
+uint8 ExynosV4L2Device::GetNumberOfPlanes() { return 2; } |
+ |
} // namespace content |