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}
diff --git a/api/data_channel_interface.cc b/api/data_channel_interface.cc
index d299ced..bddb9d1 100644
--- a/api/data_channel_interface.cc
+++ b/api/data_channel_interface.cc
@@ -40,4 +40,8 @@
return false;
}
+uint64_t DataChannelInterface::MaxSendQueueSize() {
+ return 16 * 1024 * 1024; // 16 MiB
+}
+
} // namespace webrtc
diff --git a/api/data_channel_interface.h b/api/data_channel_interface.h
index 99ea551..a02bc5e 100644
--- a/api/data_channel_interface.h
+++ b/api/data_channel_interface.h
@@ -174,6 +174,7 @@
// 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 @@
// 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;
};
diff --git a/pc/sctp_data_channel.cc b/pc/sctp_data_channel.cc
index 0e4ef7d..2ceef83 100644
--- a/pc/sctp_data_channel.cc
+++ b/pc/sctp_data_channel.cc
@@ -31,7 +31,6 @@
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::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;
}