aboutsummaryrefslogtreecommitdiff
path: root/src/base/QXmppRtcpPacket.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2015-08-25 21:43:56 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2015-08-25 21:43:56 +0200
commit3fa128ca62939dff7e161cc2ead6ade90f3c3578 (patch)
treecb0036687be5b1349cabccc5bef3f719f626a7e1 /src/base/QXmppRtcpPacket.cpp
parent0c62daec465a71767bc6339a1d13ab8f07daaefd (diff)
downloadqxmpp-3fa128ca62939dff7e161cc2ead6ade90f3c3578.tar.gz
RTCP: encode source descriptions
Diffstat (limited to 'src/base/QXmppRtcpPacket.cpp')
-rw-r--r--src/base/QXmppRtcpPacket.cpp57
1 files changed, 49 insertions, 8 deletions
diff --git a/src/base/QXmppRtcpPacket.cpp b/src/base/QXmppRtcpPacket.cpp
index 08b106ad..f8bb56ed 100644
--- a/src/base/QXmppRtcpPacket.cpp
+++ b/src/base/QXmppRtcpPacket.cpp
@@ -49,7 +49,8 @@ public:
class QXmppRtcpSourceDescriptionPrivate : public QSharedData
{
public:
- bool read(QDataStream &s);
+ bool read(QDataStream &stream);
+ void write(QDataStream &stream) const;
quint32 ssrc;
QString cname;
@@ -144,10 +145,23 @@ bool QXmppRtcpPacket::read(QDataStream &stream)
void QXmppRtcpPacket::write(QDataStream &stream) const
{
- stream << quint8((RTP_VERSION << 6) | (d->count & 0x1f));
+ QByteArray payload;
+ quint8 count;
+
+ if (d->type == SourceDescription) {
+ count = d->sourceDescriptions.size();
+ QDataStream s(&payload, QIODevice::WriteOnly);
+ foreach (const QXmppRtcpSourceDescription &desc, d->sourceDescriptions)
+ desc.d->write(s);
+ } else {
+ count = d->count;
+ payload = d->payload;
+ }
+
+ stream << quint8((RTP_VERSION << 6) | (count & 0x1f));
stream << d->type;
- stream << quint16(d->payload.size() >> 2);
- stream.writeRawData(d->payload.constData(), d->payload.size());
+ stream << quint16(payload.size() >> 2);
+ stream.writeRawData(payload.constData(), payload.size());
}
/// Returns the number of report blocks.
@@ -199,7 +213,6 @@ void QXmppRtcpPacket::setType(quint8 type)
bool QXmppRtcpSourceDescriptionPrivate::read(QDataStream &stream)
{
- QByteArray padding;
QByteArray buffer;
quint8 itemType, itemLength;
quint16 chunkLength = 0;
@@ -231,15 +244,43 @@ bool QXmppRtcpSourceDescriptionPrivate::read(QDataStream &stream)
name = QString::fromUtf8(buffer);
}
if (chunkLength % 4) {
- padding.resize(4 - chunkLength % 4);
- if (stream.readRawData(padding.data(), padding.size()) != padding.size())
+ buffer.resize(4 - chunkLength % 4);
+ if (stream.readRawData(buffer.data(), buffer.size()) != buffer.size())
return false;
- if (padding != QByteArray(padding.size(), 0))
+ if (buffer != QByteArray(buffer.size(), '\0'))
return false;
}
return true;
}
+void QXmppRtcpSourceDescriptionPrivate::write(QDataStream &stream) const
+{
+ QByteArray buffer;
+ quint16 chunkLength = 0;
+
+ stream << ssrc;
+ if (!cname.isEmpty()) {
+ buffer = cname.toUtf8();
+ stream << quint8(CnameType);
+ stream << quint8(buffer.size());
+ stream.writeRawData(buffer.constData(), buffer.size());
+ chunkLength += 2 + buffer.size();
+ }
+ if (!name.isEmpty()) {
+ buffer = name.toUtf8();
+ stream << quint8(NameType);
+ stream << quint8(buffer.size());
+ stream.writeRawData(buffer.constData(), buffer.size());
+ chunkLength += 2 + buffer.size();
+ }
+ stream << quint8(0);
+ chunkLength++;
+ if (chunkLength % 4) {
+ buffer = QByteArray(4 - chunkLength % 4, '\0');
+ stream.writeRawData(buffer.constData(), buffer.size());
+ }
+}
+
/// Constructs an empty source description
QXmppRtcpSourceDescription::QXmppRtcpSourceDescription()