From 0ccae135562ac180da053fcecda91a0365621f14 Mon Sep 17 00:00:00 2001 From: Fredrik Solenberg Date: Tue, 3 Nov 2015 10:15:49 +0100 Subject: [PATCH] Changed FakeVoiceEngine into a MockVoiceEngine. BUG=webrtc:4690 R=tommi@webrtc.org Review URL: https://codereview.webrtc.org/1402403008 . Cr-Commit-Position: refs/heads/master@{#10491} --- talk/media/webrtc/fakewebrtcvoiceengine.h | 10 - webrtc/audio/audio_receive_stream_unittest.cc | 144 +++-- webrtc/audio/audio_send_stream_unittest.cc | 108 +++- webrtc/call/bitrate_estimator_tests.cc | 29 +- webrtc/call/call_unittest.cc | 6 +- webrtc/test/fake_voice_engine.cc | 70 --- webrtc/test/fake_voice_engine.h | 503 ------------------ webrtc/test/mock_voice_engine.h | 322 +++++++++++ webrtc/test/webrtc_test_common.gyp | 4 +- webrtc/voice_engine/include/voe_rtp_rtcp.h | 14 - 10 files changed, 511 insertions(+), 699 deletions(-) delete mode 100644 webrtc/test/fake_voice_engine.cc delete mode 100644 webrtc/test/fake_voice_engine.h create mode 100644 webrtc/test/mock_voice_engine.h diff --git a/talk/media/webrtc/fakewebrtcvoiceengine.h b/talk/media/webrtc/fakewebrtcvoiceengine.h index 2405e07b5f..d031d10411 100644 --- a/talk/media/webrtc/fakewebrtcvoiceengine.h +++ b/talk/media/webrtc/fakewebrtcvoiceengine.h @@ -776,22 +776,12 @@ class FakeWebRtcVoiceEngine unsigned int& discardedPackets)); WEBRTC_STUB(GetRTCPStatistics, (int channel, webrtc::CallStatistics& stats)); WEBRTC_FUNC(SetREDStatus, (int channel, bool enable, int redPayloadtype)) { - return SetFECStatus(channel, enable, redPayloadtype); - } - // TODO(minyue): remove the below function when transition to SetREDStatus - // is finished. - WEBRTC_FUNC(SetFECStatus, (int channel, bool enable, int redPayloadtype)) { WEBRTC_CHECK_CHANNEL(channel); channels_[channel]->red = enable; channels_[channel]->red_type = redPayloadtype; return 0; } WEBRTC_FUNC(GetREDStatus, (int channel, bool& enable, int& redPayloadtype)) { - return GetFECStatus(channel, enable, redPayloadtype); - } - // TODO(minyue): remove the below function when transition to GetREDStatus - // is finished. - WEBRTC_FUNC(GetFECStatus, (int channel, bool& enable, int& redPayloadtype)) { WEBRTC_CHECK_CHANNEL(channel); enable = channels_[channel]->red; redPayloadtype = channels_[channel]->red_type; diff --git a/webrtc/audio/audio_receive_stream_unittest.cc b/webrtc/audio/audio_receive_stream_unittest.cc index 4e267f1738..0bb9b51e16 100644 --- a/webrtc/audio/audio_receive_stream_unittest.cc +++ b/webrtc/audio/audio_receive_stream_unittest.cc @@ -14,12 +14,15 @@ #include "webrtc/audio/conversion.h" #include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_estimator.h" #include "webrtc/modules/rtp_rtcp/source/byte_io.h" -#include "webrtc/test/fake_voice_engine.h" +#include "webrtc/test/mock_voice_engine.h" +namespace webrtc { +namespace test { namespace { -using webrtc::ByteWriter; - +const int kChannelId = 2; +const uint32_t kRemoteSsrc = 1234; +const uint32_t kLocalSsrc = 5678; const size_t kAbsoluteSendTimeLength = 4; void BuildAbsoluteSendTimeExtension(uint8_t* buffer, @@ -58,39 +61,38 @@ size_t CreateRtpHeaderWithAbsSendTime(uint8_t* header, } } // namespace -namespace webrtc { -namespace test { - TEST(AudioReceiveStreamTest, ConfigToString) { const int kAbsSendTimeId = 3; AudioReceiveStream::Config config; - config.rtp.remote_ssrc = 1234; - config.rtp.local_ssrc = 5678; + config.rtp.remote_ssrc = kRemoteSsrc; + config.rtp.local_ssrc = kLocalSsrc; config.rtp.extensions.push_back( RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); - config.voe_channel_id = 1; + config.voe_channel_id = kChannelId; config.combined_audio_video_bwe = true; - EXPECT_EQ("{rtp: {remote_ssrc: 1234, local_ssrc: 5678, extensions: [{name: " + EXPECT_EQ( + "{rtp: {remote_ssrc: 1234, local_ssrc: 5678, extensions: [{name: " "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, " "receive_transport: nullptr, rtcp_send_transport: nullptr, " - "voe_channel_id: 1, combined_audio_video_bwe: true}", config.ToString()); + "voe_channel_id: 2, combined_audio_video_bwe: true}", + config.ToString()); } TEST(AudioReceiveStreamTest, ConstructDestruct) { MockRemoteBitrateEstimator remote_bitrate_estimator; - FakeVoiceEngine voice_engine; + MockVoiceEngine voice_engine; AudioReceiveStream::Config config; - config.voe_channel_id = 1; + config.voe_channel_id = kChannelId; internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config, &voice_engine); } TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) { MockRemoteBitrateEstimator remote_bitrate_estimator; - FakeVoiceEngine voice_engine; + MockVoiceEngine voice_engine; AudioReceiveStream::Config config; config.combined_audio_video_bwe = true; - config.voe_channel_id = FakeVoiceEngine::kRecvChannelId; + config.voe_channel_id = kChannelId; const int kAbsSendTimeId = 3; config.rtp.extensions.push_back( RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); @@ -102,60 +104,100 @@ TEST(AudioReceiveStreamTest, AudioPacketUpdatesBweWithTimestamp) { PacketTime packet_time(5678000, 0); const size_t kExpectedHeaderLength = 20; EXPECT_CALL(remote_bitrate_estimator, - IncomingPacket(packet_time.timestamp / 1000, - sizeof(rtp_packet) - kExpectedHeaderLength, testing::_, false)) + IncomingPacket(packet_time.timestamp / 1000, + sizeof(rtp_packet) - kExpectedHeaderLength, + testing::_, false)) .Times(1); EXPECT_TRUE( recv_stream.DeliverRtp(rtp_packet, sizeof(rtp_packet), packet_time)); } TEST(AudioReceiveStreamTest, GetStats) { + const int kJitterBufferDelay = -7; + const int kPlayoutBufferDelay = 302; + const unsigned int kSpeechOutputLevel = 99; + const CallStatistics kCallStats = {345, 678, 901, 234, -12, + 3456, 7890, 567, 890, 123}; + + const CodecInst kCodecInst = {123, "codec_name_recv", 96000, -187, -198, + -103}; + + const NetworkStatistics kNetworkStats = { + 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0}; + + webrtc::AudioDecodingCallStats audio_decode_stats; + { + audio_decode_stats.calls_to_silence_generator = 234; + audio_decode_stats.calls_to_neteq = 567; + audio_decode_stats.decoded_normal = 890; + audio_decode_stats.decoded_plc = 123; + audio_decode_stats.decoded_cng = 456; + audio_decode_stats.decoded_plc_cng = 789; + } + MockRemoteBitrateEstimator remote_bitrate_estimator; - FakeVoiceEngine voice_engine; + MockVoiceEngine voice_engine; AudioReceiveStream::Config config; - config.rtp.remote_ssrc = FakeVoiceEngine::kRecvSsrc; - config.voe_channel_id = FakeVoiceEngine::kRecvChannelId; + config.rtp.remote_ssrc = kRemoteSsrc; + config.voe_channel_id = kChannelId; internal::AudioReceiveStream recv_stream(&remote_bitrate_estimator, config, &voice_engine); + using testing::_; + using testing::DoAll; + using testing::Return; + using testing::SetArgPointee; + using testing::SetArgReferee; + EXPECT_CALL(voice_engine, GetRemoteSSRC(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); + EXPECT_CALL(voice_engine, GetRTCPStatistics(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(kCallStats), Return(0))); + EXPECT_CALL(voice_engine, GetRecCodec(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); + EXPECT_CALL(voice_engine, GetDelayEstimate(kChannelId, _, _)) + .WillOnce(DoAll(SetArgPointee<1>(kJitterBufferDelay), + SetArgPointee<2>(kPlayoutBufferDelay), Return(0))); + EXPECT_CALL(voice_engine, GetSpeechOutputLevelFullRange(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(kSpeechOutputLevel), Return(0))); + EXPECT_CALL(voice_engine, GetNetworkStatistics(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(kNetworkStats), Return(0))); + EXPECT_CALL(voice_engine, GetDecodingCallStatistics(kChannelId, _)) + .WillOnce(DoAll(SetArgPointee<1>(audio_decode_stats), Return(0))); + AudioReceiveStream::Stats stats = recv_stream.GetStats(); - const CallStatistics& call_stats = FakeVoiceEngine::kRecvCallStats; - const CodecInst& codec_inst = FakeVoiceEngine::kRecvCodecInst; - const NetworkStatistics& net_stats = FakeVoiceEngine::kRecvNetworkStats; - const AudioDecodingCallStats& decode_stats = - FakeVoiceEngine::kRecvAudioDecodingCallStats; - EXPECT_EQ(FakeVoiceEngine::kRecvSsrc, stats.remote_ssrc); - EXPECT_EQ(static_cast(call_stats.bytesReceived), stats.bytes_rcvd); - EXPECT_EQ(static_cast(call_stats.packetsReceived), + EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc); + EXPECT_EQ(static_cast(kCallStats.bytesReceived), stats.bytes_rcvd); + EXPECT_EQ(static_cast(kCallStats.packetsReceived), stats.packets_rcvd); - EXPECT_EQ(call_stats.cumulativeLost, stats.packets_lost); - EXPECT_EQ(Q8ToFloat(call_stats.fractionLost), stats.fraction_lost); - EXPECT_EQ(std::string(codec_inst.plname), stats.codec_name); - EXPECT_EQ(call_stats.extendedMax, stats.ext_seqnum); - EXPECT_EQ(call_stats.jitterSamples / (codec_inst.plfreq / 1000), + EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost); + EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost); + EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); + EXPECT_EQ(kCallStats.extendedMax, stats.ext_seqnum); + EXPECT_EQ(kCallStats.jitterSamples / (kCodecInst.plfreq / 1000), stats.jitter_ms); - EXPECT_EQ(net_stats.currentBufferSize, stats.jitter_buffer_ms); - EXPECT_EQ(net_stats.preferredBufferSize, stats.jitter_buffer_preferred_ms); - EXPECT_EQ(static_cast(FakeVoiceEngine::kRecvJitterBufferDelay + - FakeVoiceEngine::kRecvPlayoutBufferDelay), stats.delay_estimate_ms); - EXPECT_EQ(static_cast(FakeVoiceEngine::kRecvSpeechOutputLevel), - stats.audio_level); - EXPECT_EQ(Q14ToFloat(net_stats.currentExpandRate), stats.expand_rate); - EXPECT_EQ(Q14ToFloat(net_stats.currentSpeechExpandRate), + EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms); + EXPECT_EQ(kNetworkStats.preferredBufferSize, + stats.jitter_buffer_preferred_ms); + EXPECT_EQ(static_cast(kJitterBufferDelay + kPlayoutBufferDelay), + stats.delay_estimate_ms); + EXPECT_EQ(static_cast(kSpeechOutputLevel), stats.audio_level); + EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate); + EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate), stats.speech_expand_rate); - EXPECT_EQ(Q14ToFloat(net_stats.currentSecondaryDecodedRate), + EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate), stats.secondary_decoded_rate); - EXPECT_EQ(Q14ToFloat(net_stats.currentAccelerateRate), stats.accelerate_rate); - EXPECT_EQ(Q14ToFloat(net_stats.currentPreemptiveRate), + EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate), + stats.accelerate_rate); + EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate), stats.preemptive_expand_rate); - EXPECT_EQ(decode_stats.calls_to_silence_generator, + EXPECT_EQ(audio_decode_stats.calls_to_silence_generator, stats.decoding_calls_to_silence_generator); - EXPECT_EQ(decode_stats.calls_to_neteq, stats.decoding_calls_to_neteq); - EXPECT_EQ(decode_stats.decoded_normal, stats.decoding_normal); - EXPECT_EQ(decode_stats.decoded_plc, stats.decoding_plc); - EXPECT_EQ(decode_stats.decoded_cng, stats.decoding_cng); - EXPECT_EQ(decode_stats.decoded_plc_cng, stats.decoding_plc_cng); - EXPECT_EQ(call_stats.capture_start_ntp_time_ms_, + EXPECT_EQ(audio_decode_stats.calls_to_neteq, stats.decoding_calls_to_neteq); + EXPECT_EQ(audio_decode_stats.decoded_normal, stats.decoding_normal); + EXPECT_EQ(audio_decode_stats.decoded_plc, stats.decoding_plc); + EXPECT_EQ(audio_decode_stats.decoded_cng, stats.decoding_cng); + EXPECT_EQ(audio_decode_stats.decoded_plc_cng, stats.decoding_plc_cng); + EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_, stats.capture_start_ntp_time_ms); } } // namespace test diff --git a/webrtc/audio/audio_send_stream_unittest.cc b/webrtc/audio/audio_send_stream_unittest.cc index 227ec83799..727178ed5b 100644 --- a/webrtc/audio/audio_send_stream_unittest.cc +++ b/webrtc/audio/audio_send_stream_unittest.cc @@ -12,64 +12,114 @@ #include "webrtc/audio/audio_send_stream.h" #include "webrtc/audio/conversion.h" -#include "webrtc/test/fake_voice_engine.h" +#include "webrtc/test/mock_voice_engine.h" namespace webrtc { namespace test { +namespace { + +const int kChannelId = 1; +const uint32_t kSsrc = 1234; +} // namespace TEST(AudioSendStreamTest, ConfigToString) { const int kAbsSendTimeId = 3; AudioSendStream::Config config(nullptr); - config.rtp.ssrc = 1234; + config.rtp.ssrc = kSsrc; config.rtp.extensions.push_back( RtpExtension(RtpExtension::kAbsSendTime, kAbsSendTimeId)); - config.voe_channel_id = 1; + config.voe_channel_id = kChannelId; config.cng_payload_type = 42; config.red_payload_type = 17; - EXPECT_EQ("{rtp: {ssrc: 1234, extensions: [{name: " + EXPECT_EQ( + "{rtp: {ssrc: 1234, extensions: [{name: " "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}]}, " "voe_channel_id: 1, cng_payload_type: 42, red_payload_type: 17}", config.ToString()); } TEST(AudioSendStreamTest, ConstructDestruct) { - FakeVoiceEngine voice_engine; + MockVoiceEngine voice_engine; AudioSendStream::Config config(nullptr); - config.voe_channel_id = 1; + config.voe_channel_id = kChannelId; internal::AudioSendStream send_stream(config, &voice_engine); } TEST(AudioSendStreamTest, GetStats) { - FakeVoiceEngine voice_engine; + const int kEchoDelayMedian = 254; + const int kEchoDelayStdDev = -3; + const int kEchoReturnLoss = -65; + const int kEchoReturnLossEnhancement = 101; + const unsigned int kSpeechInputLevel = 96; + + const CallStatistics kCallStats = {1345, 1678, 1901, 1234, 112, + 13456, 17890, 1567, -1890, -1123}; + + const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, -451, + -671}; + + const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354}; + + std::vector report_blocks; + { + webrtc::ReportBlock block = kReportBlock; + report_blocks.push_back(block); // Has wrong SSRC. + block.source_SSRC = kSsrc; + report_blocks.push_back(block); // Correct block. + block.fraction_lost = 0; + report_blocks.push_back(block); // Duplicate SSRC, bad fraction_lost. + } + + MockVoiceEngine voice_engine; AudioSendStream::Config config(nullptr); - config.rtp.ssrc = FakeVoiceEngine::kSendSsrc; - config.voe_channel_id = FakeVoiceEngine::kSendChannelId; + config.rtp.ssrc = kSsrc; + config.voe_channel_id = kChannelId; internal::AudioSendStream send_stream(config, &voice_engine); + using testing::_; + using testing::DoAll; + using testing::Return; + using testing::SetArgPointee; + using testing::SetArgReferee; + EXPECT_CALL(voice_engine, GetLocalSSRC(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(0), Return(0))); + EXPECT_CALL(voice_engine, GetRTCPStatistics(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(kCallStats), Return(0))); + EXPECT_CALL(voice_engine, GetSendCodec(kChannelId, _)) + .WillOnce(DoAll(SetArgReferee<1>(kCodecInst), Return(0))); + EXPECT_CALL(voice_engine, GetRemoteRTCPReportBlocks(kChannelId, _)) + .WillOnce(DoAll(SetArgPointee<1>(report_blocks), Return(0))); + EXPECT_CALL(voice_engine, GetSpeechInputLevelFullRange(_)) + .WillOnce(DoAll(SetArgReferee<0>(kSpeechInputLevel), Return(0))); + EXPECT_CALL(voice_engine, GetEcMetricsStatus(_)) + .WillOnce(DoAll(SetArgReferee<0>(true), Return(0))); + EXPECT_CALL(voice_engine, GetEchoMetrics(_, _, _, _)) + .WillOnce(DoAll(SetArgReferee<0>(kEchoReturnLoss), + SetArgReferee<1>(kEchoReturnLossEnhancement), Return(0))); + EXPECT_CALL(voice_engine, GetEcDelayMetrics(_, _, _)) + .WillOnce(DoAll(SetArgReferee<0>(kEchoDelayMedian), + SetArgReferee<1>(kEchoDelayStdDev), Return(0))); + AudioSendStream::Stats stats = send_stream.GetStats(); - const CallStatistics& call_stats = FakeVoiceEngine::kSendCallStats; - const CodecInst& codec_inst = FakeVoiceEngine::kSendCodecInst; - const ReportBlock& report_block = FakeVoiceEngine::kSendReportBlock; - EXPECT_EQ(FakeVoiceEngine::kSendSsrc, stats.local_ssrc); - EXPECT_EQ(static_cast(call_stats.bytesSent), stats.bytes_sent); - EXPECT_EQ(call_stats.packetsSent, stats.packets_sent); - EXPECT_EQ(static_cast(report_block.cumulative_num_packets_lost), + EXPECT_EQ(kSsrc, stats.local_ssrc); + EXPECT_EQ(static_cast(kCallStats.bytesSent), stats.bytes_sent); + EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent); + EXPECT_EQ(static_cast(kReportBlock.cumulative_num_packets_lost), stats.packets_lost); - EXPECT_EQ(Q8ToFloat(report_block.fraction_lost), stats.fraction_lost); - EXPECT_EQ(std::string(codec_inst.plname), stats.codec_name); - EXPECT_EQ(static_cast(report_block.extended_highest_sequence_number), + EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost); + EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name); + EXPECT_EQ(static_cast(kReportBlock.extended_highest_sequence_number), stats.ext_seqnum); - EXPECT_EQ(static_cast(report_block.interarrival_jitter / - (codec_inst.plfreq / 1000)), stats.jitter_ms); - EXPECT_EQ(call_stats.rttMs, stats.rtt_ms); - EXPECT_EQ(static_cast(FakeVoiceEngine::kSendSpeechInputLevel), - stats.audio_level); + EXPECT_EQ(static_cast(kReportBlock.interarrival_jitter / + (kCodecInst.plfreq / 1000)), + stats.jitter_ms); + EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms); + EXPECT_EQ(static_cast(kSpeechInputLevel), stats.audio_level); EXPECT_EQ(-1, stats.aec_quality_min); - EXPECT_EQ(FakeVoiceEngine::kSendEchoDelayMedian, stats.echo_delay_median_ms); - EXPECT_EQ(FakeVoiceEngine::kSendEchoDelayStdDev, stats.echo_delay_std_ms); - EXPECT_EQ(FakeVoiceEngine::kSendEchoReturnLoss, stats.echo_return_loss); - EXPECT_EQ(FakeVoiceEngine::kSendEchoReturnLossEnhancement, - stats.echo_return_loss_enhancement); + EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms); + EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms); + EXPECT_EQ(kEchoReturnLoss, stats.echo_return_loss); + EXPECT_EQ(kEchoReturnLossEnhancement, stats.echo_return_loss_enhancement); EXPECT_FALSE(stats.typing_noise_detected); } } // namespace test diff --git a/webrtc/call/bitrate_estimator_tests.cc b/webrtc/call/bitrate_estimator_tests.cc index 685f3fd665..f6dac6bc06 100644 --- a/webrtc/call/bitrate_estimator_tests.cc +++ b/webrtc/call/bitrate_estimator_tests.cc @@ -25,7 +25,7 @@ #include "webrtc/test/encoder_settings.h" #include "webrtc/test/fake_decoder.h" #include "webrtc/test/fake_encoder.h" -#include "webrtc/test/fake_voice_engine.h" +#include "webrtc/test/mock_voice_engine.h" #include "webrtc/test/frame_generator_capturer.h" namespace webrtc { @@ -43,9 +43,7 @@ class TraceObserver { // Call webrtc trace to initialize the tracer that would otherwise trigger a // data-race if left to be initialized by multiple threads (i.e. threads // spawned by test::DirectTransport members in BitrateEstimatorTest). - WEBRTC_TRACE(kTraceStateInfo, - kTraceUtility, - -1, + WEBRTC_TRACE(kTraceStateInfo, kTraceUtility, -1, "Instantiate without data races."); } @@ -58,9 +56,7 @@ class TraceObserver { callback_.PushExpectedLogLine(expected_log_line); } - EventTypeWrapper Wait() { - return callback_.Wait(); - } + EventTypeWrapper Wait() { return callback_.Wait(); } private: class Callback : public TraceCallback { @@ -118,13 +114,14 @@ class BitrateEstimatorTest : public test::CallTest { public: BitrateEstimatorTest() : receive_config_(nullptr) {} - virtual ~BitrateEstimatorTest() { - EXPECT_TRUE(streams_.empty()); - } + virtual ~BitrateEstimatorTest() { EXPECT_TRUE(streams_.empty()); } virtual void SetUp() { + EXPECT_CALL(mock_voice_engine_, GetEventLog()) + .WillRepeatedly(testing::Return(nullptr)); + Call::Config config; - config.voice_engine = &fake_voice_engine_; + config.voice_engine = &mock_voice_engine_; receiver_call_.reset(Call::Create(config)); sender_call_.reset(Call::Create(config)); @@ -154,7 +151,7 @@ class BitrateEstimatorTest : public test::CallTest { virtual void TearDown() { std::for_each(streams_.begin(), streams_.end(), - std::mem_fun(&Stream::StopSending)); + std::mem_fun(&Stream::StopSending)); send_transport_->StopSending(); receive_transport_->StopSending(); @@ -187,10 +184,8 @@ class BitrateEstimatorTest : public test::CallTest { test_->send_config_, test_->encoder_config_); RTC_DCHECK_EQ(1u, test_->encoder_config_.streams.size()); frame_generator_capturer_.reset(test::FrameGeneratorCapturer::Create( - send_stream_->Input(), - test_->encoder_config_.streams[0].width, - test_->encoder_config_.streams[0].height, - 30, + send_stream_->Input(), test_->encoder_config_.streams[0].width, + test_->encoder_config_.streams[0].height, 30, Clock::GetRealTimeClock())); send_stream_->Start(); frame_generator_capturer_->Start(); @@ -262,7 +257,7 @@ class BitrateEstimatorTest : public test::CallTest { test::FakeDecoder fake_decoder_; }; - test::FakeVoiceEngine fake_voice_engine_; + test::MockVoiceEngine mock_voice_engine_; TraceObserver receiver_trace_; rtc::scoped_ptr send_transport_; rtc::scoped_ptr receive_transport_; diff --git a/webrtc/call/call_unittest.cc b/webrtc/call/call_unittest.cc index 9819b538f8..25fb119895 100644 --- a/webrtc/call/call_unittest.cc +++ b/webrtc/call/call_unittest.cc @@ -13,12 +13,12 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webrtc/call.h" -#include "webrtc/test/fake_voice_engine.h" +#include "webrtc/test/mock_voice_engine.h" namespace { struct CallHelper { - CallHelper() : voice_engine_(new webrtc::test::FakeVoiceEngine()) { + CallHelper() : voice_engine_(new webrtc::test::MockVoiceEngine()) { webrtc::Call::Config config; config.voice_engine = voice_engine_.get(); call_.reset(webrtc::Call::Create(config)); @@ -27,7 +27,7 @@ struct CallHelper { webrtc::Call* operator->() { return call_.get(); } private: - rtc::scoped_ptr voice_engine_; + rtc::scoped_ptr voice_engine_; rtc::scoped_ptr call_; }; } // namespace diff --git a/webrtc/test/fake_voice_engine.cc b/webrtc/test/fake_voice_engine.cc deleted file mode 100644 index 1a32e082b7..0000000000 --- a/webrtc/test/fake_voice_engine.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "webrtc/test/fake_voice_engine.h" - -namespace { - -webrtc::AudioDecodingCallStats MakeAudioDecodingCallStats() { - webrtc::AudioDecodingCallStats stats; - stats.calls_to_silence_generator = 234; - stats.calls_to_neteq = 567; - stats.decoded_normal = 890; - stats.decoded_plc = 123; - stats.decoded_cng = 456; - stats.decoded_plc_cng = 789; - return stats; -} -} // namespace - -namespace webrtc { -namespace test { - -const int FakeVoiceEngine::kSendChannelId = 1; -const int FakeVoiceEngine::kRecvChannelId = 2; -const uint32_t FakeVoiceEngine::kSendSsrc = 665; -const uint32_t FakeVoiceEngine::kRecvSsrc = 667; -const int FakeVoiceEngine::kSendEchoDelayMedian = 254; -const int FakeVoiceEngine::kSendEchoDelayStdDev = -3; -const int FakeVoiceEngine::kSendEchoReturnLoss = -65; -const int FakeVoiceEngine::kSendEchoReturnLossEnhancement = 101; -const int FakeVoiceEngine::kRecvJitterBufferDelay = -7; -const int FakeVoiceEngine::kRecvPlayoutBufferDelay = 302; -const unsigned int FakeVoiceEngine::kSendSpeechInputLevel = 96; -const unsigned int FakeVoiceEngine::kRecvSpeechOutputLevel = 99; - -const CallStatistics FakeVoiceEngine::kSendCallStats = { - 1345, 1678, 1901, 1234, 112, 13456, 17890, 1567, -1890, -1123 -}; - -const CodecInst FakeVoiceEngine::kSendCodecInst = { - -121, "codec_name_send", 48000, -231, -451, -671 -}; - -const ReportBlock FakeVoiceEngine::kSendReportBlock = { - 456, 780, 123, 567, 890, 132, 143, 13354 -}; - -const CallStatistics FakeVoiceEngine::kRecvCallStats = { - 345, 678, 901, 234, -12, 3456, 7890, 567, 890, 123 -}; - -const CodecInst FakeVoiceEngine::kRecvCodecInst = { - 123, "codec_name_recv", 96000, -187, -198, -103 -}; - -const NetworkStatistics FakeVoiceEngine::kRecvNetworkStats = { - 123, 456, false, 0, 0, 789, 12, 345, 678, 901, -1, -1, -1, -1, -1, 0 -}; - -const AudioDecodingCallStats FakeVoiceEngine::kRecvAudioDecodingCallStats = - MakeAudioDecodingCallStats(); -} // namespace test -} // namespace webrtc diff --git a/webrtc/test/fake_voice_engine.h b/webrtc/test/fake_voice_engine.h deleted file mode 100644 index a67f9bff20..0000000000 --- a/webrtc/test/fake_voice_engine.h +++ /dev/null @@ -1,503 +0,0 @@ -/* - * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_AUDIO_FAKE_VOICE_ENGINE_H_ -#define WEBRTC_AUDIO_FAKE_VOICE_ENGINE_H_ - -#include - -#include "testing/gtest/include/gtest/gtest.h" - -#include "webrtc/voice_engine/voice_engine_impl.h" - -namespace webrtc { -namespace test { - -// NOTE: This class inherits from VoiceEngineImpl so that its clients will be -// able to get the various interfaces as usual, via T::GetInterface(). -class FakeVoiceEngine final : public VoiceEngineImpl { - public: - static const int kSendChannelId; - static const int kRecvChannelId; - static const uint32_t kSendSsrc; - static const uint32_t kRecvSsrc; - static const int kSendEchoDelayMedian; - static const int kSendEchoDelayStdDev; - static const int kSendEchoReturnLoss; - static const int kSendEchoReturnLossEnhancement; - static const int kRecvJitterBufferDelay; - static const int kRecvPlayoutBufferDelay; - static const unsigned int kSendSpeechInputLevel; - static const unsigned int kRecvSpeechOutputLevel; - static const CallStatistics kSendCallStats; - static const CodecInst kSendCodecInst; - static const ReportBlock kSendReportBlock; - static const CallStatistics kRecvCallStats; - static const CodecInst kRecvCodecInst; - static const NetworkStatistics kRecvNetworkStats; - static const AudioDecodingCallStats kRecvAudioDecodingCallStats; - - FakeVoiceEngine() : VoiceEngineImpl(new Config(), true) { - // Increase ref count so this object isn't automatically deleted whenever - // interfaces are Release():d. - ++_ref_count; - } - ~FakeVoiceEngine() override { - // Decrease ref count before base class d-tor is called; otherwise it will - // trigger an assertion. - --_ref_count; - } - - // VoEAudioProcessing - int SetNsStatus(bool enable, NsModes mode = kNsUnchanged) override { - return -1; - } - int GetNsStatus(bool& enabled, NsModes& mode) override { return -1; } - int SetAgcStatus(bool enable, AgcModes mode = kAgcUnchanged) override { - return -1; - } - int GetAgcStatus(bool& enabled, AgcModes& mode) override { return -1; } - int SetAgcConfig(AgcConfig config) override { return -1; } - int GetAgcConfig(AgcConfig& config) override { return -1; } - int SetEcStatus(bool enable, EcModes mode = kEcUnchanged) override { - return -1; - } - int GetEcStatus(bool& enabled, EcModes& mode) override { return -1; } - int EnableDriftCompensation(bool enable) override { return -1; } - bool DriftCompensationEnabled() override { return false; } - void SetDelayOffsetMs(int offset) override {} - int DelayOffsetMs() override { return -1; } - int SetAecmMode(AecmModes mode = kAecmSpeakerphone, - bool enableCNG = true) override { return -1; } - int GetAecmMode(AecmModes& mode, bool& enabledCNG) override { return -1; } - int EnableHighPassFilter(bool enable) override { return -1; } - bool IsHighPassFilterEnabled() override { return false; } - int SetRxNsStatus(int channel, - bool enable, - NsModes mode = kNsUnchanged) override { return -1; } - int GetRxNsStatus(int channel, bool& enabled, NsModes& mode) override { - return -1; - } - int SetRxAgcStatus(int channel, - bool enable, - AgcModes mode = kAgcUnchanged) override { return -1; } - int GetRxAgcStatus(int channel, bool& enabled, AgcModes& mode) override { - return -1; - } - int SetRxAgcConfig(int channel, AgcConfig config) override { return -1; } - int GetRxAgcConfig(int channel, AgcConfig& config) override { return -1; } - int RegisterRxVadObserver(int channel, - VoERxVadCallback& observer) override { return -1; } - int DeRegisterRxVadObserver(int channel) override { return -1; } - int VoiceActivityIndicator(int channel) override { return -1; } - int SetEcMetricsStatus(bool enable) override { return -1; } - int GetEcMetricsStatus(bool& enabled) override { - enabled = true; - return 0; - } - int GetEchoMetrics(int& ERL, int& ERLE, int& RERL, int& A_NLP) override { - ERL = kSendEchoReturnLoss; - ERLE = kSendEchoReturnLossEnhancement; - RERL = -123456789; - A_NLP = 123456789; - return 0; - } - int GetEcDelayMetrics(int& delay_median, - int& delay_std, - float& fraction_poor_delays) override { - delay_median = kSendEchoDelayMedian; - delay_std = kSendEchoDelayStdDev; - fraction_poor_delays = -12345.7890f; - return 0; - } - int StartDebugRecording(const char* fileNameUTF8) override { return -1; } - int StartDebugRecording(FILE* file_handle) override { return -1; } - int StopDebugRecording() override { return -1; } - int SetTypingDetectionStatus(bool enable) override { return -1; } - int GetTypingDetectionStatus(bool& enabled) override { return -1; } - int TimeSinceLastTyping(int& seconds) override { return -1; } - int SetTypingDetectionParameters(int timeWindow, - int costPerTyping, - int reportingThreshold, - int penaltyDecay, - int typeEventDelay = 0) override { - return -1; - } - void EnableStereoChannelSwapping(bool enable) override {} - bool IsStereoChannelSwappingEnabled() override { return false; } - - // VoEBase - int RegisterVoiceEngineObserver(VoiceEngineObserver& observer) override { - return -1; - } - int DeRegisterVoiceEngineObserver() override { return -1; } - int Init(AudioDeviceModule* external_adm = NULL, - AudioProcessing* audioproc = NULL) override { return -1; } - AudioProcessing* audio_processing() override { return nullptr; } - int Terminate() override { return -1; } - int CreateChannel() override { return -1; } - int CreateChannel(const Config& config) override { return -1; } - int DeleteChannel(int channel) override { return -1; } - int StartReceive(int channel) override { return -1; } - int StopReceive(int channel) override { return -1; } - int StartPlayout(int channel) override { return -1; } - int StopPlayout(int channel) override { return -1; } - int StartSend(int channel) override { return -1; } - int StopSend(int channel) override { return -1; } - int GetVersion(char version[1024]) override { return -1; } - int LastError() override { return -1; } - AudioTransport* audio_transport() { return nullptr; } - int AssociateSendChannel(int channel, int accociate_send_channel) override { - return -1; - } - - // VoECodec - int NumOfCodecs() override { return -1; } - int GetCodec(int index, CodecInst& codec) override { return -1; } - int SetSendCodec(int channel, const CodecInst& codec) override { return -1; } - int GetSendCodec(int channel, CodecInst& codec) override { - EXPECT_EQ(channel, kSendChannelId); - codec = kSendCodecInst; - return 0; - } - int SetBitRate(int channel, int bitrate_bps) override { return -1; } - int GetRecCodec(int channel, CodecInst& codec) override { - EXPECT_EQ(channel, kRecvChannelId); - codec = kRecvCodecInst; - return 0; - } - int SetRecPayloadType(int channel, const CodecInst& codec) override { - return -1; - } - int GetRecPayloadType(int channel, CodecInst& codec) override { return -1; } - int SetSendCNPayloadType(int channel, int type, - PayloadFrequencies frequency = kFreq16000Hz) override { return -1; } - int SetVADStatus(int channel, - bool enable, - VadModes mode = kVadConventional, - bool disableDTX = false) override { return -1; } - int GetVADStatus(int channel, - bool& enabled, - VadModes& mode, - bool& disabledDTX) override { return -1; } - int SetOpusMaxPlaybackRate(int channel, int frequency_hz) override { - return -1; - } - int SetOpusDtx(int channel, bool enable_dtx) override { return -1; } - RtcEventLog* GetEventLog() override { return nullptr; } - - // VoEDtmf - int SendTelephoneEvent(int channel, - int eventCode, - bool outOfBand = true, - int lengthMs = 160, - int attenuationDb = 10) override { return -1; } - int SetSendTelephoneEventPayloadType(int channel, - unsigned char type) override { - return -1; - } - int GetSendTelephoneEventPayloadType(int channel, - unsigned char& type) override { - return -1; - } - int SetDtmfFeedbackStatus(bool enable, - bool directFeedback = false) override { return -1; } - int GetDtmfFeedbackStatus(bool& enabled, bool& directFeedback) override { - return -1; - } - int PlayDtmfTone(int eventCode, - int lengthMs = 200, - int attenuationDb = 10) override { return -1; } - - // VoEExternalMedia - int RegisterExternalMediaProcessing( - int channel, - ProcessingTypes type, - VoEMediaProcess& processObject) override { return -1; } - int DeRegisterExternalMediaProcessing(int channel, - ProcessingTypes type) override { - return -1; - } - int GetAudioFrame(int channel, - int desired_sample_rate_hz, - AudioFrame* frame) override { return -1; } - int SetExternalMixing(int channel, bool enable) override { return -1; } - - // VoEFile - int StartPlayingFileLocally( - int channel, - const char fileNameUTF8[1024], - bool loop = false, - FileFormats format = kFileFormatPcm16kHzFile, - float volumeScaling = 1.0, - int startPointMs = 0, - int stopPointMs = 0) override { return -1; } - int StartPlayingFileLocally( - int channel, - InStream* stream, - FileFormats format = kFileFormatPcm16kHzFile, - float volumeScaling = 1.0, - int startPointMs = 0, - int stopPointMs = 0) override { return -1; } - int StopPlayingFileLocally(int channel) override { return -1; } - int IsPlayingFileLocally(int channel) override { return -1; } - int StartPlayingFileAsMicrophone( - int channel, - const char fileNameUTF8[1024], - bool loop = false, - bool mixWithMicrophone = false, - FileFormats format = kFileFormatPcm16kHzFile, - float volumeScaling = 1.0) override { return -1; } - int StartPlayingFileAsMicrophone( - int channel, - InStream* stream, - bool mixWithMicrophone = false, - FileFormats format = kFileFormatPcm16kHzFile, - float volumeScaling = 1.0) override { return -1; } - int StopPlayingFileAsMicrophone(int channel) override { return -1; } - int IsPlayingFileAsMicrophone(int channel) override { return -1; } - int StartRecordingPlayout(int channel, - const char* fileNameUTF8, - CodecInst* compression = NULL, - int maxSizeBytes = -1) override { return -1; } - int StopRecordingPlayout(int channel) override { return -1; } - int StartRecordingPlayout(int channel, - OutStream* stream, - CodecInst* compression = NULL) override { - return -1; - } - int StartRecordingMicrophone(const char* fileNameUTF8, - CodecInst* compression = NULL, - int maxSizeBytes = -1) override { return -1; } - int StartRecordingMicrophone(OutStream* stream, - CodecInst* compression = NULL) override { - return -1; - } - int StopRecordingMicrophone() override { return -1; } - - // VoEHardware - int GetNumOfRecordingDevices(int& devices) override { return -1; } - - // Gets the number of audio devices available for playout. - int GetNumOfPlayoutDevices(int& devices) override { return -1; } - - // Gets the name of a specific recording device given by an |index|. - // On Windows Vista/7, it also retrieves an additional unique ID - // (GUID) for the recording device. - int GetRecordingDeviceName(int index, - char strNameUTF8[128], - char strGuidUTF8[128]) override { return -1; } - - // Gets the name of a specific playout device given by an |index|. - // On Windows Vista/7, it also retrieves an additional unique ID - // (GUID) for the playout device. - int GetPlayoutDeviceName(int index, - char strNameUTF8[128], - char strGuidUTF8[128]) override { return -1; } - - // Sets the audio device used for recording. - int SetRecordingDevice( - int index, - StereoChannel recordingChannel = kStereoBoth) override { return -1; } - - // Sets the audio device used for playout. - int SetPlayoutDevice(int index) override { return -1; } - - // Sets the type of audio device layer to use. - int SetAudioDeviceLayer(AudioLayers audioLayer) override { return -1; } - - // Gets the currently used (active) audio device layer. - int GetAudioDeviceLayer(AudioLayers& audioLayer) override { return -1; } - - // Native sample rate controls (samples/sec) - int SetRecordingSampleRate(unsigned int samples_per_sec) override { - return -1; - } - int RecordingSampleRate(unsigned int* samples_per_sec) const override { - return -1; - } - int SetPlayoutSampleRate(unsigned int samples_per_sec) override { - return -1; - } - int PlayoutSampleRate(unsigned int* samples_per_sec) const override { - return -1; - } - - // Queries and controls platform audio effects on Android devices. - bool BuiltInAECIsAvailable() const override { return false; } - int EnableBuiltInAEC(bool enable) override { return -1; } - bool BuiltInAGCIsAvailable() const override { return false; } - int EnableBuiltInAGC(bool enable) override { return -1; } - bool BuiltInNSIsAvailable() const override { return false; } - int EnableBuiltInNS(bool enable) override { return -1; } - - // VoENetwork - int RegisterExternalTransport(int channel, Transport& transport) override { - return -1; - } - int DeRegisterExternalTransport(int channel) override { return -1; } - int ReceivedRTPPacket(int channel, - const void* data, - size_t length) override { return -1; } - int ReceivedRTPPacket(int channel, - const void* data, - size_t length, - const PacketTime& packet_time) override { return -1; } - int ReceivedRTCPPacket(int channel, - const void* data, - size_t length) { return -1; } - - // VoENetEqStats - int GetNetworkStatistics(int channel, NetworkStatistics& stats) override { - EXPECT_EQ(channel, kRecvChannelId); - stats = kRecvNetworkStats; - return 0; - } - int GetDecodingCallStatistics(int channel, - AudioDecodingCallStats* stats) const override { - EXPECT_EQ(channel, kRecvChannelId); - EXPECT_NE(nullptr, stats); - *stats = kRecvAudioDecodingCallStats; - return 0; - } - - // VoERTP_RTCP - int SetLocalSSRC(int channel, unsigned int ssrc) override { return -1; } - int GetLocalSSRC(int channel, unsigned int& ssrc) override { - EXPECT_EQ(channel, kSendChannelId); - ssrc = 0; - return 0; - } - int GetRemoteSSRC(int channel, unsigned int& ssrc) override { - EXPECT_EQ(channel, kRecvChannelId); - ssrc = 0; - return 0; - } - int SetSendAudioLevelIndicationStatus(int channel, - bool enable, - unsigned char id = 1) override { - return -1; - } - int SetSendAbsoluteSenderTimeStatus(int channel, - bool enable, - unsigned char id) override { return -1; } - int SetReceiveAbsoluteSenderTimeStatus(int channel, - bool enable, - unsigned char id) override { - return -1; - } - int SetRTCPStatus(int channel, bool enable) override { return -1; } - int GetRTCPStatus(int channel, bool& enabled) override { return -1; } - int SetRTCP_CNAME(int channel, const char cName[256]) override { return -1; } - int GetRTCP_CNAME(int channel, char cName[256]) { return -1; } - int GetRemoteRTCP_CNAME(int channel, char cName[256]) override { return -1; } - int GetRemoteRTCPData(int channel, - unsigned int& NTPHigh, - unsigned int& NTPLow, - unsigned int& timestamp, - unsigned int& playoutTimestamp, - unsigned int* jitter = NULL, - unsigned short* fractionLost = NULL) override { - return -1; - } - int GetRTPStatistics(int channel, - unsigned int& averageJitterMs, - unsigned int& maxJitterMs, - unsigned int& discardedPackets) override { return -1; } - int GetRTCPStatistics(int channel, CallStatistics& stats) override { - if (channel == kSendChannelId) { - stats = kSendCallStats; - } else { - EXPECT_EQ(channel, kRecvChannelId); - stats = kRecvCallStats; - } - return 0; - } - int GetRemoteRTCPReportBlocks( - int channel, - std::vector* receive_blocks) override { - EXPECT_EQ(channel, kSendChannelId); - EXPECT_NE(receive_blocks, nullptr); - EXPECT_EQ(receive_blocks->size(), 0u); - webrtc::ReportBlock block = kSendReportBlock; - receive_blocks->push_back(block); // Has wrong SSRC. - block.source_SSRC = kSendSsrc; - receive_blocks->push_back(block); // Correct block. - block.fraction_lost = 0; - receive_blocks->push_back(block); // Duplicate SSRC, bad fraction_lost. - return 0; - } - int SetNACKStatus(int channel, bool enable, int maxNoPackets) override { - return -1; - } - - // VoEVideoSync - int GetPlayoutBufferSize(int& buffer_ms) override { return -1; } - int SetMinimumPlayoutDelay(int channel, int delay_ms) override { return -1; } - int GetDelayEstimate(int channel, - int* jitter_buffer_delay_ms, - int* playout_buffer_delay_ms) override { - EXPECT_EQ(channel, kRecvChannelId); - *jitter_buffer_delay_ms = kRecvJitterBufferDelay; - *playout_buffer_delay_ms = kRecvPlayoutBufferDelay; - return 0; - } - int GetLeastRequiredDelayMs(int channel) const override { return -1; } - int SetInitTimestamp(int channel, unsigned int timestamp) override { - return -1; - } - int SetInitSequenceNumber(int channel, short sequenceNumber) override { - return -1; - } - int GetPlayoutTimestamp(int channel, unsigned int& timestamp) override { - return -1; - } - int GetRtpRtcp(int channel, - RtpRtcp** rtpRtcpModule, - RtpReceiver** rtp_receiver) override { return -1; } - - // VoEVolumeControl - int SetSpeakerVolume(unsigned int volume) override { return -1; } - int GetSpeakerVolume(unsigned int& volume) override { return -1; } - int SetMicVolume(unsigned int volume) override { return -1; } - int GetMicVolume(unsigned int& volume) override { return -1; } - int SetInputMute(int channel, bool enable) override { return -1; } - int GetInputMute(int channel, bool& enabled) override { return -1; } - int GetSpeechInputLevel(unsigned int& level) override { return -1; } - int GetSpeechOutputLevel(int channel, unsigned int& level) override { - return -1; - } - int GetSpeechInputLevelFullRange(unsigned int& level) override { - level = kSendSpeechInputLevel; - return 0; - } - int GetSpeechOutputLevelFullRange(int channel, - unsigned int& level) override { - EXPECT_EQ(channel, kRecvChannelId); - level = kRecvSpeechOutputLevel; - return 0; - } - int SetChannelOutputVolumeScaling(int channel, float scaling) override { - return -1; - } - int GetChannelOutputVolumeScaling(int channel, float& scaling) override { - return -1; - } - int SetOutputVolumePan(int channel, float left, float right) override { - return -1; - } - int GetOutputVolumePan(int channel, float& left, float& right) override { - return -1; - } -}; -} // namespace test -} // namespace webrtc - -#endif // WEBRTC_AUDIO_FAKE_VOICE_ENGINE_H_ diff --git a/webrtc/test/mock_voice_engine.h b/webrtc/test/mock_voice_engine.h new file mode 100644 index 0000000000..77b4ec8c01 --- /dev/null +++ b/webrtc/test/mock_voice_engine.h @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ +#define WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ + +#include "testing/gmock/include/gmock/gmock.h" +#include "webrtc/voice_engine/voice_engine_impl.h" + +namespace webrtc { +namespace test { + +// NOTE: This class inherits from VoiceEngineImpl so that its clients will be +// able to get the various interfaces as usual, via T::GetInterface(). +class MockVoiceEngine final : public VoiceEngineImpl { + public: + MockVoiceEngine() : VoiceEngineImpl(new Config(), true) { + // Increase ref count so this object isn't automatically deleted whenever + // interfaces are Release():d. + ++_ref_count; + } + ~MockVoiceEngine() override { + // Decrease ref count before base class d-tor is called; otherwise it will + // trigger an assertion. + --_ref_count; + } + + // VoEAudioProcessing + MOCK_METHOD2(SetNsStatus, int(bool enable, NsModes mode)); + MOCK_METHOD2(GetNsStatus, int(bool& enabled, NsModes& mode)); + MOCK_METHOD2(SetAgcStatus, int(bool enable, AgcModes mode)); + MOCK_METHOD2(GetAgcStatus, int(bool& enabled, AgcModes& mode)); + MOCK_METHOD1(SetAgcConfig, int(AgcConfig config)); + MOCK_METHOD1(GetAgcConfig, int(AgcConfig& config)); + MOCK_METHOD2(SetEcStatus, int(bool enable, EcModes mode)); + MOCK_METHOD2(GetEcStatus, int(bool& enabled, EcModes& mode)); + MOCK_METHOD1(EnableDriftCompensation, int(bool enable)); + MOCK_METHOD0(DriftCompensationEnabled, bool()); + MOCK_METHOD1(SetDelayOffsetMs, void(int offset)); + MOCK_METHOD0(DelayOffsetMs, int()); + MOCK_METHOD2(SetAecmMode, int(AecmModes mode, bool enableCNG)); + MOCK_METHOD2(GetAecmMode, int(AecmModes& mode, bool& enabledCNG)); + MOCK_METHOD1(EnableHighPassFilter, int(bool enable)); + MOCK_METHOD0(IsHighPassFilterEnabled, bool()); + MOCK_METHOD3(SetRxNsStatus, int(int channel, bool enable, NsModes mode)); + MOCK_METHOD3(GetRxNsStatus, int(int channel, bool& enabled, NsModes& mode)); + MOCK_METHOD3(SetRxAgcStatus, int(int channel, bool enable, AgcModes mode)); + MOCK_METHOD3(GetRxAgcStatus, int(int channel, bool& enabled, AgcModes& mode)); + MOCK_METHOD2(SetRxAgcConfig, int(int channel, AgcConfig config)); + MOCK_METHOD2(GetRxAgcConfig, int(int channel, AgcConfig& config)); + MOCK_METHOD2(RegisterRxVadObserver, + int(int channel, VoERxVadCallback& observer)); + MOCK_METHOD1(DeRegisterRxVadObserver, int(int channel)); + MOCK_METHOD1(VoiceActivityIndicator, int(int channel)); + MOCK_METHOD1(SetEcMetricsStatus, int(bool enable)); + MOCK_METHOD1(GetEcMetricsStatus, int(bool& enabled)); + MOCK_METHOD4(GetEchoMetrics, int(int& ERL, int& ERLE, int& RERL, int& A_NLP)); + MOCK_METHOD3(GetEcDelayMetrics, + int(int& delay_median, + int& delay_std, + float& fraction_poor_delays)); + MOCK_METHOD1(StartDebugRecording, int(const char* fileNameUTF8)); + MOCK_METHOD1(StartDebugRecording, int(FILE* file_handle)); + MOCK_METHOD0(StopDebugRecording, int()); + MOCK_METHOD1(SetTypingDetectionStatus, int(bool enable)); + MOCK_METHOD1(GetTypingDetectionStatus, int(bool& enabled)); + MOCK_METHOD1(TimeSinceLastTyping, int(int& seconds)); + MOCK_METHOD5(SetTypingDetectionParameters, + int(int timeWindow, + int costPerTyping, + int reportingThreshold, + int penaltyDecay, + int typeEventDelay)); + MOCK_METHOD1(EnableStereoChannelSwapping, void(bool enable)); + MOCK_METHOD0(IsStereoChannelSwappingEnabled, bool()); + + // VoEBase + MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer)); + MOCK_METHOD0(DeRegisterVoiceEngineObserver, int()); + MOCK_METHOD2(Init, + int(AudioDeviceModule* external_adm, + AudioProcessing* audioproc)); + MOCK_METHOD0(audio_processing, AudioProcessing*()); + MOCK_METHOD0(Terminate, int()); + MOCK_METHOD0(CreateChannel, int()); + MOCK_METHOD1(CreateChannel, int(const Config& config)); + MOCK_METHOD1(DeleteChannel, int(int channel)); + MOCK_METHOD1(StartReceive, int(int channel)); + MOCK_METHOD1(StopReceive, int(int channel)); + MOCK_METHOD1(StartPlayout, int(int channel)); + MOCK_METHOD1(StopPlayout, int(int channel)); + MOCK_METHOD1(StartSend, int(int channel)); + MOCK_METHOD1(StopSend, int(int channel)); + MOCK_METHOD1(GetVersion, int(char version[1024])); + MOCK_METHOD0(LastError, int()); + MOCK_METHOD0(audio_transport, AudioTransport*()); + MOCK_METHOD2(AssociateSendChannel, + int(int channel, int accociate_send_channel)); + + // VoECodec + MOCK_METHOD0(NumOfCodecs, int()); + MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec)); + MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec)); + MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec)); + MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps)); + MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec)); + MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec)); + MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec)); + MOCK_METHOD3(SetSendCNPayloadType, + int(int channel, int type, PayloadFrequencies frequency)); + MOCK_METHOD2(SetFECStatus, int(int channel, bool enable)); + MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled)); + MOCK_METHOD4(SetVADStatus, + int(int channel, bool enable, VadModes mode, bool disableDTX)); + MOCK_METHOD4( + GetVADStatus, + int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX)); + MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz)); + MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx)); + MOCK_METHOD0(GetEventLog, RtcEventLog*()); + + // VoEDtmf + MOCK_METHOD5(SendTelephoneEvent, + int(int channel, + int eventCode, + bool outOfBand, + int lengthMs, + int attenuationDb)); + MOCK_METHOD2(SetSendTelephoneEventPayloadType, + int(int channel, unsigned char type)); + MOCK_METHOD2(GetSendTelephoneEventPayloadType, + int(int channel, unsigned char& type)); + MOCK_METHOD2(SetDtmfFeedbackStatus, int(bool enable, bool directFeedback)); + MOCK_METHOD2(GetDtmfFeedbackStatus, int(bool& enabled, bool& directFeedback)); + MOCK_METHOD3(PlayDtmfTone, + int(int eventCode, int lengthMs, int attenuationDb)); + + // VoEExternalMedia + MOCK_METHOD3(RegisterExternalMediaProcessing, + int(int channel, + ProcessingTypes type, + VoEMediaProcess& processObject)); + MOCK_METHOD2(DeRegisterExternalMediaProcessing, + int(int channel, ProcessingTypes type)); + MOCK_METHOD3(GetAudioFrame, + int(int channel, int desired_sample_rate_hz, AudioFrame* frame)); + MOCK_METHOD2(SetExternalMixing, int(int channel, bool enable)); + + // VoEFile + MOCK_METHOD7(StartPlayingFileLocally, + int(int channel, + const char fileNameUTF8[1024], + bool loop, + FileFormats format, + float volumeScaling, + int startPointMs, + int stopPointMs)); + MOCK_METHOD6(StartPlayingFileLocally, + int(int channel, + InStream* stream, + FileFormats format, + float volumeScaling, + int startPointMs, + int stopPointMs)); + MOCK_METHOD1(StopPlayingFileLocally, int(int channel)); + MOCK_METHOD1(IsPlayingFileLocally, int(int channel)); + MOCK_METHOD6(StartPlayingFileAsMicrophone, + int(int channel, + const char fileNameUTF8[1024], + bool loop, + bool mixWithMicrophone, + FileFormats format, + float volumeScaling)); + MOCK_METHOD5(StartPlayingFileAsMicrophone, + int(int channel, + InStream* stream, + bool mixWithMicrophone, + FileFormats format, + float volumeScaling)); + MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel)); + MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel)); + MOCK_METHOD4(StartRecordingPlayout, + int(int channel, + const char* fileNameUTF8, + CodecInst* compression, + int maxSizeBytes)); + MOCK_METHOD1(StopRecordingPlayout, int(int channel)); + MOCK_METHOD3(StartRecordingPlayout, + int(int channel, OutStream* stream, CodecInst* compression)); + MOCK_METHOD3(StartRecordingMicrophone, + int(const char* fileNameUTF8, + CodecInst* compression, + int maxSizeBytes)); + MOCK_METHOD2(StartRecordingMicrophone, + int(OutStream* stream, CodecInst* compression)); + MOCK_METHOD0(StopRecordingMicrophone, int()); + + // VoEHardware + MOCK_METHOD1(GetNumOfRecordingDevices, int(int& devices)); + MOCK_METHOD1(GetNumOfPlayoutDevices, int(int& devices)); + MOCK_METHOD3(GetRecordingDeviceName, + int(int index, char strNameUTF8[128], char strGuidUTF8[128])); + MOCK_METHOD3(GetPlayoutDeviceName, + int(int index, char strNameUTF8[128], char strGuidUTF8[128])); + MOCK_METHOD2(SetRecordingDevice, + int(int index, StereoChannel recordingChannel)); + MOCK_METHOD1(SetPlayoutDevice, int(int index)); + MOCK_METHOD1(SetAudioDeviceLayer, int(AudioLayers audioLayer)); + MOCK_METHOD1(GetAudioDeviceLayer, int(AudioLayers& audioLayer)); + MOCK_METHOD1(SetRecordingSampleRate, int(unsigned int samples_per_sec)); + MOCK_CONST_METHOD1(RecordingSampleRate, int(unsigned int* samples_per_sec)); + MOCK_METHOD1(SetPlayoutSampleRate, int(unsigned int samples_per_sec)); + MOCK_CONST_METHOD1(PlayoutSampleRate, int(unsigned int* samples_per_sec)); + MOCK_CONST_METHOD0(BuiltInAECIsAvailable, bool()); + MOCK_METHOD1(EnableBuiltInAEC, int(bool enable)); + MOCK_CONST_METHOD0(BuiltInAGCIsAvailable, bool()); + MOCK_METHOD1(EnableBuiltInAGC, int(bool enable)); + MOCK_CONST_METHOD0(BuiltInNSIsAvailable, bool()); + MOCK_METHOD1(EnableBuiltInNS, int(bool enable)); + + // VoENetEqStats + MOCK_METHOD2(GetNetworkStatistics, + int(int channel, NetworkStatistics& stats)); + MOCK_CONST_METHOD2(GetDecodingCallStatistics, + int(int channel, AudioDecodingCallStats* stats)); + + // VoENetwork + MOCK_METHOD2(RegisterExternalTransport, + int(int channel, Transport& transport)); + MOCK_METHOD1(DeRegisterExternalTransport, int(int channel)); + MOCK_METHOD3(ReceivedRTPPacket, + int(int channel, const void* data, size_t length)); + MOCK_METHOD4(ReceivedRTPPacket, + int(int channel, + const void* data, + size_t length, + const PacketTime& packet_time)); + MOCK_METHOD3(ReceivedRTCPPacket, + int(int channel, const void* data, size_t length)); + + // VoERTP_RTCP + MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc)); + MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc)); + MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc)); + MOCK_METHOD3(SetSendAudioLevelIndicationStatus, + int(int channel, bool enable, unsigned char id)); + MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus, + int(int channel, bool enable, unsigned char id)); + MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus, + int(int channel, bool enable, unsigned char id)); + MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus, + int(int channel, bool enable, unsigned char id)); + MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable)); + MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled)); + MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256])); + MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256])); + MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256])); + MOCK_METHOD7(GetRemoteRTCPData, + int(int channel, + unsigned int& NTPHigh, + unsigned int& NTPLow, + unsigned int& timestamp, + unsigned int& playoutTimestamp, + unsigned int* jitter, + unsigned short* fractionLost)); + MOCK_METHOD4(GetRTPStatistics, + int(int channel, + unsigned int& averageJitterMs, + unsigned int& maxJitterMs, + unsigned int& discardedPackets)); + MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats)); + MOCK_METHOD2(GetRemoteRTCPReportBlocks, + int(int channel, std::vector* receive_blocks)); + MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype)); + MOCK_METHOD3(GetREDStatus, + int(int channel, bool& enable, int& redPayloadtype)); + MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets)); + + // VoEVideoSync + MOCK_METHOD1(GetPlayoutBufferSize, int(int& buffer_ms)); + MOCK_METHOD2(SetMinimumPlayoutDelay, int(int channel, int delay_ms)); + MOCK_METHOD3(GetDelayEstimate, + int(int channel, + int* jitter_buffer_delay_ms, + int* playout_buffer_delay_ms)); + MOCK_CONST_METHOD1(GetLeastRequiredDelayMs, int(int channel)); + MOCK_METHOD2(SetInitTimestamp, int(int channel, unsigned int timestamp)); + MOCK_METHOD2(SetInitSequenceNumber, int(int channel, short sequenceNumber)); + MOCK_METHOD2(GetPlayoutTimestamp, int(int channel, unsigned int& timestamp)); + MOCK_METHOD3(GetRtpRtcp, + int(int channel, + RtpRtcp** rtpRtcpModule, + RtpReceiver** rtp_receiver)); + + // VoEVolumeControl + MOCK_METHOD1(SetSpeakerVolume, int(unsigned int volume)); + MOCK_METHOD1(GetSpeakerVolume, int(unsigned int& volume)); + MOCK_METHOD1(SetMicVolume, int(unsigned int volume)); + MOCK_METHOD1(GetMicVolume, int(unsigned int& volume)); + MOCK_METHOD2(SetInputMute, int(int channel, bool enable)); + MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled)); + MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level)); + MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level)); + MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level)); + MOCK_METHOD2(GetSpeechOutputLevelFullRange, + int(int channel, unsigned& level)); + MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling)); + MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling)); + MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right)); + MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right)); +}; +} // namespace test +} // namespace webrtc + +#endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ diff --git a/webrtc/test/webrtc_test_common.gyp b/webrtc/test/webrtc_test_common.gyp index d075cb470b..83f38ea1a0 100644 --- a/webrtc/test/webrtc_test_common.gyp +++ b/webrtc/test/webrtc_test_common.gyp @@ -32,13 +32,12 @@ 'fake_encoder.h', 'fake_network_pipe.cc', 'fake_network_pipe.h', - 'fake_voice_engine.cc', - 'fake_voice_engine.h', 'frame_generator_capturer.cc', 'frame_generator_capturer.h', 'layer_filtering_transport.cc', 'layer_filtering_transport.h', 'mock_transport.h', + 'mock_voice_engine.h', 'null_transport.cc', 'null_transport.h', 'random.cc', @@ -62,6 +61,7 @@ }], ], 'dependencies': [ + '<(DEPTH)/testing/gmock.gyp:gmock', '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/third_party/gflags/gflags.gyp:gflags', '<(webrtc_root)/base/base.gyp:rtc_base', diff --git a/webrtc/voice_engine/include/voe_rtp_rtcp.h b/webrtc/voice_engine/include/voe_rtp_rtcp.h index 6d17501772..dd3609aa00 100644 --- a/webrtc/voice_engine/include/voe_rtp_rtcp.h +++ b/webrtc/voice_engine/include/voe_rtp_rtcp.h @@ -201,20 +201,6 @@ class WEBRTC_DLLEXPORT VoERTP_RTCP { return -1; } - // Sets the Forward Error Correction (FEC) status on a specific |channel|. - // TODO(minyue): Remove SetFECStatus() when SetFECStatus() is replaced by - // SetREDStatus() in fakewebrtcvoiceengine. - virtual int SetFECStatus(int channel, bool enable, int redPayloadtype = -1) { - return SetREDStatus(channel, enable, redPayloadtype); - }; - - // Gets the FEC status on a specific |channel|. - // TODO(minyue): Remove GetFECStatus() when GetFECStatus() is replaced by - // GetREDStatus() in fakewebrtcvoiceengine. - virtual int GetFECStatus(int channel, bool& enabled, int& redPayloadtype) { - return SetREDStatus(channel, enabled, redPayloadtype); - } - // This function enables Negative Acknowledgment (NACK) using RTCP, // implemented based on RFC 4585. NACK retransmits RTP packets if lost on // the network. This creates a lossless transport at the expense of delay.