1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2019 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 #include "test/peer_scenario/signaling_route.h"
11*d9f75844SAndroid Build Coastguard Worker
12*d9f75844SAndroid Build Coastguard Worker #include <memory>
13*d9f75844SAndroid Build Coastguard Worker
14*d9f75844SAndroid Build Coastguard Worker #include "test/network/network_emulation_manager.h"
15*d9f75844SAndroid Build Coastguard Worker
16*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
17*d9f75844SAndroid Build Coastguard Worker namespace test {
18*d9f75844SAndroid Build Coastguard Worker namespace {
19*d9f75844SAndroid Build Coastguard Worker constexpr size_t kIcePacketSize = 400;
20*d9f75844SAndroid Build Coastguard Worker constexpr size_t kSdpPacketSize = 1200;
21*d9f75844SAndroid Build Coastguard Worker
22*d9f75844SAndroid Build Coastguard Worker struct IceMessage {
23*d9f75844SAndroid Build Coastguard Worker IceMessage() = default;
IceMessagewebrtc::test::__anonc49b6e180111::IceMessage24*d9f75844SAndroid Build Coastguard Worker explicit IceMessage(const IceCandidateInterface* candidate)
25*d9f75844SAndroid Build Coastguard Worker : sdp_mid(candidate->sdp_mid()),
26*d9f75844SAndroid Build Coastguard Worker sdp_mline_index(candidate->sdp_mline_index()) {
27*d9f75844SAndroid Build Coastguard Worker RTC_CHECK(candidate->ToString(&sdp_line));
28*d9f75844SAndroid Build Coastguard Worker }
AsCandidatewebrtc::test::__anonc49b6e180111::IceMessage29*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<IceCandidateInterface> AsCandidate() const {
30*d9f75844SAndroid Build Coastguard Worker SdpParseError err;
31*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<IceCandidateInterface> candidate(
32*d9f75844SAndroid Build Coastguard Worker CreateIceCandidate(sdp_mid, sdp_mline_index, sdp_line, &err));
33*d9f75844SAndroid Build Coastguard Worker RTC_CHECK(candidate) << "Failed to parse: \"" << err.line
34*d9f75844SAndroid Build Coastguard Worker << "\". Reason: " << err.description;
35*d9f75844SAndroid Build Coastguard Worker return candidate;
36*d9f75844SAndroid Build Coastguard Worker }
37*d9f75844SAndroid Build Coastguard Worker std::string sdp_mid;
38*d9f75844SAndroid Build Coastguard Worker int sdp_mline_index;
39*d9f75844SAndroid Build Coastguard Worker std::string sdp_line;
40*d9f75844SAndroid Build Coastguard Worker };
41*d9f75844SAndroid Build Coastguard Worker
StartIceSignalingForRoute(PeerScenarioClient * caller,PeerScenarioClient * callee,CrossTrafficRoute * send_route)42*d9f75844SAndroid Build Coastguard Worker void StartIceSignalingForRoute(PeerScenarioClient* caller,
43*d9f75844SAndroid Build Coastguard Worker PeerScenarioClient* callee,
44*d9f75844SAndroid Build Coastguard Worker CrossTrafficRoute* send_route) {
45*d9f75844SAndroid Build Coastguard Worker caller->handlers()->on_ice_candidate.push_back(
46*d9f75844SAndroid Build Coastguard Worker [=](const IceCandidateInterface* candidate) {
47*d9f75844SAndroid Build Coastguard Worker IceMessage msg(candidate);
48*d9f75844SAndroid Build Coastguard Worker send_route->NetworkDelayedAction(kIcePacketSize, [callee, msg]() {
49*d9f75844SAndroid Build Coastguard Worker callee->thread()->PostTask(
50*d9f75844SAndroid Build Coastguard Worker [callee, msg]() { callee->AddIceCandidate(msg.AsCandidate()); });
51*d9f75844SAndroid Build Coastguard Worker });
52*d9f75844SAndroid Build Coastguard Worker });
53*d9f75844SAndroid Build Coastguard Worker }
54*d9f75844SAndroid Build Coastguard Worker
StartSdpNegotiation(PeerScenarioClient * caller,PeerScenarioClient * callee,CrossTrafficRoute * send_route,CrossTrafficRoute * ret_route,std::function<void (SessionDescriptionInterface * offer)> munge_offer,std::function<void (SessionDescriptionInterface *)> modify_offer,std::function<void (const SessionDescriptionInterface &)> exchange_finished)55*d9f75844SAndroid Build Coastguard Worker void StartSdpNegotiation(
56*d9f75844SAndroid Build Coastguard Worker PeerScenarioClient* caller,
57*d9f75844SAndroid Build Coastguard Worker PeerScenarioClient* callee,
58*d9f75844SAndroid Build Coastguard Worker CrossTrafficRoute* send_route,
59*d9f75844SAndroid Build Coastguard Worker CrossTrafficRoute* ret_route,
60*d9f75844SAndroid Build Coastguard Worker std::function<void(SessionDescriptionInterface* offer)> munge_offer,
61*d9f75844SAndroid Build Coastguard Worker std::function<void(SessionDescriptionInterface*)> modify_offer,
62*d9f75844SAndroid Build Coastguard Worker std::function<void(const SessionDescriptionInterface&)> exchange_finished) {
63*d9f75844SAndroid Build Coastguard Worker caller->CreateAndSetSdp(munge_offer, [=](std::string sdp_offer) {
64*d9f75844SAndroid Build Coastguard Worker if (modify_offer) {
65*d9f75844SAndroid Build Coastguard Worker auto offer = CreateSessionDescription(SdpType::kOffer, sdp_offer);
66*d9f75844SAndroid Build Coastguard Worker modify_offer(offer.get());
67*d9f75844SAndroid Build Coastguard Worker RTC_CHECK(offer->ToString(&sdp_offer));
68*d9f75844SAndroid Build Coastguard Worker }
69*d9f75844SAndroid Build Coastguard Worker send_route->NetworkDelayedAction(kSdpPacketSize, [=] {
70*d9f75844SAndroid Build Coastguard Worker callee->SetSdpOfferAndGetAnswer(sdp_offer, [=](std::string answer) {
71*d9f75844SAndroid Build Coastguard Worker ret_route->NetworkDelayedAction(kSdpPacketSize, [=] {
72*d9f75844SAndroid Build Coastguard Worker caller->SetSdpAnswer(std::move(answer), std::move(exchange_finished));
73*d9f75844SAndroid Build Coastguard Worker });
74*d9f75844SAndroid Build Coastguard Worker });
75*d9f75844SAndroid Build Coastguard Worker });
76*d9f75844SAndroid Build Coastguard Worker });
77*d9f75844SAndroid Build Coastguard Worker }
78*d9f75844SAndroid Build Coastguard Worker } // namespace
79*d9f75844SAndroid Build Coastguard Worker
SignalingRoute(PeerScenarioClient * caller,PeerScenarioClient * callee,CrossTrafficRoute * send_route,CrossTrafficRoute * ret_route)80*d9f75844SAndroid Build Coastguard Worker SignalingRoute::SignalingRoute(PeerScenarioClient* caller,
81*d9f75844SAndroid Build Coastguard Worker PeerScenarioClient* callee,
82*d9f75844SAndroid Build Coastguard Worker CrossTrafficRoute* send_route,
83*d9f75844SAndroid Build Coastguard Worker CrossTrafficRoute* ret_route)
84*d9f75844SAndroid Build Coastguard Worker : caller_(caller),
85*d9f75844SAndroid Build Coastguard Worker callee_(callee),
86*d9f75844SAndroid Build Coastguard Worker send_route_(send_route),
87*d9f75844SAndroid Build Coastguard Worker ret_route_(ret_route) {}
88*d9f75844SAndroid Build Coastguard Worker
StartIceSignaling()89*d9f75844SAndroid Build Coastguard Worker void SignalingRoute::StartIceSignaling() {
90*d9f75844SAndroid Build Coastguard Worker StartIceSignalingForRoute(caller_, callee_, send_route_);
91*d9f75844SAndroid Build Coastguard Worker StartIceSignalingForRoute(callee_, caller_, ret_route_);
92*d9f75844SAndroid Build Coastguard Worker }
93*d9f75844SAndroid Build Coastguard Worker
NegotiateSdp(std::function<void (SessionDescriptionInterface *)> munge_offer,std::function<void (SessionDescriptionInterface *)> modify_offer,std::function<void (const SessionDescriptionInterface &)> exchange_finished)94*d9f75844SAndroid Build Coastguard Worker void SignalingRoute::NegotiateSdp(
95*d9f75844SAndroid Build Coastguard Worker std::function<void(SessionDescriptionInterface*)> munge_offer,
96*d9f75844SAndroid Build Coastguard Worker std::function<void(SessionDescriptionInterface*)> modify_offer,
97*d9f75844SAndroid Build Coastguard Worker std::function<void(const SessionDescriptionInterface&)> exchange_finished) {
98*d9f75844SAndroid Build Coastguard Worker StartSdpNegotiation(caller_, callee_, send_route_, ret_route_, munge_offer,
99*d9f75844SAndroid Build Coastguard Worker modify_offer, exchange_finished);
100*d9f75844SAndroid Build Coastguard Worker }
101*d9f75844SAndroid Build Coastguard Worker
NegotiateSdp(std::function<void (SessionDescriptionInterface *)> modify_offer,std::function<void (const SessionDescriptionInterface &)> exchange_finished)102*d9f75844SAndroid Build Coastguard Worker void SignalingRoute::NegotiateSdp(
103*d9f75844SAndroid Build Coastguard Worker std::function<void(SessionDescriptionInterface*)> modify_offer,
104*d9f75844SAndroid Build Coastguard Worker std::function<void(const SessionDescriptionInterface&)> exchange_finished) {
105*d9f75844SAndroid Build Coastguard Worker NegotiateSdp({}, modify_offer, exchange_finished);
106*d9f75844SAndroid Build Coastguard Worker }
107*d9f75844SAndroid Build Coastguard Worker
NegotiateSdp(std::function<void (const SessionDescriptionInterface &)> exchange_finished)108*d9f75844SAndroid Build Coastguard Worker void SignalingRoute::NegotiateSdp(
109*d9f75844SAndroid Build Coastguard Worker std::function<void(const SessionDescriptionInterface&)> exchange_finished) {
110*d9f75844SAndroid Build Coastguard Worker NegotiateSdp({}, {}, exchange_finished);
111*d9f75844SAndroid Build Coastguard Worker }
112*d9f75844SAndroid Build Coastguard Worker
113*d9f75844SAndroid Build Coastguard Worker } // namespace test
114*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc
115