From eccd93e89262cd5664d4a777ed78f50f624a2553 Mon Sep 17 00:00:00 2001 From: Jeremy Leconte Date: Fri, 10 Feb 2023 09:26:50 +0100 Subject: [PATCH] Enable the use of CreateDataChannel with a DataChannelInit config. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie9b783464c7b4f6c2d5624a96221f266531acbe9 Bug: b/267359410 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/292861 Reviewed-by: Artem Titov Reviewed-by: Henrik Boström Commit-Queue: Jeremy Leconte Cr-Commit-Position: refs/heads/main@{#39293} --- pc/BUILD.gn | 1 + pc/peer_connection_wrapper.cc | 8 ++++++-- pc/peer_connection_wrapper.h | 4 +++- test/pc/e2e/BUILD.gn | 1 + test/pc/e2e/test_peer.h | 6 ++++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 4411fce723..41b2e7e4c2 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -2269,6 +2269,7 @@ if (rtc_include_tests && !build_with_chromium) { "../rtc_base:logging", "../test:test_support", ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_test("slow_peer_connection_unittests") { diff --git a/pc/peer_connection_wrapper.cc b/pc/peer_connection_wrapper.cc index 653d8b7b0d..2fbca1dd07 100644 --- a/pc/peer_connection_wrapper.cc +++ b/pc/peer_connection_wrapper.cc @@ -15,6 +15,7 @@ #include #include +#include "absl/types/optional.h" #include "api/function_view.h" #include "api/set_remote_description_observer_interface.h" #include "pc/sdp_utils.h" @@ -312,8 +313,11 @@ rtc::scoped_refptr PeerConnectionWrapper::AddVideoTrack( } rtc::scoped_refptr -PeerConnectionWrapper::CreateDataChannel(const std::string& label) { - auto result = pc()->CreateDataChannelOrError(label, nullptr); +PeerConnectionWrapper::CreateDataChannel( + const std::string& label, + const absl::optional& config) { + const DataChannelInit* config_ptr = config.has_value() ? &(*config) : nullptr; + auto result = pc()->CreateDataChannelOrError(label, config_ptr); if (!result.ok()) { RTC_LOG(LS_ERROR) << "CreateDataChannel failed: " << ToString(result.error().type()) << " " diff --git a/pc/peer_connection_wrapper.h b/pc/peer_connection_wrapper.h index c503a48099..bf40bbcfb8 100644 --- a/pc/peer_connection_wrapper.h +++ b/pc/peer_connection_wrapper.h @@ -15,6 +15,7 @@ #include #include +#include "absl/types/optional.h" #include "api/data_channel_interface.h" #include "api/function_view.h" #include "api/jsep.h" @@ -169,7 +170,8 @@ class PeerConnectionWrapper { // Calls the underlying PeerConnection's CreateDataChannel method with default // initialization parameters. rtc::scoped_refptr CreateDataChannel( - const std::string& label); + const std::string& label, + const absl::optional& config = absl::nullopt); // Returns the signaling state of the underlying PeerConnection. PeerConnectionInterface::SignalingState signaling_state(); diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index 7354aa8ba4..11616d0bf9 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -80,6 +80,7 @@ if (!build_with_chromium) { absl_deps = [ "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:variant", ] } diff --git a/test/pc/e2e/test_peer.h b/test/pc/e2e/test_peer.h index 1088871817..1ce2acbdf0 100644 --- a/test/pc/e2e/test_peer.h +++ b/test/pc/e2e/test_peer.h @@ -16,6 +16,7 @@ #include "absl/memory/memory.h" #include "absl/strings/string_view.h" +#include "absl/types/optional.h" #include "api/function_view.h" #include "api/scoped_refptr.h" #include "api/sequence_checker.h" @@ -109,9 +110,10 @@ class TestPeer final : public StatsProvider { } rtc::scoped_refptr CreateDataChannel( - const std::string& label) { + const std::string& label, + const absl::optional& config = absl::nullopt) { RTC_CHECK(wrapper_) << "TestPeer is already closed"; - return wrapper_->CreateDataChannel(label); + return wrapper_->CreateDataChannel(label, config); } PeerConnectionInterface::SignalingState signaling_state() {