Commit 3b025c14 authored by Gus Grubba's avatar Gus Grubba

Make video enable persistent.

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