Skip to content

Commit

Permalink
#1317 support for loading NvFBC license keys
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@17078 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Oct 3, 2017
1 parent a72c133 commit c236471
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rpmbuild/xpra.spec
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ rm -rf $RPM_BUILD_ROOT
#we only enable CUDA / NVENC with 64-bit builds:
%ifarch x86_64
%config(noreplace) %{_sysconfdir}/xpra/cuda.conf
%config(noreplace) %{_sysconfdir}/xpra/nvenc.keys
%config(noreplace) %{_sysconfdir}/xpra/*.keys
%endif
%config %{_sysconfdir}/xpra/conf.d/50_server_network.conf
%config %{_sysconfdir}/xpra/conf.d/55_server_x11.conf
Expand Down
6 changes: 6 additions & 0 deletions src/etc/xpra/nvfbc.keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# List of license keys to use with the NVFBC
#
# One key per line, ie:
# 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
# or just:
# 0102030405060708090A0B0C0D0E0F10
7 changes: 6 additions & 1 deletion src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ def add_service_exe(script, icon, base_name):
build_xpra_conf(".")
add_data_files('etc/xpra', glob.glob("etc/xpra/*conf"))
add_data_files('etc/xpra', glob.glob("etc/xpra/nvenc*.keys"))
add_data_files('etc/xpra', glob.glob("etc/xpra/nvfbc*.keys"))
add_data_files('etc/xpra/conf.d', glob.glob("etc/xpra/conf.d/*conf"))
#build minified html5 client in temporary build dir:
if "clean" not in sys.argv and html5_ENABLED:
Expand Down Expand Up @@ -1490,8 +1491,12 @@ def copytodir(src, dst_dir, dst_name=None, chmod=0o644):
etc_xpra_files = ["xorg.conf"]
if uinput_ENABLED:
etc_xpra_files.append("xorg-uinput.conf")
if nvenc_ENABLED or nvfbc_ENABLED:
etc_xpra_files.append("cuda.conf")
if nvenc_ENABLED:
etc_xpra_files += ["cuda.conf", "nvenc.keys"]
etc_xpra_files.append("nvenc.keys")
if nvfbc_ENABLED:
etc_xpra_files.append("nvfbc.keys")
for x in etc_xpra_files:
copytodir("etc/xpra/%s" % x, "/etc/xpra")
copytodir("etc/X11/xorg.conf.d/90-xpra-virtual.conf", "/etc/X11/xorg.conf.d/")
Expand Down
9 changes: 9 additions & 0 deletions src/xpra/codecs/nv_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ def validate_driver_yuv444lossless():
return True


def parse_nvfbc_hex_key(s):
#ie: 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
#ie: 0102030405060708090A0B0C0D0E0F10
#start by removing spaces and 0x:
hexstr = s.replace("0x", "").replace(",", "").replace(" ", "")
import binascii
return binascii.unhexlify(hexstr)


license_keys = {}
def get_license_keys(version=0, basefilename="nvenc"):
global license_keys
Expand Down
29 changes: 25 additions & 4 deletions src/xpra/codecs/nvfbc/fbc_capture_linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import os
import sys

from xpra.os_util import WIN32
from xpra.util import csv
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.codecs.codec_constants import TransientCodecException, CodecStateException
from xpra.codecs.nv_util import get_nvidia_module_version, get_cards
from xpra.codecs.nv_util import get_nvidia_module_version, get_cards, get_license_keys, parse_nvfbc_hex_key

from xpra.log import Logger
log = Logger("encoder", "nvfbc")
Expand All @@ -22,6 +23,8 @@ try:
import numpy
from pycuda import driver
from xpra.codecs.cuda_common.cuda_context import CUDA_ERRORS_INFO, select_device, device_info
except ImportError:
raise
except:
log.error("Error: NvFBC requires CUDA", exc_info=True)
CUDA_ERRORS_INFO = {}
Expand All @@ -32,6 +35,7 @@ from libc.stdint cimport uintptr_t, uint8_t, int64_t, uint32_t, uint64_t
from xpra.monotonic_time cimport monotonic_time

DEFAULT_PIXEL_FORMAT = os.environ.get("XPRA_NVFBC_DEFAULT_PIXEL_FORMAT", "RGB")
CLIENT_KEYS_STRS = get_license_keys(basefilename="nvfbc")


ctypedef unsigned long DWORD
Expand Down Expand Up @@ -384,9 +388,25 @@ cdef get_frame_grab_info(NVFBC_FRAME_GRAB_INFO *grab_info):
cdef NVFBC_SESSION_HANDLE create_context() except 0xffffffff:
cdef NVFBC_SESSION_HANDLE context = 0
cdef NVFBC_CREATE_HANDLE_PARAMS params
memset(&params, 0, sizeof(NVFBC_CREATE_HANDLE_PARAMS))
params.dwVersion = NVFBC_CREATE_HANDLE_PARAMS_VER
cdef NVFBCSTATUS ret = function_list.nvFBCCreateHandle(&context, &params)
cdef NVFBCSTATUS ret = <NVFBCSTATUS> 0
cdef char* ckey
keys = CLIENT_KEYS_STRS or [None]
log("create_context() will try with keys: %s", csv(keys))
assert len(keys)>0
for key in keys:
memset(&params, 0, sizeof(NVFBC_CREATE_HANDLE_PARAMS))
params.dwVersion = NVFBC_CREATE_HANDLE_PARAMS_VER
if key:
binkey = parse_nvfbc_hex_key(key)
ckey = binkey
params.privateData = <void*> ckey
params.privateDataSize = len(ckey)
log("create_context() key data=%#x, size=%i", <uintptr_t> ckey, len(ckey))
ret = function_list.nvFBCCreateHandle(&context, &params)
log("create_context() NvFBCCreateHandle()=%i for key=%s", ret, key)
if ret==0:
#success!
break
raiseNvFBC(context, ret, "NvFBCCreateHandle")
log("NvFBCCreateHandle: handle=%#x", context)
return context
Expand Down Expand Up @@ -556,6 +576,7 @@ cdef class NvFBC_CUDACapture:

def init_context(self, int width=-1, int height=-1, pixel_format="XRGB"):
log("init_context(%i, %i, %s)", width, height, pixel_format)
assert select_device, "CUDA is missing"
if pixel_format not in PIXEL_FORMAT_CONST:
raise Exception("unsupported pixel format '%s'" % pixel_format)
cdef NVFBC_BUFFER_FORMAT buffer_format = PIXEL_FORMAT_CONST[pixel_format]
Expand Down
36 changes: 27 additions & 9 deletions src/xpra/codecs/nvfbc/fbc_capture_win.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import os
import sys

from xpra.os_util import WIN32
from xpra.util import csv
from xpra.codecs.image_wrapper import ImageWrapper
from xpra.codecs.codec_constants import TransientCodecException, CodecStateException
from xpra.codecs.nv_util import get_nvidia_module_version, get_cards
from xpra.codecs.nv_util import get_nvidia_module_version, get_cards, get_license_keys, parse_nvfbc_hex_key

from xpra.log import Logger
log = Logger("encoder", "nvfbc")
Expand All @@ -35,6 +36,7 @@ from libc.stdint cimport uintptr_t, uint8_t, int64_t
from xpra.monotonic_time cimport monotonic_time

DEFAULT_PIXEL_FORMAT = os.environ.get("XPRA_NVFBC_DEFAULT_PIXEL_FORMAT", "RGB")
CLIENT_KEYS_STRS = get_license_keys(basefilename="nvfbc")


ctypedef unsigned long DWORD
Expand Down Expand Up @@ -454,14 +456,30 @@ def create_context(int width=-1, int height=-1, interface_type=NVFBC_TO_SYS):
log("create_context(%i, %i)", width, height)
check_status()
cdef NvFBCCreateParams create
memset(&create, 0, sizeof(NvFBCCreateParams))
create.dwVersion = NVFBC_CREATE_PARAMS_VER
create.dwInterfaceType = interface_type
create.dwMaxDisplayWidth = width
create.dwMaxDisplayHeight = height
#create.pDevice = 0
create.dwInterfaceVersion = NVFBC_DLL_VERSION
cdef NVFBCRESULT res = NvFBC.NvFBC_CreateEx(cvp(<uintptr_t> &create))
cdef NVFBCRESULT res = <NVFBCRESULT> 0
cdef char* ckey
keys = CLIENT_KEYS_STRS or [None]
log("create_context() will try with keys: %s", csv(keys))
assert len(keys)>0
for key in keys:
memset(&create, 0, sizeof(NvFBCCreateParams))
create.dwVersion = NVFBC_CREATE_PARAMS_VER
create.dwInterfaceType = interface_type
create.dwMaxDisplayWidth = width
create.dwMaxDisplayHeight = height
#create.pDevice = 0
create.dwInterfaceVersion = NVFBC_DLL_VERSION
if key:
binkey = parse_nvfbc_hex_key(key)
ckey = binkey
params.pPrivateData = <void*> ckey
params.dwPrivateDataSize = len(ckey)
log("create_context() key data=%#x, size=%i", <uintptr_t> ckey, len(ckey))
res = NvFBC.NvFBC_CreateEx(cvp(<uintptr_t> &create))
log("create_context() NvFBC_CreateEx()=%i for key=%s", ret, key)
if ret==0:
#success!
break
log("NvFBC_CreateEx(%#x)=%i", <uintptr_t> &create, res)
raiseNvFBC(res, "NvFBC_CreateEx")
info = {
Expand Down

0 comments on commit c236471

Please sign in to comment.