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