diff --git a/api/data_channel_interface.cc b/api/data_channel_interface.cc index d299cedf45..bddb9d1b0a 100644 --- a/api/data_channel_interface.cc +++ b/api/data_channel_interface.cc @@ -40,4 +40,8 @@ bool DataChannelInterface::negotiated() const { 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 99ea551c2d..a02bc5e0d4 100644 --- a/api/data_channel_interface.h +++ b/api/data_channel_interface.h @@ -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; }; diff --git a/pc/sctp_data_channel.cc b/pc/sctp_data_channel.cc index 0e4ef7de88..2ceef83936 100644 --- a/pc/sctp_data_channel.cc +++ b/pc/sctp_data_channel.cc @@ -31,7 +31,6 @@ namespace webrtc { namespace { static size_t kMaxQueuedReceivedDataBytes = 16 * 1024 * 1024; -static size_t kMaxQueuedSendDataBytes = 16 * 1024 * 1024; static std::atomic 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; }