24
24
#include < sys/types.h>
25
25
#include < sys/stat.h>
26
26
#include < sys/mman.h>
27
+ #include < sys/ioctl.h>
27
28
#include " kms.h"
28
29
#include " Realtek.h"
29
30
@@ -81,7 +82,6 @@ bool DRMScreenCapture_GetScreenInfo(DRMScreenCapture* handle) {
81
82
// open drm device to get screen information
82
83
int retryCount = 0 ;
83
84
drmModePlane *plane = nullptr ;
84
- struct drm_mode_map_dumb map = {};
85
85
86
86
context->fd = open (DEFAULT_DEVICE, O_RDWR);
87
87
if (!context->fd ) {
@@ -147,15 +147,19 @@ bool DRMScreenCapture_GetScreenInfo(DRMScreenCapture* handle) {
147
147
ret = false ;
148
148
break ;
149
149
}
150
- map.handle = fb->handle ;
151
- int drmRet = drmIoctl (context->fd , DRM_IOCTL_MODE_MAP_DUMB, &map);
150
+
151
+ struct drm_prime_handle drm_prime;
152
+ int drmRet = 0 ;
153
+
154
+ drm_prime.handle = fb->handle ;
155
+ drm_prime.flags = 0 ;
156
+ drmRet = ioctl (context->fd , DRM_IOCTL_PRIME_HANDLE_TO_FD, &drm_prime);
152
157
if (drmRet) {
153
- cout << " [SCREENCAP] drmIoctl fail, ret=" << drmRet << endl;
158
+ cout << " [SCREENCAP] drmIoctl(DRM_IOCTL_PRIME_HANDLE_TO_FD) fail, ret=" << drmRet << endl;
154
159
ret = false ;
155
160
break ;
156
161
}
157
- context->offset = map.offset ;
158
- cout << " [SCREENCAP] offset : " << map.offset << endl;
162
+ handle->dmabuf_fd = drm_prime.fd ;
159
163
} while (false );
160
164
161
165
if (fb)
@@ -166,17 +170,15 @@ bool DRMScreenCapture_GetScreenInfo(DRMScreenCapture* handle) {
166
170
}
167
171
168
172
bool DRMScreenCapture_ScreenCapture (DRMScreenCapture* handle, uint8_t * output, uint32_t bufSize) {
169
- DRMContext *context;
170
173
bool ret = true ;
171
174
172
175
do {
173
- if (!handle || !handle-> context || ! output) {
176
+ if (!handle || !output) {
174
177
cout << " [SCREENCAP] null input parameter" << endl;
175
178
ret = false ;
176
179
break ;
177
180
}
178
181
179
- context = (DRMContext*) handle->context ;
180
182
uint32_t size = handle->pitch * handle->height ;
181
183
if (bufSize < size) {
182
184
// buffer size not match
@@ -186,12 +188,11 @@ bool DRMScreenCapture_ScreenCapture(DRMScreenCapture* handle, uint8_t* output, u
186
188
187
189
// copy frame
188
190
void *vaddr = NULL ;
189
- vaddr =(void *) mmap (NULL , size, PROT_READ , MAP_SHARED, context->fd , context->offset ) ;
190
-
191
+ vaddr =(void *) mmap64 (NULL , size, PROT_READ , MAP_SHARED, handle->dmabuf_fd , 0 );
191
192
if (vaddr == MAP_FAILED) {
192
- perror ( " mmap failed : " ) ;
193
- ret = false ;
194
- break ;
193
+ cout << " [SCREENCAP] mmap failed" << endl ;
194
+ ret = false ;
195
+ break ;
195
196
}
196
197
197
198
memcpy (output,(unsigned char *)vaddr, size);
0 commit comments