sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This file includes unit tests for SendStatisticsProxy. |
| 12 | #include "webrtc/video/send_statistics_proxy.h" |
| 13 | |
| 14 | #include <map> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "testing/gtest/include/gtest/gtest.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 22 | class SendStatisticsProxyTest : public ::testing::Test { |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 23 | public: |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 24 | SendStatisticsProxyTest() |
| 25 | : fake_clock_(1234), avg_delay_ms_(0), max_delay_ms_(0) {} |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 26 | virtual ~SendStatisticsProxyTest() {} |
| 27 | |
| 28 | protected: |
| 29 | virtual void SetUp() { |
| 30 | statistics_proxy_.reset( |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 31 | new SendStatisticsProxy(&fake_clock_, GetTestConfig())); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 32 | config_ = GetTestConfig(); |
| 33 | expected_ = VideoSendStream::Stats(); |
| 34 | } |
| 35 | |
| 36 | VideoSendStream::Config GetTestConfig() { |
| 37 | VideoSendStream::Config config; |
| 38 | config.rtp.ssrcs.push_back(17); |
| 39 | config.rtp.ssrcs.push_back(42); |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 40 | config.rtp.rtx.ssrcs.push_back(18); |
| 41 | config.rtp.rtx.ssrcs.push_back(43); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 42 | return config; |
| 43 | } |
| 44 | |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 45 | void ExpectEqual(VideoSendStream::Stats one, VideoSendStream::Stats other) { |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 46 | EXPECT_EQ(one.input_frame_rate, other.input_frame_rate); |
| 47 | EXPECT_EQ(one.encode_frame_rate, other.encode_frame_rate); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 48 | EXPECT_EQ(one.media_bitrate_bps, other.media_bitrate_bps); |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 49 | EXPECT_EQ(one.suspended, other.suspended); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 50 | |
| 51 | EXPECT_EQ(one.substreams.size(), other.substreams.size()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 52 | for (std::map<uint32_t, SsrcStats>::const_iterator it = |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 53 | one.substreams.begin(); |
| 54 | it != one.substreams.end(); |
| 55 | ++it) { |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 56 | std::map<uint32_t, SsrcStats>::const_iterator corresponding_it = |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 57 | other.substreams.find(it->first); |
| 58 | ASSERT_TRUE(corresponding_it != other.substreams.end()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 59 | const SsrcStats& a = it->second; |
| 60 | const SsrcStats& b = corresponding_it->second; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 61 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 62 | EXPECT_EQ(a.frame_counts.key_frames, b.frame_counts.key_frames); |
| 63 | EXPECT_EQ(a.frame_counts.delta_frames, b.frame_counts.delta_frames); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 64 | EXPECT_EQ(a.total_bitrate_bps, b.total_bitrate_bps); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 65 | EXPECT_EQ(a.avg_delay_ms, b.avg_delay_ms); |
| 66 | EXPECT_EQ(a.max_delay_ms, b.max_delay_ms); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 67 | |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame^] | 68 | EXPECT_EQ(a.rtp_stats.transmitted.payload_bytes, |
| 69 | b.rtp_stats.transmitted.payload_bytes); |
| 70 | EXPECT_EQ(a.rtp_stats.transmitted.header_bytes, |
| 71 | b.rtp_stats.transmitted.header_bytes); |
| 72 | EXPECT_EQ(a.rtp_stats.transmitted.padding_bytes, |
| 73 | b.rtp_stats.transmitted.padding_bytes); |
| 74 | EXPECT_EQ(a.rtp_stats.transmitted.packets, |
| 75 | b.rtp_stats.transmitted.packets); |
| 76 | EXPECT_EQ(a.rtp_stats.retransmitted.packets, |
| 77 | b.rtp_stats.retransmitted.packets); |
| 78 | EXPECT_EQ(a.rtp_stats.fec.packets, b.rtp_stats.fec.packets); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 79 | |
| 80 | EXPECT_EQ(a.rtcp_stats.fraction_lost, b.rtcp_stats.fraction_lost); |
| 81 | EXPECT_EQ(a.rtcp_stats.cumulative_lost, b.rtcp_stats.cumulative_lost); |
| 82 | EXPECT_EQ(a.rtcp_stats.extended_max_sequence_number, |
| 83 | b.rtcp_stats.extended_max_sequence_number); |
| 84 | EXPECT_EQ(a.rtcp_stats.jitter, b.rtcp_stats.jitter); |
| 85 | } |
| 86 | } |
| 87 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 88 | scoped_ptr<SendStatisticsProxy> statistics_proxy_; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 89 | SimulatedClock fake_clock_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 90 | VideoSendStream::Config config_; |
| 91 | int avg_delay_ms_; |
| 92 | int max_delay_ms_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 93 | VideoSendStream::Stats expected_; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 94 | typedef std::map<uint32_t, SsrcStats>::const_iterator StreamIterator; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | TEST_F(SendStatisticsProxyTest, RtcpStatistics) { |
| 98 | RtcpStatisticsCallback* callback = statistics_proxy_.get(); |
| 99 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.ssrcs.begin(); |
| 100 | it != config_.rtp.ssrcs.end(); |
| 101 | ++it) { |
| 102 | const uint32_t ssrc = *it; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 103 | SsrcStats& ssrc_stats = expected_.substreams[ssrc]; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 104 | |
| 105 | // Add statistics with some arbitrary, but unique, numbers. |
| 106 | uint32_t offset = ssrc * sizeof(RtcpStatistics); |
| 107 | ssrc_stats.rtcp_stats.cumulative_lost = offset; |
| 108 | ssrc_stats.rtcp_stats.extended_max_sequence_number = offset + 1; |
| 109 | ssrc_stats.rtcp_stats.fraction_lost = offset + 2; |
| 110 | ssrc_stats.rtcp_stats.jitter = offset + 3; |
| 111 | callback->StatisticsUpdated(ssrc_stats.rtcp_stats, ssrc); |
| 112 | } |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 113 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.rtx.ssrcs.begin(); |
| 114 | it != config_.rtp.rtx.ssrcs.end(); |
| 115 | ++it) { |
| 116 | const uint32_t ssrc = *it; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 117 | SsrcStats& ssrc_stats = expected_.substreams[ssrc]; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 118 | |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 119 | // Add statistics with some arbitrary, but unique, numbers. |
| 120 | uint32_t offset = ssrc * sizeof(RtcpStatistics); |
| 121 | ssrc_stats.rtcp_stats.cumulative_lost = offset; |
| 122 | ssrc_stats.rtcp_stats.extended_max_sequence_number = offset + 1; |
| 123 | ssrc_stats.rtcp_stats.fraction_lost = offset + 2; |
| 124 | ssrc_stats.rtcp_stats.jitter = offset + 3; |
| 125 | callback->StatisticsUpdated(ssrc_stats.rtcp_stats, ssrc); |
| 126 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 127 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 128 | ExpectEqual(expected_, stats); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 129 | } |
| 130 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 131 | TEST_F(SendStatisticsProxyTest, CaptureFramerate) { |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 132 | const int capture_fps = 31; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 133 | |
| 134 | ViECaptureObserver* capture_observer = statistics_proxy_.get(); |
| 135 | capture_observer->CapturedFrameRate(0, capture_fps); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 136 | |
| 137 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 138 | EXPECT_EQ(capture_fps, stats.input_frame_rate); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | TEST_F(SendStatisticsProxyTest, EncodedBitrateAndFramerate) { |
| 142 | const int media_bitrate_bps = 500; |
| 143 | const int encode_fps = 29; |
| 144 | |
| 145 | ViEEncoderObserver* encoder_observer = statistics_proxy_.get(); |
| 146 | encoder_observer->OutgoingRate(0, encode_fps, media_bitrate_bps); |
| 147 | |
| 148 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 149 | EXPECT_EQ(media_bitrate_bps, stats.media_bitrate_bps); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 150 | EXPECT_EQ(encode_fps, stats.encode_frame_rate); |
| 151 | } |
| 152 | |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 153 | TEST_F(SendStatisticsProxyTest, Suspended) { |
| 154 | // Verify that the value is false by default. |
| 155 | EXPECT_FALSE(statistics_proxy_->GetStats().suspended); |
| 156 | |
| 157 | // Verify that we can set it to true. |
| 158 | ViEEncoderObserver* encoder_observer = statistics_proxy_.get(); |
| 159 | encoder_observer->SuspendChange(0, true); |
| 160 | EXPECT_TRUE(statistics_proxy_->GetStats().suspended); |
| 161 | |
| 162 | // Verify that we can set it back to false again. |
| 163 | encoder_observer->SuspendChange(0, false); |
| 164 | EXPECT_FALSE(statistics_proxy_->GetStats().suspended); |
| 165 | } |
| 166 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 167 | TEST_F(SendStatisticsProxyTest, FrameCounts) { |
| 168 | FrameCountObserver* observer = statistics_proxy_.get(); |
| 169 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.ssrcs.begin(); |
| 170 | it != config_.rtp.ssrcs.end(); |
| 171 | ++it) { |
| 172 | const uint32_t ssrc = *it; |
| 173 | // Add statistics with some arbitrary, but unique, numbers. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 174 | SsrcStats& stats = expected_.substreams[ssrc]; |
| 175 | uint32_t offset = ssrc * sizeof(SsrcStats); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 176 | FrameCounts frame_counts; |
| 177 | frame_counts.key_frames = offset; |
| 178 | frame_counts.delta_frames = offset + 1; |
| 179 | stats.frame_counts = frame_counts; |
| 180 | observer->FrameCountUpdated(frame_counts, ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 181 | } |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 182 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.rtx.ssrcs.begin(); |
| 183 | it != config_.rtp.rtx.ssrcs.end(); |
| 184 | ++it) { |
| 185 | const uint32_t ssrc = *it; |
| 186 | // Add statistics with some arbitrary, but unique, numbers. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 187 | SsrcStats& stats = expected_.substreams[ssrc]; |
| 188 | uint32_t offset = ssrc * sizeof(SsrcStats); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 189 | FrameCounts frame_counts; |
| 190 | frame_counts.key_frames = offset; |
| 191 | frame_counts.delta_frames = offset + 1; |
| 192 | stats.frame_counts = frame_counts; |
| 193 | observer->FrameCountUpdated(frame_counts, ssrc); |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 194 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 195 | |
| 196 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 197 | ExpectEqual(expected_, stats); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | TEST_F(SendStatisticsProxyTest, DataCounters) { |
| 201 | StreamDataCountersCallback* callback = statistics_proxy_.get(); |
| 202 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.ssrcs.begin(); |
| 203 | it != config_.rtp.ssrcs.end(); |
| 204 | ++it) { |
| 205 | const uint32_t ssrc = *it; |
| 206 | StreamDataCounters& counters = expected_.substreams[ssrc].rtp_stats; |
| 207 | // Add statistics with some arbitrary, but unique, numbers. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 208 | size_t offset = ssrc * sizeof(StreamDataCounters); |
| 209 | uint32_t offset_uint32 = static_cast<uint32_t>(offset); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame^] | 210 | counters.transmitted.payload_bytes = offset; |
| 211 | counters.transmitted.header_bytes = offset + 1; |
| 212 | counters.fec.packets = offset_uint32 + 2; |
| 213 | counters.transmitted.padding_bytes = offset + 3; |
| 214 | counters.retransmitted.packets = offset_uint32 + 4; |
| 215 | counters.transmitted.packets = offset_uint32 + 5; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 216 | callback->DataCountersUpdated(counters, ssrc); |
| 217 | } |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 218 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.rtx.ssrcs.begin(); |
| 219 | it != config_.rtp.rtx.ssrcs.end(); |
| 220 | ++it) { |
| 221 | const uint32_t ssrc = *it; |
| 222 | StreamDataCounters& counters = expected_.substreams[ssrc].rtp_stats; |
| 223 | // Add statistics with some arbitrary, but unique, numbers. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 224 | size_t offset = ssrc * sizeof(StreamDataCounters); |
| 225 | uint32_t offset_uint32 = static_cast<uint32_t>(offset); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame^] | 226 | counters.transmitted.payload_bytes = offset; |
| 227 | counters.transmitted.header_bytes = offset + 1; |
| 228 | counters.fec.packets = offset_uint32 + 2; |
| 229 | counters.transmitted.padding_bytes = offset + 3; |
| 230 | counters.retransmitted.packets = offset_uint32 + 4; |
| 231 | counters.transmitted.packets = offset_uint32 + 5; |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 232 | callback->DataCountersUpdated(counters, ssrc); |
| 233 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 234 | |
| 235 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 236 | ExpectEqual(expected_, stats); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | TEST_F(SendStatisticsProxyTest, Bitrate) { |
| 240 | BitrateStatisticsObserver* observer = statistics_proxy_.get(); |
| 241 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.ssrcs.begin(); |
| 242 | it != config_.rtp.ssrcs.end(); |
| 243 | ++it) { |
| 244 | const uint32_t ssrc = *it; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 245 | BitrateStatistics total; |
| 246 | BitrateStatistics retransmit; |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 247 | // Use ssrc as bitrate_bps to get a unique value for each stream. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 248 | total.bitrate_bps = ssrc; |
| 249 | retransmit.bitrate_bps = ssrc + 1; |
| 250 | observer->Notify(total, retransmit, ssrc); |
| 251 | expected_.substreams[ssrc].total_bitrate_bps = total.bitrate_bps; |
| 252 | expected_.substreams[ssrc].retransmit_bitrate_bps = retransmit.bitrate_bps; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 253 | } |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 254 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.rtx.ssrcs.begin(); |
| 255 | it != config_.rtp.rtx.ssrcs.end(); |
| 256 | ++it) { |
| 257 | const uint32_t ssrc = *it; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 258 | BitrateStatistics total; |
| 259 | BitrateStatistics retransmit; |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 260 | // Use ssrc as bitrate_bps to get a unique value for each stream. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 261 | total.bitrate_bps = ssrc; |
| 262 | retransmit.bitrate_bps = ssrc + 1; |
| 263 | observer->Notify(total, retransmit, ssrc); |
| 264 | expected_.substreams[ssrc].total_bitrate_bps = total.bitrate_bps; |
| 265 | expected_.substreams[ssrc].retransmit_bitrate_bps = retransmit.bitrate_bps; |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 266 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 267 | |
| 268 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 269 | ExpectEqual(expected_, stats); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 270 | } |
| 271 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 272 | TEST_F(SendStatisticsProxyTest, SendSideDelay) { |
| 273 | SendSideDelayObserver* observer = statistics_proxy_.get(); |
| 274 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.ssrcs.begin(); |
| 275 | it != config_.rtp.ssrcs.end(); |
| 276 | ++it) { |
| 277 | const uint32_t ssrc = *it; |
| 278 | // Use ssrc as avg_delay_ms and max_delay_ms to get a unique value for each |
| 279 | // stream. |
| 280 | int avg_delay_ms = ssrc; |
| 281 | int max_delay_ms = ssrc + 1; |
| 282 | observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc); |
| 283 | expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms; |
| 284 | expected_.substreams[ssrc].max_delay_ms = max_delay_ms; |
| 285 | } |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 286 | for (std::vector<uint32_t>::const_iterator it = config_.rtp.rtx.ssrcs.begin(); |
| 287 | it != config_.rtp.rtx.ssrcs.end(); |
| 288 | ++it) { |
| 289 | const uint32_t ssrc = *it; |
| 290 | // Use ssrc as avg_delay_ms and max_delay_ms to get a unique value for each |
| 291 | // stream. |
| 292 | int avg_delay_ms = ssrc; |
| 293 | int max_delay_ms = ssrc + 1; |
| 294 | observer->SendSideDelayUpdated(avg_delay_ms, max_delay_ms, ssrc); |
| 295 | expected_.substreams[ssrc].avg_delay_ms = avg_delay_ms; |
| 296 | expected_.substreams[ssrc].max_delay_ms = max_delay_ms; |
| 297 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 298 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 299 | ExpectEqual(expected_, stats); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
| 303 | uint32_t exluded_ssrc = |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 304 | std::max( |
| 305 | *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), |
| 306 | *std::max_element(config_.rtp.rtx.ssrcs.begin(), |
| 307 | config_.rtp.rtx.ssrcs.end())) + |
| 308 | 1; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 309 | // From RtcpStatisticsCallback. |
| 310 | RtcpStatistics rtcp_stats; |
| 311 | RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); |
| 312 | rtcp_callback->StatisticsUpdated(rtcp_stats, exluded_ssrc); |
| 313 | |
| 314 | // From StreamDataCountersCallback. |
| 315 | StreamDataCounters rtp_stats; |
| 316 | StreamDataCountersCallback* rtp_callback = statistics_proxy_.get(); |
| 317 | rtp_callback->DataCountersUpdated(rtp_stats, exluded_ssrc); |
| 318 | |
| 319 | // From BitrateStatisticsObserver. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 320 | BitrateStatistics total; |
| 321 | BitrateStatistics retransmit; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 322 | BitrateStatisticsObserver* bitrate_observer = statistics_proxy_.get(); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 323 | bitrate_observer->Notify(total, retransmit, exluded_ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 324 | |
| 325 | // From FrameCountObserver. |
| 326 | FrameCountObserver* fps_observer = statistics_proxy_.get(); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 327 | FrameCounts frame_counts; |
| 328 | frame_counts.key_frames = 1; |
| 329 | fps_observer->FrameCountUpdated(frame_counts, exluded_ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 330 | |
| 331 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 332 | EXPECT_TRUE(stats.substreams.empty()); |
| 333 | } |
| 334 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 335 | TEST_F(SendStatisticsProxyTest, EncodedResolutionTimesOut) { |
| 336 | static const int kEncodedWidth = 123; |
| 337 | static const int kEncodedHeight = 81; |
| 338 | EncodedImage encoded_image; |
| 339 | encoded_image._encodedWidth = kEncodedWidth; |
| 340 | encoded_image._encodedHeight = kEncodedHeight; |
| 341 | |
| 342 | RTPVideoHeader rtp_video_header; |
| 343 | |
| 344 | rtp_video_header.simulcastIdx = 0; |
| 345 | statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 346 | rtp_video_header.simulcastIdx = 1; |
| 347 | statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 348 | |
| 349 | VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 350 | EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].sent_width); |
| 351 | EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].sent_height); |
| 352 | EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[1]].sent_width); |
| 353 | EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[1]].sent_height); |
| 354 | |
| 355 | // Forward almost to timeout, this should not have removed stats. |
| 356 | fake_clock_.AdvanceTimeMilliseconds(SendStatisticsProxy::kStatsTimeoutMs - 1); |
| 357 | stats = statistics_proxy_->GetStats(); |
| 358 | EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].sent_width); |
| 359 | EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].sent_height); |
| 360 | |
| 361 | // Update the first SSRC with bogus RTCP stats to make sure that encoded |
| 362 | // resolution still times out (no global timeout for all stats). |
| 363 | RtcpStatistics rtcp_statistics; |
| 364 | RtcpStatisticsCallback* rtcp_stats = statistics_proxy_.get(); |
| 365 | rtcp_stats->StatisticsUpdated(rtcp_statistics, config_.rtp.ssrcs[0]); |
| 366 | |
| 367 | // Report stats for second SSRC to make sure it's not outdated along with the |
| 368 | // first SSRC. |
| 369 | rtp_video_header.simulcastIdx = 1; |
| 370 | statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 371 | |
| 372 | // Forward 1 ms, reach timeout, substream 0 should have no resolution |
| 373 | // reported, but substream 1 should. |
| 374 | fake_clock_.AdvanceTimeMilliseconds(1); |
| 375 | stats = statistics_proxy_->GetStats(); |
| 376 | EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[0]].sent_width); |
| 377 | EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[0]].sent_height); |
| 378 | EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[1]].sent_width); |
| 379 | EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[1]].sent_height); |
| 380 | } |
| 381 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 382 | } // namespace webrtc |