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; | |
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 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); | 40 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); |
40 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); | 41 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); |
41 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); | 42 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); |
42 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1); | 43 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1); |
43 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1); | 44 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1); |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 EXPECT_TRUE(SetupChannel()); | 759 EXPECT_TRUE(SetupChannel()); |
759 cricket::AudioRecvParameters parameters; | 760 cricket::AudioRecvParameters parameters; |
760 parameters.codecs.push_back(kIsacCodec); | 761 parameters.codecs.push_back(kIsacCodec); |
761 parameters.codecs.push_back(kPcmuCodec); | 762 parameters.codecs.push_back(kPcmuCodec); |
762 parameters.codecs.push_back(kTelephoneEventCodec1); | 763 parameters.codecs.push_back(kTelephoneEventCodec1); |
763 parameters.codecs.push_back(kTelephoneEventCodec2); | 764 parameters.codecs.push_back(kTelephoneEventCodec2); |
764 parameters.codecs[0].id = 106; // collide with existing CN 32k | 765 parameters.codecs[0].id = 106; // collide with existing CN 32k |
765 parameters.codecs[2].id = 126; | 766 parameters.codecs[2].id = 126; |
766 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 767 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
767 EXPECT_TRUE(AddRecvStream(kSsrc1)); | 768 EXPECT_TRUE(AddRecvStream(kSsrc1)); |
768 int channel_num = voe_.GetLastChannel(); | 769 EXPECT_THAT(GetRecvStreamConfig(kSsrc1).decoder_map, |
769 | 770 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>( |
770 webrtc::CodecInst gcodec; | 771 {{0, {"PCMU", 8000, 1}}, |
771 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); | 772 {106, {"ISAC", 16000, 1}}, |
772 gcodec.plfreq = 16000; | 773 {126, {"telephone-event", 8000, 1}}, |
773 gcodec.channels = 1; | 774 {107, {"telephone-event", 32000, 1}}}))); |
774 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); | |
775 EXPECT_EQ(106, gcodec.pltype); | |
776 EXPECT_STREQ("ISAC", gcodec.plname); | |
777 | |
778 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event"); | |
779 gcodec.plfreq = 8000; | |
780 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); | |
781 EXPECT_EQ(126, gcodec.pltype); | |
782 EXPECT_STREQ("telephone-event", gcodec.plname); | |
783 | |
784 gcodec.plfreq = 32000; | |
785 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); | |
786 EXPECT_EQ(107, gcodec.pltype); | |
787 EXPECT_STREQ("telephone-event", gcodec.plname); | |
788 } | 775 } |
789 | 776 |
790 // Test that we fail to set an unknown inbound codec. | 777 // Test that we fail to set an unknown inbound codec. |
791 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { | 778 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { |
792 EXPECT_TRUE(SetupChannel()); | 779 EXPECT_TRUE(SetupChannel()); |
793 cricket::AudioRecvParameters parameters; | 780 cricket::AudioRecvParameters parameters; |
794 parameters.codecs.push_back(kIsacCodec); | 781 parameters.codecs.push_back(kIsacCodec); |
795 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1)); | 782 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1)); |
796 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); | 783 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
797 } | 784 } |
(...skipping 10 matching lines...) Expand all Loading... | |
808 | 795 |
809 // Test that we can decode OPUS without stereo parameters. | 796 // Test that we can decode OPUS without stereo parameters. |
810 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { | 797 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { |
811 EXPECT_TRUE(SetupChannel()); | 798 EXPECT_TRUE(SetupChannel()); |
812 cricket::AudioRecvParameters parameters; | 799 cricket::AudioRecvParameters parameters; |
813 parameters.codecs.push_back(kIsacCodec); | 800 parameters.codecs.push_back(kIsacCodec); |
814 parameters.codecs.push_back(kPcmuCodec); | 801 parameters.codecs.push_back(kPcmuCodec); |
815 parameters.codecs.push_back(kOpusCodec); | 802 parameters.codecs.push_back(kOpusCodec); |
816 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 803 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
817 EXPECT_TRUE(AddRecvStream(kSsrc1)); | 804 EXPECT_TRUE(AddRecvStream(kSsrc1)); |
818 int channel_num = voe_.GetLastChannel(); | 805 EXPECT_THAT(GetRecvStreamConfig(kSsrc1).decoder_map, |
819 webrtc::CodecInst opus; | 806 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>( |
820 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); | 807 {{0, {"PCMU", 8000, 1}}, |
821 // Even without stereo parameters, recv codecs still specify channels = 2. | 808 {103, {"ISAC", 16000, 1}}, |
822 EXPECT_EQ(2, opus.channels); | 809 {111, {"opus", 48000, 2}}}))); |
823 EXPECT_EQ(111, opus.pltype); | |
824 EXPECT_STREQ("opus", opus.plname); | |
825 opus.pltype = 0; | |
826 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, opus)); | |
827 EXPECT_EQ(111, opus.pltype); | |
828 } | 810 } |
829 | 811 |
830 // Test that we can decode OPUS with stereo = 0. | 812 // Test that we can decode OPUS with stereo = 0. |
831 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { | 813 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { |
832 EXPECT_TRUE(SetupChannel()); | 814 EXPECT_TRUE(SetupChannel()); |
833 cricket::AudioRecvParameters parameters; | 815 cricket::AudioRecvParameters parameters; |
834 parameters.codecs.push_back(kIsacCodec); | 816 parameters.codecs.push_back(kIsacCodec); |
835 parameters.codecs.push_back(kPcmuCodec); | 817 parameters.codecs.push_back(kPcmuCodec); |
836 parameters.codecs.push_back(kOpusCodec); | 818 parameters.codecs.push_back(kOpusCodec); |
837 parameters.codecs[2].params["stereo"] = "0"; | 819 parameters.codecs[2].params["stereo"] = "0"; |
838 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 820 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
839 EXPECT_TRUE(AddRecvStream(kSsrc1)); | 821 EXPECT_TRUE(AddRecvStream(kSsrc1)); |
840 int channel_num2 = voe_.GetLastChannel(); | 822 EXPECT_THAT(GetRecvStreamConfig(kSsrc1).decoder_map, |
841 webrtc::CodecInst opus; | 823 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>( |
842 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); | 824 {{0, {"PCMU", 8000, 1}}, |
843 // Even when stereo is off, recv codecs still specify channels = 2. | 825 {103, {"ISAC", 16000, 1}}, |
844 EXPECT_EQ(2, opus.channels); | 826 {111, {"opus", 48000, 2, {{"stereo", "0"}}}}}))); |
845 EXPECT_EQ(111, opus.pltype); | |
846 EXPECT_STREQ("opus", opus.plname); | |
847 opus.pltype = 0; | |
848 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); | |
849 EXPECT_EQ(111, opus.pltype); | |
850 } | 827 } |
851 | 828 |
852 // Test that we can decode OPUS with stereo = 1. | 829 // Test that we can decode OPUS with stereo = 1. |
853 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) { | 830 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) { |
854 EXPECT_TRUE(SetupChannel()); | 831 EXPECT_TRUE(SetupChannel()); |
855 cricket::AudioRecvParameters parameters; | 832 cricket::AudioRecvParameters parameters; |
856 parameters.codecs.push_back(kIsacCodec); | 833 parameters.codecs.push_back(kIsacCodec); |
857 parameters.codecs.push_back(kPcmuCodec); | 834 parameters.codecs.push_back(kPcmuCodec); |
858 parameters.codecs.push_back(kOpusCodec); | 835 parameters.codecs.push_back(kOpusCodec); |
859 parameters.codecs[2].params["stereo"] = "1"; | 836 parameters.codecs[2].params["stereo"] = "1"; |
860 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 837 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
861 EXPECT_TRUE(AddRecvStream(kSsrc1)); | 838 EXPECT_TRUE(AddRecvStream(kSsrc1)); |
862 int channel_num2 = voe_.GetLastChannel(); | 839 EXPECT_THAT(GetRecvStreamConfig(kSsrc1).decoder_map, |
863 webrtc::CodecInst opus; | 840 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>( |
864 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); | 841 {{0, {"PCMU", 8000, 1}}, |
865 EXPECT_EQ(2, opus.channels); | 842 {103, {"ISAC", 16000, 1}}, |
866 EXPECT_EQ(111, opus.pltype); | 843 {111, {"opus", 48000, 2, {{"stereo", "1"}}}}}))); |
867 EXPECT_STREQ("opus", opus.plname); | |
868 opus.pltype = 0; | |
869 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); | |
870 EXPECT_EQ(111, opus.pltype); | |
871 } | 844 } |
872 | 845 |
873 // Test that changes to recv codecs are applied to all streams. | 846 // Test that changes to recv codecs are applied to all streams. |
the sun
2017/02/27 11:48:52
It doesn't look like the test is doing this - it m
kwiberg-webrtc
2017/03/14 14:22:37
Done.
| |
874 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) { | 847 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) { |
875 EXPECT_TRUE(SetupChannel()); | 848 EXPECT_TRUE(SetupChannel()); |
876 cricket::AudioRecvParameters parameters; | 849 cricket::AudioRecvParameters parameters; |
877 parameters.codecs.push_back(kIsacCodec); | 850 parameters.codecs.push_back(kIsacCodec); |
878 parameters.codecs.push_back(kPcmuCodec); | 851 parameters.codecs.push_back(kPcmuCodec); |
879 parameters.codecs.push_back(kTelephoneEventCodec1); | 852 parameters.codecs.push_back(kTelephoneEventCodec1); |
880 parameters.codecs.push_back(kTelephoneEventCodec2); | 853 parameters.codecs.push_back(kTelephoneEventCodec2); |
881 parameters.codecs[0].id = 106; // collide with existing CN 32k | 854 parameters.codecs[0].id = 106; // collide with existing CN 32k |
882 parameters.codecs[2].id = 126; | 855 parameters.codecs[2].id = 126; |
883 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 856 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
884 EXPECT_TRUE(AddRecvStream(kSsrc1)); | 857 EXPECT_TRUE(AddRecvStream(kSsrc1)); |
885 int channel_num2 = voe_.GetLastChannel(); | 858 EXPECT_THAT(GetRecvStreamConfig(kSsrc1).decoder_map, |
886 | 859 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>( |
887 webrtc::CodecInst gcodec; | 860 {{0, {"PCMU", 8000, 1}}, |
888 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); | 861 {106, {"ISAC", 16000, 1}}, |
889 gcodec.plfreq = 16000; | 862 {126, {"telephone-event", 8000, 1}}, |
890 gcodec.channels = 1; | 863 {107, {"telephone-event", 32000, 1}}}))); |
891 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); | |
892 EXPECT_EQ(106, gcodec.pltype); | |
893 EXPECT_STREQ("ISAC", gcodec.plname); | |
894 | |
895 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event"); | |
896 gcodec.plfreq = 8000; | |
897 gcodec.channels = 1; | |
898 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); | |
899 EXPECT_EQ(126, gcodec.pltype); | |
900 EXPECT_STREQ("telephone-event", gcodec.plname); | |
901 | |
902 gcodec.plfreq = 32000; | |
903 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); | |
904 EXPECT_EQ(107, gcodec.pltype); | |
905 EXPECT_STREQ("telephone-event", gcodec.plname); | |
906 } | 864 } |
907 | 865 |
908 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { | 866 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { |
909 EXPECT_TRUE(SetupRecvStream()); | 867 EXPECT_TRUE(SetupRecvStream()); |
910 cricket::AudioRecvParameters parameters; | 868 cricket::AudioRecvParameters parameters; |
911 parameters.codecs.push_back(kIsacCodec); | 869 parameters.codecs.push_back(kIsacCodec); |
912 parameters.codecs[0].id = 106; // collide with existing CN 32k | 870 parameters.codecs[0].id = 106; // collide with existing CN 32k |
913 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 871 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
914 | 872 |
915 const auto& dm = GetRecvStreamConfig(kSsrc1).decoder_map; | 873 const auto& dm = GetRecvStreamConfig(kSsrc1).decoder_map; |
(...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2909 | 2867 |
2910 // Test that after adding a recv stream, we do not decode more codecs than | 2868 // Test that after adding a recv stream, we do not decode more codecs than |
2911 // those previously passed into SetRecvCodecs. | 2869 // those previously passed into SetRecvCodecs. |
2912 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { | 2870 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { |
2913 EXPECT_TRUE(SetupSendStream()); | 2871 EXPECT_TRUE(SetupSendStream()); |
2914 cricket::AudioRecvParameters parameters; | 2872 cricket::AudioRecvParameters parameters; |
2915 parameters.codecs.push_back(kIsacCodec); | 2873 parameters.codecs.push_back(kIsacCodec); |
2916 parameters.codecs.push_back(kPcmuCodec); | 2874 parameters.codecs.push_back(kPcmuCodec); |
2917 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); | 2875 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
2918 EXPECT_TRUE(AddRecvStream(kSsrc1)); | 2876 EXPECT_TRUE(AddRecvStream(kSsrc1)); |
2919 int channel_num2 = voe_.GetLastChannel(); | 2877 EXPECT_THAT(GetRecvStreamConfig(kSsrc1).decoder_map, |
2920 webrtc::CodecInst gcodec; | 2878 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>( |
2921 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "opus"); | 2879 {{0, {"PCMU", 8000, 1}}, {103, {"ISAC", 16000, 1}}}))); |
2922 gcodec.plfreq = 48000; | |
2923 gcodec.channels = 2; | |
2924 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec)); | |
2925 } | 2880 } |
2926 | 2881 |
2927 // Test that we properly clean up any streams that were added, even if | 2882 // Test that we properly clean up any streams that were added, even if |
2928 // not explicitly removed. | 2883 // not explicitly removed. |
2929 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { | 2884 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { |
2930 EXPECT_TRUE(SetupSendStream()); | 2885 EXPECT_TRUE(SetupSendStream()); |
2931 SetSendParameters(send_parameters_); | 2886 SetSendParameters(send_parameters_); |
2932 EXPECT_TRUE(AddRecvStream(1)); | 2887 EXPECT_TRUE(AddRecvStream(1)); |
2933 EXPECT_TRUE(AddRecvStream(2)); | 2888 EXPECT_TRUE(AddRecvStream(2)); |
2934 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added | 2889 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3727 // Without this cast, the comparison turned unsigned and, thus, failed for -1. | 3682 // Without this cast, the comparison turned unsigned and, thus, failed for -1. |
3728 const int num_specs = static_cast<int>(specs.size()); | 3683 const int num_specs = static_cast<int>(specs.size()); |
3729 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); | 3684 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); |
3730 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); | 3685 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); |
3731 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); | 3686 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); |
3732 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); | 3687 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); |
3733 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); | 3688 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); |
3734 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); | 3689 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); |
3735 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); | 3690 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); |
3736 } | 3691 } |
OLD | NEW |