QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GStreamerEnvironment.cc
Go to the documentation of this file.
2
3#include <QtCore/QCoreApplication>
4#include <QtCore/QCryptographicHash>
5#include <QtCore/QDateTime>
6#include <QtCore/QDir>
7#include <QtCore/QFile>
8#include <QtCore/QFileInfo>
9#include <QtCore/QHash>
10#include <QtCore/QRegularExpression>
11#include <QtCore/QSaveFile>
12#include <QtCore/QStandardPaths>
13#include <QtCore/QStringList>
14#include <QtCore/QSysInfo>
15#include <QtCore/QThread>
16
17#include "QGCLoggingCategory.h"
18
19#ifdef Q_OS_ANDROID
20#include <android/asset_manager.h>
21#include <android/asset_manager_jni.h>
22
23#include <QtCore/QJniEnvironment>
24#include <QtCore/QJniObject>
25#endif
26
27#include <gst/gst.h>
28
29#ifdef Q_OS_WIN
30#include <cstdlib>
31#endif
32
33QGC_LOGGING_CATEGORY(GStreamerEnvLog, "Video.GStreamer.Environment")
34
35namespace {
36
40
41// Single source of truth for the managed plugin-path/scanner vars: keeps _clearManagedGstEnvVars
42// and logDiagnostics from drifting. Each site layers its own extras (GIO/PTP, registry) on top.
43constexpr const char* kManagedGstPathVars[] = {
44 "GST_PLUGIN_PATH", "GST_PLUGIN_PATH_1_0", "GST_PLUGIN_SYSTEM_PATH", "GST_PLUGIN_SYSTEM_PATH_1_0",
45 "GST_PLUGIN_SCANNER", "GST_PLUGIN_SCANNER_1_0",
46};
47
48BundledRuntime s_bundledRuntime;
49
50// What this layer last set each variable to, so that preparing the environment again doesn't take its own values for
51// the user's.
52QHash<QByteArray, QString> s_managedEnvValues;
53
54QString _cleanJoin(const QString& base, const QString& relative)
55{
56 return QDir::cleanPath(QDir(base).filePath(relative));
57}
58
59QStringList _cleanJoinAll(const QStringList& bases, const QString& relative)
60{
61 QStringList joined;
62 joined.reserve(bases.size());
63 for (const QString& base : bases) {
64 joined.append(_cleanJoin(base, relative));
65 }
66 return joined;
67}
68
69void _setGstEnv(const char* name, const QString& value)
70{
71#ifdef Q_OS_WIN
72 // GLib reads the wide environment; qputenv's _putenv_s would decode these UTF-8 bytes in the ANSI
73 // code page and corrupt non-ASCII install paths. g_setenv sets the process environment and GLib's C runtime copy;
74 // _wputenv_s sets QGC's, which qEnvironmentVariable reads and which is a separate (debug) runtime in Debug builds.
75 (void) g_setenv(name, value.toUtf8().constData(), TRUE);
76 (void) _wputenv_s(QString::fromLatin1(name).toStdWString().c_str(), value.toStdWString().c_str());
77#else
78 qputenv(name, value.toUtf8());
79#endif
80 s_managedEnvValues.insert(name, value);
81 qCDebug(GStreamerEnvLog) << " " << name << "=" << value;
82}
83
84bool _setByUser(const char* name)
85{
86 if (!qEnvironmentVariableIsSet(name)) {
87 return false;
88 }
89 const auto managed = s_managedEnvValues.constFind(name);
90 return (managed == s_managedEnvValues.constEnd()) || (qEnvironmentVariable(name) != managed.value());
91}
92
93QString _firstExistingPath(const QStringList& paths)
94{
95 for (const QString& path : paths) {
96 if (QFileInfo::exists(path)) {
97 return path;
98 }
99 }
100
101 return {};
102}
103
104// An AppImage is mounted, and a quarantined macOS app translocated, to a new random directory on every launch: name
105// such an install after what stays put, the AppImage file or the translocated app's name.
106QString _stableInstallPath(const QString& installPath)
107{
108 // Whatever an AppImage starts inherits APPIMAGE and APPDIR, so they only name an install inside the mount.
109 QString appImage = qEnvironmentVariable("APPIMAGE");
110 const QString mountDir = qEnvironmentVariable("APPDIR");
111 if (!appImage.isEmpty() && !mountDir.isEmpty() &&
112 installPath.startsWith(QDir::cleanPath(mountDir) + QLatin1Char('/'))) {
113 return appImage;
114 }
115
116 static const QRegularExpression translocation(QStringLiteral("/AppTranslocation/[^/]+/"));
117 return QString(installPath).replace(translocation, QStringLiteral("/AppTranslocation/"));
118}
119
120// GStreamer only rewrites a registry when the plugins change, so touch @p registry to mark it in use, and remove the
121// registries next to it that no install has used for a month (an old GStreamer version, a replaced AppImage). Removing
122// one that is still in use only costs its install a rescan.
123void _pruneUnusedRegistries(const QString& registry)
124{
125 static constexpr int kUnusedRegistryDays = 30;
126
127 const QDateTime now = QDateTime::currentDateTimeUtc();
128 QFile current(registry);
129 if (current.open(QIODevice::ReadWrite | QIODevice::ExistingOnly)) {
130 (void) current.setFileTime(now, QFileDevice::FileModificationTime);
131 current.close();
132 }
133
134 const QFileInfo registryInfo(registry);
135 const QDateTime cutoff = now.addDays(-kUnusedRegistryDays);
136 const QFileInfoList registries =
137 registryInfo.absoluteDir().entryInfoList({QStringLiteral("gstreamer-*.bin")}, QDir::Files);
138 for (const QFileInfo& other : registries) {
139 if ((other.fileName() != registryInfo.fileName()) && (other.lastModified() < cutoff) &&
140 QFile::remove(other.absoluteFilePath())) {
141 qCDebug(GStreamerEnvLog) << "Removed unused GStreamer registry" << other.absoluteFilePath();
142 }
143 }
144}
145
146#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
147void _setTmpDirVars(const QString& dir)
148{
149 _setGstEnv("TMP", dir);
150 _setGstEnv("TEMP", dir);
151 _setGstEnv("TMPDIR", dir);
152}
153
154// Points CA_CERTIFICATES, which the static plugin init makes GIO's default TLS database (gst_static_plugins.c.in), at
155// the bundled @p caBundle unless it is set.
156void _setCaBundleIfUnset(const QString& caBundle)
157{
158 if (qEnvironmentVariableIsEmpty("CA_CERTIFICATES") && QFileInfo::exists(caBundle)) {
159 _setGstEnv("CA_CERTIFICATES", caBundle);
160 }
161}
162#endif
163
164#ifdef Q_OS_ANDROID
165// Extracts an APK asset to destPath, which outlives the APK: an updated app replaces what an earlier version left.
166bool _extractApkAsset(const char* assetPath, const QString& destPath)
167{
168 QJniObject ctx = QNativeInterface::QAndroidApplication::context();
169 if (!ctx.isValid()) {
170 qCWarning(GStreamerEnvLog) << "Cannot resolve Android Context for asset extraction";
171 return false;
172 }
173
174 QJniObject jAssetMgr = ctx.callObjectMethod("getAssets", "()Landroid/content/res/AssetManager;");
175 if (!jAssetMgr.isValid()) {
176 qCWarning(GStreamerEnvLog) << "Context.getAssets() returned null";
177 return false;
178 }
179
180 QJniEnvironment env;
181 AAssetManager* am = AAssetManager_fromJava(env.jniEnv(), jAssetMgr.object());
182 if (!am) {
183 qCWarning(GStreamerEnvLog) << "AAssetManager_fromJava failed";
184 return false;
185 }
186
187 AAsset* asset = AAssetManager_open(am, assetPath, AASSET_MODE_BUFFER);
188 if (!asset) {
189 qCDebug(GStreamerEnvLog) << "APK asset not present:" << assetPath;
190 return false;
191 }
192 const off_t assetLen = AAsset_getLength(asset);
193 const void* const buf = AAsset_getBuffer(asset);
194 const bool ok = buf && (assetLen > 0) &&
196 destPath, QByteArrayView(static_cast<const char*>(buf), static_cast<qsizetype>(assetLen)));
197 AAsset_close(asset);
198 if (!ok) {
199 qCWarning(GStreamerEnvLog) << "Failed writing asset" << assetPath << "to" << destPath;
200 }
201 return ok;
202}
203#endif
204
205// QGC_GST_SYSTEM_PLUGINS: a Linux build with QGC_GST_BUNDLE_PLUGINS=OFF, packaged with the system's plugins, which it
206// always uses as they are.
207#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS) && !defined(QGC_GST_SYSTEM_PLUGINS)
208
209void _unsetEnv(const char* name)
210{
211 if (qEnvironmentVariableIsSet(name)) {
212 qunsetenv(name);
213 qCDebug(GStreamerEnvLog) << " unset" << name;
214 }
215}
216
217bool _isExecutableFile(const QString& path)
218{
219 const QFileInfo fileInfo(path);
220 return fileInfo.exists() && fileInfo.isFile() && fileInfo.isExecutable();
221}
222
223QString _joinExistingPaths(const QStringList& paths)
224{
225 QStringList existing;
226 existing.reserve(paths.size());
227
228 for (const QString& path : paths) {
229 if (QFileInfo::exists(path) && !existing.contains(path)) {
230 existing.append(path);
231 }
232 }
233
234 return existing.join(QDir::listSeparator());
235}
236
237void _clearManagedGstEnvVars()
238{
239 static constexpr const char* gioPtpVars[] = {
240 "GIO_EXTRA_MODULES", "GIO_MODULE_DIR", "GIO_USE_VFS", "GST_PTP_HELPER_1_0", "GST_PTP_HELPER",
241 };
242
243 for (const char* name : gioPtpVars) {
244 _unsetEnv(name);
245 }
246 for (const char* name : kManagedGstPathVars) {
247 _unsetEnv(name);
248 }
249}
250
251void _setGstEnvIfExecutable(const char* name, const QString& path)
252{
253 if (_isExecutableFile(path)) {
254 _setGstEnv(name, path);
255 }
256}
257
258void _applyGstEnvVars(const QString& pluginDir, const QString& gioModDir, const QString& scannerPath,
259 const QString& ptpPath)
260{
261 qCDebug(GStreamerEnvLog) << "Applying GStreamer environment:";
262
263 _clearManagedGstEnvVars();
264 if (!gioModDir.isEmpty()) {
265 _setGstEnv("GIO_EXTRA_MODULES", gioModDir);
266 }
267 _setGstEnvIfExecutable("GST_PTP_HELPER_1_0", ptpPath);
268 _setGstEnvIfExecutable("GST_PTP_HELPER", ptpPath);
269 _setGstEnvIfExecutable("GST_PLUGIN_SCANNER_1_0", scannerPath);
270 _setGstEnvIfExecutable("GST_PLUGIN_SCANNER", scannerPath);
271 // SYSTEM_PATH replaces the default system/user plugin dirs. GST_PLUGIN_PATH (cleared above) would
272 // only rescan the same dir, so leaving it unset loads the identical plugin set.
273 _setGstEnv("GST_PLUGIN_SYSTEM_PATH_1_0", pluginDir);
274 _setGstEnv("GST_PLUGIN_SYSTEM_PATH", pluginDir);
275}
276
277#if defined(Q_OS_LINUX)
278void _applyGioCompatOverride(const QString& gioModDir)
279{
280 if (gioModDir.isEmpty()) {
281 return;
282 }
283
284 // GIO 2.76+ needs bundled modules via GIO_MODULE_DIR with VFS forced local (AppImage launcher logic).
285 // The in-process GLib (the bundled one when present) is the GIO that loads these modules.
286 if (glib_check_version(2, 76, 0) == nullptr) {
287 _unsetEnv("GIO_EXTRA_MODULES");
288 _setGstEnv("GIO_MODULE_DIR", gioModDir);
289 _setGstEnv("GIO_USE_VFS", QStringLiteral("local"));
290 }
291}
292#endif
293
294void _warnIfScannerMissing(const QString& platformLabel, const QString& scannerPath)
295{
296 if (scannerPath.isEmpty()) {
297 qCWarning(GStreamerEnvLog) << "GStreamer:" << platformLabel
298 << "bundled gst-plugin-scanner not found; GStreamer will use in-process scanning";
299 } else if (!_isExecutableFile(scannerPath)) {
300 qCWarning(GStreamerEnvLog) << "GStreamer:" << platformLabel
301 << "gst-plugin-scanner is not executable:" << scannerPath;
302 }
303}
304
305// Points GStreamer at the bundled runtime. Returns false, leaving the environment untouched, when no
306// bundled plugin directory exists (system GStreamer is used as-is).
307bool _applyBundleLayout(const QString& platformLabel, const BundleLayout& layout)
308{
309 const QString pluginDirs = _joinExistingPaths(layout.pluginDirs);
310 if (pluginDirs.isEmpty()) {
311 return false;
312 }
313
314 const QString scanner = _firstExistingPath(layout.scannerCandidates);
315 _warnIfScannerMissing(platformLabel, scanner);
316 const QString gioModuleDir = _firstExistingPath(layout.gioModuleDirs);
317 _applyGstEnvVars(pluginDirs, gioModuleDir, scanner, _firstExistingPath(layout.ptpCandidates));
318 (void) GStreamer::Environment::usePrivateRegistry(QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
319 pluginDirs);
320 s_bundledRuntime = {.pluginDirs = pluginDirs.split(QDir::listSeparator()), .gioModuleDir = gioModuleDir};
321 return true;
322}
323
324#endif // !Q_OS_ANDROID && !Q_OS_IOS && !QGC_GST_SYSTEM_PLUGINS
325
326VideoBackend::EnvPrepResult _setGstEnvVars(const QString& appDir)
327{
329 s_bundledRuntime = {};
330
331 qCDebug(GStreamerEnvLog) << "App directory:" << appDir;
332
333#if defined(Q_OS_MACOS)
334 const QString frameworkDir = _cleanJoin(appDir, "../Frameworks/GStreamer.framework");
335#if defined(QGC_GST_MACOS_FRAMEWORK)
336 const BundleLayout layout = GStreamer::Environment::bundleLayout(DesktopInstall::MacOSFramework, appDir);
337#else
338 const BundleLayout layout = GStreamer::Environment::bundleLayout(DesktopInstall::MacOSFlat, appDir);
339#endif
340 const bool hasBundledFramework = QFileInfo::exists(frameworkDir);
341
342 if (!_applyBundleLayout(QStringLiteral("macOS"), layout) && hasBundledFramework) {
343 result.ok = false;
344 result.error =
345 QStringLiteral("GStreamer: bundled macOS framework found but plugin directory is missing under %1")
346 .arg(frameworkDir);
347 qCCritical(GStreamerEnvLog) << result.error;
348 }
349
350#elif defined(Q_OS_WIN)
351 if (_applyBundleLayout(QStringLiteral("Windows"),
352 GStreamer::Environment::bundleLayout(DesktopInstall::Windows, appDir))) {
353 // Put the app's bin dir on PATH so child processes (gst-plugin-scanner.exe) can locate
354 // GStreamer DLLs installed alongside the main executable.
355 const QString curPath = qEnvironmentVariable("PATH");
356 const QString binDir = QDir::toNativeSeparators(appDir);
357 // Windows paths are case-insensitive; compare accordingly to avoid duplicate prepends.
358 if (!curPath.split(QDir::listSeparator()).contains(binDir, Qt::CaseInsensitive)) {
359 _setGstEnv("PATH", binDir + QDir::listSeparator() + curPath);
360 }
361 }
362
363#elif defined(Q_OS_IOS)
364 // Static plugins — no GST_PLUGIN_PATH; bundle resources read-only, scratch in sandbox. CA
365 // bundle (MACOSX_PACKAGE_LOCATION) is consumed by qgc_load_gio_modules_and_ca() at static init.
366 {
367 const QString resources = appDir;
368 const QString docs = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
369 const QString cache = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
370 const QString tmp = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
371
372 if (!tmp.isEmpty()) {
373 _setTmpDirVars(tmp);
374 }
375 if (!cache.isEmpty()) {
376 _setGstEnv("XDG_CACHE_HOME", cache);
377 _setGstEnv("XDG_CONFIG_HOME", cache);
378 _setGstEnv("GST_REGISTRY", _cleanJoin(cache, "registry.bin"));
379 }
380 // The sandbox forbids fork(), and the plugins are static, so there is no scanner to run.
381 _setGstEnv("GST_REGISTRY_FORK", QStringLiteral("no"));
382 // Tutorial 5 binds XDG_RUNTIME_DIR to the read-only bundle; libGStreamer never writes there on iOS.
383 if (!resources.isEmpty()) {
384 _setGstEnv("XDG_RUNTIME_DIR", resources);
385 _setGstEnv("XDG_DATA_DIRS", resources);
386 _setGstEnv("XDG_CONFIG_DIRS", resources);
387 _setGstEnv("XDG_DATA_HOME", resources);
388 }
389 if (!docs.isEmpty()) {
390 _setGstEnv("HOME", docs);
391 }
392
393 if (!resources.isEmpty()) {
394 _setCaBundleIfUnset(_cleanJoin(resources, "ssl/certs/ca-certificates.crt"));
395 }
396 }
397
398#elif defined(Q_OS_ANDROID)
399 // Static plugins — no GST_PLUGIN_PATH; APK assets are read-only, so the CA bundle is extracted
400 // to filesDir, and again when an update changes it (we run gst_init from C++, not Java's GStreamer.init).
401 {
402 const QString filesDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
403 const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
404
405 if (!filesDir.isEmpty()) {
406 _setGstEnv("HOME", filesDir);
407 _setGstEnv("FONTCONFIG_PATH", _cleanJoin(filesDir, "fontconfig"));
408 const QString caBundle = _cleanJoin(filesDir, "ssl/certs/ca-certificates.crt");
409 if (_extractApkAsset("ssl/certs/ca-certificates.crt", caBundle)) {
410 _setCaBundleIfUnset(caBundle);
411 }
412 _setGstEnv("XDG_DATA_DIRS", filesDir);
413 _setGstEnv("XDG_CONFIG_DIRS", filesDir);
414 _setGstEnv("XDG_CONFIG_HOME", filesDir);
415 _setGstEnv("XDG_DATA_HOME", filesDir);
416 }
417
418 if (!cacheDir.isEmpty()) {
419 _setTmpDirVars(cacheDir);
420 _setGstEnv("XDG_CACHE_HOME", cacheDir);
421 _setGstEnv("XDG_RUNTIME_DIR", cacheDir);
422 _setGstEnv("GST_REGISTRY", _cleanJoin(cacheDir, "registry.bin"));
423 }
424
425 // The plugins are static and the APK ships no scanner; an app process must not fork() into one.
426 _setGstEnv("GST_REGISTRY_FORK", QStringLiteral("no"));
427 }
428
429#elif defined(Q_OS_LINUX) && !defined(QGC_GST_SYSTEM_PLUGINS)
430 // An AppImage or other bundle ships its runtime under <prefix>/lib; a plugin path set by the user wins.
431 if (!_setByUser("GST_PLUGIN_PATH_1_0") && !_setByUser("GST_PLUGIN_PATH") &&
432 !_setByUser("GST_PLUGIN_SYSTEM_PATH_1_0") && !_setByUser("GST_PLUGIN_SYSTEM_PATH")) {
433 const BundleLayout layout = GStreamer::Environment::bundleLayout(DesktopInstall::Linux, appDir);
434 if (_applyBundleLayout(QStringLiteral("Linux"), layout)) {
435 _applyGioCompatOverride(s_bundledRuntime.gioModuleDir);
436 }
437 }
438#endif
439
440 return result;
441}
442
443} // anonymous namespace
444
446
447BundleLayout bundleLayout(DesktopInstall install, const QString& appDir)
448{
449 const QString appLib = _cleanJoin(appDir, "../lib");
450 QStringList libDirs{appLib};
451 QStringList helperDirs{_cleanJoin(appDir, "../libexec/gstreamer-1.0")};
452 QString exeSuffix;
453 switch (install) {
456 const QString frameworkDir = _cleanJoin(appDir, "../Frameworks/GStreamer.framework");
457 QString rootDir = _firstExistingPath({
458 _cleanJoin(frameworkDir, "Versions/1.0"),
459 _cleanJoin(frameworkDir, "Versions/Current"),
460 frameworkDir,
461 });
462 if (rootDir.isEmpty()) {
463 rootDir = _cleanJoin(frameworkDir, "Versions/1.0");
464 }
465 const QString frameworkLib = _cleanJoin(rootDir, "lib");
466 libDirs = (install == DesktopInstall::MacOSFramework) ? QStringList{frameworkLib, appLib}
467 : QStringList{appLib, frameworkLib};
468 helperDirs.append(_cleanJoin(rootDir, "libexec/gstreamer-1.0"));
469 break;
470 }
472 exeSuffix = QStringLiteral(".exe");
473 break;
475 helperDirs.prepend(_cleanJoin(appLib, "gstreamer1.0/gstreamer-1.0"));
476 break;
477 }
478 return {
479 .pluginDirs = _cleanJoinAll(libDirs, "gstreamer-1.0"),
480 .gioModuleDirs = _cleanJoinAll(libDirs, "gio/modules"),
481 .scannerCandidates = _cleanJoinAll(helperDirs, QStringLiteral("gst-plugin-scanner") + exeSuffix),
482 .ptpCandidates = _cleanJoinAll(helperDirs, QStringLiteral("gst-ptp-helper") + exeSuffix),
483 };
484}
485
487{
488 // qputenv is not thread-safe against concurrent getenv; this must run on the GUI thread before
489 // the QtConcurrent init worker spawns. Warn loudly rather than corrupt the environment silently.
490 if (QCoreApplication::instance() && (QThread::currentThread() != QCoreApplication::instance()->thread())) {
491 qCWarning(GStreamerEnvLog) << "prepareEnvironment() called off the GUI thread; qputenv is not thread-safe";
492 }
493 return _setGstEnvVars(appDir.isEmpty() ? QCoreApplication::applicationDirPath() : appDir);
494}
495
496// A bundled runtime's plugins differ from the system GStreamer's, so sharing the default per-user registry would make
497// each invalidate the other's plugin cache. The runtime version in the name keeps upgrades from reusing it, and the
498// install hash keeps two installs of one version (stable and daily builds) from rescanning over each other's.
499QString usePrivateRegistry(const QString& cacheDir, const QString& installPath)
500{
501 if (cacheDir.isEmpty() || _setByUser("GST_REGISTRY_1_0") || _setByUser("GST_REGISTRY")) {
502 return {};
503 }
504 if (!QDir().mkpath(cacheDir)) {
505 qCWarning(GStreamerEnvLog) << "Cannot create the GStreamer registry directory" << cacheDir;
506 return {};
507 }
508
509 guint major = 0;
510 guint minor = 0;
511 guint micro = 0;
512 guint nano = 0;
513 gst_version(&major, &minor, &micro, &nano);
514 const QByteArray installHash =
515 QCryptographicHash::hash(_stableInstallPath(installPath).toUtf8(), QCryptographicHash::Sha256).toHex().left(8);
516 QString registry = _cleanJoin(cacheDir, QStringLiteral("gstreamer-%1.%2.%3-%4-%5.bin")
517 .arg(major)
518 .arg(minor)
519 .arg(micro)
520 .arg(QSysInfo::buildCpuArchitecture(), QLatin1String(installHash)));
521 _setGstEnv("GST_REGISTRY", registry);
522 _pruneUnusedRegistries(registry);
523 return registry;
524}
525
526bool writeIfChanged(const QString& path, QByteArrayView content)
527{
528 QFile current(path);
529 if (current.open(QIODevice::ReadOnly) && (current.size() == content.size()) && (current.readAll() == content)) {
530 return true;
531 }
532 current.close();
533
534 if (!QDir().mkpath(QFileInfo(path).absolutePath())) {
535 qCWarning(GStreamerEnvLog) << "Cannot create the directory of" << path;
536 return false;
537 }
538 QSaveFile file(path);
539 if (!file.open(QIODevice::WriteOnly) || (file.write(content.data(), content.size()) != content.size()) ||
540 !file.commit()) {
541 qCWarning(GStreamerEnvLog) << "Cannot write" << path << ":" << file.errorString();
542 return false;
543 }
544 return true;
545}
546
548{
549 return s_bundledRuntime;
550}
551
553{
554 qCCritical(GStreamerEnvLog) << "GStreamer environment diagnostics:";
555 const auto dumpVar = [](const char* var) {
556 const QByteArray val = qgetenv(var);
557 qCCritical(GStreamerEnvLog) << " " << var << "=" << (val.isEmpty() ? "(unset)" : val.constData());
558 };
559 for (const char* var : kManagedGstPathVars) {
560 dumpVar(var);
561 }
562 dumpVar("GST_REGISTRY_FORK");
563 dumpVar("GST_REGISTRY_REUSE_PLUGIN_SCANNER");
564 dumpVar("GST_REGISTRY");
565}
566
567} // namespace GStreamer::Environment
#define QGC_LOGGING_CATEGORY(name, categoryStr)
BundledRuntime bundledRuntime()
The bundled runtime the last prepareEnvironment() applied; empty before it ran.
VideoBackend::EnvPrepResult prepareEnvironment(const QString &appDir)
bool writeIfChanged(const QString &path, QByteArrayView content)
DesktopInstall
The desktop installs prepareEnvironment() knows how to point GStreamer into.
@ MacOSFlat
An app bundle with a flat SDK copied next to the app, whose paths win over the framework's.
@ Windows
bin/ beside lib/gstreamer-1.0 and libexec/gstreamer-1.0.
@ MacOSFramework
An app bundle with GStreamer.framework, whose paths win over the app's own lib.
@ Linux
An AppImage or other prefix: bin/ beside lib/ and libexec/.
QString usePrivateRegistry(const QString &cacheDir, const QString &installPath)
BundleLayout bundleLayout(DesktopInstall install, const QString &appDir)
std::span< const HwPathDescriptor *const > paths() noexcept
Where a desktop install keeps its GStreamer runtime, as candidate paths in priority order.
The desktop GStreamer runtime bundled with the app that prepareEnvironment() pointed GStreamer at.