Files
platform-external-webrtc/media/sctp/dcsctp_transport.h
Henrik Boström b951dc6f4c Allow specifying delayed task precision of dcsctp::Timer.
Context: The timer precision of PostDelayedTask() is about to be lowered
to include up to 17 ms leeway. In order not to break use cases that
require high precision timers, PostDelayedHighPrecisionTask() will
continue to have the same precision that PostDelayedTask() has today.
webrtc::TaskQueueBase has an enum (kLow, kHigh) to decide which
precision to use when calling PostDelayedTaskWithPrecision().

See go/postdelayedtask-precision-in-webrtc for motivation and a table of
delayed task use cases in WebRTC that are "high" or "low" precision.

Most timers in DCSCTP are believed to only be needing low precision (see
table), but the delayed_ack_timer_ of DataTracker[1] is an example of a
use case that is likely to break if the timer precision is lowered (if
ACK is sent too late, retransmissions may occur). So this is considered
a high precision use case.

This CL makes it possible to specify the precision of dcsctp::Timer.
In a follow-up CL we will update delayed_ack_timer_ to kHigh precision.

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/webrtc/net/dcsctp/rx/data_tracker.cc;l=340

Bug: webrtc:13604
Change-Id: I8eec5ce37044096978b5dd1985fbb00bc0d8fb7e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/249081
Reviewed-by: Victor Boivie <boivie@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35809}
2022-01-26 18:40:24 +00:00

113 lines
4.2 KiB
C++

/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MEDIA_SCTP_DCSCTP_TRANSPORT_H_
#define MEDIA_SCTP_DCSCTP_TRANSPORT_H_
#include <memory>
#include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/task_queue/task_queue_base.h"
#include "media/sctp/sctp_transport_internal.h"
#include "net/dcsctp/public/dcsctp_options.h"
#include "net/dcsctp/public/dcsctp_socket.h"
#include "net/dcsctp/public/types.h"
#include "net/dcsctp/timer/task_queue_timeout.h"
#include "p2p/base/packet_transport_internal.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/random.h"
#include "rtc_base/third_party/sigslot/sigslot.h"
#include "rtc_base/thread.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
class DcSctpTransport : public cricket::SctpTransportInternal,
public dcsctp::DcSctpSocketCallbacks,
public sigslot::has_slots<> {
public:
DcSctpTransport(rtc::Thread* network_thread,
rtc::PacketTransportInternal* transport,
Clock* clock);
~DcSctpTransport() override;
// cricket::SctpTransportInternal
void SetDtlsTransport(rtc::PacketTransportInternal* transport) override;
bool Start(int local_sctp_port,
int remote_sctp_port,
int max_message_size) override;
bool OpenStream(int sid) override;
bool ResetStream(int sid) override;
bool SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result = nullptr) override;
bool ReadyToSendData() override;
int max_message_size() const override;
absl::optional<int> max_outbound_streams() const override;
absl::optional<int> max_inbound_streams() const override;
void set_debug_name_for_testing(const char* debug_name) override;
private:
// dcsctp::DcSctpSocketCallbacks
dcsctp::SendPacketStatus SendPacketWithStatus(
rtc::ArrayView<const uint8_t> data) override;
std::unique_ptr<dcsctp::Timeout> CreateTimeout(
webrtc::TaskQueueBase::DelayPrecision precision) override;
dcsctp::TimeMs TimeMillis() override;
uint32_t GetRandomInt(uint32_t low, uint32_t high) override;
void OnTotalBufferedAmountLow() override;
void OnMessageReceived(dcsctp::DcSctpMessage message) override;
void OnError(dcsctp::ErrorKind error, absl::string_view message) override;
void OnAborted(dcsctp::ErrorKind error, absl::string_view message) override;
void OnConnected() override;
void OnClosed() override;
void OnConnectionRestarted() override;
void OnStreamsResetFailed(
rtc::ArrayView<const dcsctp::StreamID> outgoing_streams,
absl::string_view reason) override;
void OnStreamsResetPerformed(
rtc::ArrayView<const dcsctp::StreamID> outgoing_streams) override;
void OnIncomingStreamsReset(
rtc::ArrayView<const dcsctp::StreamID> incoming_streams) override;
// Transport callbacks
void ConnectTransportSignals();
void DisconnectTransportSignals();
void OnTransportWritableState(rtc::PacketTransportInternal* transport);
void OnTransportReadPacket(rtc::PacketTransportInternal* transport,
const char* data,
size_t length,
const int64_t& /* packet_time_us */,
int flags);
void OnTransportClosed(rtc::PacketTransportInternal* transport);
void MaybeConnectSocket();
rtc::Thread* network_thread_;
rtc::PacketTransportInternal* transport_;
Clock* clock_;
Random random_;
dcsctp::TaskQueueTimeoutFactory task_queue_timeout_factory_;
std::unique_ptr<dcsctp::DcSctpSocketInterface> socket_;
std::string debug_name_ = "DcSctpTransport";
rtc::CopyOnWriteBuffer receive_buffer_;
bool ready_to_send_data_ = false;
};
} // namespace webrtc
#endif // MEDIA_SCTP_DCSCTP_TRANSPORT_H_