6#include <QtCore/QString>
17std::atomic<bool> s_externalPluginLoaderFailed =
false;
20constexpr int kMaxBridgedLevel = GST_LEVEL_MEMDUMP;
23constexpr int kMaxBridgedLevel = GST_LEVEL_DEBUG;
26void glib_print_handler(
const gchar*
string)
28 qCInfo(GStreamerLoggingLog) << string;
31void glib_printerr_handler(
const gchar*
string)
33 qCWarning(GStreamerLoggingLog) << string;
36void glib_log_handler(
const gchar* log_domain, GLogLevelFlags log_level,
const gchar* message, gpointer user_data)
39 const QString domain = log_domain ? QString::fromUtf8(log_domain) : QStringLiteral(
"GLib");
40 const QString msg = QString::fromUtf8(message);
42 if (msg.contains(QStringLiteral(
"External plugin loader failed"))) {
43 s_externalPluginLoaderFailed.store(
true);
46 if (msg.contains(QStringLiteral(
"pygobject initialization failed"), Qt::CaseInsensitive)) {
47 qCDebug(GStreamerLoggingLog) << domain << msg;
51 switch (log_level & G_LOG_LEVEL_MASK) {
52 case G_LOG_LEVEL_ERROR:
53 case G_LOG_LEVEL_CRITICAL:
54 qCCritical(GStreamerLoggingLog) << domain << msg;
56 case G_LOG_LEVEL_WARNING:
57 qCWarning(GStreamerLoggingLog) << domain << msg;
59 case G_LOG_LEVEL_MESSAGE:
60 case G_LOG_LEVEL_INFO:
61 qCInfo(GStreamerLoggingLog) << domain << msg;
63 case G_LOG_LEVEL_DEBUG:
65 qCDebug(GStreamerLoggingLog) << domain << msg;
71void applyDebugLevel(
int level)
74 const int clamped = std::clamp(level, 0, maxLevel);
75 gst_debug_set_default_threshold(
static_cast<GstDebugLevel
>(clamped));
76 qCDebug(GStreamerLoggingLog) <<
"GStreamer debug threshold set to" << clamped;
85 return s_externalPluginLoaderFailed.load();
90 s_externalPluginLoaderFailed.store(
false);
95 g_set_print_handler(glib_print_handler);
96 g_set_printerr_handler(glib_printerr_handler);
97 g_log_set_default_handler(glib_log_handler,
nullptr);
102 return !qEnvironmentVariableIsEmpty(
"GST_DEBUG") || !qEnvironmentVariableIsEmpty(
"GST_DEBUG_FILE") ||
103 !qEnvironmentVariableIsEmpty(
"GST_TRACERS");
106void qtGstLog(GstDebugCategory* category, GstDebugLevel level,
const gchar* file,
const gchar* function, gint line,
107 GObject*
object, GstDebugMessage* message, gpointer data)
113 QtMsgType type = QtDebugMsg;
115 case GST_LEVEL_ERROR:
116 type = QtCriticalMsg;
118 case GST_LEVEL_WARNING:
121 case GST_LEVEL_FIXME:
128 if (!GStreamerAPILog().isEnabled(type)) {
136 source = QString::fromUtf8(objectInfo.get());
138#if GST_CHECK_VERSION(1, 22, 0)
140 else if (
const gchar*
const id = gst_debug_message_get_id(message);
id && (
id[0] !=
'\0')) {
141 source = QLatin1Char(
'<') + QString::fromUtf8(
id) + QLatin1String(
"> ");
144 qt_message_output(type, QMessageLogContext(file, line, function, GStreamerAPILog().categoryName()),
145 source + QString::fromUtf8(gst_debug_message_get(message)));
154 gst_debug_remove_log_function(gst_debug_log_default);
159 if (!qEnvironmentVariableIsEmpty(
"GST_DEBUG")) {
165 applyDebugLevel(level.value_or(GST_LEVEL_NONE));
170 if (!gst_is_initialized()) {
173 applyDebugLevel(level);
#define QGC_LOGGING_CATEGORY_ON(name, categoryStr)
#define QGC_LOGGING_CATEGORY(name, categoryStr)
GCharPtr adoptGChar(gchar *str) noexcept
void qtGstLog(GstDebugCategory *category, GstDebugLevel level, const gchar *file, const gchar *function, gint line, GObject *object, GstDebugMessage *message, gpointer data)
void setDebugLevel(int level)
bool externalPluginLoaderFailed()
void resetExternalPluginLoaderFailed()
void redirectGLibLogging()
bool nativeDebugLogRequested()
void configureDebugLogging(std::optional< int > level)
std::unique_ptr< gchar, GFreeDeleter > GCharPtr