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

Side by Side Diff: webrtc/modules/pacing/paced_sender_unittest.cc

Issue 2609113003: BitrateProber::CreateProbeCluster now only accept one parameter (bitrate_bps). (Closed)
Patch Set: static_cast<int> + PacedSenderTest fix. Created 3 years, 11 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
« no previous file with comments | « webrtc/modules/pacing/paced_sender.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <list> 11 #include <list>
12 #include <memory> 12 #include <memory>
13 13
14 #include "webrtc/modules/pacing/paced_sender.h" 14 #include "webrtc/modules/pacing/paced_sender.h"
15 #include "webrtc/system_wrappers/include/clock.h" 15 #include "webrtc/system_wrappers/include/clock.h"
16 #include "webrtc/test/gmock.h" 16 #include "webrtc/test/gmock.h"
17 #include "webrtc/test/gtest.h" 17 #include "webrtc/test/gtest.h"
18 18
19 using testing::_; 19 using testing::_;
20 using testing::Return; 20 using testing::Return;
21 21
22 namespace { 22 namespace {
23 constexpr unsigned kFirstClusterBps = 900000; 23 constexpr unsigned kFirstClusterBps = 900000;
24 constexpr int kFirstClusterCount = 6;
25 constexpr unsigned kSecondClusterBps = 1800000; 24 constexpr unsigned kSecondClusterBps = 1800000;
26 constexpr int kSecondClusterCount = 5;
27 25
28 // The error stems from truncating the time interval of probe packets to integer 26 // The error stems from truncating the time interval of probe packets to integer
29 // values. This results in probing slightly higher than the target bitrate. 27 // values. This results in probing slightly higher than the target bitrate.
30 // For 1.8 Mbps, this comes to be about 120 kbps with 1200 probe packets. 28 // For 1.8 Mbps, this comes to be about 120 kbps with 1200 probe packets.
31 constexpr int kBitrateProbingError = 150000; 29 constexpr int kBitrateProbingError = 150000;
32 } // namespace 30 } // namespace
33 31
34 namespace webrtc { 32 namespace webrtc {
35 namespace test { 33 namespace test {
36 34
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 int packets_sent_; 96 int packets_sent_;
99 int padding_sent_; 97 int padding_sent_;
100 }; 98 };
101 99
102 class PacedSenderTest : public ::testing::Test { 100 class PacedSenderTest : public ::testing::Test {
103 protected: 101 protected:
104 PacedSenderTest() : clock_(123456) { 102 PacedSenderTest() : clock_(123456) {
105 srand(0); 103 srand(0);
106 // Need to initialize PacedSender after we initialize clock. 104 // Need to initialize PacedSender after we initialize clock.
107 send_bucket_.reset(new PacedSender(&clock_, &callback_)); 105 send_bucket_.reset(new PacedSender(&clock_, &callback_));
108 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount); 106 send_bucket_->CreateProbeCluster(kFirstClusterBps);
109 send_bucket_->CreateProbeCluster(kSecondClusterBps, kSecondClusterCount); 107 send_bucket_->CreateProbeCluster(kSecondClusterBps);
110 // Default to bitrate probing disabled for testing purposes. Probing tests 108 // Default to bitrate probing disabled for testing purposes. Probing tests
111 // have to enable probing, either by creating a new PacedSender instance or 109 // have to enable probing, either by creating a new PacedSender instance or
112 // by calling SetProbingEnabled(true). 110 // by calling SetProbingEnabled(true).
113 send_bucket_->SetProbingEnabled(false); 111 send_bucket_->SetProbingEnabled(false);
114 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); 112 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps);
115 113
116 clock_.AdvanceTimeMilliseconds(send_bucket_->TimeUntilNextProcess()); 114 clock_.AdvanceTimeMilliseconds(send_bucket_->TimeUntilNextProcess());
117 } 115 }
118 116
119 void SendAndExpectPacket(PacedSender::Priority priority, 117 void SendAndExpectPacket(PacedSender::Priority priority,
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 } 797 }
800 798
801 TEST_F(PacedSenderTest, ProbingWithInsertedPackets) { 799 TEST_F(PacedSenderTest, ProbingWithInsertedPackets) {
802 const size_t kPacketSize = 1200; 800 const size_t kPacketSize = 1200;
803 const int kInitialBitrateBps = 300000; 801 const int kInitialBitrateBps = 300000;
804 uint32_t ssrc = 12346; 802 uint32_t ssrc = 12346;
805 uint16_t sequence_number = 1234; 803 uint16_t sequence_number = 1234;
806 804
807 PacedSenderProbing packet_sender; 805 PacedSenderProbing packet_sender;
808 send_bucket_.reset(new PacedSender(&clock_, &packet_sender)); 806 send_bucket_.reset(new PacedSender(&clock_, &packet_sender));
809 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount); 807 send_bucket_->CreateProbeCluster(kFirstClusterBps);
810 send_bucket_->CreateProbeCluster(kSecondClusterBps, kSecondClusterCount); 808 send_bucket_->CreateProbeCluster(kSecondClusterBps);
811 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps); 809 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
812 810
813 for (int i = 0; i < kFirstClusterCount + kSecondClusterCount; ++i) { 811 for (int i = 0; i < 10; ++i) {
814 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 812 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
815 sequence_number++, clock_.TimeInMilliseconds(), 813 sequence_number++, clock_.TimeInMilliseconds(),
816 kPacketSize, false); 814 kPacketSize, false);
817 } 815 }
818 816
819 int64_t start = clock_.TimeInMilliseconds(); 817 int64_t start = clock_.TimeInMilliseconds();
820 while (packet_sender.packets_sent() < kFirstClusterCount) { 818 while (packet_sender.packets_sent() < 5) {
821 int time_until_process = send_bucket_->TimeUntilNextProcess(); 819 int time_until_process = send_bucket_->TimeUntilNextProcess();
822 clock_.AdvanceTimeMilliseconds(time_until_process); 820 clock_.AdvanceTimeMilliseconds(time_until_process);
823 send_bucket_->Process(); 821 send_bucket_->Process();
824 } 822 }
825 int packets_sent = packet_sender.packets_sent(); 823 int packets_sent = packet_sender.packets_sent();
826 // Validate first cluster bitrate. Note that we have to account for number 824 // Validate first cluster bitrate. Note that we have to account for number
827 // of intervals and hence (packets_sent - 1) on the first cluster. 825 // of intervals and hence (packets_sent - 1) on the first cluster.
828 EXPECT_NEAR((packets_sent - 1) * kPacketSize * 8000 / 826 EXPECT_NEAR((packets_sent - 1) * kPacketSize * 8000 /
829 (clock_.TimeInMilliseconds() - start), 827 (clock_.TimeInMilliseconds() - start),
830 kFirstClusterBps, kBitrateProbingError); 828 kFirstClusterBps, kBitrateProbingError);
831 EXPECT_EQ(0, packet_sender.padding_sent()); 829 EXPECT_EQ(0, packet_sender.padding_sent());
832 830
833 start = clock_.TimeInMilliseconds(); 831 start = clock_.TimeInMilliseconds();
834 while (packet_sender.packets_sent() < 832 while (packet_sender.packets_sent() < 10) {
835 kFirstClusterCount + kSecondClusterCount) {
836 int time_until_process = send_bucket_->TimeUntilNextProcess(); 833 int time_until_process = send_bucket_->TimeUntilNextProcess();
837 clock_.AdvanceTimeMilliseconds(time_until_process); 834 clock_.AdvanceTimeMilliseconds(time_until_process);
838 send_bucket_->Process(); 835 send_bucket_->Process();
839 } 836 }
840 packets_sent = packet_sender.packets_sent() - packets_sent; 837 packets_sent = packet_sender.packets_sent() - packets_sent;
841 // Validate second cluster bitrate. 838 // Validate second cluster bitrate.
842 EXPECT_NEAR( 839 EXPECT_NEAR(
843 packets_sent * kPacketSize * 8000 / (clock_.TimeInMilliseconds() - start), 840 packets_sent * kPacketSize * 8000 / (clock_.TimeInMilliseconds() - start),
844 kSecondClusterBps, kBitrateProbingError); 841 kSecondClusterBps, kBitrateProbingError);
845 } 842 }
846 843
847 TEST_F(PacedSenderTest, ProbingWithPaddingSupport) { 844 TEST_F(PacedSenderTest, ProbingWithPaddingSupport) {
848 const size_t kPacketSize = 1200; 845 const size_t kPacketSize = 1200;
849 const int kInitialBitrateBps = 300000; 846 const int kInitialBitrateBps = 300000;
850 uint32_t ssrc = 12346; 847 uint32_t ssrc = 12346;
851 uint16_t sequence_number = 1234; 848 uint16_t sequence_number = 1234;
852 849
853 PacedSenderProbing packet_sender; 850 PacedSenderProbing packet_sender;
854 send_bucket_.reset(new PacedSender(&clock_, &packet_sender)); 851 send_bucket_.reset(new PacedSender(&clock_, &packet_sender));
855 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount); 852 send_bucket_->CreateProbeCluster(kFirstClusterBps);
856 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps); 853 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
857 854
858 for (int i = 0; i < kFirstClusterCount - 2; ++i) { 855 for (int i = 0; i < 3; ++i) {
859 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 856 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
860 sequence_number++, clock_.TimeInMilliseconds(), 857 sequence_number++, clock_.TimeInMilliseconds(),
861 kPacketSize, false); 858 kPacketSize, false);
862 } 859 }
863 860
864 int64_t start = clock_.TimeInMilliseconds(); 861 int64_t start = clock_.TimeInMilliseconds();
865 int process_count = 0; 862 int process_count = 0;
866 while (process_count < kFirstClusterCount) { 863 while (process_count < 5) {
867 int time_until_process = send_bucket_->TimeUntilNextProcess(); 864 int time_until_process = send_bucket_->TimeUntilNextProcess();
868 clock_.AdvanceTimeMilliseconds(time_until_process); 865 clock_.AdvanceTimeMilliseconds(time_until_process);
869 send_bucket_->Process(); 866 send_bucket_->Process();
870 ++process_count; 867 ++process_count;
871 } 868 }
872 int packets_sent = packet_sender.packets_sent(); 869 int packets_sent = packet_sender.packets_sent();
873 int padding_sent = packet_sender.padding_sent(); 870 int padding_sent = packet_sender.padding_sent();
874 EXPECT_GT(packets_sent, 0); 871 EXPECT_GT(packets_sent, 0);
875 EXPECT_GT(padding_sent, 0); 872 EXPECT_GT(padding_sent, 0);
876 // Note that the number of intervals here for kPacketSize is 873 // Note that the number of intervals here for kPacketSize is
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs()); 999 EXPECT_EQ(0, send_bucket_->AverageQueueTimeMs());
1003 } 1000 }
1004 1001
1005 TEST_F(PacedSenderTest, ProbeClusterId) { 1002 TEST_F(PacedSenderTest, ProbeClusterId) {
1006 uint32_t ssrc = 12346; 1003 uint32_t ssrc = 12346;
1007 uint16_t sequence_number = 1234; 1004 uint16_t sequence_number = 1234;
1008 const size_t kPacketSize = 1200; 1005 const size_t kPacketSize = 1200;
1009 1006
1010 send_bucket_->SetSendBitrateLimits(kTargetBitrateBps, kTargetBitrateBps); 1007 send_bucket_->SetSendBitrateLimits(kTargetBitrateBps, kTargetBitrateBps);
1011 send_bucket_->SetProbingEnabled(true); 1008 send_bucket_->SetProbingEnabled(true);
1012 for (int i = 0; i < 11; ++i) { 1009 for (int i = 0; i < 10; ++i) {
1013 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 1010 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
1014 sequence_number + i, clock_.TimeInMilliseconds(), 1011 sequence_number + i, clock_.TimeInMilliseconds(),
1015 kPacketSize, false); 1012 kPacketSize, false);
1016 } 1013 }
1017 1014
1018 // First probing cluster. 1015 // First probing cluster.
1019 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, 0)) 1016 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, 0))
1020 .Times(6) 1017 .Times(5)
1021 .WillRepeatedly(Return(true)); 1018 .WillRepeatedly(Return(true));
1022 for (int i = 0; i < 6; ++i) { 1019 for (int i = 0; i < 5; ++i) {
1023 clock_.AdvanceTimeMilliseconds(20); 1020 clock_.AdvanceTimeMilliseconds(20);
1024 send_bucket_->Process(); 1021 send_bucket_->Process();
1025 } 1022 }
1026 1023
1027 // Second probing cluster. 1024 // Second probing cluster.
1028 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, 1)) 1025 EXPECT_CALL(callback_, TimeToSendPacket(_, _, _, _, 1))
1029 .Times(5) 1026 .Times(5)
1030 .WillRepeatedly(Return(true)); 1027 .WillRepeatedly(Return(true));
1031 for (int i = 0; i < 5; ++i) { 1028 for (int i = 0; i < 5; ++i) {
1032 clock_.AdvanceTimeMilliseconds(20); 1029 clock_.AdvanceTimeMilliseconds(20);
1033 send_bucket_->Process(); 1030 send_bucket_->Process();
1034 } 1031 }
1035 1032
1036 // No more probing packets. 1033 // No more probing packets.
1037 EXPECT_CALL(callback_, TimeToSendPadding(_, PacketInfo::kNotAProbe)) 1034 EXPECT_CALL(callback_, TimeToSendPadding(_, PacketInfo::kNotAProbe))
1038 .Times(1) 1035 .Times(1)
1039 .WillRepeatedly(Return(500)); 1036 .WillRepeatedly(Return(500));
1040 send_bucket_->Process(); 1037 send_bucket_->Process();
1041 } 1038 }
1042 1039
1043 } // namespace test 1040 } // namespace test
1044 } // namespace webrtc 1041 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/pacing/paced_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698