Debian Codegraph @

src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp

raw symbols SCIP
1 // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.cpp`/
2
3 #include "gui/mediaplayer/libmpv/libmpvwidget.h"cxx . . $ `<file>/src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h`/
4
5 #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/
6
7 #include <mpv/client.h>
8
9 #if defined(MEDIAPLAYER_LIBMPV_OPENGLcxx . . $ `<built-in>:499:9`!)
10 #include <QOpenGLContext>
11 #endif
12
13 static void wakeupcxx . . $ wakeup(5d22bdacc48458e8).(void* ctx) {
14 // This callback is invoked from any mpv thread (but possibly also
15 // recursively from a thread that is calling the mpv API). Just notify
16 // the Qt GUI thread to wake up (so that it can process events with
17 // mpv_wait_event()), and return as quickly as possible.
18 LibMpvWidgetcxx . . $ LibMpvWidget#* backend = (LibMpvWidgetcxx . . $ LibMpvWidget#*)ctx;
19 emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! backend->launchMpvEventscxx . . $ LibMpvWidget#launchMpvEvents(49f6e7a06ebc5aa8).();
20 }
21
22 LibMpvWidgetcxx . . $ LibMpvWidget#::LibMpvWidgetcxx . . $ LibMpvWidget#LibMpvWidget(ebd8094c89bd912f).(mpv_handle* mpv_handle, QWidgetcxx . . $ QWidget#* parent)
23 : BASE_WIDGETcxx . . $ `src/librssguard/gui/mediaplayer/libmpv/libmpvwidget.h:11:9`!(parent), m_mpvHandlecxx . . $ LibMpvWidget#m_mpvHandle.(mpv_handle)
24 #if defined(MEDIAPLAYER_LIBMPV_OPENGLcxx . . $ `<built-in>:499:9`!)
25 ,
26 m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL.(nullptr)
27 #endif
28 {
29 #if !defined(MEDIAPLAYER_LIBMPV_OPENGLcxx . . $ `<built-in>:499:9`!)
30 setAttribute(Qt::WidgetAttribute::WA_DontCreateNativeAncestors);
31 setAttribute(Qt::WidgetAttribute::WA_NativeWindow);
32 #endif
33
34 setMouseTrackingcxx . . $ QWidget#setMouseTracking(b45ddcbc8423892c).(true);
35 }
36
37 LibMpvWidgetcxx . . $ LibMpvWidget#::~cxx . . $ LibMpvWidget#`~LibMpvWidget`(ced63f7c635d850d).LibMpvWidgetcxx . . $ LibMpvWidget#() {
38 destroyHandlecxx . . $ LibMpvWidget#destroyHandle(49f6e7a06ebc5aa8).();
39 }
40
41 void LibMpvWidgetcxx . . $ LibMpvWidget#::bindcxx . . $ LibMpvWidget#bind(49f6e7a06ebc5aa8).() {
42 #if !defined(MEDIAPLAYER_LIBMPV_OPENGLcxx . . $ `<built-in>:499:9`!)
43 auto raw_wid = winId();
44
45 #if defined(Q_OS_WIN)
46 // Truncate to 32-bit, as all Windows handles are. This also ensures
47 // it doesn't go negative.
48 int64_t wid = static_cast<uint32_t>(raw_wid);
49 #else
50 int64_t wid = raw_wid;
51 #endif
52
53 mpv_set_option(m_mpvHandle, "wid", MPV_FORMAT_INT64, &wid);
54 #endif
55
56 mpv_set_wakeup_callback(m_mpvHandlecxx . . $ LibMpvWidget#m_mpvHandle., wakeupcxx . . $ wakeup(5d22bdacc48458e8)., this);
57 }
58
59 void LibMpvWidgetcxx . . $ LibMpvWidget#::destroyHandlecxx . . $ LibMpvWidget#destroyHandle(49f6e7a06ebc5aa8).() {
60 #if defined(MEDIAPLAYER_LIBMPV_OPENGLcxx . . $ `<built-in>:499:9`!)
61 makeCurrentcxx . . $ QOpenGLWidget#makeCurrent(49f6e7a06ebc5aa8).();
62
63 if (m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL. != nullptr) {
64 mpv_render_context_free(m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL.);
65 m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL. = nullptr;
66 }
67
68 doneCurrentcxx . . $ QOpenGLWidget#doneCurrent(49f6e7a06ebc5aa8).();
69 #endif
70 }
71
72 #if defined(MEDIAPLAYER_LIBMPV_OPENGLcxx . . $ `<built-in>:499:9`!)
73 static void* get_proc_addresscxx . . $ get_proc_address(5c3a2d84d269ab4b).(void* ctx, const char* name) {
74 Q_UNUSEDcxx . . $ `<external>/17563275351362271547/qtpreprocessorsupport.h:20:9`!(ctx);
75
76 QOpenGLContextcxx . . $ QOpenGLContext#* glctx = QOpenGLContextcxx . . $ QOpenGLContext#::currentContextcxx . . $ QOpenGLContext#currentContext(d0ebf64f67a4b129).();
77
78 if (!glctx) {
79 return nullptr;
80 }
81
82 return reinterpret_cast<void*>(glctx->getProcAddresscxx . . $ QOpenGLContext#getProcAddress(2cbc358c843e995a).(QByteArraycxx . . $ QByteArray#QByteArray(de40a1f2d6082f12).(name)));
83 }
84
85 void LibMpvWidgetcxx . . $ LibMpvWidget#::maybeUpdatecxx . . $ LibMpvWidget#maybeUpdate(49f6e7a06ebc5aa8).() {
86 // If the Qt window is not visible, Qt's update() will just skip rendering.
87 // This confuses mpv's render API, and may lead to small occasional
88 // freezes due to video rendering timing out.
89 // Handle this by manually redrawing.
90 // Note: Qt doesn't seem to provide a way to query whether update() will
91 // be skipped, and the following code still fails when e.g. switching
92 // to a different workspace with a reparenting window manager.
93 if (windowcxx . . $ QWidget#window(27f420ad5cce8994).()->isMinimizedcxx . . $ QWidget#isMinimized(50ce9a9e25b4a850).()) {
94 makeCurrentcxx . . $ QOpenGLWidget#makeCurrent(49f6e7a06ebc5aa8).();
95 paintGLcxx . . $ LibMpvWidget#paintGL(49f6e7a06ebc5aa8).();
96 contextcxx . . $ QOpenGLWidget#context(8349f23b343e5bdc).()->swapBufferscxx . . $ QOpenGLContext#swapBuffers(e268930952e36cfa).(contextcxx . . $ QOpenGLWidget#context(8349f23b343e5bdc).()->surfacecxx . . $ QOpenGLContext#surface(3456c683ae282fa1).());
97 doneCurrentcxx . . $ QOpenGLWidget#doneCurrent(49f6e7a06ebc5aa8).();
98 }
99 else {
100 updatecxx . . $ QWidget#update(49f6e7a06ebc5aa8).();
101 }
102 }
103
104 void LibMpvWidgetcxx . . $ LibMpvWidget#::onMpvRedrawcxx . . $ LibMpvWidget#onMpvRedraw(5d22bdacc48458e8).(void* ctx) {
105 QMetaObjectcxx . . $ QMetaObject#::invokeMethodcxx . . $ QMetaObject#invokeMethod(bb73ac13b4485c8).((LibMpvWidgetcxx . . $ LibMpvWidget#*)ctx, &LibMpvWidgetcxx . . $ LibMpvWidget#::maybeUpdatecxx . . $ LibMpvWidget#maybeUpdate(49f6e7a06ebc5aa8)., Qtcxx . . $ Qt/::ConnectionTypecxx . . $ Qt/ConnectionType#::QueuedConnectioncxx . . $ Qt/QueuedConnection.);
106 }
107
108 void LibMpvWidgetcxx . . $ LibMpvWidget#::initializeGLcxx . . $ LibMpvWidget#initializeGL(49f6e7a06ebc5aa8).() {
109 mpv_opengl_init_params gl_init_params[1] = {get_proc_addresscxx . . $ get_proc_address(5c3a2d84d269ab4b)., nullptr};
110 mpv_render_param display{MPV_RENDER_PARAM_INVALID, nullptr};
111
112 #if QT_VERSION_MAJORcxx . . $ `<external>/9758848313111604122/qconfig.h:67:9`! == 6 && defined(Q_OS_UNIXcxx . . $ `/usr/include/x86_64-linux-gnu/qt6/QtCore/qsystemdetection.h:149:11`!) && !defined(Q_OS_DARWIN) && !defined(Q_OS_ANDROID)
113 #if defined(QT_FEATURE_xcbcxx . . $ `<external>/15443749595277072804/qtgui-config.h:38:9`!) && QT_CONFIGcxx . . $ `<external>/7770798561591309169/qtconfigmacros.h:67:9`!(xcb)
114 if (QGuiApplicationcxx . . $ QGuiApplication#::platformNamecxx . . $ QGuiApplication#platformName(4365c3963150523e).() ==cxx . . $ `operator==`(5bc2975d2d751687). QStringLiteralcxx . . $ `<external>/13954984326995544643/qstring.h:1789:9`!("xcb")) {
115 display.type = MPV_RENDER_PARAM_X11_DISPLAY;
116 display.data = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nativeInterfacecxx . . $ QApplication#nativeInterface(5a2a78a048fb49a8).<QNativeInterfacecxx . . $ QNativeInterface/::QX11Applicationcxx . . $ QNativeInterface/QX11Application#>()->displaycxx . . $ QNativeInterface/QX11Application#display(972173443a6a9a20).();
117 }
118 #endif
119
120 #if defined(QT_FEATURE_waylandcxx . . $ `<external>/15443749595277072804/qtgui-config.h:116:9`!) && QT_CONFIGcxx . . $ `<external>/7770798561591309169/qtconfigmacros.h:67:9`!(wayland)
121 if (qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->isWaylandcxx . . $ Application#isWayland(50ce9a9e25b4a850).()) {
122 display.type = MPV_RENDER_PARAM_WL_DISPLAY;
123 display.data = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->nativeInterfacecxx . . $ QApplication#nativeInterface(5a2a78a048fb49a8).<QNativeInterfacecxx . . $ QNativeInterface/::QWaylandApplicationcxx . . $ QNativeInterface/QWaylandApplication#>()->displaycxx . . $ QNativeInterface/QWaylandApplication#display(e71757d2d8c5058c).();
124 }
125 #endif
126 #endif
127
128 mpv_render_param params[]{{MPV_RENDER_PARAM_API_TYPE, const_cast<char*>(MPV_RENDER_API_TYPE_OPENGLcxx . . $ `<external>/17719909096319130067/render.h:468:9`!)},
129 {MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params},
130 display,
131 {MPV_RENDER_PARAM_INVALID, nullptr}};
132
133 if (mpv_render_context_create(&m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL., m_mpvHandlecxx . . $ LibMpvWidget#m_mpvHandle., params) < 0) {
134 qFatalcxx . . $ `<external>/7280663963939302026/qlogging.h:172:9`!("failed to initialize mpv GL context");
135 }
136
137 mpv_render_context_set_update_callback(m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL., LibMpvWidgetcxx . . $ LibMpvWidget#::onMpvRedrawcxx . . $ LibMpvWidget#onMpvRedraw(5d22bdacc48458e8)., reinterpret_cast<void*>(this));
138 }
139
140 void LibMpvWidgetcxx . . $ LibMpvWidget#::paintGLcxx . . $ LibMpvWidget#paintGL(49f6e7a06ebc5aa8).() {
141 qrealcxx . . $ qreal# scaling_ratio = windowcxx . . $ QWidget#window(27f420ad5cce8994).()->devicePixelRatiocxx . . $ QPaintDevice#devicePixelRatio(21b6c25e127938e2).();
142 mpv_opengl_fbo mpfbo{static_cast<int>(defaultFramebufferObjectcxx . . $ QOpenGLWidget#defaultFramebufferObject(ddd8539a2fcdd4ce).()),
143 int(widthcxx . . $ QWidget#width(455f465bc33b4cdf).() * scaling_ratio),
144 int(heightcxx . . $ QWidget#height(455f465bc33b4cdf).() * scaling_ratio),
145 0};
146 int flip_y{1};
147
148 mpv_render_param params[] = {{MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo},
149 {MPV_RENDER_PARAM_FLIP_Y, &flip_y},
150 {MPV_RENDER_PARAM_INVALID, nullptr}};
151
152 mpv_render_context_render(m_mpvGLcxx . . $ LibMpvWidget#m_mpvGL., params);
153 }
154 #endif