Skip to content

Commit 3b053da

Browse files
Merge branch 'sprint/24Q4' into sprint/24Q4
2 parents f8cce19 + 3af3e0e commit 3b053da

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

ScreenCapture/Implementation/Realtek/Realtek.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <sys/types.h>
2525
#include <sys/stat.h>
2626
#include <sys/mman.h>
27+
#include <sys/ioctl.h>
2728
#include "kms.h"
2829
#include "Realtek.h"
2930

@@ -81,7 +82,6 @@ bool DRMScreenCapture_GetScreenInfo(DRMScreenCapture* handle) {
8182
// open drm device to get screen information
8283
int retryCount = 0;
8384
drmModePlane *plane = nullptr;
84-
struct drm_mode_map_dumb map = {};
8585

8686
context->fd = open(DEFAULT_DEVICE, O_RDWR);
8787
if(!context->fd) {
@@ -147,15 +147,19 @@ bool DRMScreenCapture_GetScreenInfo(DRMScreenCapture* handle) {
147147
ret = false;
148148
break;
149149
}
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);
152157
if(drmRet) {
153-
cout << "[SCREENCAP] drmIoctl fail, ret=" << drmRet << endl;
158+
cout << "[SCREENCAP] drmIoctl(DRM_IOCTL_PRIME_HANDLE_TO_FD) fail, ret=" << drmRet << endl;
154159
ret = false;
155160
break;
156161
}
157-
context->offset = map.offset;
158-
cout << "[SCREENCAP] offset : " << map.offset << endl;
162+
handle->dmabuf_fd = drm_prime.fd;
159163
} while(false);
160164

161165
if(fb)
@@ -166,17 +170,15 @@ bool DRMScreenCapture_GetScreenInfo(DRMScreenCapture* handle) {
166170
}
167171

168172
bool DRMScreenCapture_ScreenCapture(DRMScreenCapture* handle, uint8_t* output, uint32_t bufSize) {
169-
DRMContext *context;
170173
bool ret = true;
171174

172175
do {
173-
if(!handle || !handle->context || !output) {
176+
if(!handle || !output) {
174177
cout << "[SCREENCAP] null input parameter" << endl;
175178
ret = false;
176179
break;
177180
}
178181

179-
context = (DRMContext*) handle->context;
180182
uint32_t size = handle->pitch * handle->height;
181183
if(bufSize < size) {
182184
// buffer size not match
@@ -186,12 +188,11 @@ bool DRMScreenCapture_ScreenCapture(DRMScreenCapture* handle, uint8_t* output, u
186188

187189
// copy frame
188190
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);
191192
if (vaddr == MAP_FAILED) {
192-
perror("mmap failed : ");
193-
ret = false;
194-
break;
193+
cout << "[SCREENCAP] mmap failed" << endl;
194+
ret = false;
195+
break;
195196
}
196197

197198
memcpy(output,(unsigned char*)vaddr, size);

ScreenCapture/Implementation/Realtek/Realtek.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct DRMScreenCapture_s {
2525
uint32_t height;
2626
uint32_t pitch;
2727
uint8_t bpp;
28+
int dmabuf_fd;
2829
}DRMScreenCapture;
2930

3031
DRMScreenCapture* DRMScreenCapture_Init();

0 commit comments

Comments
 (0)