OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 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/protection_bitrate_calculator.h" | |
13 #include "webrtc/system_wrappers/include/clock.h" | |
14 | |
15 namespace webrtc { | |
16 | |
17 static const int kCodecBitrateBps = 100000; | |
18 | |
19 class ProtectionBitrateCalculatorTest : public ::testing::Test { | |
20 protected: | |
21 enum { | |
22 kSampleRate = 90000 // RTP timestamps per second. | |
23 }; | |
24 | |
25 class ProtectionCallback : public VCMProtectionCallback { | |
26 int ProtectionRequest(const FecProtectionParams* delta_params, | |
27 const FecProtectionParams* key_params, | |
28 uint32_t* sent_video_rate_bps, | |
29 uint32_t* sent_nack_rate_bps, | |
30 uint32_t* sent_fec_rate_bps) override { | |
31 *sent_video_rate_bps = kCodecBitrateBps; | |
32 *sent_nack_rate_bps = 0; | |
stefan-webrtc
2016/05/19 12:52:40
Should this always be zero? Maybe we should have a
perkj_webrtc
2016/06/01 20:55:23
Done.
| |
33 *sent_fec_rate_bps = fec_rate_bps_; | |
34 return 0; | |
35 } | |
36 | |
37 public: | |
38 uint32_t fec_rate_bps_; | |
39 }; | |
40 | |
41 // Note: simulated clock starts at 1 seconds, since parts of webrtc use 0 as | |
42 // a special case (e.g. frame rate in media optimization). | |
43 ProtectionBitrateCalculatorTest() | |
44 : clock_(1000), media_opt_(&clock_, &protection_callback_) {} | |
45 | |
46 SimulatedClock clock_; | |
47 ProtectionCallback protection_callback_; | |
48 ProtectionBitrateCalculator media_opt_; | |
49 }; | |
50 | |
51 TEST_F(ProtectionBitrateCalculatorTest, ProtectsUsingFecBitrate) { | |
52 static const uint32_t kMaxBitrateBps = 130000; | |
53 | |
54 media_opt_.SetProtectionMethod(true /*enable_fec*/, false); | |
55 media_opt_.SetEncodingData(kCodecBitrateBps, 640, 480, 30, 1, 1000); | |
56 | |
57 // Using 10% of codec bitrate for FEC. | |
58 protection_callback_.fec_rate_bps_ = kCodecBitrateBps / 10; | |
59 uint32_t target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 0, 0); | |
60 | |
61 EXPECT_GT(target_bitrate, 0u); | |
62 EXPECT_GT(kMaxBitrateBps, target_bitrate); | |
63 | |
64 // Using as much for codec bitrate as fec rate, new target rate should share | |
65 // both equally, but only be half of max (since that ceiling should be hit). | |
66 protection_callback_.fec_rate_bps_ = kCodecBitrateBps; | |
67 target_bitrate = media_opt_.SetTargetRates(kMaxBitrateBps, 128, 100); | |
68 EXPECT_EQ(kMaxBitrateBps / 2, target_bitrate); | |
69 } | |
70 | |
71 } // namespace webrtc | |
OLD | NEW |