OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2008 Google Inc. | 3 * Copyright 2008 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0); | 52 static const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1, 0); |
53 static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0); | 53 static const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0); |
54 static const cricket::AudioCodec | 54 static const cricket::AudioCodec |
55 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0); | 55 kTelephoneEventCodec(106, "telephone-event", 8000, 0, 1, 0); |
56 static const cricket::AudioCodec* const kAudioCodecs[] = { | 56 static const cricket::AudioCodec* const kAudioCodecs[] = { |
57 &kPcmuCodec, &kIsacCodec, &kOpusCodec, &kG722CodecVoE, &kRedCodec, | 57 &kPcmuCodec, &kIsacCodec, &kOpusCodec, &kG722CodecVoE, &kRedCodec, |
58 &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec, | 58 &kCn8000Codec, &kCn16000Codec, &kTelephoneEventCodec, |
59 }; | 59 }; |
60 static uint32_t kSsrc1 = 0x99; | 60 static uint32_t kSsrc1 = 0x99; |
61 static uint32_t kSsrc2 = 0x98; | 61 static uint32_t kSsrc2 = 0x98; |
| 62 static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; |
62 | 63 |
63 class FakeVoEWrapper : public cricket::VoEWrapper { | 64 class FakeVoEWrapper : public cricket::VoEWrapper { |
64 public: | 65 public: |
65 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) | 66 explicit FakeVoEWrapper(cricket::FakeWebRtcVoiceEngine* engine) |
66 : cricket::VoEWrapper(engine, // processing | 67 : cricket::VoEWrapper(engine, // processing |
67 engine, // base | 68 engine, // base |
68 engine, // codec | 69 engine, // codec |
69 engine, // dtmf | 70 engine, // dtmf |
70 engine, // hw | 71 engine, // hw |
71 engine, // neteq | 72 engine, // neteq |
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1855 EXPECT_TRUE(channel_->SetPlayout(true)); | 1856 EXPECT_TRUE(channel_->SetPlayout(true)); |
1856 EXPECT_TRUE(voe_.GetPlayout(channel_num)); | 1857 EXPECT_TRUE(voe_.GetPlayout(channel_num)); |
1857 EXPECT_TRUE(channel_->SetPlayout(false)); | 1858 EXPECT_TRUE(channel_->SetPlayout(false)); |
1858 EXPECT_FALSE(voe_.GetPlayout(channel_num)); | 1859 EXPECT_FALSE(voe_.GetPlayout(channel_num)); |
1859 } | 1860 } |
1860 | 1861 |
1861 // Test that we can add and remove send streams. | 1862 // Test that we can add and remove send streams. |
1862 TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) { | 1863 TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) { |
1863 SetupForMultiSendStream(); | 1864 SetupForMultiSendStream(); |
1864 | 1865 |
1865 static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; | |
1866 | |
1867 // Set the global state for sending. | 1866 // Set the global state for sending. |
1868 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); | 1867 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
1869 | 1868 |
1870 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1869 for (uint32_t ssrc : kSsrcs4) { |
1871 EXPECT_TRUE(channel_->AddSendStream( | 1870 EXPECT_TRUE(channel_->AddSendStream( |
1872 cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); | 1871 cricket::StreamParams::CreateLegacy(ssrc))); |
| 1872 EXPECT_NE(nullptr, call_.GetAudioSendStream(ssrc)); |
1873 | 1873 |
1874 // Verify that we are in a sending state for all the created streams. | 1874 // Verify that we are in a sending state for all the created streams. |
1875 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); | 1875 int channel_num = voe_.GetChannelFromLocalSsrc(ssrc); |
1876 EXPECT_TRUE(voe_.GetSend(channel_num)); | 1876 EXPECT_TRUE(voe_.GetSend(channel_num)); |
1877 } | 1877 } |
| 1878 EXPECT_EQ(ARRAY_SIZE(kSsrcs4), call_.GetAudioSendStreams().size()); |
1878 | 1879 |
1879 // Remove the first send channel, which is the default channel. It will only | 1880 // Delete the send streams. |
1880 // recycle the default channel but not delete it. | 1881 for (uint32_t ssrc : kSsrcs4) { |
1881 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[0])); | 1882 EXPECT_TRUE(channel_->RemoveSendStream(ssrc)); |
1882 // Stream should already be Removed from the send stream list. | 1883 EXPECT_EQ(nullptr, call_.GetAudioSendStream(ssrc)); |
1883 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[0])); | |
1884 | |
1885 // Delete the rest of send channel streams. | |
1886 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) { | |
1887 EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[i])); | |
1888 // Stream should already be deleted. | 1884 // Stream should already be deleted. |
1889 EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[i])); | 1885 EXPECT_FALSE(channel_->RemoveSendStream(ssrc)); |
1890 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(kSsrcs4[i])); | 1886 EXPECT_EQ(-1, voe_.GetChannelFromLocalSsrc(ssrc)); |
1891 } | 1887 } |
| 1888 EXPECT_EQ(0u, call_.GetAudioSendStreams().size()); |
1892 } | 1889 } |
1893 | 1890 |
1894 // Test SetSendCodecs correctly configure the codecs in all send streams. | 1891 // Test SetSendCodecs correctly configure the codecs in all send streams. |
1895 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) { | 1892 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) { |
1896 SetupForMultiSendStream(); | 1893 SetupForMultiSendStream(); |
1897 | 1894 |
1898 static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; | |
1899 // Create send streams. | 1895 // Create send streams. |
1900 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1896 for (uint32_t ssrc : kSsrcs4) { |
1901 EXPECT_TRUE(channel_->AddSendStream( | 1897 EXPECT_TRUE(channel_->AddSendStream( |
1902 cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); | 1898 cricket::StreamParams::CreateLegacy(ssrc))); |
1903 } | 1899 } |
1904 | 1900 |
1905 cricket::AudioSendParameters parameters; | 1901 cricket::AudioSendParameters parameters; |
1906 // Set ISAC(16K) and CN(16K). VAD should be activated. | 1902 // Set ISAC(16K) and CN(16K). VAD should be activated. |
1907 parameters.codecs.push_back(kIsacCodec); | 1903 parameters.codecs.push_back(kIsacCodec); |
1908 parameters.codecs.push_back(kCn16000Codec); | 1904 parameters.codecs.push_back(kCn16000Codec); |
1909 parameters.codecs[1].id = 97; | 1905 parameters.codecs[1].id = 97; |
1910 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 1906 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
1911 | 1907 |
1912 // Verify ISAC and VAD are corrected configured on all send channels. | 1908 // Verify ISAC and VAD are corrected configured on all send channels. |
1913 webrtc::CodecInst gcodec; | 1909 webrtc::CodecInst gcodec; |
1914 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1910 for (uint32_t ssrc : kSsrcs4) { |
1915 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); | 1911 int channel_num = voe_.GetChannelFromLocalSsrc(ssrc); |
1916 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 1912 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
1917 EXPECT_STREQ("ISAC", gcodec.plname); | 1913 EXPECT_STREQ("ISAC", gcodec.plname); |
1918 EXPECT_TRUE(voe_.GetVAD(channel_num)); | 1914 EXPECT_TRUE(voe_.GetVAD(channel_num)); |
1919 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); | 1915 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); |
1920 } | 1916 } |
1921 | 1917 |
1922 // Change to PCMU(8K) and CN(16K). VAD should not be activated. | 1918 // Change to PCMU(8K) and CN(16K). VAD should not be activated. |
1923 parameters.codecs[0] = kPcmuCodec; | 1919 parameters.codecs[0] = kPcmuCodec; |
1924 EXPECT_TRUE(channel_->SetSendParameters(parameters)); | 1920 EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
1925 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1921 for (uint32_t ssrc : kSsrcs4) { |
1926 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); | 1922 int channel_num = voe_.GetChannelFromLocalSsrc(ssrc); |
1927 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); | 1923 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); |
1928 EXPECT_STREQ("PCMU", gcodec.plname); | 1924 EXPECT_STREQ("PCMU", gcodec.plname); |
1929 EXPECT_FALSE(voe_.GetVAD(channel_num)); | 1925 EXPECT_FALSE(voe_.GetVAD(channel_num)); |
1930 } | 1926 } |
1931 } | 1927 } |
1932 | 1928 |
1933 // Test we can SetSend on all send streams correctly. | 1929 // Test we can SetSend on all send streams correctly. |
1934 TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) { | 1930 TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) { |
1935 SetupForMultiSendStream(); | 1931 SetupForMultiSendStream(); |
1936 | 1932 |
1937 static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; | |
1938 // Create the send channels and they should be a SEND_NOTHING date. | 1933 // Create the send channels and they should be a SEND_NOTHING date. |
1939 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1934 for (uint32_t ssrc : kSsrcs4) { |
1940 EXPECT_TRUE(channel_->AddSendStream( | 1935 EXPECT_TRUE(channel_->AddSendStream( |
1941 cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); | 1936 cricket::StreamParams::CreateLegacy(ssrc))); |
1942 int channel_num = voe_.GetLastChannel(); | 1937 int channel_num = voe_.GetLastChannel(); |
1943 EXPECT_FALSE(voe_.GetSend(channel_num)); | 1938 EXPECT_FALSE(voe_.GetSend(channel_num)); |
1944 } | 1939 } |
1945 | 1940 |
1946 // Set the global state for starting sending. | 1941 // Set the global state for starting sending. |
1947 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); | 1942 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
1948 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1943 for (uint32_t ssrc : kSsrcs4) { |
1949 // Verify that we are in a sending state for all the send streams. | 1944 // Verify that we are in a sending state for all the send streams. |
1950 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); | 1945 int channel_num = voe_.GetChannelFromLocalSsrc(ssrc); |
1951 EXPECT_TRUE(voe_.GetSend(channel_num)); | 1946 EXPECT_TRUE(voe_.GetSend(channel_num)); |
1952 } | 1947 } |
1953 | 1948 |
1954 // Set the global state for stopping sending. | 1949 // Set the global state for stopping sending. |
1955 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); | 1950 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
1956 for (unsigned int i = 1; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1951 for (uint32_t ssrc : kSsrcs4) { |
1957 // Verify that we are in a stop state for all the send streams. | 1952 // Verify that we are in a stop state for all the send streams. |
1958 int channel_num = voe_.GetChannelFromLocalSsrc(kSsrcs4[i]); | 1953 int channel_num = voe_.GetChannelFromLocalSsrc(ssrc); |
1959 EXPECT_FALSE(voe_.GetSend(channel_num)); | 1954 EXPECT_FALSE(voe_.GetSend(channel_num)); |
1960 } | 1955 } |
1961 } | 1956 } |
1962 | 1957 |
1963 // Test we can set the correct statistics on all send streams. | 1958 // Test we can set the correct statistics on all send streams. |
1964 TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) { | 1959 TEST_F(WebRtcVoiceEngineTestFake, GetStatsWithMultipleSendStreams) { |
1965 SetupForMultiSendStream(); | 1960 SetupForMultiSendStream(); |
1966 | 1961 |
1967 static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; | |
1968 // Create send streams. | 1962 // Create send streams. |
1969 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1963 for (uint32_t ssrc : kSsrcs4) { |
1970 EXPECT_TRUE(channel_->AddSendStream( | 1964 EXPECT_TRUE(channel_->AddSendStream( |
1971 cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); | 1965 cricket::StreamParams::CreateLegacy(ssrc))); |
1972 } | 1966 } |
1973 // Create a receive stream to check that none of the send streams end up in | 1967 // Create a receive stream to check that none of the send streams end up in |
1974 // the receive stream stats. | 1968 // the receive stream stats. |
1975 EXPECT_TRUE(channel_->AddRecvStream( | 1969 EXPECT_TRUE(channel_->AddRecvStream( |
1976 cricket::StreamParams::CreateLegacy(kSsrc2))); | 1970 cricket::StreamParams::CreateLegacy(kSsrc2))); |
1977 // We need send codec to be set to get all stats. | 1971 // We need send codec to be set to get all stats. |
1978 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | 1972 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
1979 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); | 1973 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
1980 | 1974 |
1981 cricket::VoiceMediaInfo info; | 1975 cricket::VoiceMediaInfo info; |
1982 EXPECT_EQ(true, channel_->GetStats(&info)); | 1976 EXPECT_EQ(true, channel_->GetStats(&info)); |
1983 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size()); | 1977 EXPECT_EQ(static_cast<size_t>(ARRAY_SIZE(kSsrcs4)), info.senders.size()); |
1984 | 1978 |
1985 // Verify the statistic information is correct. | 1979 // Verify the statistic information is correct. |
| 1980 // TODO(solenberg): Make this loop ordering independent. |
1986 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { | 1981 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs4); ++i) { |
1987 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc()); | 1982 EXPECT_EQ(kSsrcs4[i], info.senders[i].ssrc()); |
1988 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name); | 1983 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name); |
1989 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent); | 1984 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent); |
1990 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent); | 1985 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent); |
1991 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost); | 1986 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost); |
1992 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost); | 1987 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost); |
1993 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum); | 1988 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum); |
1994 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms); | 1989 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms); |
1995 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms); | 1990 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms); |
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3251 cricket::WebRtcVoiceEngine engine; | 3246 cricket::WebRtcVoiceEngine engine; |
3252 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3247 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3253 rtc::scoped_ptr<webrtc::Call> call( | 3248 rtc::scoped_ptr<webrtc::Call> call( |
3254 webrtc::Call::Create(webrtc::Call::Config())); | 3249 webrtc::Call::Create(webrtc::Call::Config())); |
3255 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), | 3250 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), |
3256 call.get()); | 3251 call.get()); |
3257 cricket::AudioRecvParameters parameters; | 3252 cricket::AudioRecvParameters parameters; |
3258 parameters.codecs = engine.codecs(); | 3253 parameters.codecs = engine.codecs(); |
3259 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3254 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3260 } | 3255 } |
OLD | NEW |