VideoReceiver.h 3.06 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
#if defined(QGC_GST_STREAMING)
36
    Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged)
37
#endif
38

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

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

45
    bool running()   { return _running;   }
46
    bool recording() { return _recording; }
47
    bool streaming() { return _streaming; }
48 49
    bool starting()  { return _starting;  }
    bool stopping()  { return _stopping;  }
50 51
#endif

52 53

signals:
54
#if defined(QGC_GST_STREAMING)
55
    void recordingChanged();
56 57 58 59
    void msgErrorReceived();
    void msgEOSReceived();
    void msgStateChangedReceived();
#endif
60

61
public slots:
62 63 64 65 66
    void start              ();
    void stop               ();
    void setUri             (const QString& uri);
    void stopRecording      ();
    void startRecording     ();
67

68

69 70 71 72 73
private slots:
#if defined(QGC_GST_STREAMING)
    void _timeout       ();
    void _connected     ();
    void _socketError   (QAbstractSocket::SocketError socketError);
74 75 76
    void _handleError();
    void _handleEOS();
    void _handleStateChanged();
77
#endif
Gus Grubba's avatar
Gus Grubba committed
78 79

private:
80
#if defined(QGC_GST_STREAMING)
81 82
    typedef struct
    {
83 84 85 86 87
        GstPad*         teepad;
        GstElement*     queue;
        GstElement*     mux;
        GstElement*     filesink;
        gboolean        removing;
88 89
    } Sink;

90
    bool                _running;
91
    bool                _recording;
92
    bool                _streaming;
93 94
    bool                _starting;
    bool                _stopping;
95 96
    Sink*               _sink;
    GstElement*         _tee;
97

98 99
    static gboolean             _onBusMessage(GstBus* bus, GstMessage* message, gpointer user_data);
    static GstPadProbeReturn    _unlinkCallBack(GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
100 101 102 103
    void                        _detachRecordingBranch(GstPadProbeInfo* info);
    void                        _shutdownRecordingBranch();
    void                        _shutdownPipeline();

104
#endif
Gus Grubba's avatar
Gus Grubba committed
105 106

    QString     _uri;
107 108

#if defined(QGC_GST_STREAMING)
109
    GstElement*         _pipeline;
110
    GstElement*         _pipelineStopRec;
111
    GstElement*         _videoSink;
112 113
#endif

114 115 116 117 118 119
    //-- 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
120 121 122
};

#endif // VIDEORECEIVER_H