Chromium Code Reviews| Index: webrtc/media/engine/webrtcvoiceengine_unittest.cc |
| diff --git a/webrtc/media/engine/webrtcvoiceengine_unittest.cc b/webrtc/media/engine/webrtcvoiceengine_unittest.cc |
| index 768673d73d2e0b44275f9a5bbcbb8ce5fe3249ec..84c3e9bbf67543f2a639f11ea3d1c4822b829ff3 100644 |
| --- a/webrtc/media/engine/webrtcvoiceengine_unittest.cc |
| +++ b/webrtc/media/engine/webrtcvoiceengine_unittest.cc |
| @@ -41,7 +41,8 @@ const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1, 0); |
| const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, 0, |
| 1, 0); |
| const uint32_t kSsrc1 = 0x99; |
| -const uint32_t kSsrc2 = 0x98; |
| +const uint32_t kSsrc2 = 2; |
| +const uint32_t kSsrc3 = 3; |
| const uint32_t kSsrcs4[] = { 1, 2, 3, 4 }; |
| class FakeVoEWrapper : public cricket::VoEWrapper { |
| @@ -63,6 +64,10 @@ class FakeAudioSink : public webrtc::AudioSinkInterface { |
| void OnData(const Data& audio) override {} |
| }; |
| +class FakeAudioSource : public cricket::AudioSource { |
| + void SetSink(Sink* sink) override {} |
| +}; |
| + |
| class WebRtcVoiceEngineTestFake : public testing::Test { |
| public: |
| WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} |
| @@ -71,6 +76,7 @@ class WebRtcVoiceEngineTestFake : public testing::Test { |
| : call_(webrtc::Call::Config()), |
| engine_(new FakeVoEWrapper(&voe_)), |
| channel_(nullptr), |
| + fake_source_(new FakeAudioSource()), |
| override_field_trials_(field_trials) { |
| send_parameters_.codecs.push_back(kPcmuCodec); |
| recv_parameters_.codecs.push_back(kPcmuCodec); |
| @@ -94,8 +100,10 @@ class WebRtcVoiceEngineTestFake : public testing::Test { |
| if (!SetupEngine()) { |
| return false; |
| } |
| - return channel_->AddSendStream( |
| - cricket::StreamParams::CreateLegacy(kSsrc1)); |
| + if (!channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc1))) { |
| + return false; |
| + } |
| + return channel_->SetAudioSend(kSsrc1, true, nullptr, fake_source_.get()); |
| } |
| void SetupForMultiSendStream() { |
| EXPECT_TRUE(SetupEngineWithSendStream()); |
| @@ -127,15 +135,11 @@ class WebRtcVoiceEngineTestFake : public testing::Test { |
| } |
| const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) { |
| - const auto* send_stream = call_.GetAudioSendStream(ssrc); |
| - EXPECT_TRUE(send_stream); |
| - return send_stream->GetConfig(); |
| + return GetSendStream(ssrc).GetConfig(); |
| } |
| const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) { |
| - const auto* recv_stream = call_.GetAudioReceiveStream(ssrc); |
| - EXPECT_TRUE(recv_stream); |
| - return recv_stream->GetConfig(); |
| + return GetRecvStream(ssrc).GetConfig(); |
| } |
| void TestInsertDtmf(uint32_t ssrc, bool caller) { |
| @@ -152,7 +156,7 @@ class WebRtcVoiceEngineTestFake : public testing::Test { |
| // Test we can only InsertDtmf when the other side supports telephone-event. |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| EXPECT_FALSE(channel_->CanInsertDtmf()); |
| EXPECT_FALSE(channel_->InsertDtmf(ssrc, 1, 111)); |
| send_parameters_.codecs.push_back(kTelephoneEventCodec); |
| @@ -401,6 +405,7 @@ class WebRtcVoiceEngineTestFake : public testing::Test { |
| cricket::VoiceMediaChannel* channel_; |
| cricket::AudioSendParameters send_parameters_; |
| cricket::AudioRecvParameters recv_parameters_; |
| + rtc::scoped_ptr<FakeAudioSource> fake_source_; |
|
the sun
2016/03/07 21:24:54
No need for scoped_ptr here.
Taylor Brandstetter
2016/03/08 00:00:31
Done.
|
| private: |
| webrtc::test::ScopedFieldTrials override_field_trials_; |
| @@ -2001,12 +2006,26 @@ TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) { |
| // Test that we can create a channel and start sending on it. |
| TEST_F(WebRtcVoiceEngineTestFake, Send) { |
| EXPECT_TRUE(SetupEngineWithSendStream()); |
| - int channel_num = voe_.GetLastChannel(); |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| - EXPECT_TRUE(voe_.GetSend(channel_num)); |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| + EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); |
| + EXPECT_TRUE(channel_->SetSend(false)); |
| + EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); |
| +} |
| + |
| +// Test that a channel will send if and only if it has a source and is enabled |
| +// for sending. |
| +TEST_F(WebRtcVoiceEngineTestFake, SendStateWithAndWithoutSource) { |
| + EXPECT_TRUE(SetupEngineWithSendStream()); |
| + EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| + EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, nullptr)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| + EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); |
| + EXPECT_TRUE( |
| + channel_->SetAudioSend(kSsrc1, true, nullptr, fake_source_.get())); |
| + EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); |
| + EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, nullptr)); |
| + EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); |
| } |
| // Test that we can create a channel and start playing out on it. |
| @@ -2025,13 +2044,15 @@ TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) { |
| SetupForMultiSendStream(); |
| // Set the global state for sending. |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| for (uint32_t ssrc : kSsrcs4) { |
| EXPECT_TRUE(channel_->AddSendStream( |
| cricket::StreamParams::CreateLegacy(ssrc))); |
| + EXPECT_TRUE( |
| + channel_->SetAudioSend(ssrc, true, nullptr, fake_source_.get())); |
| // Verify that we are in a sending state for all the created streams. |
| - EXPECT_TRUE(voe_.GetSend(GetSendStreamConfig(ssrc).voe_channel_id)); |
| + EXPECT_TRUE(GetSendStream(ssrc).IsSending()); |
| } |
| EXPECT_EQ(arraysize(kSsrcs4), call_.GetAudioSendStreams().size()); |
| @@ -2086,28 +2107,27 @@ TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsWithMultipleSendStreams) { |
| TEST_F(WebRtcVoiceEngineTestFake, SetSendWithMultipleSendStreams) { |
| SetupForMultiSendStream(); |
| - // Create the send channels and they should be a SEND_NOTHING date. |
| + // Create the send channels and they should be a "not sending" date. |
| for (uint32_t ssrc : kSsrcs4) { |
| EXPECT_TRUE(channel_->AddSendStream( |
| cricket::StreamParams::CreateLegacy(ssrc))); |
| - int channel_num = voe_.GetLastChannel(); |
| - EXPECT_FALSE(voe_.GetSend(channel_num)); |
| + EXPECT_TRUE( |
| + channel_->SetAudioSend(ssrc, true, nullptr, fake_source_.get())); |
| + EXPECT_FALSE(GetSendStream(ssrc).IsSending()); |
| } |
| // Set the global state for starting sending. |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| for (uint32_t ssrc : kSsrcs4) { |
| // Verify that we are in a sending state for all the send streams. |
| - int channel_num = GetSendStreamConfig(ssrc).voe_channel_id; |
| - EXPECT_TRUE(voe_.GetSend(channel_num)); |
| + EXPECT_TRUE(GetSendStream(ssrc).IsSending()); |
| } |
| // Set the global state for stopping sending. |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| + EXPECT_TRUE(channel_->SetSend(false)); |
| for (uint32_t ssrc : kSsrcs4) { |
| // Verify that we are in a stop state for all the send streams. |
| - int channel_num = GetSendStreamConfig(ssrc).voe_channel_id; |
| - EXPECT_FALSE(voe_.GetSend(channel_num)); |
| + EXPECT_FALSE(GetSendStream(ssrc).IsSending()); |
| } |
| } |
| @@ -2180,29 +2200,27 @@ TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) { |
| EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| // Adding another stream should enable playout on the new stream only. |
| - EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| + EXPECT_TRUE( |
| + channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc2))); |
| int channel_num2 = voe_.GetLastChannel(); |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| - EXPECT_TRUE(voe_.GetSend(channel_num1)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num2)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| + EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); |
| // Make sure only the new stream is played out. |
| EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| EXPECT_TRUE(voe_.GetPlayout(channel_num2)); |
| // Adding yet another stream should have stream 2 and 3 enabled for playout. |
| - EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
| + EXPECT_TRUE( |
| + channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc3))); |
| int channel_num3 = voe_.GetLastChannel(); |
| EXPECT_FALSE(voe_.GetPlayout(channel_num1)); |
| EXPECT_TRUE(voe_.GetPlayout(channel_num2)); |
| EXPECT_TRUE(voe_.GetPlayout(channel_num3)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num3)); |
| // Stop sending. |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num1)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num2)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num3)); |
| + EXPECT_TRUE(channel_->SetSend(false)); |
| + EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); |
| // Stop playout. |
| EXPECT_TRUE(channel_->SetPlayout(false)); |
| @@ -2228,18 +2246,17 @@ TEST_F(WebRtcVoiceEngineTestFake, CodianSend) { |
| EXPECT_TRUE(SetupEngineWithSendStream()); |
| cricket::AudioOptions options_adjust_agc; |
| options_adjust_agc.adjust_agc_delta = rtc::Optional<int>(-10); |
| - int channel_num = voe_.GetLastChannel(); |
| webrtc::AgcConfig agc_config; |
| EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| EXPECT_EQ(0, agc_config.targetLeveldBOv); |
| send_parameters_.options = options_adjust_agc; |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| - EXPECT_TRUE(voe_.GetSend(channel_num)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| + EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); |
| EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); |
| - EXPECT_FALSE(voe_.GetSend(channel_num)); |
| + EXPECT_TRUE(channel_->SetSend(false)); |
| + EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); |
| EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); |
| } |
| @@ -2315,7 +2332,7 @@ TEST_F(WebRtcVoiceEngineTestFake, GetStats) { |
| // Start sending - this affects some reported stats. |
| { |
| cricket::VoiceMediaInfo info; |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| EXPECT_EQ(true, channel_->GetStats(&info)); |
| VerifyVoiceSenderInfo(info.senders[0], true); |
| } |
| @@ -2574,7 +2591,7 @@ TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) { |
| TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) { |
| EXPECT_TRUE(SetupEngineWithSendStream()); |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| - EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); |
| + EXPECT_TRUE(channel_->SetSend(true)); |
| EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
| EXPECT_TRUE(channel_->SetPlayout(true)); |
| @@ -2844,7 +2861,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { |
| EXPECT_TRUE(agc_enabled); |
| EXPECT_TRUE(ns_enabled); |
| - channel1->SetSend(cricket::SEND_MICROPHONE); |
| + channel1->SetSend(true); |
| voe_.GetEcStatus(ec_enabled, ec_mode); |
| voe_.GetAgcStatus(agc_enabled, agc_mode); |
| voe_.GetNsStatus(ns_enabled, ns_mode); |
| @@ -2852,7 +2869,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { |
| EXPECT_TRUE(agc_enabled); |
| EXPECT_FALSE(ns_enabled); |
| - channel2->SetSend(cricket::SEND_MICROPHONE); |
| + channel2->SetSend(true); |
| voe_.GetEcStatus(ec_enabled, ec_mode); |
| voe_.GetAgcStatus(agc_enabled, agc_mode); |
| voe_.GetNsStatus(ns_enabled, ns_mode); |
| @@ -2868,7 +2885,7 @@ TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { |
| rtc::Optional<bool>(false); |
| parameters_options_no_agc_nor_ns.options.noise_suppression = |
| rtc::Optional<bool>(false); |
| - channel2->SetSend(cricket::SEND_MICROPHONE); |
| + channel2->SetSend(true); |
| channel2->SetSendParameters(parameters_options_no_agc_nor_ns); |
| expected_options.echo_cancellation = rtc::Optional<bool>(true); |
| expected_options.auto_gain_control = rtc::Optional<bool>(false); |