Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "pc/peer_connection_wrapper.h" |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 15 | #include <utility> |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 16 | #include <vector> |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 17 | |
Artem Titov | 741daaf | 2019-03-21 14:37:36 +0100 | [diff] [blame] | 18 | #include "api/function_view.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "api/set_remote_description_observer_interface.h" |
| 20 | #include "pc/sdp_utils.h" |
| 21 | #include "pc/test/fake_video_track_source.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "rtc_base/checks.h" |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 23 | #include "rtc_base/gunit.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 24 | #include "rtc_base/logging.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 25 | #include "test/gtest.h" |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 29 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
| 30 | |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 31 | namespace { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 32 | const uint32_t kDefaultTimeout = 10000U; |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | PeerConnectionWrapper::PeerConnectionWrapper( |
| 36 | rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory, |
| 37 | rtc::scoped_refptr<PeerConnectionInterface> pc, |
| 38 | std::unique_ptr<MockPeerConnectionObserver> observer) |
Mirko Bonadei | 2a82310 | 2017-11-13 11:50:33 +0100 | [diff] [blame] | 39 | : pc_factory_(std::move(pc_factory)), |
| 40 | observer_(std::move(observer)), |
| 41 | pc_(std::move(pc)) { |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 42 | RTC_DCHECK(pc_factory_); |
| 43 | RTC_DCHECK(pc_); |
| 44 | RTC_DCHECK(observer_); |
| 45 | observer_->SetPeerConnectionInterface(pc_.get()); |
| 46 | } |
| 47 | |
Tomas Gunnarsson | 2efb8a5 | 2021-04-01 16:26:57 +0200 | [diff] [blame] | 48 | PeerConnectionWrapper::~PeerConnectionWrapper() { |
| 49 | if (pc_) |
| 50 | pc_->Close(); |
| 51 | } |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 52 | |
| 53 | PeerConnectionFactoryInterface* PeerConnectionWrapper::pc_factory() { |
| 54 | return pc_factory_.get(); |
| 55 | } |
| 56 | |
| 57 | PeerConnectionInterface* PeerConnectionWrapper::pc() { |
| 58 | return pc_.get(); |
| 59 | } |
| 60 | |
| 61 | MockPeerConnectionObserver* PeerConnectionWrapper::observer() { |
| 62 | return observer_.get(); |
| 63 | } |
| 64 | |
| 65 | std::unique_ptr<SessionDescriptionInterface> |
| 66 | PeerConnectionWrapper::CreateOffer() { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 67 | return CreateOffer(RTCOfferAnswerOptions()); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | std::unique_ptr<SessionDescriptionInterface> PeerConnectionWrapper::CreateOffer( |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 71 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 72 | std::string* error_out) { |
| 73 | return CreateSdp( |
| 74 | [this, options](CreateSessionDescriptionObserver* observer) { |
| 75 | pc()->CreateOffer(observer, options); |
| 76 | }, |
| 77 | error_out); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | std::unique_ptr<SessionDescriptionInterface> |
| 81 | PeerConnectionWrapper::CreateOfferAndSetAsLocal() { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 82 | return CreateOfferAndSetAsLocal(RTCOfferAnswerOptions()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | std::unique_ptr<SessionDescriptionInterface> |
| 86 | PeerConnectionWrapper::CreateOfferAndSetAsLocal( |
| 87 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 88 | auto offer = CreateOffer(options); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 89 | if (!offer) { |
| 90 | return nullptr; |
| 91 | } |
| 92 | EXPECT_TRUE(SetLocalDescription(CloneSessionDescription(offer.get()))); |
| 93 | return offer; |
| 94 | } |
| 95 | |
| 96 | std::unique_ptr<SessionDescriptionInterface> |
| 97 | PeerConnectionWrapper::CreateAnswer() { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 98 | return CreateAnswer(RTCOfferAnswerOptions()); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | std::unique_ptr<SessionDescriptionInterface> |
| 102 | PeerConnectionWrapper::CreateAnswer( |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 103 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 104 | std::string* error_out) { |
| 105 | return CreateSdp( |
| 106 | [this, options](CreateSessionDescriptionObserver* observer) { |
| 107 | pc()->CreateAnswer(observer, options); |
| 108 | }, |
| 109 | error_out); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | std::unique_ptr<SessionDescriptionInterface> |
| 113 | PeerConnectionWrapper::CreateAnswerAndSetAsLocal() { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 114 | return CreateAnswerAndSetAsLocal(RTCOfferAnswerOptions()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | std::unique_ptr<SessionDescriptionInterface> |
| 118 | PeerConnectionWrapper::CreateAnswerAndSetAsLocal( |
| 119 | const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 120 | auto answer = CreateAnswer(options); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 121 | if (!answer) { |
| 122 | return nullptr; |
| 123 | } |
| 124 | EXPECT_TRUE(SetLocalDescription(CloneSessionDescription(answer.get()))); |
| 125 | return answer; |
| 126 | } |
| 127 | |
Eldar Rello | 5ab79e6 | 2019-10-09 18:29:44 +0300 | [diff] [blame] | 128 | std::unique_ptr<SessionDescriptionInterface> |
| 129 | PeerConnectionWrapper::CreateRollback() { |
| 130 | return CreateSessionDescription(SdpType::kRollback, ""); |
| 131 | } |
| 132 | |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 133 | std::unique_ptr<SessionDescriptionInterface> PeerConnectionWrapper::CreateSdp( |
Mirko Bonadei | 2a82310 | 2017-11-13 11:50:33 +0100 | [diff] [blame] | 134 | rtc::FunctionView<void(CreateSessionDescriptionObserver*)> fn, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 135 | std::string* error_out) { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 136 | auto observer = rtc::make_ref_counted<MockCreateSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 137 | fn(observer.get()); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 138 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 139 | if (error_out && !observer->result()) { |
| 140 | *error_out = observer->error(); |
| 141 | } |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 142 | return observer->MoveDescription(); |
| 143 | } |
| 144 | |
| 145 | bool PeerConnectionWrapper::SetLocalDescription( |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 146 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 147 | std::string* error_out) { |
| 148 | return SetSdp( |
| 149 | [this, &desc](SetSessionDescriptionObserver* observer) { |
| 150 | pc()->SetLocalDescription(observer, desc.release()); |
| 151 | }, |
| 152 | error_out); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | bool PeerConnectionWrapper::SetRemoteDescription( |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 156 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 157 | std::string* error_out) { |
| 158 | return SetSdp( |
| 159 | [this, &desc](SetSessionDescriptionObserver* observer) { |
| 160 | pc()->SetRemoteDescription(observer, desc.release()); |
| 161 | }, |
| 162 | error_out); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 165 | bool PeerConnectionWrapper::SetRemoteDescription( |
| 166 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 167 | RTCError* error_out) { |
Niels Möller | e7cc883 | 2022-01-04 15:20:03 +0100 | [diff] [blame] | 168 | auto observer = rtc::make_ref_counted<FakeSetRemoteDescriptionObserver>(); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 169 | pc()->SetRemoteDescription(std::move(desc), observer); |
| 170 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
| 171 | bool ok = observer->error().ok(); |
| 172 | if (error_out) |
| 173 | *error_out = std::move(observer->error()); |
| 174 | return ok; |
| 175 | } |
| 176 | |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 177 | bool PeerConnectionWrapper::SetSdp( |
Mirko Bonadei | 2a82310 | 2017-11-13 11:50:33 +0100 | [diff] [blame] | 178 | rtc::FunctionView<void(SetSessionDescriptionObserver*)> fn, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 179 | std::string* error_out) { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 180 | auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 181 | fn(observer.get()); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 182 | EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 183 | if (error_out && !observer->result()) { |
| 184 | *error_out = observer->error(); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 185 | } |
| 186 | return observer->result(); |
| 187 | } |
| 188 | |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 189 | bool PeerConnectionWrapper::ExchangeOfferAnswerWith( |
| 190 | PeerConnectionWrapper* answerer) { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 191 | return ExchangeOfferAnswerWith(answerer, RTCOfferAnswerOptions(), |
| 192 | RTCOfferAnswerOptions()); |
| 193 | } |
| 194 | |
| 195 | bool PeerConnectionWrapper::ExchangeOfferAnswerWith( |
| 196 | PeerConnectionWrapper* answerer, |
| 197 | const PeerConnectionInterface::RTCOfferAnswerOptions& offer_options, |
| 198 | const PeerConnectionInterface::RTCOfferAnswerOptions& answer_options) { |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 199 | RTC_DCHECK(answerer); |
| 200 | if (answerer == this) { |
| 201 | RTC_LOG(LS_ERROR) << "Cannot exchange offer/answer with ourself!"; |
| 202 | return false; |
| 203 | } |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 204 | auto offer = CreateOffer(offer_options); |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 205 | EXPECT_TRUE(offer); |
| 206 | if (!offer) { |
| 207 | return false; |
| 208 | } |
| 209 | bool set_local_offer = |
| 210 | SetLocalDescription(CloneSessionDescription(offer.get())); |
| 211 | EXPECT_TRUE(set_local_offer); |
| 212 | if (!set_local_offer) { |
| 213 | return false; |
| 214 | } |
| 215 | bool set_remote_offer = answerer->SetRemoteDescription(std::move(offer)); |
| 216 | EXPECT_TRUE(set_remote_offer); |
| 217 | if (!set_remote_offer) { |
| 218 | return false; |
| 219 | } |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 220 | auto answer = answerer->CreateAnswer(answer_options); |
Steve Anton | dcc3c02 | 2017-12-22 16:02:54 -0800 | [diff] [blame] | 221 | EXPECT_TRUE(answer); |
| 222 | if (!answer) { |
| 223 | return false; |
| 224 | } |
| 225 | bool set_local_answer = |
| 226 | answerer->SetLocalDescription(CloneSessionDescription(answer.get())); |
| 227 | EXPECT_TRUE(set_local_answer); |
| 228 | if (!set_local_answer) { |
| 229 | return false; |
| 230 | } |
| 231 | bool set_remote_answer = SetRemoteDescription(std::move(answer)); |
| 232 | EXPECT_TRUE(set_remote_answer); |
| 233 | return set_remote_answer; |
| 234 | } |
| 235 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 236 | rtc::scoped_refptr<RtpTransceiverInterface> |
| 237 | PeerConnectionWrapper::AddTransceiver(cricket::MediaType media_type) { |
| 238 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 239 | pc()->AddTransceiver(media_type); |
| 240 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
| 241 | return result.MoveValue(); |
| 242 | } |
| 243 | |
| 244 | rtc::scoped_refptr<RtpTransceiverInterface> |
| 245 | PeerConnectionWrapper::AddTransceiver(cricket::MediaType media_type, |
| 246 | const RtpTransceiverInit& init) { |
| 247 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 248 | pc()->AddTransceiver(media_type, init); |
| 249 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
| 250 | return result.MoveValue(); |
| 251 | } |
| 252 | |
| 253 | rtc::scoped_refptr<RtpTransceiverInterface> |
| 254 | PeerConnectionWrapper::AddTransceiver( |
| 255 | rtc::scoped_refptr<MediaStreamTrackInterface> track) { |
| 256 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 257 | pc()->AddTransceiver(track); |
| 258 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
| 259 | return result.MoveValue(); |
| 260 | } |
| 261 | |
| 262 | rtc::scoped_refptr<RtpTransceiverInterface> |
| 263 | PeerConnectionWrapper::AddTransceiver( |
| 264 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 265 | const RtpTransceiverInit& init) { |
| 266 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 267 | pc()->AddTransceiver(track, init); |
| 268 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
| 269 | return result.MoveValue(); |
| 270 | } |
| 271 | |
| 272 | rtc::scoped_refptr<AudioTrackInterface> PeerConnectionWrapper::CreateAudioTrack( |
| 273 | const std::string& label) { |
| 274 | return pc_factory()->CreateAudioTrack(label, nullptr); |
| 275 | } |
| 276 | |
| 277 | rtc::scoped_refptr<VideoTrackInterface> PeerConnectionWrapper::CreateVideoTrack( |
| 278 | const std::string& label) { |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 279 | return pc_factory()->CreateVideoTrack(label, |
| 280 | FakeVideoTrackSource::Create().get()); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 283 | rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddTrack( |
| 284 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 285 | const std::vector<std::string>& stream_ids) { |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 286 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> result = |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 287 | pc()->AddTrack(track, stream_ids); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 288 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
| 289 | return result.MoveValue(); |
| 290 | } |
| 291 | |
Jonas Oreland | 4b2a106 | 2022-10-19 09:24:42 +0200 | [diff] [blame^] | 292 | rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddTrack( |
| 293 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 294 | const std::vector<std::string>& stream_ids, |
| 295 | const std::vector<RtpEncodingParameters>& init_send_encodings) { |
| 296 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> result = |
| 297 | pc()->AddTrack(track, stream_ids, init_send_encodings); |
| 298 | EXPECT_EQ(RTCErrorType::NONE, result.error().type()); |
| 299 | return result.MoveValue(); |
| 300 | } |
| 301 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 302 | rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddAudioTrack( |
| 303 | const std::string& track_label, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 304 | const std::vector<std::string>& stream_ids) { |
| 305 | return AddTrack(CreateAudioTrack(track_label), stream_ids); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 308 | rtc::scoped_refptr<RtpSenderInterface> PeerConnectionWrapper::AddVideoTrack( |
| 309 | const std::string& track_label, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 310 | const std::vector<std::string>& stream_ids) { |
| 311 | return AddTrack(CreateVideoTrack(track_label), stream_ids); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Steve Anton | fa2260d | 2017-12-28 16:38:23 -0800 | [diff] [blame] | 314 | rtc::scoped_refptr<DataChannelInterface> |
| 315 | PeerConnectionWrapper::CreateDataChannel(const std::string& label) { |
Harald Alvestrand | a9af50f | 2021-05-21 13:33:51 +0000 | [diff] [blame] | 316 | auto result = pc()->CreateDataChannelOrError(label, nullptr); |
| 317 | if (!result.ok()) { |
| 318 | RTC_LOG(LS_ERROR) << "CreateDataChannel failed: " |
| 319 | << ToString(result.error().type()) << " " |
| 320 | << result.error().message(); |
| 321 | return nullptr; |
| 322 | } |
| 323 | return result.MoveValue(); |
Steve Anton | fa2260d | 2017-12-28 16:38:23 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 326 | PeerConnectionInterface::SignalingState |
| 327 | PeerConnectionWrapper::signaling_state() { |
| 328 | return pc()->signaling_state(); |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 331 | bool PeerConnectionWrapper::IsIceGatheringDone() { |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 332 | return observer()->ice_gathering_complete_; |
| 333 | } |
| 334 | |
| 335 | bool PeerConnectionWrapper::IsIceConnected() { |
| 336 | return observer()->ice_connected_; |
| 337 | } |
| 338 | |
| 339 | rtc::scoped_refptr<const webrtc::RTCStatsReport> |
| 340 | PeerConnectionWrapper::GetStats() { |
Tommi | 87f7090 | 2021-04-27 14:43:08 +0200 | [diff] [blame] | 341 | auto callback = rtc::make_ref_counted<MockRTCStatsCollectorCallback>(); |
Niels Möller | afb246b | 2022-04-20 14:26:50 +0200 | [diff] [blame] | 342 | pc()->GetStats(callback.get()); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 343 | EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout); |
| 344 | return callback->report(); |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Steve Anton | 94286cb | 2017-09-26 16:20:19 -0700 | [diff] [blame] | 347 | } // namespace webrtc |