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

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

Issue 2525293002: Sent bitrate stats are incorrect if FlexFEC is configured. (Closed)
Patch Set: address comment 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
« no previous file with comments | « webrtc/video/send_statistics_proxy.cc ('k') | webrtc/video/video_send_stream.cc » ('j') | 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) 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
11 #include "webrtc/video/send_statistics_proxy.h" 11 #include "webrtc/video/send_statistics_proxy.h"
12 12
13 #include <map> 13 #include <map>
14 #include <memory> 14 #include <memory>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/system_wrappers/include/metrics.h" 18 #include "webrtc/system_wrappers/include/metrics.h"
19 #include "webrtc/system_wrappers/include/metrics_default.h" 19 #include "webrtc/system_wrappers/include/metrics_default.h"
20 #include "webrtc/test/gtest.h" 20 #include "webrtc/test/gtest.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 namespace { 23 namespace {
24 const uint32_t kFirstSsrc = 17; 24 const uint32_t kFirstSsrc = 17;
25 const uint32_t kSecondSsrc = 42; 25 const uint32_t kSecondSsrc = 42;
26 const uint32_t kFirstRtxSsrc = 18; 26 const uint32_t kFirstRtxSsrc = 18;
27 const uint32_t kSecondRtxSsrc = 43; 27 const uint32_t kSecondRtxSsrc = 43;
28 const uint32_t kFlexFecSsrc = 55;
28 29
29 const int kQpIdx0 = 21; 30 const int kQpIdx0 = 21;
30 const int kQpIdx1 = 39; 31 const int kQpIdx1 = 39;
31 } // namespace 32 } // namespace
32 33
33 class SendStatisticsProxyTest : public ::testing::Test { 34 class SendStatisticsProxyTest : public ::testing::Test {
34 public: 35 public:
35 SendStatisticsProxyTest() 36 SendStatisticsProxyTest()
36 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), 37 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0),
37 max_delay_ms_(0) {} 38 max_delay_ms_(0) {}
(...skipping 15 matching lines...) Expand all
53 VideoSendStream::Config GetTestConfig() { 54 VideoSendStream::Config GetTestConfig() {
54 VideoSendStream::Config config(nullptr); 55 VideoSendStream::Config config(nullptr);
55 config.rtp.ssrcs.push_back(kFirstSsrc); 56 config.rtp.ssrcs.push_back(kFirstSsrc);
56 config.rtp.ssrcs.push_back(kSecondSsrc); 57 config.rtp.ssrcs.push_back(kSecondSsrc);
57 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc); 58 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc);
58 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc); 59 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc);
59 config.rtp.ulpfec.red_payload_type = 17; 60 config.rtp.ulpfec.red_payload_type = 17;
60 return config; 61 return config;
61 } 62 }
62 63
64 VideoSendStream::Config GetTestConfigWithFlexFec() {
65 VideoSendStream::Config config(nullptr);
66 config.rtp.ssrcs.push_back(kFirstSsrc);
67 config.rtp.ssrcs.push_back(kSecondSsrc);
68 config.rtp.rtx.ssrcs.push_back(kFirstRtxSsrc);
69 config.rtp.rtx.ssrcs.push_back(kSecondRtxSsrc);
70 config.rtp.flexfec.flexfec_payload_type = 50;
71 config.rtp.flexfec.flexfec_ssrc = kFlexFecSsrc;
72 return config;
73 }
74
75 VideoSendStream::StreamStats GetStreamStats(uint32_t ssrc) {
76 VideoSendStream::Stats stats = statistics_proxy_->GetStats();
77 std::map<uint32_t, VideoSendStream::StreamStats>::iterator it =
78 stats.substreams.find(ssrc);
79 EXPECT_NE(it, stats.substreams.end());
80 return it->second;
81 }
82
63 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { 83 void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) {
64 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); 84 EXPECT_EQ(one.input_frame_rate, other.input_frame_rate);
65 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); 85 EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate);
66 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); 86 EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps);
67 EXPECT_EQ(one.preferred_media_bitrate_bps, 87 EXPECT_EQ(one.preferred_media_bitrate_bps,
68 other.preferred_media_bitrate_bps); 88 other.preferred_media_bitrate_bps);
69 EXPECT_EQ(one.suspended, other.suspended); 89 EXPECT_EQ(one.suspended, other.suspended);
70 90
71 EXPECT_EQ(one.substreams.size(), other.substreams.size()); 91 EXPECT_EQ(one.substreams.size(), other.substreams.size());
72 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it = 92 for (std::map<uint32_t, VideoSendStream::StreamStats>::const_iterator it =
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 2 * kRate)); 837 2 * kRate));
818 EXPECT_EQ(1, metrics::NumEvents( 838 EXPECT_EQ(1, metrics::NumEvents(
819 "WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute", 839 "WebRTC.Video.Screenshare.PliPacketsReceivedPerMinute",
820 3 * kRate)); 840 3 * kRate));
821 EXPECT_EQ(1, 841 EXPECT_EQ(1,
822 metrics::NumEvents( 842 metrics::NumEvents(
823 "WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent", 843 "WebRTC.Video.Screenshare.UniqueNackRequestsReceivedInPercent",
824 4 * 100 / 5)); 844 4 * 100 / 5));
825 } 845 }
826 846
847 TEST_F(SendStatisticsProxyTest, GetStatsReportsIsFlexFec) {
848 statistics_proxy_.reset(
849 new SendStatisticsProxy(&fake_clock_, GetTestConfigWithFlexFec(),
850 VideoEncoderConfig::ContentType::kRealtimeVideo));
851
852 StreamDataCountersCallback* proxy =
853 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
854 StreamDataCounters counters;
855 proxy->DataCountersUpdated(counters, kFirstSsrc);
856 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
857
858 EXPECT_FALSE(GetStreamStats(kFirstSsrc).is_flexfec);
859 EXPECT_TRUE(GetStreamStats(kFlexFecSsrc).is_flexfec);
860 }
861
862 TEST_F(SendStatisticsProxyTest, SendBitratesAreReportedWithFlexFecEnabled) {
863 statistics_proxy_.reset(
864 new SendStatisticsProxy(&fake_clock_, GetTestConfigWithFlexFec(),
865 VideoEncoderConfig::ContentType::kRealtimeVideo));
866
867 StreamDataCountersCallback* proxy =
868 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
869
870 StreamDataCounters counters;
871 StreamDataCounters rtx_counters;
872 proxy->DataCountersUpdated(counters, kFirstSsrc);
873 proxy->DataCountersUpdated(counters, kSecondSsrc);
874 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
875 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
876 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
877
878 counters.transmitted.header_bytes = 5000;
879 counters.transmitted.packets = 20;
880 counters.transmitted.padding_bytes = 10000;
881 counters.transmitted.payload_bytes = 20000;
882 counters.retransmitted.header_bytes = 400;
883 counters.retransmitted.packets = 2;
884 counters.retransmitted.padding_bytes = 1000;
885 counters.retransmitted.payload_bytes = 2000;
886 counters.fec = counters.retransmitted;
887 rtx_counters.transmitted = counters.transmitted;
888
889 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
890 proxy->DataCountersUpdated(counters, kFirstSsrc);
891 proxy->DataCountersUpdated(counters, kSecondSsrc);
892 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
893 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
894 proxy->DataCountersUpdated(counters, kFlexFecSsrc);
895
896 // Reset stats proxy causes histograms to be reported.
897 statistics_proxy_.reset();
898 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.BitrateSentInKbps"));
899 EXPECT_EQ(1,
900 metrics::NumEvents(
901 "WebRTC.Video.BitrateSentInKbps",
902 static_cast<int>((counters.transmitted.TotalBytes() * 4 * 8) /
903 metrics::kMinRunTimeInSeconds / 1000)));
904
905 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.MediaBitrateSentInKbps"));
906 EXPECT_EQ(1, metrics::NumEvents(
907 "WebRTC.Video.MediaBitrateSentInKbps",
908 static_cast<int>((counters.MediaPayloadBytes() * 2 * 8) /
909 metrics::kMinRunTimeInSeconds / 1000)));
910
911 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.PaddingBitrateSentInKbps"));
912 EXPECT_EQ(1,
913 metrics::NumEvents(
914 "WebRTC.Video.PaddingBitrateSentInKbps",
915 static_cast<int>((counters.transmitted.padding_bytes * 4 * 8) /
916 metrics::kMinRunTimeInSeconds / 1000)));
917
918 EXPECT_EQ(1,
919 metrics::NumSamples("WebRTC.Video.RetransmittedBitrateSentInKbps"));
920 EXPECT_EQ(1,
921 metrics::NumEvents(
922 "WebRTC.Video.RetransmittedBitrateSentInKbps",
923 static_cast<int>((counters.retransmitted.TotalBytes() * 2 * 8) /
924 metrics::kMinRunTimeInSeconds / 1000)));
925
926 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
927 EXPECT_EQ(
928 1, metrics::NumEvents(
929 "WebRTC.Video.RtxBitrateSentInKbps",
930 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
931 metrics::kMinRunTimeInSeconds / 1000)));
932
933 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
934 EXPECT_EQ(1, metrics::NumEvents(
935 "WebRTC.Video.FecBitrateSentInKbps",
936 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
937 metrics::kMinRunTimeInSeconds / 1000)));
938 }
939
827 TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) { 940 TEST_F(SendStatisticsProxyTest, ResetsRtpCountersOnContentChange) {
828 StreamDataCountersCallback* proxy = 941 StreamDataCountersCallback* proxy =
829 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get()); 942 static_cast<StreamDataCountersCallback*>(statistics_proxy_.get());
830 StreamDataCounters counters; 943 StreamDataCounters counters;
831 StreamDataCounters rtx_counters; 944 StreamDataCounters rtx_counters;
832 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds(); 945 counters.first_packet_time_ms = fake_clock_.TimeInMilliseconds();
833 proxy->DataCountersUpdated(counters, kFirstSsrc); 946 proxy->DataCountersUpdated(counters, kFirstSsrc);
834 proxy->DataCountersUpdated(counters, kSecondSsrc); 947 proxy->DataCountersUpdated(counters, kSecondSsrc);
835 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc); 948 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
836 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc); 949 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
837 950
838 counters.transmitted.header_bytes = 400; 951 counters.transmitted.header_bytes = 5000;
839 counters.transmitted.packets = 20; 952 counters.transmitted.packets = 20;
840 counters.transmitted.padding_bytes = 1000; 953 counters.transmitted.padding_bytes = 10000;
841 counters.transmitted.payload_bytes = 2000; 954 counters.transmitted.payload_bytes = 20000;
842 955
843 counters.retransmitted.header_bytes = 40; 956 counters.retransmitted.header_bytes = 400;
844 counters.retransmitted.packets = 2; 957 counters.retransmitted.packets = 2;
845 counters.retransmitted.padding_bytes = 100; 958 counters.retransmitted.padding_bytes = 1000;
846 counters.retransmitted.payload_bytes = 200; 959 counters.retransmitted.payload_bytes = 2000;
847 960
848 counters.fec = counters.retransmitted; 961 counters.fec = counters.retransmitted;
849 962
850 rtx_counters.transmitted = counters.transmitted; 963 rtx_counters.transmitted = counters.transmitted;
851 964
852 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds); 965 fake_clock_.AdvanceTimeMilliseconds(1000 * metrics::kMinRunTimeInSeconds);
853 proxy->DataCountersUpdated(counters, kFirstSsrc); 966 proxy->DataCountersUpdated(counters, kFirstSsrc);
854 proxy->DataCountersUpdated(counters, kSecondSsrc); 967 proxy->DataCountersUpdated(counters, kSecondSsrc);
855 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc); 968 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
856 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc); 969 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps")); 1004 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.RtxBitrateSentInKbps"));
892 EXPECT_EQ( 1005 EXPECT_EQ(
893 1, metrics::NumEvents( 1006 1, metrics::NumEvents(
894 "WebRTC.Video.RtxBitrateSentInKbps", 1007 "WebRTC.Video.RtxBitrateSentInKbps",
895 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) / 1008 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
896 metrics::kMinRunTimeInSeconds / 1000))); 1009 metrics::kMinRunTimeInSeconds / 1000)));
897 1010
898 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps")); 1011 EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.FecBitrateSentInKbps"));
899 EXPECT_EQ(1, metrics::NumEvents( 1012 EXPECT_EQ(1, metrics::NumEvents(
900 "WebRTC.Video.FecBitrateSentInKbps", 1013 "WebRTC.Video.FecBitrateSentInKbps",
901 static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / 1014 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
902 metrics::kMinRunTimeInSeconds / 1000))); 1015 metrics::kMinRunTimeInSeconds / 1000)));
903 1016
904 // New start time but same counter values. 1017 // New start time but same counter values.
905 proxy->DataCountersUpdated(counters, kFirstSsrc); 1018 proxy->DataCountersUpdated(counters, kFirstSsrc);
906 proxy->DataCountersUpdated(counters, kSecondSsrc); 1019 proxy->DataCountersUpdated(counters, kSecondSsrc);
907 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc); 1020 proxy->DataCountersUpdated(rtx_counters, kFirstRtxSsrc);
908 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc); 1021 proxy->DataCountersUpdated(rtx_counters, kSecondRtxSsrc);
909 1022
910 // Double counter values, this should result in the same counts as before but 1023 // Double counter values, this should result in the same counts as before but
911 // with new histogram names. 1024 // with new histogram names.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 EXPECT_EQ( 1071 EXPECT_EQ(
959 1, metrics::NumEvents( 1072 1, metrics::NumEvents(
960 "WebRTC.Video.Screenshare.RtxBitrateSentInKbps", 1073 "WebRTC.Video.Screenshare.RtxBitrateSentInKbps",
961 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) / 1074 static_cast<int>((rtx_counters.transmitted.TotalBytes() * 2 * 8) /
962 metrics::kMinRunTimeInSeconds / 1000))); 1075 metrics::kMinRunTimeInSeconds / 1000)));
963 1076
964 EXPECT_EQ( 1077 EXPECT_EQ(
965 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps")); 1078 1, metrics::NumSamples("WebRTC.Video.Screenshare.FecBitrateSentInKbps"));
966 EXPECT_EQ(1, metrics::NumEvents( 1079 EXPECT_EQ(1, metrics::NumEvents(
967 "WebRTC.Video.Screenshare.FecBitrateSentInKbps", 1080 "WebRTC.Video.Screenshare.FecBitrateSentInKbps",
968 static_cast<int>((rtx_counters.fec.TotalBytes() * 2 * 8) / 1081 static_cast<int>((counters.fec.TotalBytes() * 2 * 8) /
969 metrics::kMinRunTimeInSeconds / 1000))); 1082 metrics::kMinRunTimeInSeconds / 1000)));
970 } 1083 }
971 1084
972 } // namespace webrtc 1085 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/send_statistics_proxy.cc ('k') | webrtc/video/video_send_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698