提交 ef7effa4 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

- Do some RTCP parsing for compound messages

- Update to https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
上级 3cd729da
......@@ -198,7 +198,7 @@ namespace RTC
return (
// Minimum DTLS record length is 13 bytes.
(len >= 13) &&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 19 && data[0] < 64)
);
}
......
......@@ -51,7 +51,7 @@ namespace RTC
return (
(len >= sizeof(CommonHeader)) &&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2) &&
......
......@@ -90,7 +90,7 @@ namespace RTC
return (
(len >= sizeof(Header)) &&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2)
......
......@@ -122,8 +122,8 @@ namespace RTC
return (
// STUN headers are 20 bytes.
(len >= 20) &&
// DOC: https://tools.ietf.org/html/draft-petithuguenin-avtcore-rfc5764-mux-fixes-00
(data[0] < 20) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] < 3) &&
// Magic cookie must match.
(data[4] == StunMessage::magicCookie[0]) &&
(data[5] == StunMessage::magicCookie[1]) &&
......
......@@ -14,12 +14,65 @@ namespace RTC
if (!RtcpPacket::IsRtcp(data, len))
return nullptr;
// TODO: Do it.
// Get the header.
// TODO: just for now
CommonHeader* header = (CommonHeader*)data;
RtcpPacket* compoundPacket = new RtcpPacket(header, data, len);
MS_WARN("----begin----");
bool more = true;
while (more)
{
if (!RtcpPacket::IsRtcp(data, len))
{
MS_WARN("data is not a RTCP packet");
return nullptr;
}
CommonHeader* header = (CommonHeader*)data;
size_t packet_len = (size_t)(ntohs(header->length) + 1) * 4;
if (len < packet_len)
{
MS_WARN("packet length exceeds remaining data [len:%zu, packet_len:%zu]", len, packet_len);
return nullptr;
}
// TODO: jeje
switch (header->packet_type)
{
case 200:
MS_WARN("SENDER REPORT");
break;
case 201:
MS_WARN("RECEIVER REPORT");
break;
case 202:
MS_WARN("SDES");
break;
case 203:
MS_WARN("BYE");
break;
case 204:
MS_WARN("APPLICATION DEFINED");
break;
default:
MS_WARN("unknown RTCP packet type [packet_type:%" PRIu8 "]", header->packet_type);
}
data += packet_len;
len -= packet_len;
if (len == 0)
more = false;
}
MS_WARN("-----end-----");
return new RtcpPacket(header, data, len);
return compoundPacket;
}
/* Instance methods. */
......
......@@ -57,7 +57,6 @@ namespace RTC
// The header extension contains a 16-bit length field that counts the number of
// 32-bit words in the extension, excluding the four-octet extension header.
// extension_value_size = (size_t)(Utils::Byte::Get2Bytes(data, pos + 2) * 4);
extension_value_size = (size_t)(ntohs(extensionHeader->length) * 4);
// Packet size must be >= header size + CSRC list + header extension size.
......@@ -91,7 +90,7 @@ namespace RTC
payloadPadding = data[len - 1];
if (payloadPadding == 0)
{
MS_DEBUG("padding byte cannot be 0 packet discarded");
MS_DEBUG("padding byte cannot be 0, packet discarded");
return nullptr;
}
......@@ -177,7 +176,7 @@ namespace RTC
size_t extension_value_size = 0;
// First calculate the total required size for the entire message.
this->length = sizeof(Header); // Minimun header.
this->length = sizeof(Header); // Minimum header.
if (this->csrcList)
this->length += this->header->csrc_count * sizeof(header->ssrc);
......@@ -195,7 +194,7 @@ namespace RTC
// Allocate it.
this->raw = new uint8_t[this->length];
// Add minimun header.
// Add minimum header.
std::memcpy(this->raw, this->header, sizeof(Header));
size_t pos = sizeof(Header);
......@@ -227,7 +226,7 @@ namespace RTC
{
std::memcpy(this->raw + pos, this->payload, this->payloadLength);
// Update the pointer.
// Update the payload pointer.
this->payload = this->raw + pos;
pos += this->payloadLength;
}
......
......@@ -217,7 +217,9 @@ namespace RTC
uint8_t mappedPayloadType;
auto it = this->mapPayloadTypes.find(originalPayloadType);
// TODO: This should never happen.
// NOTE: This may happen if this peer supports just some codecs from the
// given RtpParameters.
// TODO: We should not report an error here but just ignore it.
if (it == this->mapPayloadTypes.end())
{
MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]",
......
......@@ -778,22 +778,22 @@ namespace RTC
if (!this->srtpRecvSession->DecryptSrtcp(data, &len))
return;
RTC::RtcpPacket* packet = RTC::RtcpPacket::Parse(data, len);
if (!packet)
RTC::RtcpPacket* compoundPacket = RTC::RtcpPacket::Parse(data, len);
if (!compoundPacket)
{
MS_WARN("received data is not a valid RTCP packet");
MS_WARN("received data is not a valid RTCP compound or single packet");
return;
}
// TODO: implement this properly!
// For now let route the received RTCP packet to all our RtpReceivers.
this->listener->onTransportRtcpPacket(this, packet);
this->listener->onTransportRtcpPacket(this, compoundPacket);
// Trick for clients performing aggressive ICE regardless we are ICE-Lite.
// this->iceServer->ForceSelectedTuple(tuple);
delete packet;
delete compoundPacket;
}
void Transport::onPacketRecv(RTC::UdpSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论