Commit f52bc85d authored by Andrew Voznytsa's avatar Andrew Voznytsa

Fix VideoManager state handling

parent fcf9d0dd
...@@ -109,8 +109,16 @@ VideoManager::setToolbox(QGCToolbox *toolbox) ...@@ -109,8 +109,16 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
_videoReceiver = toolbox->corePlugin()->createVideoReceiver(this); _videoReceiver = toolbox->corePlugin()->createVideoReceiver(this);
_thermalVideoReceiver = toolbox->corePlugin()->createVideoReceiver(this); _thermalVideoReceiver = toolbox->corePlugin()->createVideoReceiver(this);
connect(_videoReceiver, &VideoReceiver::timeout, this, &VideoManager::_restartVideo); connect(_videoReceiver, &VideoReceiver::timeout, this, [this](){
connect(_videoReceiver, &VideoReceiver::streamingChanged, this, &VideoManager::_streamingChanged); if (!_enableVideoRestart) return;
_startReceiver(0);
});
connect(_videoReceiver, &VideoReceiver::streamingChanged, this, [this](){
if (!_enableVideoRestart || _videoReceiver->streaming()) return;
_startReceiver(0);
});
connect(_videoReceiver, &VideoReceiver::recordingStarted, this, &VideoManager::_recordingStarted); connect(_videoReceiver, &VideoReceiver::recordingStarted, this, &VideoManager::_recordingStarted);
connect(_videoReceiver, &VideoReceiver::recordingChanged, this, &VideoManager::_recordingChanged); connect(_videoReceiver, &VideoReceiver::recordingChanged, this, &VideoManager::_recordingChanged);
connect(_videoReceiver, &VideoReceiver::onTakeScreenshotComplete, this, &VideoManager::_onTakeScreenshotComplete); connect(_videoReceiver, &VideoReceiver::onTakeScreenshotComplete, this, &VideoManager::_onTakeScreenshotComplete);
...@@ -118,8 +126,15 @@ VideoManager::setToolbox(QGCToolbox *toolbox) ...@@ -118,8 +126,15 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
// FIXME: AV: I believe _thermalVideoReceiver should be handled just like _videoReceiver in terms of event // FIXME: AV: I believe _thermalVideoReceiver should be handled just like _videoReceiver in terms of event
// and I expect that it will be changed during multiple video stream activity // and I expect that it will be changed during multiple video stream activity
if (_thermalVideoReceiver != nullptr) { if (_thermalVideoReceiver != nullptr) {
connect(_thermalVideoReceiver, &VideoReceiver::timeout, this, &VideoManager::_restartVideo); connect(_thermalVideoReceiver, &VideoReceiver::timeout, this, [this](){
connect(_thermalVideoReceiver, &VideoReceiver::streamingChanged, this, &VideoManager::_streamingChanged); if (!_enableVideoRestart) return;
_startReceiver(1);
});
connect(_thermalVideoReceiver, &VideoReceiver::streamingChanged, this, [this](){
if (!_enableVideoRestart) return;
_startReceiver(1);
});
} }
#endif #endif
_updateSettings(); _updateSettings();
...@@ -186,24 +201,10 @@ VideoManager::startVideo() ...@@ -186,24 +201,10 @@ VideoManager::startVideo()
return; return;
} }
#if defined(QGC_GST_STREAMING) _enableVideoRestart = true;
const unsigned timeout = _videoSettings->rtspTimeout()->rawValue().toUInt();
if(_videoReceiver != nullptr) {
connect(_videoReceiver, &VideoReceiver::onStartComplete, this, &VideoManager::_onStartComplete);
_videoReceiver->start(_videoUri, timeout);
if (_videoSink != nullptr) {
_videoReceiver->startDecoding(_videoSink);
}
}
if(_thermalVideoReceiver != nullptr) { _startReceiver(0);
_thermalVideoReceiver->start(_thermalVideoUri, timeout); _startReceiver(1);
if (_thermalVideoSink != nullptr) {
_thermalVideoReceiver->startDecoding(_thermalVideoSink);
}
}
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -214,13 +215,10 @@ VideoManager::stopVideo() ...@@ -214,13 +215,10 @@ VideoManager::stopVideo()
return; return;
} }
disconnect(_videoReceiver, &VideoReceiver::timeout, this, &VideoManager::_restartVideo); _enableVideoRestart = false;
disconnect(_videoReceiver, &VideoReceiver::streamingChanged, this, &VideoManager::_streamingChanged);
#if defined(QGC_GST_STREAMING) _stopReceiver(1);
if(_videoReceiver) _videoReceiver->stop(); _stopReceiver(0);
if(_thermalVideoReceiver) _thermalVideoReceiver->stop();
#endif
} }
void void
...@@ -574,16 +572,16 @@ VideoManager::_updateSettings() ...@@ -574,16 +572,16 @@ VideoManager::_updateSettings()
switch(pTinfo->type()) { switch(pTinfo->type()) {
case VIDEO_STREAM_TYPE_RTSP: case VIDEO_STREAM_TYPE_RTSP:
case VIDEO_STREAM_TYPE_TCP_MPEG: case VIDEO_STREAM_TYPE_TCP_MPEG:
_updateThermalVideoUri(pTinfo->uri()); status |= _updateThermalVideoUri(pTinfo->uri());
break; break;
case VIDEO_STREAM_TYPE_RTPUDP: case VIDEO_STREAM_TYPE_RTPUDP:
_updateThermalVideoUri(QStringLiteral("udp://0.0.0.0:%1").arg(pTinfo->uri())); status |= _updateThermalVideoUri(QStringLiteral("udp://0.0.0.0:%1").arg(pTinfo->uri()));
break; break;
case VIDEO_STREAM_TYPE_MPEG_TS_H264: case VIDEO_STREAM_TYPE_MPEG_TS_H264:
_updateThermalVideoUri(QStringLiteral("mpegts://0.0.0.0:%1").arg(pTinfo->uri())); status |= _updateThermalVideoUri(QStringLiteral("mpegts://0.0.0.0:%1").arg(pTinfo->uri()));
break; break;
default: default:
_updateThermalVideoUri(pTinfo->uri()); status |= _updateThermalVideoUri(pTinfo->uri());
break; break;
} }
} }
...@@ -621,7 +619,7 @@ VideoManager::_updateVideoUri(const QString& uri) ...@@ -621,7 +619,7 @@ VideoManager::_updateVideoUri(const QString& uri)
return true; return true;
} }
void bool
VideoManager::_updateThermalVideoUri(const QString& uri) VideoManager::_updateThermalVideoUri(const QString& uri)
{ {
#if defined(QGC_GST_TAISYNC_ENABLED) && (defined(__android__) || defined(__ios__)) #if defined(QGC_GST_TAISYNC_ENABLED) && (defined(__android__) || defined(__ios__))
...@@ -632,47 +630,13 @@ VideoManager::_updateThermalVideoUri(const QString& uri) ...@@ -632,47 +630,13 @@ VideoManager::_updateThermalVideoUri(const QString& uri)
return; return;
} }
#endif #endif
_thermalVideoUri = uri; if (uri == _thermalVideoUri) {
} return false;
//-----------------------------------------------------------------------------
void
VideoManager::_streamingChanged()
{
#if defined(QGC_GST_STREAMING)
// FIXME: AV: we need VideoReceiver::running() to avoid restarting if one of streams is not active
// but since VideoManager is going to be relpaced by Video Model during multiple video streaming development activity
// I'll leave it as is for week or two
if ((_videoReceiver && !_videoReceiver->streaming())
/*|| (_thermalVideoReceiver && !_thermalVideoReceiver->streaming())*/) {
_restartVideo();
}
#endif
}
//-----------------------------------------------------------------------------
void
VideoManager::_streamChanged()
{
if (_updateSettings()) {
_restartVideo();
} }
}
//----------------------------------------------------------------------------- _thermalVideoUri = uri;
void
VideoManager::_onStartComplete(VideoReceiver::STATUS status)
{
disconnect(_videoReceiver, &VideoReceiver::onStartComplete, this, &VideoManager::_onStartComplete);
if (status == VideoReceiver::STATUS_OK) { return true;
connect(_videoReceiver, &VideoReceiver::timeout, this, &VideoManager::_restartVideo);
connect(_videoReceiver, &VideoReceiver::streamingChanged, this, &VideoManager::_streamingChanged);
} else {
QTimer::singleShot(1000, [this](){
_restartVideo();
});
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -680,10 +644,15 @@ void ...@@ -680,10 +644,15 @@ void
VideoManager::_restartVideo() VideoManager::_restartVideo()
{ {
#if defined(QGC_GST_STREAMING) #if defined(QGC_GST_STREAMING)
if (!_updateSettings()) {
qCDebug(VideoManagerLog) << "No sense to restart video streaming, skipped";
return;
}
qCDebug(VideoManagerLog) << "Restart video streaming"; qCDebug(VideoManagerLog) << "Restart video streaming";
stopVideo();
_updateSettings(); _stopReceiver(1);
startVideo(); _stopReceiver(0);
// emit aspectRatioChanged(); // emit aspectRatioChanged();
#endif #endif
} }
...@@ -712,6 +681,44 @@ VideoManager::_onTakeScreenshotComplete(VideoReceiver::STATUS status) ...@@ -712,6 +681,44 @@ VideoManager::_onTakeScreenshotComplete(VideoReceiver::STATUS status)
{ {
} }
//----------------------------------------------------------------------------------------
void
VideoManager::_startReceiver(unsigned id)
{
#if defined(QGC_GST_STREAMING)
const unsigned timeout = _videoSettings->rtspTimeout()->rawValue().toUInt();
if (id == 0 && _videoReceiver != nullptr) {
_videoReceiver->start(_videoUri, timeout);
if (_videoSink != nullptr) {
_videoReceiver->startDecoding(_videoSink);
}
} else if (id == 1 && _thermalVideoReceiver != nullptr) {
_thermalVideoReceiver->start(_thermalVideoUri, timeout);
if (_thermalVideoSink != nullptr) {
_thermalVideoReceiver->startDecoding(_thermalVideoSink);
}
} else if (id > 1) {
qCDebug(VideoManagerLog) << "Unsupported receiver id" << id;
}
#endif
}
//----------------------------------------------------------------------------------------
void
VideoManager::_stopReceiver(unsigned id)
{
#if defined(QGC_GST_STREAMING)
if (id == 0 && _videoReceiver != nullptr) {
_videoReceiver->stop();
} else if (id == 1 && _thermalVideoReceiver != nullptr){
_thermalVideoReceiver->stop();
} else if (id > 1) {
qCDebug(VideoManagerLog) << "Unsupported receiver id" << id;
}
#endif
}
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
void void
VideoManager::_setActiveVehicle(Vehicle* vehicle) VideoManager::_setActiveVehicle(Vehicle* vehicle)
...@@ -730,7 +737,7 @@ VideoManager::_setActiveVehicle(Vehicle* vehicle) ...@@ -730,7 +737,7 @@ VideoManager::_setActiveVehicle(Vehicle* vehicle)
if(_activeVehicle) { if(_activeVehicle) {
connect(_activeVehicle, &Vehicle::connectionLostChanged, this, &VideoManager::_connectionLostChanged); connect(_activeVehicle, &Vehicle::connectionLostChanged, this, &VideoManager::_connectionLostChanged);
if(_activeVehicle->dynamicCameras()) { if(_activeVehicle->dynamicCameras()) {
connect(_activeVehicle->dynamicCameras(), &QGCCameraManager::streamChanged, this, &VideoManager::_streamChanged); connect(_activeVehicle->dynamicCameras(), &QGCCameraManager::streamChanged, this, &VideoManager::_restartVideo);
QGCCameraControl* pCamera = _activeVehicle->dynamicCameras()->currentCameraInstance(); QGCCameraControl* pCamera = _activeVehicle->dynamicCameras()->currentCameraInstance();
if(pCamera) { if(pCamera) {
pCamera->resumeStream(); pCamera->resumeStream();
......
...@@ -117,15 +117,14 @@ protected: ...@@ -117,15 +117,14 @@ protected:
void _initVideo (); void _initVideo ();
bool _updateSettings (); bool _updateSettings ();
bool _updateVideoUri (const QString& uri); bool _updateVideoUri (const QString& uri);
void _updateThermalVideoUri (const QString& uri); bool _updateThermalVideoUri (const QString& uri);
void _cleanupOldVideos (); void _cleanupOldVideos ();
void _streamChanged ();
void _onStartComplete (VideoReceiver::STATUS status);
void _restartVideo (); void _restartVideo ();
void _streamingChanged ();
void _recordingStarted (); void _recordingStarted ();
void _recordingChanged (); void _recordingChanged ();
void _onTakeScreenshotComplete (VideoReceiver::STATUS status); void _onTakeScreenshotComplete (VideoReceiver::STATUS status);
void _startReceiver (unsigned id);
void _stopReceiver (unsigned id);
protected: protected:
QString _videoFile; QString _videoFile;
...@@ -134,6 +133,7 @@ protected: ...@@ -134,6 +133,7 @@ protected:
bool _isTaisync = false; bool _isTaisync = false;
VideoReceiver* _videoReceiver = nullptr; VideoReceiver* _videoReceiver = nullptr;
VideoReceiver* _thermalVideoReceiver = nullptr; VideoReceiver* _thermalVideoReceiver = nullptr;
bool _enableVideoRestart = false;
void* _videoSink = nullptr; void* _videoSink = nullptr;
void* _thermalVideoSink = nullptr; void* _thermalVideoSink = nullptr;
VideoSettings* _videoSettings = nullptr; VideoSettings* _videoSettings = 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