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