VideoReceiver.h 3.13 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 67
    void start              ();
    void stop               ();
    void setUri             (const QString& uri);
    void setVideoSavePath   (const QString& path);
    void stopRecording      ();
    void startRecording     ();
68

69

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

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

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

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

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

    QString     _uri;
108
    QString     _path;
109 110

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

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

#endif // VIDEORECEIVER_H