Unverified Commit c34a1a20 authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #7031 from mavlink/uvcWork

Fix UVC handling
parents 76dd261e 994712c5
......@@ -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
......
......@@ -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<QCameraInfo> 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<QCameraInfo> 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();
......
......@@ -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 ();
......
......@@ -32,7 +32,6 @@ DECLARE_SETTINGGROUP(Video, "Video")
qmlRegisterUncreatableType<VideoSettings>("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;
......
......@@ -55,6 +55,11 @@ private slots:
void _configChanged (QVariant value);
private:
void _setDefaults ();
private:
bool _noVideo = false;
};
#endif
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