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

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

Issue 2669583002: Added a flag to AudioCodecSpec to indicate adaptive bitrate support. (Closed)
Patch Set: int -> size_t to avoid unsigned/signed mismatch warnings on Windows. Created 3 years, 10 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 * 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 3662 matching lines...) Expand 10 before | Expand all | Expand 10 after
3673 nullptr, webrtc::CreateBuiltinAudioDecoderFactory(), nullptr); 3673 nullptr, webrtc::CreateBuiltinAudioDecoderFactory(), nullptr);
3674 webrtc::RtcEventLogNullImpl event_log; 3674 webrtc::RtcEventLogNullImpl event_log;
3675 std::unique_ptr<webrtc::Call> call( 3675 std::unique_ptr<webrtc::Call> call(
3676 webrtc::Call::Create(webrtc::Call::Config(&event_log))); 3676 webrtc::Call::Create(webrtc::Call::Config(&event_log)));
3677 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3677 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3678 cricket::AudioOptions(), call.get()); 3678 cricket::AudioOptions(), call.get());
3679 cricket::AudioRecvParameters parameters; 3679 cricket::AudioRecvParameters parameters;
3680 parameters.codecs = engine.recv_codecs(); 3680 parameters.codecs = engine.recv_codecs();
3681 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3681 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3682 } 3682 }
3683
3684 TEST(WebRtcVoiceEngineTest, CollectRecvCodecs) {
3685 std::vector<webrtc::AudioCodecSpec> specs;
3686 webrtc::AudioCodecSpec spec1({"codec1", 48000, 2, {{"param1", "value1"}}});
3687 spec1.allow_comfort_noise = false;
3688 spec1.supports_network_adaption = true;
3689 specs.push_back(spec1);
3690 webrtc::AudioCodecSpec spec2({"codec2", 32000, 1});
3691 spec2.allow_comfort_noise = false;
3692 specs.push_back(spec2);
3693 specs.push_back(webrtc::AudioCodecSpec({"codec3", 16000, 1,
3694 {{"param1", "value1b"},
3695 {"param2", "value2"}}}));
3696 specs.push_back(webrtc::AudioCodecSpec({"codec4", 8000, 1}));
3697 specs.push_back(webrtc::AudioCodecSpec({"codec5", 8000, 2}));
3698
3699 rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> mock_factory =
3700 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>;
3701 EXPECT_CALL(*mock_factory.get(), GetSupportedDecoders())
3702 .WillOnce(Return(specs));
3703
3704 cricket::WebRtcVoiceEngine engine(nullptr, mock_factory, nullptr);
3705 auto codecs = engine.recv_codecs();
3706 EXPECT_EQ(11, codecs.size());
3707
3708 // Rather than just ASSERTing that there are enough codecs, ensure that we can
3709 // check the actual values safely, to provide better test results.
3710 auto get_codec =
3711 [&codecs](size_t index) -> const cricket::AudioCodec& {
3712 static const cricket::AudioCodec missing_codec(0, "<missing>", 0, 0, 0);
3713 if (codecs.size() > index)
3714 return codecs[index];
3715 return missing_codec;
3716 };
3717
3718 // Ensure the general codecs are generated first and in order.
3719 for (size_t i = 0; i != specs.size(); ++i) {
3720 EXPECT_EQ(specs[i].format.name, get_codec(i).name);
3721 EXPECT_EQ(specs[i].format.clockrate_hz, get_codec(i).clockrate);
3722 EXPECT_EQ(specs[i].format.num_channels, get_codec(i).channels);
3723 EXPECT_EQ(specs[i].format.parameters, get_codec(i).params);
3724 }
3725
3726 // Find the index of a codec, or -1 if not found, so that we can easily check
3727 // supplementary codecs are orderd after the general codecs.
ossu 2017/02/09 19:59:58 There's also a spelling error here.
3728 auto find_codec =
3729 [&codecs](const webrtc::SdpAudioFormat& format) -> int {
3730 for (size_t i = 0; i != codecs.size(); ++i) {
3731 const cricket::AudioCodec& codec = codecs[i];
3732 if (STR_CASE_CMP(codec.name.c_str(), format.name.c_str()) == 0 &&
3733 codec.clockrate == format.clockrate_hz &&
3734 codec.channels == format.num_channels) {
3735 return static_cast<int>(i);
kwiberg-webrtc 2017/02/09 05:26:44 This is a test, so checked_cast? Not that it's lik
ossu 2017/02/09 19:59:58 Hmm, now that you mention it, it probably should b
3736 }
3737 }
3738 return -1;
3739 };
3740
3741 // Ensure all supplementary codecs are generated last. Their internal ordering
3742 // is not important.
3743 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3744 const int num_specs = static_cast<int>(specs.size());
3745 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3746 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3747 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3748 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3749 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3750 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3751 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3752 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/modules/audio_coding/codecs/audio_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698