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

Side by Side Diff: webrtc/video/send_statistics_proxy_unittest.cc

Issue 2536613002: Use RateAccCounter for sent bitrate stats. Reports average of periodically computed stats over a ca… (Closed)
Patch Set: Created 4 years 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) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 EXPECT_TRUE(GetStreamStats(kFlexFecSsrc).is_flexfec); 946 EXPECT_TRUE(GetStreamStats(kFlexFecSsrc).is_flexfec);
947 } 947 }
948 948
949 TEST_F(SendStatisticsProxyTest, SendBitratesAreReportedWithFlexFecEnabled) { 949 TEST_F(SendStatisticsProxyTest, SendBitratesAreReportedWithFlexFecEnabled) {
950 statistics_proxy_.reset( 950 statistics_proxy_.reset(
951 new SendStatisticsProxy(&fake_clock_, GetTestConfigWithFlexFec(), 951 new SendStatisticsProxy(&fake_clock_, GetTestConfigWithFlexFec(),
952 VideoEncoderConfig::ContentType::kRealtimeVideo)); 952 VideoEncoderConfig::ContentType::kRealtimeVideo));
953 953
954 StreamDataCountersCallback* proxy = 954 StreamDataCountersCallback* proxy =
955 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get()); 955 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
956
957 StreamDataCounters counters; 956 StreamDataCounters counters;
958 StreamDataCounters rtx_counters; 957 StreamDataCounters rtx_counters;
959 proxy->DataCountersUpdated(counters, kFirstSsrc);
960 proxy->DataCountersUpdated(counters, kSecondSsrc);
961 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
962 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
963 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
964 958
965 counters.transmitted.header_bytes = 5000; 959 const int kMinRequiredPeriodSamples = 8;
966 counters.transmitted.packets = 20; 960 const int kPeriodIntervalMs = 2000;
967 counters.transmitted.padding_bytes = 10000; 961 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
968 counters.transmitted.payload_bytes = 20000; 962 counters.transmitted.packets += 20;
969 counters.retransmitted.header_bytes = 400; 963 counters.transmitted.header_bytes += 500;
970 counters.retransmitted.packets = 2; 964 counters.transmitted.padding_bytes += 1000;
971 counters.retransmitted.padding_bytes = 1000; 965 counters.transmitted.payload_bytes += 2000;
972 counters.retransmitted.payload_bytes = 2000; 966 counters.retransmitted.packets += 2;
973 counters.fec = counters.retransmitted; 967 counters.retransmitted.header_bytes += 25;
974 rtx_counters.transmitted = counters.transmitted; 968 counters.retransmitted.padding_bytes += 100;
969 counters.retransmitted.payload_bytes += 250;
970 counters.fec = counters.retransmitted;
971 rtx_counters.transmitted = counters.transmitted;
972 // Advance one interval and update counters.
973 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
974 proxy->DataCountersUpdated(counters, kFirstSsrc);
975 proxy->DataCountersUpdated(counters, kSecondSsrc);
976 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
977 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
978 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
979 }
975 980
976 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
977 proxy->DataCountersUpdated(counters, kFirstSsrc);
978 proxy->DataCountersUpdated(counters, kSecondSsrc);
979 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
980 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
981 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
982
983 // Reset stats proxy causes histograms to be reported.
984 statistics_proxy_.reset(); 981 statistics_proxy_.reset();
982 // Interval: 3500 bytes * 4 / 2 sec = 7000 bytes / sec = 56 kbps
985 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps")); 983 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps"));
986 EXPECT_EQ(1, 984 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BitrateSentInKbps", 56));
987 metrics::NumEvents( 985 // Interval: 3500 bytes * 2 / 2 sec = 3500 bytes / sec = 28 kbps
988 "WebRTC.Video.BitrateSentInKbps", 986 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
989 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) / 987 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtxBitrateSentInKbps", 28));
990 metrics::kMinRunTimeInSeconds / 1000))); 988 // Interval: (2000 - 2 * 250) bytes / 2 sec = 1500 bytes / sec = 12 kbps
991
992 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps")); 989 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps"));
993 EXPECT_EQ(1, metrics::NumEvents( 990 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.MediaBitrateSentInKbps", 12));
994 "WebRTC.Video.MediaBitrateSentInKbps", 991 // Interval: 1000 bytes * 4 / 2 sec = 2000 bytes / sec = 16 kbps
995 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
996 metrics::kMinRunTimeInSeconds / 1000)));
997
998 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps")); 992 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
999 EXPECT_EQ(1, 993 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PaddingBitrateSentInKbps", 16));
1000 metrics::NumEvents( 994 // Interval: 375 bytes * 2 / 2 sec = 375 bytes / sec = 3 kbps
1001 "WebRTC.Video.PaddingBitrateSentInKbps", 995 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1002 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) / 996 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.FecBitrateSentInKbps", 3));
1003 metrics::kMinRunTimeInSeconds / 1000))); 997 // Interval: 375 bytes * 2 / 2 sec = 375 bytes / sec = 3 kbps
1004
1005 EXPECT_EQ(1, 998 EXPECT_EQ(1,
1006 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps")); 999 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps"));
1007 EXPECT_EQ(1,
1008 metrics::NumEvents(
1009 "WebRTC.Video.RetransmittedBitrateSentInKbps",
1010 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
1011 metrics::kMinRunTimeInSeconds / 1000)));
1012
1013 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
1014 EXPECT_EQ( 1000 EXPECT_EQ(
1015 1, metrics::NumEvents( 1001 1, metrics::NumEvents("WebRTC.Video.RetransmittedBitrateSentInKbps", 3));
1016 "WebRTC.Video.RtxBitrateSentInKbps",
1017 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
1018 metrics::kMinRunTimeInSeconds / 1000)));
1019
1020 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1021 EXPECT_EQ(1, metrics::NumEvents(
1022 "WebRTC.Video.FecBitrateSentInKbps",
1023 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
1024 metrics::kMinRunTimeInSeconds / 1000)));
1025 } 1002 }
1026 1003
1027 TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) { 1004 TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) {
1028 StreamDataCountersCallback* proxy = 1005 StreamDataCountersCallback* proxy =
1029 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get()); 1006 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1030 StreamDataCounters counters; 1007 StreamDataCounters counters;
1031 StreamDataCounters rtx_counters; 1008 StreamDataCounters rtx_counters;
1032 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds(); 1009 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
1033 proxy->DataCountersUpdated(counters, kFirstSsrc); 1010
1034 proxy->DataCountersUpdated(counters, kSecondSsrc); 1011 const int kMinRequiredPeriodSamples = 8;
1035 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc); 1012 const int kPeriodIntervalMs = 2000;
1036 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc); 1013 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
1037 1014 counters.transmitted.packets += 20;
1038 counters.transmitted.header_bytes = 5000; 1015 counters.transmitted.header_bytes += 500;
1039 counters.transmitted.packets = 20; 1016 counters.transmitted.padding_bytes += 1000;
1040 counters.transmitted.padding_bytes = 10000; 1017 counters.transmitted.payload_bytes += 2000;
1041 counters.transmitted.payload_bytes = 20000; 1018 counters.retransmitted.packets += 2;
1042 1019 counters.retransmitted.header_bytes += 25;
1043 counters.retransmitted.header_bytes = 400; 1020 counters.retransmitted.padding_bytes += 100;
1044 counters.retransmitted.packets = 2; 1021 counters.retransmitted.payload_bytes += 250;
1045 counters.retransmitted.padding_bytes = 1000; 1022 counters.fec = counters.retransmitted;
1046 counters.retransmitted.payload_bytes = 2000; 1023 rtx_counters.transmitted = counters.transmitted;
1047 1024 // Advance one interval and update counters.
1048 counters.fec = counters.retransmitted; 1025 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1049 1026 proxy->DataCountersUpdated(counters, kFirstSsrc);
1050 rtx_counters.transmitted = counters.transmitted; 1027 proxy->DataCountersUpdated(counters, kSecondSsrc);
1051 1028 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1052 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); 1029 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1053 proxy->DataCountersUpdated(counters, kFirstSsrc); 1030 }
1054 proxy->DataCountersUpdated(counters, kSecondSsrc);
1055 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1056 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1057 1031
1058 // Changing content type causes histograms to be reported. 1032 // Changing content type causes histograms to be reported.
1059 VideoEncoderConfig config; 1033 VideoEncoderConfig config;
1060 config.content_type = VideoEncoderConfig::ContentType::kScreen; 1034 config.content_type = VideoEncoderConfig::ContentType::kScreen;
1061 statistics_proxy_->OnEncoderReconfigured(config, 50); 1035 statistics_proxy_->OnEncoderReconfigured(config, 50000);
1062 1036
1037 // Interval: 3500 bytes * 4 / 2 sec = 7000 bytes / sec = 56 kbps
1063 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps")); 1038 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps"));
1064 EXPECT_EQ(1, 1039 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.BitrateSentInKbps", 56));
1065 metrics::NumEvents( 1040 // Interval: 3500 bytes * 2 / 2 sec = 3500 bytes / sec = 28 kbps
1066 "WebRTC.Video.BitrateSentInKbps", 1041 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
1067 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) / 1042 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtxBitrateSentInKbps", 28));
1068 metrics::kMinRunTimeInSeconds / 1000))); 1043 // Interval: (2000 - 2 * 250) bytes / 2 sec = 1500 bytes / sec = 12 kbps
1069
1070 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps")); 1044 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps"));
1071 EXPECT_EQ(1, metrics::NumEvents( 1045 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.MediaBitrateSentInKbps", 12));
1072 "WebRTC.Video.MediaBitrateSentInKbps", 1046 // Interval: 1000 bytes * 4 / 2 sec = 2000 bytes / sec = 16 kbps
1073 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
1074 metrics::kMinRunTimeInSeconds / 1000)));
1075
1076 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps")); 1047 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
1077 EXPECT_EQ(1, 1048 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.PaddingBitrateSentInKbps", 16));
1078 metrics::NumEvents( 1049 // Interval: 375 bytes * 2 / 2 sec = 375 bytes / sec = 3 kbps
1079 "WebRTC.Video.PaddingBitrateSentInKbps", 1050 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1080 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) / 1051 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.FecBitrateSentInKbps", 3));
1081 metrics::kMinRunTimeInSeconds / 1000))); 1052 // Interval: 375 bytes * 2 / 2 sec = 375 bytes / sec = 3 kbps
1082
1083 EXPECT_EQ(1, 1053 EXPECT_EQ(1,
1084 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps")); 1054 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps"));
1085 EXPECT_EQ(1, 1055 EXPECT_EQ(
1086 metrics::NumEvents( 1056 1, metrics::NumEvents("WebRTC.Video.RetransmittedBitrateSentInKbps", 3));
1087 "WebRTC.Video.RetransmittedBitrateSentInKbps", 1057
1088 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) / 1058 // New metric counters but same data counters.
1089 metrics::kMinRunTimeInSeconds / 1000)));
1090
1091 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
1092 EXPECT_EQ(
1093 1, metrics::NumEvents(
1094 "WebRTC.Video.RtxBitrateSentInKbps",
1095 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
1096 metrics::kMinRunTimeInSeconds / 1000)));
1097
1098 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1099 EXPECT_EQ(1, metrics::NumEvents(
1100 "WebRTC.Video.FecBitrateSentInKbps",
1101 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
1102 metrics::kMinRunTimeInSeconds / 1000)));
1103
1104 // New start time but same counter values.
1105 proxy->DataCountersUpdated(counters, kFirstSsrc);
1106 proxy->DataCountersUpdated(counters, kSecondSsrc);
1107 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1108 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1109
1110 // Double counter values, this should result in the same counts as before but 1059 // Double counter values, this should result in the same counts as before but
1111 // with new histogram names. 1060 // with new histogram names.
1112 StreamDataCounters new_counters = counters; 1061 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
1113 new_counters.Add(counters); 1062 counters.transmitted.packets += 20;
1114 StreamDataCounters new_rtx_counters = rtx_counters; 1063 counters.transmitted.header_bytes += 500;
1115 new_rtx_counters.Add(rtx_counters); 1064 counters.transmitted.padding_bytes += 1000;
1116 1065 counters.transmitted.payload_bytes += 2000;
1117 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); 1066 counters.retransmitted.packets += 2;
1118 proxy->DataCountersUpdated(new_counters, kFirstSsrc); 1067 counters.retransmitted.header_bytes += 25;
1119 proxy->DataCountersUpdated(new_counters, kSecondSsrc); 1068 counters.retransmitted.padding_bytes += 100;
1120 proxy->DataCountersUpdated(new_rtx_counters, kFirstRtxSsrc); 1069 counters.retransmitted.payload_bytes += 250;
1121 proxy->DataCountersUpdated(new_rtx_counters, kSecondRtxSsrc); 1070 counters.fec = counters.retransmitted;
1122 1071 rtx_counters.transmitted = counters.transmitted;
1123 SetUp(); // Reset stats proxy also causes histograms to be reported. 1072 // Advance one interval and update counters.
1124 1073 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1074 proxy->DataCountersUpdated(counters, kFirstSsrc);
1075 proxy->DataCountersUpdated(counters, kSecondSsrc);
1076 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
1077 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
1078 }
1079
1080 // Reset stats proxy also causes histograms to be reported.
1081 statistics_proxy_.reset();
1082
1083 // Interval: 3500 bytes * 4 / 2 sec = 7000 bytes / sec = 56 kbps
1125 EXPECT_EQ(1, 1084 EXPECT_EQ(1,
1126 metrics::NumSamples("WebRTC.Video.Screenshare.BitrateSentInKbps")); 1085 metrics::NumSamples("WebRTC.Video.Screenshare.BitrateSentInKbps"));
1127 EXPECT_EQ(1, 1086 EXPECT_EQ(
1128 metrics::NumEvents( 1087 1, metrics::NumEvents("WebRTC.Video.Screenshare.BitrateSentInKbps", 56));
1129 "WebRTC.Video.Screenshare.BitrateSentInKbps", 1088 // Interval: 3500 bytes * 2 / 2 sec = 3500 bytes / sec = 28 kbps
1130 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) / 1089 EXPECT_EQ(
1131 metrics::kMinRunTimeInSeconds / 1000))); 1090 1, metrics::NumSamples("WebRTC.Video.Screenshare.RtxBitrateSentInKbps"));
1132 1091 EXPECT_EQ(1, metrics::NumEvents(
1092 "WebRTC.Video.Screenshare.RtxBitrateSentInKbps", 28));
1093 // Interval: (2000 - 2 * 250) bytes / 2 sec = 1500 bytes / sec = 12 kbps
1133 EXPECT_EQ(1, metrics::NumSamples( 1094 EXPECT_EQ(1, metrics::NumSamples(
1134 "WebRTC.Video.Screenshare.MediaBitrateSentInKbps")); 1095 "WebRTC.Video.Screenshare.MediaBitrateSentInKbps"));
1135 EXPECT_EQ(1, metrics::NumEvents( 1096 EXPECT_EQ(1, metrics::NumEvents(
1136 "WebRTC.Video.Screenshare.MediaBitrateSentInKbps", 1097 "WebRTC.Video.Screenshare.MediaBitrateSentInKbps", 12));
1137 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) / 1098 // Interval: 1000 bytes * 4 / 2 sec = 2000 bytes / sec = 16 kbps
1138 metrics::kMinRunTimeInSeconds / 1000)));
1139
1140 EXPECT_EQ(1, metrics::NumSamples( 1099 EXPECT_EQ(1, metrics::NumSamples(
1141 "WebRTC.Video.Screenshare.PaddingBitrateSentInKbps")); 1100 "WebRTC.Video.Screenshare.PaddingBitrateSentInKbps"));
1142 EXPECT_EQ(1, 1101 EXPECT_EQ(1, metrics::NumEvents(
1143 metrics::NumEvents( 1102 "WebRTC.Video.Screenshare.PaddingBitrateSentInKbps", 16));
1144 "WebRTC.Video.Screenshare.PaddingBitrateSentInKbps", 1103 // Interval: 375 bytes * 2 / 2 sec = 375 bytes / sec = 3 kbps
1145 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) / 1104 EXPECT_EQ(
1146 metrics::kMinRunTimeInSeconds / 1000))); 1105 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
1147 1106 EXPECT_EQ(1, metrics::NumEvents(
1107 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", 3));
1108 // Interval: 375 bytes * 2 / 2 sec = 375 bytes / sec = 3 kbps
1148 EXPECT_EQ(1, metrics::NumSamples( 1109 EXPECT_EQ(1, metrics::NumSamples(
1149 "WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps")); 1110 "WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps"));
1150 EXPECT_EQ(1, 1111 EXPECT_EQ(1,
1151 metrics::NumEvents( 1112 metrics::NumEvents(
1152 "WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps", 1113 "WebRTC.Video.Screenshare.RetransmittedBitrateSentInKbps", 3));
1153 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) / 1114 }
1154 metrics::kMinRunTimeInSeconds / 1000))); 1115
1155 1116 TEST_F(SendStatisticsProxyTest, RtxBitrateIsZeroWhenEnabledAndNoRtxDataIsSent) {
1156 EXPECT_EQ( 1117 StreamDataCountersCallback* proxy =
1157 1, metrics::NumSamples("WebRTC.Video.Screenshare.RtxBitrateSentInKbps")); 1118 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1158 EXPECT_EQ( 1119 StreamDataCounters counters;
1159 1, metrics::NumEvents( 1120 StreamDataCounters rtx_counters;
1160 "WebRTC.Video.Screenshare.RtxBitrateSentInKbps", 1121
1161 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) / 1122 const int kMinRequiredPeriodSamples = 8;
1162 metrics::kMinRunTimeInSeconds / 1000))); 1123 const int kPeriodIntervalMs = 2000;
1163 1124 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
1164 EXPECT_EQ( 1125 counters.transmitted.packets += 20;
1165 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); 1126 counters.transmitted.header_bytes += 500;
1166 EXPECT_EQ(1, metrics::NumEvents( 1127 counters.transmitted.payload_bytes += 2000;
1167 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", 1128 counters.fec = counters.retransmitted;
1168 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) / 1129 // Advance one interval and update counters.
1169 metrics::kMinRunTimeInSeconds / 1000))); 1130 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1131 proxy->DataCountersUpdated(counters, kFirstSsrc);
1132 }
1133
1134 // RTX enabled. No data sent over RTX.
1135 statistics_proxy_.reset();
1136 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
1137 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.RtxBitrateSentInKbps", 0));
1138 }
1139
1140 TEST_F(SendStatisticsProxyTest, RtxBitrateNotReportedWhenNotEnabled) {
1141 VideoSendStream::Config config(nullptr);
1142 config.rtp.ssrcs.push_back(kFirstSsrc); // RTX not configured.
1143 statistics_proxy_.reset(new SendStatisticsProxy(
1144 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo));
1145
1146 StreamDataCountersCallback* proxy =
1147 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1148 StreamDataCounters counters;
1149
1150 const int kMinRequiredPeriodSamples = 8;
1151 const int kPeriodIntervalMs = 2000;
1152 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
1153 counters.transmitted.packets += 20;
1154 counters.transmitted.header_bytes += 500;
1155 counters.transmitted.payload_bytes += 2000;
1156 counters.fec = counters.retransmitted;
1157 // Advance one interval and update counters.
1158 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1159 proxy->DataCountersUpdated(counters, kFirstSsrc);
1160 }
1161
1162 // RTX not enabled.
1163 statistics_proxy_.reset();
1164 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
1165 }
1166
1167 TEST_F(SendStatisticsProxyTest, FecBitrateIsZeroWhenEnabledAndNoFecDataIsSent) {
1168 StreamDataCountersCallback* proxy =
1169 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1170 StreamDataCounters counters;
1171 StreamDataCounters rtx_counters;
1172
1173 const int kMinRequiredPeriodSamples = 8;
1174 const int kPeriodIntervalMs = 2000;
1175 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
1176 counters.transmitted.packets += 20;
1177 counters.transmitted.header_bytes += 500;
1178 counters.transmitted.payload_bytes += 2000;
1179 // Advance one interval and update counters.
1180 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1181 proxy->DataCountersUpdated(counters, kFirstSsrc);
1182 }
1183
1184 // FEC enabled. No FEC data sent.
1185 statistics_proxy_.reset();
1186 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1187 EXPECT_EQ(1, metrics::NumEvents("WebRTC.Video.FecBitrateSentInKbps", 0));
1188 }
1189
1190 TEST_F(SendStatisticsProxyTest, FecBitrateNotReportedWhenNotEnabled) {
1191 VideoSendStream::Config config(nullptr);
1192 config.rtp.ssrcs.push_back(kFirstSsrc); // FEC not configured.
1193 statistics_proxy_.reset(new SendStatisticsProxy(
1194 &fake_clock_, config, VideoEncoderConfig::ContentType::kRealtimeVideo));
1195
1196 StreamDataCountersCallback* proxy =
1197 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
1198 StreamDataCounters counters;
1199
1200 const int kMinRequiredPeriodSamples = 8;
1201 const int kPeriodIntervalMs = 2000;
1202 for (int i = 0; i < kMinRequiredPeriodSamples; ++i) {
1203 counters.transmitted.packets += 20;
1204 counters.transmitted.header_bytes += 500;
1205 counters.transmitted.payload_bytes += 2000;
1206 counters.fec = counters.retransmitted;
1207 // Advance one interval and update counters.
1208 fake_clock_.AdvanceTimeMilliseconds(kPeriodIntervalMs);
1209 proxy->DataCountersUpdated(counters, kFirstSsrc);
1210 }
1211
1212 // FEC not enabled.
1213 statistics_proxy_.reset();
1214 EXPECT_EQ(0, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
1170 } 1215 }
1171 1216
1172 } // namespace webrtc 1217 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698