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

Remove PT mapping in the sender. For now on, just the PTs chosen by mediasoup…

Remove PT mapping in the sender. For now on, just the PTs chosen by mediasoup (or those given in the room codecs) will be used for receiving and sending.
上级 beea7623
......@@ -38,7 +38,7 @@ Once created, peer's capabilities must be set (otherwise no `RtpReceiver` can be
These codecs have the same fields as the room codecs, with some variations:
* `payloadType` is mandatory.
* `payloadType` is ignored (it will be mapped to the same room codec).
* `rtcpFeedback` is optional.
After that, C++ `Room::onPeerCapabilities(capabilities)` is called. This method removes peer's codecs not supported by the room, removes the unsupported RTCP feedback mechanisms from the supported codecs, and removes RTP header extensions and FEC mechanisms not supported by mediasoup.
......
......@@ -9,7 +9,7 @@
#include "RTC/RTCP/Sdes.h"
#include "Channel/Request.h"
#include "Channel/Notifier.h"
#include <unordered_map>
#include <unordered_set>
#include <json/json.h>
namespace RTC
......@@ -63,7 +63,7 @@ namespace RTC
// Allocated by this.
RTC::RtpParameters* rtpParameters = nullptr;
// Others.
std::unordered_map<uint8_t, uint8_t> mapPayloadTypes;
std::unordered_set<uint8_t> supportedPayloadTypes;
// Whether this RtpSender is valid according to Peer capabilities.
bool available = false;
// Sender Report holding the RTP stats.
......
......@@ -87,7 +87,7 @@ namespace RTC
// ignore it.
for (auto& supportedMediaCodec : Room::supportedRtpCapabilities.codecs)
{
if (supportedMediaCodec.Matches(mediaCodec, false))
if (supportedMediaCodec.Matches(mediaCodec))
{
// Clone the supported media codec.
RTC::RtpCodecParameters clonedSupportedMediaCodec = supportedMediaCodec;
......@@ -471,7 +471,11 @@ namespace RTC
if (roomCodecCapability.Matches(peerCodecCapability))
{
// Once matched, remove the unsupported RTCP feedback from the given codec.
// Set the same payload type.
peerCodecCapability.payloadType = roomCodecCapability.payloadType;
peerCodecCapability.hasPayloadType = true;
// Remove the unsupported RTCP feedback from the given codec.
peerCodecCapability.RemoveUnsupportedRtcpFeedback(roomCodecCapability.rtcpFeedback);
break;
......
......@@ -57,14 +57,21 @@ namespace RTC
this->hasPayloadType = true;
}
if (
this->scope == RTC::Scope::PEER_CAPABILITY ||
this->scope == RTC::Scope::RECEIVE)
if (this->scope == RTC::Scope::PEER_CAPABILITY)
{
if (!this->hasPayloadType)
MS_THROW_ERROR("missing RtpCodecParameters.payloadType");
}
if (this->scope == RTC::Scope::RECEIVE)
{
if (!data[k_payloadType].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.payloadType");
this->payloadType = (uint8_t)data[k_payloadType].asUInt();
this->hasPayloadType = true;
}
// `clockRate` is mandatory.
if (!data[k_clockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.clockRate");
......
......@@ -54,7 +54,7 @@ namespace RTC
static const Json::StaticString k_rtpParameters("rtpParameters");
static const Json::StaticString k_hasTransport("hasTransport");
static const Json::StaticString k_available("available");
static const Json::StaticString k_mapPayloadTypes("mapPayloadTypes");
static const Json::StaticString k_supportedPayloadTypes("supportedPayloadTypes");
Json::Value json(Json::objectValue);
......@@ -71,10 +71,11 @@ namespace RTC
json[k_available] = this->available;
json[k_mapPayloadTypes] = Json::objectValue;
for (auto& kv : this->mapPayloadTypes)
json[k_supportedPayloadTypes] = Json::arrayValue;
for (auto payloadType : this->supportedPayloadTypes)
{
json[k_mapPayloadTypes][std::to_string(kv.first)] = kv.second;
json[k_supportedPayloadTypes].append((Json::UInt)payloadType);
}
return json;
......@@ -135,8 +136,6 @@ namespace RTC
// Remove RTP parameters not supported by this Peer.
// Remove unsupported codecs.
std::unordered_set<uint8_t> supportedPayloadTypes;
for (auto it = this->rtpParameters->codecs.begin(); it != this->rtpParameters->codecs.end();)
{
auto& codec = *it;
......@@ -152,7 +151,7 @@ namespace RTC
if (it2 != this->peerCapabilities->codecs.end())
{
supportedPayloadTypes.insert(codec.payloadType);
this->supportedPayloadTypes.insert(codec.payloadType);
++it;
}
else
......@@ -178,9 +177,6 @@ namespace RTC
// TODO: Remove unsupported header extensions.
// Build the payload types map.
SetPayloadTypesMapping();
// If there are no encodings set not available.
if (this->rtpParameters->encodings.size() > 0)
this->available = true;
......@@ -209,29 +205,20 @@ namespace RTC
// Map the payload type.
uint8_t originalPayloadType = packet->GetPayloadType();
uint8_t mappedPayloadType;
auto it = this->mapPayloadTypes.find(originalPayloadType);
uint8_t payloadType = packet->GetPayloadType();
auto it = this->supportedPayloadTypes.find(payloadType);
// 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->supportedPayloadTypes.end())
{
MS_DEBUG_TAG(rtp, "payload type not mapped [payloadType:%" PRIu8 "]", originalPayloadType);
MS_DEBUG_TAG(rtp, "payload type not supported [payloadType:%" PRIu8 "]", payloadType);
return;
}
mappedPayloadType = this->mapPayloadTypes[originalPayloadType];
// Map the packet payload type.
packet->SetPayloadType(mappedPayloadType);
// Send the packet.
this->transport->SendRtpPacket(packet);
// Revert the original packet payload type.
packet->SetPayloadType(originalPayloadType);
}
void RtpSender::RetransmitRtpPacket(RTC::RtpPacket* packet)
......@@ -246,51 +233,4 @@ namespace RTC
// TODO: No RTX for now so just send as usual.
SendRtpPacket(packet);
}
void RtpSender::SetPayloadTypesMapping()
{
MS_TRACE();
MS_ASSERT(this->peerCapabilities, "peer RTP capabilities are null");
this->mapPayloadTypes.clear();
for (auto& codec : this->rtpParameters->codecs)
{
auto it = this->peerCapabilities->codecs.begin();
for (; it != this->peerCapabilities->codecs.end(); ++it)
{
auto& codecCapability = *it;
if (codecCapability.Matches(codec))
{
auto originalPayloadType = codec.payloadType;
auto mappedPayloadType = codecCapability.payloadType;
// Set the mapping.
this->mapPayloadTypes[originalPayloadType] = mappedPayloadType;
// Override the codec payload type.
codec.payloadType = mappedPayloadType;
// Override encoding.codecPayloadType.
for (auto& encoding : this->rtpParameters->encodings)
{
// TODO: remove when confirmed
MS_ASSERT(encoding.hasCodecPayloadType, "encoding without codecPayloadType");
if (encoding.codecPayloadType == originalPayloadType)
encoding.codecPayloadType = mappedPayloadType;
}
break;
}
}
// This should not happen.
MS_ASSERT(it != this->peerCapabilities->codecs.end(),
"no matching room codec found [payloadType:%" PRIu8 "]", codec.payloadType);
}
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论