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

RtpListener: remove payload type based table

上级 38a3161f
...@@ -19,7 +19,6 @@ namespace RTC ...@@ -19,7 +19,6 @@ namespace RTC
Json::Value ToJson() const; Json::Value ToJson() const;
bool HasSsrc(uint32_t ssrc, const RTC::Producer* producer) const; bool HasSsrc(uint32_t ssrc, const RTC::Producer* producer) const;
bool HasMuxId(const std::string& muxId, const RTC::Producer* producer) const; bool HasMuxId(const std::string& muxId, const RTC::Producer* producer) const;
bool HasPayloadType(uint8_t payloadType, const RTC::Producer* producer) const;
void AddProducer(RTC::Producer* producer); void AddProducer(RTC::Producer* producer);
void RemoveProducer(const RTC::Producer* producer); void RemoveProducer(const RTC::Producer* producer);
RTC::Producer* GetProducer(RTC::RtpPacket* packet); RTC::Producer* GetProducer(RTC::RtpPacket* packet);
...@@ -27,18 +26,13 @@ namespace RTC ...@@ -27,18 +26,13 @@ namespace RTC
private: private:
void RollbackProducer( void RollbackProducer(
RTC::Producer* producer, RTC::Producer* producer, std::vector<uint32_t>& previousSsrcs, std::string& previousMuxId);
std::vector<uint32_t>& previousSsrcs,
std::string& previousMuxId,
std::vector<uint8_t>& previousPayloadTypes);
public: public:
// Table of SSRC / Producer pairs. // Table of SSRC / Producer pairs.
std::unordered_map<uint32_t, RTC::Producer*> ssrcTable; std::unordered_map<uint32_t, RTC::Producer*> ssrcTable;
// Table of MID RTP header extension / Producer pairs. // Table of MID RTP header extension / Producer pairs.
std::unordered_map<std::string, const RTC::Producer*> muxIdTable; std::unordered_map<std::string, const RTC::Producer*> muxIdTable;
// Table of RTP payload type / Producer pairs.
std::unordered_map<uint8_t, RTC::Producer*> ptTable;
}; };
/* Inline instance methods. */ /* Inline instance methods. */
...@@ -70,20 +64,6 @@ namespace RTC ...@@ -70,20 +64,6 @@ namespace RTC
return (it->second != producer); return (it->second != producer);
} }
} }
inline bool RtpListener::HasPayloadType(uint8_t payloadType, const RTC::Producer* producer) const
{
auto it = this->ptTable.find(payloadType);
if (it == this->ptTable.end())
{
return false;
}
else
{
return (it->second != producer);
}
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -16,12 +16,10 @@ namespace RTC ...@@ -16,12 +16,10 @@ namespace RTC
static const Json::StaticString JsonStringSsrcTable{ "ssrcTable" }; static const Json::StaticString JsonStringSsrcTable{ "ssrcTable" };
static const Json::StaticString JsonStringMuxIdTable{ "muxIdTable" }; static const Json::StaticString JsonStringMuxIdTable{ "muxIdTable" };
static const Json::StaticString JsonStringPtTable{ "ptTable" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
Json::Value jsonSsrcTable(Json::objectValue); Json::Value jsonSsrcTable(Json::objectValue);
Json::Value jsonMuxIdTable(Json::objectValue); Json::Value jsonMuxIdTable(Json::objectValue);
Json::Value jsonPtTable(Json::objectValue);
// Add ssrcTable. // Add ssrcTable.
for (auto& kv : this->ssrcTable) for (auto& kv : this->ssrcTable)
...@@ -43,16 +41,6 @@ namespace RTC ...@@ -43,16 +41,6 @@ namespace RTC
} }
json[JsonStringMuxIdTable] = jsonMuxIdTable; json[JsonStringMuxIdTable] = jsonMuxIdTable;
// Add ptTable.
for (auto& kv : this->ptTable)
{
auto payloadType = kv.first;
auto producer = kv.second;
jsonPtTable[std::to_string(payloadType)] = std::to_string(producer->producerId);
}
json[JsonStringPtTable] = jsonPtTable;
return json; return json;
} }
...@@ -66,7 +54,6 @@ namespace RTC ...@@ -66,7 +54,6 @@ namespace RTC
std::vector<uint32_t> previousSsrcs; std::vector<uint32_t> previousSsrcs;
std::string previousMuxId; std::string previousMuxId;
std::vector<uint8_t> previousPayloadTypes;
for (auto& kv : this->ssrcTable) for (auto& kv : this->ssrcTable)
{ {
...@@ -89,15 +76,6 @@ namespace RTC ...@@ -89,15 +76,6 @@ namespace RTC
} }
} }
for (auto& kv : this->ptTable)
{
auto payloadType = kv.first;
auto& existingProducer = kv.second;
if (existingProducer == producer)
previousPayloadTypes.push_back(payloadType);
}
// First remove from the listener tables all the entries pointing to // First remove from the listener tables all the entries pointing to
// the given Producer. // the given Producer.
RemoveProducer(producer); RemoveProducer(producer);
...@@ -121,7 +99,7 @@ namespace RTC ...@@ -121,7 +99,7 @@ namespace RTC
else else
{ {
RemoveProducer(producer); RemoveProducer(producer);
RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes); RollbackProducer(producer, previousSsrcs, previousMuxId);
MS_THROW_ERROR("ssrc already exists in RTP listener [ssrc:%" PRIu32 "]", ssrc); MS_THROW_ERROR("ssrc already exists in RTP listener [ssrc:%" PRIu32 "]", ssrc);
} }
...@@ -140,7 +118,7 @@ namespace RTC ...@@ -140,7 +118,7 @@ namespace RTC
else else
{ {
RemoveProducer(producer); RemoveProducer(producer);
RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes); RollbackProducer(producer, previousSsrcs, previousMuxId);
MS_THROW_ERROR("ssrc already exists in RTP listener [ssrc:%" PRIu32 "]", ssrc); MS_THROW_ERROR("ssrc already exists in RTP listener [ssrc:%" PRIu32 "]", ssrc);
} }
...@@ -159,7 +137,7 @@ namespace RTC ...@@ -159,7 +137,7 @@ namespace RTC
else else
{ {
RemoveProducer(producer); RemoveProducer(producer);
RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes); RollbackProducer(producer, previousSsrcs, previousMuxId);
MS_THROW_ERROR("ssrc already exists in RTP listener [ssrc:%" PRIu32 "]", ssrc); MS_THROW_ERROR("ssrc already exists in RTP listener [ssrc:%" PRIu32 "]", ssrc);
} }
...@@ -180,53 +158,12 @@ namespace RTC ...@@ -180,53 +158,12 @@ namespace RTC
else else
{ {
RemoveProducer(producer); RemoveProducer(producer);
RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes); RollbackProducer(producer, previousSsrcs, previousMuxId);
MS_THROW_ERROR("muxId already exists in RTP listener [muxId:'%s']", muxId.c_str()); MS_THROW_ERROR("muxId already exists in RTP listener [muxId:'%s']", muxId.c_str());
} }
} }
} }
// Add entries into ptTable just if:
// - Not all the encoding.ssrc are given, or
// - Not all the encoding.rtx.ssrc are given, or
// - Not all the encoding.fec.ssrc are given.
{
auto it = rtpParameters.encodings.begin();
for (; it != rtpParameters.encodings.end(); ++it)
{
auto& encoding = *it;
if (
(encoding.ssrc == 0u) || (encoding.hasRtx && (encoding.rtx.ssrc == 0u)) ||
(encoding.hasFec && (encoding.fec.ssrc == 0u)))
{
break;
}
}
if (it != rtpParameters.encodings.end())
{
for (auto& codec : rtpParameters.codecs)
{
uint8_t payloadType = codec.payloadType;
if (!this->HasPayloadType(payloadType, producer))
{
this->ptTable[payloadType] = producer;
}
else
{
RemoveProducer(producer);
RollbackProducer(producer, previousSsrcs, previousMuxId, previousPayloadTypes);
MS_THROW_ERROR(
"payloadType already exists in RTP listener [payloadType:%" PRIu8 "]", payloadType);
}
}
}
}
} }
void RtpListener::RemoveProducer(const RTC::Producer* producer) void RtpListener::RemoveProducer(const RTC::Producer* producer)
...@@ -251,14 +188,6 @@ namespace RTC ...@@ -251,14 +188,6 @@ namespace RTC
else else
++it; ++it;
} }
for (auto it = this->ptTable.begin(); it != this->ptTable.end();)
{
if (it->second == producer)
it = this->ptTable.erase(it);
else
++it;
}
} }
RTC::Producer* RtpListener::GetProducer(RTC::RtpPacket* packet) RTC::Producer* RtpListener::GetProducer(RTC::RtpPacket* packet)
...@@ -295,21 +224,6 @@ namespace RTC ...@@ -295,21 +224,6 @@ namespace RTC
// Otherwise lookup into the muxId table. // Otherwise lookup into the muxId table.
// TODO: do it. // TODO: do it.
// Otherwise lookup into the PT table.
{
auto it = this->ptTable.find(packet->GetPayloadType());
if (it != this->ptTable.end())
{
auto producer = it->second;
// Update SSRC table.
this->ssrcTable[packet->GetSsrc()] = producer;
return producer;
}
}
// TODO: We may emit "unhandledrtp" event. // TODO: We may emit "unhandledrtp" event.
return nullptr; return nullptr;
} }
...@@ -330,10 +244,7 @@ namespace RTC ...@@ -330,10 +244,7 @@ namespace RTC
} }
void RtpListener::RollbackProducer( void RtpListener::RollbackProducer(
RTC::Producer* producer, RTC::Producer* producer, std::vector<uint32_t>& previousSsrcs, std::string& previousMuxId)
std::vector<uint32_t>& previousSsrcs,
std::string& previousMuxId,
std::vector<uint8_t>& previousPayloadTypes)
{ {
MS_TRACE(); MS_TRACE();
...@@ -344,10 +255,5 @@ namespace RTC ...@@ -344,10 +255,5 @@ namespace RTC
if (!previousMuxId.empty()) if (!previousMuxId.empty())
this->muxIdTable[previousMuxId] = producer; this->muxIdTable[previousMuxId] = producer;
for (auto payloadType : previousPayloadTypes)
{
this->ptTable[payloadType] = producer;
}
} }
} // namespace RTC } // namespace RTC
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论