VideoManager.h 6.26 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/


#ifndef VideoManager_H
#define VideoManager_H

#include <QObject>
#include <QTimer>
16
#include <QTime>
17
#include <QUrl>
18

19
#include "QGCMAVLink.h"
20 21 22
#include "QGCLoggingCategory.h"
#include "VideoReceiver.h"
#include "QGCToolbox.h"
23
#include "SubtitleWriter.h"
24 25 26

Q_DECLARE_LOGGING_CATEGORY(VideoManagerLog)

27
class VideoSettings;
28
class Vehicle;
29
class Joystick;
30

31 32 33 34 35
class VideoManager : public QGCTool
{
    Q_OBJECT

public:
36
    VideoManager    (QGCApplication* app, QGCToolbox* toolbox);
37
    virtual ~VideoManager   ();
38

39 40 41 42 43 44 45
    Q_PROPERTY(bool             hasVideo                READ    hasVideo                                    NOTIFY hasVideoChanged)
    Q_PROPERTY(bool             isGStreamer             READ    isGStreamer                                 NOTIFY isGStreamerChanged)
    Q_PROPERTY(bool             isTaisync               READ    isTaisync       WRITE   setIsTaisync        NOTIFY isTaisyncChanged)
    Q_PROPERTY(QString          videoSourceID           READ    videoSourceID                               NOTIFY videoSourceIDChanged)
    Q_PROPERTY(bool             uvcEnabled              READ    uvcEnabled                                  CONSTANT)
    Q_PROPERTY(bool             fullScreen              READ    fullScreen      WRITE   setfullScreen       NOTIFY fullScreenChanged)
    Q_PROPERTY(VideoReceiver*   videoReceiver           READ    videoReceiver                               CONSTANT)
46
    Q_PROPERTY(VideoReceiver*   thermalVideoReceiver    READ    thermalVideoReceiver                        CONSTANT)
47
    Q_PROPERTY(double           aspectRatio             READ    aspectRatio                                 NOTIFY aspectRatioChanged)
48 49 50
    Q_PROPERTY(double           thermalAspectRatio      READ    thermalAspectRatio                          NOTIFY aspectRatioChanged)
    Q_PROPERTY(double           hfov                    READ    hfov                                        NOTIFY aspectRatioChanged)
    Q_PROPERTY(double           thermalHfov             READ    thermalHfov                                 NOTIFY aspectRatioChanged)
51
    Q_PROPERTY(bool             autoStreamConfigured    READ    autoStreamConfigured                        NOTIFY autoStreamConfiguredChanged)
52
    Q_PROPERTY(bool             hasThermal              READ    hasThermal                                  NOTIFY aspectRatioChanged)
53
    Q_PROPERTY(QString          imageFile               READ    imageFile                                   NOTIFY imageFileChanged)
54

55 56 57 58 59 60 61 62 63 64 65
    virtual bool        hasVideo            ();
    virtual bool        isGStreamer         ();
    virtual bool        isTaisync           () { return _isTaisync; }
    virtual bool        fullScreen          () { return _fullScreen; }
    virtual QString     videoSourceID       () { return _videoSourceID; }
    virtual double      aspectRatio         ();
    virtual double      thermalAspectRatio  ();
    virtual double      hfov                ();
    virtual double      thermalHfov         ();
    virtual bool        autoStreamConfigured();
    virtual bool        hasThermal          ();
66 67
    virtual QString     imageFile           ();

68 69 70

    virtual VideoReceiver*  videoReceiver           () { return _videoReceiver; }
    virtual VideoReceiver*  thermalVideoReceiver    () { return _thermalVideoReceiver; }
71

72
#if defined(QGC_DISABLE_UVC)
73
    virtual bool        uvcEnabled          () { return false; }
74
#else
75
    virtual bool        uvcEnabled          ();
76 77
#endif

78
    virtual void        setfullScreen       (bool f);
79
    virtual void        setIsTaisync        (bool t) { _isTaisync = t;  emit isTaisyncChanged(); }
80

81
    // Override from QGCTool
82
    virtual void        setToolbox          (QGCToolbox *toolbox);
83

84 85
    Q_INVOKABLE void startVideo     ();
    Q_INVOKABLE void stopVideo      ();
Patrick José Pereira's avatar
Patrick José Pereira committed
86

87 88 89 90
    Q_INVOKABLE void startRecording (const QString& videoFile = QString());
    Q_INVOKABLE void stopRecording  ();

    Q_INVOKABLE void grabImage(const QString& imageFile);
91

92
signals:
93 94 95
    void hasVideoChanged            ();
    void isGStreamerChanged         ();
    void videoSourceIDChanged       ();
96
    void fullScreenChanged          ();
97
    void isAutoStreamChanged        ();
98
    void isTaisyncChanged           ();
99 100
    void aspectRatioChanged         ();
    void autoStreamConfiguredChanged();
101
    void imageFileChanged           ();
102

103
protected slots:
104 105 106
    void _videoSourceChanged        ();
    void _udpPortChanged            ();
    void _rtspUrlChanged            ();
107
    void _tcpUrlChanged             ();
108
    void _lowLatencyModeChanged     ();
Gus Grubba's avatar
Gus Grubba committed
109
    void _updateUVC                 ();
110
    void _setActiveVehicle          (Vehicle* vehicle);
111
    void _aspectRatioChanged        ();
112
    void _connectionLostChanged     (bool connectionLost);
113

114
protected:
115
    friend class FinishVideoInitialization;
116

117
    void _initVideo                 ();
118 119 120
    bool _updateSettings            ();
    bool _updateVideoUri            (const QString& uri);
    void _updateThermalVideoUri     (const QString& uri);
121
    void _cleanupOldVideos          ();
122
    void _streamChanged             ();
123
    void _onStartComplete           (VideoReceiver::STATUS status);
124 125 126 127
    void _restartVideo              ();
    void _streamingChanged          ();
    void _recordingStarted          ();
    void _recordingChanged          ();
128
    void _onTakeScreenshotComplete  (VideoReceiver::STATUS status);
129

130
protected:
131 132
    QString         _videoFile;
    QString         _imageFile;
133
    SubtitleWriter  _subtitleWriter;
134 135 136
    bool            _isTaisync              = false;
    VideoReceiver*  _videoReceiver          = nullptr;
    VideoReceiver*  _thermalVideoReceiver   = nullptr;
137 138
    void*           _videoSink              = nullptr;
    void*           _thermalVideoSink       = nullptr;
139
    VideoSettings*  _videoSettings          = nullptr;
140 141
    QString         _videoUri;
    QString         _thermalVideoUri;
142
    QString         _videoSourceID;
143 144
    bool            _fullScreen             = false;
    Vehicle*        _activeVehicle          = nullptr;
145 146 147
};

#endif