FlightDisplayViewController.cc 3.25 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12 13 14


#include <QQmlContext>
#include <QQmlEngine>
#include <QSettings>

Gus Grubba's avatar
Gus Grubba committed
15
#include <VideoItem.h>
Gus Grubba's avatar
Gus Grubba committed
16

Don Gagne's avatar
Don Gagne committed
17
#include "ScreenToolsController.h"
18
#include "FlightDisplayViewController.h"
dogmaphobic's avatar
dogmaphobic committed
19

20
const char* kMainFlightDisplayViewControllerGroup = "FlightDisplayViewController";
dogmaphobic's avatar
dogmaphobic committed
21

22 23
FlightDisplayViewController::FlightDisplayViewController(QObject *parent)
    : QObject(parent)
dogmaphobic's avatar
dogmaphobic committed
24
    , _videoRunning(false)
dogmaphobic's avatar
dogmaphobic committed
25
{
Gus Grubba's avatar
Gus Grubba committed
26 27 28 29
    /*
     * This is the receiving end of an UDP RTP stream. The sender can be setup with this command:
     *
     * gst-launch-1.0 uvch264src initial-bitrate=1000000 average-bitrate=1000000 iframe-period=1000 name=src auto-start=true src.vidsrc ! \
Don Gagne's avatar
Don Gagne committed
30
     * video/x-h264,width=1280,height=720,framerate=24/1 ! h264parse ! rtph264pay ! udpsink host=192.168.1.9 port=5600
Gus Grubba's avatar
Gus Grubba committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
     *
     * Where the main parameters are:
     *
     *  uvch264src:         Your h264 video source (the example above uses a Logitech C920 on an Raspberry PI 2+ or Odroid C1
     *  host=192.168.1.9    This is the IP address of QGC. You can use Avahi/Zeroconf to find QGC using the "_qgroundcontrol._udp" service.
     *
     * Advanced settings (you should probably read the gstreamer documentation before changing these):
     *
     * initial-bitrate=1000000 average-bitrate=1000000
     * The bit rate to use. The greater, the better quality at the cost of higher bandwidth.
     *
     * width=1280,height=720,framerate=24/1
     * The video resolution and frame rate. This depends on the camera used.
     *
     * iframe-period=1000
     * Interval between iFrames. The greater the interval the lesser bandwidth at the cost of a longer time to recover from lost packets.
     *
     * Do not change anything else unless you know what you are doing. Any other change will require a matching change on the receiving end.
     *
     */
51 52
    _videoSurface = new VideoSurface;
    _videoReceiver = new VideoReceiver(this);
Don Gagne's avatar
Don Gagne committed
53
    _videoReceiver->setUri(QLatin1Literal("udp://0.0.0.0:5600"));   // Port 5600=Solo UDP port, if you change you will break Solo video support
54
#if defined(QGC_GST_STREAMING)
55
    _videoReceiver->setVideoSink(_videoSurface->videoSink());
dogmaphobic's avatar
dogmaphobic committed
56 57
    connect(&_frameTimer, &QTimer::timeout, this, &FlightDisplayViewController::_updateTimer);
    _frameTimer.start(1000);
Gus Grubba's avatar
Gus Grubba committed
58
#endif
dogmaphobic's avatar
dogmaphobic committed
59 60
}

61
FlightDisplayViewController::~FlightDisplayViewController()
dogmaphobic's avatar
dogmaphobic committed
62
{
63

dogmaphobic's avatar
dogmaphobic committed
64
}
dogmaphobic's avatar
dogmaphobic committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

#if defined(QGC_GST_STREAMING)
void FlightDisplayViewController::_updateTimer(void)
{
    if(_videoRunning)
    {
        time_t elapsed = 0;
        if(_videoSurface)
        {
            elapsed = time(0) - _videoSurface->lastFrame();
        }
        if(elapsed > 2)
        {
            _videoRunning = false;
            _videoSurface->setLastFrame(0);
            emit videoRunningChanged();
        }
    }
    else
    {
        if(_videoSurface && _videoSurface->lastFrame()) {
            if(!_videoRunning)
            {
                _videoRunning = true;
                emit videoRunningChanged();
            }
        }
    }
}
#endif