From 05c8fde3c14e08b205456024c207ed2c2fe13164 Mon Sep 17 00:00:00 2001 From: Jacob Walser Date: Wed, 4 Jan 2017 12:28:34 -0500 Subject: [PATCH] Add button in general settings to select location to save video files --- src/FlightDisplay/VideoManager.cc | 14 ++++++++++++ src/FlightDisplay/VideoManager.h | 5 +++++ src/VideoStreaming/VideoReceiver.cc | 17 ++++++++++++-- src/VideoStreaming/VideoReceiver.h | 12 +++++----- src/ui/preferences/GeneralSettings.qml | 31 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/FlightDisplay/VideoManager.cc b/src/FlightDisplay/VideoManager.cc index 85437d3bd..943ff18d1 100644 --- a/src/FlightDisplay/VideoManager.cc +++ b/src/FlightDisplay/VideoManager.cc @@ -27,6 +27,7 @@ static const char* kVideoSourceKey = "VideoSource"; static const char* kVideoUDPPortKey = "VideoUDPPort"; static const char* kVideoRTSPUrlKey = "VideoRTSPUrl"; +static const char* kVideoSavePathKey = "VideoSaveDir"; #if defined(QGC_GST_STREAMING) static const char* kUDPStream = "UDP Video Stream"; static const char* kRTSPStream = "RTSP Video Stream"; @@ -80,6 +81,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox) setUdpPort(settings.value(kVideoUDPPortKey, 5600).toUInt()); setRtspURL(settings.value(kVideoRTSPUrlKey, "rtsp://192.168.42.1:554/live").toString()); //-- Example RTSP URL } + setVideoSavePath(settings.value(kVideoSavePathKey, QDir::homePath()).toString()); #endif _init = true; #if defined(QGC_GST_STREAMING) @@ -186,6 +188,17 @@ VideoManager::setRtspURL(QString url) */ } +void +VideoManager::setVideoSavePath(QString path) +{ + _videoSavePath = path; + QSettings settings; + settings.setValue(kVideoSavePathKey, path); + if(_videoReceiver) + _videoReceiver->setVideoSavePath(_videoSavePath); + emit videoSavePathChanged(); +} + //----------------------------------------------------------------------------- QStringList VideoManager::videoSourceList() @@ -265,6 +278,7 @@ void VideoManager::_updateVideo() _videoReceiver->setUri(QStringLiteral("udp://0.0.0.0:%1").arg(_udpPort)); else _videoReceiver->setUri(_rtspURL); + _videoReceiver->setVideoSavePath(_videoSavePath); #endif _videoReceiver->start(); } diff --git a/src/FlightDisplay/VideoManager.h b/src/FlightDisplay/VideoManager.h index 2ff5cfac6..1e1cbbe7b 100644 --- a/src/FlightDisplay/VideoManager.h +++ b/src/FlightDisplay/VideoManager.h @@ -37,6 +37,7 @@ public: Q_PROPERTY(bool videoRunning READ videoRunning NOTIFY videoRunningChanged) Q_PROPERTY(quint16 udpPort READ udpPort WRITE setUdpPort NOTIFY udpPortChanged) Q_PROPERTY(QString rtspURL READ rtspURL WRITE setRtspURL NOTIFY rtspURLChanged) + Q_PROPERTY(QString videoSavePath READ videoSavePath WRITE setVideoSavePath NOTIFY videoSavePathChanged) Q_PROPERTY(bool uvcEnabled READ uvcEnabled CONSTANT) Q_PROPERTY(VideoSurface* videoSurface MEMBER _videoSurface CONSTANT) Q_PROPERTY(VideoReceiver* videoReceiver MEMBER _videoReceiver CONSTANT) @@ -49,6 +50,7 @@ public: QStringList videoSourceList (); quint16 udpPort () { return _udpPort; } QString rtspURL () { return _rtspURL; } + QString videoSavePath () { return _videoSavePath; } #if defined(QGC_DISABLE_UVC) bool uvcEnabled () { return false; } @@ -59,6 +61,7 @@ public: void setVideoSource (QString vSource); void setUdpPort (quint16 port); void setRtspURL (QString url); + void setVideoSavePath (QString path); // Override from QGCTool void setToolbox (QGCToolbox *toolbox); @@ -72,6 +75,7 @@ signals: void videoSourceIDChanged (); void udpPortChanged (); void rtspURLChanged (); + void videoSavePathChanged (); private: void _updateTimer (); @@ -89,6 +93,7 @@ private: QStringList _videoSourceList; quint16 _udpPort; QString _rtspURL; + QString _videoSavePath; bool _init; }; diff --git a/src/VideoStreaming/VideoReceiver.cc b/src/VideoStreaming/VideoReceiver.cc index e382d8ed3..e0385816e 100644 --- a/src/VideoStreaming/VideoReceiver.cc +++ b/src/VideoStreaming/VideoReceiver.cc @@ -19,6 +19,7 @@ #include #include #include +#include VideoReceiver::Sink* VideoReceiver::_sink = NULL; GstElement* VideoReceiver::_pipeline = NULL; @@ -127,8 +128,14 @@ void VideoReceiver::startRecording(void) _sink->filesink = gst_element_factory_make("filesink", NULL); _sink->removing = false; - QString filename = QDir::homePath() + "/" + QDateTime::currentDateTime().toString() + ".mkv"; - g_object_set(G_OBJECT(_sink->filesink), "location", qPrintable(filename), NULL); + QString fileName; + if(QSysInfo::WindowsVersion != QSysInfo::WV_None) { + fileName = _path + "\\QGC-" + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh:mm:ss") + ".mkv"; + } else { + fileName = _path + "/QGC-" + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh:mm:ss") + ".mkv"; + } + g_object_set(G_OBJECT(_sink->filesink), "location", qPrintable(fileName), NULL); + qDebug() << "New video file:" << fileName; gst_object_ref(_sink->queue); gst_object_ref(_sink->mux); @@ -482,6 +489,12 @@ void VideoReceiver::setUri(const QString & uri) _uri = uri; } +void VideoReceiver::setVideoSavePath(const QString & path) +{ + _path = path; + qDebug() << "New Path:" << _path; +} + #if defined(QGC_GST_STREAMING) void VideoReceiver::_onBusMessage(GstMessage* msg) { diff --git a/src/VideoStreaming/VideoReceiver.h b/src/VideoStreaming/VideoReceiver.h index 847faf749..27c78a531 100644 --- a/src/VideoStreaming/VideoReceiver.h +++ b/src/VideoStreaming/VideoReceiver.h @@ -47,11 +47,12 @@ signals: void streamingChanged(); public slots: - void start (); - void stop (); - void setUri (const QString& uri); - void stopRecording (); - void startRecording (); + void start (); + void stop (); + void setUri (const QString& uri); + void setVideoSavePath (const QString& path); + void stopRecording (); + void startRecording (); private slots: #if defined(QGC_GST_STREAMING) @@ -85,6 +86,7 @@ private: #endif QString _uri; + QString _path; #if defined(QGC_GST_STREAMING) static GstElement* _pipeline; diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index d22c60515..ba381f8f7 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -41,6 +41,18 @@ QGCView { QGCPalette { id: qgcPal } + FileDialog { + id: fileDialog + title: "Choose a location to save video files." + folder: shortcuts.home + selectFolder: true + onAccepted: { + var path = fileDialog.fileUrl.toString(); + path = path.replace(/^(file:\/{2})/,""); + QGroundControl.videoManager.videoSavePath = path + } + } + QGCViewPanel { id: panel anchors.fill: parent @@ -499,6 +511,25 @@ QGCView { } } } + Row { + spacing: ScreenTools.defaultFontPixelWidth + visible: QGroundControl.videoManager.isGStreamer + QGCLabel { + anchors.baseline: pathField.baseline + text: qsTr("Save Path:") + width: _labelWidth + } + QGCTextField { + id: pathField + width: _editFieldWidth + readOnly: true + text: QGroundControl.videoManager.videoSavePath + } + Button { + text: "Browse" + onClicked: fileDialog.visible = true + } + } } } -- 2.22.0