Reland: Implement true negotiation for DatagramTransport with fallback to RTP.
In short, the caller places a x-opaque line in SDP for each m= section that
uses datagram transport. If the answerer supports datagram transport, it will
parse this line and create a datagram transport. It will then echo the x-opaque
line into the answer (to indicate that it accepted use of datagram transport).
If the offer and answer contain exactly the same x-opaque line, both peers will
use datagram transport. If the x-opaque line is omitted from the answer (or is
different in the answer) they will fall back to RTP.
Note that a different x-opaque line in the answer means the answerer did not
understand something in the negotiation proto. Since WebRTC cannot know what
was misunderstood, or whether it's still possible to use the datagram transport,
it must fall back to RTP. This may change in the future, possibly by passing
the answer to the datagram transport, but it's good enough for now.
Negotiation consists of four parts:
1. DatagramTransport exposes transport parameters for both client and server
perspectives. The client just echoes what it received from the server (modulo
any fields it might not have understood).
2. SDP adds a x-opaque line for opaque transport parameters. Identical to
x-mt, but this is specific to datagram transport and goes in each m= section,
and appears in the answer as well as the offer.
- This is propagated to Jsep as part of the TransportDescription.
- SDP files: transport_description.h,cc, transport_description_factory.h,cc,
media_session.cc, webrtc_sdp.cc
3. JsepTransport/Controller:
- Exposes opaque parameters for each mid (m= section). On offerer, this means
pre-allocating a datagram transport and getting its parameters. On the
answerer, this means echoing the offerer's parameters.
- Uses a composite RTP transport to receive from either default RTP or
datagram transport until both offer and answer arrive.
- If a provisional answer arrives, sets the composite to send on the
provisionally selected transport.
- Once both offer and answer are set, deletes the unneeded transports and
keeps whichever transport is selected.
4. PeerConnection pulls transport parameters out of Jsep and adds them to SDP.
Bug: webrtc:9719
Change-Id: Ifcc428c8d76fb77dcc8abaa79507c620bcfb31b9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/140920
Reviewed-by: Steve Anton <steveanton@webrtc.org>
Commit-Queue: Bjorn Mellem <mellem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28198}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 2617a19..063767a 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -794,6 +794,7 @@
testonly = true
sources = [
+ "test/fake_datagram_transport.h",
"test/fake_media_transport.h",
]
diff --git a/api/datagram_transport_interface.h b/api/datagram_transport_interface.h
index c908dfb..6205f00 100644
--- a/api/datagram_transport_interface.h
+++ b/api/datagram_transport_interface.h
@@ -120,10 +120,24 @@
// that the binary blob goes through). This should only be called for the
// caller's perspective.
//
- // TODO(sukhanov): Make pure virtual.
+ // TODO(mellem): Delete.
virtual absl::optional<std::string> GetTransportParametersOffer() const {
return absl::nullopt;
}
+
+ // Retrieves transport parameters for this datagram transport. May be called
+ // on either client- or server-perspective transports.
+ //
+ // For servers, the parameters represent what kind of connections and data the
+ // server is prepared to accept. This is generally a superset of acceptable
+ // parameters.
+ //
+ // For clients, the parameters echo the server configuration used to create
+ // the client, possibly removing any fields or parameters which the client
+ // does not understand.
+ //
+ // TODO(mellem): Make pure virtual.
+ virtual std::string GetTransportParameters() const { return ""; }
};
} // namespace webrtc
diff --git a/api/test/fake_datagram_transport.h b/api/test/fake_datagram_transport.h
new file mode 100644
index 0000000..a73a7e8
--- /dev/null
+++ b/api/test/fake_datagram_transport.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2019 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_TEST_FAKE_DATAGRAM_TRANSPORT_H_
+#define API_TEST_FAKE_DATAGRAM_TRANSPORT_H_
+
+#include <cstddef>
+#include <string>
+
+#include "api/datagram_transport_interface.h"
+
+namespace webrtc {
+
+// Maxmum size of datagrams sent by |FakeDatagramTransport|.
+constexpr size_t kMaxFakeDatagramSize = 1000;
+
+// Fake datagram transport. Does not support making an actual connection
+// or sending data. Only used for tests that need to stub out a transport.
+class FakeDatagramTransport : public DatagramTransportInterface {
+ public:
+ FakeDatagramTransport(const MediaTransportSettings& settings,
+ std::string transport_parameters)
+ : settings_(settings), transport_parameters_(transport_parameters) {}
+
+ ~FakeDatagramTransport() override { RTC_DCHECK(!state_callback_); }
+
+ void Connect(rtc::PacketTransportInternal* packet_transport) override {
+ packet_transport_ = packet_transport;
+ }
+
+ CongestionControlInterface* congestion_control() override {
+ return nullptr; // Datagram interface doesn't provide this yet.
+ }
+
+ void SetTransportStateCallback(
+ MediaTransportStateCallback* callback) override {
+ state_callback_ = callback;
+ }
+
+ RTCError SendDatagram(rtc::ArrayView<const uint8_t> data,
+ DatagramId datagram_id) override {
+ return RTCError::OK();
+ }
+
+ size_t GetLargestDatagramSize() const override {
+ return kMaxFakeDatagramSize;
+ }
+
+ void SetDatagramSink(DatagramSinkInterface* sink) override {}
+
+ std::string GetTransportParameters() const override {
+ if (settings_.remote_transport_parameters) {
+ return *settings_.remote_transport_parameters;
+ }
+ return transport_parameters_;
+ }
+
+ rtc::PacketTransportInternal* packet_transport() { return packet_transport_; }
+
+ void set_state(webrtc::MediaTransportState state) {
+ if (state_callback_) {
+ state_callback_->OnStateChanged(state);
+ }
+ }
+
+ const MediaTransportSettings& settings() { return settings_; }
+
+ private:
+ const MediaTransportSettings settings_;
+ const std::string transport_parameters_;
+
+ rtc::PacketTransportInternal* packet_transport_ = nullptr;
+ MediaTransportStateCallback* state_callback_ = nullptr;
+};
+
+} // namespace webrtc
+
+#endif // API_TEST_FAKE_DATAGRAM_TRANSPORT_H_
diff --git a/api/test/fake_media_transport.h b/api/test/fake_media_transport.h
index ef8284c..38b94c9 100644
--- a/api/test/fake_media_transport.h
+++ b/api/test/fake_media_transport.h
@@ -19,6 +19,7 @@
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "api/media_transport_interface.h"
+#include "api/test/fake_datagram_transport.h"
namespace webrtc {
@@ -146,6 +147,8 @@
};
// Fake media transport factory creates fake media transport.
+// Also creates fake datagram transport, since both media and datagram
+// transports are created by |MediaTransportFactory|.
class FakeMediaTransportFactory : public MediaTransportFactory {
public:
explicit FakeMediaTransportFactory(
@@ -174,6 +177,13 @@
return std::move(media_transport);
}
+ RTCErrorOr<std::unique_ptr<DatagramTransportInterface>>
+ CreateDatagramTransport(rtc::Thread* network_thread,
+ const MediaTransportSettings& settings) override {
+ return std::unique_ptr<DatagramTransportInterface>(
+ new FakeDatagramTransport(settings, transport_offer_.value_or("")));
+ }
+
private:
const absl::optional<std::string> transport_offer_;
};