Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(695)

Side by Side Diff: webrtc/p2p/base/fakeportallocator.h

Issue 1956453003: Relanding: Implement RTCConfiguration.iceCandidatePoolSize. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2010 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_P2P_CLIENT_FAKEPORTALLOCATOR_H_ 11 #ifndef WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
12 #define WEBRTC_P2P_CLIENT_FAKEPORTALLOCATOR_H_ 12 #define WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
13 13
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <vector>
16 17
17 #include "webrtc/p2p/base/basicpacketsocketfactory.h" 18 #include "webrtc/p2p/base/basicpacketsocketfactory.h"
18 #include "webrtc/p2p/base/portallocator.h" 19 #include "webrtc/p2p/base/portallocator.h"
19 #include "webrtc/p2p/base/udpport.h" 20 #include "webrtc/p2p/base/udpport.h"
20 #include "webrtc/base/scoped_ptr.h" 21 #include "webrtc/base/scoped_ptr.h"
21 22
22 namespace rtc { 23 namespace rtc {
23 class SocketFactory; 24 class SocketFactory;
24 class Thread; 25 class Thread;
25 } 26 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 origin, 80 origin,
80 emit_localhost_for_anyaddress) {} 81 emit_localhost_for_anyaddress) {}
81 82
82 bool sent_binding_response_ = false; 83 bool sent_binding_response_ = false;
83 }; 84 };
84 85
85 class FakePortAllocatorSession : public PortAllocatorSession { 86 class FakePortAllocatorSession : public PortAllocatorSession {
86 public: 87 public:
87 FakePortAllocatorSession(rtc::Thread* worker_thread, 88 FakePortAllocatorSession(rtc::Thread* worker_thread,
88 rtc::PacketSocketFactory* factory, 89 rtc::PacketSocketFactory* factory,
90 const ServerAddresses& stun_servers,
91 const std::vector<RelayServerConfig>& turn_servers,
89 const std::string& content_name, 92 const std::string& content_name,
90 int component, 93 int component,
91 const std::string& ice_ufrag, 94 const std::string& ice_ufrag,
92 const std::string& ice_pwd) 95 const std::string& ice_pwd)
93 : PortAllocatorSession(content_name, component, ice_ufrag, ice_pwd, 96 : PortAllocatorSession(content_name,
97 component,
98 ice_ufrag,
99 ice_pwd,
94 cricket::kDefaultPortAllocatorFlags), 100 cricket::kDefaultPortAllocatorFlags),
95 worker_thread_(worker_thread), 101 worker_thread_(worker_thread),
96 factory_(factory), 102 factory_(factory),
97 network_("network", "unittest", 103 network_("network", "unittest", rtc::IPAddress(INADDR_LOOPBACK), 8),
98 rtc::IPAddress(INADDR_LOOPBACK), 8), 104 port_(),
99 port_(), running_(false), 105 running_(false),
100 port_config_count_(0) { 106 port_config_count_(0),
107 stun_servers_(stun_servers),
108 turn_servers_(turn_servers) {
Taylor Brandstetter 2016/05/05 19:56:22 I started passing the servers into the fake sessio
101 network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); 109 network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK));
102 } 110 }
103 111
104 virtual void StartGettingPorts() { 112 void StartGettingPorts() override {
105 if (!port_) { 113 if (!port_) {
106 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network_, 114 port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network_,
107 network_.GetBestIP(), 0, 0, username(), 115 network_.GetBestIP(), 0, 0, username(),
108 password(), std::string(), false)); 116 password(), std::string(), false));
109 AddPort(port_.get()); 117 AddPort(port_.get());
110 } 118 }
111 ++port_config_count_; 119 ++port_config_count_;
112 running_ = true; 120 running_ = true;
113 } 121 }
114 122
115 virtual void StopGettingPorts() { running_ = false; } 123 void StopGettingPorts() override { running_ = false; }
116 virtual bool IsGettingPorts() { return running_; } 124 bool IsGettingPorts() override { return running_; }
117 virtual void ClearGettingPorts() {} 125 void ClearGettingPorts() override {}
126 std::vector<PortInterface*> ReadyPorts() const override {
127 return ready_ports_;
pthatcher1 2016/05/05 21:51:24 ready_ports()?
Taylor Brandstetter 2016/05/06 03:53:34 An underscore name implies it's a trivial method.
128 }
129 std::vector<Candidate> ReadyCandidates() const override {
130 return candidates_;
pthatcher1 2016/05/05 21:51:24 candidates()?
Taylor Brandstetter 2016/05/06 03:53:34 See above. I called it ReadyCandidates so that we
131 }
132 bool CandidatesAllocationDone() const override { return allocation_done_; }
pthatcher1 2016/05/05 21:51:24 allocation_done()?
Taylor Brandstetter 2016/05/06 03:53:34 See above.
118 133
119 int port_config_count() { return port_config_count_; } 134 int port_config_count() { return port_config_count_; }
120 135
136 const ServerAddresses& stun_servers() const { return stun_servers_; }
137
138 const std::vector<RelayServerConfig>& turn_servers() const {
139 return turn_servers_;
140 }
141
121 void AddPort(cricket::Port* port) { 142 void AddPort(cricket::Port* port) {
122 port->set_component(component_); 143 port->set_component(component());
123 port->set_generation(0); 144 port->set_generation(0);
124 port->SignalPortComplete.connect( 145 port->SignalPortComplete.connect(this,
125 this, &FakePortAllocatorSession::OnPortComplete); 146 &FakePortAllocatorSession::OnPortComplete);
126 port->PrepareAddress(); 147 port->PrepareAddress();
148 ready_ports_.push_back(port);
127 SignalPortReady(this, port); 149 SignalPortReady(this, port);
128 } 150 }
129 void OnPortComplete(cricket::Port* port) { 151 void OnPortComplete(cricket::Port* port) {
130 SignalCandidatesReady(this, port->Candidates()); 152 const std::vector<Candidate>& candidates = port->Candidates();
153 candidates_.insert(candidates_.end(), candidates.begin(), candidates.end());
154 SignalCandidatesReady(this, candidates);
155
156 allocation_done_ = true;
131 SignalCandidatesAllocationDone(this); 157 SignalCandidatesAllocationDone(this);
132 } 158 }
133 159
160 int transport_info_updates() const { return transport_info_updates_; }
pthatcher1 2016/05/05 21:51:24 transport_info_update_count_?
Taylor Brandstetter 2016/05/06 03:53:34 Done.
161
162 protected:
163 void UpdateTransportInformationInternal() override {
164 // Since this class is a fake and this method only is overridden for tests,
165 // we don't need to actually update the transport info.
166 ++transport_info_updates_;
167 }
168
134 private: 169 private:
135 rtc::Thread* worker_thread_; 170 rtc::Thread* worker_thread_;
136 rtc::PacketSocketFactory* factory_; 171 rtc::PacketSocketFactory* factory_;
137 rtc::Network network_; 172 rtc::Network network_;
138 std::unique_ptr<cricket::Port> port_; 173 std::unique_ptr<cricket::Port> port_;
139 bool running_; 174 bool running_;
140 int port_config_count_; 175 int port_config_count_;
176 std::vector<Candidate> candidates_;
177 std::vector<PortInterface*> ready_ports_;
178 bool allocation_done_ = false;
179 ServerAddresses stun_servers_;
180 std::vector<RelayServerConfig> turn_servers_;
181 int transport_info_updates_ = 0;
141 }; 182 };
142 183
143 class FakePortAllocator : public cricket::PortAllocator { 184 class FakePortAllocator : public cricket::PortAllocator {
144 public: 185 public:
145 FakePortAllocator(rtc::Thread* worker_thread, 186 FakePortAllocator(rtc::Thread* worker_thread,
146 rtc::PacketSocketFactory* factory) 187 rtc::PacketSocketFactory* factory)
147 : worker_thread_(worker_thread), factory_(factory) { 188 : worker_thread_(worker_thread), factory_(factory) {
148 if (factory_ == NULL) { 189 if (factory_ == NULL) {
149 owned_factory_.reset(new rtc::BasicPacketSocketFactory( 190 owned_factory_.reset(new rtc::BasicPacketSocketFactory(worker_thread_));
150 worker_thread_));
151 factory_ = owned_factory_.get(); 191 factory_ = owned_factory_.get();
152 } 192 }
153 } 193 }
154 194
155 void SetIceServers(
156 const ServerAddresses& stun_servers,
157 const std::vector<RelayServerConfig>& turn_servers) override {
158 stun_servers_ = stun_servers;
159 turn_servers_ = turn_servers;
160 }
161
162 void SetNetworkIgnoreMask(int network_ignore_mask) override {} 195 void SetNetworkIgnoreMask(int network_ignore_mask) override {}
163 196
164 const ServerAddresses& stun_servers() const { return stun_servers_; } 197 cricket::PortAllocatorSession* CreateSessionInternal(
165
166 const std::vector<RelayServerConfig>& turn_servers() const {
167 return turn_servers_;
168 }
169
170 virtual cricket::PortAllocatorSession* CreateSessionInternal(
171 const std::string& content_name, 198 const std::string& content_name,
172 int component, 199 int component,
173 const std::string& ice_ufrag, 200 const std::string& ice_ufrag,
174 const std::string& ice_pwd) override { 201 const std::string& ice_pwd) override {
175 return new FakePortAllocatorSession( 202 return new FakePortAllocatorSession(
176 worker_thread_, factory_, content_name, component, ice_ufrag, ice_pwd); 203 worker_thread_, factory_, stun_servers(), turn_servers(), content_name,
204 component, ice_ufrag, ice_pwd);
177 } 205 }
178 206
179 private: 207 private:
180 rtc::Thread* worker_thread_; 208 rtc::Thread* worker_thread_;
181 rtc::PacketSocketFactory* factory_; 209 rtc::PacketSocketFactory* factory_;
182 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_; 210 std::unique_ptr<rtc::BasicPacketSocketFactory> owned_factory_;
183 ServerAddresses stun_servers_;
184 std::vector<RelayServerConfig> turn_servers_;
185 }; 211 };
186 212
187 } // namespace cricket 213 } // namespace cricket
188 214
189 #endif // WEBRTC_P2P_CLIENT_FAKEPORTALLOCATOR_H_ 215 #endif // WEBRTC_P2P_BASE_FAKEPORTALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698