From b95bb4cbf74e7076ee0001ef6a8f4babd75b7710 Mon Sep 17 00:00:00 2001 From: Andrew Voznytsa Date: Wed, 19 Feb 2020 15:11:43 +0200 Subject: [PATCH] Switch gstreamer to use Qt log API by default --- src/QGCApplication.cc | 21 ++------ src/VideoStreaming/README.md | 4 ++ src/VideoStreaming/VideoStreaming.cc | 80 ++++++++++++++++++---------- src/VideoStreaming/VideoStreaming.h | 2 +- 4 files changed, 59 insertions(+), 48 deletions(-) diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a456f5cc7..88b6e74e8 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -319,27 +319,12 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) #endif // Gstreamer debug settings -#if defined(__ios__) || defined(__android__) - // Initialize Video Streaming - initializeVideoStreaming(argc, argv, nullptr, nullptr); -#else - QString savePath, gstDebugLevel; - if (settings.contains(AppSettings::savePathName)) { - savePath = settings.value(AppSettings::savePathName).toString(); - } - if(savePath.isEmpty()) { - savePath = "/tmp"; - } - savePath = savePath + "/Logs/gst"; - if (!QDir(savePath).exists()) { - QDir().mkpath(savePath); - } + int gstDebugLevel = 0; if (settings.contains(AppSettings::gstDebugLevelName)) { - gstDebugLevel = "*:" + settings.value(AppSettings::gstDebugLevelName).toString(); + gstDebugLevel = settings.value(AppSettings::gstDebugLevelName).toInt(); } // Initialize Video Streaming - initializeVideoStreaming(argc, argv, savePath.toUtf8().data(), gstDebugLevel.toUtf8().data()); -#endif + initializeVideoStreaming(argc, argv, gstDebugLevel); _toolbox = new QGCToolbox(this); _toolbox->setChildToolboxes(); diff --git a/src/VideoStreaming/README.md b/src/VideoStreaming/README.md index 130f7b2ce..0c4aa081f 100644 --- a/src/VideoStreaming/README.md +++ b/src/VideoStreaming/README.md @@ -7,6 +7,10 @@ To build video streaming support, you will need to install the GStreamer develop If you do have the proper GStreamer development libraries installed where QGC looks for it, the QGC build system will automatically use it and build video streaming support. If you would like to disable video streaming support, you can add **DISABLE_VIDEOSTREAMING** to the **DEFINES** build variable. +### Gstreamer logs + +For cases, when it is need to have more control over gstreamer logging than is availabe via QGroundControl's UI, it is possible to configure gstreamer logging via environment variables. Please see https://developer.gnome.org/gstreamer/stable/gst-running.html for details. + ### UDP Pipeline For the time being, the RTP UDP pipeline is somewhat hardcoded, using h.264 or h.265. It's best to use a camera capable of hardware encoding either h.264 (such as the Logitech C920) or h.265. On the sender end, for RTP (UDP Streaming) you would run something like this: diff --git a/src/VideoStreaming/VideoStreaming.cc b/src/VideoStreaming/VideoStreaming.cc index 30d6c0721..5b43b0657 100644 --- a/src/VideoStreaming/VideoStreaming.cc +++ b/src/VideoStreaming/VideoStreaming.cc @@ -19,23 +19,53 @@ #if defined(QGC_GST_STREAMING) #include -#if defined(__android__) -#include - -static void gst_android_log(GstDebugCategory * category, - GstDebugLevel level, - const gchar * file, - const gchar * function, - gint line, - GObject * object, - GstDebugMessage * message, - gpointer data) + +#include "QGCLoggingCategory.h" + +QGC_LOGGING_CATEGORY(GstreamerLog, "GstreamerLog") + +static void qt_gst_log(GstDebugCategory * category, + GstDebugLevel level, + const gchar * file, + const gchar * function, + gint line, + GObject * object, + GstDebugMessage * message, + gpointer data) { - if (level <= gst_debug_category_get_threshold (category)) { - __android_log_print(ANDROID_LOG_ERROR, "GST", "%s, %s: %s", file, function, gst_debug_message_get(message)); + if (level > gst_debug_category_get_threshold(category)) { + return; } + + QMessageLogger log(file, line, function); + + char* object_info = gst_info_strdup_printf("%" GST_PTR_FORMAT, static_cast(object)); + + switch (level) { + default: + case GST_LEVEL_ERROR: + log.critical(GstreamerLog, "%s %s", object_info, gst_debug_message_get(message)); + break; + case GST_LEVEL_WARNING: + log.warning(GstreamerLog, "%s %s", object_info, gst_debug_message_get(message)); + break; + case GST_LEVEL_FIXME: + case GST_LEVEL_INFO: + log.info(GstreamerLog, "%s %s", object_info, gst_debug_message_get(message)); + break; + case GST_LEVEL_DEBUG: + case GST_LEVEL_LOG: + case GST_LEVEL_TRACE: + case GST_LEVEL_MEMDUMP: + log.debug(GstreamerLog, "%s %s", object_info, gst_debug_message_get(message)); + break; + } + + g_free(object_info); + object_info = nullptr; } -#elif defined(__ios__) + +#if defined(__ios__) #include "gst_ios_init.h" #endif #else @@ -81,7 +111,7 @@ static void qgcputenv(const QString& key, const QString& root, const QString& pa #endif #endif -void initializeVideoStreaming(int &argc, char* argv[], char* logpath, char* debuglevel) +void initializeVideoStreaming(int &argc, char* argv[], int gstDebuglevel) { #if defined(QGC_GST_STREAMING) #ifdef Q_OS_MAC @@ -100,22 +130,15 @@ void initializeVideoStreaming(int &argc, char* argv[], char* logpath, char* debu qgcputenv("GST_PLUGIN_PATH", currentDir, "/gstreamer-plugins"); #endif - //-- Generic initialization - if (qgetenv("GST_DEBUG").isEmpty() && logpath) { - QString gstDebugFile = QString("%1/%2").arg(logpath).arg("gstreamer-log.txt"); - qDebug() << "GStreamer debug output:" << gstDebugFile; - if (debuglevel) { - qputenv("GST_DEBUG", debuglevel); - } - qputenv("GST_DEBUG_NO_COLOR", "1"); - qputenv("GST_DEBUG_FILE", gstDebugFile.toUtf8()); - qputenv("GST_DEBUG_DUMP_DOT_DIR", logpath); + //-- If gstreamer debugging is not configured via environment then use internal QT logging + if (qgetenv("GST_DEBUG").isEmpty()) { + gst_debug_set_default_threshold(static_cast(gstDebuglevel)); + gst_debug_remove_log_function(gst_debug_log_default); + gst_debug_add_log_function(qt_gst_log, nullptr, nullptr); } // Initialize GStreamer -#if defined(__android__) - gst_debug_add_log_function(gst_android_log, nullptr, nullptr); -#elif defined(__ios__) +#if defined(__ios__) //-- iOS specific initialization gst_ios_pre_init(); #endif @@ -175,7 +198,6 @@ void initializeVideoStreaming(int &argc, char* argv[], char* logpath, char* debu qmlRegisterType("org.freedesktop.gstreamer.GLVideoItem", 1, 0, "GstGLVideoItem"); Q_UNUSED(argc) Q_UNUSED(argv) - Q_UNUSED(logpath) Q_UNUSED(debuglevel) #endif } diff --git a/src/VideoStreaming/VideoStreaming.h b/src/VideoStreaming/VideoStreaming.h index 58f27cf2f..4551271bc 100644 --- a/src/VideoStreaming/VideoStreaming.h +++ b/src/VideoStreaming/VideoStreaming.h @@ -16,4 +16,4 @@ #pragma once -extern void initializeVideoStreaming (int &argc, char *argv[], char* filename, char* debuglevel); +extern void initializeVideoStreaming (int &argc, char *argv[], int gstDebuglevel); -- 2.22.0