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, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
| 28 #ifdef WIN32 |
| 29 #include "webrtc/base/win32.h" |
| 30 #include <objbase.h> |
| 31 #endif |
| 32 |
28 #include "webrtc/base/byteorder.h" | 33 #include "webrtc/base/byteorder.h" |
29 #include "webrtc/base/gunit.h" | 34 #include "webrtc/base/gunit.h" |
30 #include "talk/media/base/constants.h" | 35 #include "talk/media/base/constants.h" |
31 #include "talk/media/base/fakemediaengine.h" | 36 #include "talk/media/base/fakemediaengine.h" |
32 #include "talk/media/base/fakemediaprocessor.h" | 37 #include "talk/media/base/fakemediaprocessor.h" |
33 #include "talk/media/base/fakenetworkinterface.h" | 38 #include "talk/media/base/fakenetworkinterface.h" |
34 #include "talk/media/base/fakertp.h" | 39 #include "talk/media/base/fakertp.h" |
35 #include "talk/media/webrtc/fakewebrtccall.h" | 40 #include "talk/media/webrtc/fakewebrtccall.h" |
36 #include "talk/media/webrtc/fakewebrtcvoiceengine.h" | 41 #include "talk/media/webrtc/fakewebrtcvoiceengine.h" |
37 #include "talk/media/webrtc/webrtcvoiceengine.h" | 42 #include "talk/media/webrtc/webrtcvoiceengine.h" |
(...skipping 3085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3123 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); | 3128 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); |
3124 // Verify previous value is not modified if dscp option is not set. | 3129 // Verify previous value is not modified if dscp option is not set. |
3125 cricket::AudioOptions options1; | 3130 cricket::AudioOptions options1; |
3126 EXPECT_TRUE(channel->SetOptions(options1)); | 3131 EXPECT_TRUE(channel->SetOptions(options1)); |
3127 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); | 3132 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); |
3128 options.dscp.Set(false); | 3133 options.dscp.Set(false); |
3129 EXPECT_TRUE(channel->SetOptions(options)); | 3134 EXPECT_TRUE(channel->SetOptions(options)); |
3130 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); | 3135 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
3131 } | 3136 } |
3132 | 3137 |
| 3138 TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) { |
| 3139 cricket::WebRtcVoiceEngine engine; |
| 3140 cricket::AudioOptions options = engine.GetOptions(); |
| 3141 // The default options should have at least a few things set. We purposefully |
| 3142 // don't check the option values here, though. |
| 3143 EXPECT_TRUE(options.echo_cancellation.IsSet()); |
| 3144 EXPECT_TRUE(options.auto_gain_control.IsSet()); |
| 3145 EXPECT_TRUE(options.noise_suppression.IsSet()); |
| 3146 } |
| 3147 |
3133 // Test that GetReceiveChannelNum returns the default channel for the first | 3148 // Test that GetReceiveChannelNum returns the default channel for the first |
3134 // recv stream in 1-1 calls. | 3149 // recv stream in 1-1 calls. |
3135 TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) { | 3150 TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelNumIn1To1Calls) { |
3136 EXPECT_TRUE(SetupEngine()); | 3151 EXPECT_TRUE(SetupEngine()); |
3137 cricket::WebRtcVoiceMediaChannel* media_channel = | 3152 cricket::WebRtcVoiceMediaChannel* media_channel = |
3138 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); | 3153 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
3139 // Test that GetChannelNum returns the default channel if the SSRC is unknown. | 3154 // Test that GetChannelNum returns the default channel if the SSRC is unknown. |
3140 EXPECT_EQ(media_channel->voe_channel(), | 3155 EXPECT_EQ(media_channel->voe_channel(), |
3141 media_channel->GetReceiveChannelNum(0)); | 3156 media_channel->GetReceiveChannelNum(0)); |
3142 cricket::StreamParams stream; | 3157 cricket::StreamParams stream; |
(...skipping 29 matching lines...) Expand all Loading... |
3172 cricket::StreamParams stream; | 3187 cricket::StreamParams stream; |
3173 stream.ssrcs.push_back(kSsrc2); | 3188 stream.ssrcs.push_back(kSsrc2); |
3174 EXPECT_TRUE(channel_->AddRecvStream(stream)); | 3189 EXPECT_TRUE(channel_->AddRecvStream(stream)); |
3175 | 3190 |
3176 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1)); | 3191 EXPECT_TRUE(channel_->SetOutputScaling(kSsrc2, 2, 1)); |
3177 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right)); | 3192 EXPECT_TRUE(channel_->GetOutputScaling(kSsrc2, &left, &right)); |
3178 EXPECT_DOUBLE_EQ(2, left); | 3193 EXPECT_DOUBLE_EQ(2, left); |
3179 EXPECT_DOUBLE_EQ(1, right); | 3194 EXPECT_DOUBLE_EQ(1, right); |
3180 } | 3195 } |
3181 | 3196 |
| 3197 // Tests for the actual WebRtc VoE library. |
| 3198 |
| 3199 // Tests that the library initializes and shuts down properly. |
| 3200 TEST(WebRtcVoiceEngineTest, StartupShutdown) { |
| 3201 cricket::WebRtcVoiceEngine engine; |
| 3202 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
| 3203 cricket::VoiceMediaChannel* channel = |
| 3204 engine.CreateChannel(cricket::AudioOptions()); |
| 3205 EXPECT_TRUE(channel != nullptr); |
| 3206 delete channel; |
| 3207 engine.Terminate(); |
| 3208 |
| 3209 // Reinit to catch regression where VoiceEngineObserver reference is lost |
| 3210 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
| 3211 engine.Terminate(); |
| 3212 } |
| 3213 |
| 3214 // Tests that the library is configured with the codecs we want. |
| 3215 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { |
| 3216 cricket::WebRtcVoiceEngine engine; |
| 3217 // Check codecs by name. |
| 3218 EXPECT_TRUE(engine.FindCodec( |
| 3219 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0))); |
| 3220 EXPECT_TRUE(engine.FindCodec( |
| 3221 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0))); |
| 3222 EXPECT_TRUE(engine.FindCodec( |
| 3223 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0))); |
| 3224 // Check that name matching is case-insensitive. |
| 3225 EXPECT_TRUE(engine.FindCodec( |
| 3226 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0))); |
| 3227 EXPECT_TRUE(engine.FindCodec( |
| 3228 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0))); |
| 3229 EXPECT_TRUE(engine.FindCodec( |
| 3230 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0))); |
| 3231 EXPECT_TRUE(engine.FindCodec( |
| 3232 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0))); |
| 3233 EXPECT_TRUE(engine.FindCodec( |
| 3234 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0))); |
| 3235 EXPECT_TRUE(engine.FindCodec( |
| 3236 cricket::AudioCodec(96, "red", 8000, 0, 1, 0))); |
| 3237 EXPECT_TRUE(engine.FindCodec( |
| 3238 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0))); |
| 3239 EXPECT_TRUE(engine.FindCodec( |
| 3240 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0))); |
| 3241 EXPECT_TRUE(engine.FindCodec( |
| 3242 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0))); |
| 3243 EXPECT_TRUE(engine.FindCodec( |
| 3244 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0))); |
| 3245 // Check codecs with an id by id. |
| 3246 EXPECT_TRUE(engine.FindCodec( |
| 3247 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU |
| 3248 EXPECT_TRUE(engine.FindCodec( |
| 3249 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA |
| 3250 EXPECT_TRUE(engine.FindCodec( |
| 3251 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722 |
| 3252 EXPECT_TRUE(engine.FindCodec( |
| 3253 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN |
| 3254 // Check sample/bitrate matching. |
| 3255 EXPECT_TRUE(engine.FindCodec( |
| 3256 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0))); |
| 3257 // Check that bad codecs fail. |
| 3258 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0))); |
| 3259 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0))); |
| 3260 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0))); |
| 3261 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0))); |
| 3262 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0))); |
| 3263 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. |
| 3264 for (std::vector<cricket::AudioCodec>::const_iterator it = |
| 3265 engine.codecs().begin(); it != engine.codecs().end(); ++it) { |
| 3266 if (it->name == "CN" && it->clockrate == 16000) { |
| 3267 EXPECT_EQ(105, it->id); |
| 3268 } else if (it->name == "CN" && it->clockrate == 32000) { |
| 3269 EXPECT_EQ(106, it->id); |
| 3270 } else if (it->name == "ISAC" && it->clockrate == 16000) { |
| 3271 EXPECT_EQ(103, it->id); |
| 3272 } else if (it->name == "ISAC" && it->clockrate == 32000) { |
| 3273 EXPECT_EQ(104, it->id); |
| 3274 } else if (it->name == "G722" && it->clockrate == 8000) { |
| 3275 EXPECT_EQ(9, it->id); |
| 3276 } else if (it->name == "telephone-event") { |
| 3277 EXPECT_EQ(126, it->id); |
| 3278 } else if (it->name == "red") { |
| 3279 EXPECT_EQ(127, it->id); |
| 3280 } else if (it->name == "opus") { |
| 3281 EXPECT_EQ(111, it->id); |
| 3282 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); |
| 3283 EXPECT_EQ("10", it->params.find("minptime")->second); |
| 3284 ASSERT_TRUE(it->params.find("maxptime") != it->params.end()); |
| 3285 EXPECT_EQ("60", it->params.find("maxptime")->second); |
| 3286 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); |
| 3287 EXPECT_EQ("1", it->params.find("useinbandfec")->second); |
| 3288 } |
| 3289 } |
| 3290 |
| 3291 engine.Terminate(); |
| 3292 } |
| 3293 |
| 3294 // Tests that VoE supports at least 32 channels |
| 3295 TEST(WebRtcVoiceEngineTest, Has32Channels) { |
| 3296 cricket::WebRtcVoiceEngine engine; |
| 3297 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
| 3298 |
| 3299 cricket::VoiceMediaChannel* channels[32]; |
| 3300 int num_channels = 0; |
| 3301 |
| 3302 while (num_channels < ARRAY_SIZE(channels)) { |
| 3303 cricket::VoiceMediaChannel* channel = |
| 3304 engine.CreateChannel(cricket::AudioOptions()); |
| 3305 if (!channel) |
| 3306 break; |
| 3307 |
| 3308 channels[num_channels++] = channel; |
| 3309 } |
| 3310 |
| 3311 int expected = ARRAY_SIZE(channels); |
| 3312 EXPECT_EQ(expected, num_channels); |
| 3313 |
| 3314 while (num_channels > 0) { |
| 3315 delete channels[--num_channels]; |
| 3316 } |
| 3317 |
| 3318 engine.Terminate(); |
| 3319 } |
| 3320 |
| 3321 // Test that we set our preferred codecs properly. |
| 3322 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { |
| 3323 cricket::WebRtcVoiceEngine engine; |
| 3324 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
| 3325 cricket::WebRtcVoiceMediaChannel channel(&engine); |
| 3326 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs())); |
| 3327 } |
| 3328 |
| 3329 #ifdef WIN32 |
| 3330 // Test our workarounds to WebRtc VoE' munging of the coinit count |
| 3331 TEST(WebRtcVoiceEngineTest, CoInitialize) { |
| 3332 cricket::WebRtcVoiceEngine* engine = new cricket::WebRtcVoiceEngine(); |
| 3333 |
| 3334 // Initial refcount should be 0. |
| 3335 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 3336 |
| 3337 // Engine should start even with COM already inited. |
| 3338 EXPECT_TRUE(engine->Init(rtc::Thread::Current())); |
| 3339 engine->Terminate(); |
| 3340 EXPECT_TRUE(engine->Init(rtc::Thread::Current())); |
| 3341 engine->Terminate(); |
| 3342 |
| 3343 // Refcount after terminate should be 1 (in reality 3); test if it is nonzero. |
| 3344 EXPECT_EQ(S_FALSE, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 3345 // Decrement refcount to (hopefully) 0. |
| 3346 CoUninitialize(); |
| 3347 CoUninitialize(); |
| 3348 delete engine; |
| 3349 |
| 3350 // Ensure refcount is 0. |
| 3351 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 3352 CoUninitialize(); |
| 3353 } |
| 3354 #endif |
| 3355 |
3182 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { | 3356 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { |
3183 cricket::FakeCall call((webrtc::Call::Config())); | 3357 cricket::FakeCall call((webrtc::Call::Config())); |
3184 const uint32 kAudioSsrc = 123; | 3358 const uint32 kAudioSsrc = 123; |
3185 const std::string kSyncLabel = "AvSyncLabel"; | 3359 const std::string kSyncLabel = "AvSyncLabel"; |
3186 | 3360 |
3187 EXPECT_TRUE(SetupEngine()); | 3361 EXPECT_TRUE(SetupEngine()); |
3188 cricket::WebRtcVoiceMediaChannel* media_channel = | 3362 cricket::WebRtcVoiceMediaChannel* media_channel = |
3189 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); | 3363 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); |
3190 media_channel->SetCall(&call); | 3364 media_channel->SetCall(&call); |
3191 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); | 3365 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3482 // deleting logic, i.e., deleting |send_ch| will reset the associate send | 3656 // deleting logic, i.e., deleting |send_ch| will reset the associate send |
3483 // channel of |recv_ch|.This is not a common case, since, normally, only the | 3657 // channel of |recv_ch|.This is not a common case, since, normally, only the |
3484 // default channel can be associated. However, the default is not deletable. | 3658 // default channel can be associated. However, the default is not deletable. |
3485 // So we force the |recv_ch| to associate with a non-default channel. | 3659 // So we force the |recv_ch| to associate with a non-default channel. |
3486 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch)); | 3660 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch)); |
3487 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch); | 3661 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch); |
3488 | 3662 |
3489 EXPECT_TRUE(channel_->RemoveSendStream(2)); | 3663 EXPECT_TRUE(channel_->RemoveSendStream(2)); |
3490 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1); | 3664 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1); |
3491 } | 3665 } |
3492 | |
3493 // Tests for the actual WebRtc VoE library. | |
3494 | |
3495 TEST(WebRtcVoiceEngineTest, TestDefaultOptionsBeforeInit) { | |
3496 cricket::WebRtcVoiceEngine engine; | |
3497 cricket::AudioOptions options = engine.GetOptions(); | |
3498 // The default options should have at least a few things set. We purposefully | |
3499 // don't check the option values here, though. | |
3500 EXPECT_TRUE(options.echo_cancellation.IsSet()); | |
3501 EXPECT_TRUE(options.auto_gain_control.IsSet()); | |
3502 EXPECT_TRUE(options.noise_suppression.IsSet()); | |
3503 } | |
3504 | |
3505 // Tests that the library initializes and shuts down properly. | |
3506 TEST(WebRtcVoiceEngineTest, StartupShutdown) { | |
3507 cricket::WebRtcVoiceEngine engine; | |
3508 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | |
3509 cricket::VoiceMediaChannel* channel = | |
3510 engine.CreateChannel(cricket::AudioOptions()); | |
3511 EXPECT_TRUE(channel != nullptr); | |
3512 delete channel; | |
3513 engine.Terminate(); | |
3514 | |
3515 // Reinit to catch regression where VoiceEngineObserver reference is lost | |
3516 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | |
3517 engine.Terminate(); | |
3518 } | |
3519 | |
3520 // Tests that the library is configured with the codecs we want. | |
3521 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { | |
3522 cricket::WebRtcVoiceEngine engine; | |
3523 // Check codecs by name. | |
3524 EXPECT_TRUE(engine.FindCodec( | |
3525 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0))); | |
3526 EXPECT_TRUE(engine.FindCodec( | |
3527 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0))); | |
3528 EXPECT_TRUE(engine.FindCodec( | |
3529 cricket::AudioCodec(96, "ISAC", 32000, 0, 1, 0))); | |
3530 // Check that name matching is case-insensitive. | |
3531 EXPECT_TRUE(engine.FindCodec( | |
3532 cricket::AudioCodec(96, "ILBC", 8000, 0, 1, 0))); | |
3533 EXPECT_TRUE(engine.FindCodec( | |
3534 cricket::AudioCodec(96, "iLBC", 8000, 0, 1, 0))); | |
3535 EXPECT_TRUE(engine.FindCodec( | |
3536 cricket::AudioCodec(96, "PCMU", 8000, 0, 1, 0))); | |
3537 EXPECT_TRUE(engine.FindCodec( | |
3538 cricket::AudioCodec(96, "PCMA", 8000, 0, 1, 0))); | |
3539 EXPECT_TRUE(engine.FindCodec( | |
3540 cricket::AudioCodec(96, "G722", 8000, 0, 1, 0))); | |
3541 EXPECT_TRUE(engine.FindCodec( | |
3542 cricket::AudioCodec(96, "red", 8000, 0, 1, 0))); | |
3543 EXPECT_TRUE(engine.FindCodec( | |
3544 cricket::AudioCodec(96, "CN", 32000, 0, 1, 0))); | |
3545 EXPECT_TRUE(engine.FindCodec( | |
3546 cricket::AudioCodec(96, "CN", 16000, 0, 1, 0))); | |
3547 EXPECT_TRUE(engine.FindCodec( | |
3548 cricket::AudioCodec(96, "CN", 8000, 0, 1, 0))); | |
3549 EXPECT_TRUE(engine.FindCodec( | |
3550 cricket::AudioCodec(96, "telephone-event", 8000, 0, 1, 0))); | |
3551 // Check codecs with an id by id. | |
3552 EXPECT_TRUE(engine.FindCodec( | |
3553 cricket::AudioCodec(0, "", 8000, 0, 1, 0))); // PCMU | |
3554 EXPECT_TRUE(engine.FindCodec( | |
3555 cricket::AudioCodec(8, "", 8000, 0, 1, 0))); // PCMA | |
3556 EXPECT_TRUE(engine.FindCodec( | |
3557 cricket::AudioCodec(9, "", 8000, 0, 1, 0))); // G722 | |
3558 EXPECT_TRUE(engine.FindCodec( | |
3559 cricket::AudioCodec(13, "", 8000, 0, 1, 0))); // CN | |
3560 // Check sample/bitrate matching. | |
3561 EXPECT_TRUE(engine.FindCodec( | |
3562 cricket::AudioCodec(0, "PCMU", 8000, 64000, 1, 0))); | |
3563 // Check that bad codecs fail. | |
3564 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(99, "ABCD", 0, 0, 1, 0))); | |
3565 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(88, "", 0, 0, 1, 0))); | |
3566 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 0, 2, 0))); | |
3567 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 5000, 0, 1, 0))); | |
3568 EXPECT_FALSE(engine.FindCodec(cricket::AudioCodec(0, "", 0, 5000, 1, 0))); | |
3569 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. | |
3570 for (std::vector<cricket::AudioCodec>::const_iterator it = | |
3571 engine.codecs().begin(); it != engine.codecs().end(); ++it) { | |
3572 if (it->name == "CN" && it->clockrate == 16000) { | |
3573 EXPECT_EQ(105, it->id); | |
3574 } else if (it->name == "CN" && it->clockrate == 32000) { | |
3575 EXPECT_EQ(106, it->id); | |
3576 } else if (it->name == "ISAC" && it->clockrate == 16000) { | |
3577 EXPECT_EQ(103, it->id); | |
3578 } else if (it->name == "ISAC" && it->clockrate == 32000) { | |
3579 EXPECT_EQ(104, it->id); | |
3580 } else if (it->name == "G722" && it->clockrate == 8000) { | |
3581 EXPECT_EQ(9, it->id); | |
3582 } else if (it->name == "telephone-event") { | |
3583 EXPECT_EQ(126, it->id); | |
3584 } else if (it->name == "red") { | |
3585 EXPECT_EQ(127, it->id); | |
3586 } else if (it->name == "opus") { | |
3587 EXPECT_EQ(111, it->id); | |
3588 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); | |
3589 EXPECT_EQ("10", it->params.find("minptime")->second); | |
3590 ASSERT_TRUE(it->params.find("maxptime") != it->params.end()); | |
3591 EXPECT_EQ("60", it->params.find("maxptime")->second); | |
3592 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); | |
3593 EXPECT_EQ("1", it->params.find("useinbandfec")->second); | |
3594 } | |
3595 } | |
3596 | |
3597 engine.Terminate(); | |
3598 } | |
3599 | |
3600 // Tests that VoE supports at least 32 channels | |
3601 TEST(WebRtcVoiceEngineTest, Has32Channels) { | |
3602 cricket::WebRtcVoiceEngine engine; | |
3603 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | |
3604 | |
3605 cricket::VoiceMediaChannel* channels[32]; | |
3606 int num_channels = 0; | |
3607 | |
3608 while (num_channels < ARRAY_SIZE(channels)) { | |
3609 cricket::VoiceMediaChannel* channel = | |
3610 engine.CreateChannel(cricket::AudioOptions()); | |
3611 if (!channel) | |
3612 break; | |
3613 | |
3614 channels[num_channels++] = channel; | |
3615 } | |
3616 | |
3617 int expected = ARRAY_SIZE(channels); | |
3618 EXPECT_EQ(expected, num_channels); | |
3619 | |
3620 while (num_channels > 0) { | |
3621 delete channels[--num_channels]; | |
3622 } | |
3623 | |
3624 engine.Terminate(); | |
3625 } | |
3626 | |
3627 // Test that we set our preferred codecs properly. | |
3628 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { | |
3629 cricket::WebRtcVoiceEngine engine; | |
3630 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | |
3631 cricket::WebRtcVoiceMediaChannel channel(&engine); | |
3632 EXPECT_TRUE(channel.SetRecvCodecs(engine.codecs())); | |
3633 } | |
OLD | NEW |