fix: wrap get_proc_address as CFUNCTYPE for mpv render context

This commit is contained in:
2026-04-06 20:50:02 +02:00
parent 1e0c1ae892
commit e5f2c732d9
+20 -10
View File
@@ -442,17 +442,23 @@ class TimelineWidget(QWidget):
self._seek_timer.start() # debounce the mpv seek self._seek_timer.start() # debounce the mpv seek
def _mpv_get_proc_address(_, name):
"""Resolve OpenGL/EGL function pointers for mpv's render context."""
import ctypes, ctypes.util import ctypes, ctypes.util
def _make_get_proc_address():
"""Return a ctypes C-callable for mpv's OpenGL get_proc_address."""
_libs = []
for lib_name in ("EGL", "GL"): for lib_name in ("EGL", "GL"):
lib_path = ctypes.util.find_library(lib_name) path = ctypes.util.find_library(lib_name)
if not lib_path: if path:
continue
try: try:
lib = ctypes.CDLL(lib_path) _libs.append(ctypes.CDLL(path))
for fn_name in ("eglGetProcAddress", "glXGetProcAddressARB", "glXGetProcAddress"): except Exception:
fn = getattr(lib, fn_name, None) pass
def _lookup(_, name):
for lib in _libs:
for fn_name in (b"eglGetProcAddress", b"glXGetProcAddressARB", b"glXGetProcAddress"):
fn = getattr(lib, fn_name.decode(), None)
if fn is None: if fn is None:
continue continue
fn.restype = ctypes.c_void_p fn.restype = ctypes.c_void_p
@@ -460,10 +466,14 @@ def _mpv_get_proc_address(_, name):
addr = fn(name) addr = fn(name)
if addr: if addr:
return addr return addr
except Exception:
continue
return None return None
# mpv requires a real C function pointer, not a Python callable.
_PROC_ADDR_TYPE = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_char_p)
return _PROC_ADDR_TYPE(_lookup)
_mpv_get_proc_address = _make_get_proc_address()
class MpvWidget(QOpenGLWidget): class MpvWidget(QOpenGLWidget):
file_loaded = pyqtSignal() # emitted (on Qt thread) when a file is ready file_loaded = pyqtSignal() # emitted (on Qt thread) when a file is ready