Commit fb03713f authored by Andrew Voznytsa's avatar Andrew Voznytsa

Switch VideoReceiver to new API (big refactoring)

parent 862508fc
...@@ -388,11 +388,11 @@ QGCCameraControl::takePhoto() ...@@ -388,11 +388,11 @@ QGCCameraControl::takePhoto()
_setPhotoStatus(PHOTO_CAPTURE_IN_PROGRESS); _setPhotoStatus(PHOTO_CAPTURE_IN_PROGRESS);
_captureInfoRetries = 0; _captureInfoRetries = 0;
//-- Capture local image as well //-- Capture local image as well
if(qgcApp()->toolbox()->videoManager()->videoReceiver()) { if(qgcApp()->toolbox()->videoManager()) {
QString photoPath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValue().toString() + QStringLiteral("/Photo"); QString photoPath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValue().toString() + QStringLiteral("/Photo");
QDir().mkpath(photoPath); QDir().mkpath(photoPath);
photoPath += + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss.zzz") + ".jpg"; photoPath += + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss.zzz") + ".jpg";
qgcApp()->toolbox()->videoManager()->videoReceiver()->grabImage(photoPath); qgcApp()->toolbox()->videoManager()->grabImage(photoPath);
} }
return true; return true;
} }
...@@ -1542,11 +1542,11 @@ QGCCameraControl::handleCaptureStatus(const mavlink_camera_capture_status_t& cap ...@@ -1542,11 +1542,11 @@ QGCCameraControl::handleCaptureStatus(const mavlink_camera_capture_status_t& cap
//-- Time Lapse //-- Time Lapse
if(photoStatus() == PHOTO_CAPTURE_INTERVAL_IDLE || photoStatus() == PHOTO_CAPTURE_INTERVAL_IN_PROGRESS) { if(photoStatus() == PHOTO_CAPTURE_INTERVAL_IDLE || photoStatus() == PHOTO_CAPTURE_INTERVAL_IN_PROGRESS) {
//-- Capture local image as well //-- Capture local image as well
if(qgcApp()->toolbox()->videoManager()->videoReceiver()) { if(qgcApp()->toolbox()->videoManager()) {
QString photoPath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValue().toString() + QStringLiteral("/Photo"); QString photoPath = qgcApp()->toolbox()->settingsManager()->appSettings()->savePath()->rawValue().toString() + QStringLiteral("/Photo");
QDir().mkpath(photoPath); QDir().mkpath(photoPath);
photoPath += + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss.zzz") + ".jpg"; photoPath += + "/" + QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss.zzz") + ".jpg";
qgcApp()->toolbox()->videoManager()->videoReceiver()->grabImage(photoPath); qgcApp()->toolbox()->videoManager()->grabImage(photoPath);
} }
} }
} }
......
...@@ -40,7 +40,7 @@ Item { ...@@ -40,7 +40,7 @@ Item {
id: noVideo id: noVideo
anchors.fill: parent anchors.fill: parent
color: Qt.rgba(0,0,0,0.75) color: Qt.rgba(0,0,0,0.75)
visible: !(_videoReceiver && _videoReceiver.videoRunning) visible: !(_videoReceiver && _videoReceiver.decoding)
QGCLabel { QGCLabel {
text: QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue ? qsTr("WAITING FOR VIDEO") : qsTr("VIDEO DISABLED") text: QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue ? qsTr("WAITING FOR VIDEO") : qsTr("VIDEO DISABLED")
font.family: ScreenTools.demiboldFontFamily font.family: ScreenTools.demiboldFontFamily
...@@ -58,7 +58,7 @@ Item { ...@@ -58,7 +58,7 @@ Item {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
color: "black" color: "black"
visible: _videoReceiver && _videoReceiver.videoRunning visible: _videoReceiver && _videoReceiver.decoding
function getWidth() { function getWidth() {
//-- Fit Width or Stretch //-- Fit Width or Stretch
if(_fitMode === 0 || _fitMode === 2) { if(_fitMode === 0 || _fitMode === 2) {
...@@ -86,7 +86,7 @@ Item { ...@@ -86,7 +86,7 @@ Item {
target: _videoReceiver target: _videoReceiver
onImageFileChanged: { onImageFileChanged: {
videoContent.grabToImage(function(result) { videoContent.grabToImage(function(result) {
if (!result.saveToFile(_videoReceiver.imageFile)) { if (!result.saveToFile(QGroundControl.videoManager.imageFile)) {
console.error('Error capturing video frame'); console.error('Error capturing video frame');
} }
}); });
...@@ -130,7 +130,7 @@ Item { ...@@ -130,7 +130,7 @@ Item {
height: parent.getHeight() height: parent.getHeight()
width: parent.getWidth() width: parent.getWidth()
anchors.centerIn: parent anchors.centerIn: parent
visible: _videoReceiver && _videoReceiver.videoRunning visible: _videoReceiver && _videoReceiver.decoding
sourceComponent: videoBackgroundComponent sourceComponent: videoBackgroundComponent
property bool videoDisabled: QGroundControl.settingsManager.videoSettings.videoSource.rawValue === QGroundControl.settingsManager.videoSettings.disabledVideoSource property bool videoDisabled: QGroundControl.settingsManager.videoSettings.videoSource.rawValue === QGroundControl.settingsManager.videoSettings.disabledVideoSource
......
...@@ -33,7 +33,7 @@ Item { ...@@ -33,7 +33,7 @@ Item {
property bool _communicationLost: activeVehicle ? activeVehicle.connectionLost : false property bool _communicationLost: activeVehicle ? activeVehicle.connectionLost : false
property var _videoReceiver: QGroundControl.videoManager.videoReceiver property var _videoReceiver: QGroundControl.videoManager.videoReceiver
property bool _recordingVideo: _videoReceiver && _videoReceiver.recording property bool _recordingVideo: _videoReceiver && _videoReceiver.recording
property bool _videoRunning: _videoReceiver && _videoReceiver.videoRunning property bool _decodingVideo: _videoReceiver && _videoReceiver.decoding
property bool _streamingEnabled: QGroundControl.settingsManager.videoSettings.streamConfigured property bool _streamingEnabled: QGroundControl.settingsManager.videoSettings.streamConfigured
property var _dynamicCameras: activeVehicle ? activeVehicle.dynamicCameras : null property var _dynamicCameras: activeVehicle ? activeVehicle.dynamicCameras : null
property int _curCameraIndex: _dynamicCameras ? _dynamicCameras.currentCamera : 0 property int _curCameraIndex: _dynamicCameras ? _dynamicCameras.currentCamera : 0
...@@ -136,7 +136,7 @@ Item { ...@@ -136,7 +136,7 @@ Item {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
width: height width: height
radius: _recordingVideo ? 0 : height radius: _recordingVideo ? 0 : height
color: (_videoRunning && _streamingEnabled) ? "red" : "gray" color: (_decodingVideo && _streamingEnabled) ? "red" : "gray"
SequentialAnimation on opacity { SequentialAnimation on opacity {
running: _recordingVideo running: _recordingVideo
loops: Animation.Infinite loops: Animation.Infinite
...@@ -157,14 +157,14 @@ Item { ...@@ -157,14 +157,14 @@ Item {
} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
enabled: _videoRunning && _streamingEnabled enabled: _decodingVideo && _streamingEnabled
onClicked: { onClicked: {
if (_recordingVideo) { if (_recordingVideo) {
_videoReceiver.stopRecording() QGroundControl.videoManager.stopRecording()
// reset blinking animation // reset blinking animation
recordBtnBackground.opacity = 1 recordBtnBackground.opacity = 1
} else { } else {
_videoReceiver.startRecording(videoFileName.text) QGroundControl.videoManager.startRecording(videoFileName.text)
} }
} }
} }
......
...@@ -15,9 +15,6 @@ ...@@ -15,9 +15,6 @@
*/ */
#include "SubtitleWriter.h" #include "SubtitleWriter.h"
#include "SettingsManager.h"
#include "VideoReceiver.h"
#include "VideoManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCCorePlugin.h" #include "QGCCorePlugin.h"
#include <QDateTime> #include <QDateTime>
...@@ -31,48 +28,11 @@ const int SubtitleWriter::_sampleRate = 1; // Sample rate in Hz for getting tele ...@@ -31,48 +28,11 @@ const int SubtitleWriter::_sampleRate = 1; // Sample rate in Hz for getting tele
SubtitleWriter::SubtitleWriter(QObject* parent) SubtitleWriter::SubtitleWriter(QObject* parent)
: QObject(parent) : QObject(parent)
{ {
connect(&_timer, &QTimer::timeout, this, &SubtitleWriter::_captureTelemetry);
} }
void SubtitleWriter::setVideoReceiver(VideoReceiver* videoReceiver) void SubtitleWriter::startCapturingTelemetry(const QString& videoFile)
{ {
if(!videoReceiver) {
qCWarning(SubtitleWriterLog) << "Invalid VideoReceiver pointer! Aborting subtitle capture!";
return;
}
_videoReceiver = videoReceiver;
#if defined(QGC_GST_STREAMING)
// Only start writing subtitles once the recording pipeline actually starts
connect(_videoReceiver, &VideoReceiver::gotFirstRecordingKeyFrame, this, &SubtitleWriter::_startCapturingTelemetry);
// Captures recordingChanged() signals to stop writing subtitles
connect(_videoReceiver, &VideoReceiver::recordingChanged, this, &SubtitleWriter::_onVideoRecordingChanged);
#endif
// Timer for telemetry capture and writing to file
connect(&_timer, &QTimer::timeout, this, &SubtitleWriter::_captureTelemetry);
}
void SubtitleWriter::_onVideoRecordingChanged()
{
#if defined(QGC_GST_STREAMING)
// Stop capturing data if recording stopped
if(!_videoReceiver->recording()) {
qCDebug(SubtitleWriterLog) << "Stopping writing";
_timer.stop();
_file.close();
}
#endif
}
void SubtitleWriter::_startCapturingTelemetry()
{
if(!_videoReceiver) {
qCWarning(SubtitleWriterLog) << "Invalid VideoReceiver pointer! Aborting subtitle capture!";
_timer.stop();
return;
}
// Get the facts displayed in the values widget and capture them, removing the "Vehicle." prefix. // Get the facts displayed in the values widget and capture them, removing the "Vehicle." prefix.
QSettings settings; QSettings settings;
settings.beginGroup("ValuesWidget"); settings.beginGroup("ValuesWidget");
...@@ -81,8 +41,8 @@ void SubtitleWriter::_startCapturingTelemetry() ...@@ -81,8 +41,8 @@ void SubtitleWriter::_startCapturingTelemetry()
_startTime = QDateTime::currentDateTime(); _startTime = QDateTime::currentDateTime();
QFileInfo videoFile(_videoReceiver->videoFile()); QFileInfo videoFileInfo(videoFile);
QString subtitleFilePath = QStringLiteral("%1/%2.ass").arg(videoFile.path(), videoFile.completeBaseName()); QString subtitleFilePath = QStringLiteral("%1/%2.ass").arg(videoFileInfo.path(), videoFileInfo.completeBaseName());
qCDebug(SubtitleWriterLog) << "Writing overlay to file:" << subtitleFilePath; qCDebug(SubtitleWriterLog) << "Writing overlay to file:" << subtitleFilePath;
_file.setFileName(subtitleFilePath); _file.setFileName(subtitleFilePath);
...@@ -118,14 +78,17 @@ void SubtitleWriter::_startCapturingTelemetry() ...@@ -118,14 +78,17 @@ void SubtitleWriter::_startCapturingTelemetry()
_timer.start(1000/_sampleRate); _timer.start(1000/_sampleRate);
} }
void SubtitleWriter::_captureTelemetry() void SubtitleWriter::stopCapturingTelemetry()
{ {
if(!_videoReceiver) { #if defined(QGC_GST_STREAMING)
qCWarning(SubtitleWriterLog) << "Invalid VideoReceiver pointer! Aborting subtitle capture!"; qCDebug(SubtitleWriterLog) << "Stopping writing";
_timer.stop(); _timer.stop();
return; _file.close();
} #endif
}
void SubtitleWriter::_captureTelemetry()
{
static const float nRows = 3; // number of rows used for displaying data static const float nRows = 3; // number of rows used for displaying data
static const int offsetFactor = 700; // Used to simulate a larger resolution and reduce the borders in the layout static const int offsetFactor = 700; // Used to simulate a larger resolution and reduce the borders in the layout
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#pragma once #pragma once
#include "QGCLoggingCategory.h" #include "QGCLoggingCategory.h"
#include "VideoReceiver.h"
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
#include <QDateTime> #include <QDateTime>
...@@ -33,25 +32,19 @@ public: ...@@ -33,25 +32,19 @@ public:
explicit SubtitleWriter(QObject* parent = nullptr); explicit SubtitleWriter(QObject* parent = nullptr);
~SubtitleWriter() = default; ~SubtitleWriter() = default;
void setVideoReceiver(VideoReceiver* videoReceiver); // starts capturing vehicle telemetry.
void startCapturingTelemetry(const QString& videoFile);
void stopCapturingTelemetry();
private slots: private slots:
// Fires with every "videoRecordingChanged() signal, stops capturing telemetry if video stopped."
void _onVideoRecordingChanged();
// Captures a snapshot of telemetry data from vehicle into the subtitles file. // Captures a snapshot of telemetry data from vehicle into the subtitles file.
void _captureTelemetry(); void _captureTelemetry();
// starts capturing vehicle telemetry.
void _startCapturingTelemetry();
private: private:
QTimer _timer; QTimer _timer;
QStringList _values; QStringList _values;
QDateTime _startTime; QDateTime _startTime;
QFile _file; QFile _file;
VideoReceiver* _videoReceiver;
static const int _sampleRate; static const int _sampleRate;
}; };
This diff is collapsed.
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
Q_PROPERTY(double thermalHfov READ thermalHfov NOTIFY aspectRatioChanged) Q_PROPERTY(double thermalHfov READ thermalHfov NOTIFY aspectRatioChanged)
Q_PROPERTY(bool autoStreamConfigured READ autoStreamConfigured NOTIFY autoStreamConfiguredChanged) Q_PROPERTY(bool autoStreamConfigured READ autoStreamConfigured NOTIFY autoStreamConfiguredChanged)
Q_PROPERTY(bool hasThermal READ hasThermal NOTIFY aspectRatioChanged) Q_PROPERTY(bool hasThermal READ hasThermal NOTIFY aspectRatioChanged)
Q_PROPERTY(QString imageFile READ imageFile NOTIFY imageFileChanged)
virtual bool hasVideo (); virtual bool hasVideo ();
virtual bool isGStreamer (); virtual bool isGStreamer ();
...@@ -62,14 +63,12 @@ public: ...@@ -62,14 +63,12 @@ public:
virtual double thermalHfov (); virtual double thermalHfov ();
virtual bool autoStreamConfigured(); virtual bool autoStreamConfigured();
virtual bool hasThermal (); virtual bool hasThermal ();
virtual void restartVideo (); virtual QString imageFile ();
virtual VideoReceiver* videoReceiver () { return _videoReceiver; } virtual VideoReceiver* videoReceiver () { return _videoReceiver; }
virtual VideoReceiver* thermalVideoReceiver () { return _thermalVideoReceiver; } virtual VideoReceiver* thermalVideoReceiver () { return _thermalVideoReceiver; }
QStringList videoExtensions();
QStringList videoMuxes();
#if defined(QGC_DISABLE_UVC) #if defined(QGC_DISABLE_UVC)
virtual bool uvcEnabled () { return false; } virtual bool uvcEnabled () { return false; }
#else #else
...@@ -85,7 +84,10 @@ public: ...@@ -85,7 +84,10 @@ public:
Q_INVOKABLE void startVideo (); Q_INVOKABLE void startVideo ();
Q_INVOKABLE void stopVideo (); Q_INVOKABLE void stopVideo ();
void cleanupOldVideos(); Q_INVOKABLE void startRecording (const QString& videoFile = QString());
Q_INVOKABLE void stopRecording ();
Q_INVOKABLE void grabImage(const QString& imageFile);
signals: signals:
void hasVideoChanged (); void hasVideoChanged ();
...@@ -96,6 +98,7 @@ signals: ...@@ -96,6 +98,7 @@ signals:
void isTaisyncChanged (); void isTaisyncChanged ();
void aspectRatioChanged (); void aspectRatioChanged ();
void autoStreamConfiguredChanged(); void autoStreamConfiguredChanged();
void imageFileChanged ();
protected slots: protected slots:
void _videoSourceChanged (); void _videoSourceChanged ();
...@@ -115,13 +118,29 @@ protected: ...@@ -115,13 +118,29 @@ protected:
#endif #endif
void _initVideo (); void _initVideo ();
void _updateSettings (); void _updateSettings ();
void _setVideoUri (const QString& uri);
void _setThermalVideoUri (const QString& uri);
void _cleanupOldVideos ();
void _restartVideo ();
void _streamingChanged ();
void _recordingStarted ();
void _recordingChanged ();
void _screenshotComplete ();
protected: protected:
QString _videoFile;
QString _imageFile;
SubtitleWriter _subtitleWriter; SubtitleWriter _subtitleWriter;
bool _isTaisync = false; bool _isTaisync = false;
VideoReceiver* _videoReceiver = nullptr; VideoReceiver* _videoReceiver = nullptr;
VideoReceiver* _thermalVideoReceiver = nullptr; VideoReceiver* _thermalVideoReceiver = nullptr;
#if defined(QGC_GST_STREAMING)
GstElement* _videoSink = nullptr;
GstElement* _thermalVideoSink = nullptr;
#endif
VideoSettings* _videoSettings = nullptr; VideoSettings* _videoSettings = nullptr;
QString _videoUri;
QString _thermalVideoUri;
QString _videoSourceID; QString _videoSourceID;
bool _fullScreen = false; bool _fullScreen = false;
Vehicle* _activeVehicle = nullptr; Vehicle* _activeVehicle = nullptr;
......
This diff is collapsed.
This diff is collapsed.
...@@ -125,6 +125,9 @@ _vsb_init(GstQgcVideoSinkBin *vsb) ...@@ -125,6 +125,9 @@ _vsb_init(GstQgcVideoSinkBin *vsb)
break; break;
} }
// FIXME: AV: temporally disable sync due to MPEG2-TS sync issues
g_object_set(vsb->qmlglsink, "sync", FALSE, NULL);
if ((glcolorconvert = gst_element_factory_make("glcolorconvert", NULL)) == NULL) { if ((glcolorconvert = gst_element_factory_make("glcolorconvert", NULL)) == NULL) {
GST_ERROR_OBJECT(vsb, "gst_element_factory_make('glcolorconvert' failed)"); GST_ERROR_OBJECT(vsb, "gst_element_factory_make('glcolorconvert' failed)");
break; break;
......
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