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

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, 10 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 //
sheu 2014/03/06 08:51:34 Extra comment line here.
shivdasp 2014/03/06 11:10:09 Done.
5
6 #include <dlfcn.h>
7 #include <fcntl.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);
sheu 2014/03/06 08:51:34 No HANDLE_EINTR wrapper needed for this?
shivdasp 2014/03/06 11:10:09 Done.
63 }
64
65 bool TegraV4L2Device::Poll(bool poll_device, bool* event_pending) {
66 if (TegraV4L2_Poll(device_fd_, poll_device, event_pending) == -1) {
sheu 2014/03/06 08:51:34 No HANDLE_EINTR wrapper needed for this?
shivdasp 2014/03/06 11:10:09 Done.
67 DLOG(ERROR) << "TegraV4L2Poll returned -1 ";
68 return false;
69 }
70 return true;
71 }
72
73 void* TegraV4L2Device::Mmap(void* addr,
74 unsigned int len,
75 int prot,
76 int flags,
77 unsigned int offset) {
78 return TegraV4L2_Mmap(addr, len, prot, flags, device_fd_, offset);
79 }
80
81 void TegraV4L2Device::Munmap(void* addr, unsigned int len) {
82 TegraV4L2_Munmap(addr, len);
83 }
84
85 bool TegraV4L2Device::SetDevicePollInterrupt() {
86 if (HANDLE_EINTR(TegraV4L2_SetDevicePollInterrupt(device_fd_)) == -1) {
87 DLOG(ERROR) << "Error in calling TegraV4L2SetDevicePollInterrupt";
88 return false;
89 }
90 return true;
91 }
92
93 bool TegraV4L2Device::ClearDevicePollInterrupt() {
94 if (HANDLE_EINTR(TegraV4L2_ClearDevicePollInterrupt(device_fd_)) == -1) {
95 DLOG(ERROR) << "Error in calling TegraV4L2ClearDevicePollInterrupt";
96 return false;
97 }
98 return true;
99 }
100
101 bool TegraV4L2Device::Initialize() {
102 #define TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(name) \
103 do { \
104 TegraV4L2_##name = reinterpret_cast<TegraV4L2##name>( \
105 dlsym(RTLD_DEFAULT, "TegraV4L2_" #name)); \
106 if (TegraV4L2_##name == NULL) { \
107 LOG(ERROR) << "Failed to dlsym TegraV4L2_" #name; \
108 return false; \
109 } \
110 } while (0)
111
112 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Open);
113 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Close);
114 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Ioctl);
115 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Poll);
116 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(SetDevicePollInterrupt);
117 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(ClearDevicePollInterrupt);
118 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Mmap);
119 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(Munmap);
120 TEGRAV4L2_DLSYM_OR_RETURN_ON_ERROR(UseEglImage);
sheu 2014/03/06 08:51:34 Can this sort of thing be done once at startup tim
shivdasp 2014/03/06 11:10:09 Initialize() is called when the V4L2Device is crea
sheu 2014/03/07 00:18:08 We could do this once statically similar to how Va
121 #undef TEGRAV4L2_DLSYM
122
123 device_fd_ =
124 HANDLE_EINTR(TegraV4L2_Open(kDevice, O_RDWR | O_NONBLOCK | O_CLOEXEC));
125 if (device_fd_ == -1) {
126 DLOG(ERROR) << "Unable to open tegra_v4l2_open ";
127 return false;
128 }
129 return true;
130 }
131
132 EGLImageKHR TegraV4L2Device::CreateEGLImage(EGLDisplay egl_display,
133 EGLint[] /*attrib*/,
134 unsigned int texture_id,
135 unsigned int buffer_index) {
136 EGLint attr = EGL_NONE;
137 EGLImageKHR egl_image = eglCreateImageKHR(egl_display,
138 egl_context_,
139 EGL_GL_TEXTURE_2D_KHR,
140 (EGLClientBuffer)(texture_id),
sheu 2014/03/06 08:51:34 static_cast<>; we don't use C-style casts.
shivdasp 2014/03/06 11:10:09 Done.
141 &attr);
142 if (egl_image == EGL_NO_IMAGE_KHR) {
143 return egl_image;
144 }
145 if (TegraV4L2_UseEglImage(device_fd_, buffer_index, egl_image) != 0) {
146 eglDestroyImageKHR(egl_display, egl_image);
147 egl_image = EGL_NO_IMAGE_KHR;
148 }
149 return egl_image;
sheu 2014/03/06 08:51:34 So as I understand it: In the Exynos case, we exp
shivdasp 2014/03/06 11:10:09 Yes that's right. tegrav4l2lib takes care of destr
150 }
151
152 unsigned int TegraV4L2Device::GetTextureTarget() { return GL_TEXTURE_2D; }
153
154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698