提交 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 ...@@ -198,7 +198,7 @@ namespace RTC
return ( return (
// Minimum DTLS record length is 13 bytes. // Minimum DTLS record length is 13 bytes.
(len >= 13) && (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) (data[0] > 19 && data[0] < 64)
); );
} }
......
...@@ -51,7 +51,7 @@ namespace RTC ...@@ -51,7 +51,7 @@ namespace RTC
return ( return (
(len >= sizeof(CommonHeader)) && (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) && (data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2. // RTP Version must be 2.
(header->version == 2) && (header->version == 2) &&
......
...@@ -90,7 +90,7 @@ namespace RTC ...@@ -90,7 +90,7 @@ namespace RTC
return ( return (
(len >= sizeof(Header)) && (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) && (data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2. // RTP Version must be 2.
(header->version == 2) (header->version == 2)
......
...@@ -122,8 +122,8 @@ namespace RTC ...@@ -122,8 +122,8 @@ namespace RTC
return ( return (
// STUN headers are 20 bytes. // STUN headers are 20 bytes.
(len >= 20) && (len >= 20) &&
// 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] < 20) && (data[0] < 3) &&
// Magic cookie must match. // Magic cookie must match.
(data[4] == StunMessage::magicCookie[0]) && (data[4] == StunMessage::magicCookie[0]) &&
(data[5] == StunMessage::magicCookie[1]) && (data[5] == StunMessage::magicCookie[1]) &&
......
...@@ -14,12 +14,65 @@ namespace RTC ...@@ -14,12 +14,65 @@ namespace RTC
if (!RtcpPacket::IsRtcp(data, len)) if (!RtcpPacket::IsRtcp(data, len))
return nullptr; return nullptr;
// TODO: Do it. // 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;
}
// Get the header.
CommonHeader* header = (CommonHeader*)data; 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. */ /* Instance methods. */
......
...@@ -57,7 +57,6 @@ namespace RTC ...@@ -57,7 +57,6 @@ namespace RTC
// The header extension contains a 16-bit length field that counts the number of // 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. // 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); extension_value_size = (size_t)(ntohs(extensionHeader->length) * 4);
// Packet size must be >= header size + CSRC list + header extension size. // Packet size must be >= header size + CSRC list + header extension size.
...@@ -91,7 +90,7 @@ namespace RTC ...@@ -91,7 +90,7 @@ namespace RTC
payloadPadding = data[len - 1]; payloadPadding = data[len - 1];
if (payloadPadding == 0) if (payloadPadding == 0)
{ {
MS_DEBUG("padding byte cannot be 0 packet discarded"); MS_DEBUG("padding byte cannot be 0, packet discarded");
return nullptr; return nullptr;
} }
...@@ -177,7 +176,7 @@ namespace RTC ...@@ -177,7 +176,7 @@ namespace RTC
size_t extension_value_size = 0; size_t extension_value_size = 0;
// First calculate the total required size for the entire message. // 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) if (this->csrcList)
this->length += this->header->csrc_count * sizeof(header->ssrc); this->length += this->header->csrc_count * sizeof(header->ssrc);
...@@ -195,7 +194,7 @@ namespace RTC ...@@ -195,7 +194,7 @@ namespace RTC
// Allocate it. // Allocate it.
this->raw = new uint8_t[this->length]; this->raw = new uint8_t[this->length];
// Add minimun header. // Add minimum header.
std::memcpy(this->raw, this->header, sizeof(Header)); std::memcpy(this->raw, this->header, sizeof(Header));
size_t pos = sizeof(Header); size_t pos = sizeof(Header);
...@@ -227,7 +226,7 @@ namespace RTC ...@@ -227,7 +226,7 @@ namespace RTC
{ {
std::memcpy(this->raw + pos, this->payload, this->payloadLength); std::memcpy(this->raw + pos, this->payload, this->payloadLength);
// Update the pointer. // Update the payload pointer.
this->payload = this->raw + pos; this->payload = this->raw + pos;
pos += this->payloadLength; pos += this->payloadLength;
} }
......
...@@ -217,7 +217,9 @@ namespace RTC ...@@ -217,7 +217,9 @@ namespace RTC
uint8_t mappedPayloadType; uint8_t mappedPayloadType;
auto it = this->mapPayloadTypes.find(originalPayloadType); 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()) if (it == this->mapPayloadTypes.end())
{ {
MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]", MS_ERROR("payload type not mapped [payloadType:%" PRIu8 "]",
......
...@@ -778,22 +778,22 @@ namespace RTC ...@@ -778,22 +778,22 @@ namespace RTC
if (!this->srtpRecvSession->DecryptSrtcp(data, &len)) if (!this->srtpRecvSession->DecryptSrtcp(data, &len))
return; return;
RTC::RtcpPacket* packet = RTC::RtcpPacket::Parse(data, len); RTC::RtcpPacket* compoundPacket = RTC::RtcpPacket::Parse(data, len);
if (!packet) 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; return;
} }
// TODO: implement this properly! // TODO: implement this properly!
// For now let route the received RTCP packet to all our RtpReceivers. // 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. // Trick for clients performing aggressive ICE regardless we are ICE-Lite.
// this->iceServer->ForceSelectedTuple(tuple); // 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) void Transport::onPacketRecv(RTC::UdpSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论