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

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

Issue 1847353004: Allow applications to control audio send bitrate through RtpParameters. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Redesigned to keep the logic inside WebRtcVoiceMediaChannel Created 4 years, 8 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 parameters.codecs.push_back(codec); 207 parameters.codecs.push_back(codec);
208 parameters.max_bandwidth_bps = max_bitrate; 208 parameters.max_bandwidth_bps = max_bitrate;
209 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); 209 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters));
210 210
211 int channel_num = voe_.GetLastChannel(); 211 int channel_num = voe_.GetLastChannel();
212 webrtc::CodecInst temp_codec; 212 webrtc::CodecInst temp_codec;
213 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); 213 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
214 EXPECT_EQ(expected_bitrate, temp_codec.rate); 214 EXPECT_EQ(expected_bitrate, temp_codec.rate);
215 } 215 }
216 216
217 void SetAndExpectMaxBitrate(const cricket::AudioCodec& codec,
218 int global_max,
219 int stream_max,
220 bool expected_result,
221 int expected_codec_bitrate) {
222 // Clear the bitrate limit from the previous test case.
223 webrtc::RtpParameters rtp_parameters = channel_->GetRtpParameters(kSsrc1);
224 EXPECT_EQ(1UL, rtp_parameters.encodings.size());
225 rtp_parameters.encodings[0].max_bitrate_bps = -1;
226 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, rtp_parameters));
227
228 // Attempt to set the requested bitrate limits.
229 cricket::AudioSendParameters send_parameters;
230 send_parameters.codecs.push_back(codec);
231 send_parameters.max_bandwidth_bps = global_max;
232 EXPECT_TRUE(channel_->SetSendParameters(send_parameters));
233
234 rtp_parameters.encodings[0].max_bitrate_bps = stream_max;
235 EXPECT_EQ(expected_result,
236 channel_->SetRtpParameters(kSsrc1, rtp_parameters));
237
238 // Verify that reading back the parameters gives results
239 // consistent with the Set() result.
240 webrtc::RtpParameters resulting_parameters =
241 channel_->GetRtpParameters(kSsrc1);
242 EXPECT_EQ(1UL, resulting_parameters.encodings.size());
243 EXPECT_EQ(expected_result ? stream_max : -1,
244 resulting_parameters.encodings[0].max_bitrate_bps);
245
246 // Verify that the codec settings have the expected bitrate.
247 int channel_num = voe_.GetLastChannel();
248 webrtc::CodecInst temp_codec;
249 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
250 EXPECT_EQ(expected_codec_bitrate, temp_codec.rate);
251 }
252
217 void TestSetSendRtpHeaderExtensions(const std::string& ext) { 253 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
218 EXPECT_TRUE(SetupSendStream()); 254 EXPECT_TRUE(SetupSendStream());
219 255
220 // Ensure extensions are off by default. 256 // Ensure extensions are off by default.
221 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); 257 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size());
222 258
223 // Ensure unknown extensions won't cause an error. 259 // Ensure unknown extensions won't cause an error.
224 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( 260 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension(
225 "urn:ietf:params:unknownextention", 1)); 261 "urn:ietf:params:unknownextention", 1));
226 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 262 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 801 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
766 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 802 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
767 EXPECT_EQ(64000, codec.rate); 803 EXPECT_EQ(64000, codec.rate);
768 804
769 send_parameters_.max_bandwidth_bps = 128; 805 send_parameters_.max_bandwidth_bps = 128;
770 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); 806 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_));
771 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 807 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
772 EXPECT_EQ(64000, codec.rate); 808 EXPECT_EQ(64000, codec.rate);
773 } 809 }
774 810
775 // Test that we apply codecs properly. 811 // Test that the per-stream bitrate limit and the global
812 // bitrate limit both apply.
813 TEST_F(WebRtcVoiceEngineTestFake, SetMaxBitratePerStream) {
814 EXPECT_TRUE(SetupSendStream());
815
816 // opus, default bitrate == 64000.
817 SetAndExpectMaxBitrate(kOpusCodec, 0, 0, true, 64000);
818 SetAndExpectMaxBitrate(kOpusCodec, 48000, 0, true, 48000);
819 SetAndExpectMaxBitrate(kOpusCodec, 48000, 64000, true, 48000);
820 SetAndExpectMaxBitrate(kOpusCodec, 64000, 48000, true, 48000);
821
822 // CBR codecs allow both maximums to exceed the bitrate.
823 SetAndExpectMaxBitrate(kPcmuCodec, 0, 0, true, 64000);
824 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 0, true, 64000);
825 SetAndExpectMaxBitrate(kPcmuCodec, 0, 64001, true, 64000);
826 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 64001, true, 64000);
827
828 // CBR codecs don't allow per stream maximums to be too low.
829 SetAndExpectMaxBitrate(kPcmuCodec, 0, 63999, false, 64000);
830 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 63999, false, 64000);
831 }
832
833 TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) {
834 EXPECT_TRUE(SetupChannel());
835 webrtc::RtpParameters nonexistent_parameters =
836 channel_->GetRtpParameters(kSsrc1);
837 EXPECT_EQ(0, nonexistent_parameters.encodings.size());
838
839 nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters());
840 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, nonexistent_parameters));
841 }
842
843 TEST_F(WebRtcVoiceEngineTestFake,
844 CannotSetRtpParametersWithIncorrectNumberOfEncodings) {
845 // This test verifies that setting RtpParameters succeeds only if
846 // the structure contains exactly one encoding.
847 // TODO(skvlad): Update this test when we start supporting setting parameters
848 // for each encoding individually.
849
850 EXPECT_TRUE(SetupSendStream());
851 // Setting RtpParameters with no encoding is expected to fail.
852 webrtc::RtpParameters parameters;
853 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters));
854 // Setting RtpParameters with exactly one encoding should succeed.
855 parameters.encodings.push_back(webrtc::RtpEncodingParameters());
856 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, parameters));
857 // Two or more encodings should result in failure.
858 parameters.encodings.push_back(webrtc::RtpEncodingParameters());
859 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters));
860 }
861
862 // that we apply codecs properly.
Taylor Brandstetter 2016/04/05 22:05:07 Add back the word "Test" here
skvlad 2016/04/07 00:50:50 Done.
776 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { 863 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
777 EXPECT_TRUE(SetupSendStream()); 864 EXPECT_TRUE(SetupSendStream());
778 cricket::AudioSendParameters parameters; 865 cricket::AudioSendParameters parameters;
779 parameters.codecs.push_back(kIsacCodec); 866 parameters.codecs.push_back(kIsacCodec);
780 parameters.codecs.push_back(kPcmuCodec); 867 parameters.codecs.push_back(kPcmuCodec);
781 parameters.codecs.push_back(kRedCodec); 868 parameters.codecs.push_back(kRedCodec);
782 parameters.codecs[0].id = 96; 869 parameters.codecs[0].id = 96;
783 parameters.codecs[0].bitrate = 48000; 870 parameters.codecs[0].bitrate = 48000;
784 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 871 EXPECT_TRUE(channel_->SetSendParameters(parameters));
785 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 872 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
(...skipping 2559 matching lines...) Expand 10 before | Expand all | Expand 10 after
3345 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3432 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3346 cricket::WebRtcVoiceEngine engine(nullptr); 3433 cricket::WebRtcVoiceEngine engine(nullptr);
3347 std::unique_ptr<webrtc::Call> call( 3434 std::unique_ptr<webrtc::Call> call(
3348 webrtc::Call::Create(webrtc::Call::Config())); 3435 webrtc::Call::Create(webrtc::Call::Config()));
3349 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3436 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3350 cricket::AudioOptions(), call.get()); 3437 cricket::AudioOptions(), call.get());
3351 cricket::AudioRecvParameters parameters; 3438 cricket::AudioRecvParameters parameters;
3352 parameters.codecs = engine.codecs(); 3439 parameters.codecs = engine.codecs();
3353 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3440 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3354 } 3441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698