datachannel: Merge SendDataParams and DMT types with webrtc equivalent

cricket::SendDataParams is replaced by webrtc::SendDataParams.
cricket::DataMessageType is replaced by webrtc::DataMessageType.
The sid member from cricket::SendDataParams is now passed as an argument
to functions that used one when necessary.

Bug: webrtc:7484
Change-Id: Ia4a89c9651fb54ab9a084a6098d49130b6319e1b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/217761
Commit-Queue: Florent Castelli <orphis@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33966}
This commit is contained in:
Florent Castelli
2021-05-10 11:29:56 +02:00
committed by WebRTC LUCI CQ
parent 8ba623d63a
commit d95b149141
20 changed files with 142 additions and 215 deletions

View File

@ -81,6 +81,7 @@ rtc_library("rtc_media_base") {
"../api/crypto:frame_decryptor_interface", "../api/crypto:frame_decryptor_interface",
"../api/crypto:frame_encryptor_interface", "../api/crypto:frame_encryptor_interface",
"../api/crypto:options", "../api/crypto:options",
"../api/transport:datagram_transport_interface",
"../api/transport:stun_types", "../api/transport:stun_types",
"../api/transport:webrtc_key_value_config", "../api/transport:webrtc_key_value_config",
"../api/transport/rtp:rtp_source", "../api/transport/rtp:rtp_source",
@ -381,6 +382,7 @@ rtc_library("rtc_media_engine_defaults") {
rtc_source_set("rtc_data_sctp_transport_internal") { rtc_source_set("rtc_data_sctp_transport_internal") {
sources = [ "sctp/sctp_transport_internal.h" ] sources = [ "sctp/sctp_transport_internal.h" ]
deps = [ deps = [
"../api/transport:datagram_transport_interface",
"../media:rtc_media_base", "../media:rtc_media_base",
"../p2p:rtc_p2p", "../p2p:rtc_p2p",
"../rtc_base:rtc_base_approved", "../rtc_base:rtc_base_approved",

View File

@ -26,6 +26,7 @@
#include "api/media_stream_interface.h" #include "api/media_stream_interface.h"
#include "api/rtc_error.h" #include "api/rtc_error.h"
#include "api/rtp_parameters.h" #include "api/rtp_parameters.h"
#include "api/transport/data_channel_transport_interface.h"
#include "api/transport/rtp/rtp_source.h" #include "api/transport/rtp/rtp_source.h"
#include "api/video/video_content_type.h" #include "api/video/video_content_type.h"
#include "api/video/video_sink_interface.h" #include "api/video/video_sink_interface.h"
@ -892,15 +893,6 @@ class VideoMediaChannel : public MediaChannel, public Delayable {
virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0; virtual std::vector<webrtc::RtpSource> GetSources(uint32_t ssrc) const = 0;
}; };
enum DataMessageType {
// Chrome-Internal use only. See SctpDataMediaChannel for the actual PPID
// values.
DMT_NONE = 0,
DMT_CONTROL = 1,
DMT_BINARY = 2,
DMT_TEXT = 3,
};
// Info about data received in DataMediaChannel. For use in // Info about data received in DataMediaChannel. For use in
// DataMediaChannel::SignalDataReceived and in all of the signals that // DataMediaChannel::SignalDataReceived and in all of the signals that
// signal fires, on up the chain. // signal fires, on up the chain.
@ -909,28 +901,11 @@ struct ReceiveDataParams {
// SCTP data channels use SIDs. // SCTP data channels use SIDs.
int sid = 0; int sid = 0;
// The type of message (binary, text, or control). // The type of message (binary, text, or control).
DataMessageType type = DMT_TEXT; webrtc::DataMessageType type = webrtc::DataMessageType::kText;
// A per-stream value incremented per packet in the stream. // A per-stream value incremented per packet in the stream.
int seq_num = 0; int seq_num = 0;
}; };
struct SendDataParams {
// The in-packet stream indentifier.
int sid = 0;
// The type of message (binary, text, or control).
DataMessageType type = DMT_TEXT;
// For SCTP, whether to send messages flagged as ordered or not.
// If false, messages can be received out of order.
bool ordered = false;
// Provide partial reliability by resending up to this many times. Either
// count or millis is supported, not both at the same time.
absl::optional<int> max_rtx_count;
// Provide partial reliability by resending for up to this many milliseconds.
// Either count or millis is supported, not both at the same time.
absl::optional<int> max_rtx_ms;
};
enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK }; enum SendDataResult { SDR_SUCCESS, SDR_ERROR, SDR_BLOCK };
} // namespace cricket } // namespace cricket

View File

@ -32,7 +32,6 @@ namespace webrtc {
namespace { namespace {
enum class WebrtcPPID : dcsctp::PPID::UnderlyingType { enum class WebrtcPPID : dcsctp::PPID::UnderlyingType {
kNone = 0, // No protocol is specified.
// https://www.rfc-editor.org/rfc/rfc8832.html#section-8.1 // https://www.rfc-editor.org/rfc/rfc8832.html#section-8.1
kDCEP = 50, kDCEP = 50,
// https://www.rfc-editor.org/rfc/rfc8831.html#section-8 // https://www.rfc-editor.org/rfc/rfc8831.html#section-8
@ -44,34 +43,29 @@ enum class WebrtcPPID : dcsctp::PPID::UnderlyingType {
kBinaryEmpty = 57, kBinaryEmpty = 57,
}; };
WebrtcPPID ToPPID(cricket::DataMessageType message_type, size_t size) { WebrtcPPID ToPPID(DataMessageType message_type, size_t size) {
switch (message_type) { switch (message_type) {
case cricket::DMT_CONTROL: case webrtc::DataMessageType::kControl:
return WebrtcPPID::kDCEP; return WebrtcPPID::kDCEP;
case cricket::DMT_TEXT: case webrtc::DataMessageType::kText:
return size > 0 ? WebrtcPPID::kString : WebrtcPPID::kStringEmpty; return size > 0 ? WebrtcPPID::kString : WebrtcPPID::kStringEmpty;
case cricket::DMT_BINARY: case webrtc::DataMessageType::kBinary:
return size > 0 ? WebrtcPPID::kBinary : WebrtcPPID::kBinaryEmpty; return size > 0 ? WebrtcPPID::kBinary : WebrtcPPID::kBinaryEmpty;
default:
RTC_NOTREACHED();
} }
return WebrtcPPID::kNone;
} }
absl::optional<cricket::DataMessageType> ToDataMessageType(dcsctp::PPID ppid) { absl::optional<DataMessageType> ToDataMessageType(dcsctp::PPID ppid) {
switch (static_cast<WebrtcPPID>(ppid.value())) { switch (static_cast<WebrtcPPID>(ppid.value())) {
case WebrtcPPID::kNone:
return cricket::DMT_NONE;
case WebrtcPPID::kDCEP: case WebrtcPPID::kDCEP:
return cricket::DMT_CONTROL; return webrtc::DataMessageType::kControl;
case WebrtcPPID::kString: case WebrtcPPID::kString:
case WebrtcPPID::kStringPartial: case WebrtcPPID::kStringPartial:
case WebrtcPPID::kStringEmpty: case WebrtcPPID::kStringEmpty:
return cricket::DMT_TEXT; return webrtc::DataMessageType::kText;
case WebrtcPPID::kBinary: case WebrtcPPID::kBinary:
case WebrtcPPID::kBinaryPartial: case WebrtcPPID::kBinaryPartial:
case WebrtcPPID::kBinaryEmpty: case WebrtcPPID::kBinaryEmpty:
return cricket::DMT_BINARY; return webrtc::DataMessageType::kBinary;
} }
return absl::nullopt; return absl::nullopt;
} }
@ -177,13 +171,14 @@ bool DcSctpTransport::ResetStream(int sid) {
return true; return true;
} }
bool DcSctpTransport::SendData(const cricket::SendDataParams& params, bool DcSctpTransport::SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) { cricket::SendDataResult* result) {
RTC_DCHECK_RUN_ON(network_thread_); RTC_DCHECK_RUN_ON(network_thread_);
RTC_LOG(LS_VERBOSE) << debug_name_ << "->SendData(sid=" << params.sid RTC_LOG(LS_VERBOSE) << debug_name_ << "->SendData(sid=" << sid
<< ", type=" << params.type << ", type=" << static_cast<int>(params.type)
<< ", length=" << payload.size() << ")."; << ", length=" << payload.size() << ").";
if (!socket_) { if (!socket_) {
@ -216,7 +211,7 @@ bool DcSctpTransport::SendData(const cricket::SendDataParams& params,
} }
dcsctp::DcSctpMessage message( dcsctp::DcSctpMessage message(
dcsctp::StreamID(static_cast<uint16_t>(params.sid)), dcsctp::StreamID(static_cast<uint16_t>(sid)),
dcsctp::PPID(static_cast<uint16_t>(ToPPID(params.type, payload.size()))), dcsctp::PPID(static_cast<uint16_t>(ToPPID(params.type, payload.size()))),
std::move(message_payload)); std::move(message_payload));

View File

@ -47,7 +47,8 @@ class DcSctpTransport : public cricket::SctpTransportInternal,
int max_message_size) override; int max_message_size) override;
bool OpenStream(int sid) override; bool OpenStream(int sid) override;
bool ResetStream(int sid) override; bool ResetStream(int sid) override;
bool SendData(const cricket::SendDataParams& params, bool SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result = nullptr) override; cricket::SendDataResult* result = nullptr) override;
bool ReadyToSendData() override; bool ReadyToSendData() override;

View File

@ -18,6 +18,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "api/transport/data_channel_transport_interface.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/thread.h" #include "rtc_base/thread.h"
// For SendDataParams/ReceiveDataParams. // For SendDataParams/ReceiveDataParams.
@ -101,7 +102,8 @@ class SctpTransportInternal {
// usrsctp that will then post the network interface). // usrsctp that will then post the network interface).
// Returns true iff successful data somewhere on the send-queue/network. // Returns true iff successful data somewhere on the send-queue/network.
// Uses |params.ssrc| as the SCTP sid. // Uses |params.ssrc| as the SCTP sid.
virtual bool SendData(const SendDataParams& params, virtual bool SendData(int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result = nullptr) = 0; SendDataResult* result = nullptr) = 0;

View File

@ -129,46 +129,37 @@ void DebugSctpPrintf(const char* format, ...) {
} }
// Get the PPID to use for the terminating fragment of this type. // Get the PPID to use for the terminating fragment of this type.
uint32_t GetPpid(cricket::DataMessageType type, size_t size) { uint32_t GetPpid(webrtc::DataMessageType type, size_t size) {
switch (type) { switch (type) {
default: case webrtc::DataMessageType::kControl:
case cricket::DMT_NONE:
return PPID_NONE;
case cricket::DMT_CONTROL:
return PPID_CONTROL; return PPID_CONTROL;
case cricket::DMT_BINARY: case webrtc::DataMessageType::kBinary:
return size > 0 ? PPID_BINARY_LAST : PPID_BINARY_EMPTY; return size > 0 ? PPID_BINARY_LAST : PPID_BINARY_EMPTY;
case cricket::DMT_TEXT: case webrtc::DataMessageType::kText:
return size > 0 ? PPID_TEXT_LAST : PPID_TEXT_EMPTY; return size > 0 ? PPID_TEXT_LAST : PPID_TEXT_EMPTY;
} }
} }
bool GetDataMediaType(uint32_t ppid, cricket::DataMessageType* dest) { bool GetDataMediaType(uint32_t ppid, webrtc::DataMessageType* dest) {
RTC_DCHECK(dest != NULL); RTC_DCHECK(dest != NULL);
switch (ppid) { switch (ppid) {
case PPID_BINARY_PARTIAL: case PPID_BINARY_PARTIAL:
case PPID_BINARY_LAST: case PPID_BINARY_LAST:
case PPID_BINARY_EMPTY: case PPID_BINARY_EMPTY:
*dest = cricket::DMT_BINARY; *dest = webrtc::DataMessageType::kBinary;
return true; return true;
case PPID_TEXT_PARTIAL: case PPID_TEXT_PARTIAL:
case PPID_TEXT_LAST: case PPID_TEXT_LAST:
case PPID_TEXT_EMPTY: case PPID_TEXT_EMPTY:
*dest = cricket::DMT_TEXT; *dest = webrtc::DataMessageType::kText;
return true; return true;
case PPID_CONTROL: case PPID_CONTROL:
*dest = cricket::DMT_CONTROL; *dest = webrtc::DataMessageType::kControl;
return true; return true;
case PPID_NONE:
*dest = cricket::DMT_NONE;
return true;
default:
return false;
} }
return false;
} }
bool IsEmptyPPID(uint32_t ppid) { bool IsEmptyPPID(uint32_t ppid) {
@ -212,11 +203,12 @@ void VerboseLogPacket(const void* data, size_t length, int direction) {
// Creates the sctp_sendv_spa struct used for setting flags in the // Creates the sctp_sendv_spa struct used for setting flags in the
// sctp_sendv() call. // sctp_sendv() call.
sctp_sendv_spa CreateSctpSendParams(const cricket::SendDataParams& params, sctp_sendv_spa CreateSctpSendParams(int sid,
const webrtc::SendDataParams& params,
size_t size) { size_t size) {
struct sctp_sendv_spa spa = {0}; struct sctp_sendv_spa spa = {0};
spa.sendv_flags |= SCTP_SEND_SNDINFO_VALID; spa.sendv_flags |= SCTP_SEND_SNDINFO_VALID;
spa.sendv_sndinfo.snd_sid = params.sid; spa.sendv_sndinfo.snd_sid = sid;
spa.sendv_sndinfo.snd_ppid = rtc::HostToNetwork32(GetPpid(params.type, size)); spa.sendv_sndinfo.snd_ppid = rtc::HostToNetwork32(GetPpid(params.type, size));
// Explicitly marking the EOR flag turns the usrsctp_sendv call below into a // Explicitly marking the EOR flag turns the usrsctp_sendv call below into a
// non atomic operation. This means that the sctp lib might only accept the // non atomic operation. This means that the sctp lib might only accept the
@ -724,7 +716,8 @@ bool UsrsctpTransport::ResetStream(int sid) {
return true; return true;
} }
bool UsrsctpTransport::SendData(const SendDataParams& params, bool UsrsctpTransport::SendData(int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result) { SendDataResult* result) {
RTC_DCHECK_RUN_ON(network_thread_); RTC_DCHECK_RUN_ON(network_thread_);
@ -739,13 +732,13 @@ bool UsrsctpTransport::SendData(const SendDataParams& params,
} }
// Do not queue data to send on a closing stream. // Do not queue data to send on a closing stream.
auto it = stream_status_by_sid_.find(params.sid); auto it = stream_status_by_sid_.find(sid);
if (it == stream_status_by_sid_.end() || !it->second.is_open()) { if (it == stream_status_by_sid_.end() || !it->second.is_open()) {
RTC_LOG(LS_WARNING) RTC_LOG(LS_WARNING)
<< debug_name_ << debug_name_
<< "->SendData(...): " << "->SendData(...): "
"Not sending data because sid is unknown or closing: " "Not sending data because sid is unknown or closing: "
<< params.sid; << sid;
if (result) { if (result) {
*result = SDR_ERROR; *result = SDR_ERROR;
} }
@ -753,7 +746,7 @@ bool UsrsctpTransport::SendData(const SendDataParams& params,
} }
size_t payload_size = payload.size(); size_t payload_size = payload.size();
OutgoingMessage message(payload, params); OutgoingMessage message(payload, sid, params);
SendDataResult send_message_result = SendMessageInternal(&message); SendDataResult send_message_result = SendMessageInternal(&message);
if (result) { if (result) {
*result = send_message_result; *result = send_message_result;
@ -782,17 +775,17 @@ SendDataResult UsrsctpTransport::SendMessageInternal(OutgoingMessage* message) {
RTC_LOG(LS_WARNING) << debug_name_ RTC_LOG(LS_WARNING) << debug_name_
<< "->SendMessageInternal(...): " << "->SendMessageInternal(...): "
"Not sending packet with sid=" "Not sending packet with sid="
<< message->send_params().sid << message->sid() << " len=" << message->size()
<< " len=" << message->size() << " before Start()."; << " before Start().";
return SDR_ERROR; return SDR_ERROR;
} }
if (message->send_params().type != DMT_CONTROL) { if (message->send_params().type != webrtc::DataMessageType::kControl) {
auto it = stream_status_by_sid_.find(message->send_params().sid); auto it = stream_status_by_sid_.find(message->sid());
if (it == stream_status_by_sid_.end()) { if (it == stream_status_by_sid_.end()) {
RTC_LOG(LS_WARNING) << debug_name_ RTC_LOG(LS_WARNING) << debug_name_
<< "->SendMessageInternal(...): " << "->SendMessageInternal(...): "
"Not sending data because sid is unknown: " "Not sending data because sid is unknown: "
<< message->send_params().sid; << message->sid();
return SDR_ERROR; return SDR_ERROR;
} }
} }
@ -804,8 +797,8 @@ SendDataResult UsrsctpTransport::SendMessageInternal(OutgoingMessage* message) {
} }
// Send data using SCTP. // Send data using SCTP.
sctp_sendv_spa spa = sctp_sendv_spa spa = CreateSctpSendParams(
CreateSctpSendParams(message->send_params(), message->size()); message->sid(), message->send_params(), message->size());
const void* data = message->data(); const void* data = message->data();
size_t data_length = message->size(); size_t data_length = message->size();
if (message->size() == 0) { if (message->size() == 0) {
@ -1081,7 +1074,7 @@ bool UsrsctpTransport::SendQueuedStreamResets() {
// https://w3c.github.io/webrtc-pc/#closing-procedure // https://w3c.github.io/webrtc-pc/#closing-procedure
return stream.second.need_outgoing_reset() && return stream.second.need_outgoing_reset() &&
(!partial_outgoing_message_.has_value() || (!partial_outgoing_message_.has_value() ||
partial_outgoing_message_.value().send_params().sid != partial_outgoing_message_.value().sid() !=
static_cast<int>(stream.first)); static_cast<int>(stream.first));
}; };
// Figure out how many streams need to be reset. We need to do this so we can // Figure out how many streams need to be reset. We need to do this so we can
@ -1158,7 +1151,7 @@ bool UsrsctpTransport::SendBufferedMessage() {
} }
RTC_DCHECK_EQ(0u, partial_outgoing_message_->size()); RTC_DCHECK_EQ(0u, partial_outgoing_message_->size());
int sid = partial_outgoing_message_->send_params().sid; int sid = partial_outgoing_message_->sid();
partial_outgoing_message_.reset(); partial_outgoing_message_.reset();
// Send the queued stream reset if it was pending for this stream. // Send the queued stream reset if it was pending for this stream.
@ -1314,7 +1307,7 @@ void UsrsctpTransport::OnDataOrNotificationFromSctp(const void* data,
<< ", eor=" << ((flags & MSG_EOR) ? "y" : "n"); << ", eor=" << ((flags & MSG_EOR) ? "y" : "n");
// Validate payload protocol identifier // Validate payload protocol identifier
DataMessageType type = DMT_NONE; webrtc::DataMessageType type;
if (!GetDataMediaType(ppid, &type)) { if (!GetDataMediaType(ppid, &type)) {
// Unexpected PPID, dropping // Unexpected PPID, dropping
RTC_LOG(LS_ERROR) << "Received an unknown PPID " << ppid RTC_LOG(LS_ERROR) << "Received an unknown PPID " << ppid

View File

@ -81,7 +81,8 @@ class UsrsctpTransport : public SctpTransportInternal,
bool Start(int local_port, int remote_port, int max_message_size) override; bool Start(int local_port, int remote_port, int max_message_size) override;
bool OpenStream(int sid) override; bool OpenStream(int sid) override;
bool ResetStream(int sid) override; bool ResetStream(int sid) override;
bool SendData(const SendDataParams& params, bool SendData(int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
SendDataResult* result = nullptr) override; SendDataResult* result = nullptr) override;
bool ReadyToSendData() override; bool ReadyToSendData() override;
@ -113,8 +114,9 @@ class UsrsctpTransport : public SctpTransportInternal,
class OutgoingMessage { class OutgoingMessage {
public: public:
OutgoingMessage(const rtc::CopyOnWriteBuffer& buffer, OutgoingMessage(const rtc::CopyOnWriteBuffer& buffer,
const SendDataParams& send_params) int sid,
: buffer_(buffer), send_params_(send_params) {} const webrtc::SendDataParams& send_params)
: buffer_(buffer), sid_(sid), send_params_(send_params) {}
// Advances the buffer by the incremented amount. Must not advance further // Advances the buffer by the incremented amount. Must not advance further
// than the current data size. // than the current data size.
@ -127,11 +129,13 @@ class UsrsctpTransport : public SctpTransportInternal,
const void* data() const { return buffer_.data() + offset_; } const void* data() const { return buffer_.data() + offset_; }
SendDataParams send_params() const { return send_params_; } int sid() const { return sid_; }
webrtc::SendDataParams send_params() const { return send_params_; }
private: private:
const rtc::CopyOnWriteBuffer buffer_; const rtc::CopyOnWriteBuffer buffer_;
const SendDataParams send_params_; int sid_;
const webrtc::SendDataParams send_params_;
size_t offset_ = 0; size_t offset_ = 0;
}; };

View File

@ -133,23 +133,19 @@ class SimulatedPacketTransport final : public rtc::PacketTransportInternal {
}; };
/** /**
* A helper class to send specified number of messages * A helper class to send specified number of messages over UsrsctpTransport
* over UsrsctpTransport with SCTP reliability settings * with SCTP reliability settings provided by user. The reliability settings are
* provided by user. The reliability settings are specified * specified by passing a template instance of SendDataParams. The sid will be
* by passing a template instance of SendDataParams. * assigned by sender itself and will be assigned from range
* When .sid field inside SendDataParams is specified to * [cricket::kMinSctpSid; cricket::kMaxSctpSid]. The wide range of sids are used
* negative value it means that actual .sid will be * to possibly trigger more execution paths inside usrsctp.
* assigned by sender itself, .sid will be assigned from
* range [cricket::kMinSctpSid; cricket::kMaxSctpSid].
* The wide range of sids are used to possibly trigger
* more execution paths inside usrsctp.
*/ */
class SctpDataSender final { class SctpDataSender final {
public: public:
SctpDataSender(rtc::Thread* thread, SctpDataSender(rtc::Thread* thread,
cricket::UsrsctpTransport* transport, cricket::UsrsctpTransport* transport,
uint64_t target_messages_count, uint64_t target_messages_count,
cricket::SendDataParams send_params, webrtc::SendDataParams send_params,
uint32_t sender_id) uint32_t sender_id)
: thread_(thread), : thread_(thread),
transport_(transport), transport_(transport),
@ -200,14 +196,12 @@ class SctpDataSender final {
<< target_messages_count_; << target_messages_count_;
} }
cricket::SendDataParams params(send_params_); webrtc::SendDataParams params(send_params_);
if (params.sid < 0) { int sid =
params.sid = cricket::kMinSctpSid + cricket::kMinSctpSid + (num_messages_sent_ % cricket::kMaxSctpStreams);
(num_messages_sent_ % cricket::kMaxSctpStreams);
}
cricket::SendDataResult result; cricket::SendDataResult result;
transport_->SendData(params, payload_, &result); transport_->SendData(sid, params, payload_, &result);
switch (result) { switch (result) {
case cricket::SDR_BLOCK: case cricket::SDR_BLOCK:
// retry after timeout // retry after timeout
@ -233,7 +227,7 @@ class SctpDataSender final {
rtc::Thread* const thread_; rtc::Thread* const thread_;
cricket::UsrsctpTransport* const transport_; cricket::UsrsctpTransport* const transport_;
const uint64_t target_messages_count_; const uint64_t target_messages_count_;
const cricket::SendDataParams send_params_; const webrtc::SendDataParams send_params_;
const uint32_t sender_id_; const uint32_t sender_id_;
rtc::CopyOnWriteBuffer payload_{std::string(1400, '.').c_str(), 1400}; rtc::CopyOnWriteBuffer payload_{std::string(1400, '.').c_str(), 1400};
std::atomic<bool> started_ ATOMIC_VAR_INIT(false); std::atomic<bool> started_ ATOMIC_VAR_INIT(false);
@ -329,7 +323,7 @@ class SctpPingPong final {
uint32_t messages_count, uint32_t messages_count,
uint8_t packet_loss_percents, uint8_t packet_loss_percents,
uint16_t avg_send_delay_millis, uint16_t avg_send_delay_millis,
cricket::SendDataParams send_params) webrtc::SendDataParams send_params)
: id_(id), : id_(id),
port1_(port1), port1_(port1),
port2_(port2), port2_(port2),
@ -582,7 +576,7 @@ class SctpPingPong final {
const uint32_t messages_count_; const uint32_t messages_count_;
const uint8_t packet_loss_percents_; const uint8_t packet_loss_percents_;
const uint16_t avg_send_delay_millis_; const uint16_t avg_send_delay_millis_;
const cricket::SendDataParams send_params_; const webrtc::SendDataParams send_params_;
RTC_DISALLOW_COPY_AND_ASSIGN(SctpPingPong); RTC_DISALLOW_COPY_AND_ASSIGN(SctpPingPong);
}; };
@ -643,8 +637,7 @@ TEST_F(UsrSctpReliabilityTest,
static_assert(wait_timeout > 0, static_assert(wait_timeout > 0,
"Timeout computation must produce positive value"); "Timeout computation must produce positive value");
cricket::SendDataParams send_params; webrtc::SendDataParams send_params;
send_params.sid = -1;
send_params.ordered = true; send_params.ordered = true;
SctpPingPong test(1, kTransport1Port, kTransport2Port, thread1.get(), SctpPingPong test(1, kTransport1Port, kTransport2Port, thread1.get(),
@ -678,8 +671,7 @@ TEST_F(UsrSctpReliabilityTest,
static_assert(wait_timeout > 0, static_assert(wait_timeout > 0,
"Timeout computation must produce positive value"); "Timeout computation must produce positive value");
cricket::SendDataParams send_params; webrtc::SendDataParams send_params;
send_params.sid = -1;
send_params.ordered = true; send_params.ordered = true;
SctpPingPong test(1, kTransport1Port, kTransport2Port, thread1.get(), SctpPingPong test(1, kTransport1Port, kTransport2Port, thread1.get(),
@ -714,8 +706,7 @@ TEST_F(UsrSctpReliabilityTest,
static_assert(wait_timeout > 0, static_assert(wait_timeout > 0,
"Timeout computation must produce positive value"); "Timeout computation must produce positive value");
cricket::SendDataParams send_params; webrtc::SendDataParams send_params;
send_params.sid = -1;
send_params.ordered = false; send_params.ordered = false;
send_params.max_rtx_count = std::numeric_limits<uint16_t>::max(); send_params.max_rtx_count = std::numeric_limits<uint16_t>::max();
send_params.max_rtx_ms = std::numeric_limits<uint16_t>::max(); send_params.max_rtx_ms = std::numeric_limits<uint16_t>::max();
@ -750,8 +741,7 @@ TEST_F(UsrSctpReliabilityTest,
DISABLED_AllMessagesAreDeliveredOverLossyConnectionConcurrentTests) { DISABLED_AllMessagesAreDeliveredOverLossyConnectionConcurrentTests) {
ThreadPool pool(16); ThreadPool pool(16);
cricket::SendDataParams send_params; webrtc::SendDataParams send_params;
send_params.sid = -1;
send_params.ordered = true; send_params.ordered = true;
constexpr uint32_t base_sctp_port = 5000; constexpr uint32_t base_sctp_port = 5000;

View File

@ -185,12 +185,11 @@ class SctpTransportTest : public ::testing::Test, public sigslot::has_slots<> {
const std::string& msg, const std::string& msg,
SendDataResult* result, SendDataResult* result,
bool ordered = false) { bool ordered = false) {
SendDataParams params; webrtc::SendDataParams params;
params.sid = sid;
params.ordered = ordered; params.ordered = ordered;
return chan->SendData(params, rtc::CopyOnWriteBuffer(&msg[0], msg.length()), return chan->SendData(
result); sid, params, rtc::CopyOnWriteBuffer(&msg[0], msg.length()), result);
} }
bool ReceivedData(const SctpFakeDataReceiver* recv, bool ReceivedData(const SctpFakeDataReceiver* recv,
@ -599,15 +598,14 @@ TEST_P(SctpTransportTestWithOrdered, SendDataBlocked) {
SetupConnectedTransportsWithTwoStreams(); SetupConnectedTransportsWithTwoStreams();
SendDataResult result; SendDataResult result;
SendDataParams params; webrtc::SendDataParams params;
params.sid = 1;
params.ordered = GetParam(); params.ordered = GetParam();
std::vector<char> buffer(1024 * 64, 0); std::vector<char> buffer(1024 * 64, 0);
for (size_t i = 0; i < 100; ++i) { for (size_t i = 0; i < 100; ++i) {
transport1()->SendData( transport1()->SendData(
params, rtc::CopyOnWriteBuffer(&buffer[0], buffer.size()), &result); 1, params, rtc::CopyOnWriteBuffer(&buffer[0], buffer.size()), &result);
if (result == SDR_BLOCK) if (result == SDR_BLOCK)
break; break;
} }
@ -626,15 +624,15 @@ TEST_P(SctpTransportTestWithOrdered, SignalReadyToSendDataAfterBlocked) {
fake_dtls1()->SetWritable(false); fake_dtls1()->SetWritable(false);
// Send messages until we get EWOULDBLOCK. // Send messages until we get EWOULDBLOCK.
static const size_t kMaxMessages = 1024; static const size_t kMaxMessages = 1024;
SendDataParams params; webrtc::SendDataParams params;
params.sid = 1;
params.ordered = GetParam(); params.ordered = GetParam();
rtc::CopyOnWriteBuffer buf(1024); rtc::CopyOnWriteBuffer buf(1024);
memset(buf.MutableData(), 0, 1024); memset(buf.MutableData(), 0, 1024);
SendDataResult result; SendDataResult result;
size_t message_count = 0; size_t message_count = 0;
for (; message_count < kMaxMessages; ++message_count) { for (; message_count < kMaxMessages; ++message_count) {
if (!transport1()->SendData(params, buf, &result) && result == SDR_BLOCK) { if (!transport1()->SendData(1, params, buf, &result) &&
result == SDR_BLOCK) {
break; break;
} }
} }

View File

@ -31,11 +31,12 @@ bool DataChannelController::HasDataChannels() const {
return !sctp_data_channels_.empty(); return !sctp_data_channels_.empty();
} }
bool DataChannelController::SendData(const cricket::SendDataParams& params, bool DataChannelController::SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) { cricket::SendDataResult* result) {
if (data_channel_transport()) if (data_channel_transport())
return DataChannelSendData(params, payload, result); return DataChannelSendData(sid, params, payload, result);
RTC_LOG(LS_ERROR) << "SendData called before transport is ready"; RTC_LOG(LS_ERROR) << "SendData called before transport is ready";
return false; return false;
} }
@ -106,7 +107,7 @@ void DataChannelController::OnDataReceived(
RTC_DCHECK_RUN_ON(network_thread()); RTC_DCHECK_RUN_ON(network_thread());
cricket::ReceiveDataParams params; cricket::ReceiveDataParams params;
params.sid = channel_id; params.sid = channel_id;
params.type = ToCricketDataMessageType(type); params.type = type;
signaling_thread()->PostTask( signaling_thread()->PostTask(
ToQueuedTask([self = weak_factory_.GetWeakPtr(), params, buffer] { ToQueuedTask([self = weak_factory_.GetWeakPtr(), params, buffer] {
if (self) { if (self) {
@ -222,7 +223,7 @@ std::vector<DataChannelStats> DataChannelController::GetDataChannelStats()
bool DataChannelController::HandleOpenMessage_s( bool DataChannelController::HandleOpenMessage_s(
const cricket::ReceiveDataParams& params, const cricket::ReceiveDataParams& params,
const rtc::CopyOnWriteBuffer& buffer) { const rtc::CopyOnWriteBuffer& buffer) {
if (params.type == cricket::DMT_CONTROL && IsOpenMessage(buffer)) { if (params.type == DataMessageType::kControl && IsOpenMessage(buffer)) {
// Received OPEN message; parse and signal that a new data channel should // Received OPEN message; parse and signal that a new data channel should
// be created. // be created.
std::string label; std::string label;
@ -386,7 +387,8 @@ void DataChannelController::set_data_channel_transport(
} }
bool DataChannelController::DataChannelSendData( bool DataChannelController::DataChannelSendData(
const cricket::SendDataParams& params, int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) { cricket::SendDataResult* result) {
// TODO(bugs.webrtc.org/11547): Expect method to be called on the network // TODO(bugs.webrtc.org/11547): Expect method to be called on the network
@ -395,16 +397,9 @@ bool DataChannelController::DataChannelSendData(
RTC_DCHECK_RUN_ON(signaling_thread()); RTC_DCHECK_RUN_ON(signaling_thread());
RTC_DCHECK(data_channel_transport()); RTC_DCHECK(data_channel_transport());
SendDataParams send_params;
send_params.type = ToWebrtcDataMessageType(params.type);
send_params.ordered = params.ordered;
send_params.max_rtx_count = params.max_rtx_count;
send_params.max_rtx_ms = params.max_rtx_ms;
RTCError error = network_thread()->Invoke<RTCError>( RTCError error = network_thread()->Invoke<RTCError>(
RTC_FROM_HERE, [this, params, send_params, payload] { RTC_FROM_HERE, [this, sid, params, payload] {
return data_channel_transport()->SendData(params.sid, send_params, return data_channel_transport()->SendData(sid, params, payload);
payload);
}); });
if (error.ok()) { if (error.ok()) {

View File

@ -53,7 +53,8 @@ class DataChannelController : public SctpDataChannelProviderInterface,
// Implements // Implements
// SctpDataChannelProviderInterface. // SctpDataChannelProviderInterface.
bool SendData(const cricket::SendDataParams& params, bool SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) override; cricket::SendDataResult* result) override;
bool ConnectDataChannel(SctpDataChannel* webrtc_data_channel) override; bool ConnectDataChannel(SctpDataChannel* webrtc_data_channel) override;
@ -131,7 +132,8 @@ class DataChannelController : public SctpDataChannelProviderInterface,
RTC_RUN_ON(signaling_thread()); RTC_RUN_ON(signaling_thread());
// Called from SendData when data_channel_transport() is true. // Called from SendData when data_channel_transport() is true.
bool DataChannelSendData(const cricket::SendDataParams& params, bool DataChannelSendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result); cricket::SendDataResult* result);

View File

@ -286,8 +286,9 @@ TEST_F(SctpDataChannelTest, OpenMessageSent) {
SetChannelReady(); SetChannelReady();
EXPECT_GE(webrtc_data_channel_->id(), 0); EXPECT_GE(webrtc_data_channel_->id(), 0);
EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); EXPECT_EQ(webrtc::DataMessageType::kControl,
EXPECT_EQ(provider_->last_send_data_params().sid, webrtc_data_channel_->id()); provider_->last_send_data_params().type);
EXPECT_EQ(provider_->last_sid(), webrtc_data_channel_->id());
} }
TEST_F(SctpDataChannelTest, QueuedOpenMessageSent) { TEST_F(SctpDataChannelTest, QueuedOpenMessageSent) {
@ -295,8 +296,9 @@ TEST_F(SctpDataChannelTest, QueuedOpenMessageSent) {
SetChannelReady(); SetChannelReady();
provider_->set_send_blocked(false); provider_->set_send_blocked(false);
EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); EXPECT_EQ(webrtc::DataMessageType::kControl,
EXPECT_EQ(provider_->last_send_data_params().sid, webrtc_data_channel_->id()); provider_->last_send_data_params().type);
EXPECT_EQ(provider_->last_sid(), webrtc_data_channel_->id());
} }
// Tests that the DataChannel created after transport gets ready can enter OPEN // Tests that the DataChannel created after transport gets ready can enter OPEN
@ -333,7 +335,7 @@ TEST_F(SctpDataChannelTest, SendUnorderedAfterReceivesOpenAck) {
// Emulates receiving an OPEN_ACK message. // Emulates receiving an OPEN_ACK message.
cricket::ReceiveDataParams params; cricket::ReceiveDataParams params;
params.sid = init.id; params.sid = init.id;
params.type = cricket::DMT_CONTROL; params.type = webrtc::DataMessageType::kControl;
rtc::CopyOnWriteBuffer payload; rtc::CopyOnWriteBuffer payload;
webrtc::WriteDataChannelOpenAckMessage(&payload); webrtc::WriteDataChannelOpenAckMessage(&payload);
dc->OnDataReceived(params, payload); dc->OnDataReceived(params, payload);
@ -359,7 +361,7 @@ TEST_F(SctpDataChannelTest, SendUnorderedAfterReceiveData) {
// Emulates receiving a DATA message. // Emulates receiving a DATA message.
cricket::ReceiveDataParams params; cricket::ReceiveDataParams params;
params.sid = init.id; params.sid = init.id;
params.type = cricket::DMT_TEXT; params.type = webrtc::DataMessageType::kText;
webrtc::DataBuffer buffer("data"); webrtc::DataBuffer buffer("data");
dc->OnDataReceived(params, buffer.data); dc->OnDataReceived(params, buffer.data);
@ -380,7 +382,8 @@ TEST_F(SctpDataChannelTest, OpenWaitsForOpenMesssage) {
provider_->set_send_blocked(false); provider_->set_send_blocked(false);
EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen,
webrtc_data_channel_->state(), 1000); webrtc_data_channel_->state(), 1000);
EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); EXPECT_EQ(webrtc::DataMessageType::kControl,
provider_->last_send_data_params().type);
} }
// Tests that close first makes sure all queued data gets sent. // Tests that close first makes sure all queued data gets sent.
@ -401,7 +404,8 @@ TEST_F(SctpDataChannelTest, QueuedCloseFlushes) {
EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kClosed, EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kClosed,
webrtc_data_channel_->state(), 1000); webrtc_data_channel_->state(), 1000);
EXPECT_TRUE(webrtc_data_channel_->error().ok()); EXPECT_TRUE(webrtc_data_channel_->error().ok());
EXPECT_EQ(cricket::DMT_TEXT, provider_->last_send_data_params().type); EXPECT_EQ(webrtc::DataMessageType::kText,
provider_->last_send_data_params().type);
} }
// Tests that messages are sent with the right id. // Tests that messages are sent with the right id.
@ -410,7 +414,7 @@ TEST_F(SctpDataChannelTest, SendDataId) {
SetChannelReady(); SetChannelReady();
webrtc::DataBuffer buffer("data"); webrtc::DataBuffer buffer("data");
EXPECT_TRUE(webrtc_data_channel_->Send(buffer)); EXPECT_TRUE(webrtc_data_channel_->Send(buffer));
EXPECT_EQ(1, provider_->last_send_data_params().sid); EXPECT_EQ(1, provider_->last_sid());
} }
// Tests that the incoming messages with wrong ids are rejected. // Tests that the incoming messages with wrong ids are rejected.
@ -457,7 +461,7 @@ TEST_F(SctpDataChannelTest, NoMsgSentIfNegotiatedAndNotFromOpenMsg) {
rtc::Thread::Current(), rtc::Thread::Current()); rtc::Thread::Current(), rtc::Thread::Current());
EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000);
EXPECT_EQ(0, provider_->last_send_data_params().sid); EXPECT_EQ(0, provider_->last_sid());
} }
// Tests that DataChannel::messages_received() and DataChannel::bytes_received() // Tests that DataChannel::messages_received() and DataChannel::bytes_received()
@ -522,8 +526,9 @@ TEST_F(SctpDataChannelTest, OpenAckSentIfCreatedFromOpenMessage) {
EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000); EXPECT_EQ_WAIT(webrtc::DataChannelInterface::kOpen, dc->state(), 1000);
EXPECT_EQ(config.id, provider_->last_send_data_params().sid); EXPECT_EQ(config.id, provider_->last_sid());
EXPECT_EQ(cricket::DMT_CONTROL, provider_->last_send_data_params().type); EXPECT_EQ(webrtc::DataMessageType::kControl,
provider_->last_send_data_params().type);
} }
// Tests the OPEN_ACK role assigned by InternalDataChannelInit. // Tests the OPEN_ACK role assigned by InternalDataChannelInit.

View File

@ -406,7 +406,7 @@ void SctpDataChannel::OnDataReceived(const cricket::ReceiveDataParams& params,
return; return;
} }
if (params.type == cricket::DMT_CONTROL) { if (params.type == DataMessageType::kControl) {
if (handshake_state_ != kHandshakeWaitingForAck) { if (handshake_state_ != kHandshakeWaitingForAck) {
// Ignore it if we are not expecting an ACK message. // Ignore it if we are not expecting an ACK message.
RTC_LOG(LS_WARNING) RTC_LOG(LS_WARNING)
@ -427,8 +427,8 @@ void SctpDataChannel::OnDataReceived(const cricket::ReceiveDataParams& params,
return; return;
} }
RTC_DCHECK(params.type == cricket::DMT_BINARY || RTC_DCHECK(params.type == DataMessageType::kBinary ||
params.type == cricket::DMT_TEXT); params.type == DataMessageType::kText);
RTC_LOG(LS_VERBOSE) << "DataChannel received DATA message, sid = " RTC_LOG(LS_VERBOSE) << "DataChannel received DATA message, sid = "
<< params.sid; << params.sid;
@ -439,7 +439,7 @@ void SctpDataChannel::OnDataReceived(const cricket::ReceiveDataParams& params,
handshake_state_ = kHandshakeReady; handshake_state_ = kHandshakeReady;
} }
bool binary = (params.type == cricket::DMT_BINARY); bool binary = (params.type == webrtc::DataMessageType::kBinary);
auto buffer = std::make_unique<DataBuffer>(payload, binary); auto buffer = std::make_unique<DataBuffer>(payload, binary);
if (state_ == kOpen && observer_) { if (state_ == kOpen && observer_) {
++messages_received_; ++messages_received_;
@ -620,7 +620,7 @@ void SctpDataChannel::SendQueuedDataMessages() {
bool SctpDataChannel::SendDataMessage(const DataBuffer& buffer, bool SctpDataChannel::SendDataMessage(const DataBuffer& buffer,
bool queue_if_blocked) { bool queue_if_blocked) {
RTC_DCHECK_RUN_ON(signaling_thread_); RTC_DCHECK_RUN_ON(signaling_thread_);
cricket::SendDataParams send_params; SendDataParams send_params;
send_params.ordered = config_.ordered; send_params.ordered = config_.ordered;
// Send as ordered if it is still going through OPEN/ACK signaling. // Send as ordered if it is still going through OPEN/ACK signaling.
@ -633,11 +633,12 @@ bool SctpDataChannel::SendDataMessage(const DataBuffer& buffer,
send_params.max_rtx_count = config_.maxRetransmits; send_params.max_rtx_count = config_.maxRetransmits;
send_params.max_rtx_ms = config_.maxRetransmitTime; send_params.max_rtx_ms = config_.maxRetransmitTime;
send_params.sid = config_.id; send_params.type =
send_params.type = buffer.binary ? cricket::DMT_BINARY : cricket::DMT_TEXT; buffer.binary ? DataMessageType::kBinary : DataMessageType::kText;
cricket::SendDataResult send_result = cricket::SDR_SUCCESS; cricket::SendDataResult send_result = cricket::SDR_SUCCESS;
bool success = provider_->SendData(send_params, buffer.data, &send_result); bool success =
provider_->SendData(config_.id, send_params, buffer.data, &send_result);
if (success) { if (success) {
++messages_sent_; ++messages_sent_;
@ -703,16 +704,16 @@ bool SctpDataChannel::SendControlMessage(const rtc::CopyOnWriteBuffer& buffer) {
bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen; bool is_open_message = handshake_state_ == kHandshakeShouldSendOpen;
RTC_DCHECK(!is_open_message || !config_.negotiated); RTC_DCHECK(!is_open_message || !config_.negotiated);
cricket::SendDataParams send_params; SendDataParams send_params;
send_params.sid = config_.id;
// Send data as ordered before we receive any message from the remote peer to // Send data as ordered before we receive any message from the remote peer to
// make sure the remote peer will not receive any data before it receives the // make sure the remote peer will not receive any data before it receives the
// OPEN message. // OPEN message.
send_params.ordered = config_.ordered || is_open_message; send_params.ordered = config_.ordered || is_open_message;
send_params.type = cricket::DMT_CONTROL; send_params.type = DataMessageType::kControl;
cricket::SendDataResult send_result = cricket::SDR_SUCCESS; cricket::SendDataResult send_result = cricket::SDR_SUCCESS;
bool retval = provider_->SendData(send_params, buffer, &send_result); bool retval =
provider_->SendData(config_.id, send_params, buffer, &send_result);
if (retval) { if (retval) {
RTC_LOG(LS_VERBOSE) << "Sent CONTROL message on channel " << config_.id; RTC_LOG(LS_VERBOSE) << "Sent CONTROL message on channel " << config_.id;

View File

@ -40,7 +40,8 @@ class SctpDataChannel;
class SctpDataChannelProviderInterface { class SctpDataChannelProviderInterface {
public: public:
// Sends the data to the transport. // Sends the data to the transport.
virtual bool SendData(const cricket::SendDataParams& params, virtual bool SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) = 0; cricket::SendDataResult* result) = 0;
// Connects to the transport signals. // Connects to the transport signals.

View File

@ -39,17 +39,8 @@ RTCError SctpDataChannelTransport::SendData(
int channel_id, int channel_id,
const SendDataParams& params, const SendDataParams& params,
const rtc::CopyOnWriteBuffer& buffer) { const rtc::CopyOnWriteBuffer& buffer) {
// Map webrtc::SendDataParams to cricket::SendDataParams.
// TODO(mellem): See about unifying these structs.
cricket::SendDataParams sd_params;
sd_params.sid = channel_id;
sd_params.type = ToCricketDataMessageType(params.type);
sd_params.ordered = params.ordered;
sd_params.max_rtx_count = params.max_rtx_count;
sd_params.max_rtx_ms = params.max_rtx_ms;
cricket::SendDataResult result; cricket::SendDataResult result;
sctp_transport_->SendData(sd_params, buffer, &result); sctp_transport_->SendData(channel_id, params, buffer, &result);
// TODO(mellem): See about changing the interfaces to not require mapping // TODO(mellem): See about changing the interfaces to not require mapping
// SendDataResult to RTCError and back again. // SendDataResult to RTCError and back again.
@ -94,8 +85,7 @@ void SctpDataChannelTransport::OnDataReceived(
const cricket::ReceiveDataParams& params, const cricket::ReceiveDataParams& params,
const rtc::CopyOnWriteBuffer& buffer) { const rtc::CopyOnWriteBuffer& buffer) {
if (sink_) { if (sink_) {
sink_->OnDataReceived(params.sid, ToWebrtcDataMessageType(params.type), sink_->OnDataReceived(params.sid, params.type, buffer);
buffer);
} }
} }

View File

@ -38,7 +38,8 @@ class FakeCricketSctpTransport : public cricket::SctpTransportInternal {
} }
bool OpenStream(int sid) override { return true; } bool OpenStream(int sid) override { return true; }
bool ResetStream(int sid) override { return true; } bool ResetStream(int sid) override { return true; }
bool SendData(const cricket::SendDataParams& params, bool SendData(int sid,
const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result = nullptr) override { cricket::SendDataResult* result = nullptr) override {
return true; return true;

View File

@ -230,33 +230,4 @@ void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload) {
payload->SetData(&data, sizeof(data)); payload->SetData(&data, sizeof(data));
} }
cricket::DataMessageType ToCricketDataMessageType(DataMessageType type) {
switch (type) {
case DataMessageType::kText:
return cricket::DMT_TEXT;
case DataMessageType::kBinary:
return cricket::DMT_BINARY;
case DataMessageType::kControl:
return cricket::DMT_CONTROL;
default:
return cricket::DMT_NONE;
}
return cricket::DMT_NONE;
}
DataMessageType ToWebrtcDataMessageType(cricket::DataMessageType type) {
switch (type) {
case cricket::DMT_TEXT:
return DataMessageType::kText;
case cricket::DMT_BINARY:
return DataMessageType::kBinary;
case cricket::DMT_CONTROL:
return DataMessageType::kControl;
case cricket::DMT_NONE:
default:
RTC_NOTREACHED();
}
return DataMessageType::kControl;
}
} // namespace webrtc } // namespace webrtc

View File

@ -40,10 +40,6 @@ bool WriteDataChannelOpenMessage(const std::string& label,
void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload); void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload);
cricket::DataMessageType ToCricketDataMessageType(DataMessageType type);
DataMessageType ToWebrtcDataMessageType(cricket::DataMessageType type);
} // namespace webrtc } // namespace webrtc
#endif // PC_SCTP_UTILS_H_ #endif // PC_SCTP_UTILS_H_

View File

@ -26,7 +26,8 @@ class FakeDataChannelProvider
transport_error_(false) {} transport_error_(false) {}
virtual ~FakeDataChannelProvider() {} virtual ~FakeDataChannelProvider() {}
bool SendData(const cricket::SendDataParams& params, bool SendData(int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result) override { cricket::SendDataResult* result) override {
RTC_CHECK(ready_to_send_); RTC_CHECK(ready_to_send_);
@ -41,6 +42,7 @@ class FakeDataChannelProvider
return false; return false;
} }
last_sid_ = sid;
last_send_data_params_ = params; last_send_data_params_ = params;
return true; return true;
} }
@ -127,7 +129,8 @@ class FakeDataChannelProvider
void set_transport_error() { transport_error_ = true; } void set_transport_error() { transport_error_ = true; }
cricket::SendDataParams last_send_data_params() const { int last_sid() const { return last_sid_; }
const webrtc::SendDataParams& last_send_data_params() const {
return last_send_data_params_; return last_send_data_params_;
} }
@ -144,7 +147,8 @@ class FakeDataChannelProvider
} }
private: private:
cricket::SendDataParams last_send_data_params_; int last_sid_;
webrtc::SendDataParams last_send_data_params_;
bool send_blocked_; bool send_blocked_;
bool transport_available_; bool transport_available_;
bool ready_to_send_; bool ready_to_send_;

View File

@ -29,7 +29,8 @@ class FakeSctpTransport : public cricket::SctpTransportInternal {
} }
bool OpenStream(int sid) override { return true; } bool OpenStream(int sid) override { return true; }
bool ResetStream(int sid) override { return true; } bool ResetStream(int sid) override { return true; }
bool SendData(const cricket::SendDataParams& params, bool SendData(int sid,
const webrtc::SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload, const rtc::CopyOnWriteBuffer& payload,
cricket::SendDataResult* result = nullptr) override { cricket::SendDataResult* result = nullptr) override {
return true; return true;