-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathegl_ump.cpp
More file actions
190 lines (156 loc) · 5.36 KB
/
Copy pathegl_ump.cpp
File metadata and controls
190 lines (156 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#define EGL_EGLEXT_PROTOTYPES
#define MALI_USE_DMA_BUF 1
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <ump/ump.h>
#define WIDTH 1920
#define HEIGHT 1080
int main(int argc, char *argv[])
{
int v4l2_dev = -1, ump_sid = -1;
ump_handle umph;
size_t len = 1920*1080*3;
if (!(v4l2_dev = open("/dev/video10", O_RDWR | O_NONBLOCK)))
{
printf("Cannot open AML video device /dev/video10: %s\n", strerror(errno));
return -1;
}
v4l2_format fmt;
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix_mp.width = WIDTH;
fmt.fmt.pix_mp.height = HEIGHT;
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_RGB24;//V4L2_PIX_FMT_NV12;
if (ioctl(v4l2_dev, VIDIOC_S_FMT, &fmt) < 0)
{
printf("VIDIOC_S_FMT failed: %s\n", strerror(errno));
return -1;
}
v4l2_requestbuffers req;
req.count = 1;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
if (ioctl(v4l2_dev, VIDIOC_REQBUFS, &req) < 0) {
printf("VIDIOC_REQBUFS failed: %s\n", strerror(errno));
return -1;
}
if(req.count != 1) {
printf("VIDIOC_REQBUFS returns no buffers\n");
return -1;
}
struct v4l2_buffer buffer;
memset(&buffer, 0, sizeof(buffer));
buffer.type = req.type;
buffer.memory = req.memory;
buffer.index = 0;
if (ioctl (v4l2_dev, VIDIOC_QUERYBUF, &buffer)) {
printf("VIDIOC_QUERYBUF failed\n");
return -1;
}
//Currently we need the mmap call as it alloates the memory inside kernel driver
//TODO: allocate the physical adress space without mmapping stuff
size_t mem_size = buffer.length;
void *mem = mmap(NULL, buffer.length,
PROT_READ | PROT_WRITE, // recommended
MAP_SHARED, // recommended
v4l2_dev, buffer.m.offset);
if (mem == MAP_FAILED) {
printf("mmap failed\n");
return -1;
}
struct v4l2_exportbuffer expbuf;
memset(&expbuf, 0, sizeof(expbuf));
expbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
expbuf.index = 0;
if (ioctl(v4l2_dev, VIDIOC_EXPBUF, &expbuf) == -1) {
printf("VIDIOC_EXPBUF failed: %s\n", strerror(errno));
return -1;
}
ump_open();
ump_sid = expbuf.fd;
umph = ump_handle_create_from_secure_id(ump_sid);
printf("UMP: secure%x, handle:%p, size:%lu\n", ump_sid, umph, ump_size_get(umph));
/******************** EGL ***************** */
{
EGLDisplay display;
EGLConfig config;
EGLContext context;
EGLint major, minor, num_config;
static const EGLint egl_config_attribs[] = {
EGL_BUFFER_SIZE, 32,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_DEPTH_SIZE, EGL_DONT_CARE,
EGL_STENCIL_SIZE, EGL_DONT_CARE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE,
};
static const EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (!eglInitialize(display, &major, &minor)) {
printf("failed to initialize %d\n",eglGetError());
return -1;
} else
puts(eglQueryString(display,EGL_EXTENSIONS));
if (!eglBindAPI(EGL_OPENGL_ES_API)) {
printf("failed to bind api EGL_OPENGL_ES_API\n");
return -1;
}
if(!eglChooseConfig(display, egl_config_attribs, &config, 1, &num_config))
{
printf("failed to choose config\n");
return -1;
}
context = eglCreateContext(display, config, EGL_NO_CONTEXT, context_attribs);
if (context == NULL) {
printf("failed to create context\n");
return -1;
}
typedef EGLImageKHR (*eglCreateImageKHRfn)(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list);
eglCreateImageKHRfn eglCreateImageKHR = (eglCreateImageKHRfn) (eglGetProcAddress("eglCreateImageKHR"));
struct fbdev_pixmap pixmap;
memset(&pixmap, 0, sizeof(struct fbdev_pixmap));
pixmap.width = WIDTH;
pixmap.height = HEIGHT;
pixmap.bytes_per_pixel = 4;
pixmap.buffer_size = 32;
pixmap.red_size = 8;
pixmap.green_size = 8;
pixmap.blue_size = 8;
pixmap.alpha_size = 8;
pixmap.flags = FBDEV_PIXMAP_SUPPORTS_UMP;
pixmap.data = (short unsigned int*)(umph);
pixmap.format = 0;
#ifdef SURFACE
EGLSurface surface = eglCreatePixmapSurface(display, config, (EGLNativePixmapType)&pixmap, NULL);
if (surface == EGL_NO_SURFACE) {
printf("failed to create DMA surface %d\n",eglGetError());
return -1;
}
#else
printf("EGLIMAGE\n");
EGLImageKHR image = eglCreateImageKHR(display, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, (EGLNativePixmapType)&pixmap, NULL);
if (image == EGL_NO_IMAGE_KHR) {
printf("failed to create DMA pixmap %x\n",eglGetError());
return -1;
}
#endif
}
return 0;
fail:
ump_close();
munmap(mem, mem_size);
return -1;
}