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}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 5f048fc..0a0a501 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -166,6 +166,7 @@
     ":media_stream_interface",
     ":network_state_predictor_api",
     ":packet_socket_factory",
+    ":priority",
     ":rtc_error",
     ":rtc_stats_api",
     ":rtp_packet_info",
@@ -303,6 +304,10 @@
   sources = [ "rtp_transceiver_direction.h" ]
 }
 
+rtc_source_set("priority") {
+  sources = [ "priority.h" ]
+}
+
 rtc_library("rtp_parameters") {
   visibility = [ "*" ]
   sources = [
@@ -313,6 +318,7 @@
   ]
   deps = [
     ":array_view",
+    ":priority",
     ":rtp_transceiver_direction",
     "../rtc_base:checks",
     "../rtc_base:stringutils",
@@ -323,8 +329,8 @@
 }
 
 if (is_android) {
-  java_cpp_enum("rtp_parameters_enums") {
-    sources = [ "rtp_parameters.h" ]
+  java_cpp_enum("priority_enums") {
+    sources = [ "priority.h" ]
   }
 }
 
diff --git a/api/data_channel_interface.h b/api/data_channel_interface.h
index e08830f..5b2b126 100644
--- a/api/data_channel_interface.h
+++ b/api/data_channel_interface.h
@@ -20,6 +20,7 @@
 #include <string>
 
 #include "absl/types/optional.h"
+#include "api/priority.h"
 #include "api/rtc_error.h"
 #include "rtc_base/checks.h"
 #include "rtc_base/copy_on_write_buffer.h"
@@ -61,6 +62,9 @@
 
   // The stream id, or SID, for SCTP data channels. -1 if unset (see above).
   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
@@ -154,6 +158,7 @@
   // If negotiated in-band, this ID will be populated once the DTLS role is
   // determined, and until then this will return -1.
   virtual int id() const = 0;
+  virtual Priority priority() const { return Priority::kLow; }
   virtual DataState state() const = 0;
   // When state is kClosed, and the DataChannel was not closed using
   // the closing procedure, returns the error information about the closing.
diff --git a/api/priority.h b/api/priority.h
new file mode 100644
index 0000000..4953e45
--- /dev/null
+++ b/api/priority.h
@@ -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_
diff --git a/api/rtp_parameters.h b/api/rtp_parameters.h
index 49c1e0c..d7156db 100644
--- a/api/rtp_parameters.h
+++ b/api/rtp_parameters.h
@@ -20,6 +20,7 @@
 #include "absl/strings/string_view.h"
 #include "absl/types/optional.h"
 #include "api/media_types.h"
+#include "api/priority.h"
 #include "api/rtp_transceiver_direction.h"
 #include "rtc_base/system/rtc_export.h"
 
@@ -93,14 +94,6 @@
 
 RTC_EXPORT extern const double kDefaultBitratePriority;
 
-// GENERATED_JAVA_ENUM_PACKAGE: org.webrtc
-enum class Priority {
-  kVeryLow,
-  kLow,
-  kMedium,
-  kHigh,
-};
-
 struct RTC_EXPORT RtcpFeedback {
   RtcpFeedbackType type = RtcpFeedbackType::CCM;