Browse Source

Refactor and fix Video manager issues #10348

QGC4.4
Zdanek 3 years ago committed by Ramon Roche
parent
commit
4695cb3c5f
  1. 21
      src/FlightDisplay/FlightDisplayViewUVC.qml
  2. 79
      src/VideoManager/VideoManager.cc
  3. 11
      src/VideoManager/VideoManager.h
  4. 1
      src/VideoReceiver/GstVideoReceiver.cc
  5. 2
      src/ui/preferences/GeneralSettings.qml

21
src/FlightDisplay/FlightDisplayViewUVC.qml

@ -19,6 +19,7 @@ Rectangle { @@ -19,6 +19,7 @@ Rectangle {
color: Qt.rgba(0,0,0,0.75)
clip: true
anchors.centerIn: parent
visible: QGroundControl.videoManager.isUvc
function adjustAspectRatio()
{
@ -32,7 +33,7 @@ Rectangle { @@ -32,7 +33,7 @@ Rectangle {
Camera {
id: camera
deviceId: QGroundControl.videoManager.videoSourceID
deviceId: QGroundControl.videoManager.uvcVideoSourceID
captureMode: Camera.CaptureViewfinder
onDeviceIdChanged: {
adjustAspectRatio()
@ -47,12 +48,16 @@ Rectangle { @@ -47,12 +48,16 @@ Rectangle {
source: camera
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectCrop
visible: !QGroundControl.videoManager.isGStreamer
}
onVisibleChanged: {
if(visible)
camera.start()
else
camera.stop()
visible: QGroundControl.videoManager.isUvc
onVisibleChanged: {
console.log('UVC Video output visible: ', visible);
if (visible) {
camera.start()
}
else {
camera.stop()
}
}
}
}

79
src/VideoManager/VideoManager.cc

@ -110,6 +110,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox) @@ -110,6 +110,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
#ifndef QGC_DISABLE_UVC
// If we are using a UVC camera setup the device name
_updateUVC();
emit isUvcChanged();
#endif
emit isGStreamerChanged();
@ -124,10 +125,12 @@ VideoManager::setToolbox(QGCToolbox *toolbox) @@ -124,10 +125,12 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
});
connect(_videoReceiver[0], &VideoReceiver::onStartComplete, this, [this](VideoReceiver::STATUS status) {
qCDebug(VideoManagerLog) << "Video 0 Start complete, status: " << status;
if (status == VideoReceiver::STATUS_OK) {
_videoStarted[0] = true;
if (_videoSink[0] != nullptr) {
// It is absolytely ok to have video receiver active (streaming) and decoding not active
qCDebug(VideoManagerLog) << "Video 0 start decoding";
// It is absolutely ok to have video receiver active (streaming) and decoding not active
// It should be handy for cases when you have many streams and want to show only some of them
// NOTE that even if decoder did not start it is still possible to record video
_videoReceiver[0]->startDecoding(_videoSink[0]);
@ -141,17 +144,24 @@ VideoManager::setToolbox(QGCToolbox *toolbox) @@ -141,17 +144,24 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
}
});
connect(_videoReceiver[0], &VideoReceiver::onStopComplete, this, [this](VideoReceiver::STATUS) {
connect(_videoReceiver[0], &VideoReceiver::onStopComplete, this, [this](VideoReceiver::STATUS status) {
qCDebug(VideoManagerLog) << "Video 0 Stop complete, status: " << status;
_videoStarted[0] = false;
_startReceiver(0);
if (status == VideoReceiver::STATUS_INVALID_URL) {
qCDebug(VideoManagerLog) << "Invalid video URL. Not restarting";
} else {
_startReceiver(0);
}
});
connect(_videoReceiver[0], &VideoReceiver::decodingChanged, this, [this](bool active){
qCDebug(VideoManagerLog) << "Video 0 decoding changed, active: " << (active ? "yes" : "no");
_decoding = active;
emit decodingChanged();
});
connect(_videoReceiver[0], &VideoReceiver::recordingChanged, this, [this](bool active){
qCDebug(VideoManagerLog) << "Video 0 recording changed, active: " << (active ? "yes" : "no");
_recording = active;
if (!active) {
_subtitleWriter.stopCapturingTelemetry();
@ -160,10 +170,12 @@ VideoManager::setToolbox(QGCToolbox *toolbox) @@ -160,10 +170,12 @@ VideoManager::setToolbox(QGCToolbox *toolbox)
});
connect(_videoReceiver[0], &VideoReceiver::recordingStarted, this, [this](){
qCDebug(VideoManagerLog) << "Video 0 recording started";
_subtitleWriter.startCapturingTelemetry(_videoFile);
});
connect(_videoReceiver[0], &VideoReceiver::videoSizeChanged, this, [this](QSize size){
qCDebug(VideoManagerLog) << "Video 0 resized. New resolution: " << size.width() << "x" << size.height();
_videoSize = ((quint32)size.width() << 16) | (quint32)size.height();
emit videoSizeChanged();
});
@ -459,16 +471,28 @@ void @@ -459,16 +471,28 @@ 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;
QString oldUvcVideoSrcID = _uvcVideoSourceID;
if (!hasVideo() || isGStreamer()) {
_uvcVideoSourceID = "";
} else {
QString videoSource = _videoSettings->videoSource()->rawValue().toString();
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
for (const QCameraInfo &cameraInfo : cameras) {
if (cameraInfo.description() == videoSource) {
_uvcVideoSourceID = cameraInfo.deviceName();
qCDebug(VideoManagerLog)
<< "Found USB source:" << _uvcVideoSourceID << " Name:" << videoSource;
break;
}
}
}
if (oldUvcVideoSrcID != _uvcVideoSourceID) {
qCDebug(VideoManagerLog) << "UVC changed from [" << oldUvcVideoSrcID << "] to [" << _uvcVideoSourceID << "]";
emit uvcVideoSourceIDChanged();
emit isUvcChanged();
}
#endif
}
@ -477,10 +501,16 @@ void @@ -477,10 +501,16 @@ void
VideoManager::_videoSourceChanged()
{
_updateUVC();
_updateSettings(0);
emit hasVideoChanged();
emit isGStreamerChanged();
emit isUvcChanged();
emit isAutoStreamChanged();
_restartVideo(0);
if (hasVideo()) {
_restartVideo(0);
} else {
stopVideo();
}
}
//-----------------------------------------------------------------------------
@ -542,6 +572,18 @@ VideoManager::isGStreamer() @@ -542,6 +572,18 @@ VideoManager::isGStreamer()
#endif
}
bool
VideoManager::isUvc()
{
#ifndef QGC_DISABLE_UVC
auto isUvc = hasVideo() && !_uvcVideoSourceID.isEmpty();
qCDebug(VideoManagerLog) << "Is Video source UVC: " << (isUvc ? "yes" : "no");
return isUvc;
#else
return false;
#endif
}
//-----------------------------------------------------------------------------
#ifndef QGC_DISABLE_UVC
bool
@ -700,6 +742,15 @@ VideoManager::_updateSettings(unsigned id) @@ -700,6 +742,15 @@ VideoManager::_updateSettings(unsigned id)
settingsChanged |= _updateVideoUri(0, QStringLiteral("udp://0.0.0.0:8888"));
else if (source == VideoSettings::videoSourceYuneecMantisG)
settingsChanged |= _updateVideoUri(0, QStringLiteral("rtsp://192.168.42.1:554/live"));
else if (source == VideoSettings::videoDisabled || source == VideoSettings::videoSourceNoVideo)
settingsChanged |= _updateVideoUri(0, "");
else {
settingsChanged |= _updateVideoUri(0, "");
if (!isUvc()) {
qCCritical(VideoManagerLog)
<< "Video source URI \"" << source << "\" is not supported. Please add support!";
}
}
return settingsChanged;
}
@ -751,9 +802,9 @@ VideoManager::_restartVideo(unsigned id) @@ -751,9 +802,9 @@ VideoManager::_restartVideo(unsigned id)
_updateSettings(id);
bool newLowLatencyStreaming = _lowLatencyStreaming[id];
QString newUri = _videoUri[id];
qCDebug(VideoManagerLog) << "New Video URI " << newUri;
// FIXME: AV: use _updateSettings() result to check if settings were changed
if (oldUri == newUri && oldLowLatencyStreaming == newLowLatencyStreaming && _videoStarted[id]) {
if (_videoStarted[id] && oldUri == newUri && oldLowLatencyStreaming == newLowLatencyStreaming) {
qCDebug(VideoManagerLog) << "No sense to restart video streaming, skipped" << id;
return;
}

11
src/VideoManager/VideoManager.h

@ -38,8 +38,9 @@ public: @@ -38,8 +38,9 @@ public:
Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged)
Q_PROPERTY(bool isGStreamer READ isGStreamer NOTIFY isGStreamerChanged)
Q_PROPERTY(bool isUvc READ isUvc NOTIFY isUvcChanged)
Q_PROPERTY(bool isTaisync READ isTaisync WRITE setIsTaisync NOTIFY isTaisyncChanged)
Q_PROPERTY(QString videoSourceID READ videoSourceID NOTIFY videoSourceIDChanged)
Q_PROPERTY(QString uvcVideoSourceID READ uvcVideoSourceID NOTIFY uvcVideoSourceIDChanged)
Q_PROPERTY(bool uvcEnabled READ uvcEnabled CONSTANT)
Q_PROPERTY(bool fullScreen READ fullScreen WRITE setfullScreen NOTIFY fullScreenChanged)
Q_PROPERTY(VideoReceiver* videoReceiver READ videoReceiver CONSTANT)
@ -58,9 +59,10 @@ public: @@ -58,9 +59,10 @@ public:
virtual bool hasVideo ();
virtual bool isGStreamer ();
virtual bool isUvc ();
virtual bool isTaisync () { return _isTaisync; }
virtual bool fullScreen () { return _fullScreen; }
virtual QString videoSourceID () { return _videoSourceID; }
virtual QString uvcVideoSourceID () { return _uvcVideoSourceID; }
virtual double aspectRatio ();
virtual double thermalAspectRatio ();
virtual double hfov ();
@ -114,7 +116,8 @@ public: @@ -114,7 +116,8 @@ public:
signals:
void hasVideoChanged ();
void isGStreamerChanged ();
void videoSourceIDChanged ();
void isUvcChanged ();
void uvcVideoSourceIDChanged ();
void fullScreenChanged ();
void isAutoStreamChanged ();
void isTaisyncChanged ();
@ -170,7 +173,7 @@ protected: @@ -170,7 +173,7 @@ protected:
QAtomicInteger<bool> _recording = false;
QAtomicInteger<quint32> _videoSize = 0;
VideoSettings* _videoSettings = nullptr;
QString _videoSourceID;
QString _uvcVideoSourceID;
bool _fullScreen = false;
Vehicle* _activeVehicle = nullptr;
};

1
src/VideoReceiver/GstVideoReceiver.cc

@ -1297,6 +1297,7 @@ GstVideoReceiver::_onBusMessage(GstBus* bus, GstMessage* msg, gpointer data) @@ -1297,6 +1297,7 @@ GstVideoReceiver::_onBusMessage(GstBus* bus, GstMessage* msg, gpointer data)
gst_message_parse_error(msg, &error, &debug);
if (debug != nullptr) {
qCDebug(VideoReceiverLog) << "GStreamer debug: " << debug;
g_free(debug);
debug = nullptr;
}

2
src/ui/preferences/GeneralSettings.qml

@ -300,7 +300,7 @@ Rectangle { @@ -300,7 +300,7 @@ Rectangle {
QGCLabel {
id: videoFileFormatLabel
text: qsTr("File Format")
text: qsTr("Record File Format")
visible: _showSaveVideoSettings && _videoSettings.recordingFormat.visible
}
FactComboBox {

Loading…
Cancel
Save