VideoReceiver.h 2.85 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


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

#ifndef VIDEORECEIVER_H
#define VIDEORECEIVER_H

20
#include "QGCLoggingCategory.h"
Gus Grubba's avatar
Gus Grubba committed
21
#include <QObject>
22 23 24
#include <QTimer>
#include <QTcpSocket>

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

29 30
Q_DECLARE_LOGGING_CATEGORY(VideoReceiverLog)

Gus Grubba's avatar
Gus Grubba committed
31 32 33 34
class VideoReceiver : public QObject
{
    Q_OBJECT
public:
35
    Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged)
36
    Q_PROPERTY(bool streaming READ streaming NOTIFY streamingChanged)
37

Gus Grubba's avatar
Gus Grubba committed
38 39 40
    explicit VideoReceiver(QObject* parent = 0);
    ~VideoReceiver();

41
#if defined(QGC_GST_STREAMING)
42
    void setVideoSink(GstElement* _sink);
43
#endif
Gus Grubba's avatar
Gus Grubba committed
44

45
    bool recording() { return _recording; }
46
    bool streaming() { return _streaming; }
47 48 49

signals:
    void recordingChanged();
50
    void streamingChanged();
51

52
public slots:
53 54 55 56 57 58
    void start              ();
    void stop               ();
    void setUri             (const QString& uri);
    void setVideoSavePath   (const QString& path);
    void stopRecording      ();
    void startRecording     ();
59 60 61 62 63 64 65

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

private:
68
#if defined(QGC_GST_STREAMING)
69

70 71
    typedef struct
    {
72 73 74 75 76
        GstPad*         teepad;
        GstElement*     queue;
        GstElement*     mux;
        GstElement*     filesink;
        gboolean        removing;
77 78
    } Sink;

79
    bool                _recording;
80
    bool                _streaming;
81 82
    Sink*               _sink;
    GstElement*         _tee;
83 84

    void                        _onBusMessage(GstMessage* message);
85 86 87 88 89
    void                        _eosCB(GstMessage* message);
    void                        _unlinkCB(GstPadProbeInfo* info);
    static gboolean             _onBusMessage(GstBus* bus, GstMessage* message, gpointer user_data);
    static gboolean             _eosCallBack(GstBus* bus, GstMessage* message, gpointer user_data);
    static GstPadProbeReturn    _unlinkCallBack(GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
90

91
#endif
Gus Grubba's avatar
Gus Grubba committed
92 93

    QString     _uri;
94
    QString     _path;
95 96

#if defined(QGC_GST_STREAMING)
97 98 99
    GstElement*         _pipeline;
    GstElement*         _pipeline2;
    GstElement*         _videoSink;
100 101
#endif

102 103 104 105 106 107
    //-- 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
108 109 110
};

#endif // VIDEORECEIVER_H