From 026e6057505c358f7dfbceb808f20a374794d769 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Thu, 23 Feb 2017 14:39:02 -0800 Subject: [PATCH 1/3] Rename SettingsGroup json files --- qgroundcontrol.qrc | 8 +-- src/Settings/App.SettingsGroup.json | 86 +++++++++++++++++++++++++++++ src/Settings/AppSettings.cc | 2 +- src/Settings/AutoConnect.SettingsGroup.json | 44 +++++++++++++++ src/Settings/AutoConnectSettings.cc | 2 +- src/Settings/SettingsGroup.app.json | 86 ----------------------------- src/Settings/SettingsGroup.autoConnect.json | 44 --------------- src/Settings/SettingsGroup.cc | 2 +- src/Settings/SettingsGroup.units.json | 2 - src/Settings/Units.SettingsGroup.json | 2 + src/Settings/UnitsSettings.cc | 2 +- 11 files changed, 140 insertions(+), 140 deletions(-) create mode 100644 src/Settings/App.SettingsGroup.json create mode 100644 src/Settings/AutoConnect.SettingsGroup.json delete mode 100644 src/Settings/SettingsGroup.app.json delete mode 100644 src/Settings/SettingsGroup.autoConnect.json delete mode 100644 src/Settings/SettingsGroup.units.json create mode 100644 src/Settings/Units.SettingsGroup.json diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index c9620f6..870f120 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -179,10 +179,10 @@ src/Vehicle/GPSFact.json src/Vehicle/WindFact.json src/Vehicle/VibrationFact.json - src/Settings/SettingsGroup.app.json - src/Settings/SettingsGroup.autoConnect.json - src/Settings/SettingsGroup.units.json - src/Settings/SettingsGroup.video.json + src/Settings/App.SettingsGroup.json + src/Settings/AutoConnect.SettingsGroup.json + src/Settings/Units.SettingsGroup.json + src/Settings/Video.SettingsGroup.json src/MissionManager/RallyPoint.FactMetaData.json src/MissionManager/FWLandingPattern.FactMetaData.json src/MissionManager/Survey.FactMetaData.json diff --git a/src/Settings/App.SettingsGroup.json b/src/Settings/App.SettingsGroup.json new file mode 100644 index 0000000..439727c --- /dev/null +++ b/src/Settings/App.SettingsGroup.json @@ -0,0 +1,86 @@ +[ +{ + "name": "OfflineEditingFirmwareType", + "shortDescription": "Offline editing firmware type", + "type": "uint32", + "enumStrings": "ArduPilot,PX4 Pro,Mavlink Generic", + "enumValues": "3,12,0", + "defaultValue": 3 +}, +{ + "name": "OfflineEditingVehicleType", + "shortDescription": "Offline editing vehicle type", + "type": "uint32", + "enumStrings": "Fixed Wing,Multi-Rotor,VTOL,Rover,Sub", + "enumValues": "1,2,19,10,12", + "defaultValue": 1 +}, +{ + "name": "OfflineEditingCruiseSpeed", + "shortDescription": "Offline editing cruise speed", + "longDescription": "This value defines the cruising speed for forward flight vehicles for use in calculating mission duration when not connected to a vehicle.", + "type": "double", + "defaultValue": 16.0, + "min": 1.0, + "units": "m/s", + "decimalPlaces": 2 +}, +{ + "name": "OfflineEditingHoverSpeed", + "shortDescription": "Offline editing hover speed", + "longDescription": "This value defines the cruising speed for multi-rotor vehicles for use in calculating mission duration when not connected to a vehicle.", + "type": "double", + "defaultValue": 4.0, + "min": 1.0, + "units": "m/s", + "decimalPlaces": 2 +}, +{ + "name": "batteryPercentRemainingAnnounce", + "shortDescription": "Announce battery remaining percent", + "longDescription": "QGroundControl will announce the remaining battery percent when it falls below the specified percentage.", + "type": "uint32", + "defaultValue": 30, + "units": "%", + "min": 0, + "max": 100 +}, +{ + "name": "DefaultMissionItemAltitude", + "shortDescription": "Default value for altitude", + "longDescription": "This value specifies the default altitude for new items added to a mission.", + "type": "double", + "defaultValue": 50.0, + "min": 0.0, + "units": "meters", + "decimalPlaces": 2 +}, +{ + "name": "MissionAutoLoadDir", + "shortDescription": "Mission auto load directory", + "longDescription": "The directory from which missions will be automatically loaded onto a vehicle when it connects. The mission file must be named AutoLoad#.mission where the # is replaced with the vehicle id.", + "type": "string", + "defaultValue": "" +}, +{ + "name": "PromptFLightDataSave", + "shortDescription": "Prompt to save Flight Data Log after each flight", + "longDescription": "If this option is enabled you will be prompted to save Flight Data Log after each flight completes.", + "type": "bool", + "defaultValue": true +}, +{ + "name": "PromptFLightDataSaveNotArmed", + "shortDescription": "Prompt to save Flight Data Log even if vehicle was not armed", + "longDescription": "If this option is enabled you will be prompted to save Flight Data Log even if vehicle was never armed.", + "type": "bool", + "defaultValue": false +}, +{ + "name": "AudioMuted", + "shortDescription": "Mute audio output", + "longDescription": "If this option is enabled all audio output will be muted.", + "type": "bool", + "defaultValue": false +} +] diff --git a/src/Settings/AppSettings.cc b/src/Settings/AppSettings.cc index c0fb64f..d2284a7 100644 --- a/src/Settings/AppSettings.cc +++ b/src/Settings/AppSettings.cc @@ -12,7 +12,7 @@ #include #include -const char* AppSettings::appSettingsGroupName = "app"; +const char* AppSettings::appSettingsGroupName = "App"; const char* AppSettings::offlineEditingFirmwareTypeSettingsName = "OfflineEditingFirmwareType"; const char* AppSettings::offlineEditingVehicleTypeSettingsName = "OfflineEditingVehicleType"; const char* AppSettings::offlineEditingCruiseSpeedSettingsName = "OfflineEditingCruiseSpeed"; diff --git a/src/Settings/AutoConnect.SettingsGroup.json b/src/Settings/AutoConnect.SettingsGroup.json new file mode 100644 index 0000000..afce204 --- /dev/null +++ b/src/Settings/AutoConnect.SettingsGroup.json @@ -0,0 +1,44 @@ +[ +{ + "name": "AutoconnectUDP", + "shortDescription": "Automatically open a connection over UDP", + "longDescription": "If this option is enabled GroundControl will automatically connect to a vehicle which is detected on a UDP communication link.", + "type": "bool", + "defaultValue": true +}, +{ + "name": "AutoconnectPixhawk", + "shortDescription": "Automatically connect to a Pixhawk board", + "longDescription": "If this option is enabled GroundControl will automatically connect to a Pixhawk board which is connected via USB.", + "type": "bool", + "defaultValue": true +}, +{ + "name": "Autoconnect3DRRadio", + "shortDescription": "Automatically connect to a SiK Radio", + "longDescription": "If this option is enabled GroundControl will automatically connect to a vehicle which is detected on a SiK Radio communication link.", + "type": "bool", + "defaultValue": true +}, +{ + "name": "AutoconnectPX4Flow", + "shortDescription": "Automatically connect to a P4 Flow", + "longDescription": "If this option is enabled GroundControl will automatically connect to a PX4 Flow board which is connected via USB.", + "type": "bool", + "defaultValue": true +}, +{ + "name": "AutoconnectRTKGPS", + "shortDescription": "Automatically connect to an RTK GPS", + "longDescription": "If this option is enabled GroundControl will automatically connect to an RTK GPS which is connected via USB.", + "type": "bool", + "defaultValue": true +}, +{ + "name": "AutoconnectLibrePilot", + "shortDescription": "Automatically connect to a LibrePilot", + "longDescription": "If this option is enabled GroundControl will automatically connect to a LibrePilot board which is connected via USB.", + "type": "bool", + "defaultValue": true +} +] diff --git a/src/Settings/AutoConnectSettings.cc b/src/Settings/AutoConnectSettings.cc index 008c08e..fc1247f 100644 --- a/src/Settings/AutoConnectSettings.cc +++ b/src/Settings/AutoConnectSettings.cc @@ -22,7 +22,7 @@ const char* AutoConnectSettings:: autoConnectPX4FlowSettingsName = "Autocon const char* AutoConnectSettings:: autoConnectRTKGPSSettingsName = "AutoconnectRTKGPS"; const char* AutoConnectSettings:: autoConnectLibrePilotSettingsName = "AutoconnectLibrePilot"; -const char* AutoConnectSettings::autoConnectSettingsGroupName = "autoConnect"; +const char* AutoConnectSettings::autoConnectSettingsGroupName = "AutoConnect"; AutoConnectSettings::AutoConnectSettings(QObject* parent) : SettingsGroup(autoConnectSettingsGroupName, _settingsGroup, parent) diff --git a/src/Settings/SettingsGroup.app.json b/src/Settings/SettingsGroup.app.json deleted file mode 100644 index 439727c..0000000 --- a/src/Settings/SettingsGroup.app.json +++ /dev/null @@ -1,86 +0,0 @@ -[ -{ - "name": "OfflineEditingFirmwareType", - "shortDescription": "Offline editing firmware type", - "type": "uint32", - "enumStrings": "ArduPilot,PX4 Pro,Mavlink Generic", - "enumValues": "3,12,0", - "defaultValue": 3 -}, -{ - "name": "OfflineEditingVehicleType", - "shortDescription": "Offline editing vehicle type", - "type": "uint32", - "enumStrings": "Fixed Wing,Multi-Rotor,VTOL,Rover,Sub", - "enumValues": "1,2,19,10,12", - "defaultValue": 1 -}, -{ - "name": "OfflineEditingCruiseSpeed", - "shortDescription": "Offline editing cruise speed", - "longDescription": "This value defines the cruising speed for forward flight vehicles for use in calculating mission duration when not connected to a vehicle.", - "type": "double", - "defaultValue": 16.0, - "min": 1.0, - "units": "m/s", - "decimalPlaces": 2 -}, -{ - "name": "OfflineEditingHoverSpeed", - "shortDescription": "Offline editing hover speed", - "longDescription": "This value defines the cruising speed for multi-rotor vehicles for use in calculating mission duration when not connected to a vehicle.", - "type": "double", - "defaultValue": 4.0, - "min": 1.0, - "units": "m/s", - "decimalPlaces": 2 -}, -{ - "name": "batteryPercentRemainingAnnounce", - "shortDescription": "Announce battery remaining percent", - "longDescription": "QGroundControl will announce the remaining battery percent when it falls below the specified percentage.", - "type": "uint32", - "defaultValue": 30, - "units": "%", - "min": 0, - "max": 100 -}, -{ - "name": "DefaultMissionItemAltitude", - "shortDescription": "Default value for altitude", - "longDescription": "This value specifies the default altitude for new items added to a mission.", - "type": "double", - "defaultValue": 50.0, - "min": 0.0, - "units": "meters", - "decimalPlaces": 2 -}, -{ - "name": "MissionAutoLoadDir", - "shortDescription": "Mission auto load directory", - "longDescription": "The directory from which missions will be automatically loaded onto a vehicle when it connects. The mission file must be named AutoLoad#.mission where the # is replaced with the vehicle id.", - "type": "string", - "defaultValue": "" -}, -{ - "name": "PromptFLightDataSave", - "shortDescription": "Prompt to save Flight Data Log after each flight", - "longDescription": "If this option is enabled you will be prompted to save Flight Data Log after each flight completes.", - "type": "bool", - "defaultValue": true -}, -{ - "name": "PromptFLightDataSaveNotArmed", - "shortDescription": "Prompt to save Flight Data Log even if vehicle was not armed", - "longDescription": "If this option is enabled you will be prompted to save Flight Data Log even if vehicle was never armed.", - "type": "bool", - "defaultValue": false -}, -{ - "name": "AudioMuted", - "shortDescription": "Mute audio output", - "longDescription": "If this option is enabled all audio output will be muted.", - "type": "bool", - "defaultValue": false -} -] diff --git a/src/Settings/SettingsGroup.autoConnect.json b/src/Settings/SettingsGroup.autoConnect.json deleted file mode 100644 index afce204..0000000 --- a/src/Settings/SettingsGroup.autoConnect.json +++ /dev/null @@ -1,44 +0,0 @@ -[ -{ - "name": "AutoconnectUDP", - "shortDescription": "Automatically open a connection over UDP", - "longDescription": "If this option is enabled GroundControl will automatically connect to a vehicle which is detected on a UDP communication link.", - "type": "bool", - "defaultValue": true -}, -{ - "name": "AutoconnectPixhawk", - "shortDescription": "Automatically connect to a Pixhawk board", - "longDescription": "If this option is enabled GroundControl will automatically connect to a Pixhawk board which is connected via USB.", - "type": "bool", - "defaultValue": true -}, -{ - "name": "Autoconnect3DRRadio", - "shortDescription": "Automatically connect to a SiK Radio", - "longDescription": "If this option is enabled GroundControl will automatically connect to a vehicle which is detected on a SiK Radio communication link.", - "type": "bool", - "defaultValue": true -}, -{ - "name": "AutoconnectPX4Flow", - "shortDescription": "Automatically connect to a P4 Flow", - "longDescription": "If this option is enabled GroundControl will automatically connect to a PX4 Flow board which is connected via USB.", - "type": "bool", - "defaultValue": true -}, -{ - "name": "AutoconnectRTKGPS", - "shortDescription": "Automatically connect to an RTK GPS", - "longDescription": "If this option is enabled GroundControl will automatically connect to an RTK GPS which is connected via USB.", - "type": "bool", - "defaultValue": true -}, -{ - "name": "AutoconnectLibrePilot", - "shortDescription": "Automatically connect to a LibrePilot", - "longDescription": "If this option is enabled GroundControl will automatically connect to a LibrePilot board which is connected via USB.", - "type": "bool", - "defaultValue": true -} -] diff --git a/src/Settings/SettingsGroup.cc b/src/Settings/SettingsGroup.cc index c29c425..e0f1ac2 100644 --- a/src/Settings/SettingsGroup.cc +++ b/src/Settings/SettingsGroup.cc @@ -17,7 +17,7 @@ SettingsGroup::SettingsGroup(const QString& name, const QString& settingsGroup, , _settingsGroup(settingsGroup) , _visible(qgcApp()->toolbox()->corePlugin()->overrideSettingsGroupVisibility(name)) { - QString jsonNameFormat(":/json/SettingsGroup.%1.json"); + QString jsonNameFormat(":/json/%1.SettingsGroup.json"); _nameToMetaDataMap = FactMetaData::createMapFromJsonFile(jsonNameFormat.arg(name), this); } diff --git a/src/Settings/SettingsGroup.units.json b/src/Settings/SettingsGroup.units.json deleted file mode 100644 index 0d4f101..0000000 --- a/src/Settings/SettingsGroup.units.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/src/Settings/Units.SettingsGroup.json b/src/Settings/Units.SettingsGroup.json new file mode 100644 index 0000000..0d4f101 --- /dev/null +++ b/src/Settings/Units.SettingsGroup.json @@ -0,0 +1,2 @@ +[ +] diff --git a/src/Settings/UnitsSettings.cc b/src/Settings/UnitsSettings.cc index 608e45c..0d5c6e0 100644 --- a/src/Settings/UnitsSettings.cc +++ b/src/Settings/UnitsSettings.cc @@ -12,7 +12,7 @@ #include #include -const char* UnitsSettings::unitsSettingsGroupName = "units"; +const char* UnitsSettings::unitsSettingsGroupName = "Units"; const char* UnitsSettings::distanceUnitsSettingsName = "DistanceUnits"; const char* UnitsSettings::areaUnitsSettingsName = "AreaUnits"; const char* UnitsSettings::speedUnitsSettingsName = "SpeedUnits"; From 23f57eb907acc144cd1d77bf5e2b7d1532703454 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Thu, 23 Feb 2017 14:39:20 -0800 Subject: [PATCH 2/3] Move video settings to new SettingsGroup system --- src/FlightDisplay/VideoManager.cc | 193 +++++++-------------------------- src/FlightDisplay/VideoManager.h | 42 ++----- src/Settings/SettingsGroup.video.json | 2 - src/Settings/Video.SettingsGroup.json | 31 ++++++ src/Settings/VideoSettings.cc | 83 +++++++++++++- src/Settings/VideoSettings.h | 23 ++++ src/VideoStreaming/VideoReceiver.cc | 20 ++-- src/VideoStreaming/VideoReceiver.h | 2 - src/ui/preferences/GeneralSettings.qml | 57 ++++------ 9 files changed, 209 insertions(+), 244 deletions(-) delete mode 100644 src/Settings/SettingsGroup.video.json create mode 100644 src/Settings/Video.SettingsGroup.json diff --git a/src/FlightDisplay/VideoManager.cc b/src/FlightDisplay/VideoManager.cc index 09a7c32..e2cf398 100644 --- a/src/FlightDisplay/VideoManager.cc +++ b/src/FlightDisplay/VideoManager.cc @@ -25,19 +25,7 @@ #include "QGCToolbox.h" #include "QGCCorePlugin.h" #include "QGCOptions.h" - -static const char* kVideoSourceKey = "VideoSource"; -static const char* kVideoUDPPortKey = "VideoUDPPort"; -static const char* kVideoRTSPUrlKey = "VideoRTSPUrl"; -static const char* kNoVideo = "No Video Available"; - -#if defined(QGC_GST_STREAMING) -#if defined(QGC_ENABLE_VIDEORECORDING) -static const char* kVideoSavePathKey= "VideoSavePath"; -#endif -static const char* kUDPStream = "UDP Video Stream"; -static const char* kRTSPStream = "RTSP Video Stream"; -#endif +#include "Settings/SettingsManager.h" QGC_LOGGING_CATEGORY(VideoManagerLog, "VideoManagerLog") @@ -47,8 +35,8 @@ VideoManager::VideoManager(QGCApplication* app) , _videoSurface(NULL) , _videoReceiver(NULL) , _videoRunning(false) - , _udpPort(5600) //-- Defalut Port 5600 == Solo UDP Port , _init(false) + , _videoSettings(NULL) { } @@ -65,31 +53,36 @@ VideoManager::setToolbox(QGCToolbox *toolbox) QGCTool::setToolbox(toolbox); QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); qmlRegisterUncreatableType("QGroundControl.VideoManager", 1, 0, "VideoManager", "Reference only"); - //-- Get saved settings + + _videoSettings = toolbox->settingsManager()->videoSettings(); + QString videoSource = _videoSettings->videoSource()->rawValue().toString(); + #if defined(QGC_GST_STREAMING) - QSettings settings; -#if defined(NO_UDP_VIDEO) - setVideoSource(settings.value(kVideoSourceKey, kRTSPStream).toString()); -#else - setVideoSource(settings.value(kVideoSourceKey, kUDPStream).toString()); -#endif - //-- Check if core plugin defines its own video requirements - if(qgcApp()->toolbox()->corePlugin()->options()->definesVideo()) { - if(qgcApp()->toolbox()->corePlugin()->options()->videoUDPPort()) { - setUdpPort(qgcApp()->toolbox()->corePlugin()->options()->videoUDPPort()); - setVideoSource(kUDPStream); - } else { - setVideoSource(kRTSPStream); - setRtspURL(qgcApp()->toolbox()->corePlugin()->options()->videoRSTPUrl()); - } - } else { - setUdpPort(settings.value(kVideoUDPPortKey, 5600).toUInt()); - setRtspURL(settings.value(kVideoRTSPUrlKey, "rtsp://192.168.42.1:554/live").toString()); //-- Example RTSP URL - } -#if defined(QGC_ENABLE_VIDEORECORDING) - setVideoSavePath(settings.value(kVideoSavePathKey, QDir::homePath()).toString()); +#ifndef QGC_DISABLE_UVC + // If we are using a UVC camera setup the device name + QList cameras = QCameraInfo::availableCameras(); + foreach (const QCameraInfo &cameraInfo, cameras) { + if(cameraInfo.description() == videoSource) { + _videoSourceID = cameraInfo.deviceName(); + emit videoSourceIDChanged(); + qCDebug(VideoManagerLog) << "Found USB source:" << _videoSourceID << " Name:" << videoSource; + break; + } + } #endif + + emit isGStreamerChanged(); + qCDebug(VideoManagerLog) << "New Video Source:" << videoSource; + + if(_videoReceiver) { + if(isGStreamer()) { + _videoReceiver->start(); + } else { + _videoReceiver->stop(); + } + } #endif + _init = true; #if defined(QGC_GST_STREAMING) _updateVideo(); @@ -105,7 +98,8 @@ VideoManager::hasVideo() #if defined(QGC_GST_STREAMING) return true; #endif - return !_videoSource.isEmpty(); + QString videoSource = _videoSettings->videoSource()->rawValue().toString(); + return !videoSource.isEmpty() && videoSource != VideoSettings::videoSourceNoVideo; } //----------------------------------------------------------------------------- @@ -113,7 +107,8 @@ bool VideoManager::isGStreamer() { #if defined(QGC_GST_STREAMING) - return _videoSource == kUDPStream || _videoSource == kRTSPStream; + QString videoSource = _videoSettings->videoSource()->rawValue().toString(); + return videoSource == VideoSettings::videoSourceUDP || videoSource == VideoSettings::videoSourceRTSP; #else return false; #endif @@ -129,118 +124,6 @@ VideoManager::uvcEnabled() #endif //----------------------------------------------------------------------------- -void -VideoManager::setVideoSource(QString vSource) -{ - if(vSource == kNoVideo) - return; - _videoSource = vSource; - QSettings settings; - settings.setValue(kVideoSourceKey, vSource); - emit videoSourceChanged(); -#ifndef QGC_DISABLE_UVC - QList cameras = QCameraInfo::availableCameras(); - foreach (const QCameraInfo &cameraInfo, cameras) { - if(cameraInfo.description() == vSource) { - _videoSourceID = cameraInfo.deviceName(); - emit videoSourceIDChanged(); - qCDebug(VideoManagerLog) << "Found USB source:" << _videoSourceID << " Name:" << _videoSource; - break; - } - } -#endif - emit isGStreamerChanged(); - qCDebug(VideoManagerLog) << "New Video Source:" << vSource; - /* - * Not working. Requires restart for now. (Undef KRTSP/kUDP above when enabling this) - if(isGStreamer()) - _updateVideo(); - */ - if(_videoReceiver) { - if(isGStreamer()) { - _videoReceiver->start(); - } else { - _videoReceiver->stop(); - } - } -} - -//----------------------------------------------------------------------------- -void -VideoManager::setUdpPort(quint16 port) -{ - _udpPort = port; - QSettings settings; - settings.setValue(kVideoUDPPortKey, port); - emit udpPortChanged(); - /* - * Not working. Requires restart for now. (Undef KRTSP/kUDP above when enabling this) - if(_videoSource == kUDPStream) - _updateVideo(); - */ -} - -//----------------------------------------------------------------------------- -void -VideoManager::setRtspURL(QString url) -{ - _rtspURL = url; - QSettings settings; - settings.setValue(kVideoRTSPUrlKey, url); - emit rtspURLChanged(); - /* - * Not working. Requires restart for now. (Undef KRTSP/kUDP above when enabling this) - if(_videoSource == kRTSPStream) - _updateVideo(); - */ -} - -void -VideoManager::setVideoSavePathByUrl(QUrl url) { -#if defined(QGC_ENABLE_VIDEORECORDING) - setVideoSavePath(url.toLocalFile()); -#else - Q_UNUSED(url); -#endif -} - -void -VideoManager::setVideoSavePath(QString path) -{ -#if defined(QGC_ENABLE_VIDEORECORDING) - _videoSavePath = path; - QSettings settings; - settings.setValue(kVideoSavePathKey, path); - if(_videoReceiver) - _videoReceiver->setVideoSavePath(_videoSavePath); - emit videoSavePathChanged(); -#else - Q_UNUSED(path); -#endif -} - -//----------------------------------------------------------------------------- -QStringList -VideoManager::videoSourceList() -{ - _videoSourceList.clear(); -#if defined(QGC_GST_STREAMING) - _videoSourceList.append(kUDPStream); - _videoSourceList.append(kRTSPStream); -#endif -#ifndef QGC_DISABLE_UVC - QList cameras = QCameraInfo::availableCameras(); - foreach (const QCameraInfo &cameraInfo, cameras) { - qCDebug(VideoManagerLog) << "UVC Video source ID:" << cameraInfo.deviceName() << " Name:" << cameraInfo.description(); - _videoSourceList.append(cameraInfo.description()); - } -#endif - if(_videoSourceList.count() == 0) - _videoSourceList.append(kNoVideo); - return _videoSourceList; -} - -//----------------------------------------------------------------------------- void VideoManager::_updateTimer() { #if defined(QGC_GST_STREAMING) @@ -292,13 +175,11 @@ void VideoManager::_updateVideo() _videoReceiver = new VideoReceiver(this); #if defined(QGC_GST_STREAMING) _videoReceiver->setVideoSink(_videoSurface->videoSink()); - if(_videoSource == kUDPStream) - _videoReceiver->setUri(QStringLiteral("udp://0.0.0.0:%1").arg(_udpPort)); + QString videoSource = _videoSettings->videoSource()->rawValue().toString(); + if (_videoSettings->videoSource()->rawValue().toString() == VideoSettings::videoSourceUDP) + _videoReceiver->setUri(QStringLiteral("udp://0.0.0.0:%1").arg(_videoSettings->udpPort()->rawValue().toInt())); else - _videoReceiver->setUri(_rtspURL); -#if defined(QGC_ENABLE_VIDEORECORDING) - _videoReceiver->setVideoSavePath(_videoSavePath); -#endif + _videoReceiver->setUri(_videoSettings->rtspUrl()->rawValue().toString()); #endif _videoReceiver->start(); } diff --git a/src/FlightDisplay/VideoManager.h b/src/FlightDisplay/VideoManager.h index 912e577..f96f1ac 100644 --- a/src/FlightDisplay/VideoManager.h +++ b/src/FlightDisplay/VideoManager.h @@ -22,6 +22,8 @@ Q_DECLARE_LOGGING_CATEGORY(VideoManagerLog) +class VideoSettings; + class VideoManager : public QGCTool { Q_OBJECT @@ -33,28 +35,16 @@ public: Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged) Q_PROPERTY(bool isGStreamer READ isGStreamer NOTIFY isGStreamerChanged) Q_PROPERTY(QString videoSourceID READ videoSourceID NOTIFY videoSourceIDChanged) - Q_PROPERTY(QString videoSource READ videoSource WRITE setVideoSource NOTIFY videoSourceChanged) - Q_PROPERTY(QStringList videoSourceList READ videoSourceList NOTIFY videoSourceListChanged) Q_PROPERTY(bool videoRunning READ videoRunning NOTIFY videoRunningChanged) - Q_PROPERTY(quint16 udpPort READ udpPort WRITE setUdpPort NOTIFY udpPortChanged) - Q_PROPERTY(QString rtspURL READ rtspURL WRITE setRtspURL NOTIFY rtspURLChanged) - Q_PROPERTY(QString videoSavePath READ videoSavePath NOTIFY videoSavePathChanged) Q_PROPERTY(bool uvcEnabled READ uvcEnabled CONSTANT) Q_PROPERTY(VideoSurface* videoSurface MEMBER _videoSurface CONSTANT) Q_PROPERTY(VideoReceiver* videoReceiver MEMBER _videoReceiver CONSTANT) Q_PROPERTY(bool recordingEnabled READ recordingEnabled CONSTANT) - Q_INVOKABLE void setVideoSavePathByUrl (QUrl url); - bool hasVideo (); bool isGStreamer (); bool videoRunning () { return _videoRunning; } QString videoSourceID () { return _videoSourceID; } - QString videoSource () { return _videoSource; } - QStringList videoSourceList (); - quint16 udpPort () { return _udpPort; } - QString rtspURL () { return _rtspURL; } - QString videoSavePath () { return _videoSavePath; } #if defined(QGC_DISABLE_UVC) bool uvcEnabled () { return false; } @@ -68,43 +58,29 @@ public: bool recordingEnabled () { return false; } #endif - void setVideoSource (QString vSource); - void setUdpPort (quint16 port); - void setRtspURL (QString url); - void setVideoSavePath (QString path); - // Override from QGCTool void setToolbox (QGCToolbox *toolbox); signals: void hasVideoChanged (); void videoRunningChanged (); - void videoSourceChanged (); - void videoSourceListChanged (); void isGStreamerChanged (); void videoSourceIDChanged (); - void udpPortChanged (); - void rtspURLChanged (); - void videoSavePathChanged (); private: void _updateTimer (); void _updateVideo (); private: - VideoSurface* _videoSurface; - VideoReceiver* _videoReceiver; - bool _videoRunning; + VideoSurface* _videoSurface; + VideoReceiver* _videoReceiver; + bool _videoRunning; #if defined(QGC_GST_STREAMING) - QTimer _frameTimer; + QTimer _frameTimer; #endif - QString _videoSource; - QString _videoSourceID; - QStringList _videoSourceList; - quint16 _udpPort; - QString _rtspURL; - QString _videoSavePath; - bool _init; + QString _videoSourceID; + bool _init; + VideoSettings* _videoSettings; }; #endif diff --git a/src/Settings/SettingsGroup.video.json b/src/Settings/SettingsGroup.video.json deleted file mode 100644 index 0d4f101..0000000 --- a/src/Settings/SettingsGroup.video.json +++ /dev/null @@ -1,2 +0,0 @@ -[ -] diff --git a/src/Settings/Video.SettingsGroup.json b/src/Settings/Video.SettingsGroup.json new file mode 100644 index 0000000..c9835ee --- /dev/null +++ b/src/Settings/Video.SettingsGroup.json @@ -0,0 +1,31 @@ +[ +{ + "name": "VideoSource", + "shortDescription": "Video source", + "longDescription": "Source for video. UDP, RTSP and UVC Cameras may be supported supported depending on Vehicle and QGroundControl version.", + "type": "string", + "defaultValue": "" +}, +{ + "name": "VideoUDPPort", + "shortDescription": "Video UDP Port", + "longDescription": "UDP port to bind to for video stream.", + "type": "uint16", + "min": 1025, + "defaultValue": 5600 +}, +{ + "name": "VideoRTSPUrl", + "shortDescription": "Video RTSP Url", + "longDescription": "RTSP url address and port to bind to for video stream. Example: rtsp://192.168.42.1:554/live", + "type": "string", + "defaultValue": "" +}, +{ + "name": "VideoSavePath", + "shortDescription": "Video save directory", + "longDescription": "Directory to save videos to.", + "type": "string", + "defaultValue": "" +} +] diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index cd0228e..ca2a9ed 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -11,12 +11,93 @@ #include #include +#include +#include -const char* VideoSettings::videoSettingsGroupName = "video"; +const char* VideoSettings::videoSettingsGroupName = "Video"; + +const char* VideoSettings::videoSourceName = "VideoSource"; +const char* VideoSettings::udpPortName = "VideoUDPPort"; +const char* VideoSettings::rtspUrlName = "VideoRTSPUrl"; +const char* VideoSettings::videoSavePathName = "VideoSavePath"; + +const char* VideoSettings::videoSourceNoVideo = "No Video Available"; +const char* VideoSettings::videoSourceUDP = "UDP Video Stream"; +const char* VideoSettings::videoSourceRTSP = "RTSP Video Stream"; VideoSettings::VideoSettings(QObject* parent) : SettingsGroup(videoSettingsGroupName, QString() /* root settings group */, parent) + , _videoSourceFact(NULL) + , _udpPortFact(NULL) + , _rtspUrlFact(NULL) + , _videoSavePathFact(NULL) { QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); qmlRegisterUncreatableType("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only"); + + // Setup enum values for videoSource settings into meta data + QStringList videoSourceList; +#ifdef QGC_GST_STREAMING +#ifndef NO_UDP_VIDEO + videoSourceList.append(videoSourceUDP); +#endif + videoSourceList.append(videoSourceRTSP); +#endif +#ifndef QGC_DISABLE_UVC + QList cameras = QCameraInfo::availableCameras(); + foreach (const QCameraInfo &cameraInfo, cameras) { + videoSourceList.append(cameraInfo.description()); + } +#endif + if (videoSourceList.count() == 0) { + videoSourceList.append(videoSourceNoVideo); + } + QVariantList videoSourceVarList; + foreach (const QString& videoSource, videoSourceList) { + videoSourceVarList.append(QVariant::fromValue(videoSource)); + } + _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList); + + // Set default value for videoSource +#if defined(NO_UDP_VIDEO) + _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceRTSP); +#else + _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceUDP); +#endif +} + +Fact* VideoSettings::videoSource(void) +{ + if (!_videoSourceFact) { + _videoSourceFact = _createSettingsFact(videoSourceName); + } + + return _videoSourceFact; +} + +Fact* VideoSettings::udpPort(void) +{ + if (!_udpPortFact) { + _udpPortFact = _createSettingsFact(udpPortName); + } + + return _udpPortFact; +} + +Fact* VideoSettings::rtspUrl(void) +{ + if (!_rtspUrlFact) { + _rtspUrlFact = _createSettingsFact(rtspUrlName); + } + + return _rtspUrlFact; +} + +Fact* VideoSettings::videoSavePath(void) +{ + if (!_videoSavePathFact) { + _videoSavePathFact = _createSettingsFact(videoSavePathName); + } + + return _videoSavePathFact; } diff --git a/src/Settings/VideoSettings.h b/src/Settings/VideoSettings.h index 04bfc6b..df38217 100644 --- a/src/Settings/VideoSettings.h +++ b/src/Settings/VideoSettings.h @@ -19,9 +19,32 @@ class VideoSettings : public SettingsGroup public: VideoSettings(QObject* parent = NULL); + Q_PROPERTY(Fact* videoSource READ videoSource CONSTANT) + Q_PROPERTY(Fact* udpPort READ udpPort CONSTANT) + Q_PROPERTY(Fact* rtspUrl READ rtspUrl CONSTANT) + Q_PROPERTY(Fact* videoSavePath READ videoSavePath CONSTANT) + + Fact* videoSource (void); + Fact* udpPort (void); + Fact* rtspUrl (void); + Fact* videoSavePath (void); + static const char* videoSettingsGroupName; + static const char* videoSourceName; + static const char* udpPortName; + static const char* rtspUrlName; + static const char* videoSavePathName; + + static const char* videoSourceNoVideo; + static const char* videoSourceUDP; + static const char* videoSourceRTSP; + private: + SettingsFact* _videoSourceFact; + SettingsFact* _udpPortFact; + SettingsFact* _rtspUrlFact; + SettingsFact* _videoSavePathFact; }; #endif diff --git a/src/VideoStreaming/VideoReceiver.cc b/src/VideoStreaming/VideoReceiver.cc index 0a58ff8..383f92b 100644 --- a/src/VideoStreaming/VideoReceiver.cc +++ b/src/VideoStreaming/VideoReceiver.cc @@ -15,6 +15,9 @@ */ #include "VideoReceiver.h" +#include "SettingsManager.h" +#include "QGCApplication.h" + #include #include #include @@ -348,16 +351,6 @@ void VideoReceiver::setUri(const QString & uri) _uri = uri; } -void VideoReceiver::setVideoSavePath(const QString& path) -{ -#if defined(QGC_ENABLE_VIDEORECORDING) - _path = path; - qCDebug(VideoReceiverLog) << "New Path:" << _path; -#else - Q_UNUSED(path); -#endif -} - #if defined(QGC_GST_STREAMING) void VideoReceiver::_shutdownPipeline() { if(!_pipeline) { @@ -467,8 +460,9 @@ void VideoReceiver::startRecording(void) return; } - if(_path.isEmpty()) { - qWarning() << "VideoReceiver::startRecording Empty Path!"; + QString savePath = qgcApp()->toolbox()->settingsManager()->videoSettings()->videoSavePath()->rawValue().toString(); + if(savePath.isEmpty()) { + qgcApp()->showMessage("Unabled to record video. Video save path must be specified in Settings."); return; } @@ -485,7 +479,7 @@ void VideoReceiver::startRecording(void) } QString videoFile; - videoFile = _path + "/QGC-" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss") + ".mkv"; + videoFile = savePath + "/QGC-" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss") + ".mkv"; g_object_set(G_OBJECT(_sink->filesink), "location", qPrintable(videoFile), NULL); qCDebug(VideoReceiverLog) << "New video file:" << videoFile; diff --git a/src/VideoStreaming/VideoReceiver.h b/src/VideoStreaming/VideoReceiver.h index 9ec600f..2c294cf 100644 --- a/src/VideoStreaming/VideoReceiver.h +++ b/src/VideoStreaming/VideoReceiver.h @@ -62,7 +62,6 @@ public slots: void start (); void stop (); void setUri (const QString& uri); - void setVideoSavePath (const QString& path); void stopRecording (); void startRecording (); @@ -105,7 +104,6 @@ private: #endif QString _uri; - QString _path; #if defined(QGC_GST_STREAMING) GstElement* _pipeline; diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index 94f1968..a83ceb5 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -453,84 +453,68 @@ QGCView { anchors.margins: ScreenTools.defaultFontPixelWidth anchors.horizontalCenter: parent.horizontalCenter visible: QGroundControl.settingsManager.videoSettings.visible + Column { id: videoCol spacing: ScreenTools.defaultFontPixelWidth anchors.centerIn: parent + + Row { spacing: ScreenTools.defaultFontPixelWidth + visible: QGroundControl.settingsManager.videoSettings.videoSource.visible QGCLabel { anchors.baseline: videoSource.baseline text: qsTr("Video Source:") width: _labelWidth } - QGCComboBox { - id: videoSource - width: _editFieldWidth - model: QGroundControl.videoManager.videoSourceList - Component.onCompleted: { - var index = videoSource.find(QGroundControl.videoManager.videoSource) - if (index >= 0) { - videoSource.currentIndex = index - } - } - onActivated: { - if (index != -1) { - currentIndex = index - QGroundControl.videoManager.videoSource = model[index] - } - } + FactComboBox { + id: videoSource + width: _editFieldWidth + indexModel: false + fact: QGroundControl.settingsManager.videoSettings.videoSource } } Row { spacing: ScreenTools.defaultFontPixelWidth - visible: QGroundControl.videoManager.isGStreamer && videoSource.currentIndex === 0 + visible: QGroundControl.settingsManager.videoSettings.udpPort.visible && QGroundControl.videoManager.isGStreamer && videoSource.currentIndex === 0 QGCLabel { anchors.baseline: udpField.baseline text: qsTr("UDP Port:") width: _labelWidth } - QGCTextField { + FactTextField { id: udpField width: _editFieldWidth - text: QGroundControl.videoManager.udpPort - validator: IntValidator {bottom: 1024; top: 65535;} - inputMethodHints: Qt.ImhDigitsOnly - onEditingFinished: { - QGroundControl.videoManager.udpPort = parseInt(text) - } + fact: QGroundControl.settingsManager.videoSettings.udpPort } } Row { spacing: ScreenTools.defaultFontPixelWidth - visible: QGroundControl.videoManager.isGStreamer && videoSource.currentIndex === 1 + visible: QGroundControl.settingsManager.videoSettings.rtspUrl.visible && QGroundControl.videoManager.isGStreamer && videoSource.currentIndex === 1 QGCLabel { anchors.baseline: rtspField.baseline text: qsTr("RTSP URL:") width: _labelWidth } - QGCTextField { + FactTextField { id: rtspField width: _editFieldWidth - text: QGroundControl.videoManager.rtspURL - onEditingFinished: { - QGroundControl.videoManager.rtspURL = text - } + fact: QGroundControl.settingsManager.videoSettings.rtspUrl } } Row { spacing: ScreenTools.defaultFontPixelWidth - visible: QGroundControl.videoManager.isGStreamer && QGroundControl.videoManager.recordingEnabled + visible: QGroundControl.settingsManager.videoSettings.videoSavePath.visible && QGroundControl.videoManager.isGStreamer && QGroundControl.videoManager.recordingEnabled QGCLabel { anchors.baseline: pathField.baseline text: qsTr("Save Path:") width: _labelWidth } - QGCTextField { + FactTextField { id: pathField width: _editFieldWidth - readOnly: true - text: QGroundControl.videoManager.videoSavePath + fact: QGroundControl.settingsManager.videoSettings.videoSavePath } QGCButton { text: "Browse" @@ -541,13 +525,12 @@ QGCView { title: "Choose a location to save video files." folder: shortcuts.home selectFolder: true - onAccepted: QGroundControl.videoManager.setVideoSavePathByUrl(fileDialog.fileUrl) + onAccepted: QGroundControl.settingsManager.videoSettings.videoSavePath.value = QGroundControl.urlToLocalFile(videoLocationFileDialog.fileUrl) } - } } } - } + } // Video Source - Rectangle QGCLabel { anchors.horizontalCenter: parent.horizontalCenter From aa2cade0867bdcc544c1a1322c07cc0347757dd5 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Thu, 23 Feb 2017 17:26:15 -0800 Subject: [PATCH 3/3] Fix include ifdef --- src/Settings/VideoSettings.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index ca2a9ed..190c87f 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -12,7 +12,10 @@ #include #include #include + +#ifndef QGC_DISABLE_UVC #include +#endif const char* VideoSettings::videoSettingsGroupName = "Video";