From d084f107af5a3a559a088e3d679c76c532b76cbd Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Wed, 27 Nov 2019 11:09:25 -0500 Subject: [PATCH 01/29] Add JNI method for preventing Android screen sleep --- inc/util.h | 4 ++++ src/util.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/inc/util.h b/inc/util.h index 15358e8ef..f0e4109d4 100644 --- a/inc/util.h +++ b/inc/util.h @@ -17,4 +17,8 @@ QString tracker_mode_from_enum(TRACKER_MODE mode); uint map(double input, double input_start, double input_end, uint16_t output_start, uint16_t output_end); +#if defined(__android__) +void keep_screen_on(bool on); +#endif + #endif // UTIL_H diff --git a/src/util.cpp b/src/util.cpp index 1b1f34dac..f9726ea9f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -3,6 +3,11 @@ #include "util.h" +#if defined(__android__) +#include +#include +#endif + int battery_voltage_to_percent(int cells, double voltage) { double cell_voltage = voltage / static_cast(cells); @@ -257,4 +262,28 @@ uint map(double input, double input_start, double input_end, uint16_t output_sta return (input - input_start)*output_range / input_range + output_start; } +#if defined(__android__) +void keep_screen_on(bool on) { + QtAndroid::runOnAndroidThread([on] { + QAndroidJniObject activity = QtAndroid::androidActivity(); + if (activity.isValid()) { + QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;"); + + if (window.isValid()) { + const int FLAG_KEEP_SCREEN_ON = 128; + if (on) { + window.callMethod("addFlags", "(I)V", FLAG_KEEP_SCREEN_ON); + } else { + window.callMethod("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON); + } + } + } + QAndroidJniEnvironment env; + if (env->ExceptionCheck()) { + env->ExceptionClear(); + } + }); +} +#endif + #endif // UTIL_CPP From a855ca079d334fed492179e1c1f3b03e97c8f30b Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Wed, 27 Nov 2019 11:10:03 -0500 Subject: [PATCH 02/29] Prevent screen from sleeping on Android This only has effect while the app is running, if it goes to the background the device should still sleep normally --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index b61780f8c..883f458ad 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,8 @@ const QVector permissions({"android.permission.INTERNET", #include "qopenhdlink.h" +#include "util.h" + #if defined(ENABLE_VIDEO) #include #endif @@ -50,6 +52,8 @@ int main(int argc, char *argv[]) { QCoreApplication::setApplicationName("Open.HD"); #if defined(__android__) + keep_screen_on(true); + for(const QString &permission : permissions) { auto result = QtAndroid::checkPermission(permission); From fcfd7059f2c85149a4e8bed624b9c5c9825bd20c Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Thu, 28 Nov 2019 16:35:41 -0500 Subject: [PATCH 03/29] Fix arming/fight mode UI glitches caused by QGC Closes: #33 --- src/mavlinktelemetry.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mavlinktelemetry.cpp b/src/mavlinktelemetry.cpp index 3869b7455..b98469b39 100755 --- a/src/mavlinktelemetry.cpp +++ b/src/mavlinktelemetry.cpp @@ -104,6 +104,15 @@ void MavlinkTelemetry::processMavlinkDatagrams() { #endif void MavlinkTelemetry::processMavlinkMessage(mavlink_message_t msg) { + /* QGC sends its own heartbeats with compid 0 (fixed) + * and sysid 255 (configurable). We want to ignore these + * because they cause UI glitches like the flight mode + * appearing to change and the armed status flipping back + * and forth. + */ + if (msg.compid != 1) { + return; + } switch (msg.msgid) { case MAVLINK_MSG_ID_HEARTBEAT: { mavlink_heartbeat_t heartbeat; From 542e977807627ba40067ee88950d64e4296dc4af Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Thu, 28 Nov 2019 17:08:19 -0500 Subject: [PATCH 04/29] Fix windows installer vcredist installation --- tools/qopenhd_installer.nsi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/qopenhd_installer.nsi b/tools/qopenhd_installer.nsi index 6f626020b..a9902ab08 100755 --- a/tools/qopenhd_installer.nsi +++ b/tools/qopenhd_installer.nsi @@ -47,9 +47,8 @@ doinstall: File /r /x ${EXENAME}.pdb /x ${EXENAME}.lib /x ${EXENAME}.exp ${DESTDIR}\*.* - File "vcredist_x86.exe" - ExecWait '$DESTDIR\vc_redist.x86.exe /passive /norestart' - Delete "$DESTDIR\vc_redist.x86.exe" + ExecWait '$INSTDIR\vc_redist.x86.exe /passive /norestart' + Delete "$INSTDIR\vc_redist.x86.exe" WriteUninstaller $INSTDIR\${EXENAME}-Uninstall.exe WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}" From a4cddc812acc7efafeb632fc211c4a514a6210a6 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:38:43 -0500 Subject: [PATCH 05/29] Fix use of ENABLE_SPEECH ifdef in OpenHDRC --- src/openhdrc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openhdrc.cpp b/src/openhdrc.cpp index 5aff10682..9b1fe0d28 100755 --- a/src/openhdrc.cpp +++ b/src/openhdrc.cpp @@ -255,7 +255,7 @@ void OpenHDRC::connectedChanged(bool value) { QSettings settings; -#if defined(SPEECH) +#if defined(ENABLE_SPEECH) auto enable_speech = settings.value("enable_speech", QVariant(0)); if (value && enable_speech == 1) { m_speech->say("Game pad connected"); From 61dc8619b53802f5312453072577fb28e3994fa0 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:41:12 -0500 Subject: [PATCH 06/29] Set RC channel properties when using QJoysticks Saving 10 channels at the moment, which is more than the custom network packet format can handle anyway --- src/openhdrc.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/openhdrc.cpp b/src/openhdrc.cpp index 9b1fe0d28..4b706fe0d 100755 --- a/src/openhdrc.cpp +++ b/src/openhdrc.cpp @@ -247,6 +247,51 @@ void OpenHDRC::axisChanged(const int js, const int axis, const qreal value) { Q_UNUSED(axis) qDebug() << "OpenHDRC::axisChanged()"; + switch (axis) { + case 0: + set_rc1(map(value, -1, 1, 1000, 2000)); + break; + + case 1: + set_rc2(map(value, -1, 1, 1000, 2000)); + break; + + case 2: + set_rc3(map(value, -1, 1, 1000, 2000)); + break; + + case 3: + set_rc4(map(value, -1, 1, 1000, 2000)); + break; + + case 4: + set_rc5(map(value, -1, 1, 1000, 2000)); + break; + + case 5: + set_rc6(map(value, -1, 1, 1000, 2000)); + break; + + case 6: + set_rc7(map(value, -1, 1, 1000, 2000)); + break; + + case 7: + set_rc8(map(value, -1, 1, 1000, 2000)); + break; + + case 8: + set_rc9(map(value, -1, 1, 1000, 2000)); + break; + + case 9: + set_rc10(map(value, -1, 1, 1000, 2000)); + break; + + default: + break; + } + qDebug() << "Axis " << axis << ": " << value; } From 17aff8d5a8c01d9ad633eff479f9829455034c45 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:42:11 -0500 Subject: [PATCH 07/29] Wait for RC socket to open before continuing init --- src/openhdrc.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openhdrc.cpp b/src/openhdrc.cpp index 4b706fe0d..78e805446 100755 --- a/src/openhdrc.cpp +++ b/src/openhdrc.cpp @@ -41,6 +41,8 @@ OpenHDRC::OpenHDRC(QObject *parent): QObject(parent) { #else rcSocket->connectToHost("192.168.2.1", PORT); #endif + rcSocket->waitForConnected(); + connect(rcSocket, &QUdpSocket::readyRead, this, &OpenHDRC::processRCDatagrams); #if defined(ENABLE_SPEECH) From fca7aee5d5de2ea2ecc3c9c185ccb69983d09eb6 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:42:37 -0500 Subject: [PATCH 08/29] Add RC sequence number member in OpenHDRC --- inc/openhdrc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/openhdrc.h b/inc/openhdrc.h index 3c14b73f5..27916f3b3 100755 --- a/inc/openhdrc.h +++ b/inc/openhdrc.h @@ -166,6 +166,8 @@ private slots: QTextToSpeech *m_speech; #endif + uint8_t seqno = 0; + uint m_rc1 = 1500; uint m_rc2 = 1500; uint m_rc3 = 1500; From 4da6f792cf044642dcb59c0ef2745f644437cc52 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:43:47 -0500 Subject: [PATCH 09/29] Send custom RC packet format, not struct The struct is only used on the ground side --- src/openhdrc.cpp | 72 ++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/openhdrc.cpp b/src/openhdrc.cpp index 78e805446..4e858e684 100755 --- a/src/openhdrc.cpp +++ b/src/openhdrc.cpp @@ -14,24 +14,6 @@ #define BUFLEN 21 #define PORT 5565 // UDP port for OpenHD RC -struct rcdata_s { - unsigned int chan1 : 11; - unsigned int chan2 : 11; - unsigned int chan3 : 11; - unsigned int chan4 : 11; - unsigned int chan5 : 11; - unsigned int chan6 : 11; - unsigned int chan7 : 11; - unsigned int chan8 : 11; - unsigned int Is16 : 8; - unsigned int switches : 16; -} -#ifndef _MSC_VER -__attribute__((packed)) -#endif -; -static struct rcdata_s rcdata; - OpenHDRC::OpenHDRC(QObject *parent): QObject(parent) { rcSocket = new QUdpSocket(this); @@ -81,21 +63,45 @@ void OpenHDRC::channelTrigger() { QSettings settings; auto enable_rc = settings.value("enable_rc", QVariant::Int); if (enable_rc == 1) { - QNetworkDatagram d; - rcdata.chan1 = m_rc1; - rcdata.chan2 = m_rc2; - rcdata.chan3 = m_rc3; - rcdata.chan4 = m_rc4; - rcdata.chan5 = m_rc5; - rcdata.chan6 = m_rc6; - rcdata.chan7 = m_rc7; - rcdata.chan8 = m_rc8; - rcdata.Is16 = 0; - rcdata.switches = 0; - QByteArray rcChannels; - rcChannels.resize(sizeof(rcdata)); - memcpy(rcChannels.data(), &rcdata, sizeof(rcdata)); - rcSocket->writeDatagram(d); + QByteArray rcChannels(BUFLEN, 0); + + rcChannels[0] = m_rc1 & 0xFF; + rcChannels[1] = (m_rc1 >> 8) & 0xFF; + + rcChannels[2] = m_rc2 & 0xFF; + rcChannels[3] = (m_rc2 >> 8) & 0xFF; + + rcChannels[4] = m_rc3 & 0xFF; + rcChannels[5] = (m_rc3 >> 8) & 0xFF; + + rcChannels[6] = m_rc4 & 0xFF; + rcChannels[7] = (m_rc4 >> 8) & 0xFF; + + rcChannels[8] = m_rc5 & 0xFF; + rcChannels[9] = (m_rc5 >> 8) & 0xFF; + + rcChannels[10] = m_rc6 & 0xFF; + rcChannels[11] = (m_rc6 >> 8) & 0xFF; + + rcChannels[12] = m_rc7 & 0xFF; + rcChannels[13] = (m_rc7 >> 8) & 0xFF; + + rcChannels[14] = m_rc8 & 0xFF; + rcChannels[15] = (m_rc8 >> 8) & 0xFF; + + rcChannels[16] = seqno; + rcChannels[17] = 0; + + // is16 + rcChannels[18] = 0; + + // these would be the buttons, disabled for now. + rcChannels[19] = 1; + rcChannels[20] = 1; + + rcSocket->write(rcChannels, rcChannels.length()); + + seqno++; } #endif } From 8ad4994e1307f7b77b1c5fd6294d18d93a64b984 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:44:37 -0500 Subject: [PATCH 10/29] Fix retrieval of settings value in OpenHDRC It's not actually an integer even though some platforms store it that way --- src/openhdrc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/openhdrc.cpp b/src/openhdrc.cpp index 4e858e684..3d6bd44d6 100755 --- a/src/openhdrc.cpp +++ b/src/openhdrc.cpp @@ -61,8 +61,9 @@ void OpenHDRC::channelTrigger() { emit channelUpdate(m_rc1, m_rc2, m_rc3, m_rc4, m_rc5, m_rc6, m_rc7, m_rc8, m_rc9, m_rc10); #if defined(ENABLE_RC) QSettings settings; - auto enable_rc = settings.value("enable_rc", QVariant::Int); - if (enable_rc == 1) { + auto enable_rc = settings.value("enable_rc", false).toBool(); + + if (enable_rc) { QByteArray rcChannels(BUFLEN, 0); rcChannels[0] = m_rc1 & 0xFF; From 7c5fd0ff273ba9470993b49d386109f6ac3bca82 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:49:42 -0500 Subject: [PATCH 11/29] Disable gamepads on all platforms Joysticks are handled separately --- QOpenHD.pro | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index 20eaf76a7..f9ab40da0 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -173,7 +173,7 @@ iOSBuild { icons/LaunchScreen.storyboard LIBS += -framework VideoToolbox -framework AudioToolbox -framework CoreAudio -framework CoreVideo -framework CoreMedia CONFIG -= bitcode - CONFIG += EnableGamepads + #CONFIG += EnableGamepads CONFIG += EnableSpeech CONFIG += EnableVideo CONFIG += EnablePiP @@ -198,7 +198,7 @@ MacBuild { DISTFILES += mac/Info.plist LIBS += -framework ApplicationServices LIBS += -framework VideoToolbox -framework CoreVideo -framework CoreMedia - CONFIG += EnableGamepads + #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech CONFIG += EnableVideo @@ -212,7 +212,7 @@ MacBuild { LinuxBuild { QT += x11extras - CONFIG += EnableGamepads + #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableVideo CONFIG += EnablePiP @@ -236,7 +236,7 @@ RaspberryPiBuild { } WindowsBuild { - CONFIG += EnableGamepads + #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech CONFIG += EnableVideo @@ -251,7 +251,7 @@ WindowsBuild { } AndroidBuild { - CONFIG += EnableGamepads + #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech CONFIG += EnableVideo From e7ed20173c0cdc165e1ac56c0cc4aa1cf1e2b7db Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:52:08 -0500 Subject: [PATCH 12/29] Enable RC on Mac Ref: #10 --- QOpenHD.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/QOpenHD.pro b/QOpenHD.pro index f9ab40da0..53b0b2bca 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -198,6 +198,7 @@ MacBuild { DISTFILES += mac/Info.plist LIBS += -framework ApplicationServices LIBS += -framework VideoToolbox -framework CoreVideo -framework CoreMedia + CONFIG += EnableRC #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech From 14f1050de8e1ac061dd9360a125b061aacbefddb Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:55:35 -0500 Subject: [PATCH 13/29] Fix Enable RC setting row color --- qml/ui/AppSettingsPanel.ui.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qml/ui/AppSettingsPanel.ui.qml b/qml/ui/AppSettingsPanel.ui.qml index 7e762e727..df53a44dc 100755 --- a/qml/ui/AppSettingsPanel.ui.qml +++ b/qml/ui/AppSettingsPanel.ui.qml @@ -190,7 +190,7 @@ Item { Rectangle { width: parent.width height: rowHeight - color: "#8cbfd7f3" + color: "#00000000" y: 3 * rowHeight visible: EnableRC From 36ff3c939895ac04162e5de6759008e020e63f06 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:55:52 -0500 Subject: [PATCH 14/29] Fix accidentally disabled Link on Mac --- QOpenHD.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index 53b0b2bca..775b012a5 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -204,7 +204,7 @@ MacBuild { CONFIG += EnableSpeech CONFIG += EnableVideo CONFIG += EnablePiP - #CONFIG += EnableLink + CONFIG += EnableLink DEFINES += GST_GL_HAVE_WINDOW_COCOA=1 DEFINES += GST_GL_HAVE_PLATFORM_CGL=1 From 27fba4bce8011f9cff071ebdf9495b4ee6e54dfe Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 18:56:17 -0500 Subject: [PATCH 15/29] Remove old global RC disable --- QOpenHD.pro | 2 -- 1 file changed, 2 deletions(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index 775b012a5..8e4f10982 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -162,8 +162,6 @@ SOURCES += \ lib/GeographicLib-1.50/src/UTMUPS.cpp \ lib/GeographicLib-1.50/src/Utility.cpp -#CONFIG += EnableRC - iOSBuild { QMAKE_INFO_PLIST = ios/Info.plist From 96c20b660a13fa3b592c7d8b4c4030e6b2e1a7bf Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 21:20:20 -0500 Subject: [PATCH 16/29] Add sdl2 library to installer on Windows --- QOpenHD.pro | 6 +++++- win_deploy_sdl.cmd | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 win_deploy_sdl.cmd diff --git a/QOpenHD.pro b/QOpenHD.pro index 8e4f10982..d1ba72a14 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -327,8 +327,12 @@ installer { } WindowsBuild { + DESTDIR_WIN = $$replace(DESTDIR, "/", "\\") + OTHER_FILES += tools/qopenhd_installer.nsi - QMAKE_POST_LINK += c:\Qt\5.13.1\msvc2017\bin\windeployqt.exe --qmldir $${PWD}/qml \"$${DESTDIR_WIN}\\QOpenHD.exe\" + QMAKE_POST_LINK +=$${PWD}/win_deploy_sdl.cmd \"$$DESTDIR_WIN\" \"$$PWD\QJoysticks\lib\SDL\bin\windows\msvc\x86\" $$escape_expand(\\n) + + QMAKE_POST_LINK += $$escape_expand(\\n) c:\Qt\5.13.1\msvc2017\bin\windeployqt.exe --qmldir $${PWD}/qml \"$${DESTDIR_WIN}\\QOpenHD.exe\" #QMAKE_POST_LINK += && $$escape_expand(\\n) $$QMAKE_COPY \"C:\\Windows\\System32\\msvcp140.dll\" \"$$DESTDIR_WIN\" #QMAKE_POST_LINK += && $$escape_expand(\\n) $$QMAKE_COPY \"C:\\Windows\\System32\\msvcr140.dll\" \"$$DESTDIR_WIN\" diff --git a/win_deploy_sdl.cmd b/win_deploy_sdl.cmd new file mode 100644 index 000000000..4254a40a6 --- /dev/null +++ b/win_deploy_sdl.cmd @@ -0,0 +1,5 @@ + +SET DESTDIR_WIN=%~f1 +SET SDL_DIR=%~f2 + +xcopy %SDL_DIR%\SDL2.dll %DESTDIR_WIN%\ /S/Y From 4554c4527306f56f7fab7b5b4cbec580f3230844 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 22:05:19 -0500 Subject: [PATCH 17/29] Revert "Enable RC on Mac" This reverts commit e7ed20173c0cdc165e1ac56c0cc4aa1cf1e2b7db. --- QOpenHD.pro | 1 - 1 file changed, 1 deletion(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index d1ba72a14..73cbcee67 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -196,7 +196,6 @@ MacBuild { DISTFILES += mac/Info.plist LIBS += -framework ApplicationServices LIBS += -framework VideoToolbox -framework CoreVideo -framework CoreMedia - CONFIG += EnableRC #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech From 86a55650cc7563293a6762472794fb20ee64c073 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 22:33:19 -0500 Subject: [PATCH 18/29] Use consistent names for widget enable in settings This makes it possible to use the widgetIdentifier to find the correct setting key to enable/disable a widget, which is necessary for enabling/disabling widgets across the Link --- qml/main.qml | 4 ++-- qml/ui/AppSettingsPanel.ui.qml | 8 ++++---- qml/ui/HUDOverlayGridForm.ui.qml | 1 - qml/ui/widgets/AltitudeSecondWidgetForm.ui.qml | 2 +- qml/ui/widgets/MessageHUDForm.ui.qml | 2 +- qml/ui/widgets/VideoWidget.qml | 1 - qml/ui/widgets/VideoWidgetForm.ui.qml | 4 ++-- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/qml/main.qml b/qml/main.qml index 3b04beb05..081f71e0b 100755 --- a/qml/main.qml +++ b/qml/main.qml @@ -76,13 +76,13 @@ ApplicationWindow { property bool show_flight_mode: true property bool show_ground_status: true property bool show_air_status: true - property bool show_log_onscreen: true + property bool show_message_hud: true property bool show_horizon: true property bool show_fpv: true property bool show_altitude: true property bool show_speed: true property bool show_heading: true - property bool show_second_alt: true + property bool show_altitude_second: true property bool show_arrow: true property bool show_map: true property bool show_throttle: true diff --git a/qml/ui/AppSettingsPanel.ui.qml b/qml/ui/AppSettingsPanel.ui.qml index df53a44dc..71fd74c62 100755 --- a/qml/ui/AppSettingsPanel.ui.qml +++ b/qml/ui/AppSettingsPanel.ui.qml @@ -553,8 +553,8 @@ Item { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter - checked: settings.show_log_onscreen - onCheckedChanged: settings.show_log_onscreen = checked + checked: settings.show_message_hud + onCheckedChanged: settings.show_message_hud = checked } } @@ -733,8 +733,8 @@ Item { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter - checked: settings.show_second_alt - onCheckedChanged: settings.show_second_alt = checked + checked: settings.show_altitude_second + onCheckedChanged: settings.show_altitude_second = checked } } diff --git a/qml/ui/HUDOverlayGridForm.ui.qml b/qml/ui/HUDOverlayGridForm.ui.qml index 8ef2060f6..dbffd0141 100644 --- a/qml/ui/HUDOverlayGridForm.ui.qml +++ b/qml/ui/HUDOverlayGridForm.ui.qml @@ -119,7 +119,6 @@ Item { VideoWidget { id: pipVideoWidget - elementName: "pipVideoItem" } MapWidget { diff --git a/qml/ui/widgets/AltitudeSecondWidgetForm.ui.qml b/qml/ui/widgets/AltitudeSecondWidgetForm.ui.qml index f00a8ffd9..d28a7b61f 100644 --- a/qml/ui/widgets/AltitudeSecondWidgetForm.ui.qml +++ b/qml/ui/widgets/AltitudeSecondWidgetForm.ui.qml @@ -17,7 +17,7 @@ BaseWidget { defaultYOffset: 64 dragging: false - visible: settings.show_second_alt + visible: settings.show_altitude_second widgetIdentifier: "altitude_second_widget" diff --git a/qml/ui/widgets/MessageHUDForm.ui.qml b/qml/ui/widgets/MessageHUDForm.ui.qml index de773a237..09d590e07 100644 --- a/qml/ui/widgets/MessageHUDForm.ui.qml +++ b/qml/ui/widgets/MessageHUDForm.ui.qml @@ -15,7 +15,7 @@ BaseWidget { width: 480 height: 72 - visible: settings.show_log_onscreen + visible: settings.show_message_hud widgetIdentifier: "message_hud_widget" diff --git a/qml/ui/widgets/VideoWidget.qml b/qml/ui/widgets/VideoWidget.qml index 828f8fc6e..152a9e97e 100755 --- a/qml/ui/widgets/VideoWidget.qml +++ b/qml/ui/widgets/VideoWidget.qml @@ -3,6 +3,5 @@ import QtQuick.Window 2.12 import QtQuick.Layouts 1.12 Loader { - property string elementName source: (EnableVideo && EnablePiP) ? "VideoWidgetForm.ui.qml" : "" } diff --git a/qml/ui/widgets/VideoWidgetForm.ui.qml b/qml/ui/widgets/VideoWidgetForm.ui.qml index c2723a7fd..c261f389d 100644 --- a/qml/ui/widgets/VideoWidgetForm.ui.qml +++ b/qml/ui/widgets/VideoWidgetForm.ui.qml @@ -14,7 +14,7 @@ BaseWidget { visible: settings.show_pip_video - widgetIdentifier: elementName + "_widget" + widgetIdentifier: "pip_video_widget" defaultAlignment: 0 defaultXOffset: 12 @@ -43,7 +43,7 @@ BaseWidget { GstGLVideoItem { id: videoElement - objectName: elementName + objectName: "pipVideoItem" anchors.fill: parent } } From 12503a5fc413f7aacbf3b34b0a3428ef7a3af137 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Fri, 29 Nov 2019 22:38:34 -0500 Subject: [PATCH 19/29] Add Link API for remotely disabling widgets --- inc/qopenhdlink.h | 5 ++++- src/qopenhdlink.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/inc/qopenhdlink.h b/inc/qopenhdlink.h index 61fad7dff..468d3eb26 100644 --- a/inc/qopenhdlink.h +++ b/inc/qopenhdlink.h @@ -17,9 +17,12 @@ class QOpenHDLink: public QObject { explicit QOpenHDLink(QObject *parent = nullptr); Q_INVOKABLE void setWidgetLocation(QString widgetName, int alignment, int xOffset, int yOffset, bool hCenter, bool vCenter); + Q_INVOKABLE void setWidgetEnabled(QString widgetName, bool enabled); signals: void widgetLocation(QString widgetName, int alignment, int xOffset, int yOffset, bool hCenter, bool vCenter); + void widgetEnabled(QString widgetName, bool enabled); + private slots: void readyRead(); @@ -28,7 +31,7 @@ private slots: void processCommand(QByteArray buffer); void processSetWidgetLocation(nlohmann::json command); - + void processSetWidgetEnabled(nlohmann::json commandData); QUdpSocket *linkSocket = nullptr; }; diff --git a/src/qopenhdlink.cpp b/src/qopenhdlink.cpp index 4d6d228d2..ddb4675e2 100644 --- a/src/qopenhdlink.cpp +++ b/src/qopenhdlink.cpp @@ -72,6 +72,22 @@ void QOpenHDLink::setWidgetLocation(QString widgetName, int alignment, int xOffs #endif } +void QOpenHDLink::setWidgetEnabled(QString widgetName, bool enabled) { +#if defined(ENABLE_LINK) + nlohmann::json j = { + {"cmd", "setWidgetEnabled"}, + {"widgetName", widgetName.toStdString()}, + {"enabled", enabled} + }; + + std::string serialized_string = j.dump(); + auto buf = QByteArray(serialized_string.c_str()); + if (linkSocket->state() != QUdpSocket::ConnectedState) { + linkSocket->connectToHost("192.168.2.1", LINK_PORT); + } + linkSocket->writeDatagram(buf); +#endif +} void QOpenHDLink::processCommand(QByteArray buffer) { #if defined(ENABLE_LINK) @@ -83,6 +99,10 @@ void QOpenHDLink::processCommand(QByteArray buffer) { if (cmd == "setWidgetLocation") { processSetWidgetLocation(commandData); } + + if (cmd == "setWidgetEnabled") { + processSetWidgetEnabled(commandData); + } } } catch (std::exception &e) { // not much we can do about it but we definitely don't want a crash here, @@ -106,3 +126,13 @@ void QOpenHDLink::processSetWidgetLocation(nlohmann::json commandData) { emit widgetLocation(QString(widgetName.c_str()), alignment, xOffset, yOffset, hCenter, vCenter); #endif } + +void QOpenHDLink::processSetWidgetEnabled(nlohmann::json commandData) { +#if defined(ENABLE_LINK) + std::string widgetName = commandData["widgetName"]; + + bool enabled = commandData["enabled"]; + + emit widgetEnabled(QString(widgetName.c_str()), enabled); +#endif +} From 407f886020184e2e0ef6a3837c18265fc9b69007 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Sat, 30 Nov 2019 23:10:04 -0500 Subject: [PATCH 20/29] Allow Mavlink message compid 250 for iNav --- src/mavlinktelemetry.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mavlinktelemetry.cpp b/src/mavlinktelemetry.cpp index b98469b39..850c0d675 100755 --- a/src/mavlinktelemetry.cpp +++ b/src/mavlinktelemetry.cpp @@ -110,7 +110,7 @@ void MavlinkTelemetry::processMavlinkMessage(mavlink_message_t msg) { * appearing to change and the armed status flipping back * and forth. */ - if (msg.compid != 1) { + if (msg.compid != 1 && msg.compid != 250) { return; } switch (msg.msgid) { From f59febdcb62e625a9a61d421bbb6e42369e993f5 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Sun, 1 Dec 2019 16:01:03 -0500 Subject: [PATCH 21/29] Add support for raw video Turn off RTP and the receiver pipeline assumes raw h264 is in use as the next element in the pipeline is always h264parse. Tested working on Android 5.0 and Android 9.0 --- inc/openhdvideostream.h | 1 + qml/main.qml | 1 + qml/ui/AppSettingsPanel.ui.qml | 40 +++++++++++++++++++++++++++++----- src/openhdvideostream.cpp | 20 ++++++++++++----- 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/inc/openhdvideostream.h b/inc/openhdvideostream.h index 11f0347c2..6e2839a0b 100755 --- a/inc/openhdvideostream.h +++ b/inc/openhdvideostream.h @@ -37,6 +37,7 @@ public slots: bool m_enable_videotest = false; bool m_enable_hardware_video_decoder = true; + bool m_enable_rtp = true; bool m_enable_pip_video = false; diff --git a/qml/main.qml b/qml/main.qml index 081f71e0b..8213492c5 100755 --- a/qml/main.qml +++ b/qml/main.qml @@ -61,6 +61,7 @@ ApplicationWindow { property int battery_cells: 3 property bool show_pip_video: false property bool enable_hardware_video_decoder: true + property bool enable_rtp: true property bool enable_speech: true property bool enable_imperial: false diff --git a/qml/ui/AppSettingsPanel.ui.qml b/qml/ui/AppSettingsPanel.ui.qml index 71fd74c62..155afe4b9 100755 --- a/qml/ui/AppSettingsPanel.ui.qml +++ b/qml/ui/AppSettingsPanel.ui.qml @@ -885,7 +885,7 @@ Item { id: videoView width: parent.width height: parent.height - contentHeight: 4 * rowHeight + contentHeight: 5 * rowHeight clip: true visible: EnableVideo @@ -926,6 +926,36 @@ Item { color: "#00000000" y: 1 * rowHeight + Text { + text: "Stream is RTP" + font.weight: Font.Bold + font.pixelSize: 13 + anchors.leftMargin: 8 + verticalAlignment: Text.AlignVCenter + anchors.verticalCenter: parent.verticalCenter + width: 224 + height: elementHeight + anchors.left: parent.left + } + + Switch { + width: 32 + height: elementHeight + anchors.rightMargin: Qt.inputMethod.visible ? 96 : 36 + + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + checked: settings.enable_rtp + onCheckedChanged: settings.enable_rtp = checked + } + } + + Rectangle { + width: parent.width + height: rowHeight + color: "#8cbfd7f3" + y: 2 * rowHeight + Text { text: "Main video port" font.weight: Font.Bold @@ -958,8 +988,8 @@ Item { Rectangle { width: parent.width height: rowHeight - color: "#8cbfd7f3" - y: 2 * rowHeight + color: "#00000000" + y: 3 * rowHeight visible: EnablePiP Text { @@ -989,8 +1019,8 @@ Item { Rectangle { width: parent.width height: rowHeight - color: "#00000000" - y: 3 * rowHeight + color: "#8cbfd7f3" + y: 4 * rowHeight visible: EnablePiP Text { diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index 794d4ded5..5dcaeea2e 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -731,9 +731,13 @@ void OpenHDVideoStream::_start() { } else { qDebug() << "Listening on port" << m_video_port; - s << QString("udpsrc port=%1 caps=\"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264\" !").arg(m_video_port); - s << "rtpjitterbuffer latency=25 mode=0 !"; - s << "rtph264depay ! "; + if (m_enable_rtp) { + s << QString("udpsrc port=%1 caps=\"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264\" !").arg(m_video_port); + s << "rtpjitterbuffer latency=25 mode=0 !"; + s << "rtph264depay ! "; + } else { + s << QString("udpsrc port=%1 !").arg(m_video_port); + } //s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; if (m_enable_hardware_video_decoder) { @@ -806,6 +810,8 @@ void OpenHDVideoStream::_timer() { QSettings settings; auto _enable_videotest = settings.value("enable_videotest", false).toBool(); auto _enable_hardware_video_decoder = settings.value("enable_hardware_video_decoder", true).toBool(); + auto _enable_rtp = settings.value("enable_rtp", true).toBool(); + auto _show_pip_video = settings.value("show_pip_video", false).toBool(); auto _main_video_port = settings.value("main_video_port", main_default_port).toInt(); @@ -813,20 +819,24 @@ void OpenHDVideoStream::_timer() { if (m_stream_type == StreamTypeMain) { - if (_enable_videotest != m_enable_videotest || _enable_hardware_video_decoder != m_enable_hardware_video_decoder || _main_video_port != m_video_port) { + if (_enable_videotest != m_enable_videotest || _enable_hardware_video_decoder != m_enable_hardware_video_decoder || _main_video_port != m_video_port || _enable_rtp != m_enable_rtp) { qDebug() << "Restarting main stream"; stopVideo(); m_enable_videotest = _enable_videotest; m_enable_hardware_video_decoder = _enable_hardware_video_decoder; + m_enable_rtp = _enable_rtp; + m_video_port = _main_video_port; startVideo(); } } else if (m_stream_type == StreamTypePiP) { - if (m_enable_pip_video != _show_pip_video || _enable_videotest != m_enable_videotest || _enable_hardware_video_decoder != m_enable_hardware_video_decoder || _pip_video_port != m_video_port) { + if (m_enable_pip_video != _show_pip_video || _enable_videotest != m_enable_videotest || _enable_hardware_video_decoder != m_enable_hardware_video_decoder || _pip_video_port != m_video_port || _enable_rtp != m_enable_rtp) { qDebug() << "Restarting PiP stream"; stopVideo(); m_enable_videotest = _enable_videotest; m_enable_hardware_video_decoder = _enable_hardware_video_decoder; + m_enable_rtp = _enable_rtp; + m_video_port = _pip_video_port; m_enable_pip_video = _show_pip_video; if (_show_pip_video) { From 6fc35cb6992cae90c4f89e192b092b660feb6cf8 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 20:48:21 -0500 Subject: [PATCH 22/29] Always use omxh264dec on ground station --- src/openhdvideostream.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index 5dcaeea2e..0fa77adf4 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -743,7 +743,11 @@ void OpenHDVideoStream::_start() { if (m_enable_hardware_video_decoder) { qDebug() << "Using hardware decoder"; s << "h264parse !"; + #if defined(__rasp_pi__) + s << "omxh264dec !"; + #else s << "decodebin3 !"; + #endif //s << "amcviddec-omxqcomvideodecoderavc !"; //s << "amcviddec-omxmtkvideodecoderavc !"; } else { From e71afde742d9ed713d5f4ceeb1861a2b3b5638b3 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 20:52:36 -0500 Subject: [PATCH 23/29] Enable the video pipeline queues These aren't really queues in the buffering sense, they create thread boundaries to isolate major parts of the pipeline from each other, which improves streaming on low powered devices --- src/openhdvideostream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index 0fa77adf4..0f57088e0 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -738,7 +738,7 @@ void OpenHDVideoStream::_start() { } else { s << QString("udpsrc port=%1 !").arg(m_video_port); } - //s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; + s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; if (m_enable_hardware_video_decoder) { qDebug() << "Using hardware decoder"; @@ -756,7 +756,7 @@ void OpenHDVideoStream::_start() { s << "avdec_h264 !"; } } - //s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; + s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; s << "glupload ! glcolorconvert !"; s << "qmlglsink name=qmlglsink sync=false"; From 98c91ab64e08b8ed78c94845d3d3c1624c2994aa Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 20:53:56 -0500 Subject: [PATCH 24/29] Don't use in-tree version of qmlglsink on GroundPi We use the one in our GStreamer packages --- src/openhdvideostream.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index 0f57088e0..c960be403 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -150,9 +150,11 @@ G_PASTE(g_io_module_, G_PASTE(name, _load_static)) () #if defined(ENABLE_VIDEO) #ifndef __desktoplinux__ +#ifndef __rasp_pi__ GST_PLUGIN_STATIC_DECLARE(qmlgl); #endif #endif +#endif #if defined(GST_MOBILE_PLUGIN_COREELEMENTS) || defined(GST_MOBILE_PLUGINS_CORE) GST_PLUGIN_STATIC_DECLARE(coreelements); @@ -482,8 +484,10 @@ OpenHDVideoStream::OpenHDVideoStream(int &argc, char *argv[], QObject * parent): //gst_debug_add_log_function(printf_extension_log_func, nullptr, nullptr); #if defined(ENABLE_VIDEO) #ifndef __desktoplinux__ +#ifndef __rasp_pi__ GST_PLUGIN_STATIC_REGISTER(qmlgl); #endif +#endif #endif #if defined(GST_MOBILE_PLUGIN_COREELEMENTS) || defined(GST_MOBILE_PLUGINS_CORE) From 5b10d30d45644724200516c34df6681454614ac9 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 20:54:38 -0500 Subject: [PATCH 25/29] Preload initial RTP setting before video starts --- src/openhdvideostream.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index c960be403..96899ef6c 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -711,6 +711,8 @@ void OpenHDVideoStream::init(QQmlApplicationEngine* engine = nullptr, enum Strea } else { m_video_port = settings.value("pip_video_port", 5601).toInt(); } + m_enable_rtp = settings.value("enable_rtp", true).toBool(); + QObject::connect(timer, &QTimer::timeout, this, &OpenHDVideoStream::_timer); timer->start(1000); From 89d137ea33f2e3e3749970081c30b307662423b5 Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 20:55:15 -0500 Subject: [PATCH 26/29] Re-enable app video and PiP on the GroundPi --- QOpenHD.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index 73cbcee67..8846542e9 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -225,8 +225,8 @@ RaspberryPiBuild { # handled by another process running on the ground station. We could # replace that at some point but for now it isn't necessary. message("RaspberryPiBuild - config") - #CONFIG += EnableVideo - #CONFIG +- EnablePiP + CONFIG += EnableVideo + CONFIG += EnablePiP CONFIG += EnableLink DEFINES += GST_GL_HAVE_PLATFORM_EGL=1 From 2f91f941c42e7332c512dbade615018d0044c4ae Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 20:55:40 -0500 Subject: [PATCH 27/29] Remove old compiler defines for qmlgl --- QOpenHD.pro | 3 --- 1 file changed, 3 deletions(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index 8846542e9..aefd53c4e 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -228,9 +228,6 @@ RaspberryPiBuild { CONFIG += EnableVideo CONFIG += EnablePiP CONFIG += EnableLink - - DEFINES += GST_GL_HAVE_PLATFORM_EGL=1 - DEFINES += HAVE_QT_EGLFS=1 } WindowsBuild { From d464094aaac1ab59e4bb39439138f50c7aef9d6c Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 23:51:40 -0500 Subject: [PATCH 28/29] Change hardware decoder switch to "force software" The UI can't claim to enable hardware decoding with a switch, that would be misleading. The pipeline construction and the different decoder elements for every hardware decoder on every platform are too complex to handle without using decodebin3 to construct a working pipeline automatically and hope that it finds a usable hardware decoder. However, the UI can promise to force software decoding, because we can easily construct a software-only pipeline. --- inc/openhdvideostream.h | 2 +- qml/main.qml | 2 +- qml/ui/AppSettingsPanel.ui.qml | 6 +++--- src/openhdvideostream.cpp | 24 +++++++++++------------- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/inc/openhdvideostream.h b/inc/openhdvideostream.h index 6e2839a0b..3beb14a44 100755 --- a/inc/openhdvideostream.h +++ b/inc/openhdvideostream.h @@ -36,7 +36,7 @@ public slots: bool firstRun = true; bool m_enable_videotest = false; - bool m_enable_hardware_video_decoder = true; + bool m_enable_software_video_decoder = false; bool m_enable_rtp = true; bool m_enable_pip_video = false; diff --git a/qml/main.qml b/qml/main.qml index 8213492c5..89c4fa478 100755 --- a/qml/main.qml +++ b/qml/main.qml @@ -60,7 +60,7 @@ ApplicationWindow { property int pip_video_port: 5601 property int battery_cells: 3 property bool show_pip_video: false - property bool enable_hardware_video_decoder: true + property bool enable_software_video_decoder: false property bool enable_rtp: true property bool enable_speech: true diff --git a/qml/ui/AppSettingsPanel.ui.qml b/qml/ui/AppSettingsPanel.ui.qml index 155afe4b9..11aa42a64 100755 --- a/qml/ui/AppSettingsPanel.ui.qml +++ b/qml/ui/AppSettingsPanel.ui.qml @@ -897,7 +897,7 @@ Item { y: 0 * rowHeight Text { - text: "Use hardware video decoder" + text: "Always use software video decoder" font.weight: Font.Bold font.pixelSize: 13 anchors.leftMargin: 8 @@ -915,8 +915,8 @@ Item { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter - checked: settings.enable_hardware_video_decoder - onCheckedChanged: settings.enable_hardware_video_decoder = checked + checked: settings.enable_software_video_decoder + onCheckedChanged: settings.enable_software_video_decoder = checked } } diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index 96899ef6c..dddf3a5be 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -746,20 +746,18 @@ void OpenHDVideoStream::_start() { } s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; - if (m_enable_hardware_video_decoder) { - qDebug() << "Using hardware decoder"; + if (m_enable_software_video_decoder) { + qDebug() << "Forcing software decoder"; + s << "h264parse !"; + s << "avdec_h264 !"; + } else { + qDebug() << "Using hardware decoder, fallback to software if unavailable"; s << "h264parse !"; #if defined(__rasp_pi__) s << "omxh264dec !"; #else s << "decodebin3 !"; #endif - //s << "amcviddec-omxqcomvideodecoderavc !"; - //s << "amcviddec-omxmtkvideodecoderavc !"; - } else { - qDebug() << "Using software decoder"; - s << "h264parse !"; - s << "avdec_h264 !"; } } s << "queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 !"; @@ -819,7 +817,7 @@ void OpenHDVideoStream::_timer() { } QSettings settings; auto _enable_videotest = settings.value("enable_videotest", false).toBool(); - auto _enable_hardware_video_decoder = settings.value("enable_hardware_video_decoder", true).toBool(); + auto _enable_software_video_decoder = settings.value("enable_software_video_decoder", false).toBool(); auto _enable_rtp = settings.value("enable_rtp", true).toBool(); auto _show_pip_video = settings.value("show_pip_video", false).toBool(); @@ -829,22 +827,22 @@ void OpenHDVideoStream::_timer() { if (m_stream_type == StreamTypeMain) { - if (_enable_videotest != m_enable_videotest || _enable_hardware_video_decoder != m_enable_hardware_video_decoder || _main_video_port != m_video_port || _enable_rtp != m_enable_rtp) { + if (_enable_videotest != m_enable_videotest || _enable_software_video_decoder != m_enable_software_video_decoder || _main_video_port != m_video_port || _enable_rtp != m_enable_rtp) { qDebug() << "Restarting main stream"; stopVideo(); m_enable_videotest = _enable_videotest; - m_enable_hardware_video_decoder = _enable_hardware_video_decoder; + m_enable_software_video_decoder = _enable_software_video_decoder; m_enable_rtp = _enable_rtp; m_video_port = _main_video_port; startVideo(); } } else if (m_stream_type == StreamTypePiP) { - if (m_enable_pip_video != _show_pip_video || _enable_videotest != m_enable_videotest || _enable_hardware_video_decoder != m_enable_hardware_video_decoder || _pip_video_port != m_video_port || _enable_rtp != m_enable_rtp) { + if (m_enable_pip_video != _show_pip_video || _enable_videotest != m_enable_videotest || _enable_software_video_decoder != m_enable_software_video_decoder || _pip_video_port != m_video_port || _enable_rtp != m_enable_rtp) { qDebug() << "Restarting PiP stream"; stopVideo(); m_enable_videotest = _enable_videotest; - m_enable_hardware_video_decoder = _enable_hardware_video_decoder; + m_enable_software_video_decoder = _enable_software_video_decoder; m_enable_rtp = _enable_rtp; m_video_port = _pip_video_port; From 96bfc01933a28d5a10abcaeee860d6a7ec141efe Mon Sep 17 00:00:00 2001 From: Stephen Oliver Date: Mon, 2 Dec 2019 23:54:45 -0500 Subject: [PATCH 29/29] Allow main and PiP video to be enabled separately Previously you could only enable main video or also enable PiP, but we want to have the ability to only enable PiP on the ground pi for the moment until we're sure the main video can be stable when running in the app itself. --- QOpenHD.pro | 18 +++++++++--------- qml/main.qml | 14 +++++++------- qml/ui/AppSettingsPanel.ui.qml | 6 +++--- qml/ui/widgets/VideoWidget.qml | 2 +- src/main.cpp | 27 +++++++++++++++------------ src/openhdvideostream.cpp | 12 ++++++------ 6 files changed, 41 insertions(+), 38 deletions(-) diff --git a/QOpenHD.pro b/QOpenHD.pro index aefd53c4e..0e89f093d 100755 --- a/QOpenHD.pro +++ b/QOpenHD.pro @@ -173,7 +173,7 @@ iOSBuild { CONFIG -= bitcode #CONFIG += EnableGamepads CONFIG += EnableSpeech - CONFIG += EnableVideo + CONFIG += EnableMainVideo CONFIG += EnablePiP CONFIG += EnableLink @@ -199,7 +199,7 @@ MacBuild { #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech - CONFIG += EnableVideo + CONFIG += EnableMainVideo CONFIG += EnablePiP CONFIG += EnableLink @@ -212,7 +212,7 @@ LinuxBuild { QT += x11extras #CONFIG += EnableGamepads CONFIG += EnableJoysticks - CONFIG += EnableVideo + CONFIG += EnableMainVideo CONFIG += EnablePiP CONFIG += EnableLink @@ -225,7 +225,7 @@ RaspberryPiBuild { # handled by another process running on the ground station. We could # replace that at some point but for now it isn't necessary. message("RaspberryPiBuild - config") - CONFIG += EnableVideo + CONFIG += EnableMainVideo CONFIG += EnablePiP CONFIG += EnableLink } @@ -234,7 +234,7 @@ WindowsBuild { #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech - CONFIG += EnableVideo + CONFIG += EnableMainVideo #CONFIG +- EnablePiP CONFIG += EnableLink @@ -249,7 +249,7 @@ AndroidBuild { #CONFIG += EnableGamepads CONFIG += EnableJoysticks CONFIG += EnableSpeech - CONFIG += EnableVideo + CONFIG += EnableMainVideo CONFIG += EnablePiP CONFIG += EnableLink @@ -269,9 +269,9 @@ EnableSpeech { QT += texttospeech } -EnableVideo { - message("EnableVideo") - DEFINES += ENABLE_VIDEO +EnableMainVideo { + message("EnableMainVideo") + DEFINES += ENABLE_MAIN_VIDEO } EnablePiP { diff --git a/qml/main.qml b/qml/main.qml index 89c4fa478..eb6ecfdb0 100755 --- a/qml/main.qml +++ b/qml/main.qml @@ -19,7 +19,7 @@ ApplicationWindow { minimumHeight: 320 minimumWidth: 480 title: qsTr("Open.HD") - color: EnableVideo ? "black" : "#00000000" + color: EnableMainVideo ? "black" : "#00000000" visibility: UseFullscreen ? "FullScreen" : "AutomaticVisibility" @@ -32,11 +32,11 @@ ApplicationWindow { OpenHDRC.initRC; } initialised = true; - if (EnableVideo) { + if (EnableMainVideo) { MainStream.startVideo(); - if (EnablePiP) { - PiPStream.startVideo(); - } + } + if (EnablePiP) { + PiPStream.startVideo(); } } } @@ -46,7 +46,7 @@ ApplicationWindow { // to be initialized, depending on the order they appear in the QML, will simply // not work on desktop linux. Loader { - source: (EnableVideo && EnablePiP) ? "DummyVideoItem.qml" : "" + source: (EnableMainVideo && EnablePiP) ? "DummyVideoItem.qml" : "" } /* @@ -118,7 +118,7 @@ ApplicationWindow { width: parent.width height: parent.height z: 1.0 - source: EnableVideo ? "MainVideoItem.qml" : "" + source: EnableMainVideo ? "MainVideoItem.qml" : "" } Connections { diff --git a/qml/ui/AppSettingsPanel.ui.qml b/qml/ui/AppSettingsPanel.ui.qml index 11aa42a64..3f2cdc83f 100755 --- a/qml/ui/AppSettingsPanel.ui.qml +++ b/qml/ui/AppSettingsPanel.ui.qml @@ -57,10 +57,10 @@ Item { TabButton { text: qsTr("Video") - width: EnableVideo ? implicitWidth : 0 + width: (EnableMainVideo || EnablePiP) ? implicitWidth : 0 height: 48 font.pixelSize: 13 - visible: EnableVideo + visible: (EnableMainVideo || EnablePiP) } @@ -888,7 +888,7 @@ Item { contentHeight: 5 * rowHeight clip: true - visible: EnableVideo + visible: EnableMainVideo || EnablePiP Rectangle { width: parent.width diff --git a/qml/ui/widgets/VideoWidget.qml b/qml/ui/widgets/VideoWidget.qml index 152a9e97e..c7eea9709 100755 --- a/qml/ui/widgets/VideoWidget.qml +++ b/qml/ui/widgets/VideoWidget.qml @@ -3,5 +3,5 @@ import QtQuick.Window 2.12 import QtQuick.Layouts 1.12 Loader { - source: (EnableVideo && EnablePiP) ? "VideoWidgetForm.ui.qml" : "" + source: EnablePiP ? "VideoWidgetForm.ui.qml" : "" } diff --git a/src/main.cpp b/src/main.cpp index 883f458ad..8bac6b0ce 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,7 +31,7 @@ const QVector permissions({"android.permission.INTERNET", #include "util.h" -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) #include #endif @@ -120,29 +120,31 @@ int main(int argc, char *argv[]) { QObject::connect(&timer, &QTimer::timeout, openhd, &OpenHD::updateFlightTimer); timer.start(1000); -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) OpenHDVideoStream* stream = new OpenHDVideoStream(argc, argv); +#endif #if defined(ENABLE_PIP) OpenHDVideoStream* stream2 = new OpenHDVideoStream(argc, argv); -#endif #endif + QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("OpenHD", openhd); -#if defined(ENABLE_VIDEO) - engine.rootContext()->setContextProperty("EnableVideo", QVariant(true)); +#if defined(ENABLE_MAIN_VIDEO) + engine.rootContext()->setContextProperty("EnableMainVideo", QVariant(true)); engine.rootContext()->setContextProperty("MainStream", stream); +#else + engine.rootContext()->setContextProperty("EnableMainVideo", QVariant(false)); +#endif + #if defined(ENABLE_PIP) engine.rootContext()->setContextProperty("EnablePiP", QVariant(true)); engine.rootContext()->setContextProperty("PiPStream", stream2); #else engine.rootContext()->setContextProperty("EnablePiP", QVariant(false)); #endif -#else - engine.rootContext()->setContextProperty("EnableVideo", QVariant(false)); -#endif #if defined(ENABLE_RC) @@ -176,19 +178,20 @@ int main(int argc, char *argv[]) { qDebug() << "Running QML"; -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) stream->init(&engine, StreamTypeMain); +#endif #if defined(ENABLE_PIP) stream2->init(&engine, StreamTypePiP); -#endif #endif const int retval = app.exec(); -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) stream->stopVideo(); +#endif + #if defined(ENABLE_PIP) stream2->stopVideo(); -#endif #endif return retval; } diff --git a/src/openhdvideostream.cpp b/src/openhdvideostream.cpp index dddf3a5be..9e6db3bc0 100644 --- a/src/openhdvideostream.cpp +++ b/src/openhdvideostream.cpp @@ -148,7 +148,7 @@ G_PASTE(g_io_module_, G_PASTE(name, _load_static)) () #define GST_MOBILE_PLUGIN_RTPMANAGER #endif -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) #ifndef __desktoplinux__ #ifndef __rasp_pi__ GST_PLUGIN_STATIC_DECLARE(qmlgl); @@ -410,7 +410,7 @@ OpenHDVideoStream::OpenHDVideoStream(int &argc, char *argv[], QObject * parent): qDebug() << "OpenHDVideoStream::OpenHDVideoStream()"; #ifdef __macos__ - #ifdef ENABLE_VIDEO + #if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) #ifdef RELEASE_BUILD QString currentDir = QCoreApplication::applicationDirPath(); putenv("GST_PLUGIN_SCANNER", currentDir, "/../Frameworks/GStreamer.framework/Versions/1.0/libexec/gstreamer-1.0/gst-plugin-scanner"); @@ -482,7 +482,7 @@ OpenHDVideoStream::OpenHDVideoStream(int &argc, char *argv[], QObject * parent): //gst_debug_remove_log_function(gst_debug_log_default); //gst_debug_add_log_function(printf_extension_log_func, nullptr, nullptr); -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) #ifndef __desktoplinux__ #ifndef __rasp_pi__ GST_PLUGIN_STATIC_REGISTER(qmlgl); @@ -855,13 +855,13 @@ void OpenHDVideoStream::_timer() { } void OpenHDVideoStream::startVideo() { -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) QFuture future = QtConcurrent::run(this, &OpenHDVideoStream::_start); #endif } void OpenHDVideoStream::_stop() { -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) qDebug() << "OpenHDVideoStream::_stop()"; if (m_pipeline != nullptr) { @@ -872,7 +872,7 @@ void OpenHDVideoStream::_stop() { } void OpenHDVideoStream::stopVideo() { -#if defined(ENABLE_VIDEO) +#if defined(ENABLE_MAIN_VIDEO) || defined(ENABLE_PIP) QFuture future = QtConcurrent::run(this, &OpenHDVideoStream::_stop); #endif }