Commit 91b7cef8 authored by Gus Grubba's avatar Gus Grubba

Taisync Fixes

Handle crash on first time switch from disable to enabled
Handle video settings restore after disabling Taisync
parent 78ff045e
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "TaisyncHandler.h" #include "TaisyncHandler.h"
#include "SettingsManager.h" #include "SettingsManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCCorePlugin.h"
#include "VideoManager.h" #include "VideoManager.h"
#include <QSettings> #include <QSettings>
...@@ -88,10 +89,6 @@ TaisyncManager::_reset() ...@@ -88,10 +89,6 @@ TaisyncManager::_reset()
emit connectedChanged(); emit connectedChanged();
_linkConnected = false; _linkConnected = false;
emit linkConnectedChanged(); emit linkConnectedChanged();
_taiSettings = new TaisyncSettings(this);
connect(_taiSettings, &TaisyncSettings::updateSettings, this, &TaisyncManager::_updateSettings);
connect(_taiSettings, &TaisyncSettings::connected, this, &TaisyncManager::_connected);
connect(_taiSettings, &TaisyncSettings::disconnected, this, &TaisyncManager::_disconnected);
if(!_appSettings) { if(!_appSettings) {
_appSettings = _toolbox->settingsManager()->appSettings(); _appSettings = _toolbox->settingsManager()->appSettings();
connect(_appSettings->enableTaisync(), &Fact::rawValueChanged, this, &TaisyncManager::_setEnabled); connect(_appSettings->enableTaisync(), &Fact::rawValueChanged, this, &TaisyncManager::_setEnabled);
...@@ -183,6 +180,7 @@ TaisyncManager::setToolbox(QGCToolbox* toolbox) ...@@ -183,6 +180,7 @@ TaisyncManager::setToolbox(QGCToolbox* toolbox)
_videoRateList.append("high"); _videoRateList.append("high");
connect(_videoRate, &Fact::_containerRawValueChanged, this, &TaisyncManager::_videoSettingsChanged); connect(_videoRate, &Fact::_containerRawValueChanged, this, &TaisyncManager::_videoSettingsChanged);
} }
//-- Start it all
_reset(); _reset();
} }
...@@ -286,6 +284,12 @@ TaisyncManager::_setEnabled() ...@@ -286,6 +284,12 @@ TaisyncManager::_setEnabled()
{ {
bool enable = _appSettings->enableTaisync()->rawValue().toBool(); bool enable = _appSettings->enableTaisync()->rawValue().toBool();
if(enable) { if(enable) {
if(!_taiSettings) {
_taiSettings = new TaisyncSettings(this);
connect(_taiSettings, &TaisyncSettings::updateSettings, this, &TaisyncManager::_updateSettings);
connect(_taiSettings, &TaisyncSettings::connected, this, &TaisyncManager::_connected);
connect(_taiSettings, &TaisyncSettings::disconnected, this, &TaisyncManager::_disconnected);
}
#if defined(__ios__) || defined(__android__) #if defined(__ios__) || defined(__android__)
if(!_taiTelemetery) { if(!_taiTelemetery) {
_taiTelemetery = new TaisyncTelemetry(this); _taiTelemetery = new TaisyncTelemetry(this);
...@@ -298,7 +302,7 @@ TaisyncManager::_setEnabled() ...@@ -298,7 +302,7 @@ TaisyncManager::_setEnabled()
_taiTelemetery->start(); _taiTelemetery->start();
} }
#endif #endif
_reqMask = REQ_ALL; _reqMask = static_cast<uint32_t>(REQ_ALL);
_workTimer.start(1000); _workTimer.start(1000);
} else { } else {
//-- Stop everything //-- Stop everything
...@@ -310,6 +314,16 @@ TaisyncManager::_setEnabled() ...@@ -310,6 +314,16 @@ TaisyncManager::_setEnabled()
_setVideoEnabled(); _setVideoEnabled();
} }
//-----------------------------------------------------------------------------
void
TaisyncManager::_restoreVideoSettings(Fact* setting)
{
SettingsFact* pFact = dynamic_cast<SettingsFact*>(setting);
if(pFact) {
pFact->setVisible(qgcApp()->toolbox()->corePlugin()->adjustSettingMetaData(VideoSettings::settingsGroup, *setting->metaData()));
}
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
TaisyncManager::_setVideoEnabled() TaisyncManager::_setVideoEnabled()
...@@ -317,21 +331,13 @@ TaisyncManager::_setVideoEnabled() ...@@ -317,21 +331,13 @@ TaisyncManager::_setVideoEnabled()
//-- Check both if video is enabled and Taisync support itself is enabled as well. //-- Check both if video is enabled and Taisync support itself is enabled as well.
bool enable = _appSettings->enableTaisyncVideo()->rawValue().toBool() && _appSettings->enableTaisync()->rawValue().toBool(); bool enable = _appSettings->enableTaisyncVideo()->rawValue().toBool() && _appSettings->enableTaisync()->rawValue().toBool();
if(enable) { if(enable) {
//-- If we haven't already saved the previous settings... //-- Set it up the way we need it do be.
if(!_savedVideoSource.isValid()) {
//-- Hide video selection as we will be fixed to Taisync video and set the way we need it.
VideoSettings* pVSettings = qgcApp()->toolbox()->settingsManager()->videoSettings(); VideoSettings* pVSettings = qgcApp()->toolbox()->settingsManager()->videoSettings();
//-- First save current state.
_savedVideoSource = pVSettings->videoSource()->rawValue();
_savedVideoUDP = pVSettings->udpPort()->rawValue();
_savedAR = pVSettings->aspectRatio()->rawValue();
_savedVideoState = pVSettings->visible();
//-- Now set it up the way we need it do be.
pVSettings->setVisible(false); pVSettings->setVisible(false);
pVSettings->udpPort()->setRawValue(5600); pVSettings->udpPort()->setRawValue(5600);
//-- TODO: this AR must come from somewhere
pVSettings->aspectRatio()->setRawValue(1024.0 / 768.0); pVSettings->aspectRatio()->setRawValue(1024.0 / 768.0);
pVSettings->videoSource()->setRawValue(QString(VideoSettings::videoSourceUDP)); pVSettings->videoSource()->setRawValue(QString(VideoSettings::videoSourceUDP));
}
#if defined(__ios__) || defined(__android__) #if defined(__ios__) || defined(__android__)
if(!_taiVideo) { if(!_taiVideo) {
//-- iOS and Android receive raw h.264 and need a different pipeline //-- iOS and Android receive raw h.264 and need a different pipeline
...@@ -350,14 +356,11 @@ TaisyncManager::_setVideoEnabled() ...@@ -350,14 +356,11 @@ TaisyncManager::_setVideoEnabled()
_taiVideo = nullptr; _taiVideo = nullptr;
} }
#endif #endif
if(!_savedVideoSource.isValid()) {
VideoSettings* pVSettings = qgcApp()->toolbox()->settingsManager()->videoSettings(); VideoSettings* pVSettings = qgcApp()->toolbox()->settingsManager()->videoSettings();
pVSettings->videoSource()->setRawValue(_savedVideoSource); _restoreVideoSettings(pVSettings->videoSource());
pVSettings->udpPort()->setRawValue(_savedVideoUDP); _restoreVideoSettings(pVSettings->aspectRatio());
pVSettings->aspectRatio()->setRawValue(_savedAR); _restoreVideoSettings(pVSettings->udpPort());
pVSettings->setVisible(_savedVideoState); pVSettings->setVisible(true);
_savedVideoSource.clear();
}
} }
_enableVideo = enable; _enableVideo = enable;
} }
...@@ -422,9 +425,11 @@ TaisyncManager::_checkTaisync() ...@@ -422,9 +425,11 @@ TaisyncManager::_checkTaisync()
{ {
if(_enabled) { if(_enabled) {
if(!_isConnected) { if(!_isConnected) {
if(_taiSettings) {
if(!_taiSettings->isServerRunning()) { if(!_taiSettings->isServerRunning()) {
_taiSettings->start(); _taiSettings->start();
} }
}
} else { } else {
//qCDebug(TaisyncVerbose) << bin << _reqMask; //qCDebug(TaisyncVerbose) << bin << _reqMask;
while(true) { while(true) {
......
...@@ -110,6 +110,7 @@ private slots: ...@@ -110,6 +110,7 @@ private slots:
private: private:
void _close (); void _close ();
void _reset (); void _reset ();
void _restoreVideoSettings (Fact* setting);
FactMetaData *_createMetadata (const char *name, QStringList enums); FactMetaData *_createMetadata (const char *name, QStringList enums);
private: private:
...@@ -122,10 +123,10 @@ private: ...@@ -122,10 +123,10 @@ private:
REQ_RADIO_SETTINGS = 16, REQ_RADIO_SETTINGS = 16,
REQ_RTSP_SETTINGS = 32, REQ_RTSP_SETTINGS = 32,
REQ_IP_SETTINGS = 64, REQ_IP_SETTINGS = 64,
REQ_ALL = 0xFFFFFFFF, REQ_ALL = 0xFFFFFFF,
}; };
uint32_t _reqMask = REQ_ALL; uint32_t _reqMask = static_cast<uint32_t>(REQ_ALL);
bool _running = false; bool _running = false;
bool _isConnected = false; bool _isConnected = false;
AppSettings* _appSettings = nullptr; AppSettings* _appSettings = nullptr;
...@@ -148,10 +149,6 @@ private: ...@@ -148,10 +149,6 @@ private:
int _decodeIndex = 0; int _decodeIndex = 0;
QStringList _rateList; QStringList _rateList;
int _rateIndex = 0; int _rateIndex = 0;
bool _savedVideoState = true;
QVariant _savedVideoSource;
QVariant _savedVideoUDP;
QVariant _savedAR;
QString _serialNumber; QString _serialNumber;
QString _fwVersion; QString _fwVersion;
Fact* _radioMode = nullptr; Fact* _radioMode = nullptr;
......
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