OLD | NEW |
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 |
11 #include "webrtc/base/gunit.h" | 11 #include "webrtc/base/gunit.h" |
12 #include "webrtc/media/base/codec.h" | 12 #include "webrtc/media/base/codec.h" |
13 | 13 |
14 using cricket::AudioCodec; | 14 using cricket::AudioCodec; |
15 using cricket::Codec; | 15 using cricket::Codec; |
16 using cricket::DataCodec; | 16 using cricket::DataCodec; |
17 using cricket::FeedbackParam; | 17 using cricket::FeedbackParam; |
18 using cricket::VideoCodec; | 18 using cricket::VideoCodec; |
19 using cricket::kCodecParamAssociatedPayloadType; | 19 using cricket::kCodecParamAssociatedPayloadType; |
20 using cricket::kCodecParamMaxBitrate; | 20 using cricket::kCodecParamMaxBitrate; |
21 using cricket::kCodecParamMinBitrate; | 21 using cricket::kCodecParamMinBitrate; |
22 | 22 |
| 23 class TestCodec : public Codec { |
| 24 public: |
| 25 TestCodec(int id, const std::string name, int clockrate) |
| 26 : Codec(id, name, clockrate) {} |
| 27 TestCodec() : Codec() {} |
| 28 TestCodec(const TestCodec& c) : Codec(c) {} |
| 29 }; |
| 30 |
23 TEST(CodecTest, TestCodecOperators) { | 31 TEST(CodecTest, TestCodecOperators) { |
24 Codec c0(96, "D", 1000); | 32 TestCodec c0(96, "D", 1000); |
25 c0.SetParam("a", 1); | 33 c0.SetParam("a", 1); |
26 | 34 |
27 Codec c1 = c0; | 35 TestCodec c1 = c0; |
28 EXPECT_TRUE(c1 == c0); | 36 EXPECT_TRUE(c1 == c0); |
29 | 37 |
30 int param_value0; | 38 int param_value0; |
31 int param_value1; | 39 int param_value1; |
32 EXPECT_TRUE(c0.GetParam("a", ¶m_value0)); | 40 EXPECT_TRUE(c0.GetParam("a", ¶m_value0)); |
33 EXPECT_TRUE(c1.GetParam("a", ¶m_value1)); | 41 EXPECT_TRUE(c1.GetParam("a", ¶m_value1)); |
34 EXPECT_EQ(param_value0, param_value1); | 42 EXPECT_EQ(param_value0, param_value1); |
35 | 43 |
36 c1.id = 86; | 44 c1.id = 86; |
37 EXPECT_TRUE(c0 != c1); | 45 EXPECT_TRUE(c0 != c1); |
38 | 46 |
39 c1 = c0; | 47 c1 = c0; |
40 c1.name = "x"; | 48 c1.name = "x"; |
41 EXPECT_TRUE(c0 != c1); | 49 EXPECT_TRUE(c0 != c1); |
42 | 50 |
43 c1 = c0; | 51 c1 = c0; |
44 c1.clockrate = 2000; | 52 c1.clockrate = 2000; |
45 EXPECT_TRUE(c0 != c1); | 53 EXPECT_TRUE(c0 != c1); |
46 | 54 |
47 c1 = c0; | 55 c1 = c0; |
48 c1.SetParam("a", 2); | 56 c1.SetParam("a", 2); |
49 EXPECT_TRUE(c0 != c1); | 57 EXPECT_TRUE(c0 != c1); |
50 | 58 |
51 Codec c5; | 59 TestCodec c5; |
52 Codec c6(0, "", 0); | 60 TestCodec c6(0, "", 0); |
53 EXPECT_TRUE(c5 == c6); | 61 EXPECT_TRUE(c5 == c6); |
54 } | 62 } |
55 | 63 |
56 TEST(CodecTest, TestAudioCodecOperators) { | 64 TEST(CodecTest, TestAudioCodecOperators) { |
57 AudioCodec c0(96, "A", 44100, 20000, 2); | 65 AudioCodec c0(96, "A", 44100, 20000, 2); |
58 AudioCodec c1(95, "A", 44100, 20000, 2); | 66 AudioCodec c1(95, "A", 44100, 20000, 2); |
59 AudioCodec c2(96, "x", 44100, 20000, 2); | 67 AudioCodec c2(96, "x", 44100, 20000, 2); |
60 AudioCodec c3(96, "A", 48000, 20000, 2); | 68 AudioCodec c3(96, "A", 48000, 20000, 2); |
61 AudioCodec c4(96, "A", 44100, 10000, 2); | 69 AudioCodec c4(96, "A", 44100, 10000, 2); |
62 AudioCodec c5(96, "A", 44100, 20000, 1); | 70 AudioCodec c5(96, "A", 44100, 20000, 1); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 EXPECT_FALSE(codec.GetParam("c", &str_value)); | 221 EXPECT_FALSE(codec.GetParam("c", &str_value)); |
214 EXPECT_TRUE(codec.RemoveParam("a")); | 222 EXPECT_TRUE(codec.RemoveParam("a")); |
215 EXPECT_FALSE(codec.RemoveParam("c")); | 223 EXPECT_FALSE(codec.RemoveParam("c")); |
216 } | 224 } |
217 | 225 |
218 TEST(CodecTest, TestIntersectFeedbackParams) { | 226 TEST(CodecTest, TestIntersectFeedbackParams) { |
219 const FeedbackParam a1("a", "1"); | 227 const FeedbackParam a1("a", "1"); |
220 const FeedbackParam b2("b", "2"); | 228 const FeedbackParam b2("b", "2"); |
221 const FeedbackParam b3("b", "3"); | 229 const FeedbackParam b3("b", "3"); |
222 const FeedbackParam c3("c", "3"); | 230 const FeedbackParam c3("c", "3"); |
223 Codec c1; | 231 TestCodec c1; |
224 c1.AddFeedbackParam(a1); // Only match with c2. | 232 c1.AddFeedbackParam(a1); // Only match with c2. |
225 c1.AddFeedbackParam(b2); // Same param different values. | 233 c1.AddFeedbackParam(b2); // Same param different values. |
226 c1.AddFeedbackParam(c3); // Not in c2. | 234 c1.AddFeedbackParam(c3); // Not in c2. |
227 Codec c2; | 235 TestCodec c2; |
228 c2.AddFeedbackParam(a1); | 236 c2.AddFeedbackParam(a1); |
229 c2.AddFeedbackParam(b3); | 237 c2.AddFeedbackParam(b3); |
230 | 238 |
231 c1.IntersectFeedbackParams(c2); | 239 c1.IntersectFeedbackParams(c2); |
232 EXPECT_TRUE(c1.HasFeedbackParam(a1)); | 240 EXPECT_TRUE(c1.HasFeedbackParam(a1)); |
233 EXPECT_FALSE(c1.HasFeedbackParam(b2)); | 241 EXPECT_FALSE(c1.HasFeedbackParam(b2)); |
234 EXPECT_FALSE(c1.HasFeedbackParam(c3)); | 242 EXPECT_FALSE(c1.HasFeedbackParam(c3)); |
235 } | 243 } |
236 | 244 |
237 TEST(CodecTest, TestGetCodecType) { | 245 TEST(CodecTest, TestGetCodecType) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 EXPECT_EQ(cricket::kVideoCodecClockrate, codec_params_1.clock_rate); | 315 EXPECT_EQ(cricket::kVideoCodecClockrate, codec_params_1.clock_rate); |
308 EXPECT_EQ(1, codec_params_1.channels); | 316 EXPECT_EQ(1, codec_params_1.channels); |
309 | 317 |
310 const AudioCodec a(97, "A", 44100, 20000, 2); | 318 const AudioCodec a(97, "A", 44100, 20000, 2); |
311 webrtc::RtpCodecParameters codec_params_2 = a.ToCodecParameters(); | 319 webrtc::RtpCodecParameters codec_params_2 = a.ToCodecParameters(); |
312 EXPECT_EQ(97, codec_params_2.payload_type); | 320 EXPECT_EQ(97, codec_params_2.payload_type); |
313 EXPECT_EQ("A", codec_params_2.mime_type); | 321 EXPECT_EQ("A", codec_params_2.mime_type); |
314 EXPECT_EQ(44100, codec_params_2.clock_rate); | 322 EXPECT_EQ(44100, codec_params_2.clock_rate); |
315 EXPECT_EQ(2, codec_params_2.channels); | 323 EXPECT_EQ(2, codec_params_2.channels); |
316 } | 324 } |
OLD | NEW |