Skip to content

Commit

Permalink
#3390 add drm query tool
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Sep 12, 2022
1 parent 4736acc commit 5eca552
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ tests/unittests/test-file*
/xpra/codecs/nvjpeg/decoder.c
/xpra/codecs/nvjpeg/common.c
/xpra/codecs/evdi/capture.cpp
/xpra/codecs/evdi/drm.c
/xpra/gtk_common/gdk_atoms.c
/xpra/gtk_common/gtk3/gdk_atoms.c
/xpra/gtk_common/gtk3/gdk_bindings.c
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def has_header_file(name, isdir=False):
notifications_ENABLED = DEFAULT
keyboard_ENABLED = DEFAULT
v4l2_ENABLED = DEFAULT and (not WIN32 and not OSX and not FREEBSD and not OPENBSD)
evdi_ENABLED = DEFAULT and POSIX and pkg_config_version("1.10", "evdi")
evdi_ENABLED = DEFAULT and LINUX and pkg_config_version("1.12", "evdi")
evdi_drm_ENABLED = DEFAULT and LINUX and pkg_config_version("2.4", "drm")
#ffmpeg 3.1 or later is required
dec_avcodec2_ENABLED = DEFAULT and BITS==64 and pkg_config_version("57", "libavcodec")
csc_swscale_ENABLED = DEFAULT and BITS==64 and pkg_config_ok("--exists", "libswscale")
Expand Down Expand Up @@ -248,7 +249,7 @@ def has_header_file(name, isdir=False):
"spng_decoder", "spng_encoder",
"jpeg_encoder", "jpeg_decoder",
"nvjpeg", "avif", "argb",
"v4l2", "evdi",
"v4l2", "evdi", "evdi_drm",
"dec_avcodec2", "csc_swscale",
"csc_cython", "csc_libyuv",
]
Expand Down Expand Up @@ -1053,6 +1054,7 @@ def clean():
"xpra/codecs/v4l2/pusher.c",
"xpra/codecs/v4l2/constants.pxi",
"xpra/codecs/evdi/capture.cpp",
"xpra/codecs/evdi/drm.c",
"xpra/codecs/libav_common/av_log.c",
"xpra/codecs/webp/encoder.c",
"xpra/codecs/webp/decoder.c",
Expand Down Expand Up @@ -2177,6 +2179,7 @@ def nvcc_compile(cmd):
tace(argb_ENABLED, "xpra.codecs.argb.argb", optimize=3)
toggle_packages(evdi_ENABLED, "xpra.codecs.evdi")
tace(evdi_ENABLED, "xpra.codecs.evdi.capture", "evdi", language="c++")
tace(evdi_drm_ENABLED, "xpra.codecs.evdi.drm", "libdrm")
toggle_packages(enc_x264_ENABLED, "xpra.codecs.enc_x264")
tace(enc_x264_ENABLED, "xpra.codecs.enc_x264.encoder", "x264")
toggle_packages(enc_x265_ENABLED, "xpra.codecs.enc_x265")
Expand Down
96 changes: 96 additions & 0 deletions xpra/codecs/evdi/drm.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This file is part of Xpra.
# Copyright (C) 2022 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

#cython: wraparound=False

from xpra.os_util import bytestostr

from xpra.log import Logger
log = Logger("encoder", "evdi")

cdef extern from "drm/drm.h":
ctypedef unsigned int __kernel_size_t
ctypedef struct drm_version:
int version_major
int version_minor
int version_patchlevel
__kernel_size_t name_len
char *name
__kernel_size_t date_len
char *date
__kernel_size_t desc_len
char *desc
ctypedef drm_version* drmVersionPtr

cdef extern from "xf86drm.h":
int DRM_NODE_PRIMARY
ctypedef struct drmDevice:
char **nodes #DRM_NODE_MAX sized array
int available_nodes #DRM_NODE_* bitmask
int bustype
#union {
#drmPciBusInfoPtr pci
#drmUsbBusInfoPtr usb
#drmPlatformBusInfoPtr platform
#drmHost1xBusInfoPtr host1x
#} businfo;
#union {
#drmPciDeviceInfoPtr pci
#drmUsbDeviceInfoPtr usb
#drmPlatformDeviceInfoPtr platform
#drmHost1xDeviceInfoPtr host1x
#} deviceinfo;
ctypedef drmDevice* drmDevicePtr

drmVersionPtr drmGetVersion(int fd)
void drmFreeVersion(drmVersionPtr ver)

int drmGetDevices(drmDevicePtr devices[], int max_devices)
void drmFreeDevices(drmDevicePtr devices[], int count)

cdef extern from "xf86drmMode.h":
#drmModeResPtr drmModeGetResources(int fd)
int drmIsKMS(int fd)

def query():
info = {}
cdef int count = drmGetDevices(NULL, 16)
if count<0:
log.error(f"Error querying drm devices: {count}")
return info
if count==0:
log.warn("Warning: no drm devices found")
return info
cdef drmDevicePtr[16] devices
count = drmGetDevices(devices, 16)
assert 0<count<16
log(f"{count} drm devices found")
cdef char *path
cdef int fd
cdef drmVersionPtr version
for i in range(count):
if not devices[i].available_nodes & (1 << DRM_NODE_PRIMARY):
log(f"{i} is not primary")
continue
dev_info = info.setdefault(i, {})
path = devices[i].nodes[DRM_NODE_PRIMARY]
log(f"{i} at {path}")
dev_info["path"] = bytestostr(path)
with open(path, "rb") as drm_device:
fd = drm_device.fileno()
kms = bool(drmIsKMS(fd))
dev_info["kms"] = kms
version = drmGetVersion(fd)
if version:
dev_info.update({
"version" : (version.version_major, version.version_minor, version.version_patchlevel),
"name" : bytestostr(version.name[:version.name_len]),
"date" : bytestostr(version.date[:version.date_len]),
"desc" : bytestostr(version.desc[:version.desc_len]),
})
drmFreeVersion(version)
#drmModeGetResources
drmFreeDevices(devices, count)
return info

0 comments on commit 5eca552

Please sign in to comment.