Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: talk/media/webrtc/webrtcvoiceengine_unittest.cc

Issue 1604563002: Add send-side BWE to WebRtcVoiceEngine under a finch experiment. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
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 #include "webrtc/base/arraysize.h" 28 #include "webrtc/base/arraysize.h"
29 #include "webrtc/base/byteorder.h" 29 #include "webrtc/base/byteorder.h"
30 #include "webrtc/base/gunit.h" 30 #include "webrtc/base/gunit.h"
31 #include "webrtc/call.h" 31 #include "webrtc/call.h"
32 #include "webrtc/p2p/base/faketransportcontroller.h"
33 #include "webrtc/test/field_trial.h"
32 #include "talk/media/base/constants.h" 34 #include "talk/media/base/constants.h"
33 #include "talk/media/base/fakemediaengine.h" 35 #include "talk/media/base/fakemediaengine.h"
34 #include "talk/media/base/fakenetworkinterface.h" 36 #include "talk/media/base/fakenetworkinterface.h"
35 #include "talk/media/base/fakertp.h" 37 #include "talk/media/base/fakertp.h"
36 #include "talk/media/webrtc/fakewebrtccall.h" 38 #include "talk/media/webrtc/fakewebrtccall.h"
37 #include "talk/media/webrtc/fakewebrtcvoiceengine.h" 39 #include "talk/media/webrtc/fakewebrtcvoiceengine.h"
38 #include "talk/media/webrtc/webrtcvoiceengine.h" 40 #include "talk/media/webrtc/webrtcvoiceengine.h"
39 #include "webrtc/p2p/base/faketransportcontroller.h"
40 #include "talk/session/media/channel.h" 41 #include "talk/session/media/channel.h"
41 42
42 using cricket::kRtpAudioLevelHeaderExtension; 43 using cricket::kRtpAudioLevelHeaderExtension;
43 using cricket::kRtpAbsoluteSenderTimeHeaderExtension; 44 using cricket::kRtpAbsoluteSenderTimeHeaderExtension;
44 45
45 namespace { 46 namespace {
46 47
47 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0); 48 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1, 0);
48 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0); 49 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1, 0);
49 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0); 50 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2, 0);
(...skipping 17 matching lines...) Expand all
67 engine, // hw 68 engine, // hw
68 engine, // network 69 engine, // network
69 engine, // rtp 70 engine, // rtp
70 engine) { // volume 71 engine) { // volume
71 } 72 }
72 }; 73 };
73 } // namespace 74 } // namespace
74 75
75 class WebRtcVoiceEngineTestFake : public testing::Test { 76 class WebRtcVoiceEngineTestFake : public testing::Test {
76 public: 77 public:
77 WebRtcVoiceEngineTestFake() 78 explicit WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {}
79
80 explicit WebRtcVoiceEngineTestFake(const char* field_trials)
78 : call_(webrtc::Call::Config()), 81 : call_(webrtc::Call::Config()),
79 engine_(new FakeVoEWrapper(&voe_)), 82 engine_(new FakeVoEWrapper(&voe_)),
80 channel_(nullptr) { 83 channel_(nullptr),
84 override_field_trials_(field_trials) {
81 send_parameters_.codecs.push_back(kPcmuCodec); 85 send_parameters_.codecs.push_back(kPcmuCodec);
82 recv_parameters_.codecs.push_back(kPcmuCodec); 86 recv_parameters_.codecs.push_back(kPcmuCodec);
83 } 87 }
84 bool SetupEngine() { 88 bool SetupEngine() {
85 if (!engine_.Init(rtc::Thread::Current())) { 89 if (!engine_.Init(rtc::Thread::Current())) {
86 return false; 90 return false;
87 } 91 }
88 channel_ = engine_.CreateChannel(&call_, cricket::AudioOptions()); 92 channel_ = engine_.CreateChannel(&call_, cricket::AudioOptions());
89 return (channel_ != nullptr); 93 return (channel_ != nullptr);
90 } 94 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT_EQ(ext, GetRecvStreamConfig(kSsrc2).rtp.extensions[0].name); 278 EXPECT_EQ(ext, GetRecvStreamConfig(kSsrc2).rtp.extensions[0].name);
275 EXPECT_EQ(id, GetRecvStreamConfig(kSsrc2).rtp.extensions[0].id); 279 EXPECT_EQ(id, GetRecvStreamConfig(kSsrc2).rtp.extensions[0].id);
276 280
277 // Ensure all extensions go back off with an empty list. 281 // Ensure all extensions go back off with an empty list.
278 recv_parameters_.extensions.clear(); 282 recv_parameters_.extensions.clear();
279 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); 283 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
280 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc1).rtp.extensions.size()); 284 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc1).rtp.extensions.size());
281 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc2).rtp.extensions.size()); 285 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc2).rtp.extensions.size());
282 } 286 }
283 287
288 void TestExtensionFilter(const std::vector<std::string>& extensions,
289 const std::string& expected_extension) {
290 EXPECT_TRUE(SetupEngineWithSendStream());
291 cricket::AudioSendParameters parameters = send_parameters_;
292 int expected_id = -1;
293 int id = 1;
294 for (const std::string& extension : extensions) {
295 if (extension == expected_extension)
296 expected_id = id;
297 parameters.extensions.push_back(
298 cricket::RtpHeaderExtension(extension, id++));
299 }
300 EXPECT_TRUE(channel_->SetSendParameters(parameters));
301 const cricket::FakeAudioSendStream send_stream = GetSendStream(kSsrc1);
302
303 // Verify that only one of them has been set, and that it is the one with
304 // highest priority (transport sequence number).
305 ASSERT_EQ(1u, send_stream.GetConfig().rtp.extensions.size());
306 EXPECT_EQ(expected_id, send_stream.GetConfig().rtp.extensions[0].id);
307 EXPECT_EQ(expected_extension,
308 send_stream.GetConfig().rtp.extensions[0].name);
309 }
310
284 webrtc::AudioSendStream::Stats GetAudioSendStreamStats() const { 311 webrtc::AudioSendStream::Stats GetAudioSendStreamStats() const {
285 webrtc::AudioSendStream::Stats stats; 312 webrtc::AudioSendStream::Stats stats;
286 stats.local_ssrc = 12; 313 stats.local_ssrc = 12;
287 stats.bytes_sent = 345; 314 stats.bytes_sent = 345;
288 stats.packets_sent = 678; 315 stats.packets_sent = 678;
289 stats.packets_lost = 9012; 316 stats.packets_lost = 9012;
290 stats.fraction_lost = 34.56f; 317 stats.fraction_lost = 34.56f;
291 stats.codec_name = "codec_name_send"; 318 stats.codec_name = "codec_name_send";
292 stats.ext_seqnum = 789; 319 stats.ext_seqnum = 789;
293 stats.jitter_ms = 12; 320 stats.jitter_ms = 12;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms); 419 EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms);
393 } 420 }
394 421
395 protected: 422 protected:
396 cricket::FakeCall call_; 423 cricket::FakeCall call_;
397 cricket::FakeWebRtcVoiceEngine voe_; 424 cricket::FakeWebRtcVoiceEngine voe_;
398 cricket::WebRtcVoiceEngine engine_; 425 cricket::WebRtcVoiceEngine engine_;
399 cricket::VoiceMediaChannel* channel_; 426 cricket::VoiceMediaChannel* channel_;
400 cricket::AudioSendParameters send_parameters_; 427 cricket::AudioSendParameters send_parameters_;
401 cricket::AudioRecvParameters recv_parameters_; 428 cricket::AudioRecvParameters recv_parameters_;
429
430 private:
431 webrtc::test::ScopedFieldTrials override_field_trials_;
402 }; 432 };
403 433
404 // Tests that our stub library "works". 434 // Tests that our stub library "works".
405 TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) { 435 TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
406 EXPECT_FALSE(voe_.IsInited()); 436 EXPECT_FALSE(voe_.IsInited());
407 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 437 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
408 EXPECT_TRUE(voe_.IsInited()); 438 EXPECT_TRUE(voe_.IsInited());
409 engine_.Terminate(); 439 engine_.Terminate();
410 EXPECT_FALSE(voe_.IsInited()); 440 EXPECT_FALSE(voe_.IsInited());
411 } 441 }
(...skipping 14 matching lines...) Expand all
426 EXPECT_EQ(48000, codecs[0].clockrate); 456 EXPECT_EQ(48000, codecs[0].clockrate);
427 EXPECT_EQ(2, codecs[0].channels); 457 EXPECT_EQ(2, codecs[0].channels);
428 EXPECT_EQ(64000, codecs[0].bitrate); 458 EXPECT_EQ(64000, codecs[0].bitrate);
429 int pref = codecs[0].preference; 459 int pref = codecs[0].preference;
430 for (size_t i = 1; i < codecs.size(); ++i) { 460 for (size_t i = 1; i < codecs.size(); ++i) {
431 EXPECT_GT(pref, codecs[i].preference); 461 EXPECT_GT(pref, codecs[i].preference);
432 pref = codecs[i].preference; 462 pref = codecs[i].preference;
433 } 463 }
434 } 464 }
435 465
466 TEST_F(WebRtcVoiceEngineTestFake, OpusSupportsTransportCc) {
467 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
468 bool opus_found = false;
469 for (cricket::AudioCodec codec : codecs) {
470 if (codec.name == "opus") {
471 EXPECT_TRUE(HasTransportCc(codec));
472 opus_found = true;
473 }
474 }
475 EXPECT_TRUE(opus_found);
476 }
477
436 // Tests that we can find codecs by name or id, and that we interpret the 478 // Tests that we can find codecs by name or id, and that we interpret the
437 // clockrate and bitrate fields properly. 479 // clockrate and bitrate fields properly.
438 TEST_F(WebRtcVoiceEngineTestFake, FindCodec) { 480 TEST_F(WebRtcVoiceEngineTestFake, FindCodec) {
439 cricket::AudioCodec codec; 481 cricket::AudioCodec codec;
440 webrtc::CodecInst codec_inst; 482 webrtc::CodecInst codec_inst;
441 // Find PCMU with explicit clockrate and bitrate. 483 // Find PCMU with explicit clockrate and bitrate.
442 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(kPcmuCodec, &codec_inst)); 484 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(kPcmuCodec, &codec_inst));
443 // Find ISAC with explicit clockrate and 0 bitrate. 485 // Find ISAC with explicit clockrate and 0 bitrate.
444 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(kIsacCodec, &codec_inst)); 486 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(kIsacCodec, &codec_inst));
445 // Find telephone-event with explicit clockrate and 0 bitrate. 487 // Find telephone-event with explicit clockrate and 0 bitrate.
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 int channel_num = voe_.GetLastChannel(); 1311 int channel_num = voe_.GetLastChannel();
1270 cricket::AudioSendParameters parameters; 1312 cricket::AudioSendParameters parameters;
1271 parameters.codecs.push_back(kOpusCodec); 1313 parameters.codecs.push_back(kOpusCodec);
1272 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1314 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1273 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1315 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1274 parameters.codecs[0].params["useinbandfec"] = "1"; 1316 parameters.codecs[0].params["useinbandfec"] = "1";
1275 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1317 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1276 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1318 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1277 } 1319 }
1278 1320
1321 TEST_F(WebRtcVoiceEngineTestFake, TransportCcCanBeEnabledAndDisabled) {
1322 EXPECT_TRUE(SetupEngine());
1323 cricket::AudioSendParameters send_parameters;
1324 send_parameters.codecs.push_back(kOpusCodec);
1325 EXPECT_TRUE(send_parameters.codecs[0].feedback_params.params().empty());
1326 EXPECT_TRUE(channel_->SetSendParameters(send_parameters));
1327
1328 cricket::AudioRecvParameters recv_parameters;
1329 recv_parameters.codecs.push_back(kOpusCodec);
1330 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters));
1331 EXPECT_TRUE(
1332 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1)));
1333 ASSERT_TRUE(call_.GetAudioReceiveStream(kSsrc1) != nullptr);
1334 EXPECT_FALSE(
1335 call_.GetAudioReceiveStream(kSsrc1)->GetConfig().rtp.transport_cc);
1336
1337 send_parameters.codecs = engine_.codecs();
1338 EXPECT_TRUE(channel_->SetSendParameters(send_parameters));
1339 ASSERT_TRUE(call_.GetAudioReceiveStream(kSsrc1) != nullptr);
1340 EXPECT_TRUE(
1341 call_.GetAudioReceiveStream(kSsrc1)->GetConfig().rtp.transport_cc);
1342 }
1343
1279 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode. 1344 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1280 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) { 1345 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1281 EXPECT_TRUE(SetupEngineWithSendStream()); 1346 EXPECT_TRUE(SetupEngineWithSendStream());
1282 int channel_num = voe_.GetLastChannel(); 1347 int channel_num = voe_.GetLastChannel();
1283 cricket::AudioSendParameters parameters; 1348 cricket::AudioSendParameters parameters;
1284 parameters.codecs.push_back(kOpusCodec); 1349 parameters.codecs.push_back(kOpusCodec);
1285 parameters.codecs[0].bitrate = 0; 1350 parameters.codecs[0].bitrate = 0;
1286 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); 1351 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1287 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1352 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1288 EXPECT_EQ(cricket::kOpusBandwidthNb, 1353 EXPECT_EQ(cricket::kOpusBandwidthNb,
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 parameters.codecs[0].params[""] = "97/97"; 1976 parameters.codecs[0].params[""] = "97/97";
1912 parameters.codecs[1].id = 96; 1977 parameters.codecs[1].id = 96;
1913 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1978 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1914 webrtc::CodecInst gcodec; 1979 webrtc::CodecInst gcodec;
1915 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1980 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1916 EXPECT_EQ(96, gcodec.pltype); 1981 EXPECT_EQ(96, gcodec.pltype);
1917 EXPECT_STREQ("ISAC", gcodec.plname); 1982 EXPECT_STREQ("ISAC", gcodec.plname);
1918 EXPECT_FALSE(voe_.GetRED(channel_num)); 1983 EXPECT_FALSE(voe_.GetRED(channel_num));
1919 } 1984 }
1920 1985
1986 class WebRtcVoiceEngineWithSendSideBweTest : public WebRtcVoiceEngineTestFake {
1987 public:
1988 WebRtcVoiceEngineWithSendSideBweTest()
1989 : WebRtcVoiceEngineTestFake("WebRTC-Audio-SendSideBwe/Enabled/") {}
1990 };
1991
1992 TEST_F(WebRtcVoiceEngineWithSendSideBweTest,
1993 SupportsTransportSequenceNumberHeaderExtension) {
1994 cricket::RtpCapabilities capabilities = engine_.GetCapabilities();
1995 ASSERT_FALSE(capabilities.header_extensions.empty());
1996 for (const cricket::RtpHeaderExtension& extension :
1997 capabilities.header_extensions) {
1998 if (extension.uri == cricket::kRtpTransportSequenceNumberHeaderExtension) {
1999 EXPECT_EQ(cricket::kRtpTransportSequenceNumberHeaderExtensionDefaultId,
2000 extension.id);
2001 return;
2002 }
2003 }
2004 FAIL() << "Transport sequence number extension not in header-extension list.";
2005 }
2006
2007 TEST_F(WebRtcVoiceEngineWithSendSideBweTest,
2008 FiltersExtensionsPicksTransportSeqNum) {
2009 // Enable three redundant extensions.
2010 std::vector<std::string> extensions;
2011 extensions.push_back(cricket::kRtpAbsoluteSenderTimeHeaderExtension);
2012 extensions.push_back(cricket::kRtpTransportSequenceNumberHeaderExtension);
2013 TestExtensionFilter(extensions,
2014 cricket::kRtpTransportSequenceNumberHeaderExtension);
2015 }
2016
1921 // Test support for audio level header extension. 2017 // Test support for audio level header extension.
1922 TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) { 2018 TEST_F(WebRtcVoiceEngineTestFake, SendAudioLevelHeaderExtensions) {
1923 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension); 2019 TestSetSendRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1924 } 2020 }
1925 TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) { 2021 TEST_F(WebRtcVoiceEngineTestFake, RecvAudioLevelHeaderExtensions) {
1926 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension); 2022 TestSetRecvRtpHeaderExtensions(kRtpAudioLevelHeaderExtension);
1927 } 2023 }
1928 2024
1929 // Test support for absolute send time header extension. 2025 // Test support for absolute send time header extension.
1930 TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) { 2026 TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
3238 cricket::WebRtcVoiceEngine engine; 3334 cricket::WebRtcVoiceEngine engine;
3239 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3335 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3240 rtc::scoped_ptr<webrtc::Call> call( 3336 rtc::scoped_ptr<webrtc::Call> call(
3241 webrtc::Call::Create(webrtc::Call::Config())); 3337 webrtc::Call::Create(webrtc::Call::Config()));
3242 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), 3338 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(),
3243 call.get()); 3339 call.get());
3244 cricket::AudioRecvParameters parameters; 3340 cricket::AudioRecvParameters parameters;
3245 parameters.codecs = engine.codecs(); 3341 parameters.codecs = engine.codecs();
3246 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3342 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3247 } 3343 }
OLDNEW
« talk/media/webrtc/webrtcvoiceengine.cc ('K') | « talk/media/webrtc/webrtcvoiceengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698