VideoSettings.cc 5.84 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
const char* VideoSettings::videoSourceNoVideo   = "No Video Available";
const char* VideoSettings::videoDisabled        = "Video Stream Disabled";
const char* VideoSettings::videoSourceRTSP      = "RTSP Video Stream";
const char* VideoSettings::videoSourceUDP       = "UDP Video Stream";
const char* VideoSettings::videoSourceTCP       = "TCP-MPEG2 Video Stream";
27
const char* VideoSettings::videoSourceMPEGTS    = "MPEG-TS (h.264) Video Stream";
28

29
DECLARE_SETTINGGROUP(Video, "Video")
30 31
{
    qmlRegisterUncreatableType<VideoSettings>("QGroundControl.SettingsManager", 1, 0, "VideoSettings", "Reference only");
32 33 34 35

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

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

73 74 75 76 77 78 79 80 81 82 83 84
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)
85 86 87
{
    if (!_videoSourceFact) {
        _videoSourceFact = _createSettingsFact(videoSourceName);
Gus Grubba's avatar
Gus Grubba committed
88
        //-- Check for sources no longer available
89
        if(!_videoSourceFact->enumStrings().contains(_videoSourceFact->rawValue().toString())) {
Gus Grubba's avatar
Gus Grubba committed
90 91 92 93 94 95
            if (_noVideo) {
                _videoSourceFact->setRawValue(videoSourceNoVideo);
            } else {
                _videoSourceFact->setRawValue(videoDisabled);
            }
        }
96
        connect(_videoSourceFact, &Fact::valueChanged, this, &VideoSettings::_configChanged);
97 98 99 100
    }
    return _videoSourceFact;
}

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

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

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

128 129 130 131 132
bool VideoSettings::streamConfigured(void)
{
#if !defined(QGC_GST_STREAMING)
    return false;
#endif
133
    //-- First, check if it's disabled
134 135 136 137
    QString vSource = videoSource()->rawValue().toString();
    if(vSource == videoSourceNoVideo || vSource == videoDisabled) {
        return false;
    }
138 139 140 141 142
    //-- Check if it's autoconfigured
    if(qgcApp()->toolbox()->videoManager()->autoStreamConfigured()) {
        qCDebug(VideoManagerLog) << "Stream auto configured";
        return true;
    }
143 144
    //-- If UDP, check if port is set
    if(vSource == videoSourceUDP) {
145
        qCDebug(VideoManagerLog) << "Testing configuration for UDP Stream:" << udpPort()->rawValue().toInt();
146 147 148 149
        return udpPort()->rawValue().toInt() != 0;
    }
    //-- If RTSP, check for URL
    if(vSource == videoSourceRTSP) {
150
        qCDebug(VideoManagerLog) << "Testing configuration for RTSP Stream:" << rtspUrl()->rawValue().toString();
151 152
        return !rtspUrl()->rawValue().toString().isEmpty();
    }
153 154 155 156
    //-- If TCP, check for URL
    if(vSource == videoSourceTCP) {
        qCDebug(VideoManagerLog) << "Testing configuration for TCP Stream:" << tcpUrl()->rawValue().toString();
        return !tcpUrl()->rawValue().toString().isEmpty();
157
    }
158 159 160 161 162
    //-- 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;
    }
163 164 165 166 167 168 169
    return false;
}

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