Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make transport-cc feedback work similarly to libwebrtc #1088

Merged
merged 34 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cfe202b
fix tcc-feedback
penguinol May 26, 2023
08d14a9
update format
penguinol May 26, 2023
601736f
Update TransportCongestionControlServer.cpp
penguinol May 26, 2023
86676f6
Update TransportCongestionControlServer.hpp
penguinol May 26, 2023
e7808c1
Update worker/src/RTC/TransportCongestionControlServer.cpp
penguinol Jun 25, 2023
186d72f
add comment
penguinol Jul 11, 2023
ecf03af
Merge branch 'fix_tcc_feedback' of https://github.com/penguinol/media…
penguinol Jul 11, 2023
1e3e9c0
Merge branch 'v3' into fix_tcc_feedback
ibc Jan 1, 2024
e3c935e
Update worker/src/RTC/TransportCongestionControlServer.cpp
penguinol Jan 2, 2024
d0c4c02
prepare for test
penguinol Jan 8, 2024
56ab0f4
Merge branch 'fix_tcc_feedback' of https://github.com/penguinol/media…
penguinol Jan 8, 2024
9e69ee0
fix tcc feedback
penguinol Jan 18, 2024
ba0b2b8
cosmetic
penguinol Jan 18, 2024
66d435a
Update TestFeedbackRtpTransport.cpp
penguinol Jan 18, 2024
3ac5a05
optimize
penguinol Jan 23, 2024
8bf5758
add test case
penguinol Jan 24, 2024
3d3a054
try fix compile error
penguinol Jan 24, 2024
9ef5cf0
fix test case
penguinol Jan 24, 2024
fd44165
Update worker/src/RTC/RTCP/FeedbackRtpTransport.cpp
penguinol Jan 30, 2024
381b889
Update worker/src/RTC/TransportCongestionControlServer.cpp
penguinol Jan 30, 2024
882e6d9
Update worker/src/RTC/TransportCongestionControlServer.cpp
penguinol Jan 30, 2024
b6a9729
Apply suggestions from code review
penguinol Jan 30, 2024
096e48f
Update TestFeedbackRtpTransport.cpp
penguinol Jan 30, 2024
e027f54
Merge branch 'versatica:v3' into fix_tcc_feedback
penguinol Jan 31, 2024
2bc46be
add baseSet and other optimize
penguinol Jan 31, 2024
5e25d10
Merge branch 'fix_tcc_feedback' of https://github.com/penguinol/media…
penguinol Jan 31, 2024
e9aeb16
Update CHANGELOG.md
penguinol Jan 31, 2024
ea3b19c
Apply suggestions from code review
penguinol Jan 31, 2024
4bd33f3
Apply suggestions from code review
penguinol Jan 31, 2024
a885f48
Update CHANGELOG.md
penguinol Feb 1, 2024
4856fa7
Update TransportCongestionControlServer.cpp
penguinol Feb 1, 2024
13871d2
Merge branch 'fix_tcc_feedback' of https://github.com/penguinol/media…
penguinol Feb 1, 2024
1137852
Update TransportCongestionControlServer.cpp
penguinol Feb 1, 2024
4b290d9
Merge branch 'v3' into fix_tcc_feedback
ibc Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions worker/include/RTC/TransportCongestionControlServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "RTC/RTCP/FeedbackRtpTransport.hpp"
#include "RTC/RTCP/Packet.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/SeqManager.hpp"
#include "handles/Timer.hpp"
#include <libwebrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h>
#include <deque>
Expand Down Expand Up @@ -57,6 +58,8 @@ namespace RTC

private:
void SendTransportCcFeedback();
void MayDropOldPacketArrivalTimes(uint16_t seqNum, uint64_t nowMs);
void FillAndSendTransportCcFeedback();
void MaySendLimitationRembFeedback();
void UpdatePacketLoss(double packetLoss);

Expand Down Expand Up @@ -89,6 +92,9 @@ namespace RTC
uint8_t unlimitedRembCounter{ 0u };
std::deque<double> packetLossHistory;
double packetLoss{ 0 };
bool receivedTransportWideSeqNumber{ false };
penguinol marked this conversation as resolved.
Show resolved Hide resolved
uint16_t transportCcFeedbackStartSeqNum{ 0u };
penguinol marked this conversation as resolved.
Show resolved Hide resolved
std::map<uint16_t, uint64_t, RTC::SeqManager<uint16_t>::SeqLowerThan> mapPacketArrivalTimes;
};
} // namespace RTC

Expand Down
146 changes: 90 additions & 56 deletions worker/src/RTC/TransportCongestionControlServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace RTC

static constexpr uint64_t TransportCcFeedbackSendInterval{ 100u }; // In ms.
static constexpr uint64_t LimitationRembInterval{ 1500u }; // In ms.
static constexpr uint64_t PacketArrivalTimestampWindow{ 500u }; // In ms.
static constexpr uint8_t UnlimitedRembNumPackets{ 4u };
static constexpr size_t PacketLossHistogramLength{ 24 };

Expand Down Expand Up @@ -124,60 +125,25 @@ namespace RTC
break;
}

// Update the RTCP media SSRC of the ongoing Transport-CC Feedback packet.
this->transportCcFeedbackSenderSsrc = 0u;
this->transportCcFeedbackMediaSsrc = packet->GetSsrc();

this->transportCcFeedbackPacket->SetSenderSsrc(0u);
this->transportCcFeedbackPacket->SetMediaSsrc(this->transportCcFeedbackMediaSsrc);

// Provide the feedback packet with the RTP packet info. If it fails,
// send current feedback and add the packet info to a new one.
auto result =
this->transportCcFeedbackPacket->AddPacket(wideSeqNumber, nowMs, this->maxRtcpPacketLen);

switch (result)
if (
penguinol marked this conversation as resolved.
Show resolved Hide resolved
!this->receivedTransportWideSeqNumber ||
RTC::SeqManager<uint16_t>::IsSeqLowerThan(
wideSeqNumber, this->transportCcFeedbackStartSeqNum))
{
case RTC::RTCP::FeedbackRtpTransportPacket::AddPacketResult::SUCCESS:
{
// If the feedback packet is full, send it now.
if (this->transportCcFeedbackPacket->IsFull())
{
MS_DEBUG_DEV("transport-cc feedback packet is full, sending feedback now");

SendTransportCcFeedback();
}

break;
}

case RTC::RTCP::FeedbackRtpTransportPacket::AddPacketResult::MAX_SIZE_EXCEEDED:
{
// Send ongoing feedback packet and add the new packet info to the
// regenerated one.
SendTransportCcFeedback();

this->transportCcFeedbackPacket->AddPacket(wideSeqNumber, nowMs, this->maxRtcpPacketLen);

break;
}

case RTC::RTCP::FeedbackRtpTransportPacket::AddPacketResult::FATAL:
{
// Create a new feedback packet.
this->transportCcFeedbackPacket.reset(new RTC::RTCP::FeedbackRtpTransportPacket(
this->transportCcFeedbackSenderSsrc, this->transportCcFeedbackMediaSsrc));

// Use current packet count.
// NOTE: Do not increment it since the previous ongoing feedback
// packet was not sent.
this->transportCcFeedbackPacket->SetFeedbackPacketCount(
this->transportCcFeedbackPacketCount);
this->transportCcFeedbackStartSeqNum = wideSeqNumber;
}
this->receivedTransportWideSeqNumber = true;
penguinol marked this conversation as resolved.
Show resolved Hide resolved

break;
}
auto result = this->mapPacketArrivalTimes.emplace(wideSeqNumber, nowMs);
if (result.second)
penguinol marked this conversation as resolved.
Show resolved Hide resolved
{
MayDropOldPacketArrivalTimes(wideSeqNumber, nowMs);
}

// Update the RTCP media SSRC of the ongoing Transport-CC Feedback packet.
this->transportCcFeedbackSenderSsrc = 0u;
this->transportCcFeedbackMediaSsrc = packet->GetSsrc();

MaySendLimitationRembFeedback();

break;
Expand All @@ -204,6 +170,61 @@ namespace RTC
}
}

inline void TransportCongestionControlServer::FillAndSendTransportCcFeedback()
{
MS_TRACE();

for (auto it = this->mapPacketArrivalTimes.find(this->transportCcFeedbackStartSeqNum);
it != this->mapPacketArrivalTimes.end();
++it)
{
auto result =
this->transportCcFeedbackPacket->AddPacket(it->first, it->second, this->maxRtcpPacketLen);

switch (result)
{
case RTC::RTCP::FeedbackRtpTransportPacket::AddPacketResult::SUCCESS:
{
// If the feedback packet is full, send it now.
if (this->transportCcFeedbackPacket->IsFull())
{
MS_DEBUG_DEV("transport-cc feedback packet is full, sending feedback now");

SendTransportCcFeedback();
}

break;
}

case RTC::RTCP::FeedbackRtpTransportPacket::AddPacketResult::MAX_SIZE_EXCEEDED:
{
// This should not happen
MS_DEBUG_DEV("transport-cc feedback packet is exceeded!");
// Create a new feedback packet.
this->transportCcFeedbackPacket.reset(new RTC::RTCP::FeedbackRtpTransportPacket(
this->transportCcFeedbackSenderSsrc, this->transportCcFeedbackMediaSsrc));
}

case RTC::RTCP::FeedbackRtpTransportPacket::AddPacketResult::FATAL:
{
// Create a new feedback packet.
this->transportCcFeedbackPacket.reset(new RTC::RTCP::FeedbackRtpTransportPacket(
this->transportCcFeedbackSenderSsrc, this->transportCcFeedbackMediaSsrc));

// Use current packet count.
// NOTE: Do not increment it since the previous ongoing feedback
// packet was not sent.
this->transportCcFeedbackPacket->SetFeedbackPacketCount(
this->transportCcFeedbackPacketCount);

break;
}
}
}

SendTransportCcFeedback();
}

void TransportCongestionControlServer::SetMaxIncomingBitrate(uint32_t bitrate)
{
MS_TRACE();
Expand Down Expand Up @@ -233,7 +254,6 @@ namespace RTC
}

auto latestWideSeqNumber = this->transportCcFeedbackPacket->GetLatestSequenceNumber();
auto latestTimestamp = this->transportCcFeedbackPacket->GetLatestTimestamp();

// Notify the listener.
this->listener->OnTransportCongestionControlServerSendRtcpPacket(
Expand Down Expand Up @@ -262,12 +282,26 @@ namespace RTC

// Increment packet count.
this->transportCcFeedbackPacket->SetFeedbackPacketCount(++this->transportCcFeedbackPacketCount);
this->transportCcFeedbackStartSeqNum = latestWideSeqNumber;
}

inline void TransportCongestionControlServer::MayDropOldPacketArrivalTimes(
uint16_t seqNum, uint64_t nowMs)
{
MS_TRACE();

// Pass the latest packet info (if any) as pre base for the new feedback packet.
if (latestTimestamp > 0u)
if (nowMs >= PacketArrivalTimestampWindow)
penguinol marked this conversation as resolved.
Show resolved Hide resolved
{
this->transportCcFeedbackPacket->AddPacket(
latestWideSeqNumber, latestTimestamp, this->maxRtcpPacketLen);
auto expiryTimestamp = nowMs - PacketArrivalTimestampWindow;
auto it = this->mapPacketArrivalTimes.begin();

while (it != this->mapPacketArrivalTimes.end() &&
it->first != this->transportCcFeedbackStartSeqNum &&
RTC::SeqManager<uint16_t>::IsSeqLowerThan(it->first, seqNum) &&
it->second <= expiryTimestamp)
{
it = this->mapPacketArrivalTimes.erase(it);
}
}
}

Expand Down Expand Up @@ -389,7 +423,7 @@ namespace RTC

if (timer == this->transportCcFeedbackSendPeriodicTimer)
{
SendTransportCcFeedback();
FillAndSendTransportCcFeedback();
}
}
} // namespace RTC