Skip to content

Commit

Permalink
worker: Do not use references for async callbacks (#1274)
Browse files Browse the repository at this point in the history
* worker: Do not use references for async callbacks

If the callback is not executed in the same uv_loop iteration, the
access to such values upon executing the callback is undefined.

* Update CHANGELOG.md
  • Loading branch information
jmillan authored Dec 20, 2023
1 parent c2c4323 commit 8365c62
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog


### NEXT

* worker: Do not use references for async callbacks ([PR #1274](https://github.com/versatica/mediasoup/pull/1274)).


### 3.13.12

* worker: Disable `RtcLogger` usage if not enabled ([PR #1264](https://github.com/versatica/mediasoup/pull/1264)).
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/SenderBandwidthEstimator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace RTC
public:
void TransportConnected();
void TransportDisconnected();
void RtpPacketSent(SentInfo& sentInfo);
void RtpPacketSent(const SentInfo& sentInfo);
void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback);
void EstimateAvailableBitrate(CummulativeResult& cummulativeResult);
void UpdateRtt(float rtt);
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/TransportCongestionControlClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace RTC
void TransportDisconnected();
void InsertPacket(webrtc::RtpPacketSendInfo& packetInfo);
webrtc::PacedPacketInfo GetPacingInfo();
void PacketSent(webrtc::RtpPacketSendInfo& packetInfo, int64_t nowMs);
void PacketSent(const webrtc::RtpPacketSendInfo& packetInfo, int64_t nowMs);
void ReceiveEstimatedBitrate(uint32_t bitrate);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReportPacket* packet, float rtt, int64_t nowMs);
void ReceiveRtcpTransportFeedback(const RTC::RTCP::FeedbackRtpTransportPacket* feedback);
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/SenderBandwidthEstimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace RTC
this->cummulativeResult.Reset();
}

void SenderBandwidthEstimator::RtpPacketSent(SentInfo& sentInfo)
void SenderBandwidthEstimator::RtpPacketSent(const SentInfo& sentInfo)
{
MS_TRACE();

Expand Down
12 changes: 6 additions & 6 deletions worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2493,7 +2493,7 @@ namespace RTC
sentInfo.sendingAtMs = DepLibUV::GetTimeMs();

auto* cb = new onSendCallback(
[tccClientWeakPtr, &packetInfo, senderBweWeakPtr, &sentInfo](bool sent)
[tccClientWeakPtr, packetInfo, senderBweWeakPtr, sentInfo](bool sent)
{
if (sent)
{
Expand All @@ -2517,7 +2517,7 @@ namespace RTC
SendRtpPacket(consumer, packet, cb);
#else
const auto* cb = new onSendCallback(
[tccClientWeakPtr, &packetInfo](bool sent)
[tccClientWeakPtr, packetInfo](bool sent)
{
if (sent)
{
Expand Down Expand Up @@ -2582,7 +2582,7 @@ namespace RTC
sentInfo.sendingAtMs = DepLibUV::GetTimeMs();

auto* cb = new onSendCallback(
[tccClientWeakPtr, &packetInfo, senderBweWeakPtr, &sentInfo](bool sent)
[tccClientWeakPtr, packetInfo, senderBweWeakPtr, sentInfo](bool sent)
{
if (sent)
{
Expand All @@ -2606,7 +2606,7 @@ namespace RTC
SendRtpPacket(consumer, packet, cb);
#else
const auto* cb = new onSendCallback(
[tccClientWeakPtr, &packetInfo](bool sent)
[tccClientWeakPtr, packetInfo](bool sent)
{
if (sent)
{
Expand Down Expand Up @@ -2982,7 +2982,7 @@ namespace RTC
sentInfo.sendingAtMs = DepLibUV::GetTimeMs();

auto* cb = new onSendCallback(
[tccClientWeakPtr, &packetInfo, senderBweWeakPtr, &sentInfo](bool sent)
[tccClientWeakPtr, packetInfo, senderBweWeakPtr, sentInfo](bool sent)
{
if (sent)
{
Expand All @@ -3006,7 +3006,7 @@ namespace RTC
SendRtpPacket(nullptr, packet, cb);
#else
const auto* cb = new onSendCallback(
[tccClientWeakPtr, &packetInfo](bool sent)
[tccClientWeakPtr, packetInfo](bool sent)
{
if (sent)
{
Expand Down
3 changes: 2 additions & 1 deletion worker/src/RTC/TransportCongestionControlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ namespace RTC
return this->rtpTransportControllerSend->packet_sender()->GetPacingInfo();
}

void TransportCongestionControlClient::PacketSent(webrtc::RtpPacketSendInfo& packetInfo, int64_t nowMs)
void TransportCongestionControlClient::PacketSent(
const webrtc::RtpPacketSendInfo& packetInfo, int64_t nowMs)
{
MS_TRACE();

Expand Down

0 comments on commit 8365c62

Please sign in to comment.