VideoReceiver.h 2.37 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 33
    Q_PROPERTY(bool             recording        READ    recording                                NOTIFY recordingChanged)

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

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

41 42 43 44 45
    bool recording() { return _recording; }

signals:
    void recordingChanged();

46 47
public slots:
    void start      ();
48
    void EOS        ();
49 50
    void stop       ();
    void setUri     (const QString& uri);
51 52
    void _stopRecording();
    void _startRecording();
53 54 55 56 57 58 59

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

private:
62
#if defined(QGC_GST_STREAMING)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    typedef struct
    {
        GstPad* teepad;
        GstElement* queue;
        GstElement* mux;
        GstElement* filesink;
        gboolean removing;
    } Sink;

    static Sink* sink;

    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);

    bool _recording;
    static GstElement*     tee;

82
#endif
Gus Grubba's avatar
Gus Grubba committed
83 84

    QString     _uri;
85 86

#if defined(QGC_GST_STREAMING)
87 88 89
    static GstElement* _pipeline;
    static GstElement* _pipeline2;

Gus Grubba's avatar
Gus Grubba committed
90
    GstElement* _videoSink;
91 92
#endif

93 94 95 96 97 98
    //-- 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
99 100 101
};

#endif // VIDEORECEIVER_H