VideoReceiver.h 2.6 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.
 *
 ****************************************************************************/
Gus Grubba's avatar
Gus Grubba committed
9 10 11 12 13 14 15 16 17 18 19 20


/**
 * @file
 *   @brief QGC Video Receiver
 *   @author Gus Grubba <mavlink@grubba.com>
 */

#ifndef VIDEORECEIVER_H
#define VIDEORECEIVER_H

#include <QObject>
21 22 23
#include <QTimer>
#include <QTcpSocket>

24
#if defined(QGC_GST_STREAMING)
Gus Grubba's avatar
Gus Grubba committed
25
#include <gst/gst.h>
26
#endif
Gus Grubba's avatar
Gus Grubba committed
27 28 29 30 31

class VideoReceiver : public QObject
{
    Q_OBJECT
public:
32
    Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged)
33
    Q_PROPERTY(bool streaming READ streaming NOTIFY streamingChanged)
34

Gus Grubba's avatar
Gus Grubba committed
35 36 37
    explicit VideoReceiver(QObject* parent = 0);
    ~VideoReceiver();

38
#if defined(QGC_GST_STREAMING)
39
    void setVideoSink(GstElement* _sink);
40
#endif
Gus Grubba's avatar
Gus Grubba committed
41

42
    bool recording() { return _recording; }
43
    bool streaming() { return GST_STATE(_pipeline) == GST_STATE_PLAYING; }
44 45 46

signals:
    void recordingChanged();
47
    void streamingChanged();
48

49
public slots:
50 51 52 53 54 55
    void start          ();
    void EOS            ();
    void stop           ();
    void setUri         (const QString& uri);
    void stopRecording  ();
    void startRecording ();
56 57 58 59 60 61 62

private slots:
#if defined(QGC_GST_STREAMING)
    void _timeout       ();
    void _connected     ();
    void _socketError   (QAbstractSocket::SocketError socketError);
#endif
Gus Grubba's avatar
Gus Grubba committed
63 64

private:
65
#if defined(QGC_GST_STREAMING)
66

67 68
    typedef struct
    {
69 70 71 72 73
        GstPad*         teepad;
        GstElement*     queue;
        GstElement*     mux;
        GstElement*     filesink;
        gboolean        removing;
74 75
    } Sink;

76
    bool                _recording;
77
    bool                _streaming;
78 79
    static Sink*        _sink;
    static GstElement*  _tee;
80 81 82 83 84 85

    void                        _onBusMessage(GstMessage* message);
    static gboolean             _onBusMessage(GstBus* bus, GstMessage* msg, gpointer user_data);
    static gboolean             _eosCB(GstBus* bus, GstMessage* message, gpointer user_data);
    static GstPadProbeReturn    _unlinkCB(GstPad* pad, GstPadProbeInfo* info, gpointer user_data);

86
#endif
Gus Grubba's avatar
Gus Grubba committed
87 88

    QString     _uri;
89 90

#if defined(QGC_GST_STREAMING)
91 92 93
    static GstElement*   _pipeline;
    static GstElement*   _pipeline2;
    GstElement*          _videoSink;
94 95
#endif

96 97 98 99 100 101
    //-- Wait for Video Server to show up before starting
#if defined(QGC_GST_STREAMING)
    QTimer      _timer;
    QTcpSocket* _socket;
    bool        _serverPresent;
#endif
Gus Grubba's avatar
Gus Grubba committed
102 103 104
};

#endif // VIDEORECEIVER_H