OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2008 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 12 matching lines...) Expand all Loading... |
23 #include "webrtc/media/base/mediaconstants.h" | 23 #include "webrtc/media/base/mediaconstants.h" |
24 #include "webrtc/media/engine/fakewebrtccall.h" | 24 #include "webrtc/media/engine/fakewebrtccall.h" |
25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" | 25 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" |
26 #include "webrtc/media/engine/webrtcvoiceengine.h" | 26 #include "webrtc/media/engine/webrtcvoiceengine.h" |
27 | 27 |
28 using cricket::kRtpAudioLevelHeaderExtension; | 28 using cricket::kRtpAudioLevelHeaderExtension; |
29 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; | 29 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0); | 33 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); |
34 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0); | 34 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); |
35 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0); | 35 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); |
36 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1, 0); | 36 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1); |
37 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1, 0); | 37 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1); |
38 const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0); | 38 const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1); |
39 const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0); | 39 const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1); |
40 const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0); | 40 const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1); |
41 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, 0, | 41 const cricket::AudioCodec kTelephoneEventCodec(106, |
42 1, 0); | 42 "telephone-event", |
| 43 8000, |
| 44 0, |
| 45 1); |
43 const uint32_t kSsrc1 = 0x99; | 46 const uint32_t kSsrc1 = 0x99; |
44 const uint32_t kSsrc2 = 2; | 47 const uint32_t kSsrc2 = 2; |
45 const uint32_t kSsrc3 = 3; | 48 const uint32_t kSsrc3 = 3; |
46 const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; | 49 const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; |
47 | 50 |
48 class FakeVoEWrapper : public cricket::VoEWrapper { | 51 class FakeVoEWrapper : public cricket::VoEWrapper { |
49 public: | 52 public: |
50 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) | 53 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) |
51 : cricket::VoEWrapper(engine, // processing | 54 : cricket::VoEWrapper(engine, // processing |
52 engine, // base | 55 engine, // base |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 424 |
422 // Tests that we can create and destroy a channel. | 425 // Tests that we can create and destroy a channel. |
423 TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) { | 426 TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) { |
424 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); | 427 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
425 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(), | 428 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(), |
426 cricket::AudioOptions()); | 429 cricket::AudioOptions()); |
427 EXPECT_TRUE(channel_ != nullptr); | 430 EXPECT_TRUE(channel_ != nullptr); |
428 } | 431 } |
429 | 432 |
430 // Tests that the list of supported codecs is created properly and ordered | 433 // Tests that the list of supported codecs is created properly and ordered |
431 // correctly | 434 // correctly (such that opus appears first). |
432 TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) { | 435 TEST_F(WebRtcVoiceEngineTestFake, CodecOrder) { |
433 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs(); | 436 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs(); |
434 ASSERT_FALSE(codecs.empty()); | 437 ASSERT_FALSE(codecs.empty()); |
435 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str()); | 438 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str()); |
436 EXPECT_EQ(48000, codecs[0].clockrate); | 439 EXPECT_EQ(48000, codecs[0].clockrate); |
437 EXPECT_EQ(2, codecs[0].channels); | 440 EXPECT_EQ(2, codecs[0].channels); |
438 EXPECT_EQ(64000, codecs[0].bitrate); | 441 EXPECT_EQ(64000, codecs[0].bitrate); |
439 int pref = codecs[0].preference; | |
440 for (size_t i = 1; i < codecs.size(); ++i) { | |
441 EXPECT_GT(pref, codecs[i].preference); | |
442 pref = codecs[i].preference; | |
443 } | |
444 } | 442 } |
445 | 443 |
446 TEST_F(WebRtcVoiceEngineTestFake, OpusSupportsTransportCc) { | 444 TEST_F(WebRtcVoiceEngineTestFake, OpusSupportsTransportCc) { |
447 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs(); | 445 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs(); |
448 bool opus_found = false; | 446 bool opus_found = false; |
449 for (cricket::AudioCodec codec : codecs) { | 447 for (cricket::AudioCodec codec : codecs) { |
450 if (codec.name == "opus") { | 448 if (codec.name == "opus") { |
451 EXPECT_TRUE(HasTransportCc(codec)); | 449 EXPECT_TRUE(HasTransportCc(codec)); |
452 opus_found = true; | 450 opus_found = true; |
453 } | 451 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); | 515 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); |
518 EXPECT_EQ(126, gcodec.pltype); | 516 EXPECT_EQ(126, gcodec.pltype); |
519 EXPECT_STREQ("telephone-event", gcodec.plname); | 517 EXPECT_STREQ("telephone-event", gcodec.plname); |
520 } | 518 } |
521 | 519 |
522 // Test that we fail to set an unknown inbound codec. | 520 // Test that we fail to set an unknown inbound codec. |
523 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { | 521 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { |
524 EXPECT_TRUE(SetupEngine()); | 522 EXPECT_TRUE(SetupEngine()); |
525 cricket::AudioRecvParameters parameters; | 523 cricket::AudioRecvParameters parameters; |
526 parameters.codecs.push_back(kIsacCodec); | 524 parameters.codecs.push_back(kIsacCodec); |
527 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0)); | 525 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1)); |
528 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); | 526 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
529 } | 527 } |
530 | 528 |
531 // Test that we fail if we have duplicate types in the inbound list. | 529 // Test that we fail if we have duplicate types in the inbound list. |
532 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) { | 530 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) { |
533 EXPECT_TRUE(SetupEngine()); | 531 EXPECT_TRUE(SetupEngine()); |
534 cricket::AudioRecvParameters parameters; | 532 cricket::AudioRecvParameters parameters; |
535 parameters.codecs.push_back(kIsacCodec); | 533 parameters.codecs.push_back(kIsacCodec); |
536 parameters.codecs.push_back(kCn16000Codec); | 534 parameters.codecs.push_back(kCn16000Codec); |
537 parameters.codecs[1].id = kIsacCodec.id; | 535 parameters.codecs[1].id = kIsacCodec.id; |
(...skipping 2692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 | 3228 |
3231 // Reinit to catch regression where VoiceEngineObserver reference is lost | 3229 // Reinit to catch regression where VoiceEngineObserver reference is lost |
3232 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3230 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3233 engine.Terminate(); | 3231 engine.Terminate(); |
3234 } | 3232 } |
3235 | 3233 |
3236 // Tests that the library is configured with the codecs we want. | 3234 // Tests that the library is configured with the codecs we want. |
3237 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 3235 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
3238 // Check codecs by name. | 3236 // Check codecs by name. |
3239 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3237 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3240 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0), nullptr)); | 3238 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); |
3241 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3239 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3242 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0), nullptr)); | 3240 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); |
3243 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3241 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3244 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0), nullptr)); | 3242 cricket::AudioCodec(96, "ISAC", 32000, 0, 1), nullptr)); |
3245 // Check that name matching is case-insensitive. | 3243 // Check that name matching is case-insensitive. |
3246 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3244 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3247 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0), nullptr)); | 3245 cricket::AudioCodec(96, "ILBC", 8000, 0, 1), nullptr)); |
3248 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3246 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3249 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0), nullptr)); | 3247 cricket::AudioCodec(96, "iLBC", 8000, 0, 1), nullptr)); |
3250 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3248 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3251 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0), nullptr)); | 3249 cricket::AudioCodec(96, "PCMU", 8000, 0, 1), nullptr)); |
3252 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3250 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3253 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0), nullptr)); | 3251 cricket::AudioCodec(96, "PCMA", 8000, 0, 1), nullptr)); |
3254 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3252 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3255 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0), nullptr)); | 3253 cricket::AudioCodec(96, "G722", 8000, 0, 1), nullptr)); |
3256 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3254 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3257 cricket::AudioCodec(96, "red", 8000, 0, 1, 0), nullptr)); | 3255 cricket::AudioCodec(96, "red", 8000, 0, 1), nullptr)); |
3258 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3256 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3259 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0), nullptr)); | 3257 cricket::AudioCodec(96, "CN", 32000, 0, 1), nullptr)); |
3260 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3258 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3261 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0), nullptr)); | 3259 cricket::AudioCodec(96, "CN", 16000, 0, 1), nullptr)); |
3262 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3260 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3263 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0), nullptr)); | 3261 cricket::AudioCodec(96, "CN", 8000, 0, 1), nullptr)); |
3264 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3262 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3265 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0), nullptr)); | 3263 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1), nullptr)); |
3266 // Check codecs with an id by id. | 3264 // Check codecs with an id by id. |
3267 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3265 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3268 cricket::AudioCodec(0, "", 8000, 0, 1, 0), nullptr)); // PCMU | 3266 cricket::AudioCodec(0, "", 8000, 0, 1), nullptr)); // PCMU |
3269 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3267 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3270 cricket::AudioCodec(8, "", 8000, 0, 1, 0), nullptr)); // PCMA | 3268 cricket::AudioCodec(8, "", 8000, 0, 1), nullptr)); // PCMA |
3271 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3269 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3272 cricket::AudioCodec(9, "", 8000, 0, 1, 0), nullptr)); // G722 | 3270 cricket::AudioCodec(9, "", 8000, 0, 1), nullptr)); // G722 |
3273 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3271 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3274 cricket::AudioCodec(13, "", 8000, 0, 1, 0), nullptr)); // CN | 3272 cricket::AudioCodec(13, "", 8000, 0, 1), nullptr)); // CN |
3275 // Check sample/bitrate matching. | 3273 // Check sample/bitrate matching. |
3276 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3274 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3277 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0), nullptr)); | 3275 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1), nullptr)); |
3278 // Check that bad codecs fail. | 3276 // Check that bad codecs fail. |
3279 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3277 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3280 cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0), nullptr)); | 3278 cricket::AudioCodec(99, "ABCD", 0, 0, 1), nullptr)); |
3281 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3279 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3282 cricket::AudioCodec(88, "", 0, 0, 1, 0), nullptr)); | 3280 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); |
3283 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3281 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3284 cricket::AudioCodec(0, "", 0, 0, 2, 0), nullptr)); | 3282 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); |
3285 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3283 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3286 cricket::AudioCodec(0, "", 5000, 0, 1, 0), nullptr)); | 3284 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); |
3287 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3285 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3288 cricket::AudioCodec(0, "", 0, 5000, 1, 0), nullptr)); | 3286 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); |
3289 | 3287 |
3290 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3288 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3291 cricket::WebRtcVoiceEngine engine; | 3289 cricket::WebRtcVoiceEngine engine; |
3292 for (std::vector<cricket::AudioCodec>::const_iterator it = | 3290 for (std::vector<cricket::AudioCodec>::const_iterator it = |
3293 engine.codecs().begin(); it != engine.codecs().end(); ++it) { | 3291 engine.codecs().begin(); it != engine.codecs().end(); ++it) { |
3294 if (it->name == "CN" && it->clockrate == 16000) { | 3292 if (it->name == "CN" && it->clockrate == 16000) { |
3295 EXPECT_EQ(105, it->id); | 3293 EXPECT_EQ(105, it->id); |
3296 } else if (it->name == "CN" && it->clockrate == 32000) { | 3294 } else if (it->name == "CN" && it->clockrate == 32000) { |
3297 EXPECT_EQ(106, it->id); | 3295 EXPECT_EQ(106, it->id); |
3298 } else if (it->name == "ISAC" && it->clockrate == 16000) { | 3296 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3349 cricket::WebRtcVoiceEngine engine; | 3347 cricket::WebRtcVoiceEngine engine; |
3350 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3348 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3351 std::unique_ptr<webrtc::Call> call( | 3349 std::unique_ptr<webrtc::Call> call( |
3352 webrtc::Call::Create(webrtc::Call::Config())); | 3350 webrtc::Call::Create(webrtc::Call::Config())); |
3353 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3351 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3354 cricket::AudioOptions(), call.get()); | 3352 cricket::AudioOptions(), call.get()); |
3355 cricket::AudioRecvParameters parameters; | 3353 cricket::AudioRecvParameters parameters; |
3356 parameters.codecs = engine.codecs(); | 3354 parameters.codecs = engine.codecs(); |
3357 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3355 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3358 } | 3356 } |
OLD | NEW |