From 994712c5485e3fe37fe7beaacf78eb787e2be7d9 Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Wed, 21 Nov 2018 19:55:23 -0500 Subject: [PATCH] Fix UVC handling --- src/FlightDisplay/FlightDisplayViewUVC.qml | 24 +++++++++++++++++- src/FlightDisplay/VideoManager.cc | 29 +++++++++++++++------- src/FlightDisplay/VideoManager.h | 5 ++-- src/Settings/VideoSettings.cc | 18 +++++++++++--- src/Settings/VideoSettings.h | 5 ++++ 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/src/FlightDisplay/FlightDisplayViewUVC.qml b/src/FlightDisplay/FlightDisplayViewUVC.qml index 10b768a8c..2670e437a 100644 --- a/src/FlightDisplay/FlightDisplayViewUVC.qml +++ b/src/FlightDisplay/FlightDisplayViewUVC.qml @@ -13,12 +13,34 @@ import QtMultimedia 5.5 import QGroundControl 1.0 Rectangle { - anchors.fill: parent + id: _root + width: parent.width + height: parent.height + anchors.centerIn: parent color: Qt.rgba(0,0,0,0.75) + + function adjustAspectRatio() + { + //-- Set aspect ratio + var size = camera.viewfinder.resolution + if(size.height > 0 && size.width > 0) { + var ar = size.width / size.height + _root.height = parent.height * ar + } + } + Camera { id: camera deviceId: QGroundControl.videoManager.videoSourceID captureMode: Camera.CaptureViewfinder + onDeviceIdChanged: { + adjustAspectRatio() + } + onCameraStateChanged: { + if(camera.cameraStatus === Camera.ActiveStatus) { + adjustAspectRatio() + } + } } VideoOutput { source: camera diff --git a/src/FlightDisplay/VideoManager.cc b/src/FlightDisplay/VideoManager.cc index f9c0fd3fb..f8fd614fb 100644 --- a/src/FlightDisplay/VideoManager.cc +++ b/src/FlightDisplay/VideoManager.cc @@ -65,15 +65,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox) #if defined(QGC_GST_STREAMING) #ifndef QGC_DISABLE_UVC // If we are using a UVC camera setup the device name - QList cameras = QCameraInfo::availableCameras(); - for (const QCameraInfo &cameraInfo: cameras) { - if(cameraInfo.description() == videoSource) { - _videoSourceID = cameraInfo.deviceName(); - emit videoSourceIDChanged(); - qCDebug(VideoManagerLog) << "Found USB source:" << _videoSourceID << " Name:" << videoSource; - break; - } - } + _updateUVC(); #endif emit isGStreamerChanged(); @@ -89,10 +81,29 @@ VideoManager::setToolbox(QGCToolbox *toolbox) #endif } +//----------------------------------------------------------------------------- +void +VideoManager::_updateUVC() +{ +#ifndef QGC_DISABLE_UVC + QString videoSource = _videoSettings->videoSource()->rawValue().toString(); + QList cameras = QCameraInfo::availableCameras(); + for (const QCameraInfo &cameraInfo: cameras) { + if(cameraInfo.description() == videoSource) { + _videoSourceID = cameraInfo.deviceName(); + emit videoSourceIDChanged(); + qCDebug(VideoManagerLog) << "Found USB source:" << _videoSourceID << " Name:" << videoSource; + break; + } + } +#endif +} + //----------------------------------------------------------------------------- void VideoManager::_videoSourceChanged() { + _updateUVC(); emit hasVideoChanged(); emit isGStreamerChanged(); _restartVideo(); diff --git a/src/FlightDisplay/VideoManager.h b/src/FlightDisplay/VideoManager.h index a63d6837a..1de729d6c 100644 --- a/src/FlightDisplay/VideoManager.h +++ b/src/FlightDisplay/VideoManager.h @@ -56,8 +56,8 @@ public: // Override from QGCTool void setToolbox (QGCToolbox *toolbox); - Q_INVOKABLE void startVideo() {_videoReceiver->start();}; - Q_INVOKABLE void stopVideo() {_videoReceiver->stop();}; + Q_INVOKABLE void startVideo() {_videoReceiver->start();} + Q_INVOKABLE void stopVideo() {_videoReceiver->stop(); } signals: void hasVideoChanged (); @@ -70,6 +70,7 @@ private slots: void _udpPortChanged (); void _rtspUrlChanged (); void _tcpUrlChanged (); + void _updateUVC (); private: void _updateSettings (); diff --git a/src/Settings/VideoSettings.cc b/src/Settings/VideoSettings.cc index 5c0b4e34b..0fdd43d96 100644 --- a/src/Settings/VideoSettings.cc +++ b/src/Settings/VideoSettings.cc @@ -32,7 +32,6 @@ DECLARE_SETTINGGROUP(Video, "Video") qmlRegisterUncreatableType("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only"); // Setup enum values for videoSource settings into meta data - bool noVideo = false; QStringList videoSourceList; #ifdef QGC_GST_STREAMING #ifndef NO_UDP_VIDEO @@ -51,7 +50,7 @@ DECLARE_SETTINGGROUP(Video, "Video") } #endif if (videoSourceList.count() == 0) { - noVideo = true; + _noVideo = true; videoSourceList.append(videoSourceNoVideo); } else { videoSourceList.insert(0, videoDisabled); @@ -63,7 +62,12 @@ DECLARE_SETTINGGROUP(Video, "Video") _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList); // Set default value for videoSource - if (noVideo) { + _setDefaults(); +} + +void VideoSettings::_setDefaults() +{ + if (_noVideo) { _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo); } else { _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled); @@ -85,6 +89,14 @@ DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource) { if (!_videoSourceFact) { _videoSourceFact = _createSettingsFact(videoSourceName); + //-- Check for sources no longer available + if(!_nameToMetaDataMap.contains(_videoSourceFact->rawValue().toString())) { + if (_noVideo) { + _videoSourceFact->setRawValue(videoSourceNoVideo); + } else { + _videoSourceFact->setRawValue(videoDisabled); + } + } connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged); } return _videoSourceFact; diff --git a/src/Settings/VideoSettings.h b/src/Settings/VideoSettings.h index f3f2edec8..1f5f3b213 100644 --- a/src/Settings/VideoSettings.h +++ b/src/Settings/VideoSettings.h @@ -55,6 +55,11 @@ private slots: void _configChanged (QVariant value); private: + void _setDefaults (); + +private: + bool _noVideo = false; + }; #endif -- 2.22.0