Skip to content

Commit 0cfe328

Browse files
committed
add support for nvenc and accel_assist
1 parent b40ace3 commit 0cfe328

22 files changed

+11017
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ xrdp/xrdp.ini
6363
xrdp_configure_options.h
6464
xrdpapi/xrdp-xrdpapi-simple
6565
.vscode/*
66+
xrdp_accel_assist/xrdp-accel-assist

Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ SUBDIRS = \
7070
$(XRDPVRDIR) \
7171
$(ULALACADIR) \
7272
tests \
73-
tools
73+
tools \
74+
xrdp_accel_assist
7475

7576
distclean-local:
7677
-rm -f xrdp_configure_options.h

common/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ AM_CPPFLAGS = \
3030
-DXRDP_PID_PATH=\"${localstatedir}/run\" \
3131
-DXRDP_LOG_PATH=\"${localstatedir}/log\"
3232

33+
if XRDP_NVENC
34+
AM_CPPFLAGS += -DXRDP_NVENC
35+
endif
36+
3337
# -no-suppress is an automake-specific flag which is needed
3438
# to prevent us missing compiler errors in some circumstances
3539
# (see https://github.com/neutrinolabs/xrdp/pull/1843 )

common/os_calls.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,36 @@ g_init(const char *app_name)
154154

155155
WSAStartup(2, &wsadata);
156156
#endif
157+
#if defined(XRDP_NVENC)
158+
if (g_strcmp(app_name, "xrdp") == 0)
159+
{
160+
/* call cuInit() to initalize the nvidia drivers */
161+
/* TODO create an issue on nvidia forums to figure out why we need to
162+
* do this */
163+
if (g_fork() == 0)
164+
{
165+
typedef int (*cu_init_proc)(int flags);
166+
cu_init_proc cu_init;
167+
long lib;
168+
char cuda_lib_name[] = "libcuda.so";
169+
char cuda_func_name[] = "cuInit";
170+
171+
lib = g_load_library(cuda_lib_name);
172+
if (lib != 0)
173+
{
174+
cu_init = (cu_init_proc)
175+
g_get_proc_address(lib, cuda_func_name);
176+
if (cu_init != NULL)
177+
{
178+
cu_init(0);
179+
}
180+
}
181+
log_end();
182+
g_deinit();
183+
g_exit(0);
184+
}
185+
}
186+
#endif
157187
}
158188

159189
/*****************************************************************************/
@@ -1530,6 +1560,39 @@ g_sck_send_fd_set(int sck, const void *ptr, unsigned int len,
15301560
return rv;
15311561
}
15321562

1563+
/******************************************************************************/
1564+
int
1565+
g_alloc_shm_map_fd(void **addr, int *fd, size_t size)
1566+
{
1567+
int lfd = -1;
1568+
void *laddr;
1569+
char name[128];
1570+
static unsigned int autoinc;
1571+
1572+
snprintf(name, 128, "/%8.8X%8.8X", getpid(), autoinc++);
1573+
lfd = shm_open(name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
1574+
if (lfd == -1)
1575+
{
1576+
return 1;
1577+
}
1578+
shm_unlink(name);
1579+
if (ftruncate(lfd, size) == -1)
1580+
{
1581+
close(lfd);
1582+
return 2;
1583+
}
1584+
/* map fd to address space */
1585+
laddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, lfd, 0);
1586+
if (laddr == MAP_FAILED)
1587+
{
1588+
close(lfd);
1589+
return 3;
1590+
}
1591+
*addr = laddr;
1592+
*fd = lfd;
1593+
return 0;
1594+
}
1595+
15331596
/*****************************************************************************/
15341597
/* returns boolean */
15351598
int

common/os_calls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ int g_sck_recv_fd_set(int sck, void *ptr, unsigned int len,
124124
*/
125125
int g_sck_send_fd_set(int sck, const void *ptr, unsigned int len,
126126
int fds[], unsigned int fdcount);
127+
int g_alloc_shm_map_fd(void **addr, int *fd, size_t size);
127128
int g_sck_last_error_would_block(int sck);
128129
int g_sck_socket_ok(int sck);
129130
/**

common/trans.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ enum xrdp_source
5757
XRDP_SOURCE_SESMAN,
5858
XRDP_SOURCE_CHANSRV,
5959
XRDP_SOURCE_MOD,
60+
XORGXRDP_SOURCE_XORG,
61+
XORGXRDP_SOURCE_XRDP,
6062

6163
XRDP_SOURCE_MAX_COUNT
6264
};

configure.ac

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ AC_ARG_ENABLE(x264, AS_HELP_STRING([--enable-x264],
175175
[Use x264 library (default: no)]),
176176
[], [enable_x264=no])
177177
AM_CONDITIONAL(XRDP_X264, [test x$enable_x264 = xyes])
178+
AC_ARG_ENABLE(nvenc, AS_HELP_STRING([--enable-nvenc],
179+
[Use nvenc library (default: no), env vars XRDP_NVENC_CFLAGS and
180+
XRDP_NVENC_LIBS should be set if used]),
181+
[], [enable_nvenc=no])
182+
AM_CONDITIONAL(XRDP_NVENC, [test x$enable_nvenc = xyes])
183+
AM_CONDITIONAL(XRDP_YAMI, [test x$enable_yami = xyes])
178184
AC_ARG_ENABLE(painter, AS_HELP_STRING([--disable-painter],
179185
[Do not use included painter library (default: no)]),
180186
[], [enable_painter=yes])
@@ -259,6 +265,9 @@ AC_CHECK_HEADER([security/_pam_types.h],
259265
AC_CHECK_HEADER([security/pam_constants.h],
260266
[AC_DEFINE([HAVE_PAM_CONSTANTS_H], 1, [Using OpenPAM], [])])
261267

268+
# shm_open may not be in the C library
269+
AC_SEARCH_LIBS([shm_open], [rt])
270+
262271
# Find imlib2
263272
case "$with_imlib2" in
264273
'' | no) AC_MSG_NOTICE([imlib2 will not be supported])
@@ -493,6 +502,18 @@ AS_IF( [test "x$enable_pixman" = "xyes"] , [PKG_CHECK_MODULES(PIXMAN, pixman-1 >
493502

494503
AS_IF( [test "x$enable_x264" = "xyes"] , [PKG_CHECK_MODULES(XRDP_X264, x264 >= 0.3.0)] )
495504

505+
if test "x$enable_nvenc" = "xyes"
506+
then
507+
if test ! -z "$XRDP_NVENC_CFLAGS"
508+
then
509+
AC_SUBST(XRDP_NVENC_CFLAGS, ["$XRDP_NVENC_CFLAGS"])
510+
fi
511+
if test ! -z "$XRDP_NVENC_LIBS"
512+
then
513+
AC_SUBST(XRDP_NVENC_LIBS, ["$XRDP_NVENC_LIBS"])
514+
fi
515+
fi
516+
496517
# checking for TurboJPEG
497518
if test "x$enable_tjpeg" = "xyes"
498519
then
@@ -653,6 +674,8 @@ AC_CONFIG_FILES([
653674
xup/Makefile
654675
third_party/Makefile
655676
third_party/tomlc99/Makefile
677+
xrdp_accel_assist/Makefile
678+
656679
])
657680

658681
AC_REQUIRE_AUX_FILE([tap-driver.sh])
@@ -668,6 +691,7 @@ echo " jpeg $enable_jpeg"
668691
echo " turbo jpeg $enable_tjpeg"
669692
echo " rfxcodec $enable_rfxcodec"
670693
echo " x264 $enable_x264"
694+
echo " nvenc $enable_nvenc"
671695
echo " painter $enable_painter"
672696
echo " pixman $enable_pixman"
673697
echo " fuse $enable_fuse"

sesman/sesman.ini.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ param=Xorg
147147
; Leave the rest parameters as-is unless you understand what will happen.
148148
param=-config
149149
param=xrdp/xorg.conf
150+
;param=xrdp/xorg_nvidia.conf
150151
param=-noreset
151152
param=-nolisten
152153
param=tcp
@@ -213,3 +214,4 @@ EnableSyslog=true
213214

214215
[SessionVariables]
215216
PULSE_SCRIPT=@sesmansysconfdir@/pulse/default.pa
217+
;XRDP_USE_ACCEL_ASSIST=1

xrdp_accel_assist/Makefile.am

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
AM_CPPFLAGS = \
2+
-I$(top_srcdir)/common
3+
4+
EXTRA_DIST = xrdp_accel_assist_shaders.c
5+
6+
XRDP_EXTRA_LIBS =
7+
XRDP_EXTRA_SOURCES =
8+
9+
if XRDP_NVENC
10+
AM_CPPFLAGS += -DXRDP_NVENC
11+
AM_CPPFLAGS += $(XRDP_NVENC_CFLAGS)
12+
XRDP_EXTRA_LIBS += $(XRDP_NVENC_LIBS)
13+
XRDP_EXTRA_SOURCES += xrdp_accel_assist_nvenc.c xrdp_accel_assist_nvenc.h encoder_headers/nvEncodeAPI_11_1.h
14+
endif
15+
16+
if XRDP_YAMI
17+
AM_CPPFLAGS += -DXRDP_YAMI
18+
AM_CPPFLAGS += $(XRDP_YAMI_CFLAGS)
19+
XRDP_EXTRA_LIBS += $(XRDP_YAMI_LIBS)
20+
XRDP_EXTRA_SOURCES += xrdp_accel_assist_yami.c xrdp_accel_assist_yami.h encoder_headers/yami_inf.h
21+
endif
22+
23+
pkglibexec_PROGRAMS = \
24+
xrdp-accel-assist
25+
26+
xrdp_accel_assist_SOURCES = \
27+
xrdp_accel_assist.c \
28+
xrdp_accel_assist.h \
29+
xrdp_accel_assist_x11.c \
30+
xrdp_accel_assist_x11.h \
31+
xrdp_accel_assist_egl.c \
32+
xrdp_accel_assist_egl.h \
33+
xrdp_accel_assist_glx.c \
34+
xrdp_accel_assist_glx.h \
35+
$(XRDP_EXTRA_SOURCES)
36+
37+
xrdp_accel_assist_LDADD = \
38+
$(top_builddir)/common/libcommon.la \
39+
$(XRDP_EXTRA_LIBS) \
40+
-lX11 -lepoxy
41+

0 commit comments

Comments
 (0)