OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2017 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 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 rtc::Optional<int> GetRttEstimate() override { | 154 rtc::Optional<int> GetRttEstimate() override { |
155 return rtc::Optional<int>(); | 155 return rtc::Optional<int>(); |
156 } | 156 } |
157 | 157 |
158 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { | 158 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { |
159 } | 159 } |
160 | 160 |
161 // Fake PacketTransportInternal implementation. | 161 // Fake PacketTransportInternal implementation. |
162 bool writable() const override { return writable_; } | 162 bool writable() const override { return writable_; } |
163 bool receiving() const override { return receiving_; } | 163 bool receiving() const override { return receiving_; } |
| 164 // If combine is enabled, every two consecutive packets to be sent with |
| 165 // "SendPacket" will be combined into one outgoing packet. |
| 166 void combine_outgoing_packets(bool combine) { |
| 167 combine_outgoing_packets_ = combine; |
| 168 } |
164 int SendPacket(const char* data, | 169 int SendPacket(const char* data, |
165 size_t len, | 170 size_t len, |
166 const rtc::PacketOptions& options, | 171 const rtc::PacketOptions& options, |
167 int flags) override { | 172 int flags) override { |
168 if (!dest_) { | 173 if (!dest_) { |
169 return -1; | 174 return -1; |
170 } | 175 } |
171 rtc::CopyOnWriteBuffer packet(data, len); | 176 |
172 if (async_) { | 177 send_packet_.AppendData(data, len); |
173 invoker_.AsyncInvokeDelayed<void>( | 178 if (!combine_outgoing_packets_ || send_packet_.size() > len) { |
174 RTC_FROM_HERE, rtc::Thread::Current(), | 179 rtc::CopyOnWriteBuffer packet(std::move(send_packet_)); |
175 rtc::Bind(&FakeIceTransport::SendPacketInternal, this, packet), | 180 if (async_) { |
176 async_delay_ms_); | 181 invoker_.AsyncInvokeDelayed<void>( |
177 } else { | 182 RTC_FROM_HERE, rtc::Thread::Current(), |
178 SendPacketInternal(packet); | 183 rtc::Bind(&FakeIceTransport::SendPacketInternal, this, packet), |
| 184 async_delay_ms_); |
| 185 } else { |
| 186 SendPacketInternal(packet); |
| 187 } |
179 } | 188 } |
180 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); | 189 rtc::SentPacket sent_packet(options.packet_id, rtc::TimeMillis()); |
181 SignalSentPacket(this, sent_packet); | 190 SignalSentPacket(this, sent_packet); |
182 return static_cast<int>(len); | 191 return static_cast<int>(len); |
183 } | 192 } |
184 int SetOption(rtc::Socket::Option opt, int value) override { return true; } | 193 int SetOption(rtc::Socket::Option opt, int value) override { return true; } |
185 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } | 194 bool GetOption(rtc::Socket::Option opt, int* value) override { return true; } |
186 int GetError() override { return 0; } | 195 int GetError() override { return 0; } |
187 | 196 |
188 private: | 197 private: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 std::string ice_ufrag_; | 235 std::string ice_ufrag_; |
227 std::string ice_pwd_; | 236 std::string ice_pwd_; |
228 std::string remote_ice_ufrag_; | 237 std::string remote_ice_ufrag_; |
229 std::string remote_ice_pwd_; | 238 std::string remote_ice_pwd_; |
230 IceMode remote_ice_mode_ = ICEMODE_FULL; | 239 IceMode remote_ice_mode_ = ICEMODE_FULL; |
231 size_t connection_count_ = 0; | 240 size_t connection_count_ = 0; |
232 IceGatheringState gathering_state_ = kIceGatheringNew; | 241 IceGatheringState gathering_state_ = kIceGatheringNew; |
233 bool had_connection_ = false; | 242 bool had_connection_ = false; |
234 bool writable_ = false; | 243 bool writable_ = false; |
235 bool receiving_ = false; | 244 bool receiving_ = false; |
| 245 bool combine_outgoing_packets_ = false; |
| 246 rtc::CopyOnWriteBuffer send_packet_; |
236 }; | 247 }; |
237 | 248 |
238 } // namespace cricket | 249 } // namespace cricket |
239 | 250 |
240 #endif // WEBRTC_P2P_BASE_FAKEICETRANSPORT_H_ | 251 #endif // WEBRTC_P2P_BASE_FAKEICETRANSPORT_H_ |
OLD | NEW |