OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 #include <stdlib.h> // NULL | 11 #include <stdlib.h> // nullptr |
12 | 12 |
13 #include "webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.h" | 13 #include "webrtc/modules/rtp_rtcp/source/vp8_partition_aggregator.h" |
14 #include "webrtc/test/gtest.h" | 14 #include "webrtc/test/gtest.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 TEST(PartitionTreeNode, CreateAndDelete) { | 18 TEST(PartitionTreeNode, CreateAndDelete) { |
19 const size_t kVector[] = {1, 2, 3}; | 19 const size_t kVector[] = {1, 2, 3}; |
20 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); | 20 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); |
21 PartitionTreeNode* node1 = | 21 PartitionTreeNode* node1 = |
22 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); | 22 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); |
23 PartitionTreeNode* node2 = | 23 PartitionTreeNode* node2 = |
24 new PartitionTreeNode(node1, kVector, kNumPartitions, 17); | 24 new PartitionTreeNode(node1, kVector, kNumPartitions, 17); |
25 delete node1; | 25 delete node1; |
26 delete node2; | 26 delete node2; |
27 } | 27 } |
28 | 28 |
29 TEST(PartitionTreeNode, CreateChildrenAndDelete) { | 29 TEST(PartitionTreeNode, CreateChildrenAndDelete) { |
30 const size_t kVector[] = {1, 2, 3}; | 30 const size_t kVector[] = {1, 2, 3}; |
31 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); | 31 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); |
32 const size_t kMaxSize = 10; | 32 const size_t kMaxSize = 10; |
33 const size_t kPenalty = 5; | 33 const size_t kPenalty = 5; |
34 PartitionTreeNode* root = | 34 PartitionTreeNode* root = |
35 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); | 35 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); |
36 EXPECT_TRUE(root->CreateChildren(kMaxSize)); | 36 EXPECT_TRUE(root->CreateChildren(kMaxSize)); |
37 ASSERT_TRUE(NULL != root->left_child()); | 37 ASSERT_TRUE(nullptr != root->left_child()); |
38 ASSERT_TRUE(NULL != root->right_child()); | 38 ASSERT_TRUE(nullptr != root->right_child()); |
39 EXPECT_EQ(3u, root->left_child()->this_size()); | 39 EXPECT_EQ(3u, root->left_child()->this_size()); |
40 EXPECT_EQ(2u, root->right_child()->this_size()); | 40 EXPECT_EQ(2u, root->right_child()->this_size()); |
41 EXPECT_EQ(11, root->right_child()->Cost(kPenalty)); | 41 EXPECT_EQ(11, root->right_child()->Cost(kPenalty)); |
42 EXPECT_FALSE(root->left_child()->packet_start()); | 42 EXPECT_FALSE(root->left_child()->packet_start()); |
43 EXPECT_TRUE(root->right_child()->packet_start()); | 43 EXPECT_TRUE(root->right_child()->packet_start()); |
44 delete root; | 44 delete root; |
45 } | 45 } |
46 | 46 |
47 TEST(PartitionTreeNode, FindOptimalConfig) { | 47 TEST(PartitionTreeNode, FindOptimalConfig) { |
48 const size_t kVector[] = {197, 194, 213, 215, 184, 199, 197, 207}; | 48 const size_t kVector[] = {197, 194, 213, 215, 184, 199, 197, 207}; |
49 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); | 49 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); |
50 const size_t kMaxSize = 1500; | 50 const size_t kMaxSize = 1500; |
51 const size_t kPenalty = 1; | 51 const size_t kPenalty = 1; |
52 PartitionTreeNode* root = | 52 PartitionTreeNode* root = |
53 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); | 53 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); |
54 root->set_max_parent_size(500); | 54 root->set_max_parent_size(500); |
55 root->set_min_parent_size(300); | 55 root->set_min_parent_size(300); |
56 PartitionTreeNode* opt = root->GetOptimalNode(kMaxSize, kPenalty); | 56 PartitionTreeNode* opt = root->GetOptimalNode(kMaxSize, kPenalty); |
57 ASSERT_TRUE(opt != NULL); | 57 ASSERT_TRUE(opt != nullptr); |
58 EXPECT_EQ(4u, opt->NumPackets()); | 58 EXPECT_EQ(4u, opt->NumPackets()); |
59 // Expect optimal sequence to be {1, 0, 1, 0, 1, 0, 1, 0}, which corresponds | 59 // Expect optimal sequence to be {1, 0, 1, 0, 1, 0, 1, 0}, which corresponds |
60 // to (right)-left-right-left-right-left-right-left, where the root node is | 60 // to (right)-left-right-left-right-left-right-left, where the root node is |
61 // implicitly a "right" node by definition. | 61 // implicitly a "right" node by definition. |
62 EXPECT_TRUE(opt->parent()->parent()->parent()->parent()->parent()-> | 62 EXPECT_TRUE(opt->parent()->parent()->parent()->parent()->parent()-> |
63 parent()->parent()->packet_start()); | 63 parent()->parent()->packet_start()); |
64 EXPECT_FALSE(opt->parent()->parent()->parent()->parent()->parent()-> | 64 EXPECT_FALSE(opt->parent()->parent()->parent()->parent()->parent()-> |
65 parent()->packet_start()); | 65 parent()->packet_start()); |
66 EXPECT_TRUE(opt->parent()->parent()->parent()->parent()->parent()-> | 66 EXPECT_TRUE(opt->parent()->parent()->parent()->parent()->parent()-> |
67 packet_start()); | 67 packet_start()); |
68 EXPECT_FALSE(opt->parent()->parent()->parent()->parent()->packet_start()); | 68 EXPECT_FALSE(opt->parent()->parent()->parent()->parent()->packet_start()); |
69 EXPECT_TRUE(opt->parent()->parent()->parent()->packet_start()); | 69 EXPECT_TRUE(opt->parent()->parent()->parent()->packet_start()); |
70 EXPECT_FALSE(opt->parent()->parent()->packet_start()); | 70 EXPECT_FALSE(opt->parent()->parent()->packet_start()); |
71 EXPECT_TRUE(opt->parent()->packet_start()); | 71 EXPECT_TRUE(opt->parent()->packet_start()); |
72 EXPECT_FALSE(opt->packet_start()); | 72 EXPECT_FALSE(opt->packet_start()); |
73 EXPECT_TRUE(opt == root->left_child()->right_child()->left_child()-> | 73 EXPECT_TRUE(opt == root->left_child()->right_child()->left_child()-> |
74 right_child()->left_child()->right_child()->left_child()); | 74 right_child()->left_child()->right_child()->left_child()); |
75 delete root; | 75 delete root; |
76 } | 76 } |
77 | 77 |
78 TEST(PartitionTreeNode, FindOptimalConfigSinglePartition) { | 78 TEST(PartitionTreeNode, FindOptimalConfigSinglePartition) { |
79 const size_t kVector[] = {17}; | 79 const size_t kVector[] = {17}; |
80 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); | 80 const size_t kNumPartitions = GTEST_ARRAY_SIZE_(kVector); |
81 const size_t kMaxSize = 1500; | 81 const size_t kMaxSize = 1500; |
82 const size_t kPenalty = 1; | 82 const size_t kPenalty = 1; |
83 PartitionTreeNode* root = | 83 PartitionTreeNode* root = |
84 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); | 84 PartitionTreeNode::CreateRootNode(kVector, kNumPartitions); |
85 PartitionTreeNode* opt = root->GetOptimalNode(kMaxSize, kPenalty); | 85 PartitionTreeNode* opt = root->GetOptimalNode(kMaxSize, kPenalty); |
86 ASSERT_TRUE(opt != NULL); | 86 ASSERT_TRUE(opt != nullptr); |
87 EXPECT_EQ(1u, opt->NumPackets()); | 87 EXPECT_EQ(1u, opt->NumPackets()); |
88 EXPECT_TRUE(opt == root); | 88 EXPECT_TRUE(opt == root); |
89 delete root; | 89 delete root; |
90 } | 90 } |
91 | 91 |
92 static void VerifyConfiguration( | 92 static void VerifyConfiguration( |
93 const size_t* expected_config, | 93 const size_t* expected_config, |
94 size_t expected_config_len, | 94 size_t expected_config_len, |
95 const Vp8PartitionAggregator::ConfigVec& opt_config, | 95 const Vp8PartitionAggregator::ConfigVec& opt_config, |
96 const RTPFragmentationHeader& fragmentation) { | 96 const RTPFragmentationHeader& fragmentation) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 1600, kMTU, 1, 300, 900)); | 203 1600, kMTU, 1, 300, 900)); |
204 EXPECT_EQ(3u, | 204 EXPECT_EQ(3u, |
205 Vp8PartitionAggregator::CalcNumberOfFragments( | 205 Vp8PartitionAggregator::CalcNumberOfFragments( |
206 1600, kMTU, 1, 300, 798)); | 206 1600, kMTU, 1, 300, 798)); |
207 EXPECT_EQ(2u, | 207 EXPECT_EQ(2u, |
208 Vp8PartitionAggregator::CalcNumberOfFragments( | 208 Vp8PartitionAggregator::CalcNumberOfFragments( |
209 1600, kMTU, 1, 900, 1000)); | 209 1600, kMTU, 1, 900, 1000)); |
210 } | 210 } |
211 | 211 |
212 } // namespace webrtc | 212 } // namespace webrtc |
OLD | NEW |