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

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

Issue 1917193008: Adding getParameters/setParameters APIs to RtpReceiver. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding isEqual implementation for RTCRtpSender and RTCRtpReceiver Created 4 years, 7 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); 228 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters));
229 229
230 int channel_num = voe_.GetLastChannel(); 230 int channel_num = voe_.GetLastChannel();
231 webrtc::CodecInst temp_codec; 231 webrtc::CodecInst temp_codec;
232 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); 232 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
233 EXPECT_EQ(expected_bitrate, temp_codec.rate); 233 EXPECT_EQ(expected_bitrate, temp_codec.rate);
234 } 234 }
235 235
236 // Sets the per-stream maximum bitrate limit for the specified SSRC. 236 // Sets the per-stream maximum bitrate limit for the specified SSRC.
237 bool SetMaxBitrateForStream(int32_t ssrc, int bitrate) { 237 bool SetMaxBitrateForStream(int32_t ssrc, int bitrate) {
238 webrtc::RtpParameters parameters = channel_->GetRtpParameters(ssrc); 238 webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(ssrc);
239 EXPECT_EQ(1UL, parameters.encodings.size()); 239 EXPECT_EQ(1UL, parameters.encodings.size());
240 240
241 parameters.encodings[0].max_bitrate_bps = bitrate; 241 parameters.encodings[0].max_bitrate_bps = bitrate;
242 return channel_->SetRtpParameters(ssrc, parameters); 242 return channel_->SetRtpSendParameters(ssrc, parameters);
243 } 243 }
244 244
245 bool SetGlobalMaxBitrate(const cricket::AudioCodec& codec, int bitrate) { 245 bool SetGlobalMaxBitrate(const cricket::AudioCodec& codec, int bitrate) {
246 cricket::AudioSendParameters send_parameters; 246 cricket::AudioSendParameters send_parameters;
247 send_parameters.codecs.push_back(codec); 247 send_parameters.codecs.push_back(codec);
248 send_parameters.max_bandwidth_bps = bitrate; 248 send_parameters.max_bandwidth_bps = bitrate;
249 return channel_->SetSendParameters(send_parameters); 249 return channel_->SetSendParameters(send_parameters);
250 } 250 }
251 251
252 int GetCodecBitrate(int32_t ssrc) { 252 int GetCodecBitrate(int32_t ssrc) {
(...skipping 14 matching lines...) Expand all
267 // Clear the bitrate limit from the previous test case. 267 // Clear the bitrate limit from the previous test case.
268 EXPECT_TRUE(SetMaxBitrateForStream(kSsrc1, -1)); 268 EXPECT_TRUE(SetMaxBitrateForStream(kSsrc1, -1));
269 269
270 // Attempt to set the requested bitrate limits. 270 // Attempt to set the requested bitrate limits.
271 EXPECT_TRUE(SetGlobalMaxBitrate(codec, global_max)); 271 EXPECT_TRUE(SetGlobalMaxBitrate(codec, global_max));
272 EXPECT_EQ(expected_result, SetMaxBitrateForStream(kSsrc1, stream_max)); 272 EXPECT_EQ(expected_result, SetMaxBitrateForStream(kSsrc1, stream_max));
273 273
274 // Verify that reading back the parameters gives results 274 // Verify that reading back the parameters gives results
275 // consistent with the Set() result. 275 // consistent with the Set() result.
276 webrtc::RtpParameters resulting_parameters = 276 webrtc::RtpParameters resulting_parameters =
277 channel_->GetRtpParameters(kSsrc1); 277 channel_->GetRtpSendParameters(kSsrc1);
278 EXPECT_EQ(1UL, resulting_parameters.encodings.size()); 278 EXPECT_EQ(1UL, resulting_parameters.encodings.size());
279 EXPECT_EQ(expected_result ? stream_max : -1, 279 EXPECT_EQ(expected_result ? stream_max : -1,
280 resulting_parameters.encodings[0].max_bitrate_bps); 280 resulting_parameters.encodings[0].max_bitrate_bps);
281 281
282 // Verify that the codec settings have the expected bitrate. 282 // Verify that the codec settings have the expected bitrate.
283 EXPECT_EQ(expected_codec_bitrate, GetCodecBitrate(kSsrc1)); 283 EXPECT_EQ(expected_codec_bitrate, GetCodecBitrate(kSsrc1));
284 } 284 }
285 285
286 void TestSetSendRtpHeaderExtensions(const std::string& ext) { 286 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
287 EXPECT_TRUE(SetupSendStream()); 287 EXPECT_TRUE(SetupSendStream());
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 // CBR codecs don't allow per stream maximums to be too low. 860 // CBR codecs don't allow per stream maximums to be too low.
861 SetAndExpectMaxBitrate(kPcmuCodec, 0, 63999, false, 64000); 861 SetAndExpectMaxBitrate(kPcmuCodec, 0, 63999, false, 64000);
862 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 63999, false, 64000); 862 SetAndExpectMaxBitrate(kPcmuCodec, 64001, 63999, false, 64000);
863 } 863 }
864 864
865 // Test that an attempt to set RtpParameters for a stream that does not exist 865 // Test that an attempt to set RtpParameters for a stream that does not exist
866 // fails. 866 // fails.
867 TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) { 867 TEST_F(WebRtcVoiceEngineTestFake, CannotSetMaxBitrateForNonexistentStream) {
868 EXPECT_TRUE(SetupChannel()); 868 EXPECT_TRUE(SetupChannel());
869 webrtc::RtpParameters nonexistent_parameters = 869 webrtc::RtpParameters nonexistent_parameters =
870 channel_->GetRtpParameters(kSsrc1); 870 channel_->GetRtpSendParameters(kSsrc1);
871 EXPECT_EQ(0, nonexistent_parameters.encodings.size()); 871 EXPECT_EQ(0, nonexistent_parameters.encodings.size());
872 872
873 nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters()); 873 nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters());
874 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, nonexistent_parameters)); 874 EXPECT_FALSE(channel_->SetRtpSendParameters(kSsrc1, nonexistent_parameters));
875 } 875 }
876 876
877 TEST_F(WebRtcVoiceEngineTestFake, 877 TEST_F(WebRtcVoiceEngineTestFake,
878 CannotSetRtpParametersWithIncorrectNumberOfEncodings) { 878 CannotSetRtpSendParametersWithIncorrectNumberOfEncodings) {
879 // This test verifies that setting RtpParameters succeeds only if 879 // This test verifies that setting RtpParameters succeeds only if
880 // the structure contains exactly one encoding. 880 // the structure contains exactly one encoding.
881 // TODO(skvlad): Update this test when we start supporting setting parameters 881 // TODO(skvlad): Update this test when we start supporting setting parameters
882 // for each encoding individually. 882 // for each encoding individually.
883 883
884 EXPECT_TRUE(SetupSendStream()); 884 EXPECT_TRUE(SetupSendStream());
885 // Setting RtpParameters with no encoding is expected to fail. 885 // Setting RtpParameters with no encoding is expected to fail.
886 webrtc::RtpParameters parameters; 886 webrtc::RtpParameters parameters;
887 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); 887 EXPECT_FALSE(channel_->SetRtpSendParameters(kSsrc1, parameters));
888 // Setting RtpParameters with exactly one encoding should succeed. 888 // Setting RtpParameters with exactly one encoding should succeed.
889 parameters.encodings.push_back(webrtc::RtpEncodingParameters()); 889 parameters.encodings.push_back(webrtc::RtpEncodingParameters());
890 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, parameters)); 890 EXPECT_TRUE(channel_->SetRtpSendParameters(kSsrc1, parameters));
891 // Two or more encodings should result in failure. 891 // Two or more encodings should result in failure.
892 parameters.encodings.push_back(webrtc::RtpEncodingParameters()); 892 parameters.encodings.push_back(webrtc::RtpEncodingParameters());
893 EXPECT_FALSE(channel_->SetRtpParameters(kSsrc1, parameters)); 893 EXPECT_FALSE(channel_->SetRtpSendParameters(kSsrc1, parameters));
894 } 894 }
895 895
896 // Test that SetRtpParameters configures the correct encoding channel for each 896 // Test that SetRtpSendParameters configures the correct encoding channel for
897 // each
897 // SSRC. 898 // SSRC.
898 TEST_F(WebRtcVoiceEngineTestFake, RtpParametersArePerStream) { 899 TEST_F(WebRtcVoiceEngineTestFake, RtpParametersArePerStream) {
899 SetupForMultiSendStream(); 900 SetupForMultiSendStream();
900 // Create send streams. 901 // Create send streams.
901 for (uint32_t ssrc : kSsrcs4) { 902 for (uint32_t ssrc : kSsrcs4) {
902 EXPECT_TRUE( 903 EXPECT_TRUE(
903 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(ssrc))); 904 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(ssrc)));
904 } 905 }
905 // Configure one stream to be limited by the stream config, another to be 906 // Configure one stream to be limited by the stream config, another to be
906 // limited by the global max, and the third one with no per-stream limit 907 // limited by the global max, and the third one with no per-stream limit
907 // (still subject to the global limit). 908 // (still subject to the global limit).
908 EXPECT_TRUE(SetGlobalMaxBitrate(kOpusCodec, 64000)); 909 EXPECT_TRUE(SetGlobalMaxBitrate(kOpusCodec, 64000));
909 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[0], 48000)); 910 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[0], 48000));
910 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[1], 96000)); 911 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[1], 96000));
911 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[2], -1)); 912 EXPECT_TRUE(SetMaxBitrateForStream(kSsrcs4[2], -1));
912 913
913 EXPECT_EQ(48000, GetCodecBitrate(kSsrcs4[0])); 914 EXPECT_EQ(48000, GetCodecBitrate(kSsrcs4[0]));
914 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[1])); 915 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[1]));
915 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[2])); 916 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[2]));
916 917
917 // Remove the global cap; the streams should switch to their respective 918 // Remove the global cap; the streams should switch to their respective
918 // maximums (or remain unchanged if there was no other limit on them.) 919 // maximums (or remain unchanged if there was no other limit on them.)
919 EXPECT_TRUE(SetGlobalMaxBitrate(kOpusCodec, -1)); 920 EXPECT_TRUE(SetGlobalMaxBitrate(kOpusCodec, -1));
920 EXPECT_EQ(48000, GetCodecBitrate(kSsrcs4[0])); 921 EXPECT_EQ(48000, GetCodecBitrate(kSsrcs4[0]));
921 EXPECT_EQ(96000, GetCodecBitrate(kSsrcs4[1])); 922 EXPECT_EQ(96000, GetCodecBitrate(kSsrcs4[1]));
922 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[2])); 923 EXPECT_EQ(64000, GetCodecBitrate(kSsrcs4[2]));
923 } 924 }
924 925
925 // Test that GetRtpParameters returns the currently configured codecs. 926 // Test that GetRtpSendParameters returns the currently configured codecs.
926 TEST_F(WebRtcVoiceEngineTestFake, GetRtpParametersCodecs) { 927 TEST_F(WebRtcVoiceEngineTestFake, GetRtpSendParametersCodecs) {
927 EXPECT_TRUE(SetupSendStream()); 928 EXPECT_TRUE(SetupSendStream());
928 cricket::AudioSendParameters parameters; 929 cricket::AudioSendParameters parameters;
929 parameters.codecs.push_back(kIsacCodec); 930 parameters.codecs.push_back(kIsacCodec);
930 parameters.codecs.push_back(kPcmuCodec); 931 parameters.codecs.push_back(kPcmuCodec);
931 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 932 EXPECT_TRUE(channel_->SetSendParameters(parameters));
932 933
933 webrtc::RtpParameters rtp_parameters = channel_->GetRtpParameters(kSsrc1); 934 webrtc::RtpParameters rtp_parameters = channel_->GetRtpSendParameters(kSsrc1);
934 ASSERT_EQ(2u, rtp_parameters.codecs.size()); 935 ASSERT_EQ(2u, rtp_parameters.codecs.size());
935 EXPECT_EQ(kIsacCodec.id, rtp_parameters.codecs[0].payload_type); 936 EXPECT_EQ(kIsacCodec.ToCodecParameters(), rtp_parameters.codecs[0]);
936 EXPECT_EQ(kIsacCodec.name, rtp_parameters.codecs[0].mime_type); 937 EXPECT_EQ(kPcmuCodec.ToCodecParameters(), rtp_parameters.codecs[1]);
937 EXPECT_EQ(kIsacCodec.clockrate, rtp_parameters.codecs[0].clock_rate);
938 EXPECT_EQ(kIsacCodec.channels, rtp_parameters.codecs[0].channels);
939 EXPECT_EQ(kPcmuCodec.id, rtp_parameters.codecs[1].payload_type);
940 EXPECT_EQ(kPcmuCodec.name, rtp_parameters.codecs[1].mime_type);
941 EXPECT_EQ(kPcmuCodec.clockrate, rtp_parameters.codecs[1].clock_rate);
942 EXPECT_EQ(kPcmuCodec.channels, rtp_parameters.codecs[1].channels);
943 } 938 }
944 939
945 // Test that if we set/get parameters multiple times, we get the same results. 940 // Test that if we set/get parameters multiple times, we get the same results.
946 TEST_F(WebRtcVoiceEngineTestFake, SetAndGetRtpParameters) { 941 TEST_F(WebRtcVoiceEngineTestFake, SetAndGetRtpSendParameters) {
947 EXPECT_TRUE(SetupSendStream()); 942 EXPECT_TRUE(SetupSendStream());
948 cricket::AudioSendParameters parameters; 943 cricket::AudioSendParameters parameters;
949 parameters.codecs.push_back(kIsacCodec); 944 parameters.codecs.push_back(kIsacCodec);
950 parameters.codecs.push_back(kPcmuCodec); 945 parameters.codecs.push_back(kPcmuCodec);
951 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 946 EXPECT_TRUE(channel_->SetSendParameters(parameters));
952 947
953 webrtc::RtpParameters initial_params = channel_->GetRtpParameters(kSsrc1); 948 webrtc::RtpParameters initial_params = channel_->GetRtpSendParameters(kSsrc1);
954 949
955 // We should be able to set the params we just got. 950 // We should be able to set the params we just got.
956 EXPECT_TRUE(channel_->SetRtpParameters(kSsrc1, initial_params)); 951 EXPECT_TRUE(channel_->SetRtpSendParameters(kSsrc1, initial_params));
957 952
958 // ... And this shouldn't change the params returned by GetRtpParameters. 953 // ... And this shouldn't change the params returned by GetRtpSendParameters.
959 webrtc::RtpParameters new_params = channel_->GetRtpParameters(kSsrc1); 954 webrtc::RtpParameters new_params = channel_->GetRtpSendParameters(kSsrc1);
960 EXPECT_EQ(initial_params, channel_->GetRtpParameters(kSsrc1)); 955 EXPECT_EQ(initial_params, channel_->GetRtpSendParameters(kSsrc1));
956 }
957
958 // Test that GetRtpReceiveParameters returns the currently configured codecs.
959 TEST_F(WebRtcVoiceEngineTestFake, GetRtpReceiveParametersCodecs) {
960 EXPECT_TRUE(SetupRecvStream());
961 cricket::AudioRecvParameters parameters;
962 parameters.codecs.push_back(kIsacCodec);
963 parameters.codecs.push_back(kPcmuCodec);
964 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
965
966 webrtc::RtpParameters rtp_parameters =
967 channel_->GetRtpReceiveParameters(kSsrc1);
968 ASSERT_EQ(2u, rtp_parameters.codecs.size());
969 EXPECT_EQ(kIsacCodec.ToCodecParameters(), rtp_parameters.codecs[0]);
970 EXPECT_EQ(kPcmuCodec.ToCodecParameters(), rtp_parameters.codecs[1]);
971 }
972
973 // Test that if we set/get parameters multiple times, we get the same results.
974 TEST_F(WebRtcVoiceEngineTestFake, SetAndGetRtpReceiveParameters) {
975 EXPECT_TRUE(SetupRecvStream());
976 cricket::AudioRecvParameters parameters;
977 parameters.codecs.push_back(kIsacCodec);
978 parameters.codecs.push_back(kPcmuCodec);
979 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
980
981 webrtc::RtpParameters initial_params =
982 channel_->GetRtpReceiveParameters(kSsrc1);
983
984 // We should be able to set the params we just got.
985 EXPECT_TRUE(channel_->SetRtpReceiveParameters(kSsrc1, initial_params));
986
987 // ... And this shouldn't change the params returned by
988 // GetRtpReceiveParameters.
989 webrtc::RtpParameters new_params = channel_->GetRtpReceiveParameters(kSsrc1);
990 EXPECT_EQ(initial_params, channel_->GetRtpReceiveParameters(kSsrc1));
961 } 991 }
962 992
963 // Test that we apply codecs properly. 993 // Test that we apply codecs properly.
964 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { 994 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
965 EXPECT_TRUE(SetupSendStream()); 995 EXPECT_TRUE(SetupSendStream());
966 cricket::AudioSendParameters parameters; 996 cricket::AudioSendParameters parameters;
967 parameters.codecs.push_back(kIsacCodec); 997 parameters.codecs.push_back(kIsacCodec);
968 parameters.codecs.push_back(kPcmuCodec); 998 parameters.codecs.push_back(kPcmuCodec);
969 parameters.codecs.push_back(kRedCodec); 999 parameters.codecs.push_back(kRedCodec);
970 parameters.codecs[0].id = 96; 1000 parameters.codecs[0].id = 96;
(...skipping 2597 matching lines...) Expand 10 before | Expand all | Expand 10 after
3568 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3598 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3569 cricket::WebRtcVoiceEngine engine(nullptr); 3599 cricket::WebRtcVoiceEngine engine(nullptr);
3570 std::unique_ptr<webrtc::Call> call( 3600 std::unique_ptr<webrtc::Call> call(
3571 webrtc::Call::Create(webrtc::Call::Config())); 3601 webrtc::Call::Create(webrtc::Call::Config()));
3572 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3602 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3573 cricket::AudioOptions(), call.get()); 3603 cricket::AudioOptions(), call.get());
3574 cricket::AudioRecvParameters parameters; 3604 cricket::AudioRecvParameters parameters;
3575 parameters.codecs = engine.codecs(); 3605 parameters.codecs = engine.codecs();
3576 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3606 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3577 } 3607 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698