Pass datachannel priority in DC open messages

This adds priority to the API configuration of datachannels,
and passes the value in the OPEN message.

It does not yet influence SCTP prioritization of messages.

Bug: chromium:1083227
Change-Id: I46ddd1eefa0e3d07c959383788b9e80fcbfa38d6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175107
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Taylor <deadbeef@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31287}
This commit is contained in:
Harald Alvestrand 2020-05-16 08:37:49 +02:00 committed by Commit Bot
parent 49a5e3ec3c
commit fd5ae7f959
9 changed files with 116 additions and 11 deletions

View file

@ -166,6 +166,7 @@ rtc_library("libjingle_peerconnection_api") {
":media_stream_interface", ":media_stream_interface",
":network_state_predictor_api", ":network_state_predictor_api",
":packet_socket_factory", ":packet_socket_factory",
":priority",
":rtc_error", ":rtc_error",
":rtc_stats_api", ":rtc_stats_api",
":rtp_packet_info", ":rtp_packet_info",
@ -303,6 +304,10 @@ rtc_source_set("rtp_transceiver_direction") {
sources = [ "rtp_transceiver_direction.h" ] sources = [ "rtp_transceiver_direction.h" ]
} }
rtc_source_set("priority") {
sources = [ "priority.h" ]
}
rtc_library("rtp_parameters") { rtc_library("rtp_parameters") {
visibility = [ "*" ] visibility = [ "*" ]
sources = [ sources = [
@ -313,6 +318,7 @@ rtc_library("rtp_parameters") {
] ]
deps = [ deps = [
":array_view", ":array_view",
":priority",
":rtp_transceiver_direction", ":rtp_transceiver_direction",
"../rtc_base:checks", "../rtc_base:checks",
"../rtc_base:stringutils", "../rtc_base:stringutils",
@ -323,8 +329,8 @@ rtc_library("rtp_parameters") {
} }
if (is_android) { if (is_android) {
java_cpp_enum("rtp_parameters_enums") { java_cpp_enum("priority_enums") {
sources = [ "rtp_parameters.h" ] sources = [ "priority.h" ]
} }
} }

View file

@ -20,6 +20,7 @@
#include <string> #include <string>
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/priority.h"
#include "api/rtc_error.h" #include "api/rtc_error.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
@ -61,6 +62,9 @@ struct DataChannelInit {
// The stream id, or SID, for SCTP data channels. -1 if unset (see above). // The stream id, or SID, for SCTP data channels. -1 if unset (see above).
int id = -1; int id = -1;
// https://w3c.github.io/webrtc-priority/#new-rtcdatachannelinit-member
absl::optional<Priority> priority;
}; };
// At the JavaScript level, data can be passed in as a string or a blob, so // At the JavaScript level, data can be passed in as a string or a blob, so
@ -154,6 +158,7 @@ class RTC_EXPORT DataChannelInterface : public rtc::RefCountInterface {
// If negotiated in-band, this ID will be populated once the DTLS role is // If negotiated in-band, this ID will be populated once the DTLS role is
// determined, and until then this will return -1. // determined, and until then this will return -1.
virtual int id() const = 0; virtual int id() const = 0;
virtual Priority priority() const { return Priority::kLow; }
virtual DataState state() const = 0; virtual DataState state() const = 0;
// When state is kClosed, and the DataChannel was not closed using // When state is kClosed, and the DataChannel was not closed using
// the closing procedure, returns the error information about the closing. // the closing procedure, returns the error information about the closing.

26
api/priority.h Normal file
View file

@ -0,0 +1,26 @@
/*
* Copyright 2020 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 API_PRIORITY_H_
#define API_PRIORITY_H_
namespace webrtc {
// GENERATED_JAVA_ENUM_PACKAGE: org.webrtc
enum class Priority {
kVeryLow,
kLow,
kMedium,
kHigh,
};
} // namespace webrtc
#endif // API_PRIORITY_H_

View file

@ -20,6 +20,7 @@
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/media_types.h" #include "api/media_types.h"
#include "api/priority.h"
#include "api/rtp_transceiver_direction.h" #include "api/rtp_transceiver_direction.h"
#include "rtc_base/system/rtc_export.h" #include "rtc_base/system/rtc_export.h"
@ -93,14 +94,6 @@ enum class DegradationPreference {
RTC_EXPORT extern const double kDefaultBitratePriority; RTC_EXPORT extern const double kDefaultBitratePriority;
// GENERATED_JAVA_ENUM_PACKAGE: org.webrtc
enum class Priority {
kVeryLow,
kLow,
kMedium,
kHigh,
};
struct RTC_EXPORT RtcpFeedback { struct RTC_EXPORT RtcpFeedback {
RtcpFeedbackType type = RtcpFeedbackType::CCM; RtcpFeedbackType type = RtcpFeedbackType::CCM;

View file

@ -88,6 +88,7 @@ rtc_library("rtc_pc_base") {
"../api:function_view", "../api:function_view",
"../api:ice_transport_factory", "../api:ice_transport_factory",
"../api:libjingle_peerconnection_api", "../api:libjingle_peerconnection_api",
"../api:priority",
"../api:rtc_error", "../api:rtc_error",
"../api:rtp_headers", "../api:rtp_headers",
"../api:rtp_parameters", "../api:rtp_parameters",
@ -236,6 +237,7 @@ rtc_library("peerconnection") {
"../api:libjingle_peerconnection_api", "../api:libjingle_peerconnection_api",
"../api:media_stream_interface", "../api:media_stream_interface",
"../api:network_state_predictor_api", "../api:network_state_predictor_api",
"../api:priority",
"../api:rtc_error", "../api:rtc_error",
"../api:rtc_event_log_output_file", "../api:rtc_event_log_output_file",
"../api:rtc_stats_api", "../api:rtc_stats_api",

View file

@ -17,6 +17,7 @@
#include <string> #include <string>
#include "api/data_channel_interface.h" #include "api/data_channel_interface.h"
#include "api/priority.h"
#include "api/proxy.h" #include "api/proxy.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "media/base/media_channel.h" #include "media/base/media_channel.h"
@ -142,6 +143,9 @@ class DataChannel : public DataChannelInterface, public sigslot::has_slots<> {
virtual std::string protocol() const { return config_.protocol; } virtual std::string protocol() const { return config_.protocol; }
virtual bool negotiated() const { return config_.negotiated; } virtual bool negotiated() const { return config_.negotiated; }
virtual int id() const { return config_.id; } virtual int id() const { return config_.id; }
virtual Priority priority() const {
return config_.priority ? *config_.priority : Priority::kLow;
}
virtual int internal_id() const { return internal_id_; } virtual int internal_id() const { return internal_id_; }
virtual uint64_t buffered_amount() const; virtual uint64_t buffered_amount() const;
virtual void Close(); virtual void Close();
@ -324,6 +328,7 @@ PROXY_CONSTMETHOD0(absl::optional<int>, maxPacketLifeTime)
PROXY_CONSTMETHOD0(std::string, protocol) PROXY_CONSTMETHOD0(std::string, protocol)
PROXY_CONSTMETHOD0(bool, negotiated) PROXY_CONSTMETHOD0(bool, negotiated)
PROXY_CONSTMETHOD0(int, id) PROXY_CONSTMETHOD0(int, id)
PROXY_CONSTMETHOD0(Priority, priority)
PROXY_CONSTMETHOD0(DataState, state) PROXY_CONSTMETHOD0(DataState, state)
PROXY_CONSTMETHOD0(RTCError, error) PROXY_CONSTMETHOD0(RTCError, error)
PROXY_CONSTMETHOD0(uint32_t, messages_sent) PROXY_CONSTMETHOD0(uint32_t, messages_sent)

View file

@ -13,6 +13,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "api/priority.h"
#include "rtc_base/byte_buffer.h" #include "rtc_base/byte_buffer.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
@ -34,6 +35,15 @@ enum DataChannelOpenMessageChannelType {
DCOMCT_UNORDERED_PARTIAL_TIME = 0x82, DCOMCT_UNORDERED_PARTIAL_TIME = 0x82,
}; };
// Values of priority in the DC open protocol message.
// These are compared against an integer, so are enum, not enum class.
enum DataChannelPriority {
DCO_PRIORITY_VERY_LOW = 128,
DCO_PRIORITY_LOW = 256,
DCO_PRIORITY_MEDIUM = 512,
DCO_PRIORITY_HIGH = 1024,
};
bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload) { bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload) {
// Format defined at // Format defined at
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 // http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04
@ -76,6 +86,18 @@ bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload,
<< "Could not read OPEN message reliabilility prioirty."; << "Could not read OPEN message reliabilility prioirty.";
return false; return false;
} }
// Parse priority as defined in
// https://w3c.github.io/webrtc-priority/#rtcdatachannel-processing-steps
if (priority <= DCO_PRIORITY_VERY_LOW) {
config->priority = Priority::kVeryLow;
} else if (priority <= DCO_PRIORITY_LOW) {
config->priority = Priority::kLow;
} else if (priority <= DCO_PRIORITY_MEDIUM) {
config->priority = Priority::kMedium;
} else {
config->priority = Priority::kHigh;
}
uint32_t reliability_param; uint32_t reliability_param;
if (!buffer.ReadUInt32(&reliability_param)) { if (!buffer.ReadUInt32(&reliability_param)) {
RTC_LOG(LS_WARNING) << "Could not read OPEN message reliabilility param."; RTC_LOG(LS_WARNING) << "Could not read OPEN message reliabilility param.";
@ -146,6 +168,24 @@ bool WriteDataChannelOpenMessage(const std::string& label,
uint8_t channel_type = 0; uint8_t channel_type = 0;
uint32_t reliability_param = 0; uint32_t reliability_param = 0;
uint16_t priority = 0; uint16_t priority = 0;
// Set priority according to
// https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-12#section-6.4
if (config.priority) {
switch (*config.priority) {
case Priority::kVeryLow:
priority = DCO_PRIORITY_VERY_LOW;
break;
case Priority::kLow:
priority = DCO_PRIORITY_LOW;
break;
case Priority::kMedium:
priority = DCO_PRIORITY_MEDIUM;
break;
case Priority::kHigh:
priority = DCO_PRIORITY_HIGH;
break;
}
}
if (config.ordered) { if (config.ordered) {
if (config.maxRetransmits) { if (config.maxRetransmits) {
channel_type = DCOMCT_ORDERED_PARTIAL_RTXS; channel_type = DCOMCT_ORDERED_PARTIAL_RTXS;

View file

@ -45,6 +45,13 @@ class SctpUtilsTest : public ::testing::Test {
} }
ASSERT_TRUE(buffer.ReadUInt16(&priority)); ASSERT_TRUE(buffer.ReadUInt16(&priority));
if (config.priority) {
// Exact values are checked by round-trip conversion, but
// all values defined are greater than zero.
EXPECT_GT(priority, 0);
} else {
EXPECT_EQ(priority, 0);
}
ASSERT_TRUE(buffer.ReadUInt32(&reliability)); ASSERT_TRUE(buffer.ReadUInt32(&reliability));
if (config.maxRetransmits || config.maxRetransmitTime) { if (config.maxRetransmits || config.maxRetransmitTime) {
@ -136,6 +143,27 @@ TEST_F(SctpUtilsTest, WriteParseOpenMessageWithMaxRetransmits) {
EXPECT_FALSE(output_config.maxRetransmitTime); EXPECT_FALSE(output_config.maxRetransmitTime);
} }
TEST_F(SctpUtilsTest, WriteParseOpenMessageWithPriority) {
webrtc::DataChannelInit config;
std::string label = "abc";
config.protocol = "y";
config.priority = webrtc::Priority::kVeryLow;
rtc::CopyOnWriteBuffer packet;
ASSERT_TRUE(webrtc::WriteDataChannelOpenMessage(label, config, &packet));
VerifyOpenMessageFormat(packet, label, config);
std::string output_label;
webrtc::DataChannelInit output_config;
ASSERT_TRUE(webrtc::ParseDataChannelOpenMessage(packet, &output_label,
&output_config));
EXPECT_EQ(label, output_label);
ASSERT_TRUE(output_config.priority);
EXPECT_EQ(*config.priority, *output_config.priority);
}
TEST_F(SctpUtilsTest, WriteParseAckMessage) { TEST_F(SctpUtilsTest, WriteParseAckMessage) {
rtc::CopyOnWriteBuffer packet; rtc::CopyOnWriteBuffer packet;
webrtc::WriteDataChannelOpenAckMessage(&packet); webrtc::WriteDataChannelOpenAckMessage(&packet);

View file

@ -326,7 +326,7 @@ if (is_android) {
"//third_party/android_deps:com_android_support_support_annotations_java", "//third_party/android_deps:com_android_support_support_annotations_java",
] ]
srcjar_deps = [ srcjar_deps = [
"//api:rtp_parameters_enums", "//api:priority_enums",
"//api/video:video_frame_enums", "//api/video:video_frame_enums",
] ]
} }