VideoManager.h 5.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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 23 24 25
#include "QGCLoggingCategory.h"
#include "VideoReceiver.h"
#include "QGCToolbox.h"

Q_DECLARE_LOGGING_CATEGORY(VideoManagerLog)

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

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

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

38 39
    Q_PROPERTY(bool             hasVideo            READ    hasVideo                                    NOTIFY hasVideoChanged)
    Q_PROPERTY(bool             isGStreamer         READ    isGStreamer                                 NOTIFY isGStreamerChanged)
40
    Q_PROPERTY(bool             isAutoStream        READ    isAutoStream                                NOTIFY isAutoStreamChanged)
41
    Q_PROPERTY(bool             isTaisync           READ    isTaisync       WRITE   setIsTaisync        NOTIFY isTaisyncChanged)
42 43
    Q_PROPERTY(QString          videoSourceID       READ    videoSourceID                               NOTIFY videoSourceIDChanged)
    Q_PROPERTY(bool             uvcEnabled          READ    uvcEnabled                                  CONSTANT)
44
    Q_PROPERTY(bool             fullScreen          READ    fullScreen      WRITE   setfullScreen       NOTIFY fullScreenChanged)
45
    Q_PROPERTY(VideoReceiver*   videoReceiver       READ    videoReceiver                               CONSTANT)
46 47 48 49
    Q_PROPERTY(double           aspectRatio         READ    aspectRatio                                 NOTIFY streamInfoChanged)
    Q_PROPERTY(bool             hasZoom             READ    hasZoom                                     NOTIFY streamInfoChanged)
    Q_PROPERTY(int              streamCount         READ    streamCount                                 NOTIFY streamCountChanged)
    Q_PROPERTY(int              currentStream       READ    currentStream   WRITE setCurrentStream      NOTIFY currentStreamChanged)
50

51 52
    bool        hasVideo            ();
    bool        isGStreamer         ();
53
    bool        isAutoStream        ();
54
    bool        isTaisync           () { return _isTaisync; }
55
    bool        fullScreen          () { return _fullScreen; }
56
    QString     videoSourceID       () { return _videoSourceID; }
57 58
    QString     autoURL             () { return QString(_streamInfo.uri); }
    double      aspectRatio         ();
59 60 61
    bool        hasZoom             () { return _streamInfo.flags & VIDEO_STREAM_HAS_BASIC_ZOOM; }
    int         currentStream       () { return _currentStream; }
    int         streamCount         () { return _streamInfo.count; }
62

63 64
    VideoReceiver*  videoReceiver   () { return _videoReceiver; }

65 66 67 68 69 70
#if defined(QGC_DISABLE_UVC)
    bool        uvcEnabled          () { return false; }
#else
    bool        uvcEnabled          ();
#endif

71
    void        setfullScreen       (bool f) { _fullScreen = f; emit fullScreenChanged(); }
72
    void        setIsTaisync        (bool t) { _isTaisync = t;  emit isTaisyncChanged(); }
73
    void        setCurrentStream    (int stream);
74

75 76 77
    // Override from QGCTool
    void        setToolbox          (QGCToolbox *toolbox);

78 79 80 81
    Q_INVOKABLE void startVideo     () { _videoReceiver->start(); }
    Q_INVOKABLE void stopVideo      () { _videoReceiver->stop();  }
    Q_INVOKABLE void stepZoom       (int direction);
    Q_INVOKABLE void stepStream     (int direction);
Patrick José Pereira's avatar
Patrick José Pereira committed
82

83
signals:
84 85 86
    void hasVideoChanged            ();
    void isGStreamerChanged         ();
    void videoSourceIDChanged       ();
87
    void fullScreenChanged          ();
88
    void isAutoStreamChanged        ();
89
    void streamInfoChanged          ();
90
    void isTaisyncChanged           ();
91 92
    void currentStreamChanged       ();
    void streamCountChanged         ();
93

94
private slots:
95 96 97
    void _videoSourceChanged        ();
    void _udpPortChanged            ();
    void _rtspUrlChanged            ();
98
    void _tcpUrlChanged             ();
Gus Grubba's avatar
Gus Grubba committed
99
    void _updateUVC                 ();
100
    void _streamInfoChanged         ();
101
    void _setActiveVehicle          (Vehicle* vehicle);
102
    void _activeJoystickChanged     (Joystick* joystick);
103
    void _vehicleMessageReceived    (const mavlink_message_t& message);
104

105
private:
106 107
    void _updateSettings            ();
    void _restartVideo              ();
108

109 110 111 112
private:
    bool            _isTaisync          = false;
    VideoReceiver*  _videoReceiver      = nullptr;
    VideoSettings*  _videoSettings      = nullptr;
113
    QString         _videoSourceID;
114 115
    bool            _fullScreen         = false;
    Vehicle*        _activeVehicle      = nullptr;
116
    Joystick*       _activeJoystick     = nullptr;
117
    mavlink_video_stream_information_t _streamInfo;
118 119 120 121 122
    bool            _hasAutoStream      = false;
    uint8_t         _videoStreamCompID  = 0;
    int             _currentStream      = 1;
    QTime           _lastZoomChange;
    QTime           _lastStreamChange;
123 124 125
};

#endif