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 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); | 378 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
378 | 379 |
379 statistics_proxy_->OnInactiveSsrc(config_.rtp.ssrcs[1]); | 380 statistics_proxy_->OnInactiveSsrc(config_.rtp.ssrcs[1]); |
380 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 381 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
381 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].width); | 382 EXPECT_EQ(kEncodedWidth, stats.substreams[config_.rtp.ssrcs[0]].width); |
382 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].height); | 383 EXPECT_EQ(kEncodedHeight, stats.substreams[config_.rtp.ssrcs[0]].height); |
383 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].width); | 384 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].width); |
384 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].height); | 385 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].height); |
385 } | 386 } |
386 | 387 |
| 388 TEST_F(SendStatisticsProxyTest, Qp) { |
| 389 const int kQpIdx0 = 21; |
| 390 const int kQpIdx1 = 39; |
| 391 EncodedImage encoded_image; |
| 392 |
| 393 RTPVideoHeader rtp_video_header; |
| 394 rtp_video_header.codec = kRtpVideoVp8; |
| 395 |
| 396 rtp_video_header.simulcastIdx = 0; |
| 397 encoded_image.qp_ = kQpIdx0; |
| 398 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 399 |
| 400 rtp_video_header.simulcastIdx = 1; |
| 401 encoded_image.qp_ = kQpIdx1; |
| 402 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 403 |
| 404 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
| 405 EXPECT_EQ(kQpIdx0, stats.substreams[config_.rtp.ssrcs[0]].qp); |
| 406 EXPECT_EQ(kQpIdx1, stats.substreams[config_.rtp.ssrcs[1]].qp); |
| 407 } |
| 408 |
| 409 TEST_F(SendStatisticsProxyTest, VerifyQpHistogramStats_Vp8) { |
| 410 test::ClearHistograms(); |
| 411 const int kMinRequiredSamples = 200; |
| 412 const int kQpIdx0 = 21; |
| 413 const int kQpIdx1 = 39; |
| 414 EncodedImage encoded_image; |
| 415 |
| 416 RTPVideoHeader rtp_video_header; |
| 417 rtp_video_header.codec = kRtpVideoVp8; |
| 418 |
| 419 for (int i = 0; i < kMinRequiredSamples; ++i) { |
| 420 rtp_video_header.simulcastIdx = 0; |
| 421 encoded_image.qp_ = kQpIdx0; |
| 422 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 423 rtp_video_header.simulcastIdx = 1; |
| 424 encoded_image.qp_ = kQpIdx1; |
| 425 statistics_proxy_->OnSendEncodedImage(encoded_image, &rtp_video_header); |
| 426 } |
| 427 statistics_proxy_.reset(); |
| 428 EXPECT_EQ(2, test::NumHistogramSamples("WebRTC.Video.Encoded.Vp8.Qp")); |
| 429 EXPECT_EQ(kQpIdx1, test::LastHistogramSample("WebRTC.Video.Encoded.Vp8.Qp")); |
| 430 } |
| 431 |
387 TEST_F(SendStatisticsProxyTest, ClearsBitratesFromInactiveSsrcs) { | 432 TEST_F(SendStatisticsProxyTest, ClearsBitratesFromInactiveSsrcs) { |
388 BitrateStatistics bitrate; | 433 BitrateStatistics bitrate; |
389 bitrate.bitrate_bps = 42; | 434 bitrate.bitrate_bps = 42; |
390 BitrateStatisticsObserver* observer = statistics_proxy_.get(); | 435 BitrateStatisticsObserver* observer = statistics_proxy_.get(); |
391 observer->Notify(bitrate, bitrate, config_.rtp.ssrcs[0]); | 436 observer->Notify(bitrate, bitrate, config_.rtp.ssrcs[0]); |
392 observer->Notify(bitrate, bitrate, config_.rtp.ssrcs[1]); | 437 observer->Notify(bitrate, bitrate, config_.rtp.ssrcs[1]); |
393 | 438 |
394 statistics_proxy_->OnInactiveSsrc(config_.rtp.ssrcs[1]); | 439 statistics_proxy_->OnInactiveSsrc(config_.rtp.ssrcs[1]); |
395 | 440 |
396 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); | 441 VideoSendStream::Stats stats = statistics_proxy_->GetStats(); |
397 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 442 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
398 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); | 443 stats.substreams[config_.rtp.ssrcs[0]].total_bitrate_bps); |
399 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), | 444 EXPECT_EQ(static_cast<int>(bitrate.bitrate_bps), |
400 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); | 445 stats.substreams[config_.rtp.ssrcs[0]].retransmit_bitrate_bps); |
401 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); | 446 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].total_bitrate_bps); |
402 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); | 447 EXPECT_EQ(0, stats.substreams[config_.rtp.ssrcs[1]].retransmit_bitrate_bps); |
403 } | 448 } |
404 | 449 |
405 } // namespace webrtc | 450 } // namespace webrtc |
OLD | NEW |