VideoSettings.cc 6.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#include "VideoSettings.h"
11 12
#include "QGCApplication.h"
#include "VideoManager.h"
13 14

#include <QQmlEngine>
Don Gagne's avatar
Don Gagne committed
15
#include <QtQml>
16
#include <QVariantList>
Don Gagne's avatar
Don Gagne committed
17 18

#ifndef QGC_DISABLE_UVC
19
#include <QCameraInfo>
Don Gagne's avatar
Don Gagne committed
20
#endif
21

22 23 24 25 26 27
const char* VideoSettings::videoSourceNoVideo   = "No Video Available";
const char* VideoSettings::videoDisabled        = "Video Stream Disabled";
const char* VideoSettings::videoSourceAuto      = "Automatic Video Stream";
const char* VideoSettings::videoSourceRTSP      = "RTSP Video Stream";
const char* VideoSettings::videoSourceUDP       = "UDP Video Stream";
const char* VideoSettings::videoSourceTCP       = "TCP-MPEG2 Video Stream";
28
const char* VideoSettings::videoSourceMPEGTS    = "MPEG-TS (h.264) Video Stream";
29

30
DECLARE_SETTINGGROUP(Video, "Video")
31 32 33
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
34 35 36 37

    // Setup enum values for videoSource settings into meta data
    QStringList videoSourceList;
#ifdef QGC_GST_STREAMING
38 39
    videoSourceList.append(videoSourceAuto);
    videoSourceList.append(videoSourceRTSP);
40 41 42
#ifndef NO_UDP_VIDEO
    videoSourceList.append(videoSourceUDP);
#endif
43
    videoSourceList.append(videoSourceTCP);
44
    videoSourceList.append(videoSourceMPEGTS);
45 46 47
#endif
#ifndef QGC_DISABLE_UVC
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
48
    for (const QCameraInfo &cameraInfo: cameras) {
49 50 51 52
        videoSourceList.append(cameraInfo.description());
    }
#endif
    if (videoSourceList.count() == 0) {
Gus Grubba's avatar
Gus Grubba committed
53
        _noVideo = true;
54
        videoSourceList.append(videoSourceNoVideo);
55 56
    } else {
        videoSourceList.insert(0, videoDisabled);
57 58
    }
    QVariantList videoSourceVarList;
59
    for (const QString& videoSource: videoSourceList) {
60 61 62 63
        videoSourceVarList.append(QVariant::fromValue(videoSource));
    }
    _nameToMetaDataMap[videoSourceName]->setEnumInfo(videoSourceList, videoSourceVarList);
    // Set default value for videoSource
Gus Grubba's avatar
Gus Grubba committed
64 65 66 67 68 69
    _setDefaults();
}

void VideoSettings::_setDefaults()
{
    if (_noVideo) {
70 71 72 73
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoSourceNoVideo);
    } else {
        _nameToMetaDataMap[videoSourceName]->setRawDefaultValue(videoDisabled);
    }
74 75
}

76 77 78 79 80 81 82 83 84 85 86 87
DECLARE_SETTINGSFACT(VideoSettings, aspectRatio)
DECLARE_SETTINGSFACT(VideoSettings, videoFit)
DECLARE_SETTINGSFACT(VideoSettings, gridLines)
DECLARE_SETTINGSFACT(VideoSettings, showRecControl)
DECLARE_SETTINGSFACT(VideoSettings, recordingFormat)
DECLARE_SETTINGSFACT(VideoSettings, maxVideoSize)
DECLARE_SETTINGSFACT(VideoSettings, enableStorageLimit)
DECLARE_SETTINGSFACT(VideoSettings, rtspTimeout)
DECLARE_SETTINGSFACT(VideoSettings, streamEnabled)
DECLARE_SETTINGSFACT(VideoSettings, disableWhenDisarmed)

DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, videoSource)
88 89 90
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
Gus Grubba's avatar
Gus Grubba committed
91
        //-- Check for sources no longer available
92
        if(!_videoSourceFact->enumStrings().contains(_videoSourceFact->rawValue().toString())) {
Gus Grubba's avatar
Gus Grubba committed
93 94 95 96 97 98
            if (_noVideo) {
                _videoSourceFact->setRawValue(videoSourceNoVideo);
            } else {
                _videoSourceFact->setRawValue(videoDisabled);
            }
        }
99
        connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
100 101 102 103
    }
    return _videoSourceFact;
}

104
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, udpPort)
105 106 107
{
    if (!_udpPortFact) {
        _udpPortFact = _createSettingsFact(udpPortName);
108
        connect(_udpPortFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
109 110 111 112
    }
    return _udpPortFact;
}

113
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, rtspUrl)
114 115 116
{
    if (!_rtspUrlFact) {
        _rtspUrlFact = _createSettingsFact(rtspUrlName);
117
        connect(_rtspUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
118 119 120 121
    }
    return _rtspUrlFact;
}

122
DECLARE_SETTINGSFACT_NO_FUNC(VideoSettings, tcpUrl)
123 124 125
{
    if (!_tcpUrlFact) {
        _tcpUrlFact = _createSettingsFact(tcpUrlName);
126
        connect(_tcpUrlFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
127 128 129 130
    }
    return _tcpUrlFact;
}

131 132 133 134 135 136 137 138 139 140 141
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
    //-- If UDP, check if port is set
    if(vSource == videoSourceUDP) {
142
        qCDebug(VideoManagerLog) << "Testing configuration for UDP Stream:" << udpPort()->rawValue().toInt();
143 144 145 146
        return udpPort()->rawValue().toInt() != 0;
    }
    //-- If RTSP, check for URL
    if(vSource == videoSourceRTSP) {
147
        qCDebug(VideoManagerLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString();
148 149
        return !rtspUrl()->rawValue().toString().isEmpty();
    }
150 151 152 153
    //-- If TCP, check for URL
    if(vSource == videoSourceTCP) {
        qCDebug(VideoManagerLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString();
        return !tcpUrl()->rawValue().toString().isEmpty();
154
    }
155 156 157 158 159
    //-- If MPEG-TS, check if port is set
    if(vSource == videoSourceMPEGTS) {
        qCDebug(VideoManagerLog) << "Testing configuration for MPEG-TS Stream:" << udpPort()->rawValue().toInt();
        return udpPort()->rawValue().toInt() != 0;
    }
160
    //-- If Auto, check for received URL
161 162
    if(vSource == videoSourceAuto) {
        qCDebug(VideoManagerLog) << "Testing configuration for Auto Stream:" << qgcApp()->toolbox()->videoManager()->autoURL();
163
        return !qgcApp()->toolbox()->videoManager()->autoURL().isEmpty();
164 165 166 167 168 169 170 171
    }
    return false;
}

void VideoSettings::_configChanged(QVariant)
{
    emit streamConfiguredChanged();
}