From c70a6fa4b0c50bdaf1814874b0afcd4a4a2aeaca Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Wed, 6 Jun 2018 10:06:59 -0400 Subject: [PATCH] Expose VideoReceiver allowing plugins to override it. --- src/FlightDisplay/VideoManager.cc | 2 +- src/VideoStreaming/VideoReceiver.cc | 7 +-- src/VideoStreaming/VideoReceiver.h | 82 +++++++++++++++-------------- src/api/QGCCorePlugin.cc | 6 +++ src/api/QGCCorePlugin.h | 4 ++ 5 files changed, 57 insertions(+), 44 deletions(-) diff --git a/src/FlightDisplay/VideoManager.cc b/src/FlightDisplay/VideoManager.cc index a2b839a47..702e20250 100644 --- a/src/FlightDisplay/VideoManager.cc +++ b/src/FlightDisplay/VideoManager.cc @@ -78,7 +78,7 @@ VideoManager::setToolbox(QGCToolbox *toolbox) emit isGStreamerChanged(); qCDebug(VideoManagerLog) << "New Video Source:" << videoSource; - _videoReceiver = new VideoReceiver(this); + _videoReceiver = toolbox->corePlugin()->createVideoReceiver(this); _updateSettings(); if(isGStreamer()) { _videoReceiver->start(); diff --git a/src/VideoStreaming/VideoReceiver.cc b/src/VideoStreaming/VideoReceiver.cc index a51638df6..97455b383 100644 --- a/src/VideoStreaming/VideoReceiver.cc +++ b/src/VideoStreaming/VideoReceiver.cc @@ -63,6 +63,7 @@ VideoReceiver::VideoReceiver(QObject* parent) , _videoSink(NULL) , _socket(NULL) , _serverPresent(false) + , _rtspTestInterval_ms(5000) #endif , _videoSurface(NULL) , _videoRunning(false) @@ -164,9 +165,9 @@ VideoReceiver::_socketError(QAbstractSocket::SocketError socketError) Q_UNUSED(socketError); _socket->deleteLater(); _socket = NULL; - //-- Try again in 5 seconds + //-- Try again in a while if(_videoSettings->streamEnabled()->rawValue().toBool()) { - _timer.start(5000); + _timer.start(_rtspTestInterval_ms); } } #endif @@ -194,7 +195,7 @@ VideoReceiver::_timeout() connect(_socket, static_cast(&QTcpSocket::error), this, &VideoReceiver::_socketError); connect(_socket, &QTcpSocket::connected, this, &VideoReceiver::_connected); _socket->connectToHost(url.host(), url.port()); - _timer.start(5000); + _timer.start(_rtspTestInterval_ms); } } #endif diff --git a/src/VideoStreaming/VideoReceiver.h b/src/VideoStreaming/VideoReceiver.h index 7739b2350..edecf8502 100644 --- a/src/VideoStreaming/VideoReceiver.h +++ b/src/VideoStreaming/VideoReceiver.h @@ -49,54 +49,54 @@ public: ~VideoReceiver(); #if defined(QGC_GST_STREAMING) - bool running () { return _running; } - bool recording () { return _recording; } - bool streaming () { return _streaming; } - bool starting () { return _starting; } - bool stopping () { return _stopping; } + virtual bool running () { return _running; } + virtual bool recording () { return _recording; } + virtual bool streaming () { return _streaming; } + virtual bool starting () { return _starting; } + virtual bool stopping () { return _stopping; } #endif - VideoSurface* videoSurface () { return _videoSurface; } - bool videoRunning () { return _videoRunning; } - QString imageFile () { return _imageFile; } - QString videoFile () { return _videoFile; } - bool showFullScreen () { return _showFullScreen; } + virtual VideoSurface* videoSurface () { return _videoSurface; } + virtual bool videoRunning () { return _videoRunning; } + virtual QString imageFile () { return _imageFile; } + virtual QString videoFile () { return _videoFile; } + virtual bool showFullScreen () { return _showFullScreen; } - void grabImage (QString imageFile); + virtual void grabImage (QString imageFile); - void setShowFullScreen (bool show) { _showFullScreen = show; emit showFullScreenChanged(); } + virtual void setShowFullScreen (bool show) { _showFullScreen = show; emit showFullScreenChanged(); } signals: - void videoRunningChanged (); - void imageFileChanged (); - void videoFileChanged (); - void showFullScreenChanged (); + void videoRunningChanged (); + void imageFileChanged (); + void videoFileChanged (); + void showFullScreenChanged (); #if defined(QGC_GST_STREAMING) - void recordingChanged (); - void msgErrorReceived (); - void msgEOSReceived (); - void msgStateChangedReceived (); + void recordingChanged (); + void msgErrorReceived (); + void msgEOSReceived (); + void msgStateChangedReceived (); #endif public slots: - void start (); - void stop (); - void setUri (const QString& uri); - void stopRecording (); - void startRecording (const QString& videoFile = QString()); - -private slots: - void _updateTimer (); + virtual void start (); + virtual void stop (); + virtual void setUri (const QString& uri); + virtual void stopRecording (); + virtual void startRecording (const QString& videoFile = QString()); + +protected slots: + virtual void _updateTimer (); #if defined(QGC_GST_STREAMING) - void _timeout (); - void _connected (); - void _socketError (QAbstractSocket::SocketError socketError); - void _handleError (); - void _handleEOS (); - void _handleStateChanged (); + virtual void _timeout (); + virtual void _connected (); + virtual void _socketError (QAbstractSocket::SocketError socketError); + virtual void _handleError (); + virtual void _handleEOS (); + virtual void _handleStateChanged (); #endif -private: +protected: #if defined(QGC_GST_STREAMING) typedef struct @@ -121,11 +121,12 @@ private: static gboolean _onBusMessage (GstBus* bus, GstMessage* message, gpointer user_data); static GstPadProbeReturn _unlinkCallBack (GstPad* pad, GstPadProbeInfo* info, gpointer user_data); static GstPadProbeReturn _keyframeWatch (GstPad* pad, GstPadProbeInfo* info, gpointer user_data); - void _detachRecordingBranch (GstPadProbeInfo* info); - void _shutdownRecordingBranch(); - void _shutdownPipeline (); - void _cleanupOldVideos (); - void _setVideoSink (GstElement* sink); + + virtual void _detachRecordingBranch (GstPadProbeInfo* info); + virtual void _shutdownRecordingBranch(); + virtual void _shutdownPipeline (); + virtual void _cleanupOldVideos (); + virtual void _setVideoSink (GstElement* sink); GstElement* _pipeline; GstElement* _pipelineStopRec; @@ -136,6 +137,7 @@ private: QTimer _timer; QTcpSocket* _socket; bool _serverPresent; + int _rtspTestInterval_ms; #endif diff --git a/src/api/QGCCorePlugin.cc b/src/api/QGCCorePlugin.cc index d99898b52..9031c9056 100644 --- a/src/api/QGCCorePlugin.cc +++ b/src/api/QGCCorePlugin.cc @@ -15,6 +15,7 @@ #include "SettingsManager.h" #include "AppMessages.h" #include "QmlObjectListModel.h" +#include "VideoReceiver.h" #include #include @@ -286,3 +287,8 @@ QmlObjectListModel* QGCCorePlugin::customMapItems(void) { return &_p->_emptyCustomMapItems; } + +VideoReceiver* QGCCorePlugin::createVideoReceiver(QObject* parent) +{ + return new VideoReceiver(parent); +} diff --git a/src/api/QGCCorePlugin.h b/src/api/QGCCorePlugin.h index cb8b82a97..b68f32457 100644 --- a/src/api/QGCCorePlugin.h +++ b/src/api/QGCCorePlugin.h @@ -31,6 +31,7 @@ class QQmlApplicationEngine; class Vehicle; class LinkInterface; class QmlObjectListModel; +class VideoReceiver; class QGCCorePlugin : public QGCTool { @@ -98,6 +99,9 @@ public: /// Allows the plugin to override the creation of the root (native) window. virtual QQmlApplicationEngine* createRootWindow(QObject* parent); + /// Allows the plugin to override the creation of VideoReceiver. + virtual VideoReceiver* createVideoReceiver(QObject* parent); + /// Allows the plugin to see all mavlink traffic to a vehicle /// @return true: Allow vehicle to continue processing, false: Vehicle should not process message virtual bool mavlinkMessage(Vehicle* vehicle, LinkInterface* link, mavlink_message_t message); -- 2.22.0