QXmpp  Version:0.9.3
QXmppRtpChannel.h
00001 /*
00002  * Copyright (C) 2008-2014 The QXmpp developers
00003  *
00004  * Author:
00005  *  Jeremy Lainé
00006  *
00007  * Source:
00008  *  https://github.com/qxmpp-project/qxmpp
00009  *
00010  * This file is a part of QXmpp library.
00011  *
00012  * This library is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 2.1 of the License, or (at your option) any later version.
00016  *
00017  * This library is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  */
00023 
00024 #ifndef QXMPPRTPCHANNEL_H
00025 #define QXMPPRTPCHANNEL_H
00026 
00027 #include <QIODevice>
00028 #include <QSize>
00029 
00030 #include "QXmppJingleIq.h"
00031 #include "QXmppLogger.h"
00032 
00033 class QXmppCodec;
00034 class QXmppJinglePayloadType;
00035 class QXmppRtpAudioChannelPrivate;
00036 class QXmppRtpVideoChannelPrivate;
00037 
00038 class QXMPP_EXPORT QXmppRtpChannel
00039 {
00040 public:
00041     QXmppRtpChannel();
00042 
00044     virtual void close() = 0;
00045 
00047     virtual QIODevice::OpenMode openMode() const = 0;
00048 
00049     QList<QXmppJinglePayloadType> localPayloadTypes();
00050     void setRemotePayloadTypes(const QList<QXmppJinglePayloadType> &remotePayloadTypes);
00051 
00052     quint32 localSsrc() const;
00053     void setLocalSsrc(quint32 ssrc);
00054 
00055 protected:
00057     virtual void payloadTypesChanged() = 0;
00058 
00059     QList<QXmppJinglePayloadType> m_incomingPayloadTypes;
00060     QList<QXmppJinglePayloadType> m_outgoingPayloadTypes;
00061     bool m_outgoingPayloadNumbered;
00063 
00064 private:
00065     quint32 m_outgoingSsrc;
00066 };
00067 
00074 
00075 class QXMPP_EXPORT QXmppRtpAudioChannel : public QIODevice, public QXmppRtpChannel
00076 {
00077     Q_OBJECT
00078     Q_ENUMS(Tone)
00079 
00080 public:
00082     enum Tone {
00083         Tone_0 = 0, 
00084         Tone_1,     
00085         Tone_2,     
00086         Tone_3,     
00087         Tone_4,     
00088         Tone_5,     
00089         Tone_6,     
00090         Tone_7,     
00091         Tone_8,     
00092         Tone_9,     
00093         Tone_Star,  
00094         Tone_Pound, 
00095         Tone_A,     
00096         Tone_B,     
00097         Tone_C,     
00098         Tone_D      
00099     };
00100 
00101     QXmppRtpAudioChannel(QObject *parent = 0);
00102     ~QXmppRtpAudioChannel();
00103 
00104     qint64 bytesAvailable() const;
00105     void close();
00106     bool isSequential() const;
00107     QIODevice::OpenMode openMode() const;
00108     QXmppJinglePayloadType payloadType() const;
00109     qint64 pos() const;
00110     bool seek(qint64 pos);
00111 
00112 signals:
00114     void sendDatagram(const QByteArray &ba);
00115 
00117     void logMessage(QXmppLogger::MessageType type, const QString &msg);
00118 
00119 public slots:
00120     void datagramReceived(const QByteArray &ba);
00121     void startTone(QXmppRtpAudioChannel::Tone tone);
00122     void stopTone(QXmppRtpAudioChannel::Tone tone);
00123 
00124 protected:
00126     void debug(const QString &message)
00127     {
00128         emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
00129     }
00130 
00131     void warning(const QString &message)
00132     {
00133         emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
00134     }
00135 
00136     void logReceived(const QString &message)
00137     {
00138         emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
00139     }
00140 
00141     void logSent(const QString &message)
00142     {
00143         emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
00144     }
00145 
00146     void payloadTypesChanged();
00147     qint64 readData(char * data, qint64 maxSize);
00148     qint64 writeData(const char * data, qint64 maxSize);
00150 
00151 private slots:
00152     void emitSignals();
00153     void writeDatagram();
00154 
00155 private:
00156     friend class QXmppRtpAudioChannelPrivate;
00157     QXmppRtpAudioChannelPrivate * d;
00158 };
00159 
00163 
00164 class QXMPP_EXPORT QXmppVideoFrame
00165 {
00166 public:
00168     enum PixelFormat {
00169         Format_Invalid = 0,     
00170         Format_RGB32 = 3,       
00171         Format_RGB24 = 4,       
00172         Format_YUV420P = 18,    
00173 
00174 
00175 
00176         Format_UYVY = 20,       
00177 
00178 
00179 
00180 
00181         Format_YUYV = 21        
00182 
00183 
00184 
00185 
00186     };
00187 
00188     QXmppVideoFrame();
00189     QXmppVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
00190     uchar *bits();
00191     const uchar *bits() const;
00192     int bytesPerLine() const;
00193     int height() const;
00194     bool isValid() const;
00195     int mappedBytes() const;
00196     PixelFormat pixelFormat() const;
00197     QSize size() const;
00198     int width() const;
00199 
00200 private:
00201     int m_bytesPerLine;
00202     QByteArray m_data;
00203     int m_height;
00204     int m_mappedBytes;
00205     PixelFormat m_pixelFormat;
00206     int m_width;
00207 };
00208 
00209 class QXMPP_EXPORT QXmppVideoFormat
00210 {
00211 public:
00212     int frameHeight() const {
00213         return m_frameSize.height();
00214     }
00215 
00216     int frameWidth() const {
00217         return m_frameSize.width();
00218     }
00219 
00220     qreal frameRate() const {
00221         return m_frameRate;
00222     }
00223 
00224     void setFrameRate(qreal frameRate) {
00225         m_frameRate = frameRate;
00226     }
00227 
00228     QSize frameSize() const {
00229         return m_frameSize;
00230     }
00231 
00232     void setFrameSize(const QSize &frameSize) {
00233         m_frameSize = frameSize;
00234     }
00235 
00236     QXmppVideoFrame::PixelFormat pixelFormat() const {
00237         return m_pixelFormat;
00238     }
00239 
00240     void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) {
00241         m_pixelFormat = pixelFormat;
00242     }
00243 
00244 private:
00245     qreal m_frameRate;
00246     QSize m_frameSize;
00247     QXmppVideoFrame::PixelFormat m_pixelFormat;
00248 };
00249 
00250 
00254 
00255 class QXMPP_EXPORT QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
00256 {
00257     Q_OBJECT
00258 
00259 public:
00260     QXmppRtpVideoChannel(QObject *parent = 0);
00261     ~QXmppRtpVideoChannel();
00262 
00263     void close();
00264     QIODevice::OpenMode openMode() const;
00265 
00266     // incoming stream
00267     QXmppVideoFormat decoderFormat() const;
00268     QList<QXmppVideoFrame> readFrames();
00269 
00270     // outgoing stream
00271     QXmppVideoFormat encoderFormat() const;
00272     void setEncoderFormat(const QXmppVideoFormat &format);
00273     void writeFrame(const QXmppVideoFrame &frame);
00274 
00275 signals:
00277     void sendDatagram(const QByteArray &ba);
00278 
00279 public slots:
00280     void datagramReceived(const QByteArray &ba);
00281 
00282 protected:
00284     void payloadTypesChanged();
00286 
00287 private:
00288     friend class QXmppRtpVideoChannelPrivate;
00289     QXmppRtpVideoChannelPrivate * d;
00290 };
00291 
00292 #endif
 All Classes Functions Enumerations Enumerator Properties