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

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

Issue 2686043006: WebRtcVoiceMediaChannel::AddRecvStream: Don't call SetRecPayloadType (Closed)
Patch Set: Discard packets when updating payload type map 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 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 EXPECT_TRUE(SetupChannel()); 762 EXPECT_TRUE(SetupChannel());
762 cricket::AudioRecvParameters parameters; 763 cricket::AudioRecvParameters parameters;
763 parameters.codecs.push_back(kIsacCodec); 764 parameters.codecs.push_back(kIsacCodec);
764 parameters.codecs.push_back(kPcmuCodec); 765 parameters.codecs.push_back(kPcmuCodec);
765 parameters.codecs.push_back(kTelephoneEventCodec1); 766 parameters.codecs.push_back(kTelephoneEventCodec1);
766 parameters.codecs.push_back(kTelephoneEventCodec2); 767 parameters.codecs.push_back(kTelephoneEventCodec2);
767 parameters.codecs[0].id = 106; // collide with existing CN 32k 768 parameters.codecs[0].id = 106; // collide with existing CN 32k
768 parameters.codecs[2].id = 126; 769 parameters.codecs[2].id = 126;
769 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 770 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
770 EXPECT_TRUE(AddRecvStream(kSsrcX)); 771 EXPECT_TRUE(AddRecvStream(kSsrcX));
771 int channel_num = voe_.GetLastChannel(); 772 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
772 773 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
773 webrtc::CodecInst gcodec; 774 {{0, {"PCMU", 8000, 1}},
774 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 775 {106, {"ISAC", 16000, 1}},
775 gcodec.plfreq = 16000; 776 {126, {"telephone-event", 8000, 1}},
776 gcodec.channels = 1; 777 {107, {"telephone-event", 32000, 1}}})));
777 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
778 EXPECT_EQ(106, gcodec.pltype);
779 EXPECT_STREQ("ISAC", gcodec.plname);
780
781 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event");
782 gcodec.plfreq = 8000;
783 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
784 EXPECT_EQ(126, gcodec.pltype);
785 EXPECT_STREQ("telephone-event", gcodec.plname);
786
787 gcodec.plfreq = 32000;
788 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
789 EXPECT_EQ(107, gcodec.pltype);
790 EXPECT_STREQ("telephone-event", gcodec.plname);
791 } 778 }
792 779
793 // Test that we fail to set an unknown inbound codec. 780 // Test that we fail to set an unknown inbound codec.
794 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { 781 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
795 EXPECT_TRUE(SetupChannel()); 782 EXPECT_TRUE(SetupChannel());
796 cricket::AudioRecvParameters parameters; 783 cricket::AudioRecvParameters parameters;
797 parameters.codecs.push_back(kIsacCodec); 784 parameters.codecs.push_back(kIsacCodec);
798 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1)); 785 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1));
799 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); 786 EXPECT_FALSE(channel_->SetRecvParameters(parameters));
800 } 787 }
(...skipping 10 matching lines...) Expand all
811 798
812 // Test that we can decode OPUS without stereo parameters. 799 // Test that we can decode OPUS without stereo parameters.
813 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { 800 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
814 EXPECT_TRUE(SetupChannel()); 801 EXPECT_TRUE(SetupChannel());
815 cricket::AudioRecvParameters parameters; 802 cricket::AudioRecvParameters parameters;
816 parameters.codecs.push_back(kIsacCodec); 803 parameters.codecs.push_back(kIsacCodec);
817 parameters.codecs.push_back(kPcmuCodec); 804 parameters.codecs.push_back(kPcmuCodec);
818 parameters.codecs.push_back(kOpusCodec); 805 parameters.codecs.push_back(kOpusCodec);
819 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 806 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
820 EXPECT_TRUE(AddRecvStream(kSsrcX)); 807 EXPECT_TRUE(AddRecvStream(kSsrcX));
821 int channel_num = voe_.GetLastChannel(); 808 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
822 webrtc::CodecInst opus; 809 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
823 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 810 {{0, {"PCMU", 8000, 1}},
824 // Even without stereo parameters, recv codecs still specify channels = 2. 811 {103, {"ISAC", 16000, 1}},
825 EXPECT_EQ(2, opus.channels); 812 {111, {"opus", 48000, 2}}})));
826 EXPECT_EQ(111, opus.pltype);
827 EXPECT_STREQ("opus", opus.plname);
828 opus.pltype = 0;
829 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, opus));
830 EXPECT_EQ(111, opus.pltype);
831 } 813 }
832 814
833 // Test that we can decode OPUS with stereo = 0. 815 // Test that we can decode OPUS with stereo = 0.
834 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { 816 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
835 EXPECT_TRUE(SetupChannel()); 817 EXPECT_TRUE(SetupChannel());
836 cricket::AudioRecvParameters parameters; 818 cricket::AudioRecvParameters parameters;
837 parameters.codecs.push_back(kIsacCodec); 819 parameters.codecs.push_back(kIsacCodec);
838 parameters.codecs.push_back(kPcmuCodec); 820 parameters.codecs.push_back(kPcmuCodec);
839 parameters.codecs.push_back(kOpusCodec); 821 parameters.codecs.push_back(kOpusCodec);
840 parameters.codecs[2].params["stereo"] = "0"; 822 parameters.codecs[2].params["stereo"] = "0";
841 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 823 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
842 EXPECT_TRUE(AddRecvStream(kSsrcX)); 824 EXPECT_TRUE(AddRecvStream(kSsrcX));
843 int channel_num2 = voe_.GetLastChannel(); 825 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
844 webrtc::CodecInst opus; 826 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
845 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 827 {{0, {"PCMU", 8000, 1}},
846 // Even when stereo is off, recv codecs still specify channels = 2. 828 {103, {"ISAC", 16000, 1}},
847 EXPECT_EQ(2, opus.channels); 829 {111, {"opus", 48000, 2, {{"stereo", "0"}}}}})));
848 EXPECT_EQ(111, opus.pltype);
849 EXPECT_STREQ("opus", opus.plname);
850 opus.pltype = 0;
851 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
852 EXPECT_EQ(111, opus.pltype);
853 } 830 }
854 831
855 // Test that we can decode OPUS with stereo = 1. 832 // Test that we can decode OPUS with stereo = 1.
856 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) { 833 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
857 EXPECT_TRUE(SetupChannel()); 834 EXPECT_TRUE(SetupChannel());
858 cricket::AudioRecvParameters parameters; 835 cricket::AudioRecvParameters parameters;
859 parameters.codecs.push_back(kIsacCodec); 836 parameters.codecs.push_back(kIsacCodec);
860 parameters.codecs.push_back(kPcmuCodec); 837 parameters.codecs.push_back(kPcmuCodec);
861 parameters.codecs.push_back(kOpusCodec); 838 parameters.codecs.push_back(kOpusCodec);
862 parameters.codecs[2].params["stereo"] = "1"; 839 parameters.codecs[2].params["stereo"] = "1";
863 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 840 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
864 EXPECT_TRUE(AddRecvStream(kSsrcX)); 841 EXPECT_TRUE(AddRecvStream(kSsrcX));
865 int channel_num2 = voe_.GetLastChannel(); 842 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
866 webrtc::CodecInst opus; 843 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
867 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 844 {{0, {"PCMU", 8000, 1}},
868 EXPECT_EQ(2, opus.channels); 845 {103, {"ISAC", 16000, 1}},
869 EXPECT_EQ(111, opus.pltype); 846 {111, {"opus", 48000, 2, {{"stereo", "1"}}}}})));
870 EXPECT_STREQ("opus", opus.plname);
871 opus.pltype = 0;
872 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
873 EXPECT_EQ(111, opus.pltype);
874 } 847 }
875 848
876 // Test that changes to recv codecs are applied to all streams. 849 // Test that changes to recv codecs are applied to all streams.
877 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) { 850 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
878 EXPECT_TRUE(SetupChannel()); 851 EXPECT_TRUE(SetupChannel());
879 cricket::AudioRecvParameters parameters; 852 cricket::AudioRecvParameters parameters;
880 parameters.codecs.push_back(kIsacCodec); 853 parameters.codecs.push_back(kIsacCodec);
881 parameters.codecs.push_back(kPcmuCodec); 854 parameters.codecs.push_back(kPcmuCodec);
882 parameters.codecs.push_back(kTelephoneEventCodec1); 855 parameters.codecs.push_back(kTelephoneEventCodec1);
883 parameters.codecs.push_back(kTelephoneEventCodec2); 856 parameters.codecs.push_back(kTelephoneEventCodec2);
884 parameters.codecs[0].id = 106; // collide with existing CN 32k 857 parameters.codecs[0].id = 106; // collide with existing CN 32k
885 parameters.codecs[2].id = 126; 858 parameters.codecs[2].id = 126;
886 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 859 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
887 EXPECT_TRUE(AddRecvStream(kSsrcX)); 860 for (const auto& ssrc : {kSsrcX, kSsrcY}) {
888 int channel_num2 = voe_.GetLastChannel(); 861 EXPECT_TRUE(AddRecvStream(ssrc));
889 862 EXPECT_THAT(GetRecvStreamConfig(ssrc).decoder_map,
890 webrtc::CodecInst gcodec; 863 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
891 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 864 {{0, {"PCMU", 8000, 1}},
892 gcodec.plfreq = 16000; 865 {106, {"ISAC", 16000, 1}},
893 gcodec.channels = 1; 866 {126, {"telephone-event", 8000, 1}},
894 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 867 {107, {"telephone-event", 32000, 1}}})));
895 EXPECT_EQ(106, gcodec.pltype); 868 }
896 EXPECT_STREQ("ISAC", gcodec.plname);
897
898 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event");
899 gcodec.plfreq = 8000;
900 gcodec.channels = 1;
901 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
902 EXPECT_EQ(126, gcodec.pltype);
903 EXPECT_STREQ("telephone-event", gcodec.plname);
904
905 gcodec.plfreq = 32000;
906 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
907 EXPECT_EQ(107, gcodec.pltype);
908 EXPECT_STREQ("telephone-event", gcodec.plname);
909 } 869 }
910 870
911 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { 871 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
912 EXPECT_TRUE(SetupRecvStream()); 872 EXPECT_TRUE(SetupRecvStream());
913 cricket::AudioRecvParameters parameters; 873 cricket::AudioRecvParameters parameters;
914 parameters.codecs.push_back(kIsacCodec); 874 parameters.codecs.push_back(kIsacCodec);
915 parameters.codecs[0].id = 106; // collide with existing CN 32k 875 parameters.codecs[0].id = 106; // collide with existing CN 32k
916 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 876 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
917 877
918 const auto& dm = GetRecvStreamConfig(kSsrcX).decoder_map; 878 const auto& dm = GetRecvStreamConfig(kSsrcX).decoder_map;
(...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after
2927 2887
2928 // Test that after adding a recv stream, we do not decode more codecs than 2888 // Test that after adding a recv stream, we do not decode more codecs than
2929 // those previously passed into SetRecvCodecs. 2889 // those previously passed into SetRecvCodecs.
2930 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { 2890 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2931 EXPECT_TRUE(SetupSendStream()); 2891 EXPECT_TRUE(SetupSendStream());
2932 cricket::AudioRecvParameters parameters; 2892 cricket::AudioRecvParameters parameters;
2933 parameters.codecs.push_back(kIsacCodec); 2893 parameters.codecs.push_back(kIsacCodec);
2934 parameters.codecs.push_back(kPcmuCodec); 2894 parameters.codecs.push_back(kPcmuCodec);
2935 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 2895 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
2936 EXPECT_TRUE(AddRecvStream(kSsrcX)); 2896 EXPECT_TRUE(AddRecvStream(kSsrcX));
2937 int channel_num2 = voe_.GetLastChannel(); 2897 EXPECT_THAT(GetRecvStreamConfig(kSsrcX).decoder_map,
2938 webrtc::CodecInst gcodec; 2898 (ContainerEq<std::map<int, webrtc::SdpAudioFormat>>(
2939 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "opus"); 2899 {{0, {"PCMU", 8000, 1}}, {103, {"ISAC", 16000, 1}}})));
2940 gcodec.plfreq = 48000;
2941 gcodec.channels = 2;
2942 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2943 } 2900 }
2944 2901
2945 // Test that we properly clean up any streams that were added, even if 2902 // Test that we properly clean up any streams that were added, even if
2946 // not explicitly removed. 2903 // not explicitly removed.
2947 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { 2904 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2948 EXPECT_TRUE(SetupSendStream()); 2905 EXPECT_TRUE(SetupSendStream());
2949 SetSendParameters(send_parameters_); 2906 SetSendParameters(send_parameters_);
2950 EXPECT_TRUE(AddRecvStream(1)); 2907 EXPECT_TRUE(AddRecvStream(1));
2951 EXPECT_TRUE(AddRecvStream(2)); 2908 EXPECT_TRUE(AddRecvStream(2));
2952 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added 2909 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
3809 // Without this cast, the comparison turned unsigned and, thus, failed for -1. 3766 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3810 const int num_specs = static_cast<int>(specs.size()); 3767 const int num_specs = static_cast<int>(specs.size());
3811 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); 3768 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3812 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); 3769 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3813 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); 3770 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3814 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); 3771 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3815 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); 3772 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3816 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); 3773 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3817 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); 3774 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3818 } 3775 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698