OLD | NEW |
| (Empty) |
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 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "webrtc/modules/video_coding/media_optimization.h" | |
13 #include "webrtc/system_wrappers/include/clock.h" | |
14 | |
15 namespace webrtc { | |
16 namespace media_optimization { | |
17 | |
18 class TestMediaOptimization : public ::testing::Test { | |
19 protected: | |
20 enum { | |
21 kSampleRate = 90000 // RTP timestamps per second. | |
22 }; | |
23 | |
24 // Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as | |
25 // a special case (e.g. frame rate in media optimization). | |
26 TestMediaOptimization() | |
27 : clock_(1000), | |
28 media_opt_(&clock_), | |
29 frame_time_ms_(33), | |
30 next_timestamp_(0) {} | |
31 | |
32 // This method mimics what happens in VideoSender::AddVideoFrame. | |
33 void AddFrameAndAdvanceTime(uint32_t bitrate_bps, bool expect_frame_drop) { | |
34 bool frame_dropped = media_opt_.DropFrame(); | |
35 EXPECT_EQ(expect_frame_drop, frame_dropped); | |
36 if (!frame_dropped) { | |
37 size_t bytes_per_frame = bitrate_bps * frame_time_ms_ / (8 * 1000); | |
38 EncodedImage encoded_image; | |
39 encoded_image._length = bytes_per_frame; | |
40 encoded_image._timeStamp = next_timestamp_; | |
41 encoded_image._frameType = kVideoFrameKey; | |
42 ASSERT_EQ(VCM_OK, media_opt_.UpdateWithEncodedData(encoded_image)); | |
43 } | |
44 next_timestamp_ += frame_time_ms_ * kSampleRate / 1000; | |
45 clock_.AdvanceTimeMilliseconds(frame_time_ms_); | |
46 } | |
47 | |
48 SimulatedClock clock_; | |
49 MediaOptimization media_opt_; | |
50 int frame_time_ms_; | |
51 uint32_t next_timestamp_; | |
52 }; | |
53 | |
54 TEST_F(TestMediaOptimization, VerifyMuting) { | |
55 // Enable video suspension with these limits. | |
56 // Suspend the video when the rate is below 50 kbps and resume when it gets | |
57 // above 50 + 10 kbps again. | |
58 const uint32_t kThresholdBps = 50000; | |
59 const uint32_t kWindowBps = 10000; | |
60 media_opt_.SuspendBelowMinBitrate(kThresholdBps, kWindowBps); | |
61 | |
62 // The video should not be suspended from the start. | |
63 EXPECT_FALSE(media_opt_.IsVideoSuspended()); | |
64 | |
65 uint32_t target_bitrate_kbps = 100; | |
66 media_opt_.SetTargetRates(target_bitrate_kbps * 1000, | |
67 0, // Lossrate. | |
68 100); // RTT in ms. | |
69 media_opt_.EnableFrameDropper(true); | |
70 for (int time = 0; time < 2000; time += frame_time_ms_) { | |
71 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, false)); | |
72 } | |
73 | |
74 // Set the target rate below the limit for muting. | |
75 media_opt_.SetTargetRates(kThresholdBps - 1000, | |
76 0, // Lossrate. | |
77 100); // RTT in ms. | |
78 // Expect the muter to engage immediately and stay muted. | |
79 // Test during 2 seconds. | |
80 for (int time = 0; time < 2000; time += frame_time_ms_) { | |
81 EXPECT_TRUE(media_opt_.IsVideoSuspended()); | |
82 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true)); | |
83 } | |
84 | |
85 // Set the target above the limit for muting, but not above the | |
86 // limit + window. | |
87 media_opt_.SetTargetRates(kThresholdBps + 1000, | |
88 0, // Lossrate. | |
89 100); // RTT in ms. | |
90 // Expect the muter to stay muted. | |
91 // Test during 2 seconds. | |
92 for (int time = 0; time < 2000; time += frame_time_ms_) { | |
93 EXPECT_TRUE(media_opt_.IsVideoSuspended()); | |
94 ASSERT_NO_FATAL_FAILURE(AddFrameAndAdvanceTime(target_bitrate_kbps, true)); | |
95 } | |
96 | |
97 // Set the target above limit + window. | |
98 media_opt_.SetTargetRates(kThresholdBps + kWindowBps + 1000, | |
99 0, // Lossrate. | |
100 100); // RTT in ms. | |
101 // Expect the muter to disengage immediately. | |
102 // Test during 2 seconds. | |
103 for (int time = 0; time < 2000; time += frame_time_ms_) { | |
104 EXPECT_FALSE(media_opt_.IsVideoSuspended()); | |
105 ASSERT_NO_FATAL_FAILURE( | |
106 AddFrameAndAdvanceTime((kThresholdBps + kWindowBps) / 1000, false)); | |
107 } | |
108 } | |
109 | |
110 } // namespace media_optimization | |
111 } // namespace webrtc | |
OLD | NEW |