Skip to content
VideoReceiver.h 2.71 KiB
Newer Older
/****************************************************************************
 *
 *   (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


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

#ifndef VIDEORECEIVER_H
#define VIDEORECEIVER_H

#include "QGCLoggingCategory.h"
Gus Grubba's avatar
Gus Grubba committed
#include <QObject>
#include <QTimer>
#include <QTcpSocket>

#if defined(QGC_GST_STREAMING)
Gus Grubba's avatar
Gus Grubba committed
#include <gst/gst.h>
Gus Grubba's avatar
Gus Grubba committed

Q_DECLARE_LOGGING_CATEGORY(VideoReceiverLog)

Gus Grubba's avatar
Gus Grubba committed
class VideoReceiver : public QObject
{
    Q_OBJECT
public:
    Q_PROPERTY(bool recording READ recording NOTIFY recordingChanged)
    Q_PROPERTY(bool streaming READ streaming NOTIFY streamingChanged)
Gus Grubba's avatar
Gus Grubba committed
    explicit VideoReceiver(QObject* parent = 0);
    ~VideoReceiver();

#if defined(QGC_GST_STREAMING)
    void setVideoSink(GstElement* _sink);
Gus Grubba's avatar
Gus Grubba committed

    bool recording() { return _recording; }
    bool streaming() { return _streaming; }
    void streamingChanged();
public slots:
    void start              ();
    void stop               ();
    void setUri             (const QString& uri);
    void setVideoSavePath   (const QString& path);
    void stopRecording      ();
    void startRecording     ();

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

private:
#if defined(QGC_GST_STREAMING)
        GstPad*         teepad;
        GstElement*     queue;
        GstElement*     mux;
        GstElement*     filesink;
        gboolean        removing;
    bool                _streaming;
    static Sink*        _sink;
    static GstElement*  _tee;

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

Gus Grubba's avatar
Gus Grubba committed

    QString     _uri;

#if defined(QGC_GST_STREAMING)
    static GstElement*   _pipeline;
    static GstElement*   _pipeline2;
    GstElement*          _videoSink;
    //-- 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
};

#endif // VIDEORECEIVER_H