OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2008 Google Inc. | 3 * Copyright 2008 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const uint32_t kSsrc1 = 0x99; | 57 const uint32_t kSsrc1 = 0x99; |
58 const uint32_t kSsrc2 = 0x98; | 58 const uint32_t kSsrc2 = 0x98; |
59 const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; | 59 const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; |
60 | 60 |
61 class FakeVoEWrapper : public cricket::VoEWrapper { | 61 class FakeVoEWrapper : public cricket::VoEWrapper { |
62 public: | 62 public: |
63 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) | 63 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) |
64 : cricket::VoEWrapper(engine, // processing | 64 : cricket::VoEWrapper(engine, // processing |
65 engine, // base | 65 engine, // base |
66 engine, // codec | 66 engine, // codec |
67 engine, // dtmf | |
68 engine, // hw | 67 engine, // hw |
69 engine, // network | 68 engine, // network |
70 engine, // rtp | 69 engine, // rtp |
71 engine) { // volume | 70 engine) { // volume |
72 } | 71 } |
73 }; | 72 }; |
74 } // namespace | 73 } // namespace |
75 | 74 |
76 class WebRtcVoiceEngineTestFake : public testing::Test { | 75 class WebRtcVoiceEngineTestFake : public testing::Test { |
77 public: | 76 public: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 113 } |
115 void DeliverPacket(const void* data, int len) { | 114 void DeliverPacket(const void* data, int len) { |
116 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len); | 115 rtc::Buffer packet(reinterpret_cast<const uint8_t*>(data), len); |
117 channel_->OnPacketReceived(&packet, rtc::PacketTime()); | 116 channel_->OnPacketReceived(&packet, rtc::PacketTime()); |
118 } | 117 } |
119 void TearDown() override { | 118 void TearDown() override { |
120 delete channel_; | 119 delete channel_; |
121 engine_.Terminate(); | 120 engine_.Terminate(); |
122 } | 121 } |
123 | 122 |
| 123 const cricket::FakeAudioSendStream& GetSendStream(uint32_t ssrc) { |
| 124 const auto* send_stream = call_.GetAudioSendStream(ssrc); |
| 125 EXPECT_TRUE(send_stream); |
| 126 return *send_stream; |
| 127 } |
| 128 |
124 const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) { | 129 const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) { |
125 const auto* send_stream = call_.GetAudioSendStream(ssrc); | 130 const auto* send_stream = call_.GetAudioSendStream(ssrc); |
126 EXPECT_TRUE(send_stream); | 131 EXPECT_TRUE(send_stream); |
127 return send_stream->GetConfig(); | 132 return send_stream->GetConfig(); |
128 } | 133 } |
129 | 134 |
130 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) { | 135 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) { |
131 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc); | 136 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc); |
132 EXPECT_TRUE(recv_stream); | 137 EXPECT_TRUE(recv_stream); |
133 return recv_stream->GetConfig(); | 138 return recv_stream->GetConfig(); |
(...skipping 22 matching lines...) Expand all Loading... |
156 if (!caller) { | 161 if (!caller) { |
157 // If this is callee, there's no active send channel yet. | 162 // If this is callee, there's no active send channel yet. |
158 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123)); | 163 EXPECT_FALSE(channel_->InsertDtmf(ssrc, 2, 123)); |
159 EXPECT_TRUE(channel_->AddSendStream( | 164 EXPECT_TRUE(channel_->AddSendStream( |
160 cricket::StreamParams::CreateLegacy(kSsrc1))); | 165 cricket::StreamParams::CreateLegacy(kSsrc1))); |
161 } | 166 } |
162 | 167 |
163 // Check we fail if the ssrc is invalid. | 168 // Check we fail if the ssrc is invalid. |
164 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111)); | 169 EXPECT_FALSE(channel_->InsertDtmf(-1, 1, 111)); |
165 | 170 |
166 // Test send | 171 // Test send. |
167 int channel_id = voe_.GetLastChannel(); | 172 cricket::FakeAudioSendStream::TelephoneEvent telephone_event = |
168 EXPECT_FALSE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123)); | 173 GetSendStream(kSsrc1).GetLatestTelephoneEvent(); |
| 174 EXPECT_EQ(-1, telephone_event.payload_type); |
169 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123)); | 175 EXPECT_TRUE(channel_->InsertDtmf(ssrc, 2, 123)); |
170 EXPECT_TRUE(voe_.WasSendTelephoneEventCalled(channel_id, 2, 123)); | 176 telephone_event = GetSendStream(kSsrc1).GetLatestTelephoneEvent(); |
| 177 EXPECT_EQ(kTelephoneEventCodec.id, telephone_event.payload_type); |
| 178 EXPECT_EQ(2, telephone_event.event_code); |
| 179 EXPECT_EQ(123, telephone_event.duration_ms); |
171 } | 180 } |
172 | 181 |
173 // Test that send bandwidth is set correctly. | 182 // Test that send bandwidth is set correctly. |
174 // |codec| is the codec under test. | 183 // |codec| is the codec under test. |
175 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth(). | 184 // |max_bitrate| is a parameter to set to SetMaxSendBandwidth(). |
176 // |expected_result| is the expected result from SetMaxSendBandwidth(). | 185 // |expected_result| is the expected result from SetMaxSendBandwidth(). |
177 // |expected_bitrate| is the expected audio bitrate afterward. | 186 // |expected_bitrate| is the expected audio bitrate afterward. |
178 void TestSendBandwidth(const cricket::AudioCodec& codec, | 187 void TestSendBandwidth(const cricket::AudioCodec& codec, |
179 int max_bitrate, | 188 int max_bitrate, |
180 bool expected_result, | 189 bool expected_result, |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 int channel_num = voe_.GetLastChannel(); | 768 int channel_num = voe_.GetLastChannel(); |
760 webrtc::CodecInst gcodec; | 769 webrtc::CodecInst gcodec; |
761 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 770 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
762 EXPECT_EQ(96, gcodec.pltype); | 771 EXPECT_EQ(96, gcodec.pltype); |
763 EXPECT_EQ(48000, gcodec.rate); | 772 EXPECT_EQ(48000, gcodec.rate); |
764 EXPECT_STREQ("ISAC", gcodec.plname); | 773 EXPECT_STREQ("ISAC", gcodec.plname); |
765 EXPECT_FALSE(voe_.GetVAD(channel_num)); | 774 EXPECT_FALSE(voe_.GetVAD(channel_num)); |
766 EXPECT_FALSE(voe_.GetRED(channel_num)); | 775 EXPECT_FALSE(voe_.GetRED(channel_num)); |
767 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); | 776 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
768 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true)); | 777 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true)); |
769 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num)); | 778 EXPECT_FALSE(channel_->CanInsertDtmf()); |
770 } | 779 } |
771 | 780 |
772 // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried | 781 // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried |
773 // to apply. | 782 // to apply. |
774 TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) { | 783 TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) { |
775 EXPECT_TRUE(SetupEngineWithSendStream()); | 784 EXPECT_TRUE(SetupEngineWithSendStream()); |
776 cricket::AudioSendParameters parameters; | 785 cricket::AudioSendParameters parameters; |
777 parameters.codecs.push_back(kIsacCodec); | 786 parameters.codecs.push_back(kIsacCodec); |
778 parameters.codecs.push_back(kPcmuCodec); | 787 parameters.codecs.push_back(kPcmuCodec); |
779 parameters.codecs.push_back(kRedCodec); | 788 parameters.codecs.push_back(kRedCodec); |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 parameters.codecs.push_back(kTelephoneEventCodec); | 1609 parameters.codecs.push_back(kTelephoneEventCodec); |
1601 parameters.codecs.push_back(kIsacCodec); | 1610 parameters.codecs.push_back(kIsacCodec); |
1602 parameters.codecs.push_back(kPcmuCodec); | 1611 parameters.codecs.push_back(kPcmuCodec); |
1603 parameters.codecs[0].id = 98; // DTMF | 1612 parameters.codecs[0].id = 98; // DTMF |
1604 parameters.codecs[1].id = 96; | 1613 parameters.codecs[1].id = 96; |
1605 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 1614 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
1606 webrtc::CodecInst gcodec; | 1615 webrtc::CodecInst gcodec; |
1607 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 1616 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
1608 EXPECT_EQ(96, gcodec.pltype); | 1617 EXPECT_EQ(96, gcodec.pltype); |
1609 EXPECT_STREQ("ISAC", gcodec.plname); | 1618 EXPECT_STREQ("ISAC", gcodec.plname); |
1610 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); | 1619 EXPECT_TRUE(channel_->CanInsertDtmf()); |
1611 } | 1620 } |
1612 | 1621 |
1613 // Test that we can set send codecs even with CN codec as the first | 1622 // Test that we can set send codecs even with CN codec as the first |
1614 // one on the list. | 1623 // one on the list. |
1615 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) { | 1624 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) { |
1616 EXPECT_TRUE(SetupEngineWithSendStream()); | 1625 EXPECT_TRUE(SetupEngineWithSendStream()); |
1617 int channel_num = voe_.GetLastChannel(); | 1626 int channel_num = voe_.GetLastChannel(); |
1618 cricket::AudioSendParameters parameters; | 1627 cricket::AudioSendParameters parameters; |
1619 parameters.codecs.push_back(kCn16000Codec); | 1628 parameters.codecs.push_back(kCn16000Codec); |
1620 parameters.codecs.push_back(kIsacCodec); | 1629 parameters.codecs.push_back(kIsacCodec); |
(...skipping 25 matching lines...) Expand all Loading... |
1646 parameters.codecs[4].id = 98; // DTMF | 1655 parameters.codecs[4].id = 98; // DTMF |
1647 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 1656 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
1648 webrtc::CodecInst gcodec; | 1657 webrtc::CodecInst gcodec; |
1649 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 1658 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
1650 EXPECT_EQ(96, gcodec.pltype); | 1659 EXPECT_EQ(96, gcodec.pltype); |
1651 EXPECT_STREQ("ISAC", gcodec.plname); | 1660 EXPECT_STREQ("ISAC", gcodec.plname); |
1652 EXPECT_TRUE(voe_.GetVAD(channel_num)); | 1661 EXPECT_TRUE(voe_.GetVAD(channel_num)); |
1653 EXPECT_FALSE(voe_.GetRED(channel_num)); | 1662 EXPECT_FALSE(voe_.GetRED(channel_num)); |
1654 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); | 1663 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
1655 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); | 1664 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
1656 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); | 1665 EXPECT_TRUE(channel_->CanInsertDtmf()); |
1657 } | 1666 } |
1658 | 1667 |
1659 // Test that we set VAD and DTMF types correctly as callee. | 1668 // Test that we set VAD and DTMF types correctly as callee. |
1660 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) { | 1669 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) { |
1661 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); | 1670 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); |
1662 channel_ = engine_.CreateChannel(&call_, cricket::AudioOptions()); | 1671 channel_ = engine_.CreateChannel(&call_, cricket::AudioOptions()); |
1663 EXPECT_TRUE(channel_ != nullptr); | 1672 EXPECT_TRUE(channel_ != nullptr); |
1664 | 1673 |
1665 cricket::AudioSendParameters parameters; | 1674 cricket::AudioSendParameters parameters; |
1666 parameters.codecs.push_back(kIsacCodec); | 1675 parameters.codecs.push_back(kIsacCodec); |
(...skipping 12 matching lines...) Expand all Loading... |
1679 int channel_num = voe_.GetLastChannel(); | 1688 int channel_num = voe_.GetLastChannel(); |
1680 | 1689 |
1681 webrtc::CodecInst gcodec; | 1690 webrtc::CodecInst gcodec; |
1682 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 1691 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
1683 EXPECT_EQ(96, gcodec.pltype); | 1692 EXPECT_EQ(96, gcodec.pltype); |
1684 EXPECT_STREQ("ISAC", gcodec.plname); | 1693 EXPECT_STREQ("ISAC", gcodec.plname); |
1685 EXPECT_TRUE(voe_.GetVAD(channel_num)); | 1694 EXPECT_TRUE(voe_.GetVAD(channel_num)); |
1686 EXPECT_FALSE(voe_.GetRED(channel_num)); | 1695 EXPECT_FALSE(voe_.GetRED(channel_num)); |
1687 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); | 1696 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
1688 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); | 1697 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
1689 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); | 1698 EXPECT_TRUE(channel_->CanInsertDtmf()); |
1690 } | 1699 } |
1691 | 1700 |
1692 // Test that we only apply VAD if we have a CN codec that matches the | 1701 // Test that we only apply VAD if we have a CN codec that matches the |
1693 // send codec clockrate. | 1702 // send codec clockrate. |
1694 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) { | 1703 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) { |
1695 EXPECT_TRUE(SetupEngineWithSendStream()); | 1704 EXPECT_TRUE(SetupEngineWithSendStream()); |
1696 int channel_num = voe_.GetLastChannel(); | 1705 int channel_num = voe_.GetLastChannel(); |
1697 cricket::AudioSendParameters parameters; | 1706 cricket::AudioSendParameters parameters; |
1698 // Set ISAC(16K) and CN(16K). VAD should be activated. | 1707 // Set ISAC(16K) and CN(16K). VAD should be activated. |
1699 parameters.codecs.push_back(kIsacCodec); | 1708 parameters.codecs.push_back(kIsacCodec); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 parameters.codecs[4].id = 98; // DTMF | 1752 parameters.codecs[4].id = 98; // DTMF |
1744 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 1753 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
1745 webrtc::CodecInst gcodec; | 1754 webrtc::CodecInst gcodec; |
1746 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 1755 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
1747 EXPECT_EQ(96, gcodec.pltype); | 1756 EXPECT_EQ(96, gcodec.pltype); |
1748 EXPECT_STREQ("ISAC", gcodec.plname); | 1757 EXPECT_STREQ("ISAC", gcodec.plname); |
1749 EXPECT_TRUE(voe_.GetVAD(channel_num)); | 1758 EXPECT_TRUE(voe_.GetVAD(channel_num)); |
1750 EXPECT_FALSE(voe_.GetRED(channel_num)); | 1759 EXPECT_FALSE(voe_.GetRED(channel_num)); |
1751 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); | 1760 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); |
1752 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); | 1761 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
1753 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); | 1762 EXPECT_TRUE(channel_->CanInsertDtmf()); |
1754 } | 1763 } |
1755 | 1764 |
1756 // Test that we set up RED correctly as caller. | 1765 // Test that we set up RED correctly as caller. |
1757 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) { | 1766 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) { |
1758 EXPECT_TRUE(SetupEngineWithSendStream()); | 1767 EXPECT_TRUE(SetupEngineWithSendStream()); |
1759 int channel_num = voe_.GetLastChannel(); | 1768 int channel_num = voe_.GetLastChannel(); |
1760 cricket::AudioSendParameters parameters; | 1769 cricket::AudioSendParameters parameters; |
1761 parameters.codecs.push_back(kRedCodec); | 1770 parameters.codecs.push_back(kRedCodec); |
1762 parameters.codecs.push_back(kIsacCodec); | 1771 parameters.codecs.push_back(kIsacCodec); |
1763 parameters.codecs.push_back(kPcmuCodec); | 1772 parameters.codecs.push_back(kPcmuCodec); |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3343 cricket::WebRtcVoiceEngine engine; | 3352 cricket::WebRtcVoiceEngine engine; |
3344 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3353 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3345 rtc::scoped_ptr<webrtc::Call> call( | 3354 rtc::scoped_ptr<webrtc::Call> call( |
3346 webrtc::Call::Create(webrtc::Call::Config())); | 3355 webrtc::Call::Create(webrtc::Call::Config())); |
3347 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), | 3356 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), |
3348 call.get()); | 3357 call.get()); |
3349 cricket::AudioRecvParameters parameters; | 3358 cricket::AudioRecvParameters parameters; |
3350 parameters.codecs = engine.codecs(); | 3359 parameters.codecs = engine.codecs(); |
3351 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3360 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3352 } | 3361 } |
OLD | NEW |