Commit 994712c5 authored by Gus Grubba's avatar Gus Grubba

Fix UVC handling

parent e8816a23
...@@ -13,12 +13,34 @@ import QtMultimedia 5.5 ...@@ -13,12 +13,34 @@ import QtMultimedia 5.5
import QGroundControl 1.0 import QGroundControl 1.0
Rectangle { Rectangle {
anchors.fill: parent id: _root
width: parent.width
height: parent.height
anchors.centerIn: parent
color: Qt.rgba(0,0,0,0.75) 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 { Camera {
id: camera id: camera
deviceId: QGroundControl.videoManager.videoSourceID deviceId: QGroundControl.videoManager.videoSourceID
captureMode: Camera.CaptureViewfinder captureMode: Camera.CaptureViewfinder
onDeviceIdChanged: {
adjustAspectRatio()
}
onCameraStateChanged: {
if(camera.cameraStatus === Camera.ActiveStatus) {
adjustAspectRatio()
}
}
} }
VideoOutput { VideoOutput {
source: camera source: camera
......
...@@ -65,15 +65,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox) ...@@ -65,15 +65,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
#if defined(QGC_GST_STREAMING) #if defined(QGC_GST_STREAMING)
#ifndef QGC_DISABLE_UVC #ifndef QGC_DISABLE_UVC
// If we are using a UVC camera setup the device name // If we are using a UVC camera setup the device name
QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); _updateUVC();
for (const QCameraInfo &cameraInfo: cameras) {
if(cameraInfo.description() == videoSource) {
_videoSourceID = cameraInfo.deviceName();
emit videoSourceIDChanged();
qCDebug(VideoManagerLog) << "Found USB source:" << _videoSourceID << " Name:" << videoSource;
break;
}
}
#endif #endif
emit isGStreamerChanged(); emit isGStreamerChanged();
...@@ -89,10 +81,29 @@ VideoManager::setToolbox(QGCToolbox *toolbox) ...@@ -89,10 +81,29 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
#endif #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 void
VideoManager::_videoSourceChanged() VideoManager::_videoSourceChanged()
{ {
_updateUVC();
emit hasVideoChanged(); emit hasVideoChanged();
emit isGStreamerChanged(); emit isGStreamerChanged();
_restartVideo(); _restartVideo();
......
...@@ -56,8 +56,8 @@ public: ...@@ -56,8 +56,8 @@ public:
// Override from QGCTool // Override from QGCTool
void setToolbox (QGCToolbox *toolbox); void setToolbox (QGCToolbox *toolbox);
Q_INVOKABLE void startVideo() {_videoReceiver->start();}; Q_INVOKABLE void startVideo() {_videoReceiver->start();}
Q_INVOKABLE void stopVideo() {_videoReceiver->stop();}; Q_INVOKABLE void stopVideo() {_videoReceiver->stop(); }
signals: signals:
void hasVideoChanged (); void hasVideoChanged ();
...@@ -70,6 +70,7 @@ private slots: ...@@ -70,6 +70,7 @@ private slots:
void _udpPortChanged (); void _udpPortChanged ();
void _rtspUrlChanged (); void _rtspUrlChanged ();
void _tcpUrlChanged (); void _tcpUrlChanged ();
void _updateUVC ();
private: private:
void _updateSettings (); void _updateSettings ();
......
...@@ -32,7 +32,6 @@ DECLARE_SETTINGGROUP(Video, "Video") ...@@ -32,7 +32,6 @@ DECLARE_SETTINGGROUP(Video, "Video")
qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only"); qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
// Setup enum values for videoSource settings into meta data // Setup enum values for videoSource settings into meta data
bool noVideo = false;
QStringList videoSourceList; QStringList videoSourceList;
#ifdef QGC_GST_STREAMING #ifdef QGC_GST_STREAMING
#ifndef NO_UDP_VIDEO #ifndef NO_UDP_VIDEO
...@@ -51,7 +50,7 @@ DECLARE_SETTINGGROUP(Video, "Video") ...@@ -51,7 +50,7 @@ DECLARE_SETTINGGROUP(Video, "Video")
} }
#endif #endif
if (videoSourceList.count() == 0) { if (videoSourceList.count() == 0) {
noVideo = true; _noVideo = true;
videoSourceList.append(videoSourceNoVideo); videoSourceList.append(videoSourceNoVideo);
} else { } else {
videoSourceList.insert(0, videoDisabled); videoSourceList.insert(0, videoDisabled);
...@@ -63,7 +62,12 @@ DECLARE_SETTINGGROUP(Video, "Video") ...@@ -63,7 +62,12 @@ DECLARE_SETTINGGROUP(Video, "Video")
_nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList); _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);
// Set default value for videoSource // Set default value for videoSource
if (noVideo) { _setDefaults();
}
void VideoSettings::_setDefaults()
{
if (_noVideo) {
_nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo); _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
} else { } else {
_nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled); _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
...@@ -85,6 +89,14 @@ DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource) ...@@ -85,6 +89,14 @@ DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource)
{ {
if (!_videoSourceFact) { if (!_videoSourceFact) {
_videoSourceFact = _createSettingsFact(videoSourceName); _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); connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
} }
return _videoSourceFact; return _videoSourceFact;
......
...@@ -55,6 +55,11 @@ private slots: ...@@ -55,6 +55,11 @@ private slots:
void _configChanged (QVariant value); void _configChanged (QVariant value);
private: private:
void _setDefaults ();
private:
bool _noVideo = false;
}; };
#endif #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