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

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

Issue 2347023002: BitrateProber: Support higher probing bitrates (Closed)
Patch Set: Add tests Created 4 years, 3 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 (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 "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/modules/pacing/paced_sender.h" 16 #include "webrtc/modules/pacing/paced_sender.h"
17 #include "webrtc/system_wrappers/include/clock.h" 17 #include "webrtc/system_wrappers/include/clock.h"
18 18
19 using testing::_; 19 using testing::_;
20 using testing::Return; 20 using testing::Return;
21 21
22 namespace {
23 constexpr unsigned kFirstClusterBps = 900000;
24 constexpr int kFirstClusterCount = 6;
25 constexpr unsigned kSecondClusterBps = 1800000;
26 constexpr int kSecondClusterCount = 5;
27 } // namespace
28
22 namespace webrtc { 29 namespace webrtc {
23 namespace test { 30 namespace test {
24 31
25 static const int kTargetBitrateBps = 800000; 32 static const int kTargetBitrateBps = 800000;
26 33
27 class MockPacedSenderCallback : public PacedSender::PacketSender { 34 class MockPacedSenderCallback : public PacedSender::PacketSender {
28 public: 35 public:
29 MOCK_METHOD5(TimeToSendPacket, 36 MOCK_METHOD5(TimeToSendPacket,
30 bool(uint32_t ssrc, 37 bool(uint32_t ssrc,
31 uint16_t sequence_number, 38 uint16_t sequence_number,
(...skipping 23 matching lines...) Expand all
55 } 62 }
56 63
57 size_t padding_sent() { return padding_sent_; } 64 size_t padding_sent() { return padding_sent_; }
58 65
59 private: 66 private:
60 size_t padding_sent_; 67 size_t padding_sent_;
61 }; 68 };
62 69
63 class PacedSenderProbing : public PacedSender::PacketSender { 70 class PacedSenderProbing : public PacedSender::PacketSender {
64 public: 71 public:
65 PacedSenderProbing(const std::list<int>& expected_deltas, Clock* clock) 72 PacedSenderProbing() : packets_sent_(0), padding_sent_(0) {}
66 : prev_packet_time_ms_(-1),
67 expected_deltas_(expected_deltas),
68 packets_sent_(0),
69 clock_(clock) {}
70 73
71 bool TimeToSendPacket(uint32_t ssrc, 74 bool TimeToSendPacket(uint32_t ssrc,
72 uint16_t sequence_number, 75 uint16_t sequence_number,
73 int64_t capture_time_ms, 76 int64_t capture_time_ms,
74 bool retransmission, 77 bool retransmission,
75 int probe_cluster_id) override { 78 int probe_cluster_id) override {
76 ExpectAndCountPacket(); 79 packets_sent_++;
77 return true; 80 return true;
78 } 81 }
79 82
80 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id) override { 83 size_t TimeToSendPadding(size_t bytes, int probe_cluster_id) override {
81 ExpectAndCountPacket(); 84 padding_sent_ += bytes;
82 return bytes; 85 return padding_sent_;
83 }
84
85 void ExpectAndCountPacket() {
86 ++packets_sent_;
87 EXPECT_FALSE(expected_deltas_.empty());
88 if (expected_deltas_.empty())
89 return;
90 int64_t now_ms = clock_->TimeInMilliseconds();
91 if (prev_packet_time_ms_ >= 0) {
92 EXPECT_EQ(expected_deltas_.front(), now_ms - prev_packet_time_ms_);
93 expected_deltas_.pop_front();
94 }
95 prev_packet_time_ms_ = now_ms;
96 } 86 }
97 87
98 int packets_sent() const { return packets_sent_; } 88 int packets_sent() const { return packets_sent_; }
99 89
90 int padding_sent() const { return padding_sent_; }
91
100 private: 92 private:
101 int64_t prev_packet_time_ms_;
102 std::list<int> expected_deltas_;
103 int packets_sent_; 93 int packets_sent_;
104 Clock* clock_; 94 int padding_sent_;
105 }; 95 };
106 96
107 class PacedSenderTest : public ::testing::Test { 97 class PacedSenderTest : public ::testing::Test {
108 protected: 98 protected:
109 PacedSenderTest() : clock_(123456) { 99 PacedSenderTest() : clock_(123456) {
110 srand(0); 100 srand(0);
111 // Need to initialize PacedSender after we initialize clock. 101 // Need to initialize PacedSender after we initialize clock.
112 send_bucket_.reset(new PacedSender(&clock_, &callback_)); 102 send_bucket_.reset(new PacedSender(&clock_, &callback_));
113 send_bucket_->CreateProbeCluster(900000, 6); 103 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount);
114 send_bucket_->CreateProbeCluster(1800000, 5); 104 send_bucket_->CreateProbeCluster(kSecondClusterBps, kSecondClusterCount);
115 // Default to bitrate probing disabled for testing purposes. Probing tests 105 // Default to bitrate probing disabled for testing purposes. Probing tests
116 // have to enable probing, either by creating a new PacedSender instance or 106 // have to enable probing, either by creating a new PacedSender instance or
117 // by calling SetProbingEnabled(true). 107 // by calling SetProbingEnabled(true).
118 send_bucket_->SetProbingEnabled(false); 108 send_bucket_->SetProbingEnabled(false);
119 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps); 109 send_bucket_->SetEstimatedBitrate(kTargetBitrateBps);
120 110
121 clock_.AdvanceTimeMilliseconds(send_bucket_->TimeUntilNextProcess()); 111 clock_.AdvanceTimeMilliseconds(send_bucket_->TimeUntilNextProcess());
122 } 112 }
123 113
124 void SendAndExpectPacket(PacedSender::Priority priority, 114 void SendAndExpectPacket(PacedSender::Priority priority,
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 clock_.TimeInMilliseconds(), 786 clock_.TimeInMilliseconds(),
797 1200, 787 1200,
798 false); 788 false);
799 789
800 clock_.AdvanceTimeMilliseconds(500); 790 clock_.AdvanceTimeMilliseconds(500);
801 EXPECT_EQ(500, send_bucket_->QueueInMs()); 791 EXPECT_EQ(500, send_bucket_->QueueInMs());
802 send_bucket_->Process(); 792 send_bucket_->Process();
803 EXPECT_EQ(0, send_bucket_->QueueInMs()); 793 EXPECT_EQ(0, send_bucket_->QueueInMs());
804 } 794 }
805 795
806 TEST_F(PacedSenderTest, ProbingWithInitialFrame) { 796 TEST_F(PacedSenderTest, ProbingWithInsertedPackets) {
807 const int kNumPackets = 11;
808 const int kNumDeltas = kNumPackets - 1;
809 const size_t kPacketSize = 1200; 797 const size_t kPacketSize = 1200;
810 const int kInitialBitrateBps = 300000; 798 const int kInitialBitrateBps = 300000;
811 uint32_t ssrc = 12346; 799 uint32_t ssrc = 12346;
812 uint16_t sequence_number = 1234; 800 uint16_t sequence_number = 1234;
813 801
814 const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5}; 802 PacedSenderProbing packet_sender;
815 std::list<int> expected_deltas_list(expected_deltas, 803 send_bucket_.reset(new PacedSender(&clock_, &packet_sender));
816 expected_deltas + kNumDeltas); 804 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount);
817 PacedSenderProbing callback(expected_deltas_list, &clock_); 805 send_bucket_->CreateProbeCluster(kSecondClusterBps, kSecondClusterCount);
818 send_bucket_.reset(new PacedSender(&clock_, &callback));
819 send_bucket_->CreateProbeCluster(900000, 6);
820 send_bucket_->CreateProbeCluster(1800000, 5);
821 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps); 806 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
822 807
823 for (int i = 0; i < kNumPackets; ++i) { 808 for (int i = 0; i < kFirstClusterCount + kSecondClusterCount; ++i) {
824 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 809 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
825 sequence_number++, clock_.TimeInMilliseconds(), 810 sequence_number++, clock_.TimeInMilliseconds(),
826 kPacketSize, false); 811 kPacketSize, false);
827 } 812 }
828 813
829 while (callback.packets_sent() < kNumPackets) { 814 int64_t start = clock_.TimeInMilliseconds();
815 while (packet_sender.packets_sent() < kFirstClusterCount) {
philipel 2016/09/21 09:26:40 Simplify loop: int time_until_process = send_bucke
Irfan 2016/09/21 17:00:37 Done.
830 int time_until_process = send_bucket_->TimeUntilNextProcess(); 816 int time_until_process = send_bucket_->TimeUntilNextProcess();
831 if (time_until_process <= 0) { 817 if (time_until_process <= 0) {
832 send_bucket_->Process(); 818 send_bucket_->Process();
819 } else {
820 clock_.AdvanceTimeMilliseconds(time_until_process);
821 }
822 }
823 int packets_sent = packet_sender.packets_sent();
824 // Validate first cluster bitrate.
825 EXPECT_GT(
philipel 2016/09/21 09:26:40 Why do we EXPECT_GT? Shouldn't we EXPECT_NEAR inst
Irfan 2016/09/21 17:00:37 I have clarified this in the comments. Have switch
826 packets_sent * kPacketSize * 8000 / (clock_.TimeInMilliseconds() - start),
827 kFirstClusterBps);
828
829 start = clock_.TimeInMilliseconds();
830 while (packet_sender.packets_sent() <
philipel 2016/09/21 09:26:40 simplfy loop
Irfan 2016/09/21 17:00:37 Done.
831 kFirstClusterCount + kSecondClusterCount) {
832 int time_until_process = send_bucket_->TimeUntilNextProcess();
833 if (time_until_process <= 0) {
834 send_bucket_->Process();
833 } else { 835 } else {
834 clock_.AdvanceTimeMilliseconds(time_until_process); 836 clock_.AdvanceTimeMilliseconds(time_until_process);
835 } 837 }
836 } 838 }
839 packets_sent = packet_sender.packets_sent() - packets_sent;
840 // Validate second cluster bitrate.
841 EXPECT_GT(
philipel 2016/09/21 09:26:40 EXPECT_NEAR?
Irfan 2016/09/21 17:00:37 Done.
842 packets_sent * kPacketSize * 8000 / (clock_.TimeInMilliseconds() - start),
843 kSecondClusterBps);
837 } 844 }
838 845
839 TEST_F(PacedSenderTest, ProbingWithTooSmallInitialFrame) { 846 TEST_F(PacedSenderTest, ProbingWithPaddingSupport) {
840 const int kNumPackets = 11;
841 const int kNumDeltas = kNumPackets - 1;
842 const size_t kPacketSize = 1200; 847 const size_t kPacketSize = 1200;
843 const int kInitialBitrateBps = 300000; 848 const int kInitialBitrateBps = 300000;
844 uint32_t ssrc = 12346; 849 uint32_t ssrc = 12346;
845 uint16_t sequence_number = 1234; 850 uint16_t sequence_number = 1234;
846 const int expected_deltas[kNumDeltas] = {10, 10, 10, 10, 10, 5, 5, 5, 5, 5}; 851
847 std::list<int> expected_deltas_list(expected_deltas, 852 PacedSenderProbing packet_sender;
848 expected_deltas + kNumDeltas); 853 send_bucket_.reset(new PacedSender(&clock_, &packet_sender));
849 PacedSenderProbing callback(expected_deltas_list, &clock_); 854 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount);
850 send_bucket_.reset(new PacedSender(&clock_, &callback));
851 send_bucket_->CreateProbeCluster(900000, 6);
852 send_bucket_->CreateProbeCluster(1800000, 5);
853 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps); 855 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
854 856
855 for (int i = 0; i < kNumPackets - 5; ++i) { 857 for (int i = 0; i < kFirstClusterCount - 2; ++i) {
856 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc, 858 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
857 sequence_number++, clock_.TimeInMilliseconds(), 859 sequence_number++, clock_.TimeInMilliseconds(),
858 kPacketSize, false); 860 kPacketSize, false);
859 } 861 }
860 while (callback.packets_sent() < kNumPackets) { 862
863 int64_t start = clock_.TimeInMilliseconds();
864 int process_count = 0;
865 while (process_count < kFirstClusterCount) {
philipel 2016/09/21 09:26:40 Simplify loop
Irfan 2016/09/21 17:00:37 Done.
866 int time_until_process = send_bucket_->TimeUntilNextProcess();
867 if (time_until_process <= 0) {
868 send_bucket_->Process();
869 process_count++;
870 } else {
871 clock_.AdvanceTimeMilliseconds(time_until_process);
872 }
873 }
874 int packets_sent = packet_sender.packets_sent();
875 int padding_sent = packet_sender.padding_sent();
876 // Validate first cluster bitrate
877 EXPECT_GT((packets_sent * kPacketSize * 8000 + padding_sent) /
philipel 2016/09/21 09:26:40 EXPECT_NEAR
Irfan 2016/09/21 17:00:37 Done.
878 (clock_.TimeInMilliseconds() - start),
879 kFirstClusterBps);
880 }
881
882 TEST_F(PacedSenderTest, ProbingUsesRetransmissions) {
883 const size_t kPacketSize = 1200;
884 const int kInitialBitrateBps = 300000;
885 uint32_t ssrc = 12346;
886 uint16_t sequence_number = 1234;
887
888 PacedSenderProbing packet_sender;
889 send_bucket_.reset(new PacedSender(&clock_, &packet_sender));
890 send_bucket_->CreateProbeCluster(kFirstClusterBps, kFirstClusterCount);
891 send_bucket_->SetEstimatedBitrate(kInitialBitrateBps);
892
893 // All packets inserted are retransmissions.
894 for (int i = 0; i < kFirstClusterCount; ++i) {
895 send_bucket_->InsertPacket(PacedSender::kNormalPriority, ssrc,
896 sequence_number++, clock_.TimeInMilliseconds(),
897 kPacketSize, true);
898 }
899
900 int64_t start = clock_.TimeInMilliseconds();
901 while (packet_sender.packets_sent() < kFirstClusterCount) {
philipel 2016/09/21 09:26:39 Simplify loop
Irfan 2016/09/21 17:00:37 Done.
861 int time_until_process = send_bucket_->TimeUntilNextProcess(); 902 int time_until_process = send_bucket_->TimeUntilNextProcess();
862 if (time_until_process <= 0) { 903 if (time_until_process <= 0) {
863 send_bucket_->Process(); 904 send_bucket_->Process();
864 } else { 905 } else {
865 clock_.AdvanceTimeMilliseconds(time_until_process); 906 clock_.AdvanceTimeMilliseconds(time_until_process);
866 } 907 }
867 } 908 }
868 909 int packets_sent = packet_sender.packets_sent();
869 // Process one more time and make sure we don't send any more probes. 910 int padding_sent = packet_sender.padding_sent();
870 int time_until_process = send_bucket_->TimeUntilNextProcess(); 911 EXPECT_EQ(padding_sent, 0);
871 clock_.AdvanceTimeMilliseconds(time_until_process); 912 // Validate first cluster bitrate.
872 send_bucket_->Process(); 913 EXPECT_GT((packets_sent * kPacketSize * 8000) /
philipel 2016/09/21 09:26:40 EXPECT_NEAR
Irfan 2016/09/21 17:00:37 Done.
873 EXPECT_EQ(kNumPackets, callback.packets_sent()); 914 (clock_.TimeInMilliseconds() - start),
915 kFirstClusterBps);
874 } 916 }
875 917
876 TEST_F(PacedSenderTest, PriorityInversion) { 918 TEST_F(PacedSenderTest, PriorityInversion) {
877 uint32_t ssrc = 12346; 919 uint32_t ssrc = 12346;
878 uint16_t sequence_number = 1234; 920 uint16_t sequence_number = 1234;
879 const size_t kPacketSize = 1200; 921 const size_t kPacketSize = 1200;
880 922
881 send_bucket_->InsertPacket( 923 send_bucket_->InsertPacket(
882 PacedSender::kHighPriority, ssrc, sequence_number + 3, 924 PacedSender::kHighPriority, ssrc, sequence_number + 3,
883 clock_.TimeInMilliseconds() + 33, kPacketSize, true); 925 clock_.TimeInMilliseconds() + 33, kPacketSize, true);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 1070
1029 // No more probing packets. 1071 // No more probing packets.
1030 EXPECT_CALL(callback_, TimeToSendPadding(_, PacketInfo::kNotAProbe)) 1072 EXPECT_CALL(callback_, TimeToSendPadding(_, PacketInfo::kNotAProbe))
1031 .Times(1) 1073 .Times(1)
1032 .WillRepeatedly(Return(500)); 1074 .WillRepeatedly(Return(500));
1033 send_bucket_->Process(); 1075 send_bucket_->Process();
1034 } 1076 }
1035 1077
1036 } // namespace test 1078 } // namespace test
1037 } // namespace webrtc 1079 } // namespace webrtc
OLDNEW
« webrtc/modules/pacing/bitrate_prober.h ('K') | « webrtc/modules/pacing/paced_sender.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698