diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2015-08-20 09:04:38 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2015-08-20 09:04:38 +0200 |
| commit | f87d817c2f3390d80a038007dcfaf588375319dd (patch) | |
| tree | 28b5ddec34b6ca33af536e6de14b841bbb117704 /src/base | |
| parent | 3a51c38d120a30f717e8584a4502d3848a0e1ac5 (diff) | |
| download | qxmpp-f87d817c2f3390d80a038007dcfaf588375319dd.tar.gz | |
move QXmppRtpPacket to it's own files
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/QXmppCodec.cpp | 1 | ||||
| -rw-r--r-- | src/base/QXmppRtpChannel.cpp | 81 | ||||
| -rw-r--r-- | src/base/QXmppRtpChannel.h | 28 | ||||
| -rw-r--r-- | src/base/QXmppRtpPacket.cpp | 115 | ||||
| -rw-r--r-- | src/base/QXmppRtpPacket.h | 62 | ||||
| -rw-r--r-- | src/base/base.pri | 2 |
6 files changed, 181 insertions, 108 deletions
diff --git a/src/base/QXmppCodec.cpp b/src/base/QXmppCodec.cpp index 556295b4..97de1996 100644 --- a/src/base/QXmppCodec.cpp +++ b/src/base/QXmppCodec.cpp @@ -32,6 +32,7 @@ #include "QXmppCodec_p.h" #include "QXmppRtpChannel.h" +#include "QXmppRtpPacket.h" #include <cstring> diff --git a/src/base/QXmppRtpChannel.cpp b/src/base/QXmppRtpChannel.cpp index 59f18287..ca498a63 100644 --- a/src/base/QXmppRtpChannel.cpp +++ b/src/base/QXmppRtpChannel.cpp @@ -30,6 +30,7 @@ #include "QXmppCodec_p.h" #include "QXmppJingleIq.h" #include "QXmppRtpChannel.h" +#include "QXmppRtpPacket.h" #ifndef M_PI #define M_PI 3.14159265358979323846264338327950288 @@ -39,83 +40,6 @@ //#define QXMPP_DEBUG_RTP_BUFFER #define SAMPLE_BYTES 2 -const quint8 RTP_VERSION = 0x02; - -/// Parses an RTP packet. -/// -/// \param ba - -bool QXmppRtpPacket::decode(const QByteArray &ba) -{ - if (ba.isEmpty()) - return false; - - // fixed header - quint8 tmp; - QDataStream stream(ba); - stream >> tmp; - version = (tmp >> 6); - const quint8 cc = (tmp >> 1) & 0xf; - const int hlen = 12 + 4 * cc; - if (version != RTP_VERSION || ba.size() < hlen) - return false; - stream >> tmp; - marker = (tmp >> 7); - type = tmp & 0x7f; - stream >> sequence; - stream >> stamp; - stream >> ssrc; - - // contributing source IDs - csrc.clear(); - quint32 src; - for (int i = 0; i < cc; ++i) { - stream >> src; - csrc << src; - } - - // retrieve payload - payload = ba.right(ba.size() - hlen); - return true; -} - -/// Encodes an RTP packet. - -QByteArray QXmppRtpPacket::encode() const -{ - Q_ASSERT(csrc.size() < 16); - - // fixed header - QByteArray ba; - ba.resize(payload.size() + 12 + 4 * csrc.size()); - QDataStream stream(&ba, QIODevice::WriteOnly); - stream << quint8(((version & 0x3) << 6) | - ((csrc.size() & 0xf) << 1)); - stream << quint8((type & 0x7f) | (marker << 7)); - stream << sequence; - stream << stamp; - stream << ssrc; - - // contributing source ids - foreach (const quint32 &src, csrc) - stream << src; - - stream.writeRawData(payload.constData(), payload.size()); - return ba; -} - -/// Returns a string representation of the RTP header. - -QString QXmppRtpPacket::toString() const -{ - return QString("RTP packet seq %1 stamp %2 marker %3 type %4 size %5").arg( - QString::number(sequence), - QString::number(stamp), - QString::number(marker), - QString::number(type), - QString::number(payload.size())); -} - /// Creates a new RTP channel. QXmppRtpChannel::QXmppRtpChannel() @@ -698,7 +622,6 @@ void QXmppRtpAudioChannel::writeDatagram() if (d->outgoingTonesType.id()) { // send RFC 2833 DTMF QXmppRtpPacket packet; - packet.version = RTP_VERSION; packet.marker = (info.outgoingStart == d->outgoingStamp); packet.type = d->outgoingTonesType.id(); packet.sequence = d->outgoingSequence; @@ -730,7 +653,6 @@ void QXmppRtpAudioChannel::writeDatagram() if (sendAudio) { // send audio data QXmppRtpPacket packet; - packet.version = RTP_VERSION; if (d->outgoingMarker) { packet.marker = true; @@ -1066,7 +988,6 @@ void QXmppRtpVideoChannel::writeFrame(const QXmppVideoFrame &frame) } QXmppRtpPacket packet; - packet.version = RTP_VERSION; packet.marker = false; packet.type = d->outgoingId; packet.ssrc = localSsrc(); diff --git a/src/base/QXmppRtpChannel.h b/src/base/QXmppRtpChannel.h index 352a250f..32e0cd35 100644 --- a/src/base/QXmppRtpChannel.h +++ b/src/base/QXmppRtpChannel.h @@ -35,34 +35,6 @@ class QXmppJinglePayloadType; class QXmppRtpAudioChannelPrivate; class QXmppRtpVideoChannelPrivate; -/// \brief The QXmppRtpPacket class represents an RTP packet. -/// - -class QXMPP_EXPORT QXmppRtpPacket -{ -public: - bool decode(const QByteArray &ba); - QByteArray encode() const; - QString toString() const; - - /// RTP version. - quint8 version; - /// Marker flag. - bool marker; - /// Payload type. - quint8 type; - /// Synchronization source. - quint32 ssrc; - /// Contributing sources. - QList<quint32> csrc; - /// Sequence number. - quint16 sequence; - /// Timestamp. - quint32 stamp; - /// Raw payload data. - QByteArray payload; -}; - class QXMPP_EXPORT QXmppRtpChannel { public: diff --git a/src/base/QXmppRtpPacket.cpp b/src/base/QXmppRtpPacket.cpp new file mode 100644 index 00000000..37d4eb7b --- /dev/null +++ b/src/base/QXmppRtpPacket.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2008-2014 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#include <QDataStream> + +#include "QXmppRtpPacket.h" + +#define RTP_VERSION 2 + +QXmppRtpPacket::QXmppRtpPacket() + : marker(false) + , type(0) + , ssrc(0) + , sequence(0) + , stamp(0) +{ +} + +QXmppRtpPacket::~QXmppRtpPacket() +{ +} + +/// Parses an RTP packet. +/// +/// \param ba + +bool QXmppRtpPacket::decode(const QByteArray &ba) +{ + if (ba.isEmpty()) + return false; + + // fixed header + quint8 tmp; + QDataStream stream(ba); + stream >> tmp; + const quint8 cc = (tmp >> 1) & 0xf; + const int hlen = 12 + 4 * cc; + if ((tmp >> 6) != RTP_VERSION || ba.size() < hlen) + return false; + stream >> tmp; + marker = (tmp >> 7); + type = tmp & 0x7f; + stream >> sequence; + stream >> stamp; + stream >> ssrc; + + // contributing source IDs + csrc.clear(); + quint32 src; + for (int i = 0; i < cc; ++i) { + stream >> src; + csrc << src; + } + + // retrieve payload + payload = ba.right(ba.size() - hlen); + return true; +} + +/// Encodes an RTP packet. + +QByteArray QXmppRtpPacket::encode() const +{ + Q_ASSERT(csrc.size() < 16); + + // fixed header + QByteArray ba; + ba.resize(payload.size() + 12 + 4 * csrc.size()); + QDataStream stream(&ba, QIODevice::WriteOnly); + stream << quint8((RTP_VERSION << 6) | + ((csrc.size() & 0xf) << 1)); + stream << quint8((type & 0x7f) | (marker << 7)); + stream << sequence; + stream << stamp; + stream << ssrc; + + // contributing source ids + foreach (const quint32 &src, csrc) + stream << src; + + stream.writeRawData(payload.constData(), payload.size()); + return ba; +} + +/// Returns a string representation of the RTP header. + +QString QXmppRtpPacket::toString() const +{ + return QString("RTP packet seq %1 stamp %2 marker %3 type %4 size %5").arg( + QString::number(sequence), + QString::number(stamp), + QString::number(marker), + QString::number(type), + QString::number(payload.size())); +} diff --git a/src/base/QXmppRtpPacket.h b/src/base/QXmppRtpPacket.h new file mode 100644 index 00000000..d4ef590a --- /dev/null +++ b/src/base/QXmppRtpPacket.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2008-2014 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * Source: + * https://github.com/qxmpp-project/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + +#ifndef QXMPPRTPPACKET_H +#define QXMPPRTPPACKET_H + +#include <QSharedDataPointer> + +#include "QXmppGlobal.h" + +class QXmppRtpPacketPrivate; + +/// \brief The QXmppRtpPacket class represents an RTP packet. +/// + +class QXMPP_EXPORT QXmppRtpPacket +{ +public: + QXmppRtpPacket(); + ~QXmppRtpPacket(); + + bool decode(const QByteArray &ba); + QByteArray encode() const; + QString toString() const; + + /// Marker flag. + bool marker; + /// Payload type. + quint8 type; + /// Synchronization source. + quint32 ssrc; + /// Contributing sources. + QList<quint32> csrc; + /// Sequence number. + quint16 sequence; + /// Timestamp. + quint32 stamp; + /// Raw payload data. + QByteArray payload; +}; + +#endif diff --git a/src/base/base.pri b/src/base/base.pri index 537fe75c..4bd31982 100644 --- a/src/base/base.pri +++ b/src/base/base.pri @@ -26,6 +26,7 @@ INSTALL_HEADERS += \ base/QXmppRpcIq.h \ base/QXmppRtcpPacket.h \ base/QXmppRtpChannel.h \ + base/QXmppRtpPacket.h \ base/QXmppSessionIq.h \ base/QXmppSocks.h \ base/QXmppStanza.h \ @@ -70,6 +71,7 @@ SOURCES += \ base/QXmppRpcIq.cpp \ base/QXmppRtcpPacket.cpp \ base/QXmppRtpChannel.cpp \ + base/QXmppRtpPacket.cpp \ base/QXmppSasl.cpp \ base/QXmppSessionIq.cpp \ base/QXmppSocks.cpp \ |
