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