diff --git a/src/FlightDisplay/FlightDisplayViewVideo.qml b/src/FlightDisplay/FlightDisplayViewVideo.qml index f9673ea52bcba38f23d869121300fbac2d5caec2..0ed7eed06c52d2d51be399a794aa5108e788aa5d 100644 --- a/src/FlightDisplay/FlightDisplayViewVideo.qml +++ b/src/FlightDisplay/FlightDisplayViewVideo.qml @@ -34,7 +34,7 @@ Item { color: Qt.rgba(0,0,0,0.75) visible: !(_videoReceiver && _videoReceiver.videoRunning) QGCLabel { - text: _videoReceiver && _videoReceiver.enabled ? qsTr("WAITING FOR VIDEO") : qsTr("VIDEO DISABLED") + text: QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue ? qsTr("WAITING FOR VIDEO") : qsTr("VIDEO DISABLED") font.family: ScreenTools.demiboldFontFamily color: "white" font.pointSize: _mainIsMap ? ScreenTools.smallFontPointSize : ScreenTools.largeFontPointSize diff --git a/src/FlightMap/Widgets/VideoPageWidget.qml b/src/FlightMap/Widgets/VideoPageWidget.qml index a58fb3414ef74e425630b57705d831a8fde80aee..e27961beebe4c1b0836d6bc75cdd666985b7abdd 100644 --- a/src/FlightMap/Widgets/VideoPageWidget.qml +++ b/src/FlightMap/Widgets/VideoPageWidget.qml @@ -36,8 +36,9 @@ Item { property var _videoReceiver: QGroundControl.videoManager.videoReceiver property bool _recordingVideo: _videoReceiver && _videoReceiver.recording property bool _videoRunning: _videoReceiver && _videoReceiver.videoRunning + property bool _streamingEnabled: QGroundControl.settingsManager.videoSettings.streamConfigured - QGCPalette { id:qgcPal; colorGroupEnabled: parent.enabled } + QGCPalette { id:qgcPal; colorGroupEnabled: true } GridLayout { id: videoGrid @@ -50,12 +51,14 @@ Item { font.pointSize: ScreenTools.smallFontPointSize } Switch { - checked: _videoRunning - enabled: _activeVehicle + enabled: _streamingEnabled && _activeVehicle + checked: QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue onClicked: { if(checked) { + QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue = 1 _videoReceiver.start() } else { + QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue = 0 _videoReceiver.stop() } } @@ -82,14 +85,13 @@ Item { width: height Layout.alignment: Qt.AlignHCenter visible: QGroundControl.settingsManager.videoSettings.showRecControl.rawValue - Rectangle { id: recordBtnBackground anchors.top: parent.top anchors.bottom: parent.bottom width: height radius: _recordingVideo ? 0 : height - color: _videoRunning ? "red" : "gray" + color: (_videoRunning && _streamingEnabled) ? "red" : "gray" SequentialAnimation on opacity { running: _recordingVideo loops: Animation.Infinite @@ -97,7 +99,6 @@ Item { PropertyAnimation { to: 1.0; duration: 500 } } } - QGCColoredImage { anchors.top: parent.top anchors.bottom: parent.bottom @@ -109,10 +110,9 @@ Item { fillMode: Image.PreserveAspectFit color: "white" } - MouseArea { anchors.fill: parent - enabled: _videoRunning + enabled: _videoRunning && _streamingEnabled onClicked: { if (_recordingVideo) { _videoReceiver.stopRecording() @@ -124,5 +124,11 @@ Item { } } } + QGCLabel { + text: qsTr("Video Streaming Not Configured") + font.pointSize: ScreenTools.smallFontPointSize + visible: !_streamingEnabled + Layout.columnSpan: 2 + } } } diff --git a/src/Settings/Video.SettingsGroup.json b/src/Settings/Video.SettingsGroup.json index 68088d4e68c7fe160f5beed4678f8b7ed10cf0bb..172e393ddb2c91be7b63b338a62b3c38aff1f367 100644 --- a/src/Settings/Video.SettingsGroup.json +++ b/src/Settings/Video.SettingsGroup.json @@ -94,5 +94,12 @@ "min": 1, "units": "s", "defaultValue": 2 +}, +{ + "name": "StreamEnabled", + "shortDescription": "Video Stream Enabled", + "longDescription": "Start/Stop Video Stream.", + "type": "bool", + "defaultValue": true } ] diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index 631a7d14a202390924513fe4984a4e38a6df3759..200f48accb24f38601761c5b6b1ea676e88828b8 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -30,6 +30,7 @@ const char* VideoSettings::recordingFormatName = "RecordingFormat"; const char* VideoSettings::maxVideoSizeName = "MaxVideoSize"; const char* VideoSettings::enableStorageLimitName = "EnableStorageLimit"; const char* VideoSettings::rtspTimeoutName = "RtspTimeout"; +const char* VideoSettings::streamEnabledName = "StreamEnabled"; const char* VideoSettings::videoSourceNoVideo = "No Video Available"; const char* VideoSettings::videoDisabled = "Video Stream Disabled"; @@ -50,6 +51,7 @@ VideoSettings::VideoSettings(QObject* parent) , _maxVideoSizeFact(NULL) , _enableStorageLimitFact(NULL) , _rtspTimeoutFact(NULL) + , _streamEnabledFact(NULL) { QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership); qmlRegisterUncreatableType("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only"); @@ -94,8 +96,8 @@ Fact* VideoSettings::videoSource(void) { if (!_videoSourceFact) { _videoSourceFact = _createSettingsFact(videoSourceName); + connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged); } - return _videoSourceFact; } @@ -103,8 +105,8 @@ Fact* VideoSettings::udpPort(void) { if (!_udpPortFact) { _udpPortFact = _createSettingsFact(udpPortName); + connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged); } - return _udpPortFact; } @@ -112,8 +114,8 @@ Fact* VideoSettings::rtspUrl(void) { if (!_rtspUrlFact) { _rtspUrlFact = _createSettingsFact(rtspUrlName); + connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged); } - return _rtspUrlFact; } @@ -121,8 +123,8 @@ Fact* VideoSettings::tcpUrl(void) { if (!_tcpUrlFact) { _tcpUrlFact = _createSettingsFact(tcpUrlName); + connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged); } - return _tcpUrlFact; } @@ -131,7 +133,6 @@ Fact* VideoSettings::aspectRatio(void) if (!_videoAspectRatioFact) { _videoAspectRatioFact = _createSettingsFact(videoAspectRatioName); } - return _videoAspectRatioFact; } @@ -140,7 +141,6 @@ Fact* VideoSettings::gridLines(void) if (!_gridLinesFact) { _gridLinesFact = _createSettingsFact(videoGridLinesName); } - return _gridLinesFact; } @@ -149,7 +149,6 @@ Fact* VideoSettings::showRecControl(void) if (!_showRecControlFact) { _showRecControlFact = _createSettingsFact(showRecControlName); } - return _showRecControlFact; } @@ -158,7 +157,6 @@ Fact* VideoSettings::recordingFormat(void) if (!_recordingFormatFact) { _recordingFormatFact = _createSettingsFact(recordingFormatName); } - return _recordingFormatFact; } @@ -167,7 +165,6 @@ Fact* VideoSettings::maxVideoSize(void) if (!_maxVideoSizeFact) { _maxVideoSizeFact = _createSettingsFact(maxVideoSizeName); } - return _maxVideoSizeFact; } @@ -176,7 +173,6 @@ Fact* VideoSettings::enableStorageLimit(void) if (!_enableStorageLimitFact) { _enableStorageLimitFact = _createSettingsFact(enableStorageLimitName); } - return _enableStorageLimitFact; } @@ -185,6 +181,42 @@ Fact* VideoSettings::rtspTimeout(void) if (!_rtspTimeoutFact) { _rtspTimeoutFact = _createSettingsFact(rtspTimeoutName); } - return _rtspTimeoutFact; } + +Fact* VideoSettings::streamEnabled(void) +{ + if (!_streamEnabledFact) { + _streamEnabledFact = _createSettingsFact(streamEnabledName); + } + return _streamEnabledFact; +} + +bool VideoSettings::streamConfigured(void) +{ +#if !defined(QGC_GST_STREAMING) + return false; +#endif + QString vSource = videoSource()->rawValue().toString(); + if(vSource == videoSourceNoVideo || vSource == videoDisabled) { + return false; + } + //-- If UDP, check if port is set + if(vSource == videoSourceUDP) { + return udpPort()->rawValue().toInt() != 0; + } + //-- If RTSP, check for URL + if(vSource == videoSourceRTSP) { + return !rtspUrl()->rawValue().toString().isEmpty(); + } + //-- If TCP, check for URL + if(vSource == videoSourceTCP) { + return !tcpUrl()->rawValue().toString().isEmpty(); + } + return false; +} + +void VideoSettings::_configChanged(QVariant) +{ + emit streamConfiguredChanged(); +} diff --git a/src/Settings/VideoSettings.h b/src/Settings/VideoSettings.h index e05816a1cc561cbd4b05c029cf8b3c1e36ddb062..ee3200038c7e5a42781d64e9693c77932c20a5b1 100644 --- a/src/Settings/VideoSettings.h +++ b/src/Settings/VideoSettings.h @@ -30,6 +30,8 @@ public: Q_PROPERTY(Fact* maxVideoSize READ maxVideoSize CONSTANT) Q_PROPERTY(Fact* enableStorageLimit READ enableStorageLimit CONSTANT) Q_PROPERTY(Fact* rtspTimeout READ rtspTimeout CONSTANT) + Q_PROPERTY(Fact* streamEnabled READ streamEnabled CONSTANT) + Q_PROPERTY(bool streamConfigured READ streamConfigured NOTIFY streamConfiguredChanged) Fact* videoSource (void); Fact* udpPort (void); @@ -41,7 +43,9 @@ public: Fact* recordingFormat (void); Fact* maxVideoSize (void); Fact* enableStorageLimit(void); - Fact* rtspTimeout (void); + Fact* rtspTimeout (void); + Fact* streamEnabled (void); + bool streamConfigured (void); static const char* videoSettingsGroupName; @@ -56,6 +60,7 @@ public: static const char* maxVideoSizeName; static const char* enableStorageLimitName; static const char* rtspTimeoutName; + static const char* streamEnabledName; static const char* videoSourceNoVideo; static const char* videoDisabled; @@ -63,6 +68,12 @@ public: static const char* videoSourceRTSP; static const char* videoSourceTCP; +signals: + void streamConfiguredChanged (); + +private slots: + void _configChanged (QVariant value); + private: SettingsFact* _videoSourceFact; SettingsFact* _udpPortFact; @@ -75,6 +86,7 @@ private: SettingsFact* _maxVideoSizeFact; SettingsFact* _enableStorageLimitFact; SettingsFact* _rtspTimeoutFact; + SettingsFact* _streamEnabledFact; }; #endif diff --git a/src/VideoStreaming/VideoReceiver.cc b/src/VideoStreaming/VideoReceiver.cc index 7c79b98260c1abcd58edfeb443cc65f224dfd340..21695f76add83070db06e32e2e2c0e4f38fba473 100644 --- a/src/VideoStreaming/VideoReceiver.cc +++ b/src/VideoStreaming/VideoReceiver.cc @@ -67,7 +67,6 @@ VideoReceiver::VideoReceiver(QObject* parent) , _videoSurface(NULL) , _videoRunning(false) , _showFullScreen(false) - , _enabled(true) { _videoSurface = new VideoSurface; #if defined(QGC_GST_STREAMING) @@ -148,7 +147,7 @@ VideoReceiver::_connected() _timer.stop(); _socket->deleteLater(); _socket = NULL; - if(_enabled) { + if(qgcApp()->toolbox()->settingsManager()->videoSettings()->streamEnabled()->rawValue().toBool()) { _serverPresent = true; start(); } @@ -164,7 +163,7 @@ VideoReceiver::_socketError(QAbstractSocket::SocketError socketError) _socket->deleteLater(); _socket = NULL; //-- Try again in 5 seconds - if(_enabled) { + if(qgcApp()->toolbox()->settingsManager()->videoSettings()->streamEnabled()->rawValue().toBool()) { _timer.start(5000); } } @@ -180,7 +179,7 @@ VideoReceiver::_timeout() delete _socket; _socket = NULL; } - if(_enabled) { + if(qgcApp()->toolbox()->settingsManager()->videoSettings()->streamEnabled()->rawValue().toBool()) { //-- RTSP will try to connect to the server. If it cannot connect, // it will simply give up and never try again. Instead, we keep // attempting a connection on this timer. Once a connection is @@ -209,8 +208,11 @@ VideoReceiver::_timeout() void VideoReceiver::start() { - _enabled = true; - emit enabledChanged(); + if(!qgcApp()->toolbox()->settingsManager()->videoSettings()->streamEnabled()->rawValue().toBool() || + !qgcApp()->toolbox()->settingsManager()->videoSettings()->streamConfigured()) { + qCDebug(VideoReceiverLog) << "start() but not enabled/configured"; + return; + } #if defined(QGC_GST_STREAMING) qCDebug(VideoReceiverLog) << "start()"; @@ -424,8 +426,6 @@ VideoReceiver::start() void VideoReceiver::stop() { - _enabled = false; - emit enabledChanged(); #if defined(QGC_GST_STREAMING) qCDebug(VideoReceiverLog) << "stop()"; if(!_streaming) { @@ -824,7 +824,7 @@ VideoReceiver::_updateTimer() stop(); } } else { - if(!running() && !_uri.isEmpty() && _enabled) { + if(!running() && !_uri.isEmpty() && qgcApp()->toolbox()->settingsManager()->videoSettings()->streamEnabled()->rawValue().toBool()) { start(); } } diff --git a/src/VideoStreaming/VideoReceiver.h b/src/VideoStreaming/VideoReceiver.h index b32cd7b015a13d985b0fd96412599061b1db6ebc..caced64e9512bec98b9761d038164d4b1e6ec0bb 100644 --- a/src/VideoStreaming/VideoReceiver.h +++ b/src/VideoStreaming/VideoReceiver.h @@ -41,7 +41,6 @@ public: Q_PROPERTY(bool videoRunning READ videoRunning NOTIFY videoRunningChanged) Q_PROPERTY(QString imageFile READ imageFile NOTIFY imageFileChanged) Q_PROPERTY(bool showFullScreen READ showFullScreen WRITE setShowFullScreen NOTIFY showFullScreenChanged) - Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) explicit VideoReceiver(QObject* parent = 0); ~VideoReceiver(); @@ -58,7 +57,6 @@ public: bool videoRunning () { return _videoRunning; } QString imageFile () { return _imageFile; } bool showFullScreen () { return _showFullScreen; } - bool enabled () { return _enabled; } void grabImage (QString imageFile); @@ -68,7 +66,6 @@ signals: void videoRunningChanged (); void imageFileChanged (); void showFullScreenChanged (); - void enabledChanged (); #if defined(QGC_GST_STREAMING) void recordingChanged (); void msgErrorReceived (); @@ -140,8 +137,6 @@ private: VideoSurface* _videoSurface; bool _videoRunning; bool _showFullScreen; - bool _enabled; - }; #endif // VIDEORECEIVER_H