From 58b8db244baf775f4ce29a4f089aeeaa3dd8b2b6 Mon Sep 17 00:00:00 2001 From: Andrew Voznytsa Date: Mon, 13 Apr 2020 14:19:52 +0300 Subject: [PATCH] More consistent video receiver state handling --- VideoReceiverApp/main.cpp | 67 ++++++++++++++++----------- src/VideoManager/VideoManager.cc | 13 ------ src/VideoReceiver/GstVideoReceiver.cc | 2 + 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/VideoReceiverApp/main.cpp b/VideoReceiverApp/main.cpp index 81711133f..121d7ffe7 100644 --- a/VideoReceiverApp/main.cpp +++ b/VideoReceiverApp/main.cpp @@ -302,25 +302,8 @@ VideoReceiverApp::exec() startStreaming(); - QObject::connect(_receiver, &VideoReceiver::timeout, [this](){ + QObject::connect(_receiver, &VideoReceiver::timeout, [](){ qCDebug(AppLog) << "Streaming timeout"; - - _dispatch([this](){ - if (_streaming) { - _receiver->stop(); - } else { - if (--_connect > 0) { - qCDebug(AppLog) << "Restarting streaming"; - _dispatch([this](){ - startStreaming(); - }); - } else { - qCDebug(AppLog) << "Closing..."; - delete _receiver; - _app.exit(); - } - } - }); }); QObject::connect(_receiver, &VideoReceiver::streamingChanged, [this](bool active){ @@ -329,16 +312,6 @@ VideoReceiverApp::exec() qCDebug(AppLog) << "Streaming started"; } else { qCDebug(AppLog) << "Streaming stopped"; - _dispatch([this](){ - if (--_connect > 0) { - qCDebug(AppLog) << "Restarting streaming"; - startStreaming(); - } else { - qCDebug(AppLog) << "Closing..."; - delete _receiver; - _app.exit(); - } - }); } }); @@ -374,6 +347,44 @@ VideoReceiverApp::exec() } }); + QObject::connect(_receiver, &VideoReceiver::onStartComplete, [this](VideoReceiver::STATUS status){ + if (status != VideoReceiver::STATUS_OK) { + qCDebug(AppLog) << "Video receiver start failed"; + _dispatch([this](){ + if (--_connect > 0) { + qCDebug(AppLog) << "Restarting ..."; + _dispatch([this](){ + startStreaming(); + }); + } else { + qCDebug(AppLog) << "Closing..."; + delete _receiver; + _app.exit(); + } + }); + } else { + qCDebug(AppLog) << "Video receiver started"; + } + }); + + QObject::connect(_receiver, &VideoReceiver::onStopComplete, [this](VideoReceiver::STATUS ){ + qCDebug(AppLog) << "Video receiver stopped"; + + _dispatch([this](){ + if (--_connect > 0) { + qCDebug(AppLog) << "Restarting ..."; + _dispatch([this](){ + startStreaming(); + }); + } else { + qCDebug(AppLog) << "Closing..."; + delete _receiver; + _app.exit(); + } + }); + }); + + return _app.exec(); } diff --git a/src/VideoManager/VideoManager.cc b/src/VideoManager/VideoManager.cc index fc176a8c7..ebefed5e7 100644 --- a/src/VideoManager/VideoManager.cc +++ b/src/VideoManager/VideoManager.cc @@ -115,14 +115,9 @@ VideoManager::setToolbox(QGCToolbox *toolbox) _videoReceiver[0] = toolbox->corePlugin()->createVideoReceiver(this); _videoReceiver[1] = toolbox->corePlugin()->createVideoReceiver(this); - connect(_videoReceiver[0], &VideoReceiver::timeout, this, [this](){ - _stopReceiver(0); - }); - connect(_videoReceiver[0], &VideoReceiver::streamingChanged, this, [this](bool active){ _streaming = active; emit streamingChanged(); - _restartVideo(0); }); connect(_videoReceiver[0], &VideoReceiver::onStartComplete, this, [this](VideoReceiver::STATUS status) { @@ -178,14 +173,6 @@ VideoManager::setToolbox(QGCToolbox *toolbox) // 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 if (_videoReceiver[1] != nullptr) { - connect(_videoReceiver[1], &VideoReceiver::timeout, this, [this](){ - _stopReceiver(1); - }); - - connect(_videoReceiver[1], &VideoReceiver::streamingChanged, this, [this](bool active){ - _restartVideo(1); - }); - connect(_videoReceiver[1], &VideoReceiver::onStartComplete, this, [this](VideoReceiver::STATUS status) { if (status == VideoReceiver::STATUS_OK) { _videoStarted[1] = true; diff --git a/src/VideoReceiver/GstVideoReceiver.cc b/src/VideoReceiver/GstVideoReceiver.cc index 5f4fed69a..8e35089ce 100644 --- a/src/VideoReceiver/GstVideoReceiver.cc +++ b/src/VideoReceiver/GstVideoReceiver.cc @@ -644,6 +644,7 @@ GstVideoReceiver::_watchdog(void) _dispatchSignal([this](){ emit timeout(); }); + stop(); } if (_decoding && !_removingDecoder) { @@ -656,6 +657,7 @@ GstVideoReceiver::_watchdog(void) _dispatchSignal([this](){ emit timeout(); }); + stop(); } } }); -- 2.22.0