2015-10-16 14:35:07 -07:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-12-01 11:26:34 +01:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2015-10-16 14:35:07 -07:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#include "webrtc/audio/audio_send_stream.h"
|
2015-11-06 15:34:49 -08:00
|
|
|
#include "webrtc/audio/audio_state.h"
|
2015-10-27 03:35:21 -07:00
|
|
|
#include "webrtc/audio/conversion.h"
|
2016-05-11 06:01:13 -07:00
|
|
|
#include "webrtc/modules/congestion_controller/include/mock/mock_congestion_controller.h"
|
2016-02-23 13:30:42 +01:00
|
|
|
#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
|
2015-12-07 10:26:18 +01:00
|
|
|
#include "webrtc/modules/pacing/paced_sender.h"
|
2016-02-08 14:31:30 +01:00
|
|
|
#include "webrtc/modules/remote_bitrate_estimator/include/mock/mock_remote_bitrate_estimator.h"
|
2015-11-25 08:16:52 -08:00
|
|
|
#include "webrtc/test/mock_voe_channel_proxy.h"
|
2015-11-03 10:15:49 +01:00
|
|
|
#include "webrtc/test/mock_voice_engine.h"
|
2015-10-16 14:35:07 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2015-10-27 03:35:21 -07:00
|
|
|
namespace test {
|
2015-11-03 10:15:49 +01:00
|
|
|
namespace {
|
|
|
|
|
|
2015-11-16 07:34:50 -08:00
|
|
|
using testing::_;
|
|
|
|
|
using testing::Return;
|
|
|
|
|
|
2015-11-03 10:15:49 +01:00
|
|
|
const int kChannelId = 1;
|
|
|
|
|
const uint32_t kSsrc = 1234;
|
2015-11-16 07:34:50 -08:00
|
|
|
const char* kCName = "foo_name";
|
|
|
|
|
const int kAudioLevelId = 2;
|
|
|
|
|
const int kAbsSendTimeId = 3;
|
2015-12-07 10:26:18 +01:00
|
|
|
const int kTransportSequenceNumberId = 4;
|
2015-11-06 15:34:49 -08:00
|
|
|
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};
|
Misc. small cleanups.
* Better param names
* Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases.
* Use arraysize()
* Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers
* reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead
* Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition
* Fix indenting
* Use uint32_t for timestamps (matching how it's already a uint32_t in most places)
* Spelling
* RTC_CHECK_EQ(expected, actual)
* Rewrap
* Use .empty()
* Be more pedantic about matching int/int32_t/
* Remove pointless consts on input parameters to functions
* Add missing sanity checks
All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first.
BUG=none
TEST=none
Review URL: https://codereview.webrtc.org/1534193008
Cr-Commit-Position: refs/heads/master@{#11191}
2016-01-08 13:50:27 -08:00
|
|
|
const CodecInst kCodecInst = {-121, "codec_name_send", 48000, -231, 0, -671};
|
2015-11-06 15:34:49 -08:00
|
|
|
const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354};
|
2015-12-04 15:22:19 +01:00
|
|
|
const int kTelephoneEventPayloadType = 123;
|
2016-03-11 03:06:41 -08:00
|
|
|
const int kTelephoneEventCode = 45;
|
|
|
|
|
const int kTelephoneEventDuration = 6789;
|
2015-11-06 15:34:49 -08:00
|
|
|
|
|
|
|
|
struct ConfigHelper {
|
2015-12-07 10:26:18 +01:00
|
|
|
ConfigHelper()
|
2016-02-08 14:31:30 +01:00
|
|
|
: simulated_clock_(123456),
|
|
|
|
|
stream_config_(nullptr),
|
|
|
|
|
congestion_controller_(&simulated_clock_,
|
|
|
|
|
&bitrate_observer_,
|
|
|
|
|
&remote_bitrate_observer_) {
|
2015-11-25 08:16:52 -08:00
|
|
|
using testing::Invoke;
|
2015-11-16 07:34:50 -08:00
|
|
|
using testing::StrEq;
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
EXPECT_CALL(voice_engine_,
|
2015-11-16 07:34:50 -08:00
|
|
|
RegisterVoiceEngineObserver(_)).WillOnce(Return(0));
|
2015-11-06 15:34:49 -08:00
|
|
|
EXPECT_CALL(voice_engine_,
|
2015-11-16 07:34:50 -08:00
|
|
|
DeRegisterVoiceEngineObserver()).WillOnce(Return(0));
|
2015-11-06 15:34:49 -08:00
|
|
|
AudioState::Config config;
|
|
|
|
|
config.voice_engine = &voice_engine_;
|
|
|
|
|
audio_state_ = AudioState::Create(config);
|
2015-11-16 07:34:50 -08:00
|
|
|
|
2015-11-25 08:16:52 -08:00
|
|
|
EXPECT_CALL(voice_engine_, ChannelProxyFactory(kChannelId))
|
|
|
|
|
.WillOnce(Invoke([this](int channel_id) {
|
|
|
|
|
EXPECT_FALSE(channel_proxy_);
|
|
|
|
|
channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>();
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, SetRTCPStatus(true)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kSsrc)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, SetRTCP_CNAME(StrEq(kCName))).Times(1);
|
2016-06-14 10:02:41 -07:00
|
|
|
EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 10)).Times(1);
|
2015-11-27 10:46:42 -08:00
|
|
|
EXPECT_CALL(*channel_proxy_,
|
|
|
|
|
SetSendAbsoluteSenderTimeStatus(true, kAbsSendTimeId)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_,
|
|
|
|
|
SetSendAudioLevelIndicationStatus(true, kAudioLevelId)).Times(1);
|
2015-12-07 10:26:18 +01:00
|
|
|
EXPECT_CALL(*channel_proxy_, EnableSendTransportSequenceNumber(
|
|
|
|
|
kTransportSequenceNumberId))
|
|
|
|
|
.Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_,
|
2016-02-01 04:39:55 -08:00
|
|
|
RegisterSenderCongestionControlObjects(
|
2015-12-07 10:26:18 +01:00
|
|
|
congestion_controller_.pacer(),
|
|
|
|
|
congestion_controller_.GetTransportFeedbackObserver(),
|
|
|
|
|
congestion_controller_.packet_router()))
|
|
|
|
|
.Times(1);
|
2016-02-01 04:39:55 -08:00
|
|
|
EXPECT_CALL(*channel_proxy_, ResetCongestionControlObjects())
|
2015-12-07 10:26:18 +01:00
|
|
|
.Times(1);
|
2016-04-29 00:57:13 -07:00
|
|
|
EXPECT_CALL(*channel_proxy_, RegisterExternalTransport(nullptr))
|
|
|
|
|
.Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, DeRegisterExternalTransport())
|
|
|
|
|
.Times(1);
|
2015-11-25 08:16:52 -08:00
|
|
|
return channel_proxy_;
|
|
|
|
|
}));
|
2015-11-06 15:34:49 -08:00
|
|
|
stream_config_.voe_channel_id = kChannelId;
|
|
|
|
|
stream_config_.rtp.ssrc = kSsrc;
|
2016-06-14 10:02:41 -07:00
|
|
|
stream_config_.rtp.nack.rtp_history_ms = 200;
|
2015-11-16 07:34:50 -08:00
|
|
|
stream_config_.rtp.c_name = kCName;
|
|
|
|
|
stream_config_.rtp.extensions.push_back(
|
2016-05-26 11:24:55 -07:00
|
|
|
RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
|
2015-11-16 07:34:50 -08:00
|
|
|
stream_config_.rtp.extensions.push_back(
|
2016-05-26 11:24:55 -07:00
|
|
|
RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId));
|
2015-12-07 10:26:18 +01:00
|
|
|
stream_config_.rtp.extensions.push_back(RtpExtension(
|
2016-05-26 11:24:55 -07:00
|
|
|
RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId));
|
2015-11-06 15:34:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioSendStream::Config& config() { return stream_config_; }
|
|
|
|
|
rtc::scoped_refptr<AudioState> audio_state() { return audio_state_; }
|
2015-12-07 10:26:18 +01:00
|
|
|
CongestionController* congestion_controller() {
|
|
|
|
|
return &congestion_controller_;
|
|
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
|
2015-12-04 15:22:19 +01:00
|
|
|
void SetupMockForSendTelephoneEvent() {
|
|
|
|
|
EXPECT_TRUE(channel_proxy_);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_,
|
|
|
|
|
SetSendTelephoneEventPayloadType(kTelephoneEventPayloadType))
|
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
EXPECT_CALL(*channel_proxy_,
|
|
|
|
|
SendTelephoneEventOutband(kTelephoneEventCode, kTelephoneEventDuration))
|
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
void SetupMockForGetStats() {
|
2015-11-16 07:34:50 -08:00
|
|
|
using testing::DoAll;
|
|
|
|
|
using testing::SetArgReferee;
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
std::vector<ReportBlock> 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.
|
|
|
|
|
|
2015-11-27 10:46:42 -08:00
|
|
|
EXPECT_TRUE(channel_proxy_);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, GetRTCPStatistics())
|
|
|
|
|
.WillRepeatedly(Return(kCallStats));
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, GetRemoteRTCPReportBlocks())
|
|
|
|
|
.WillRepeatedly(Return(report_blocks));
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
EXPECT_CALL(voice_engine_, GetSendCodec(kChannelId, _))
|
|
|
|
|
.WillRepeatedly(DoAll(SetArgReferee<1>(kCodecInst), Return(0)));
|
|
|
|
|
EXPECT_CALL(voice_engine_, GetSpeechInputLevelFullRange(_))
|
|
|
|
|
.WillRepeatedly(DoAll(SetArgReferee<0>(kSpeechInputLevel), Return(0)));
|
|
|
|
|
EXPECT_CALL(voice_engine_, GetEcMetricsStatus(_))
|
|
|
|
|
.WillRepeatedly(DoAll(SetArgReferee<0>(true), Return(0)));
|
|
|
|
|
EXPECT_CALL(voice_engine_, GetEchoMetrics(_, _, _, _))
|
|
|
|
|
.WillRepeatedly(DoAll(SetArgReferee<0>(kEchoReturnLoss),
|
|
|
|
|
SetArgReferee<1>(kEchoReturnLossEnhancement),
|
|
|
|
|
Return(0)));
|
|
|
|
|
EXPECT_CALL(voice_engine_, GetEcDelayMetrics(_, _, _))
|
|
|
|
|
.WillRepeatedly(DoAll(SetArgReferee<0>(kEchoDelayMedian),
|
|
|
|
|
SetArgReferee<1>(kEchoDelayStdDev), Return(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2016-02-08 14:31:30 +01:00
|
|
|
SimulatedClock simulated_clock_;
|
2015-11-16 07:34:50 -08:00
|
|
|
testing::StrictMock<MockVoiceEngine> voice_engine_;
|
2015-11-06 15:34:49 -08:00
|
|
|
rtc::scoped_refptr<AudioState> audio_state_;
|
|
|
|
|
AudioSendStream::Config stream_config_;
|
2015-11-25 08:16:52 -08:00
|
|
|
testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr;
|
2016-05-11 06:01:13 -07:00
|
|
|
testing::NiceMock<MockCongestionObserver> bitrate_observer_;
|
2016-02-08 14:31:30 +01:00
|
|
|
testing::NiceMock<MockRemoteBitrateObserver> remote_bitrate_observer_;
|
2015-12-07 10:26:18 +01:00
|
|
|
CongestionController congestion_controller_;
|
2015-11-06 15:34:49 -08:00
|
|
|
};
|
2015-11-03 10:15:49 +01:00
|
|
|
} // namespace
|
2015-10-16 14:35:07 -07:00
|
|
|
|
|
|
|
|
TEST(AudioSendStreamTest, ConfigToString) {
|
|
|
|
|
AudioSendStream::Config config(nullptr);
|
2015-11-03 10:15:49 +01:00
|
|
|
config.rtp.ssrc = kSsrc;
|
2015-10-16 14:35:07 -07:00
|
|
|
config.rtp.extensions.push_back(
|
2016-05-26 11:24:55 -07:00
|
|
|
RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId));
|
2015-11-16 07:34:50 -08:00
|
|
|
config.rtp.c_name = kCName;
|
2015-11-03 10:15:49 +01:00
|
|
|
config.voe_channel_id = kChannelId;
|
2015-10-16 14:35:07 -07:00
|
|
|
config.cng_payload_type = 42;
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(
|
2016-05-26 11:24:55 -07:00
|
|
|
"{rtp: {ssrc: 1234, extensions: [{uri: "
|
2015-11-16 07:34:50 -08:00
|
|
|
"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time, id: 3}], "
|
2016-06-14 10:02:41 -07:00
|
|
|
"nack: {rtp_history_ms: 0}, c_name: foo_name}, voe_channel_id: 1, "
|
|
|
|
|
"cng_payload_type: 42}",
|
2015-10-27 03:35:21 -07:00
|
|
|
config.ToString());
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioSendStreamTest, ConstructDestruct) {
|
2015-11-06 15:34:49 -08:00
|
|
|
ConfigHelper helper;
|
2015-12-07 10:26:18 +01:00
|
|
|
internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
|
|
|
|
|
helper.congestion_controller());
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
2015-10-27 03:35:21 -07:00
|
|
|
|
2015-12-04 15:22:19 +01:00
|
|
|
TEST(AudioSendStreamTest, SendTelephoneEvent) {
|
|
|
|
|
ConfigHelper helper;
|
2015-12-07 10:26:18 +01:00
|
|
|
internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
|
|
|
|
|
helper.congestion_controller());
|
2015-12-04 15:22:19 +01:00
|
|
|
helper.SetupMockForSendTelephoneEvent();
|
|
|
|
|
EXPECT_TRUE(send_stream.SendTelephoneEvent(kTelephoneEventPayloadType,
|
|
|
|
|
kTelephoneEventCode, kTelephoneEventDuration));
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-27 03:35:21 -07:00
|
|
|
TEST(AudioSendStreamTest, GetStats) {
|
2015-11-06 15:34:49 -08:00
|
|
|
ConfigHelper helper;
|
2015-12-07 10:26:18 +01:00
|
|
|
internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
|
|
|
|
|
helper.congestion_controller());
|
2015-11-06 15:34:49 -08:00
|
|
|
helper.SetupMockForGetStats();
|
2015-10-27 03:35:21 -07:00
|
|
|
AudioSendStream::Stats stats = send_stream.GetStats();
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(kSsrc, stats.local_ssrc);
|
|
|
|
|
EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesSent), stats.bytes_sent);
|
|
|
|
|
EXPECT_EQ(kCallStats.packetsSent, stats.packets_sent);
|
|
|
|
|
EXPECT_EQ(static_cast<int32_t>(kReportBlock.cumulative_num_packets_lost),
|
2015-10-27 03:35:21 -07:00
|
|
|
stats.packets_lost);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(Q8ToFloat(kReportBlock.fraction_lost), stats.fraction_lost);
|
|
|
|
|
EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name);
|
|
|
|
|
EXPECT_EQ(static_cast<int32_t>(kReportBlock.extended_highest_sequence_number),
|
2015-10-27 03:35:21 -07:00
|
|
|
stats.ext_seqnum);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(static_cast<int32_t>(kReportBlock.interarrival_jitter /
|
|
|
|
|
(kCodecInst.plfreq / 1000)),
|
|
|
|
|
stats.jitter_ms);
|
|
|
|
|
EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms);
|
|
|
|
|
EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level);
|
2015-10-27 03:35:21 -07:00
|
|
|
EXPECT_EQ(-1, stats.aec_quality_min);
|
2015-11-03 10:15:49 +01:00
|
|
|
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);
|
2015-10-27 03:35:21 -07:00
|
|
|
EXPECT_FALSE(stats.typing_noise_detected);
|
|
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
|
|
|
|
|
TEST(AudioSendStreamTest, GetStatsTypingNoiseDetected) {
|
|
|
|
|
ConfigHelper helper;
|
2015-12-07 10:26:18 +01:00
|
|
|
internal::AudioSendStream send_stream(helper.config(), helper.audio_state(),
|
|
|
|
|
helper.congestion_controller());
|
2015-11-06 15:34:49 -08:00
|
|
|
helper.SetupMockForGetStats();
|
|
|
|
|
EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
|
|
|
|
|
|
|
|
|
|
internal::AudioState* internal_audio_state =
|
|
|
|
|
static_cast<internal::AudioState*>(helper.audio_state().get());
|
|
|
|
|
VoiceEngineObserver* voe_observer =
|
|
|
|
|
static_cast<VoiceEngineObserver*>(internal_audio_state);
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_WARNING);
|
|
|
|
|
EXPECT_TRUE(send_stream.GetStats().typing_noise_detected);
|
|
|
|
|
voe_observer->CallbackOnError(-1, VE_TYPING_NOISE_OFF_WARNING);
|
|
|
|
|
EXPECT_FALSE(send_stream.GetStats().typing_noise_detected);
|
|
|
|
|
}
|
2015-10-27 03:35:21 -07:00
|
|
|
} // namespace test
|
2015-10-16 14:35:07 -07:00
|
|
|
} // namespace webrtc
|