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

Fix GetRtcp in PipeConsumer (avoid assert)

上级 feb7fd40
......@@ -12,6 +12,7 @@
#include "RTC/RtpHeaderExtensionIds.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream.hpp"
#include "RTC/RtpStreamSend.hpp"
#include <string>
#include <unordered_set>
#include <vector>
......@@ -66,8 +67,10 @@ namespace RTC
virtual uint32_t UseAvailableBitrate(uint32_t bitrate);
virtual uint32_t IncreaseLayer(uint32_t bitrate);
virtual void ApplyLayers();
virtual void SendRtpPacket(RTC::RtpPacket* packet) = 0;
virtual void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) = 0;
virtual void SendRtpPacket(RTC::RtpPacket* packet) = 0;
virtual std::vector<RTC::RtpStreamSend*> GetRtpStreams() = 0;
virtual void GetRtcp(
RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now) = 0;
virtual void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) = 0;
virtual void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) = 0;
virtual void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType) = 0;
......
......@@ -21,7 +21,8 @@ namespace RTC
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override;
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType) override;
......@@ -44,7 +45,16 @@ namespace RTC
private:
// Allocated by this.
std::unordered_map<uint32_t, RTC::RtpStreamSend*> mapMappedSsrcRtpStream;
// Others.
std::vector<RTC::RtpStreamSend*> rtpStreams;
};
// Inline methods.
inline std::vector<RTC::RtpStreamSend*> PipeConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC
#endif
......@@ -23,7 +23,8 @@ namespace RTC
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now) override;
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType) override;
......@@ -61,6 +62,11 @@ namespace RTC
{
return (RTC::Consumer::IsActive() && this->producerRtpStream);
}
inline std::vector<RTC::RtpStreamSend*> SimpleConsumer::GetRtpStreams()
{
return std::vector<RTC::RtpStreamSend*>{ this->rtpStream };
}
} // namespace RTC
#endif
......@@ -29,7 +29,8 @@ namespace RTC
uint32_t IncreaseLayer(uint32_t bitrate) override;
void ApplyLayers() override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override;
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType) override;
......@@ -99,6 +100,11 @@ namespace RTC
);
// clang-format on
}
inline std::vector<RTC::RtpStreamSend*> SimulcastConsumer::GetRtpStreams()
{
return std::vector<RTC::RtpStreamSend*>{ this->rtpStream };
}
} // namespace RTC
#endif
......@@ -128,30 +128,31 @@ namespace RTC
}
}
void PipeConsumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
void PipeConsumer::GetRtcp(
RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now)
{
MS_TRACE();
MS_ASSERT(
std::find(this->rtpStreams.begin(), this->rtpStreams.end(), rtpStream) != this->rtpStreams.end(),
"RTP stream does exist");
if (static_cast<float>((now - this->lastRtcpSentTime) * 1.15) < this->maxRtcpInterval)
return;
for (auto& kv : this->mapMappedSsrcRtpStream)
{
auto& rtpStream = kv.second;
auto* report = rtpStream->GetRtcpSenderReport(now);
auto* report = rtpStream->GetRtcpSenderReport(now);
if (!report)
continue;
if (!report)
return;
packet->AddSenderReport(report);
packet->AddSenderReport(report);
// Build SDES chunk for this sender.
auto* sdesChunk = rtpStream->GetRtcpSdesChunk();
// Build SDES chunk for this sender.
auto* sdesChunk = rtpStream->GetRtcpSdesChunk();
packet->AddSdesChunk(sdesChunk);
packet->AddSdesChunk(sdesChunk);
this->lastRtcpSentTime = now;
}
this->lastRtcpSentTime = now;
}
void PipeConsumer::NeedWorstRemoteFractionLost(uint32_t /*mappedSsrc*/, uint8_t& worstRemoteFractionLost)
......@@ -363,6 +364,7 @@ namespace RTC
rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
this->mapMappedSsrcRtpStream[encoding.ssrc] = rtpStream;
this->rtpStreams.push_back(rtpStream);
}
}
......
......@@ -233,10 +233,13 @@ namespace RTC
packet->SetTimestamp(origTimestamp);
}
void SimpleConsumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
void SimpleConsumer::GetRtcp(
RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now)
{
MS_TRACE();
MS_ASSERT(rtpStream == this->rtpStream, "RTP stream does not match");
if (static_cast<float>((now - this->lastRtcpSentTime) * 1.15) < this->maxRtcpInterval)
return;
......
......@@ -587,10 +587,12 @@ namespace RTC
if (this->keyFrameSupported && !packet->IsKeyFrame())
return;
MS_ERROR("calling UpdateCurrentLayer [currentSpatialLayer:%" PRIu16 ", targetSpatialLayer:%" PRIu16 ", isKeyFrame:%s]",
this->currentSpatialLayer,
this->targetSpatialLayer,
packet->IsKeyFrame() ? "true" : "false");
MS_ERROR(
"calling UpdateCurrentLayer [currentSpatialLayer:%" PRIu16 ", targetSpatialLayer:%" PRIu16
", isKeyFrame:%s]",
this->currentSpatialLayer,
this->targetSpatialLayer,
packet->IsKeyFrame() ? "true" : "false");
// Update current spatial and temporal layers.
UpdateCurrentLayers();
......@@ -717,10 +719,13 @@ namespace RTC
packet->RestorePayload();
}
void SimulcastConsumer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
void SimulcastConsumer::GetRtcp(
RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now)
{
MS_TRACE();
MS_ASSERT(rtpStream == this->rtpStream, "RTP stream does not match");
if (static_cast<float>((now - this->lastRtcpSentTime) * 1.15) < this->maxRtcpInterval)
return;
......@@ -952,7 +957,7 @@ namespace RTC
if (this->kind != RTC::Media::Kind::VIDEO)
return;
auto* producerTargetRtpStream = GetProducerTargetRtpStream();
auto* producerTargetRtpStream = GetProducerTargetRtpStream();
if (!producerTargetRtpStream)
return;
......
......@@ -760,29 +760,31 @@ namespace RTC
{
MS_TRACE();
// - Create a CompoundPacket.
// - Request every Consumer and Producer their RTCP data.
// - Send the CompoundPacket.
std::unique_ptr<RTC::RTCP::CompoundPacket> packet(new RTC::RTCP::CompoundPacket());
std::unique_ptr<RTC::RTCP::CompoundPacket> packet{ nullptr };
for (auto& kv : this->mapConsumers)
{
auto* consumer = kv.second;
consumer->GetRtcp(packet.get(), now);
// Send the RTCP compound packet if there is a sender report.
if (packet->HasSenderReport())
for (auto& rtpStream : consumer->GetRtpStreams())
{
packet->Serialize(RTC::RTCP::Buffer);
SendRtcpCompoundPacket(packet.get());
// Reset the Compound packet.
packet.reset(new RTC::RTCP::CompoundPacket());
consumer->GetRtcp(packet.get(), rtpStream, now);
// Send the RTCP compound packet if there is a sender report.
if (packet->HasSenderReport())
{
packet->Serialize(RTC::RTCP::Buffer);
SendRtcpCompoundPacket(packet.get());
}
}
}
// Reset the Compound packet.
packet.reset(new RTC::RTCP::CompoundPacket());
for (auto& kv : this->mapProducers)
{
auto* producer = kv.second;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论