QXmppRtpChannel.h

    00001 /*
    00002  * Copyright (C) 2008-2011 The QXmpp developers
    00003  *
    00004  * Author:
    00005  *  Jeremy Lainé
    00006  *
    00007  * Source:
    00008  *  http://code.google.com/p/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
    00040
    00041 class QXmppRtpPacket
    00042 {
    00043 public:
    00044     bool decode(const QByteArray &ba);
    00045     QByteArray encode() const;
    00046     QString toString() const;
    00047
    00048     quint8 version;
    00049     bool marker;
    00050     quint8 type;
    00051     quint32 ssrc;
    00052     QList<quint32> csrc;
    00053     quint16 sequence;
    00054     quint32 stamp;
    00055     QByteArray payload;
    00056 };
    00057
    00058 class QXmppRtpChannel
    00059 {
    00060 public:
    00061     QXmppRtpChannel();
    00062
    00063     virtual void close() = 0;
    00064     virtual QIODevice::OpenMode openMode() const = 0;
    00065     QList<QXmppJinglePayloadType> localPayloadTypes();
    00066     void setRemotePayloadTypes(const QList<QXmppJinglePayloadType> &remotePayloadTypes);
    00067
    00068 protected:
    00069     virtual void payloadTypesChanged();
    00070
    00071     QList<QXmppJinglePayloadType> m_incomingPayloadTypes;
    00072     QList<QXmppJinglePayloadType> m_outgoingPayloadTypes;
    00073     bool m_outgoingPayloadNumbered;
    00074 };
    00075
    00082
    00083 class QXmppRtpAudioChannel : public QIODevice, public QXmppRtpChannel
    00084 {
    00085     Q_OBJECT
    00086     Q_ENUMS(Tone)
    00087
    00088 public:
    00090     enum Tone {
    00091         Tone_0 = 0,
    00092         Tone_1,
    00093         Tone_2,
    00094         Tone_3,
    00095         Tone_4,
    00096         Tone_5,
    00097         Tone_6,
    00098         Tone_7,
    00099         Tone_8,
    00100         Tone_9,
    00101         Tone_Star,
    00102         Tone_Pound,
    00103         Tone_A,
    00104         Tone_B,
    00105         Tone_C,
    00106         Tone_D
    00107     };
    00108
    00109     QXmppRtpAudioChannel(QObject *parent = 0);
    00110     ~QXmppRtpAudioChannel();
    00111
    00112     QXmppJinglePayloadType payloadType() const;
    00113
    00115     qint64 bytesAvailable() const;
    00116     void close();
    00117     bool isSequential() const;
    00118     QIODevice::OpenMode openMode() const;
    00119     qint64 pos() const;
    00120     bool seek(qint64 pos);
    00122
    00123 signals:
    00125     void sendDatagram(const QByteArray &ba);
    00126
    00128     void logMessage(QXmppLogger::MessageType type, const QString &msg);
    00129
    00130 public slots:
    00131     void datagramReceived(const QByteArray &ba);
    00132     void startTone(QXmppRtpAudioChannel::Tone tone);
    00133     void stopTone(QXmppRtpAudioChannel::Tone tone);
    00134
    00135 protected:
    00137     void debug(const QString &message)
    00138     {
    00139         emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
    00140     }
    00141
    00142     void warning(const QString &message)
    00143     {
    00144         emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
    00145     }
    00146
    00147     void logReceived(const QString &message)
    00148     {
    00149         emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
    00150     }
    00151
    00152     void logSent(const QString &message)
    00153     {
    00154         emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
    00155     }
    00156
    00157     void payloadTypesChanged();
    00158     qint64 readData(char * data, qint64 maxSize);
    00159     qint64 writeData(const char * data, qint64 maxSize);
    00161
    00162 private slots:
    00163     void emitSignals();
    00164     void writeDatagram();
    00165
    00166 private:
    00167     friend class QXmppRtpAudioChannelPrivate;
    00168     QXmppRtpAudioChannelPrivate * d;
    00169 };
    00170
    00174
    00175 class QXmppVideoFrame
    00176 {
    00177 public:
    00178     enum PixelFormat {
    00179         Format_Invalid = 0,
    00180         Format_RGB32 = 3,
    00181         Format_RGB24 = 4,
    00182         Format_YUV420P = 18,
    00183         Format_UYVY = 20,
    00184         Format_YUYV = 21,
    00185     };
    00186
    00187     QXmppVideoFrame();
    00188     QXmppVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format);
    00189     uchar *bits();
    00190     const uchar *bits() const;
    00191     int bytesPerLine() const;
    00192     int height() const;
    00193     bool isValid() const;
    00194     int mappedBytes() const;
    00195     PixelFormat pixelFormat() const;
    00196     QSize size() const;
    00197     int width() const;
    00198
    00199 private:
    00200     int m_bytesPerLine;
    00201     QByteArray m_data;
    00202     int m_height;
    00203     int m_mappedBytes;
    00204     PixelFormat m_pixelFormat;
    00205     int m_width;
    00206 };
    00207
    00208 class QXmppVideoFormat
    00209 {
    00210 public:
    00211     int frameHeight() const {
    00212         return m_frameSize.height();
    00213     }
    00214
    00215     int frameWidth() const {
    00216         return m_frameSize.width();
    00217     }
    00218
    00219     qreal frameRate() const {
    00220         return m_frameRate;
    00221     }
    00222
    00223     void setFrameRate(qreal frameRate) {
    00224         m_frameRate = frameRate;
    00225     }
    00226
    00227     QSize frameSize() const {
    00228         return m_frameSize;
    00229     }
    00230
    00231     void setFrameSize(const QSize &frameSize) {
    00232         m_frameSize = frameSize;
    00233     }
    00234
    00235     QXmppVideoFrame::PixelFormat pixelFormat() const {
    00236         return m_pixelFormat;
    00237     }
    00238
    00239     void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) {
    00240         m_pixelFormat = pixelFormat;
    00241     }
    00242
    00243 private:
    00244     qreal m_frameRate;
    00245     QSize m_frameSize;
    00246     QXmppVideoFrame::PixelFormat m_pixelFormat;
    00247 };
    00248
    00249
    00253
    00254 class QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel
    00255 {
    00256     Q_OBJECT
    00257
    00258 public:
    00259     QXmppRtpVideoChannel(QObject *parent = 0);
    00260     ~QXmppRtpVideoChannel();
    00261
    00262     // incoming stream
    00263     QXmppVideoFormat decoderFormat() const;
    00264     QList<QXmppVideoFrame> readFrames();
    00265
    00266     // outgoing stream
    00267     QXmppVideoFormat encoderFormat() const;
    00268     void setEncoderFormat(const QXmppVideoFormat &format);
    00269     void writeFrame(const QXmppVideoFrame &frame);
    00270
    00271     QIODevice::OpenMode openMode() const;
    00272     void close();
    00273
    00274 signals:
    00276     void sendDatagram(const QByteArray &ba);
    00277
    00278 public slots:
    00279     void datagramReceived(const QByteArray &ba);
    00280
    00281 protected:
    00282     void payloadTypesChanged();
    00283
    00284 private:
    00285     friend class QXmppRtpVideoChannelPrivate;
    00286     QXmppRtpVideoChannelPrivate * d;
    00287 };
    00288
    00289 #endif

All Classes Functions Enumerations Enumerator Properties