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

Side by Side Diff: webrtc/media/base/codec_unittest.cc

Issue 2408153002: Remove cricket::VideoCodec with, height and framerate properties (Closed)
Patch Set: Rebased Created 4 years, 2 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
« no previous file with comments | « webrtc/media/base/codec.cc ('k') | webrtc/media/base/fakemediaengine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2009 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2009 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
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 EXPECT_TRUE(c2.Matches(AudioCodec(97, "A", 16000, -1, 1))); 124 EXPECT_TRUE(c2.Matches(AudioCodec(97, "A", 16000, -1, 1)));
125 125
126 // Stereo doesn't match channels = 0. 126 // Stereo doesn't match channels = 0.
127 AudioCodec c3(96, "A", 44100, 20000, 2); 127 AudioCodec c3(96, "A", 44100, 20000, 2);
128 EXPECT_TRUE(c3.Matches(AudioCodec(96, "A", 44100, 20000, 2))); 128 EXPECT_TRUE(c3.Matches(AudioCodec(96, "A", 44100, 20000, 2)));
129 EXPECT_FALSE(c3.Matches(AudioCodec(96, "A", 44100, 20000, 1))); 129 EXPECT_FALSE(c3.Matches(AudioCodec(96, "A", 44100, 20000, 1)));
130 EXPECT_FALSE(c3.Matches(AudioCodec(96, "A", 44100, 20000, 0))); 130 EXPECT_FALSE(c3.Matches(AudioCodec(96, "A", 44100, 20000, 0)));
131 } 131 }
132 132
133 TEST(CodecTest, TestVideoCodecOperators) { 133 TEST(CodecTest, TestVideoCodecOperators) {
134 VideoCodec c0(96, "V", 320, 200, 30); 134 VideoCodec c0(96, "V");
135 VideoCodec c1(95, "V", 320, 200, 30); 135 VideoCodec c1(95, "V");
136 VideoCodec c2(96, "x", 320, 200, 30); 136 VideoCodec c2(96, "x");
137 VideoCodec c3(96, "V", 120, 200, 30); 137
138 VideoCodec c4(96, "V", 320, 100, 30);
139 VideoCodec c5(96, "V", 320, 200, 10);
140 EXPECT_TRUE(c0 != c1); 138 EXPECT_TRUE(c0 != c1);
141 EXPECT_TRUE(c0 != c2); 139 EXPECT_TRUE(c0 != c2);
142 EXPECT_TRUE(c0 != c3);
143 EXPECT_TRUE(c0 != c4);
144 EXPECT_TRUE(c0 != c5);
145 140
146 VideoCodec c7; 141 VideoCodec c7;
147 VideoCodec c8(0, "", 0, 0, 0); 142 VideoCodec c8(0, "");
148 VideoCodec c9 = c0; 143 VideoCodec c9 = c0;
149 EXPECT_TRUE(c8 == c7); 144 EXPECT_TRUE(c8 == c7);
150 EXPECT_TRUE(c9 != c7); 145 EXPECT_TRUE(c9 != c7);
151 EXPECT_TRUE(c9 == c0); 146 EXPECT_TRUE(c9 == c0);
152 147
153 VideoCodec c10(c0); 148 VideoCodec c10(c0);
154 VideoCodec c11(c0); 149 VideoCodec c11(c0);
155 VideoCodec c12(c0); 150 VideoCodec c12(c0);
156 VideoCodec c13(c0); 151 VideoCodec c13(c0);
157 c10.params["x"] = "abc"; 152 c10.params["x"] = "abc";
158 c11.params["x"] = "def"; 153 c11.params["x"] = "def";
159 c12.params["y"] = "abc"; 154 c12.params["y"] = "abc";
160 c13.params["x"] = "abc"; 155 c13.params["x"] = "abc";
161 EXPECT_TRUE(c10 != c0); 156 EXPECT_TRUE(c10 != c0);
162 EXPECT_TRUE(c11 != c0); 157 EXPECT_TRUE(c11 != c0);
163 EXPECT_TRUE(c11 != c10); 158 EXPECT_TRUE(c11 != c10);
164 EXPECT_TRUE(c12 != c0); 159 EXPECT_TRUE(c12 != c0);
165 EXPECT_TRUE(c12 != c10); 160 EXPECT_TRUE(c12 != c10);
166 EXPECT_TRUE(c12 != c11); 161 EXPECT_TRUE(c12 != c11);
167 EXPECT_TRUE(c13 == c10); 162 EXPECT_TRUE(c13 == c10);
168 } 163 }
169 164
170 TEST(CodecTest, TestVideoCodecMatches) { 165 TEST(CodecTest, TestVideoCodecMatches) {
171 // Test a codec with a static payload type. 166 // Test a codec with a static payload type.
172 VideoCodec c0(95, "V", 320, 200, 30); 167 VideoCodec c0(95, "V");
173 EXPECT_TRUE(c0.Matches(VideoCodec(95, "", 640, 400, 15))); 168 EXPECT_TRUE(c0.Matches(VideoCodec(95, "")));
174 EXPECT_FALSE(c0.Matches(VideoCodec(96, "", 320, 200, 30))); 169 EXPECT_FALSE(c0.Matches(VideoCodec(96, "")));
175 170
176 // Test a codec with a dynamic payload type. 171 // Test a codec with a dynamic payload type.
177 VideoCodec c1(96, "V", 320, 200, 30); 172 VideoCodec c1(96, "V");
178 EXPECT_TRUE(c1.Matches(VideoCodec(96, "V", 640, 400, 15))); 173 EXPECT_TRUE(c1.Matches(VideoCodec(96, "V")));
179 EXPECT_TRUE(c1.Matches(VideoCodec(97, "V", 640, 400, 15))); 174 EXPECT_TRUE(c1.Matches(VideoCodec(97, "V")));
180 EXPECT_TRUE(c1.Matches(VideoCodec(96, "v", 640, 400, 15))); 175 EXPECT_TRUE(c1.Matches(VideoCodec(96, "v")));
181 EXPECT_TRUE(c1.Matches(VideoCodec(97, "v", 640, 400, 15))); 176 EXPECT_TRUE(c1.Matches(VideoCodec(97, "v")));
182 EXPECT_FALSE(c1.Matches(VideoCodec(96, "", 320, 200, 30))); 177 EXPECT_FALSE(c1.Matches(VideoCodec(96, "")));
183 EXPECT_FALSE(c1.Matches(VideoCodec(95, "V", 640, 400, 15))); 178 EXPECT_FALSE(c1.Matches(VideoCodec(95, "V")));
184 } 179 }
185 180
186 TEST(CodecTest, TestVideoCodecMatchesH264Baseline) { 181 TEST(CodecTest, TestVideoCodecMatchesH264Baseline) {
187 const VideoCodec no_params(96, cricket::kH264CodecName, 640, 480, 30); 182 const VideoCodec no_params(96, cricket::kH264CodecName);
188 183
189 VideoCodec baseline(96, cricket::kH264CodecName, 640, 480, 30); 184 VideoCodec baseline(96, cricket::kH264CodecName);
190 baseline.SetParam(cricket::kH264FmtpProfileLevelId, 185 baseline.SetParam(cricket::kH264FmtpProfileLevelId,
191 cricket::kH264FmtpDefaultProfileLevelId); 186 cricket::kH264FmtpDefaultProfileLevelId);
192 187
193 EXPECT_TRUE(baseline.Matches(baseline)); 188 EXPECT_TRUE(baseline.Matches(baseline));
194 EXPECT_TRUE(baseline.Matches(no_params)); 189 EXPECT_TRUE(baseline.Matches(no_params));
195 EXPECT_TRUE(no_params.Matches(baseline)); 190 EXPECT_TRUE(no_params.Matches(baseline));
196 EXPECT_TRUE(no_params.Matches(no_params)); 191 EXPECT_TRUE(no_params.Matches(no_params));
197 } 192 }
198 193
199 TEST(CodecTest, TestVideoCodecMatchesH264Profiles) { 194 TEST(CodecTest, TestVideoCodecMatchesH264Profiles) {
200 VideoCodec baseline(96, cricket::kH264CodecName, 640, 480, 30); 195 VideoCodec baseline(96, cricket::kH264CodecName);
201 baseline.SetParam(cricket::kH264FmtpProfileLevelId, 196 baseline.SetParam(cricket::kH264FmtpProfileLevelId,
202 cricket::kH264FmtpDefaultProfileLevelId); 197 cricket::kH264FmtpDefaultProfileLevelId);
203 baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); 198 baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1");
204 199
205 VideoCodec constrained_baseline(96, cricket::kH264CodecName, 640, 480, 30); 200 VideoCodec constrained_baseline(96, cricket::kH264CodecName);
206 constrained_baseline.SetParam(cricket::kH264FmtpProfileLevelId, 201 constrained_baseline.SetParam(cricket::kH264FmtpProfileLevelId,
207 cricket::kH264ProfileLevelConstrainedBaseline); 202 cricket::kH264ProfileLevelConstrainedBaseline);
208 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1"); 203 constrained_baseline.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, "1");
209 204
210 EXPECT_TRUE(baseline.Matches(baseline)); 205 EXPECT_TRUE(baseline.Matches(baseline));
211 EXPECT_FALSE(baseline.Matches(constrained_baseline)); 206 EXPECT_FALSE(baseline.Matches(constrained_baseline));
212 EXPECT_FALSE(constrained_baseline.Matches(baseline)); 207 EXPECT_FALSE(constrained_baseline.Matches(baseline));
213 EXPECT_TRUE(constrained_baseline.Matches(constrained_baseline)); 208 EXPECT_TRUE(constrained_baseline.Matches(constrained_baseline));
214 } 209 }
215 210
216 TEST(CodecTest, TestVideoCodecMatchesH264LevelAsymmetry) { 211 TEST(CodecTest, TestVideoCodecMatchesH264LevelAsymmetry) {
217 // Constrained Baseline Profile Level 1.0. 212 // Constrained Baseline Profile Level 1.0.
218 VideoCodec cbp_1_0(96, cricket::kH264CodecName, 640, 480, 30); 213 VideoCodec cbp_1_0(96, cricket::kH264CodecName);
219 cbp_1_0.SetParam(cricket::kH264FmtpProfileLevelId, 214 cbp_1_0.SetParam(cricket::kH264FmtpProfileLevelId,
220 "42e00a"); 215 "42e00a");
221 216
222 VideoCodec cbp_1_0_asymmetry_allowed = cbp_1_0; 217 VideoCodec cbp_1_0_asymmetry_allowed = cbp_1_0;
223 cbp_1_0_asymmetry_allowed.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, 218 cbp_1_0_asymmetry_allowed.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed,
224 "1"); 219 "1");
225 220
226 // Constrained Baseline Profile Level 3.1. 221 // Constrained Baseline Profile Level 3.1.
227 VideoCodec cbp_3_1(96, cricket::kH264CodecName, 640, 480, 30); 222 VideoCodec cbp_3_1(96, cricket::kH264CodecName);
228 cbp_3_1.SetParam(cricket::kH264FmtpProfileLevelId, "42e01f"); 223 cbp_3_1.SetParam(cricket::kH264FmtpProfileLevelId, "42e01f");
229 224
230 VideoCodec cbp_3_1_asymmetry_allowed = cbp_3_1; 225 VideoCodec cbp_3_1_asymmetry_allowed = cbp_3_1;
231 cbp_3_1_asymmetry_allowed.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed, 226 cbp_3_1_asymmetry_allowed.SetParam(cricket::kH264FmtpLevelAsymmetryAllowed,
232 "1"); 227 "1");
233 228
234 // It's ok to differ in level-asymmetry-allowed param as long as the level is 229 // It's ok to differ in level-asymmetry-allowed param as long as the level is
235 // the same. 230 // the same.
236 EXPECT_TRUE(cbp_1_0.Matches(cbp_1_0_asymmetry_allowed)); 231 EXPECT_TRUE(cbp_1_0.Matches(cbp_1_0_asymmetry_allowed));
237 EXPECT_TRUE(cbp_3_1.Matches(cbp_3_1_asymmetry_allowed)); 232 EXPECT_TRUE(cbp_3_1.Matches(cbp_3_1_asymmetry_allowed));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 c2.AddFeedbackParam(b3); 294 c2.AddFeedbackParam(b3);
300 295
301 c1.IntersectFeedbackParams(c2); 296 c1.IntersectFeedbackParams(c2);
302 EXPECT_TRUE(c1.HasFeedbackParam(a1)); 297 EXPECT_TRUE(c1.HasFeedbackParam(a1));
303 EXPECT_FALSE(c1.HasFeedbackParam(b2)); 298 EXPECT_FALSE(c1.HasFeedbackParam(b2));
304 EXPECT_FALSE(c1.HasFeedbackParam(c3)); 299 EXPECT_FALSE(c1.HasFeedbackParam(c3));
305 } 300 }
306 301
307 TEST(CodecTest, TestGetCodecType) { 302 TEST(CodecTest, TestGetCodecType) {
308 // Codec type comparison should be case insenstive on names. 303 // Codec type comparison should be case insenstive on names.
309 const VideoCodec codec(96, "V", 320, 200, 30); 304 const VideoCodec codec(96, "V");
310 const VideoCodec rtx_codec(96, "rTx", 320, 200, 30); 305 const VideoCodec rtx_codec(96, "rTx");
311 const VideoCodec ulpfec_codec(96, "ulpFeC", 320, 200, 30); 306 const VideoCodec ulpfec_codec(96, "ulpFeC");
312 const VideoCodec red_codec(96, "ReD", 320, 200, 30); 307 const VideoCodec red_codec(96, "ReD");
313 EXPECT_EQ(VideoCodec::CODEC_VIDEO, codec.GetCodecType()); 308 EXPECT_EQ(VideoCodec::CODEC_VIDEO, codec.GetCodecType());
314 EXPECT_EQ(VideoCodec::CODEC_RTX, rtx_codec.GetCodecType()); 309 EXPECT_EQ(VideoCodec::CODEC_RTX, rtx_codec.GetCodecType());
315 EXPECT_EQ(VideoCodec::CODEC_ULPFEC, ulpfec_codec.GetCodecType()); 310 EXPECT_EQ(VideoCodec::CODEC_ULPFEC, ulpfec_codec.GetCodecType());
316 EXPECT_EQ(VideoCodec::CODEC_RED, red_codec.GetCodecType()); 311 EXPECT_EQ(VideoCodec::CODEC_RED, red_codec.GetCodecType());
317 } 312 }
318 313
319 TEST(CodecTest, TestCreateRtxCodec) { 314 TEST(CodecTest, TestCreateRtxCodec) {
320 VideoCodec rtx_codec = VideoCodec::CreateRtxCodec(96, 120); 315 VideoCodec rtx_codec = VideoCodec::CreateRtxCodec(96, 120);
321 EXPECT_EQ(96, rtx_codec.id); 316 EXPECT_EQ(96, rtx_codec.id);
322 EXPECT_EQ(VideoCodec::CODEC_RTX, rtx_codec.GetCodecType()); 317 EXPECT_EQ(VideoCodec::CODEC_RTX, rtx_codec.GetCodecType());
323 int associated_payload_type; 318 int associated_payload_type;
324 ASSERT_TRUE(rtx_codec.GetParam(kCodecParamAssociatedPayloadType, 319 ASSERT_TRUE(rtx_codec.GetParam(kCodecParamAssociatedPayloadType,
325 &associated_payload_type)); 320 &associated_payload_type));
326 EXPECT_EQ(120, associated_payload_type); 321 EXPECT_EQ(120, associated_payload_type);
327 } 322 }
328 323
329 TEST(CodecTest, TestValidateCodecFormat) { 324 TEST(CodecTest, TestValidateCodecFormat) {
330 const VideoCodec codec(96, "V", 320, 200, 30); 325 const VideoCodec codec(96, "V");
331 ASSERT_TRUE(codec.ValidateCodecFormat()); 326 ASSERT_TRUE(codec.ValidateCodecFormat());
332 327
333 // Accept 0-127 as payload types. 328 // Accept 0-127 as payload types.
334 VideoCodec low_payload_type = codec; 329 VideoCodec low_payload_type = codec;
335 low_payload_type.id = 0; 330 low_payload_type.id = 0;
336 VideoCodec high_payload_type = codec; 331 VideoCodec high_payload_type = codec;
337 high_payload_type.id = 127; 332 high_payload_type.id = 127;
338 ASSERT_TRUE(low_payload_type.ValidateCodecFormat()); 333 ASSERT_TRUE(low_payload_type.ValidateCodecFormat());
339 EXPECT_TRUE(high_payload_type.ValidateCodecFormat()); 334 EXPECT_TRUE(high_payload_type.ValidateCodecFormat());
340 335
341 // Reject negative payloads. 336 // Reject negative payloads.
342 VideoCodec negative_payload_type = codec; 337 VideoCodec negative_payload_type = codec;
343 negative_payload_type.id = -1; 338 negative_payload_type.id = -1;
344 EXPECT_FALSE(negative_payload_type.ValidateCodecFormat()); 339 EXPECT_FALSE(negative_payload_type.ValidateCodecFormat());
345 340
346 // Reject too-high payloads. 341 // Reject too-high payloads.
347 VideoCodec too_high_payload_type = codec; 342 VideoCodec too_high_payload_type = codec;
348 too_high_payload_type.id = 128; 343 too_high_payload_type.id = 128;
349 EXPECT_FALSE(too_high_payload_type.ValidateCodecFormat()); 344 EXPECT_FALSE(too_high_payload_type.ValidateCodecFormat());
350 345
351 // Accept non-video codecs with zero dimensions.
352 VideoCodec zero_width_rtx_codec = VideoCodec::CreateRtxCodec(96, 120);
353 zero_width_rtx_codec.width = 0;
354 EXPECT_TRUE(zero_width_rtx_codec.ValidateCodecFormat());
355
356 // Reject codecs with min bitrate > max bitrate. 346 // Reject codecs with min bitrate > max bitrate.
357 VideoCodec incorrect_bitrates = codec; 347 VideoCodec incorrect_bitrates = codec;
358 incorrect_bitrates.params[kCodecParamMinBitrate] = "100"; 348 incorrect_bitrates.params[kCodecParamMinBitrate] = "100";
359 incorrect_bitrates.params[kCodecParamMaxBitrate] = "80"; 349 incorrect_bitrates.params[kCodecParamMaxBitrate] = "80";
360 EXPECT_FALSE(incorrect_bitrates.ValidateCodecFormat()); 350 EXPECT_FALSE(incorrect_bitrates.ValidateCodecFormat());
361 351
362 // Accept min bitrate == max bitrate. 352 // Accept min bitrate == max bitrate.
363 VideoCodec equal_bitrates = codec; 353 VideoCodec equal_bitrates = codec;
364 equal_bitrates.params[kCodecParamMinBitrate] = "100"; 354 equal_bitrates.params[kCodecParamMinBitrate] = "100";
365 equal_bitrates.params[kCodecParamMaxBitrate] = "100"; 355 equal_bitrates.params[kCodecParamMaxBitrate] = "100";
366 EXPECT_TRUE(equal_bitrates.ValidateCodecFormat()); 356 EXPECT_TRUE(equal_bitrates.ValidateCodecFormat());
367 357
368 // Accept min bitrate < max bitrate. 358 // Accept min bitrate < max bitrate.
369 VideoCodec different_bitrates = codec; 359 VideoCodec different_bitrates = codec;
370 different_bitrates.params[kCodecParamMinBitrate] = "99"; 360 different_bitrates.params[kCodecParamMinBitrate] = "99";
371 different_bitrates.params[kCodecParamMaxBitrate] = "100"; 361 different_bitrates.params[kCodecParamMaxBitrate] = "100";
372 EXPECT_TRUE(different_bitrates.ValidateCodecFormat()); 362 EXPECT_TRUE(different_bitrates.ValidateCodecFormat());
373 } 363 }
374 364
375 TEST(CodecTest, TestToCodecParameters) { 365 TEST(CodecTest, TestToCodecParameters) {
376 const VideoCodec v(96, "V", 320, 200, 30); 366 const VideoCodec v(96, "V");
377 webrtc::RtpCodecParameters codec_params_1 = v.ToCodecParameters(); 367 webrtc::RtpCodecParameters codec_params_1 = v.ToCodecParameters();
378 EXPECT_EQ(96, codec_params_1.payload_type); 368 EXPECT_EQ(96, codec_params_1.payload_type);
379 EXPECT_EQ("V", codec_params_1.mime_type); 369 EXPECT_EQ("V", codec_params_1.mime_type);
380 EXPECT_EQ(cricket::kVideoCodecClockrate, codec_params_1.clock_rate); 370 EXPECT_EQ(cricket::kVideoCodecClockrate, codec_params_1.clock_rate);
381 EXPECT_EQ(1, codec_params_1.channels); 371 EXPECT_EQ(1, codec_params_1.channels);
382 372
383 const AudioCodec a(97, "A", 44100, 20000, 2); 373 const AudioCodec a(97, "A", 44100, 20000, 2);
384 webrtc::RtpCodecParameters codec_params_2 = a.ToCodecParameters(); 374 webrtc::RtpCodecParameters codec_params_2 = a.ToCodecParameters();
385 EXPECT_EQ(97, codec_params_2.payload_type); 375 EXPECT_EQ(97, codec_params_2.payload_type);
386 EXPECT_EQ("A", codec_params_2.mime_type); 376 EXPECT_EQ("A", codec_params_2.mime_type);
387 EXPECT_EQ(44100, codec_params_2.clock_rate); 377 EXPECT_EQ(44100, codec_params_2.clock_rate);
388 EXPECT_EQ(2, codec_params_2.channels); 378 EXPECT_EQ(2, codec_params_2.channels);
389 } 379 }
OLDNEW
« no previous file with comments | « webrtc/media/base/codec.cc ('k') | webrtc/media/base/fakemediaengine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698