#ifndef VIDEOSTREAM_H
#define VIDEOSTREAM_H

#include <QList>
#include <QString>

extern "C" {
 #include <gst/gst.h>
}

class VideoWidget;

class VideoStream
{

    public:

        typedef enum {
            E_STREAM_STOPPED,
            E_STREAM_PLAYING,
            E_STREAM_PAUSED,
            E_STREAM_ERROR  
        } E_STREAM_STATE;
    
        VideoStream(unsigned short int rtpPort, unsigned long int rtcpPort, const QString& rtcpHost = QString("localhost"));
        ~VideoStream();

        void setRtpPort(unsigned short int rtcpPort);
        unsigned short int getRtpPort() const;
        void setRtcpPort(unsigned short int rtcpPort);
        unsigned short int getRtcpPort() const;
        void setRtcpHost(const QString& rtcpHost);
        QString getRtcpHost() const;

        void play();
        void stop();

        E_STREAM_STATE getStreamState() const;

    private:
        friend class VideoWidget;
        void addConnection(VideoWidget *videoWidget);
        void removeConnection(VideoWidget *videoWidget);

        static bool handleMessage (GstBus *bus, GstMessage *message, gpointer data);

        unsigned short int a_rtpPort;
        unsigned short int a_rtcpPort;
        QString a_rtcpHost;
        
        QList<VideoWidget*> a_connectedWidgets;
        GstElement *a_rtpSource;
        GstElement *a_rtpSession;
        GstElement *a_depay;
        GstElement *a_rtcpSink;
        GstElement *a_pipeline;
        GstElement *a_decoder;
        GstElement *a_tee;
        GstBus     *a_bus;
};

#endif
