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 15 matching lines...) Expand all Loading... |
26 #include "webrtc/media/engine/webrtcvoiceengine.h" | 26 #include "webrtc/media/engine/webrtcvoiceengine.h" |
27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" | 27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" |
28 | 28 |
29 using cricket::kRtpAudioLevelHeaderExtension; | 29 using cricket::kRtpAudioLevelHeaderExtension; |
30 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; | 30 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; |
31 using testing::Return; | 31 using testing::Return; |
32 using testing::StrictMock; | 32 using testing::StrictMock; |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0); | 36 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); |
37 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0); | 37 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); |
38 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0); | 38 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); |
39 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1, 0); | 39 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1); |
40 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1, 0); | 40 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1); |
41 const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1, 0); | 41 const cricket::AudioCodec kRedCodec(117, "red", 8000, 0, 1); |
42 const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0); | 42 const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1); |
43 const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0); | 43 const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1); |
44 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, 0, | 44 const cricket::AudioCodec kTelephoneEventCodec(106, |
45 1, 0); | 45 "telephone-event", |
| 46 8000, |
| 47 0, |
| 48 1); |
46 const uint32_t kSsrc1 = 0x99; | 49 const uint32_t kSsrc1 = 0x99; |
47 const uint32_t kSsrc2 = 2; | 50 const uint32_t kSsrc2 = 2; |
48 const uint32_t kSsrc3 = 3; | 51 const uint32_t kSsrc3 = 3; |
49 const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; | 52 const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; |
50 | 53 |
51 class FakeVoEWrapper : public cricket::VoEWrapper { | 54 class FakeVoEWrapper : public cricket::VoEWrapper { |
52 public: | 55 public: |
53 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) | 56 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) |
54 : cricket::VoEWrapper(engine, // processing | 57 : cricket::VoEWrapper(engine, // processing |
55 engine, // base | 58 engine, // base |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 private: | 479 private: |
477 webrtc::test::ScopedFieldTrials override_field_trials_; | 480 webrtc::test::ScopedFieldTrials override_field_trials_; |
478 }; | 481 }; |
479 | 482 |
480 // Tests that we can create and destroy a channel. | 483 // Tests that we can create and destroy a channel. |
481 TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) { | 484 TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) { |
482 EXPECT_TRUE(SetupChannel()); | 485 EXPECT_TRUE(SetupChannel()); |
483 } | 486 } |
484 | 487 |
485 // Tests that the list of supported codecs is created properly and ordered | 488 // Tests that the list of supported codecs is created properly and ordered |
486 // correctly | 489 // correctly (such that opus appears first). |
487 TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) { | 490 TEST_F(WebRtcVoiceEngineTestFake, CodecOrder) { |
488 const std::vector<cricket::AudioCodec>& codecs = engine_->codecs(); | 491 const std::vector<cricket::AudioCodec>& codecs = engine_->codecs(); |
489 ASSERT_FALSE(codecs.empty()); | 492 ASSERT_FALSE(codecs.empty()); |
490 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str()); | 493 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str()); |
491 EXPECT_EQ(48000, codecs[0].clockrate); | 494 EXPECT_EQ(48000, codecs[0].clockrate); |
492 EXPECT_EQ(2, codecs[0].channels); | 495 EXPECT_EQ(2, codecs[0].channels); |
493 EXPECT_EQ(64000, codecs[0].bitrate); | 496 EXPECT_EQ(64000, codecs[0].bitrate); |
494 int pref = codecs[0].preference; | |
495 for (size_t i = 1; i < codecs.size(); ++i) { | |
496 EXPECT_GT(pref, codecs[i].preference); | |
497 pref = codecs[i].preference; | |
498 } | |
499 } | 497 } |
500 | 498 |
501 TEST_F(WebRtcVoiceEngineTestFake, OpusSupportsTransportCc) { | 499 TEST_F(WebRtcVoiceEngineTestFake, OpusSupportsTransportCc) { |
502 const std::vector<cricket::AudioCodec>& codecs = engine_->codecs(); | 500 const std::vector<cricket::AudioCodec>& codecs = engine_->codecs(); |
503 bool opus_found = false; | 501 bool opus_found = false; |
504 for (cricket::AudioCodec codec : codecs) { | 502 for (cricket::AudioCodec codec : codecs) { |
505 if (codec.name == "opus") { | 503 if (codec.name == "opus") { |
506 EXPECT_TRUE(HasTransportCc(codec)); | 504 EXPECT_TRUE(HasTransportCc(codec)); |
507 opus_found = true; | 505 opus_found = true; |
508 } | 506 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); | 570 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); |
573 EXPECT_EQ(126, gcodec.pltype); | 571 EXPECT_EQ(126, gcodec.pltype); |
574 EXPECT_STREQ("telephone-event", gcodec.plname); | 572 EXPECT_STREQ("telephone-event", gcodec.plname); |
575 } | 573 } |
576 | 574 |
577 // Test that we fail to set an unknown inbound codec. | 575 // Test that we fail to set an unknown inbound codec. |
578 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { | 576 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { |
579 EXPECT_TRUE(SetupChannel()); | 577 EXPECT_TRUE(SetupChannel()); |
580 cricket::AudioRecvParameters parameters; | 578 cricket::AudioRecvParameters parameters; |
581 parameters.codecs.push_back(kIsacCodec); | 579 parameters.codecs.push_back(kIsacCodec); |
582 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0)); | 580 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1)); |
583 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); | 581 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
584 } | 582 } |
585 | 583 |
586 // Test that we fail if we have duplicate types in the inbound list. | 584 // Test that we fail if we have duplicate types in the inbound list. |
587 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) { | 585 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) { |
588 EXPECT_TRUE(SetupChannel()); | 586 EXPECT_TRUE(SetupChannel()); |
589 cricket::AudioRecvParameters parameters; | 587 cricket::AudioRecvParameters parameters; |
590 parameters.codecs.push_back(kIsacCodec); | 588 parameters.codecs.push_back(kIsacCodec); |
591 parameters.codecs.push_back(kCn16000Codec); | 589 parameters.codecs.push_back(kCn16000Codec); |
592 parameters.codecs[1].id = kIsacCodec.id; | 590 parameters.codecs[1].id = kIsacCodec.id; |
(...skipping 2785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3378 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); | 3376 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); |
3379 EXPECT_TRUE(channel != nullptr); | 3377 EXPECT_TRUE(channel != nullptr); |
3380 delete channel; | 3378 delete channel; |
3381 } | 3379 } |
3382 } | 3380 } |
3383 | 3381 |
3384 // Tests that the library is configured with the codecs we want. | 3382 // Tests that the library is configured with the codecs we want. |
3385 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | 3383 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
3386 // Check codecs by name. | 3384 // Check codecs by name. |
3387 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3385 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3388 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0), nullptr)); | 3386 cricket::AudioCodec(96, "OPUS", 48000, 0, 2), nullptr)); |
3389 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3387 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3390 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0), nullptr)); | 3388 cricket::AudioCodec(96, "ISAC", 16000, 0, 1), nullptr)); |
3391 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3389 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3392 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0), nullptr)); | 3390 cricket::AudioCodec(96, "ISAC", 32000, 0, 1), nullptr)); |
3393 // Check that name matching is case-insensitive. | 3391 // Check that name matching is case-insensitive. |
3394 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3392 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3395 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0), nullptr)); | 3393 cricket::AudioCodec(96, "ILBC", 8000, 0, 1), nullptr)); |
3396 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3394 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3397 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0), nullptr)); | 3395 cricket::AudioCodec(96, "iLBC", 8000, 0, 1), nullptr)); |
3398 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3396 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3399 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0), nullptr)); | 3397 cricket::AudioCodec(96, "PCMU", 8000, 0, 1), nullptr)); |
3400 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3398 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3401 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0), nullptr)); | 3399 cricket::AudioCodec(96, "PCMA", 8000, 0, 1), nullptr)); |
3402 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3400 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3403 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0), nullptr)); | 3401 cricket::AudioCodec(96, "G722", 8000, 0, 1), nullptr)); |
3404 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3402 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3405 cricket::AudioCodec(96, "red", 8000, 0, 1, 0), nullptr)); | 3403 cricket::AudioCodec(96, "red", 8000, 0, 1), nullptr)); |
3406 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3404 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3407 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0), nullptr)); | 3405 cricket::AudioCodec(96, "CN", 32000, 0, 1), nullptr)); |
3408 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3406 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3409 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0), nullptr)); | 3407 cricket::AudioCodec(96, "CN", 16000, 0, 1), nullptr)); |
3410 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3408 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3411 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0), nullptr)); | 3409 cricket::AudioCodec(96, "CN", 8000, 0, 1), nullptr)); |
3412 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3410 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3413 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0), nullptr)); | 3411 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1), nullptr)); |
3414 // Check codecs with an id by id. | 3412 // Check codecs with an id by id. |
3415 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3413 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3416 cricket::AudioCodec(0, "", 8000, 0, 1, 0), nullptr)); // PCMU | 3414 cricket::AudioCodec(0, "", 8000, 0, 1), nullptr)); // PCMU |
3417 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3415 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3418 cricket::AudioCodec(8, "", 8000, 0, 1, 0), nullptr)); // PCMA | 3416 cricket::AudioCodec(8, "", 8000, 0, 1), nullptr)); // PCMA |
3419 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3417 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3420 cricket::AudioCodec(9, "", 8000, 0, 1, 0), nullptr)); // G722 | 3418 cricket::AudioCodec(9, "", 8000, 0, 1), nullptr)); // G722 |
3421 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3419 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3422 cricket::AudioCodec(13, "", 8000, 0, 1, 0), nullptr)); // CN | 3420 cricket::AudioCodec(13, "", 8000, 0, 1), nullptr)); // CN |
3423 // Check sample/bitrate matching. | 3421 // Check sample/bitrate matching. |
3424 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3422 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3425 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0), nullptr)); | 3423 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1), nullptr)); |
3426 // Check that bad codecs fail. | 3424 // Check that bad codecs fail. |
3427 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3425 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3428 cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0), nullptr)); | 3426 cricket::AudioCodec(99, "ABCD", 0, 0, 1), nullptr)); |
3429 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3427 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3430 cricket::AudioCodec(88, "", 0, 0, 1, 0), nullptr)); | 3428 cricket::AudioCodec(88, "", 0, 0, 1), nullptr)); |
3431 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3429 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3432 cricket::AudioCodec(0, "", 0, 0, 2, 0), nullptr)); | 3430 cricket::AudioCodec(0, "", 0, 0, 2), nullptr)); |
3433 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3431 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3434 cricket::AudioCodec(0, "", 5000, 0, 1, 0), nullptr)); | 3432 cricket::AudioCodec(0, "", 5000, 0, 1), nullptr)); |
3435 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( | 3433 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( |
3436 cricket::AudioCodec(0, "", 0, 5000, 1, 0), nullptr)); | 3434 cricket::AudioCodec(0, "", 0, 5000, 1), nullptr)); |
3437 | 3435 |
3438 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | 3436 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
3439 cricket::WebRtcVoiceEngine engine(nullptr); | 3437 cricket::WebRtcVoiceEngine engine(nullptr); |
3440 for (std::vector<cricket::AudioCodec>::const_iterator it = | 3438 for (std::vector<cricket::AudioCodec>::const_iterator it = |
3441 engine.codecs().begin(); it != engine.codecs().end(); ++it) { | 3439 engine.codecs().begin(); it != engine.codecs().end(); ++it) { |
3442 if (it->name == "CN" && it->clockrate == 16000) { | 3440 if (it->name == "CN" && it->clockrate == 16000) { |
3443 EXPECT_EQ(105, it->id); | 3441 EXPECT_EQ(105, it->id); |
3444 } else if (it->name == "CN" && it->clockrate == 32000) { | 3442 } else if (it->name == "CN" && it->clockrate == 32000) { |
3445 EXPECT_EQ(106, it->id); | 3443 EXPECT_EQ(106, it->id); |
3446 } else if (it->name == "ISAC" && it->clockrate == 16000) { | 3444 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3493 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | 3491 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
3494 cricket::WebRtcVoiceEngine engine(nullptr); | 3492 cricket::WebRtcVoiceEngine engine(nullptr); |
3495 std::unique_ptr<webrtc::Call> call( | 3493 std::unique_ptr<webrtc::Call> call( |
3496 webrtc::Call::Create(webrtc::Call::Config())); | 3494 webrtc::Call::Create(webrtc::Call::Config())); |
3497 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), | 3495 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), |
3498 cricket::AudioOptions(), call.get()); | 3496 cricket::AudioOptions(), call.get()); |
3499 cricket::AudioRecvParameters parameters; | 3497 cricket::AudioRecvParameters parameters; |
3500 parameters.codecs = engine.codecs(); | 3498 parameters.codecs = engine.codecs(); |
3501 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3499 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3502 } | 3500 } |
OLD | NEW |