OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include "webrtc/test/fake_network_pipe.h" | 11 #include "webrtc/test/fake_network_pipe.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <math.h> | 14 #include <math.h> |
15 #include <string.h> | 15 #include <string.h> |
16 | 16 |
17 #include <algorithm> | 17 #include <algorithm> |
18 #include <cmath> | 18 #include <cmath> |
19 | 19 |
20 #include "webrtc/base/logging.h" | 20 #include "webrtc/base/logging.h" |
21 #include "webrtc/call/call.h" | 21 #include "webrtc/call/call.h" |
22 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | |
22 #include "webrtc/system_wrappers/include/clock.h" | 23 #include "webrtc/system_wrappers/include/clock.h" |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
25 | 26 |
26 namespace { | 27 namespace { |
27 constexpr int64_t kDefaultProcessIntervalMs = 5; | 28 constexpr int64_t kDefaultProcessIntervalMs = 5; |
28 } | 29 } |
29 | 30 |
30 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 31 FakeNetworkPipe::FakeNetworkPipe( |
31 const FakeNetworkPipe::Config& config, | 32 Clock* clock, |
32 MediaType media_type) | 33 const FakeNetworkPipe::Config& config, |
33 : FakeNetworkPipe(clock, config, media_type, 1) {} | 34 const std::map<uint8_t, MediaType>& payload_type_map) |
35 : FakeNetworkPipe(clock, config, payload_type_map, 1) {} | |
34 | 36 |
35 FakeNetworkPipe::FakeNetworkPipe(Clock* clock, | 37 FakeNetworkPipe::FakeNetworkPipe( |
36 const FakeNetworkPipe::Config& config, | 38 Clock* clock, |
37 MediaType media_type, | 39 const FakeNetworkPipe::Config& config, |
38 uint64_t seed) | 40 const std::map<uint8_t, MediaType>& payload_type_map, |
41 uint64_t seed) | |
39 : clock_(clock), | 42 : clock_(clock), |
40 media_type_(media_type), | |
41 packet_receiver_(NULL), | 43 packet_receiver_(NULL), |
42 random_(seed), | 44 random_(seed), |
43 config_(), | 45 config_(), |
44 dropped_packets_(0), | 46 dropped_packets_(0), |
45 sent_packets_(0), | 47 sent_packets_(0), |
46 total_packet_delay_(0), | 48 total_packet_delay_(0), |
47 bursting_(false), | 49 bursting_(false), |
48 next_process_time_(clock_->TimeInMilliseconds()), | 50 next_process_time_(clock_->TimeInMilliseconds()), |
49 last_log_time_(clock_->TimeInMilliseconds()) { | 51 last_log_time_(clock_->TimeInMilliseconds()), |
52 payload_type_map_(payload_type_map) { | |
50 SetConfig(config); | 53 SetConfig(config); |
51 } | 54 } |
52 | 55 |
53 FakeNetworkPipe::~FakeNetworkPipe() { | 56 FakeNetworkPipe::~FakeNetworkPipe() { |
54 while (!capacity_link_.empty()) { | 57 while (!capacity_link_.empty()) { |
55 delete capacity_link_.front(); | 58 delete capacity_link_.front(); |
56 capacity_link_.pop(); | 59 capacity_link_.pop(); |
57 } | 60 } |
58 while (!delay_link_.empty()) { | 61 while (!delay_link_.empty()) { |
59 delete *delay_link_.begin(); | 62 delete *delay_link_.begin(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 // |time_now| might be later than when the packet should have arrived, due | 198 // |time_now| might be later than when the packet should have arrived, due |
196 // to NetworkProcess being called too late. For stats, use the time it | 199 // to NetworkProcess being called too late. For stats, use the time it |
197 // should have been on the link. | 200 // should have been on the link. |
198 total_packet_delay_ += packet->arrival_time() - packet->send_time(); | 201 total_packet_delay_ += packet->arrival_time() - packet->send_time(); |
199 } | 202 } |
200 sent_packets_ += packets_to_deliver.size(); | 203 sent_packets_ += packets_to_deliver.size(); |
201 } | 204 } |
202 while (!packets_to_deliver.empty()) { | 205 while (!packets_to_deliver.empty()) { |
203 NetworkPacket* packet = packets_to_deliver.front(); | 206 NetworkPacket* packet = packets_to_deliver.front(); |
204 packets_to_deliver.pop(); | 207 packets_to_deliver.pop(); |
205 packet_receiver_->DeliverPacket(media_type_, packet->data(), | 208 |
206 packet->data_length(), PacketTime()); | 209 const uint8_t* const packet_data = packet->data(); |
210 const size_t packet_length = packet->data_length(); | |
211 MediaType media_type = MediaType::ANY; | |
212 if (!RtpHeaderParser::IsRtcp(packet_data, packet_length)) { | |
213 RTC_CHECK_GE(packet_length, 2); | |
214 const uint8_t pt = packet_data[1] & 0x7f; | |
stefan-webrtc
2017/04/06 11:54:51
payload_type
| |
215 std::map<uint8_t, MediaType>::const_iterator it = | |
216 payload_type_map_.find(pt); | |
217 RTC_CHECK(it != payload_type_map_.end()) | |
minyue-webrtc
2017/04/06 11:33:38
I made it very strict here. All payloads have to b
perkj_webrtc
2017/04/06 13:49:53
but it will break upstream since that is not the c
minyue-webrtc
2017/04/06 18:45:10
Ok. and so, is the change of ctor definition also
perkj_webrtc
2017/04/06 19:13:14
no, the "deprecated" version is used.
| |
218 << "payload type " << static_cast<int>(pt) << " unknown."; | |
219 media_type = it->second; | |
220 } | |
221 packet_receiver_->DeliverPacket(media_type, packet_data, packet_length, | |
222 PacketTime()); | |
207 delete packet; | 223 delete packet; |
208 } | 224 } |
209 | 225 |
210 next_process_time_ = !delay_link_.empty() | 226 next_process_time_ = !delay_link_.empty() |
211 ? (*delay_link_.begin())->arrival_time() | 227 ? (*delay_link_.begin())->arrival_time() |
212 : time_now + kDefaultProcessIntervalMs; | 228 : time_now + kDefaultProcessIntervalMs; |
213 } | 229 } |
214 | 230 |
215 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { | 231 int64_t FakeNetworkPipe::TimeUntilNextProcess() const { |
216 rtc::CritScope crit(&lock_); | 232 rtc::CritScope crit(&lock_); |
217 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), | 233 return std::max<int64_t>(next_process_time_ - clock_->TimeInMilliseconds(), |
218 0); | 234 0); |
219 } | 235 } |
220 | 236 |
221 } // namespace webrtc | 237 } // namespace webrtc |
OLD | NEW |