Unverified 提交 dcb9c1b4 authored 作者: José Luis Millán's avatar José Luis Millán 提交者: GitHub

sctp fixes (#479)

- DataConsumer: make 'setBufferedAmountLowThreshold' trigger 'bufferedamountlow'
    if the buffered amount data is less or same than the given threshold.
- SctpAssociation: Increase buffered amount data before sending it in
  order to avoid inconsistencies if 'onSendSctpData' fires while 'usrsctp_senv'
  is being executed. Be conservative.
上级 dee0d2f0
...@@ -97,6 +97,7 @@ namespace RTC ...@@ -97,6 +97,7 @@ namespace RTC
size_t bytesSent{ 0u }; size_t bytesSent{ 0u };
uint32_t bufferedAmount{ 0u }; uint32_t bufferedAmount{ 0u };
uint32_t bufferedAmountLowThreshold{ 0u }; uint32_t bufferedAmountLowThreshold{ 0u };
bool forceTriggerBufferedAmountLow{ false };
}; };
} // namespace RTC } // namespace RTC
......
...@@ -164,6 +164,24 @@ namespace RTC ...@@ -164,6 +164,24 @@ namespace RTC
request->Accept(); request->Accept();
// There is less or same buffered data than the given threshold.
// Trigger 'bufferedamountlow' now.
if (this->bufferedAmount <= this->bufferedAmountLowThreshold)
{
// Notify the Node DataConsumer.
json data = json::object();
data["bufferedAmount"] = this->bufferedAmount;
Channel::Notifier::Emit(this->id, "bufferedamountlow", data);
}
// Force the trigger of 'bufferedamountlow' once there is less or same
// buffered data than the given threshold.
else
{
this->forceTriggerBufferedAmountLow = true;
}
break; break;
} }
...@@ -269,11 +287,13 @@ namespace RTC ...@@ -269,11 +287,13 @@ namespace RTC
// clang-format off // clang-format off
if ( if (
previousBufferedAmount > this->bufferedAmountLowThreshold && (this->forceTriggerBufferedAmountLow || previousBufferedAmount > this->bufferedAmountLowThreshold) &&
this->bufferedAmount <= this->bufferedAmountLowThreshold this->bufferedAmount <= this->bufferedAmountLowThreshold
) )
// clang-format on // clang-format on
{ {
this->forceTriggerBufferedAmountLow = false;
// Notify the Node DataConsumer. // Notify the Node DataConsumer.
json data = json::object(); json data = json::object();
......
...@@ -427,19 +427,17 @@ namespace RTC ...@@ -427,19 +427,17 @@ namespace RTC
this->sctpBufferedAmount += len; this->sctpBufferedAmount += len;
// Notify the listener about the buffered amount increase regardless
// usrsctp_sendv result.
// In case of failure the correct value will be later provided by usrsctp
// via onSendSctpData.
this->listener->OnSctpAssociationBufferedAmount(this, this->sctpBufferedAmount);
int ret = usrsctp_sendv( int ret = usrsctp_sendv(
this->socket, msg, len, nullptr, 0, &spa, static_cast<socklen_t>(sizeof(spa)), SCTP_SENDV_SPA, 0); this->socket, msg, len, nullptr, 0, &spa, static_cast<socklen_t>(sizeof(spa)), SCTP_SENDV_SPA, 0);
if (ret > 0)
{
// NOTE: 'usrsctp_sendv' returns the number of bytes sent.
this->listener->OnSctpAssociationBufferedAmount(this, this->sctpBufferedAmount);
}
if (ret < 0) if (ret < 0)
{ {
this->sctpBufferedAmount -= ret;
MS_WARN_TAG( MS_WARN_TAG(
sctp, sctp,
"error sending SCTP message [sid:%" PRIu16 ", ppid:%" PRIu32 ", message size:%zu]: %s", "error sending SCTP message [sid:%" PRIu16 ", ppid:%" PRIu32 ", message size:%zu]: %s",
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论