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

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

Issue 2686043006: WebRtcVoiceMediaChannel::AddRecvStream: Don't call SetRecPayloadType (Closed)
Patch Set: rebase Created 3 years, 9 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 13 matching lines...) Expand all
24 #include "webrtc/media/engine/fakewebrtcvoiceengine.h" 24 #include "webrtc/media/engine/fakewebrtcvoiceengine.h"
25 #include "webrtc/media/engine/webrtcvoiceengine.h" 25 #include "webrtc/media/engine/webrtcvoiceengine.h"
26 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" 26 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
27 #include "webrtc/modules/audio_device/include/mock_audio_device.h" 27 #include "webrtc/modules/audio_device/include/mock_audio_device.h"
28 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" 28 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h"
29 #include "webrtc/pc/channel.h" 29 #include "webrtc/pc/channel.h"
30 #include "webrtc/test/field_trial.h" 30 #include "webrtc/test/field_trial.h"
31 #include "webrtc/test/gtest.h" 31 #include "webrtc/test/gtest.h"
32 #include "webrtc/voice_engine/transmit_mixer.h" 32 #include "webrtc/voice_engine/transmit_mixer.h"
33 33
34 using testing::ContainerEq;
34 using testing::Return; 35 using testing::Return;
35 using testing::StrictMock; 36 using testing::StrictMock;
36 37
37 namespace { 38 namespace {
38 39
39 constexpr uint32_t kMaxUnsignaledRecvStreams = 1; 40 constexpr uint32_t kMaxUnsignaledRecvStreams = 1;
40 41
41 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); 42 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1);
42 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); 43 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1);
43 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); 44 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2);
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 EXPECT_TRUE(SetupChannel()); 789 EXPECT_TRUE(SetupChannel());
789 cricket::AudioRecvParameters parameters; 790 cricket::AudioRecvParameters parameters;
790 parameters.codecs.push_back(kIsacCodec); 791 parameters.codecs.push_back(kIsacCodec);
791 parameters.codecs.push_back(kPcmuCodec); 792 parameters.codecs.push_back(kPcmuCodec);
792 parameters.codecs.push_back(kTelephoneEventCodec1); 793 parameters.codecs.push_back(kTelephoneEventCodec1);
793 parameters.codecs.push_back(kTelephoneEventCodec2); 794 parameters.codecs.push_back(kTelephoneEventCodec2);
794 parameters.codecs[0].id = 106; // collide with existing CN 32k 795 parameters.codecs[0].id = 106; // collide with existing CN 32k
795 parameters.codecs[2].id = 126; 796 parameters.codecs[2].id = 126;
796 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 797 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
797 EXPECT_TRUE(AddRecvStream(kSsrcX)); 798 EXPECT_TRUE(AddRecvStream(kSsrcX));
798 int channel_num = voe_.GetLastChannel(); 799 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
799 800 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
800 webrtc::CodecInst gcodec; 801 {{0, {"PCMU", 8000, 1}},
801 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 802 {106, {"ISAC", 16000, 1}},
802 gcodec.plfreq = 16000; 803 {126, {"telephone-event", 8000, 1}},
803 gcodec.channels = 1; 804 {107, {"telephone-event", 32000, 1}}})));
804 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
805 EXPECT_EQ(106, gcodec.pltype);
806 EXPECT_STREQ("ISAC", gcodec.plname);
807
808 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event");
809 gcodec.plfreq = 8000;
810 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
811 EXPECT_EQ(126, gcodec.pltype);
812 EXPECT_STREQ("telephone-event", gcodec.plname);
813
814 gcodec.plfreq = 32000;
815 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
816 EXPECT_EQ(107, gcodec.pltype);
817 EXPECT_STREQ("telephone-event", gcodec.plname);
818 } 805 }
819 806
820 // Test that we fail to set an unknown inbound codec. 807 // Test that we fail to set an unknown inbound codec.
821 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { 808 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
822 EXPECT_TRUE(SetupChannel()); 809 EXPECT_TRUE(SetupChannel());
823 cricket::AudioRecvParameters parameters; 810 cricket::AudioRecvParameters parameters;
824 parameters.codecs.push_back(kIsacCodec); 811 parameters.codecs.push_back(kIsacCodec);
825 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1)); 812 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1));
826 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); 813 EXPECT_FALSE(channel_->SetRecvParameters(parameters));
827 } 814 }
(...skipping 10 matching lines...) Expand all
838 825
839 // Test that we can decode OPUS without stereo parameters. 826 // Test that we can decode OPUS without stereo parameters.
840 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { 827 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
841 EXPECT_TRUE(SetupChannel()); 828 EXPECT_TRUE(SetupChannel());
842 cricket::AudioRecvParameters parameters; 829 cricket::AudioRecvParameters parameters;
843 parameters.codecs.push_back(kIsacCodec); 830 parameters.codecs.push_back(kIsacCodec);
844 parameters.codecs.push_back(kPcmuCodec); 831 parameters.codecs.push_back(kPcmuCodec);
845 parameters.codecs.push_back(kOpusCodec); 832 parameters.codecs.push_back(kOpusCodec);
846 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 833 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
847 EXPECT_TRUE(AddRecvStream(kSsrcX)); 834 EXPECT_TRUE(AddRecvStream(kSsrcX));
848 int channel_num = voe_.GetLastChannel(); 835 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
849 webrtc::CodecInst opus; 836 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
850 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 837 {{0, {"PCMU", 8000, 1}},
851 // Even without stereo parameters, recv codecs still specify channels = 2. 838 {103, {"ISAC", 16000, 1}},
852 EXPECT_EQ(2, opus.channels); 839 {111, {"opus", 48000, 2}}})));
853 EXPECT_EQ(111, opus.pltype);
854 EXPECT_STREQ("opus", opus.plname);
855 opus.pltype = 0;
856 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, opus));
857 EXPECT_EQ(111, opus.pltype);
858 } 840 }
859 841
860 // Test that we can decode OPUS with stereo = 0. 842 // Test that we can decode OPUS with stereo = 0.
861 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { 843 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
862 EXPECT_TRUE(SetupChannel()); 844 EXPECT_TRUE(SetupChannel());
863 cricket::AudioRecvParameters parameters; 845 cricket::AudioRecvParameters parameters;
864 parameters.codecs.push_back(kIsacCodec); 846 parameters.codecs.push_back(kIsacCodec);
865 parameters.codecs.push_back(kPcmuCodec); 847 parameters.codecs.push_back(kPcmuCodec);
866 parameters.codecs.push_back(kOpusCodec); 848 parameters.codecs.push_back(kOpusCodec);
867 parameters.codecs[2].params["stereo"] = "0"; 849 parameters.codecs[2].params["stereo"] = "0";
868 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 850 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
869 EXPECT_TRUE(AddRecvStream(kSsrcX)); 851 EXPECT_TRUE(AddRecvStream(kSsrcX));
870 int channel_num2 = voe_.GetLastChannel(); 852 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
871 webrtc::CodecInst opus; 853 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
872 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 854 {{0, {"PCMU", 8000, 1}},
873 // Even when stereo is off, recv codecs still specify channels = 2. 855 {103, {"ISAC", 16000, 1}},
874 EXPECT_EQ(2, opus.channels); 856 {111, {"opus", 48000, 2, {{"stereo", "0"}}}}})));
875 EXPECT_EQ(111, opus.pltype);
876 EXPECT_STREQ("opus", opus.plname);
877 opus.pltype = 0;
878 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
879 EXPECT_EQ(111, opus.pltype);
880 } 857 }
881 858
882 // Test that we can decode OPUS with stereo = 1. 859 // Test that we can decode OPUS with stereo = 1.
883 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) { 860 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
884 EXPECT_TRUE(SetupChannel()); 861 EXPECT_TRUE(SetupChannel());
885 cricket::AudioRecvParameters parameters; 862 cricket::AudioRecvParameters parameters;
886 parameters.codecs.push_back(kIsacCodec); 863 parameters.codecs.push_back(kIsacCodec);
887 parameters.codecs.push_back(kPcmuCodec); 864 parameters.codecs.push_back(kPcmuCodec);
888 parameters.codecs.push_back(kOpusCodec); 865 parameters.codecs.push_back(kOpusCodec);
889 parameters.codecs[2].params["stereo"] = "1"; 866 parameters.codecs[2].params["stereo"] = "1";
890 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 867 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
891 EXPECT_TRUE(AddRecvStream(kSsrcX)); 868 EXPECT_TRUE(AddRecvStream(kSsrcX));
892 int channel_num2 = voe_.GetLastChannel(); 869 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
893 webrtc::CodecInst opus; 870 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
894 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 871 {{0, {"PCMU", 8000, 1}},
895 EXPECT_EQ(2, opus.channels); 872 {103, {"ISAC", 16000, 1}},
896 EXPECT_EQ(111, opus.pltype); 873 {111, {"opus", 48000, 2, {{"stereo", "1"}}}}})));
897 EXPECT_STREQ("opus", opus.plname);
898 opus.pltype = 0;
899 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
900 EXPECT_EQ(111, opus.pltype);
901 } 874 }
902 875
903 // Test that changes to recv codecs are applied to all streams. 876 // Test that changes to recv codecs are applied to all streams.
904 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) { 877 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
905 EXPECT_TRUE(SetupChannel()); 878 EXPECT_TRUE(SetupChannel());
906 cricket::AudioRecvParameters parameters; 879 cricket::AudioRecvParameters parameters;
907 parameters.codecs.push_back(kIsacCodec); 880 parameters.codecs.push_back(kIsacCodec);
908 parameters.codecs.push_back(kPcmuCodec); 881 parameters.codecs.push_back(kPcmuCodec);
909 parameters.codecs.push_back(kTelephoneEventCodec1); 882 parameters.codecs.push_back(kTelephoneEventCodec1);
910 parameters.codecs.push_back(kTelephoneEventCodec2); 883 parameters.codecs.push_back(kTelephoneEventCodec2);
911 parameters.codecs[0].id = 106; // collide with existing CN 32k 884 parameters.codecs[0].id = 106; // collide with existing CN 32k
912 parameters.codecs[2].id = 126; 885 parameters.codecs[2].id = 126;
913 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 886 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
914 EXPECT_TRUE(AddRecvStream(kSsrcX)); 887 for (const auto& ssrc : {kSsrcX, kSsrcY}) {
915 int channel_num2 = voe_.GetLastChannel(); 888 EXPECT_TRUE(AddRecvStream(ssrc));
916 889 EXPECT_THAT(GetRecvStreamConfig(ssrc).decoder_map,
917 webrtc::CodecInst gcodec; 890 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
918 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 891 {{0, {"PCMU", 8000, 1}},
919 gcodec.plfreq = 16000; 892 {106, {"ISAC", 16000, 1}},
920 gcodec.channels = 1; 893 {126, {"telephone-event", 8000, 1}},
921 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 894 {107, {"telephone-event", 32000, 1}}})));
922 EXPECT_EQ(106, gcodec.pltype); 895 }
923 EXPECT_STREQ("ISAC", gcodec.plname);
924
925 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event");
926 gcodec.plfreq = 8000;
927 gcodec.channels = 1;
928 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
929 EXPECT_EQ(126, gcodec.pltype);
930 EXPECT_STREQ("telephone-event", gcodec.plname);
931
932 gcodec.plfreq = 32000;
933 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
934 EXPECT_EQ(107, gcodec.pltype);
935 EXPECT_STREQ("telephone-event", gcodec.plname);
936 } 896 }
937 897
938 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { 898 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
939 EXPECT_TRUE(SetupRecvStream()); 899 EXPECT_TRUE(SetupRecvStream());
940 cricket::AudioRecvParameters parameters; 900 cricket::AudioRecvParameters parameters;
941 parameters.codecs.push_back(kIsacCodec); 901 parameters.codecs.push_back(kIsacCodec);
942 parameters.codecs[0].id = 106; // collide with existing CN 32k 902 parameters.codecs[0].id = 106; // collide with existing CN 32k
943 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 903 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
944 904
945 const auto& dm = GetRecvStreamConfig(kSsrcX).decoder_map; 905 const auto& dm = GetRecvStreamConfig(kSsrcX).decoder_map;
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2954 2914
2955 // Test that after adding a recv stream, we do not decode more codecs than 2915 // Test that after adding a recv stream, we do not decode more codecs than
2956 // those previously passed into SetRecvCodecs. 2916 // those previously passed into SetRecvCodecs.
2957 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { 2917 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2958 EXPECT_TRUE(SetupSendStream()); 2918 EXPECT_TRUE(SetupSendStream());
2959 cricket::AudioRecvParameters parameters; 2919 cricket::AudioRecvParameters parameters;
2960 parameters.codecs.push_back(kIsacCodec); 2920 parameters.codecs.push_back(kIsacCodec);
2961 parameters.codecs.push_back(kPcmuCodec); 2921 parameters.codecs.push_back(kPcmuCodec);
2962 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 2922 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
2963 EXPECT_TRUE(AddRecvStream(kSsrcX)); 2923 EXPECT_TRUE(AddRecvStream(kSsrcX));
2964 int channel_num2 = voe_.GetLastChannel(); 2924 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
2965 webrtc::CodecInst gcodec; 2925 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
2966 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "opus"); 2926 {{0, {"PCMU", 8000, 1}}, {103, {"ISAC", 16000, 1}}})));
2967 gcodec.plfreq = 48000;
2968 gcodec.channels = 2;
2969 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2970 } 2927 }
2971 2928
2972 // Test that we properly clean up any streams that were added, even if 2929 // Test that we properly clean up any streams that were added, even if
2973 // not explicitly removed. 2930 // not explicitly removed.
2974 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { 2931 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2975 EXPECT_TRUE(SetupSendStream()); 2932 EXPECT_TRUE(SetupSendStream());
2976 SetSendParameters(send_parameters_); 2933 SetSendParameters(send_parameters_);
2977 EXPECT_TRUE(AddRecvStream(1)); 2934 EXPECT_TRUE(AddRecvStream(1));
2978 EXPECT_TRUE(AddRecvStream(2)); 2935 EXPECT_TRUE(AddRecvStream(2));
2979 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added 2936 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 // Without this cast, the comparison turned unsigned and, thus, failed for -1. 3793 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3837 const int num_specs = static_cast<int>(specs.size()); 3794 const int num_specs = static_cast<int>(specs.size());
3838 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); 3795 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3839 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); 3796 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3840 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); 3797 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3841 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); 3798 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3842 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); 3799 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3843 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); 3800 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3844 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); 3801 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3845 } 3802 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/modules/audio_coding/acm2/acm_receiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698