datachannel: Add a MaxSendQueueSize() accessor in the API

Previous limits was only in a comment and users had no way to query it
from the API.

Bug: webrtc:13289
Change-Id: I6187dd9f9482bc3e457909c5e703ef1553d8ef15
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/235378
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35224}
This commit is contained in:
Florent Castelli
2021-10-18 11:46:21 +02:00
committed by WebRTC LUCI CQ
parent d91edc2244
commit a563a2a361
3 changed files with 13 additions and 4 deletions

View File

@ -40,4 +40,8 @@ bool DataChannelInterface::negotiated() const {
return false;
}
uint64_t DataChannelInterface::MaxSendQueueSize() {
return 16 * 1024 * 1024; // 16 MiB
}
} // namespace webrtc

View File

@ -174,6 +174,7 @@ class RTC_EXPORT DataChannelInterface : public rtc::RefCountInterface {
// Returns the number of bytes of application data (UTF-8 text and binary
// data) that have been queued using Send but have not yet been processed at
// the SCTP level. See comment above Send below.
// Values are less or equal to MaxSendQueueSize().
virtual uint64_t buffered_amount() const = 0;
// Begins the graceful data channel closing procedure. See:
@ -182,14 +183,18 @@ class RTC_EXPORT DataChannelInterface : public rtc::RefCountInterface {
// Sends `data` to the remote peer. If the data can't be sent at the SCTP
// level (due to congestion control), it's buffered at the data channel level,
// up to a maximum of 16MB. If Send is called while this buffer is full, the
// data channel will be closed abruptly.
// up to a maximum of MaxSendQueueSize(). If Send is called while this buffer
// is full, the data channel will be closed abruptly.
//
// So, it's important to use buffered_amount() and OnBufferedAmountChange to
// ensure the data channel is used efficiently but without filling this
// buffer.
virtual bool Send(const DataBuffer& buffer) = 0;
// Amount of bytes that can be queued for sending on the data channel.
// Those are bytes that have not yet been processed at the SCTP level.
static uint64_t MaxSendQueueSize();
protected:
~DataChannelInterface() override = default;
};

View File

@ -31,7 +31,6 @@ namespace webrtc {
namespace {
static size_t kMaxQueuedReceivedDataBytes = 16 * 1024 * 1024;
static size_t kMaxQueuedSendDataBytes = 16 * 1024 * 1024;
static std::atomic<int> g_unique_id{0};
@ -671,7 +670,8 @@ bool SctpDataChannel::SendDataMessage(const DataBuffer& buffer,
bool SctpDataChannel::QueueSendDataMessage(const DataBuffer& buffer) {
RTC_DCHECK_RUN_ON(signaling_thread_);
size_t start_buffered_amount = queued_send_data_.byte_count();
if (start_buffered_amount + buffer.size() > kMaxQueuedSendDataBytes) {
if (start_buffered_amount + buffer.size() >
DataChannelInterface::MaxSendQueueSize()) {
RTC_LOG(LS_ERROR) << "Can't buffer any more data for the data channel.";
return false;
}