QXmpp Version:0.3.0
|
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_YUYV = 21, 00184 }; 00185 00186 QXmppVideoFrame(); 00187 QXmppVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFormat format); 00188 uchar *bits(); 00189 const uchar *bits() const; 00190 int bytesPerLine() const; 00191 int height() const; 00192 bool isValid() const; 00193 int mappedBytes() const; 00194 PixelFormat pixelFormat() const; 00195 QSize size() const; 00196 int width() const; 00197 00198 private: 00199 int m_bytesPerLine; 00200 QByteArray m_data; 00201 int m_height; 00202 int m_mappedBytes; 00203 PixelFormat m_pixelFormat; 00204 int m_width; 00205 }; 00206 00207 class QXmppVideoFormat 00208 { 00209 public: 00210 int frameHeight() const { 00211 return m_frameSize.height(); 00212 } 00213 00214 int frameWidth() const { 00215 return m_frameSize.width(); 00216 } 00217 00218 qreal frameRate() const { 00219 return m_frameRate; 00220 } 00221 00222 void setFrameRate(qreal frameRate) { 00223 m_frameRate = frameRate; 00224 } 00225 00226 QSize frameSize() const { 00227 return m_frameSize; 00228 } 00229 00230 void setFrameSize(const QSize &frameSize) { 00231 m_frameSize = frameSize; 00232 } 00233 00234 QXmppVideoFrame::PixelFormat pixelFormat() const { 00235 return m_pixelFormat; 00236 } 00237 00238 void setPixelFormat(QXmppVideoFrame::PixelFormat pixelFormat) { 00239 m_pixelFormat = pixelFormat; 00240 } 00241 00242 private: 00243 qreal m_frameRate; 00244 QSize m_frameSize; 00245 QXmppVideoFrame::PixelFormat m_pixelFormat; 00246 }; 00247 00248 00252 00253 class QXmppRtpVideoChannel : public QXmppLoggable, public QXmppRtpChannel 00254 { 00255 Q_OBJECT 00256 00257 public: 00258 QXmppRtpVideoChannel(QObject *parent = 0); 00259 ~QXmppRtpVideoChannel(); 00260 00261 // incoming stream 00262 QXmppVideoFormat decoderFormat() const; 00263 QList<QXmppVideoFrame> readFrames(); 00264 00265 // outgoing stream 00266 QXmppVideoFormat encoderFormat() const; 00267 void setEncoderFormat(const QXmppVideoFormat &format); 00268 void writeFrame(const QXmppVideoFrame &frame); 00269 00270 QIODevice::OpenMode openMode() const; 00271 void close(); 00272 00273 signals: 00275 void sendDatagram(const QByteArray &ba); 00276 00277 public slots: 00278 void datagramReceived(const QByteArray &ba); 00279 00280 protected: 00281 void payloadTypesChanged(); 00282 00283 private: 00284 friend class QXmppRtpVideoChannelPrivate; 00285 QXmppRtpVideoChannelPrivate * d; 00286 }; 00287 00288 #endif