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 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 MockRtpPacketSender() {} | 107 MockRtpPacketSender() {} |
108 virtual ~MockRtpPacketSender() {} | 108 virtual ~MockRtpPacketSender() {} |
109 | 109 |
110 MOCK_METHOD6(InsertPacket, | 110 MOCK_METHOD6(InsertPacket, |
111 void(Priority priority, | 111 void(Priority priority, |
112 uint32_t ssrc, | 112 uint32_t ssrc, |
113 uint16_t sequence_number, | 113 uint16_t sequence_number, |
114 int64_t capture_time_ms, | 114 int64_t capture_time_ms, |
115 size_t bytes, | 115 size_t bytes, |
116 bool retransmission)); | 116 bool retransmission)); |
| 117 |
| 118 MOCK_METHOD1(AllocateRetransmissionBitrate, bool(size_t bytes)); |
| 119 MOCK_METHOD0(CurrentRetransmissionBitrate, int(void)); |
117 }; | 120 }; |
118 | 121 |
119 class MockTransportSequenceNumberAllocator | 122 class MockTransportSequenceNumberAllocator |
120 : public TransportSequenceNumberAllocator { | 123 : public TransportSequenceNumberAllocator { |
121 public: | 124 public: |
122 MOCK_METHOD0(AllocateSequenceNumber, uint16_t()); | 125 MOCK_METHOD0(AllocateSequenceNumber, uint16_t()); |
123 }; | 126 }; |
124 | 127 |
125 class MockSendPacketObserver : public SendPacketObserver { | 128 class MockSendPacketObserver : public SendPacketObserver { |
126 public: | 129 public: |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 ASSERT_NE(-1, rtp_length_int); | 807 ASSERT_NE(-1, rtp_length_int); |
805 size_t rtp_length = static_cast<size_t>(rtp_length_int); | 808 size_t rtp_length = static_cast<size_t>(rtp_length_int); |
806 | 809 |
807 // Packet should be stored in a send bucket. | 810 // Packet should be stored in a send bucket. |
808 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, | 811 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, |
809 capture_time_ms, kAllowRetransmission, | 812 capture_time_ms, kAllowRetransmission, |
810 RtpPacketSender::kNormalPriority)); | 813 RtpPacketSender::kNormalPriority)); |
811 | 814 |
812 EXPECT_EQ(0, transport_.packets_sent_); | 815 EXPECT_EQ(0, transport_.packets_sent_); |
813 | 816 |
| 817 EXPECT_CALL(mock_paced_sender_, AllocateRetransmissionBitrate(rtp_length)) |
| 818 .WillOnce(testing::Return(true)); |
814 EXPECT_CALL(mock_paced_sender_, InsertPacket(RtpPacketSender::kNormalPriority, | 819 EXPECT_CALL(mock_paced_sender_, InsertPacket(RtpPacketSender::kNormalPriority, |
815 _, kSeqNum, _, _, _)); | 820 _, kSeqNum, _, _, _)); |
816 | 821 |
817 const int kStoredTimeInMs = 100; | 822 const int kStoredTimeInMs = 100; |
818 fake_clock_.AdvanceTimeMilliseconds(kStoredTimeInMs); | 823 fake_clock_.AdvanceTimeMilliseconds(kStoredTimeInMs); |
819 | 824 |
820 EXPECT_EQ(rtp_length_int, rtp_sender_->ReSendPacket(kSeqNum)); | 825 EXPECT_EQ(rtp_length_int, rtp_sender_->ReSendPacket(kSeqNum)); |
821 EXPECT_EQ(0, transport_.packets_sent_); | 826 EXPECT_EQ(0, transport_.packets_sent_); |
822 | 827 |
823 rtp_sender_->TimeToSendPacket(kSeqNum, capture_time_ms, false, | 828 rtp_sender_->TimeToSendPacket(kSeqNum, capture_time_ms, false, |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 EXPECT_EQ(ssrc, callback.ssrc_); | 1211 EXPECT_EQ(ssrc, callback.ssrc_); |
1207 EXPECT_EQ(1, callback.frame_counts_.key_frames); | 1212 EXPECT_EQ(1, callback.frame_counts_.key_frames); |
1208 EXPECT_EQ(1, callback.frame_counts_.delta_frames); | 1213 EXPECT_EQ(1, callback.frame_counts_.delta_frames); |
1209 | 1214 |
1210 rtp_sender_.reset(); | 1215 rtp_sender_.reset(); |
1211 } | 1216 } |
1212 | 1217 |
1213 TEST_F(RtpSenderTest, BitrateCallbacks) { | 1218 TEST_F(RtpSenderTest, BitrateCallbacks) { |
1214 class TestCallback : public BitrateStatisticsObserver { | 1219 class TestCallback : public BitrateStatisticsObserver { |
1215 public: | 1220 public: |
1216 TestCallback() : BitrateStatisticsObserver(), num_calls_(0), ssrc_(0) {} | 1221 TestCallback() |
| 1222 : BitrateStatisticsObserver(), |
| 1223 num_calls_(0), |
| 1224 ssrc_(0), |
| 1225 total_bitrate_(0), |
| 1226 retransmit_bitrate_(0) {} |
1217 virtual ~TestCallback() {} | 1227 virtual ~TestCallback() {} |
1218 | 1228 |
1219 void Notify(const BitrateStatistics& total_stats, | 1229 void Notify(uint32_t total_bitrate, |
1220 const BitrateStatistics& retransmit_stats, | 1230 uint32_t retransmit_bitrate, |
1221 uint32_t ssrc) override { | 1231 uint32_t ssrc) override { |
1222 ++num_calls_; | 1232 ++num_calls_; |
1223 ssrc_ = ssrc; | 1233 ssrc_ = ssrc; |
1224 total_stats_ = total_stats; | 1234 total_bitrate_ = total_bitrate; |
1225 retransmit_stats_ = retransmit_stats; | 1235 retransmit_bitrate_ = retransmit_bitrate; |
1226 } | 1236 } |
1227 | 1237 |
1228 uint32_t num_calls_; | 1238 uint32_t num_calls_; |
1229 uint32_t ssrc_; | 1239 uint32_t ssrc_; |
1230 BitrateStatistics total_stats_; | 1240 uint32_t total_bitrate_; |
1231 BitrateStatistics retransmit_stats_; | 1241 uint32_t retransmit_bitrate_; |
1232 } callback; | 1242 } callback; |
1233 rtp_sender_.reset(new RTPSender(false, &fake_clock_, &transport_, nullptr, | 1243 rtp_sender_.reset(new RTPSender(false, &fake_clock_, &transport_, nullptr, |
1234 nullptr, nullptr, &callback, nullptr, nullptr, | 1244 nullptr, nullptr, &callback, nullptr, nullptr, |
1235 nullptr, nullptr)); | 1245 nullptr, nullptr)); |
1236 | 1246 |
1237 // Simulate kNumPackets sent with kPacketInterval ms intervals. | 1247 // Simulate kNumPackets sent with kPacketInterval ms intervals, with the |
1238 const uint32_t kNumPackets = 15; | 1248 // number of packets selected so that we fill (but don't overflow) the one |
| 1249 // second averaging window. |
| 1250 const uint32_t kWindowSizeMs = 1000; |
1239 const uint32_t kPacketInterval = 20; | 1251 const uint32_t kPacketInterval = 20; |
| 1252 const uint32_t kNumPackets = |
| 1253 (kWindowSizeMs - kPacketInterval) / kPacketInterval; |
1240 // Overhead = 12 bytes RTP header + 1 byte generic header. | 1254 // Overhead = 12 bytes RTP header + 1 byte generic header. |
1241 const uint32_t kPacketOverhead = 13; | 1255 const uint32_t kPacketOverhead = 13; |
1242 | 1256 |
1243 char payload_name[RTP_PAYLOAD_NAME_SIZE] = "GENERIC"; | 1257 char payload_name[RTP_PAYLOAD_NAME_SIZE] = "GENERIC"; |
1244 const uint8_t payload_type = 127; | 1258 const uint8_t payload_type = 127; |
1245 ASSERT_EQ(0, rtp_sender_->RegisterPayload(payload_name, payload_type, 90000, | 1259 ASSERT_EQ(0, rtp_sender_->RegisterPayload(payload_name, payload_type, 90000, |
1246 0, 1500)); | 1260 0, 1500)); |
1247 uint8_t payload[] = {47, 11, 32, 93, 89}; | 1261 uint8_t payload[] = {47, 11, 32, 93, 89}; |
1248 rtp_sender_->SetStorePacketsStatus(true, 1); | 1262 rtp_sender_->SetStorePacketsStatus(true, 1); |
1249 uint32_t ssrc = rtp_sender_->SSRC(); | 1263 uint32_t ssrc = rtp_sender_->SSRC(); |
1250 | 1264 |
1251 // Initial process call so we get a new time window. | 1265 // Initial process call so we get a new time window. |
1252 rtp_sender_->ProcessBitrate(); | 1266 rtp_sender_->ProcessBitrate(); |
1253 uint64_t start_time = fake_clock_.CurrentNtpInMilliseconds(); | |
1254 | 1267 |
1255 // Send a few frames. | 1268 // Send a few frames. |
1256 for (uint32_t i = 0; i < kNumPackets; ++i) { | 1269 for (uint32_t i = 0; i < kNumPackets; ++i) { |
1257 ASSERT_EQ(0, | 1270 ASSERT_EQ(0, |
1258 rtp_sender_->SendOutgoingData(kVideoFrameKey, payload_type, 1234, | 1271 rtp_sender_->SendOutgoingData(kVideoFrameKey, payload_type, 1234, |
1259 4321, payload, sizeof(payload), 0)); | 1272 4321, payload, sizeof(payload), 0)); |
1260 fake_clock_.AdvanceTimeMilliseconds(kPacketInterval); | 1273 fake_clock_.AdvanceTimeMilliseconds(kPacketInterval); |
1261 } | 1274 } |
1262 | 1275 |
1263 rtp_sender_->ProcessBitrate(); | 1276 rtp_sender_->ProcessBitrate(); |
1264 | 1277 |
1265 const uint32_t expected_packet_rate = 1000 / kPacketInterval; | |
1266 | |
1267 // We get one call for every stats updated, thus two calls since both the | 1278 // We get one call for every stats updated, thus two calls since both the |
1268 // stream stats and the retransmit stats are updated once. | 1279 // stream stats and the retransmit stats are updated once. |
1269 EXPECT_EQ(2u, callback.num_calls_); | 1280 EXPECT_EQ(2u, callback.num_calls_); |
1270 EXPECT_EQ(ssrc, callback.ssrc_); | 1281 EXPECT_EQ(ssrc, callback.ssrc_); |
1271 EXPECT_EQ(start_time + (kNumPackets * kPacketInterval), | 1282 const uint32_t kTotalPacketSize = kPacketOverhead + sizeof(payload); |
1272 callback.total_stats_.timestamp_ms); | 1283 // Bitrate measured over delta between last and first timestamp, plus one. |
1273 EXPECT_EQ(expected_packet_rate, callback.total_stats_.packet_rate); | 1284 const uint32_t kExpectedWindowMs = kNumPackets * kPacketInterval + 1; |
1274 EXPECT_EQ((kPacketOverhead + sizeof(payload)) * 8 * expected_packet_rate, | 1285 const uint32_t kExpectedBitsAccumulated = kTotalPacketSize * kNumPackets * 8; |
1275 callback.total_stats_.bitrate_bps); | 1286 const uint32_t KexpectedRateBps = |
| 1287 (kExpectedBitsAccumulated * 1000 + (kExpectedWindowMs / 2)) / |
| 1288 kExpectedWindowMs; |
| 1289 EXPECT_EQ(KexpectedRateBps, callback.total_bitrate_); |
1276 | 1290 |
1277 rtp_sender_.reset(); | 1291 rtp_sender_.reset(); |
1278 } | 1292 } |
1279 | 1293 |
1280 class RtpSenderAudioTest : public RtpSenderTest { | 1294 class RtpSenderAudioTest : public RtpSenderTest { |
1281 protected: | 1295 protected: |
1282 RtpSenderAudioTest() {} | 1296 RtpSenderAudioTest() {} |
1283 | 1297 |
1284 void SetUp() override { | 1298 void SetUp() override { |
1285 payload_ = kAudioPayload; | 1299 payload_ = kAudioPayload; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1603 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), | 1617 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), |
1604 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation); | 1618 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation); |
1605 | 1619 |
1606 // Verify that this packet does have CVO byte. | 1620 // Verify that this packet does have CVO byte. |
1607 VerifyCVOPacket( | 1621 VerifyCVOPacket( |
1608 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), | 1622 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), |
1609 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1, | 1623 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1, |
1610 hdr.rotation); | 1624 hdr.rotation); |
1611 } | 1625 } |
1612 } // namespace webrtc | 1626 } // namespace webrtc |
OLD | NEW |