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

Side by Side Diff: content/common/gpu/media/tegra_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: Created 6 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <dlfcn.h>
6 #include <fcntl.h>
7 #include <linux/videodev2.h>
8
9 #include "base/debug/trace_event.h"
10 #include "base/posix/eintr_wrapper.h"
11 #include "content/common/gpu/media/tegra_v4l2_video_device.h"
12 #include "ui/gl/gl_bindings.h"
13
14 namespace content {
15
16 namespace {
17 const char kDevice[] = "/dev/tegra_avpchannel";
18 }
19
20 typedef int32 (*TegraV4L2Open)(const char* name, int32 flags);
21 typedef int32 (*TegraV4L2Close)(int32 fd);
22 typedef int32 (*TegraV4L2Ioctl)(int32 fd, unsigned long cmd, ...);
23 typedef int32 (*TegraV4L2Poll)(int32 fd, bool poll_device, bool* event_pending);
24 typedef int32 (*TegraV4L2SetDevicePollInterrupt)(int32 fd);
25 typedef int32 (*TegraV4L2ClearDevicePollInterrupt)(int32 fd);
26 typedef void* (*TegraV4L2Mmap)(void* addr,
27 size_t length,
28 int prot,
29 int flags,
30 int fd,
31 unsigned int offset);
32 typedef int32 (*TegraV4L2Munmap)(void* addr, size_t length);
33 typedef int32 (*TegraV4L2UseEglImage)(int fd,
34 unsigned int buffer_index,
35 void* egl_image);
36
37 #define TEGRAV4L2_SYM(name) TegraV4L2##name TegraV4L2_##name = NULL
38
39 TEGRAV4L2_SYM(Open);
40 TEGRAV4L2_SYM(Close);
41 TEGRAV4L2_SYM(Ioctl);
42 TEGRAV4L2_SYM(Poll);
43 TEGRAV4L2_SYM(SetDevicePollInterrupt);
44 TEGRAV4L2_SYM(ClearDevicePollInterrupt);
45 TEGRAV4L2_SYM(Mmap);
46 TEGRAV4L2_SYM(Munmap);
47 TEGRAV4L2_SYM(UseEglImage);
48
49 #undef TEGRAV4L2_SYM
50
51 TegraV4L2Device::TegraV4L2Device(EGLContext egl_context)
52 : device_fd_(-1), egl_context_(egl_context) {}
53
54 TegraV4L2Device::~TegraV4L2Device() {
55 if (device_fd_ != -1) {
56 TegraV4L2_Close(device_fd_);
57 device_fd_ = -1;
58 }
59 }
60
61 int TegraV4L2Device::Ioctl(int flags, void* arg) {
62 return TegraV4L2_Ioctl(device_fd_, flags, arg);
63 }
64
65 bool TegraV4L2Device::Poll(bool poll_device, bool* event_pending) {
66 if (HANDLE_EINTR(TegraV4L2_Poll(device_fd_, poll_device, event_pending)) ==
67 -1) {
68 DLOG(ERROR) << "TegraV4L2Poll returned -1 ";
69 return false;
70 }
71 return true;
72 }
73
74 void* TegraV4L2Device::Mmap(void* addr,
75 unsigned int len,
76 int prot,
77 int flags,
78 unsigned int offset) {
79 return TegraV4L2_Mmap(addr, len, prot, flags, device_fd_, offset);
80 }
81
82 void TegraV4L2Device::Munmap(void* addr, unsigned int len) {
83 TegraV4L2_Munmap(addr, len);
84 }
85
86 bool TegraV4L2Device::SetDevicePollInterrupt() {
87 if (HANDLE_EINTR(TegraV4L2_SetDevicePollInterrupt(device_fd_)) == -1) {
88 DLOG(ERROR) << "Error in calling TegraV4L2SetDevicePollInterrupt";
89 return false;
90 }
91 return true;
92 }
93
94 bool TegraV4L2Device::ClearDevicePollInterrupt() {
95 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) {
96 DLOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt";
97 return false;
98 }
99 return true;
100 }
101
102 bool TegraV4L2Device::Initialize() {
103 static bool functions_initialized = InitializeLibrarySymbols();
Ami GONE FROM CHROMIUM 2014/03/28 19:33:40 Why add a known race condition when the fix is so
shivdasp 2014/03/28 20:39:26 I am not very familiar with LazyInstance, will thi
shivdasp 2014/03/28 22:03:10 Making this change in next patchset. class declara
104
105 if (!functions_initialized) {
106 DLOG(ERROR) << "Unable to initialize functions ";
107 return false;
108 }
109 device_fd_ =
110 HANDLE_EINTR(TegraV4L2_Open(kDevice, O_RDWR | O_NONBLOCK | O_CLOEXEC));
111 if (device_fd_ == -1) {
112 DLOG(ERROR) << "Unable to open tegra_v4l2_open ";
113 return false;
114 }
115 return true;
116 }
117
118 EGLImageKHR TegraV4L2Device::CreateEGLImage(EGLDisplay egl_display,
119 GLuint texture_id,
120 gfx::Size /* frame_buffer_size */,
121 unsigned int buffer_index,
122 size_t /* planes_count */) {
123 DVLOG(3) << "CreateEGLImage()";
124 EGLint attr = EGL_NONE;
125 EGLImageKHR egl_image =
126 eglCreateImageKHR(egl_display,
127 egl_context_,
128 EGL_GL_TEXTURE_2D_KHR,
129 reinterpret_cast<EGLClientBuffer>(texture_id),
130 &attr);
131 if (egl_image == EGL_NO_IMAGE_KHR) {
132 return egl_image;
133 }
134 if (TegraV4L2_UseEglImage(device_fd_, buffer_index, egl_image) != 0) {
135 eglDestroyImageKHR(egl_display, egl_image);
136 egl_image = EGL_NO_IMAGE_KHR;
137 }
138 return egl_image;
139 }
140
141 EGLBoolean TegraV4L2Device::DestroyEGLImage(EGLDisplay egl_display,
142 EGLImageKHR egl_image) {
143 return eglDestroyImageKHR(egl_display, egl_image);
144 }
145
146 GLenum TegraV4L2Device::GetTextureTarget() { return GL_TEXTURE_2D; }
147
148 uint32 TegraV4L2Device::PreferredOutputFormat() { return V4L2_PIX_FMT_NV12M; }
149
150 bool TegraV4L2Device::InitializeLibrarySymbols() {
151 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \
152 do { \
153 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \
Ami GONE FROM CHROMIUM 2014/03/28 19:33:40 I don't see spaces. To be clear I mean that Tegr
shivdasp 2014/03/28 20:39:26 Trust me , I really did these changes but for some
154 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \
155 if (TegraV4L2_##name == NULL) { \
156 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \
157 return false; \
158 } \
159 } while (0)
160
161 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Open);
162 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Close);
163 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Ioctl);
164 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Poll);
165 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(SetDevicePollInterrupt);
166 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(ClearDevicePollInterrupt);
167 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Mmap);
168 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Munmap);
169 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(UseEglImage);
170 #undef TEGRAV4L2_DLSYM
171 return true;
172 }
173
174 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698