Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: webrtc/media/engine/webrtcmediaengine_unittest.cc

Issue 1984983002: Remove use of RtpHeaderExtension and clean up (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed nit Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #include "webrtc/media/engine/webrtcmediaengine.h" 13 #include "webrtc/media/engine/webrtcmediaengine.h"
14 14
15 using webrtc::RtpExtension;
16
15 namespace cricket { 17 namespace cricket {
16 namespace { 18 namespace {
17 19
18 std::vector<RtpHeaderExtension> MakeUniqueExtensions() { 20 std::vector<RtpExtension> MakeUniqueExtensions() {
19 std::vector<RtpHeaderExtension> result; 21 std::vector<RtpExtension> result;
20 char name[] = "a"; 22 char name[] = "a";
21 for (int i = 0; i < 7; ++i) { 23 for (int i = 0; i < 7; ++i) {
22 result.push_back(RtpHeaderExtension(name, 1 + i)); 24 result.push_back(RtpExtension(name, 1 + i));
23 name[0]++; 25 name[0]++;
24 result.push_back(RtpHeaderExtension(name, 14 - i)); 26 result.push_back(RtpExtension(name, 14 - i));
25 name[0]++; 27 name[0]++;
26 } 28 }
27 return result; 29 return result;
28 } 30 }
29 31
30 std::vector<RtpHeaderExtension> MakeRedundantExtensions() { 32 std::vector<RtpExtension> MakeRedundantExtensions() {
31 std::vector<RtpHeaderExtension> result; 33 std::vector<RtpExtension> result;
32 char name[] = "a"; 34 char name[] = "a";
33 for (int i = 0; i < 7; ++i) { 35 for (int i = 0; i < 7; ++i) {
34 result.push_back(RtpHeaderExtension(name, 1 + i)); 36 result.push_back(RtpExtension(name, 1 + i));
35 result.push_back(RtpHeaderExtension(name, 14 - i)); 37 result.push_back(RtpExtension(name, 14 - i));
36 name[0]++; 38 name[0]++;
37 } 39 }
38 return result; 40 return result;
39 } 41 }
40 42
41 bool SupportedExtensions1(const std::string& name) { 43 bool SupportedExtensions1(const std::string& name) {
42 return name == "c" || name == "i"; 44 return name == "c" || name == "i";
43 } 45 }
44 46
45 bool SupportedExtensions2(const std::string& name) { 47 bool SupportedExtensions2(const std::string& name) {
46 return name != "a" && name != "n"; 48 return name != "a" && name != "n";
47 } 49 }
48 50
49 bool IsSorted(const std::vector<webrtc::RtpExtension>& extensions) { 51 bool IsSorted(const std::vector<webrtc::RtpExtension>& extensions) {
50 const std::string* last = nullptr; 52 const std::string* last = nullptr;
51 for (const auto& extension : extensions) { 53 for (const auto& extension : extensions) {
52 if (last && *last > extension.name) { 54 if (last && *last > extension.uri) {
53 return false; 55 return false;
54 } 56 }
55 last = &extension.name; 57 last = &extension.uri;
56 } 58 }
57 return true; 59 return true;
58 } 60 }
59 } // namespace 61 } // namespace
60 62
61 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_EmptyList) { 63 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_EmptyList) {
62 std::vector<RtpHeaderExtension> extensions; 64 std::vector<RtpExtension> extensions;
63 EXPECT_TRUE(ValidateRtpExtensions(extensions)); 65 EXPECT_TRUE(ValidateRtpExtensions(extensions));
64 } 66 }
65 67
66 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_AllGood) { 68 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_AllGood) {
67 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 69 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
68 EXPECT_TRUE(ValidateRtpExtensions(extensions)); 70 EXPECT_TRUE(ValidateRtpExtensions(extensions));
69 } 71 }
70 72
71 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_Low) { 73 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_Low) {
72 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 74 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
73 extensions.push_back(RtpHeaderExtension("foo", 0)); 75 extensions.push_back(RtpExtension("foo", 0));
74 EXPECT_FALSE(ValidateRtpExtensions(extensions)); 76 EXPECT_FALSE(ValidateRtpExtensions(extensions));
75 } 77 }
76 78
77 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_High) { 79 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OutOfRangeId_High) {
78 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 80 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
79 extensions.push_back(RtpHeaderExtension("foo", 15)); 81 extensions.push_back(RtpExtension("foo", 15));
80 EXPECT_FALSE(ValidateRtpExtensions(extensions)); 82 EXPECT_FALSE(ValidateRtpExtensions(extensions));
81 } 83 }
82 84
83 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_StartOfSet) { 85 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_StartOfSet) {
84 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 86 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
85 extensions.push_back(RtpHeaderExtension("foo", 1)); 87 extensions.push_back(RtpExtension("foo", 1));
86 EXPECT_FALSE(ValidateRtpExtensions(extensions)); 88 EXPECT_FALSE(ValidateRtpExtensions(extensions));
87 } 89 }
88 90
89 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_EndOfSet) { 91 TEST(WebRtcMediaEngineTest, ValidateRtpExtensions_OverlappingIds_EndOfSet) {
90 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 92 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
91 extensions.push_back(RtpHeaderExtension("foo", 14)); 93 extensions.push_back(RtpExtension("foo", 14));
92 EXPECT_FALSE(ValidateRtpExtensions(extensions)); 94 EXPECT_FALSE(ValidateRtpExtensions(extensions));
93 } 95 }
94 96
95 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_EmptyList) { 97 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_EmptyList) {
96 std::vector<RtpHeaderExtension> extensions; 98 std::vector<RtpExtension> extensions;
97 std::vector<webrtc::RtpExtension> filtered = 99 std::vector<webrtc::RtpExtension> filtered =
98 FilterRtpExtensions(extensions, SupportedExtensions1, true); 100 FilterRtpExtensions(extensions, SupportedExtensions1, true);
99 EXPECT_EQ(0, filtered.size()); 101 EXPECT_EQ(0, filtered.size());
100 } 102 }
101 103
102 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_IncludeOnlySupported) { 104 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_IncludeOnlySupported) {
103 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 105 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
104 std::vector<webrtc::RtpExtension> filtered = 106 std::vector<webrtc::RtpExtension> filtered =
105 FilterRtpExtensions(extensions, SupportedExtensions1, false); 107 FilterRtpExtensions(extensions, SupportedExtensions1, false);
106 EXPECT_EQ(2, filtered.size()); 108 EXPECT_EQ(2, filtered.size());
107 EXPECT_EQ("c", filtered[0].name); 109 EXPECT_EQ("c", filtered[0].uri);
108 EXPECT_EQ("i", filtered[1].name); 110 EXPECT_EQ("i", filtered[1].uri);
109 } 111 }
110 112
111 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_1) { 113 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_1) {
112 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 114 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
113 std::vector<webrtc::RtpExtension> filtered = 115 std::vector<webrtc::RtpExtension> filtered =
114 FilterRtpExtensions(extensions, SupportedExtensions2, false); 116 FilterRtpExtensions(extensions, SupportedExtensions2, false);
115 EXPECT_EQ(12, filtered.size()); 117 EXPECT_EQ(12, filtered.size());
116 EXPECT_TRUE(IsSorted(filtered)); 118 EXPECT_TRUE(IsSorted(filtered));
117 } 119 }
118 120
119 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_2) { 121 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_SortedByName_2) {
120 std::vector<RtpHeaderExtension> extensions = MakeUniqueExtensions(); 122 std::vector<RtpExtension> extensions = MakeUniqueExtensions();
121 std::vector<webrtc::RtpExtension> filtered = 123 std::vector<webrtc::RtpExtension> filtered =
122 FilterRtpExtensions(extensions, SupportedExtensions2, true); 124 FilterRtpExtensions(extensions, SupportedExtensions2, true);
123 EXPECT_EQ(12, filtered.size()); 125 EXPECT_EQ(12, filtered.size());
124 EXPECT_TRUE(IsSorted(filtered)); 126 EXPECT_TRUE(IsSorted(filtered));
125 } 127 }
126 128
127 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_DontRemoveRedundant) { 129 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_DontRemoveRedundant) {
128 std::vector<RtpHeaderExtension> extensions = MakeRedundantExtensions(); 130 std::vector<RtpExtension> extensions = MakeRedundantExtensions();
129 std::vector<webrtc::RtpExtension> filtered = 131 std::vector<webrtc::RtpExtension> filtered =
130 FilterRtpExtensions(extensions, SupportedExtensions2, false); 132 FilterRtpExtensions(extensions, SupportedExtensions2, false);
131 EXPECT_EQ(12, filtered.size()); 133 EXPECT_EQ(12, filtered.size());
132 EXPECT_TRUE(IsSorted(filtered)); 134 EXPECT_TRUE(IsSorted(filtered));
133 EXPECT_EQ(filtered[0].name, filtered[1].name); 135 EXPECT_EQ(filtered[0].uri, filtered[1].uri);
134 } 136 }
135 137
136 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundant) { 138 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundant) {
137 std::vector<RtpHeaderExtension> extensions = MakeRedundantExtensions(); 139 std::vector<RtpExtension> extensions = MakeRedundantExtensions();
138 std::vector<webrtc::RtpExtension> filtered = 140 std::vector<webrtc::RtpExtension> filtered =
139 FilterRtpExtensions(extensions, SupportedExtensions2, true); 141 FilterRtpExtensions(extensions, SupportedExtensions2, true);
140 EXPECT_EQ(6, filtered.size()); 142 EXPECT_EQ(6, filtered.size());
141 EXPECT_TRUE(IsSorted(filtered)); 143 EXPECT_TRUE(IsSorted(filtered));
142 EXPECT_NE(filtered[0].name, filtered[1].name); 144 EXPECT_NE(filtered[0].uri, filtered[1].uri);
143 } 145 }
144 146
145 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_1) { 147 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_1) {
146 std::vector<RtpHeaderExtension> extensions; 148 std::vector<RtpExtension> extensions;
147 extensions.push_back( 149 extensions.push_back(
148 RtpHeaderExtension(kRtpTransportSequenceNumberHeaderExtension, 3)); 150 RtpExtension(RtpExtension::kTransportSequenceNumberUri, 3));
151 extensions.push_back(RtpExtension(RtpExtension::kTimestampOffsetUri, 9));
152 extensions.push_back(RtpExtension(RtpExtension::kAbsSendTimeUri, 6));
149 extensions.push_back( 153 extensions.push_back(
150 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 9)); 154 RtpExtension(RtpExtension::kTransportSequenceNumberUri, 1));
151 extensions.push_back( 155 extensions.push_back(RtpExtension(RtpExtension::kTimestampOffsetUri, 14));
152 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 6));
153 extensions.push_back(
154 RtpHeaderExtension(kRtpTransportSequenceNumberHeaderExtension, 1));
155 extensions.push_back(
156 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 14));
157 std::vector<webrtc::RtpExtension> filtered = 156 std::vector<webrtc::RtpExtension> filtered =
158 FilterRtpExtensions(extensions, SupportedExtensions2, true); 157 FilterRtpExtensions(extensions, SupportedExtensions2, true);
159 EXPECT_EQ(1, filtered.size()); 158 EXPECT_EQ(1, filtered.size());
160 EXPECT_EQ(kRtpTransportSequenceNumberHeaderExtension, filtered[0].name); 159 EXPECT_EQ(RtpExtension::kTransportSequenceNumberUri, filtered[0].uri);
161 } 160 }
162 161
163 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_2) { 162 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_2) {
164 std::vector<RtpHeaderExtension> extensions; 163 std::vector<RtpExtension> extensions;
165 extensions.push_back( 164 extensions.push_back(RtpExtension(RtpExtension::kTimestampOffsetUri, 1));
166 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 1)); 165 extensions.push_back(RtpExtension(RtpExtension::kAbsSendTimeUri, 14));
167 extensions.push_back( 166 extensions.push_back(RtpExtension(RtpExtension::kTimestampOffsetUri, 7));
168 RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, 14));
169 extensions.push_back(
170 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 7));
171 std::vector<webrtc::RtpExtension> filtered = 167 std::vector<webrtc::RtpExtension> filtered =
172 FilterRtpExtensions(extensions, SupportedExtensions2, true); 168 FilterRtpExtensions(extensions, SupportedExtensions2, true);
173 EXPECT_EQ(1, filtered.size()); 169 EXPECT_EQ(1, filtered.size());
174 EXPECT_EQ(kRtpAbsoluteSenderTimeHeaderExtension, filtered[0].name); 170 EXPECT_EQ(RtpExtension::kAbsSendTimeUri, filtered[0].uri);
175 } 171 }
176 172
177 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_3) { 173 TEST(WebRtcMediaEngineTest, FilterRtpExtensions_RemoveRedundantBwe_3) {
178 std::vector<RtpHeaderExtension> extensions; 174 std::vector<RtpExtension> extensions;
179 extensions.push_back( 175 extensions.push_back(RtpExtension(RtpExtension::kTimestampOffsetUri, 2));
180 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 2)); 176 extensions.push_back(RtpExtension(RtpExtension::kTimestampOffsetUri, 14));
181 extensions.push_back(
182 RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, 14));
183 std::vector<webrtc::RtpExtension> filtered = 177 std::vector<webrtc::RtpExtension> filtered =
184 FilterRtpExtensions(extensions, SupportedExtensions2, true); 178 FilterRtpExtensions(extensions, SupportedExtensions2, true);
185 EXPECT_EQ(1, filtered.size()); 179 EXPECT_EQ(1, filtered.size());
186 EXPECT_EQ(kRtpTimestampOffsetHeaderExtension, filtered[0].name); 180 EXPECT_EQ(RtpExtension::kTimestampOffsetUri, filtered[0].uri);
187 } 181 }
188 } // namespace cricket 182 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698