blob: 59963da8464a05db20170e3115ddb64dc60a4f7c [file] [log] [blame]
Stefan Holmer8bffba72015-09-23 15:53:52 +02001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
kwiberg1c07c702017-03-27 07:15:49 -070011#include <map>
Fredrik Solenbergea073732015-12-01 11:26:34 +010012#include <string>
stefan3313ec92016-01-21 06:32:43 -080013#include <vector>
Fredrik Solenbergea073732015-12-01 11:26:34 +010014
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/test/mock_audio_mixer.h"
16#include "audio/audio_receive_stream.h"
17#include "audio/conversion.h"
Fredrik Solenberga8b7c7f2018-01-17 11:18:31 +010018#include "audio/mock_voe_channel_proxy.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "call/rtp_stream_receiver_controller.h"
20#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
Fredrik Solenberg2a877972017-12-15 16:42:15 +010021#include "modules/audio_device/include/mock_audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "modules/audio_processing/include/mock_audio_processing.h"
23#include "modules/bitrate_controller/include/mock/mock_bitrate_controller.h"
24#include "modules/pacing/packet_router.h"
25#include "modules/rtp_rtcp/source/byte_io.h"
26#include "test/gtest.h"
27#include "test/mock_audio_decoder_factory.h"
Stefan Holmer8bffba72015-09-23 15:53:52 +020028
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010029namespace webrtc {
30namespace test {
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +020031namespace {
32
solenberg3a941542015-11-16 07:34:50 -080033using testing::_;
solenberg217fb662016-06-17 08:30:54 -070034using testing::FloatEq;
solenberg3a941542015-11-16 07:34:50 -080035using testing::Return;
ossu29b1a8d2016-06-13 07:34:51 -070036using testing::ReturnRef;
solenberg3a941542015-11-16 07:34:50 -080037
solenberg566ef242015-11-06 15:34:49 -080038AudioDecodingCallStats MakeAudioDecodeStatsForTest() {
39 AudioDecodingCallStats audio_decode_stats;
40 audio_decode_stats.calls_to_silence_generator = 234;
41 audio_decode_stats.calls_to_neteq = 567;
42 audio_decode_stats.decoded_normal = 890;
43 audio_decode_stats.decoded_plc = 123;
44 audio_decode_stats.decoded_cng = 456;
45 audio_decode_stats.decoded_plc_cng = 789;
henrik.lundin63489782016-09-20 01:47:12 -070046 audio_decode_stats.decoded_muted_output = 987;
solenberg566ef242015-11-06 15:34:49 -080047 return audio_decode_stats;
48}
49
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010050const uint32_t kRemoteSsrc = 1234;
51const uint32_t kLocalSsrc = 5678;
Stefan Holmer3842c5c2016-01-12 13:55:00 +010052const size_t kOneByteExtensionHeaderLength = 4;
53const size_t kOneByteExtensionLength = 4;
solenberg7add0582015-11-20 09:59:34 -080054const int kAudioLevelId = 3;
Stefan Holmer3842c5c2016-01-12 13:55:00 +010055const int kTransportSequenceNumberId = 4;
solenberg566ef242015-11-06 15:34:49 -080056const int kJitterBufferDelay = -7;
57const int kPlayoutBufferDelay = 302;
58const unsigned int kSpeechOutputLevel = 99;
zsteine76bd3a2017-07-14 12:17:49 -070059const double kTotalOutputEnergy = 0.25;
60const double kTotalOutputDuration = 0.5;
61
Yves Gerey665174f2018-06-19 15:03:05 +020062const CallStatistics kCallStats = {345, 678, 901, 234, -12,
63 3456, 7890, 567, 890, 123};
64const CodecInst kCodecInst = {123, "codec_name_recv", 96000, -187, 0, -103};
Gustaf Ullbergb0a02072017-10-02 12:00:34 +020065const NetworkStatistics kNetworkStats = {
66 123, 456, false, 789012, 3456, 123, 456, 0, {}, 789, 12,
67 345, 678, 901, 0, -1, -1, -1, -1, -1, 0};
solenberg566ef242015-11-06 15:34:49 -080068const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest();
69
70struct ConfigHelper {
Yves Gerey665174f2018-06-19 15:03:05 +020071 ConfigHelper() : ConfigHelper(new rtc::RefCountedObject<MockAudioMixer>()) {}
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010072
73 explicit ConfigHelper(rtc::scoped_refptr<MockAudioMixer> audio_mixer)
74 : audio_mixer_(audio_mixer) {
solenberg13725082015-11-25 08:16:52 -080075 using testing::Invoke;
76
solenberg566ef242015-11-06 15:34:49 -080077 AudioState::Config config;
aleloi04c07222016-11-22 06:42:53 -080078 config.audio_mixer = audio_mixer_;
peaha9cc40b2017-06-29 08:32:09 -070079 config.audio_processing = new rtc::RefCountedObject<MockAudioProcessing>();
Fredrik Solenberg2a877972017-12-15 16:42:15 +010080 config.audio_device_module =
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010081 new rtc::RefCountedObject<testing::NiceMock<MockAudioDeviceModule>>();
solenberg566ef242015-11-06 15:34:49 -080082 audio_state_ = AudioState::Create(config);
solenberg7add0582015-11-20 09:59:34 -080083
Niels Möllerb222f492018-10-03 16:50:08 +020084 channel_proxy_ = new testing::StrictMock<MockChannelReceiveProxy>();
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010085 EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kLocalSsrc)).Times(1);
86 EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 15)).Times(1);
87 EXPECT_CALL(*channel_proxy_,
Yves Gerey665174f2018-06-19 15:03:05 +020088 RegisterReceiverCongestionControlObjects(&packet_router_))
89 .Times(1);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010090 EXPECT_CALL(*channel_proxy_, ResetReceiverCongestionControlObjects())
91 .Times(1);
92 EXPECT_CALL(*channel_proxy_, RegisterTransport(nullptr)).Times(2);
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010093 EXPECT_CALL(*channel_proxy_, DisassociateSendChannel()).Times(1);
94 EXPECT_CALL(*channel_proxy_, SetReceiveCodecs(_))
Yves Gerey665174f2018-06-19 15:03:05 +020095 .WillRepeatedly(Invoke([](const std::map<int, SdpAudioFormat>& codecs) {
96 EXPECT_THAT(codecs, testing::IsEmpty());
97 }));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +010098
solenberg566ef242015-11-06 15:34:49 -080099 stream_config_.rtp.local_ssrc = kLocalSsrc;
100 stream_config_.rtp.remote_ssrc = kRemoteSsrc;
solenberg8189b022016-06-14 12:13:00 -0700101 stream_config_.rtp.nack.rtp_history_ms = 300;
solenberg7add0582015-11-20 09:59:34 -0800102 stream_config_.rtp.extensions.push_back(
isheriff6f8d6862016-05-26 11:24:55 -0700103 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
stefan3313ec92016-01-21 06:32:43 -0800104 stream_config_.rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -0700105 RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100106 stream_config_.decoder_factory =
107 new rtc::RefCountedObject<MockAudioDecoderFactory>;
solenberg13725082015-11-25 08:16:52 -0800108 }
solenberg566ef242015-11-06 15:34:49 -0800109
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100110 std::unique_ptr<internal::AudioReceiveStream> CreateAudioReceiveStream() {
111 return std::unique_ptr<internal::AudioReceiveStream>(
112 new internal::AudioReceiveStream(
Yves Gerey665174f2018-06-19 15:03:05 +0200113 &rtp_stream_receiver_controller_, &packet_router_, stream_config_,
114 audio_state_, &event_log_,
Niels Möllerb222f492018-10-03 16:50:08 +0200115 std::unique_ptr<voe::ChannelReceiveProxy>(channel_proxy_)));
nisse0f15f922017-06-21 01:05:22 -0700116 }
solenberg566ef242015-11-06 15:34:49 -0800117
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100118 AudioReceiveStream::Config& config() { return stream_config_; }
119 rtc::scoped_refptr<MockAudioMixer> audio_mixer() { return audio_mixer_; }
Niels Möllerb222f492018-10-03 16:50:08 +0200120 MockChannelReceiveProxy* channel_proxy() { return channel_proxy_; }
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100121
solenberg566ef242015-11-06 15:34:49 -0800122 void SetupMockForGetStats() {
solenberg566ef242015-11-06 15:34:49 -0800123 using testing::DoAll;
solenbergbd9a77f2017-02-06 12:53:57 -0800124 using testing::SetArgPointee;
solenberg13725082015-11-25 08:16:52 -0800125
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100126 ASSERT_TRUE(channel_proxy_);
solenberg358057b2015-11-27 10:46:42 -0800127 EXPECT_CALL(*channel_proxy_, GetRTCPStatistics())
128 .WillOnce(Return(kCallStats));
129 EXPECT_CALL(*channel_proxy_, GetDelayEstimate())
130 .WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay));
131 EXPECT_CALL(*channel_proxy_, GetSpeechOutputLevelFullRange())
132 .WillOnce(Return(kSpeechOutputLevel));
zsteine76bd3a2017-07-14 12:17:49 -0700133 EXPECT_CALL(*channel_proxy_, GetTotalOutputEnergy())
134 .WillOnce(Return(kTotalOutputEnergy));
135 EXPECT_CALL(*channel_proxy_, GetTotalOutputDuration())
136 .WillOnce(Return(kTotalOutputDuration));
solenberg358057b2015-11-27 10:46:42 -0800137 EXPECT_CALL(*channel_proxy_, GetNetworkStatistics())
138 .WillOnce(Return(kNetworkStats));
139 EXPECT_CALL(*channel_proxy_, GetDecodingCallStatistics())
140 .WillOnce(Return(kAudioDecodeStats));
solenbergbd9a77f2017-02-06 12:53:57 -0800141 EXPECT_CALL(*channel_proxy_, GetRecCodec(_))
142 .WillOnce(DoAll(SetArgPointee<0>(kCodecInst), Return(true)));
solenberg566ef242015-11-06 15:34:49 -0800143 }
144
145 private:
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100146 PacketRouter packet_router_;
ivoc14d5dbe2016-07-04 07:06:55 -0700147 MockRtcEventLog event_log_;
solenberg566ef242015-11-06 15:34:49 -0800148 rtc::scoped_refptr<AudioState> audio_state_;
aleloi04c07222016-11-22 06:42:53 -0800149 rtc::scoped_refptr<MockAudioMixer> audio_mixer_;
solenberg566ef242015-11-06 15:34:49 -0800150 AudioReceiveStream::Config stream_config_;
Niels Möllerb222f492018-10-03 16:50:08 +0200151 testing::StrictMock<MockChannelReceiveProxy>* channel_proxy_ = nullptr;
nisse0f15f922017-06-21 01:05:22 -0700152 RtpStreamReceiverController rtp_stream_receiver_controller_;
solenberg566ef242015-11-06 15:34:49 -0800153};
Stefan Holmer8bffba72015-09-23 15:53:52 +0200154
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100155void BuildOneByteExtension(std::vector<uint8_t>::iterator it,
156 int id,
157 uint32_t extension_value,
158 size_t value_length) {
Stefan Holmer8bffba72015-09-23 15:53:52 +0200159 const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100160 ByteWriter<uint16_t>::WriteBigEndian(&(*it), kRtpOneByteHeaderExtensionId);
161 it += 2;
Stefan Holmer8bffba72015-09-23 15:53:52 +0200162
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100163 ByteWriter<uint16_t>::WriteBigEndian(&(*it), kOneByteExtensionLength / 4);
164 it += 2;
165 const size_t kExtensionDataLength = kOneByteExtensionLength - 1;
166 uint32_t shifted_value = extension_value
167 << (8 * (kExtensionDataLength - value_length));
Peter Boström02083222016-06-14 12:52:54 +0200168 *it = (id << 4) + (static_cast<uint8_t>(value_length) - 1);
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100169 ++it;
170 ByteWriter<uint32_t, kExtensionDataLength>::WriteBigEndian(&(*it),
171 shifted_value);
Stefan Holmer8bffba72015-09-23 15:53:52 +0200172}
173
mflodman3d7db262016-04-29 00:57:13 -0700174const std::vector<uint8_t> CreateRtpHeaderWithOneByteExtension(
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100175 int extension_id,
176 uint32_t extension_value,
177 size_t value_length) {
178 std::vector<uint8_t> header;
179 header.resize(webrtc::kRtpHeaderSize + kOneByteExtensionHeaderLength +
180 kOneByteExtensionLength);
Stefan Holmer8bffba72015-09-23 15:53:52 +0200181 header[0] = 0x80; // Version 2.
182 header[0] |= 0x10; // Set extension bit.
183 header[1] = 100; // Payload type.
184 header[1] |= 0x80; // Marker bit is set.
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100185 ByteWriter<uint16_t>::WriteBigEndian(&header[2], 0x1234); // Sequence number.
186 ByteWriter<uint32_t>::WriteBigEndian(&header[4], 0x5678); // Timestamp.
187 ByteWriter<uint32_t>::WriteBigEndian(&header[8], 0x4321); // SSRC.
Stefan Holmer8bffba72015-09-23 15:53:52 +0200188
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100189 BuildOneByteExtension(header.begin() + webrtc::kRtpHeaderSize, extension_id,
190 extension_value, value_length);
191 return header;
Stefan Holmer8bffba72015-09-23 15:53:52 +0200192}
mflodman3d7db262016-04-29 00:57:13 -0700193
194const std::vector<uint8_t> CreateRtcpSenderReport() {
195 std::vector<uint8_t> packet;
196 const size_t kRtcpSrLength = 28; // In bytes.
197 packet.resize(kRtcpSrLength);
198 packet[0] = 0x80; // Version 2.
199 packet[1] = 0xc8; // PT = 200, SR.
200 // Length in number of 32-bit words - 1.
201 ByteWriter<uint16_t>::WriteBigEndian(&packet[2], 6);
202 ByteWriter<uint32_t>::WriteBigEndian(&packet[4], kLocalSsrc);
203 return packet;
204}
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200205} // namespace
206
solenberg85a04962015-10-27 03:35:21 -0700207TEST(AudioReceiveStreamTest, ConfigToString) {
solenberg85a04962015-10-27 03:35:21 -0700208 AudioReceiveStream::Config config;
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100209 config.rtp.remote_ssrc = kRemoteSsrc;
210 config.rtp.local_ssrc = kLocalSsrc;
stefanb521aa72016-11-01 03:17:16 -0700211 config.rtp.extensions.push_back(
212 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100213 EXPECT_EQ(
stefanb521aa72016-11-01 03:17:16 -0700214 "{rtp: {remote_ssrc: 1234, local_ssrc: 5678, transport_cc: off, nack: "
215 "{rtp_history_ms: 0}, extensions: [{uri: "
216 "urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 3}]}, "
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100217 "rtcp_send_transport: null}",
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100218 config.ToString());
solenberg85a04962015-10-27 03:35:21 -0700219}
220
221TEST(AudioReceiveStreamTest, ConstructDestruct) {
solenberg566ef242015-11-06 15:34:49 -0800222 ConfigHelper helper;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100223 auto recv_stream = helper.CreateAudioReceiveStream();
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100224}
225
mflodman3d7db262016-04-29 00:57:13 -0700226TEST(AudioReceiveStreamTest, ReceiveRtpPacket) {
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100227 ConfigHelper helper;
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100228 helper.config().rtp.transport_cc = true;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100229 auto recv_stream = helper.CreateAudioReceiveStream();
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100230 const int kTransportSequenceNumberValue = 1234;
231 std::vector<uint8_t> rtp_packet = CreateRtpHeaderWithOneByteExtension(
232 kTransportSequenceNumberId, kTransportSequenceNumberValue, 2);
Niels Möller70082872018-08-07 11:03:12 +0200233 constexpr int64_t packet_time_us = 5678000;
nisse657bab22017-02-21 06:28:10 -0800234
235 RtpPacketReceived parsed_packet;
236 ASSERT_TRUE(parsed_packet.Parse(&rtp_packet[0], rtp_packet.size()));
Niels Möller70082872018-08-07 11:03:12 +0200237 parsed_packet.set_arrival_time_ms((packet_time_us + 500) / 1000);
nisse657bab22017-02-21 06:28:10 -0800238
mflodman3d7db262016-04-29 00:57:13 -0700239 EXPECT_CALL(*helper.channel_proxy(),
nisse657bab22017-02-21 06:28:10 -0800240 OnRtpPacket(testing::Ref(parsed_packet)));
241
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100242 recv_stream->OnRtpPacket(parsed_packet);
Stefan Holmer8bffba72015-09-23 15:53:52 +0200243}
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200244
mflodman3d7db262016-04-29 00:57:13 -0700245TEST(AudioReceiveStreamTest, ReceiveRtcpPacket) {
246 ConfigHelper helper;
247 helper.config().rtp.transport_cc = true;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100248 auto recv_stream = helper.CreateAudioReceiveStream();
mflodman3d7db262016-04-29 00:57:13 -0700249 std::vector<uint8_t> rtcp_packet = CreateRtcpSenderReport();
250 EXPECT_CALL(*helper.channel_proxy(),
251 ReceivedRTCPPacket(&rtcp_packet[0], rtcp_packet.size()))
252 .WillOnce(Return(true));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100253 EXPECT_TRUE(recv_stream->DeliverRtcp(&rtcp_packet[0], rtcp_packet.size()));
mflodman3d7db262016-04-29 00:57:13 -0700254}
255
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200256TEST(AudioReceiveStreamTest, GetStats) {
solenberg566ef242015-11-06 15:34:49 -0800257 ConfigHelper helper;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100258 auto recv_stream = helper.CreateAudioReceiveStream();
solenberg566ef242015-11-06 15:34:49 -0800259 helper.SetupMockForGetStats();
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100260 AudioReceiveStream::Stats stats = recv_stream->GetStats();
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100261 EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc);
262 EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd);
263 EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived),
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200264 stats.packets_rcvd);
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100265 EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost);
266 EXPECT_EQ(Q8ToFloat(kCallStats.fractionLost), stats.fraction_lost);
267 EXPECT_EQ(std::string(kCodecInst.plname), stats.codec_name);
268 EXPECT_EQ(kCallStats.extendedMax, stats.ext_seqnum);
269 EXPECT_EQ(kCallStats.jitterSamples / (kCodecInst.plfreq / 1000),
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200270 stats.jitter_ms);
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100271 EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms);
272 EXPECT_EQ(kNetworkStats.preferredBufferSize,
273 stats.jitter_buffer_preferred_ms);
274 EXPECT_EQ(static_cast<uint32_t>(kJitterBufferDelay + kPlayoutBufferDelay),
275 stats.delay_estimate_ms);
276 EXPECT_EQ(static_cast<int32_t>(kSpeechOutputLevel), stats.audio_level);
zsteine76bd3a2017-07-14 12:17:49 -0700277 EXPECT_EQ(kTotalOutputEnergy, stats.total_output_energy);
Steve Anton2dbc69f2017-08-24 17:15:13 -0700278 EXPECT_EQ(kNetworkStats.totalSamplesReceived, stats.total_samples_received);
zsteine76bd3a2017-07-14 12:17:49 -0700279 EXPECT_EQ(kTotalOutputDuration, stats.total_output_duration);
Steve Anton2dbc69f2017-08-24 17:15:13 -0700280 EXPECT_EQ(kNetworkStats.concealedSamples, stats.concealed_samples);
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200281 EXPECT_EQ(kNetworkStats.concealmentEvents, stats.concealment_events);
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200282 EXPECT_EQ(static_cast<double>(kNetworkStats.jitterBufferDelayMs) /
283 static_cast<double>(rtc::kNumMillisecsPerSec),
284 stats.jitter_buffer_delay_seconds);
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100285 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate);
286 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate),
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200287 stats.speech_expand_rate);
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100288 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate),
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200289 stats.secondary_decoded_rate);
minyue-webrtc0e320ec2017-08-28 13:51:27 +0200290 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDiscardedRate),
291 stats.secondary_discarded_rate);
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100292 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate),
293 stats.accelerate_rate);
294 EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate),
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200295 stats.preemptive_expand_rate);
solenberg566ef242015-11-06 15:34:49 -0800296 EXPECT_EQ(kAudioDecodeStats.calls_to_silence_generator,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200297 stats.decoding_calls_to_silence_generator);
solenberg566ef242015-11-06 15:34:49 -0800298 EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq);
299 EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal);
300 EXPECT_EQ(kAudioDecodeStats.decoded_plc, stats.decoding_plc);
301 EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng);
302 EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng);
henrik.lundin63489782016-09-20 01:47:12 -0700303 EXPECT_EQ(kAudioDecodeStats.decoded_muted_output,
304 stats.decoding_muted_output);
Fredrik Solenberg0ccae132015-11-03 10:15:49 +0100305 EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_,
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200306 stats.capture_start_ntp_time_ms);
307}
solenberg217fb662016-06-17 08:30:54 -0700308
309TEST(AudioReceiveStreamTest, SetGain) {
310 ConfigHelper helper;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100311 auto recv_stream = helper.CreateAudioReceiveStream();
solenberg217fb662016-06-17 08:30:54 -0700312 EXPECT_CALL(*helper.channel_proxy(),
Yves Gerey665174f2018-06-19 15:03:05 +0200313 SetChannelOutputVolumeScaling(FloatEq(0.765f)));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100314 recv_stream->SetGain(0.765f);
solenberg217fb662016-06-17 08:30:54 -0700315}
aleloi04c07222016-11-22 06:42:53 -0800316
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100317TEST(AudioReceiveStreamTest, StreamsShouldBeAddedToMixerOnceOnStart) {
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100318 ConfigHelper helper1;
319 ConfigHelper helper2(helper1.audio_mixer());
320 auto recv_stream1 = helper1.CreateAudioReceiveStream();
321 auto recv_stream2 = helper2.CreateAudioReceiveStream();
aleloi04c07222016-11-22 06:42:53 -0800322
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100323 EXPECT_CALL(*helper1.channel_proxy(), StartPlayout()).Times(1);
324 EXPECT_CALL(*helper2.channel_proxy(), StartPlayout()).Times(1);
325 EXPECT_CALL(*helper1.channel_proxy(), StopPlayout()).Times(1);
326 EXPECT_CALL(*helper2.channel_proxy(), StopPlayout()).Times(1);
327 EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream1.get()))
aleloi04c07222016-11-22 06:42:53 -0800328 .WillOnce(Return(true));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100329 EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream2.get()))
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100330 .WillOnce(Return(true));
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100331 EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream1.get()))
332 .Times(1);
333 EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream2.get()))
334 .Times(1);
aleloi04c07222016-11-22 06:42:53 -0800335
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100336 recv_stream1->Start();
337 recv_stream2->Start();
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100338
339 // One more should not result in any more mixer sources added.
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100340 recv_stream1->Start();
Fredrik Solenbergd5247512017-12-18 22:41:03 +0100341
342 // Stop stream before it is being destructed.
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100343 recv_stream2->Stop();
aleloi04c07222016-11-22 06:42:53 -0800344}
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100345
346TEST(AudioReceiveStreamTest, ReconfigureWithSameConfig) {
347 ConfigHelper helper;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100348 auto recv_stream = helper.CreateAudioReceiveStream();
349 recv_stream->Reconfigure(helper.config());
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100350}
351
352TEST(AudioReceiveStreamTest, ReconfigureWithUpdatedConfig) {
353 ConfigHelper helper;
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100354 auto recv_stream = helper.CreateAudioReceiveStream();
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100355
356 auto new_config = helper.config();
357 new_config.rtp.local_ssrc = kLocalSsrc + 1;
358 new_config.rtp.nack.rtp_history_ms = 300 + 20;
359 new_config.rtp.extensions.clear();
360 new_config.rtp.extensions.push_back(
Yves Gerey665174f2018-06-19 15:03:05 +0200361 RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId + 1));
362 new_config.rtp.extensions.push_back(
363 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
364 kTransportSequenceNumberId + 1));
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100365 new_config.decoder_map.emplace(1, SdpAudioFormat("foo", 8000, 1));
366
Niels Möllerb222f492018-10-03 16:50:08 +0200367 MockChannelReceiveProxy& channel_proxy = *helper.channel_proxy();
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100368 EXPECT_CALL(channel_proxy, SetLocalSSRC(kLocalSsrc + 1)).Times(1);
369 EXPECT_CALL(channel_proxy, SetNACKStatus(true, 15 + 1)).Times(1);
370 EXPECT_CALL(channel_proxy, SetReceiveCodecs(new_config.decoder_map));
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100371
Fredrik Solenberg8f5787a2018-01-11 13:52:30 +0100372 recv_stream->Reconfigure(new_config);
Fredrik Solenberg3b903d02018-01-10 15:17:10 +0100373}
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200374} // namespace test
Stefan Holmer8bffba72015-09-23 15:53:52 +0200375} // namespace webrtc