OLD | NEW |
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 // This file includes unit tests for SendStatisticsProxy. | 11 // This file includes unit tests for SendStatisticsProxy. |
12 #include "webrtc/video/send_statistics_proxy.h" | 12 #include "webrtc/video/send_statistics_proxy.h" |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webrtc/test/histogram.h" |
19 | 20 |
20 namespace webrtc { | 21 namespace webrtc { |
21 | 22 |
22 class SendStatisticsProxyTest : public ::testing::Test { | 23 class SendStatisticsProxyTest : public ::testing::Test { |
23 public: | 24 public: |
24 SendStatisticsProxyTest() | 25 SendStatisticsProxyTest() |
25 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), | 26 : fake_clock_(1234), config_(GetTestConfig()), avg_delay_ms_(0), |
26 max_delay_ms_(0) {} | 27 max_delay_ms_(0) {} |
27 virtual ~SendStatisticsProxyTest() {} | 28 virtual ~SendStatisticsProxyTest() {} |
28 | 29 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 290 } |
290 | 291 |
291 TEST_F(SendStatisticsProxyTest, OnEncodedFrame) { | 292 TEST_F(SendStatisticsProxyTest, OnEncodedFrame) { |
292 const int kEncodeTimeMs = 11; | 293 const int kEncodeTimeMs = 11; |
293 statistics_proxy_->OnEncodedFrame(kEncodeTimeMs); | 294 statistics_proxy_->OnEncodedFrame(kEncodeTimeMs); |
294 | 295 |
295 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 296 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
296 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); | 297 EXPECT_EQ(kEncodeTimeMs, stats.avg_encode_time_ms); |
297 } | 298 } |
298 | 299 |
| 300 TEST_F(SendStatisticsProxyTest, SwitchContentTypeUpdatesHistograms) { |
| 301 test::ClearHistograms(); |
| 302 const int kMinRequiredSamples = 200; |
| 303 const int kWidth = 640; |
| 304 const int kHeight = 480; |
| 305 |
| 306 for (int i = 0; i < kMinRequiredSamples; ++i) |
| 307 statistics_proxy_->OnIncomingFrame(kWidth, kHeight); |
| 308 |
| 309 // No switch, stats not should be updated. |
| 310 statistics_proxy_->SetContentType( |
| 311 VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 312 EXPECT_EQ(0, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels")); |
| 313 |
| 314 // Switch to screenshare, real-time stats should be updated. |
| 315 statistics_proxy_->SetContentType(VideoEncoderConfig::ContentType::kScreen); |
| 316 EXPECT_EQ(1, test::NumHistogramSamples("WebRTC.Video.InputWidthInPixels")); |
| 317 } |
| 318 |
299 TEST_F(SendStatisticsProxyTest, NoSubstreams) { | 319 TEST_F(SendStatisticsProxyTest, NoSubstreams) { |
300 uint32_t excluded_ssrc = | 320 uint32_t excluded_ssrc = |
301 std::max( | 321 std::max( |
302 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), | 322 *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), |
303 *std::max_element(config_.rtp.rtx.ssrcs.begin(), | 323 *std::max_element(config_.rtp.rtx.ssrcs.begin(), |
304 config_.rtp.rtx.ssrcs.end())) + | 324 config_.rtp.rtx.ssrcs.end())) + |
305 1; | 325 1; |
306 // From RtcpStatisticsCallback. | 326 // From RtcpStatisticsCallback. |
307 RtcpStatistics rtcp_stats; | 327 RtcpStatistics rtcp_stats; |
308 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); | 328 RtcpStatisticsCallback* rtcp_callback = statistics_proxy_.get(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 425 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
406 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 426 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
407 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); | 427 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); |
408 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 428 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
409 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); | 429 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); |
410 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); | 430 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); |
411 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); | 431 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); |
412 } | 432 } |
413 | 433 |
414 } // namespace webrtc | 434 } // namespace webrtc |
OLD | NEW |