2015-09-23 15:53:52 +02: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-03-27 07:15:49 -07:00
|
|
|
#include <map>
|
2015-12-01 11:26:34 +01:00
|
|
|
#include <string>
|
2016-01-21 06:32:43 -08:00
|
|
|
#include <vector>
|
2015-12-01 11:26:34 +01:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/test/mock_audio_mixer.h"
|
|
|
|
|
#include "audio/audio_receive_stream.h"
|
|
|
|
|
#include "audio/conversion.h"
|
2018-01-17 11:18:31 +01:00
|
|
|
#include "audio/mock_voe_channel_proxy.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/rtp_stream_receiver_controller.h"
|
|
|
|
|
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
#include "modules/audio_device/include/mock_audio_device.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_processing/include/mock_audio_processing.h"
|
|
|
|
|
#include "modules/bitrate_controller/include/mock/mock_bitrate_controller.h"
|
|
|
|
|
#include "modules/pacing/packet_router.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/byte_io.h"
|
|
|
|
|
#include "test/gtest.h"
|
|
|
|
|
#include "test/mock_audio_decoder_factory.h"
|
2015-09-23 15:53:52 +02:00
|
|
|
|
2015-11-03 10:15:49 +01:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
2015-10-22 10:49:27 +02:00
|
|
|
namespace {
|
|
|
|
|
|
2015-11-16 07:34:50 -08:00
|
|
|
using testing::_;
|
2016-06-17 08:30:54 -07:00
|
|
|
using testing::FloatEq;
|
2015-11-16 07:34:50 -08:00
|
|
|
using testing::Return;
|
2016-06-13 07:34:51 -07:00
|
|
|
using testing::ReturnRef;
|
2015-11-16 07:34:50 -08:00
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
AudioDecodingCallStats MakeAudioDecodeStatsForTest() {
|
|
|
|
|
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;
|
2016-09-20 01:47:12 -07:00
|
|
|
audio_decode_stats.decoded_muted_output = 987;
|
2015-11-06 15:34:49 -08:00
|
|
|
return audio_decode_stats;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 10:15:49 +01:00
|
|
|
const uint32_t kRemoteSsrc = 1234;
|
|
|
|
|
const uint32_t kLocalSsrc = 5678;
|
2016-01-12 13:55:00 +01:00
|
|
|
const size_t kOneByteExtensionHeaderLength = 4;
|
|
|
|
|
const size_t kOneByteExtensionLength = 4;
|
2015-11-20 09:59:34 -08:00
|
|
|
const int kAudioLevelId = 3;
|
2016-01-12 13:55:00 +01:00
|
|
|
const int kTransportSequenceNumberId = 4;
|
2015-11-06 15:34:49 -08:00
|
|
|
const int kJitterBufferDelay = -7;
|
|
|
|
|
const int kPlayoutBufferDelay = 302;
|
|
|
|
|
const unsigned int kSpeechOutputLevel = 99;
|
2017-07-14 12:17:49 -07:00
|
|
|
const double kTotalOutputEnergy = 0.25;
|
|
|
|
|
const double kTotalOutputDuration = 0.5;
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
const CallStatistics kCallStats = {345, 678, 901, 234, -12,
|
|
|
|
|
3456, 7890, 567, 890, 123};
|
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 = {123, "codec_name_recv", 96000, -187, 0, -103};
|
2017-10-02 12:00:34 +02:00
|
|
|
const NetworkStatistics kNetworkStats = {
|
|
|
|
|
123, 456, false, 789012, 3456, 123, 456, 0, {}, 789, 12,
|
|
|
|
|
345, 678, 901, 0, -1, -1, -1, -1, -1, 0};
|
2015-11-06 15:34:49 -08:00
|
|
|
const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest();
|
|
|
|
|
|
|
|
|
|
struct ConfigHelper {
|
2018-01-11 13:52:30 +01:00
|
|
|
ConfigHelper() : ConfigHelper(new rtc::RefCountedObject<MockAudioMixer>()) {}
|
|
|
|
|
|
|
|
|
|
explicit ConfigHelper(rtc::scoped_refptr<MockAudioMixer> audio_mixer)
|
|
|
|
|
: audio_mixer_(audio_mixer) {
|
2015-11-25 08:16:52 -08:00
|
|
|
using testing::Invoke;
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
AudioState::Config config;
|
2016-11-22 06:42:53 -08:00
|
|
|
config.audio_mixer = audio_mixer_;
|
2017-06-29 08:32:09 -07:00
|
|
|
config.audio_processing = new rtc::RefCountedObject<MockAudioProcessing>();
|
Remove voe::TransmitMixer
TransmitMixer's functionality is moved into the AudioTransportProxy
owned by AudioState. This removes the need for an AudioTransport
implementation in VoEBaseImpl, which means that the proxy is no longer
a proxy, hence AudioTransportProxy is renamed to AudioTransportImpl.
In the short term, AudioState needs to know which AudioDeviceModule is
used, so it is added in AudioState::Config. AudioTransportImpl needs
to know which AudioSendStream:s are currently enabled to send, so
AudioState maintains a map of them, which is reduced into a simple
vector for AudioTransportImpl.
To encode and transmit audio,
AudioSendStream::OnAudioData(std::unique_ptr<AudioFrame> audio_frame)
is introduced, which is used in both the Chromium and standalone use
cases. This removes the need for two different instances of
voe::Channel::ProcessAndEncodeAudio(), so there is now only one,
taking an AudioFrame as argument. Callers need to allocate their own
AudioFrame:s, which is wasteful but not a regression since this was
already happening in the voe::Channel functions.
Most of the logic changed resides in
AudioTransportImpl::RecordedDataIsAvailable(), where two strange
things were found:
1. The clock drift parameter was ineffective since
apm->echo_cancellation()->enable_drift_compensation(false) is
called during initialization.
2. The output parameter 'new_mic_volume' was never set - instead it
was returned as a result, causing the ADM to never update the
analog mic gain
(https://cs.chromium.org/chromium/src/third_party/webrtc/voice_engine/voe_base_impl.cc?q=voe_base_impl.cc&dr&l=100).
Besides this, tests are updated, and some dead code is removed which
was found in the process.
Bug: webrtc:4690, webrtc:8591
Change-Id: I789d5296bf5efb7299a5ee05a4f3ce6abf9124b2
Reviewed-on: https://webrtc-review.googlesource.com/26681
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21301}
2017-12-15 16:42:15 +01:00
|
|
|
config.audio_device_module =
|
2018-01-11 13:52:30 +01:00
|
|
|
new rtc::RefCountedObject<testing::NiceMock<MockAudioDeviceModule>>();
|
2015-11-06 15:34:49 -08:00
|
|
|
audio_state_ = AudioState::Create(config);
|
2015-11-20 09:59:34 -08:00
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
channel_proxy_ = new testing::StrictMock<MockVoEChannelProxy>();
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kLocalSsrc)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, SetNACKStatus(true, 15)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_,
|
|
|
|
|
RegisterReceiverCongestionControlObjects(&packet_router_))
|
|
|
|
|
.Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, ResetReceiverCongestionControlObjects())
|
|
|
|
|
.Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, RegisterTransport(nullptr)).Times(2);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, DisassociateSendChannel()).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, SetReceiveCodecs(_))
|
|
|
|
|
.WillRepeatedly(Invoke([](const std::map<int, SdpAudioFormat>& codecs) {
|
|
|
|
|
EXPECT_THAT(codecs, testing::IsEmpty());
|
|
|
|
|
}));
|
|
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
stream_config_.rtp.local_ssrc = kLocalSsrc;
|
|
|
|
|
stream_config_.rtp.remote_ssrc = kRemoteSsrc;
|
2016-06-14 12:13:00 -07:00
|
|
|
stream_config_.rtp.nack.rtp_history_ms = 300;
|
2015-11-20 09:59:34 -08:00
|
|
|
stream_config_.rtp.extensions.push_back(
|
2016-05-26 11:24:55 -07:00
|
|
|
RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
|
2016-01-21 06:32:43 -08:00
|
|
|
stream_config_.rtp.extensions.push_back(RtpExtension(
|
2016-05-26 11:24:55 -07:00
|
|
|
RtpExtension::kTransportSequenceNumberUri, kTransportSequenceNumberId));
|
2018-01-11 13:52:30 +01:00
|
|
|
stream_config_.decoder_factory =
|
|
|
|
|
new rtc::RefCountedObject<MockAudioDecoderFactory>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<internal::AudioReceiveStream> CreateAudioReceiveStream() {
|
|
|
|
|
return std::unique_ptr<internal::AudioReceiveStream>(
|
|
|
|
|
new internal::AudioReceiveStream(
|
|
|
|
|
&rtp_stream_receiver_controller_, &packet_router_, stream_config_,
|
|
|
|
|
audio_state_, &event_log_,
|
|
|
|
|
std::unique_ptr<voe::ChannelProxy>(channel_proxy_)));
|
2015-11-25 08:16:52 -08:00
|
|
|
}
|
2015-11-06 15:34:49 -08:00
|
|
|
|
|
|
|
|
AudioReceiveStream::Config& config() { return stream_config_; }
|
2016-11-22 06:42:53 -08:00
|
|
|
rtc::scoped_refptr<MockAudioMixer> audio_mixer() { return audio_mixer_; }
|
2016-04-29 00:57:13 -07:00
|
|
|
MockVoEChannelProxy* channel_proxy() { return channel_proxy_; }
|
2015-11-06 15:34:49 -08:00
|
|
|
|
|
|
|
|
void SetupMockForGetStats() {
|
|
|
|
|
using testing::DoAll;
|
2017-02-06 12:53:57 -08:00
|
|
|
using testing::SetArgPointee;
|
2015-11-25 08:16:52 -08:00
|
|
|
|
2016-01-12 13:55:00 +01:00
|
|
|
ASSERT_TRUE(channel_proxy_);
|
2015-11-27 10:46:42 -08:00
|
|
|
EXPECT_CALL(*channel_proxy_, GetRTCPStatistics())
|
|
|
|
|
.WillOnce(Return(kCallStats));
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, GetDelayEstimate())
|
|
|
|
|
.WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay));
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, GetSpeechOutputLevelFullRange())
|
|
|
|
|
.WillOnce(Return(kSpeechOutputLevel));
|
2017-07-14 12:17:49 -07:00
|
|
|
EXPECT_CALL(*channel_proxy_, GetTotalOutputEnergy())
|
|
|
|
|
.WillOnce(Return(kTotalOutputEnergy));
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, GetTotalOutputDuration())
|
|
|
|
|
.WillOnce(Return(kTotalOutputDuration));
|
2015-11-27 10:46:42 -08:00
|
|
|
EXPECT_CALL(*channel_proxy_, GetNetworkStatistics())
|
|
|
|
|
.WillOnce(Return(kNetworkStats));
|
|
|
|
|
EXPECT_CALL(*channel_proxy_, GetDecodingCallStatistics())
|
|
|
|
|
.WillOnce(Return(kAudioDecodeStats));
|
2017-02-06 12:53:57 -08:00
|
|
|
EXPECT_CALL(*channel_proxy_, GetRecCodec(_))
|
|
|
|
|
.WillOnce(DoAll(SetArgPointee<0>(kCodecInst), Return(true)));
|
2015-11-06 15:34:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2016-01-12 13:55:00 +01:00
|
|
|
PacketRouter packet_router_;
|
2016-07-04 07:06:55 -07:00
|
|
|
MockRtcEventLog event_log_;
|
2015-11-06 15:34:49 -08:00
|
|
|
rtc::scoped_refptr<AudioState> audio_state_;
|
2016-11-22 06:42:53 -08:00
|
|
|
rtc::scoped_refptr<MockAudioMixer> audio_mixer_;
|
2015-11-06 15:34:49 -08:00
|
|
|
AudioReceiveStream::Config stream_config_;
|
2015-11-25 08:16:52 -08:00
|
|
|
testing::StrictMock<MockVoEChannelProxy>* channel_proxy_ = nullptr;
|
2017-06-21 01:05:22 -07:00
|
|
|
RtpStreamReceiverController rtp_stream_receiver_controller_;
|
2015-11-06 15:34:49 -08:00
|
|
|
};
|
2015-09-23 15:53:52 +02:00
|
|
|
|
2016-01-12 13:55:00 +01:00
|
|
|
void BuildOneByteExtension(std::vector<uint8_t>::iterator it,
|
|
|
|
|
int id,
|
|
|
|
|
uint32_t extension_value,
|
|
|
|
|
size_t value_length) {
|
2015-09-23 15:53:52 +02:00
|
|
|
const uint16_t kRtpOneByteHeaderExtensionId = 0xBEDE;
|
2016-01-12 13:55:00 +01:00
|
|
|
ByteWriter<uint16_t>::WriteBigEndian(&(*it), kRtpOneByteHeaderExtensionId);
|
|
|
|
|
it += 2;
|
2015-09-23 15:53:52 +02:00
|
|
|
|
2016-01-12 13:55:00 +01:00
|
|
|
ByteWriter<uint16_t>::WriteBigEndian(&(*it), kOneByteExtensionLength / 4);
|
|
|
|
|
it += 2;
|
|
|
|
|
const size_t kExtensionDataLength = kOneByteExtensionLength - 1;
|
|
|
|
|
uint32_t shifted_value = extension_value
|
|
|
|
|
<< (8 * (kExtensionDataLength - value_length));
|
2016-06-14 12:52:54 +02:00
|
|
|
*it = (id << 4) + (static_cast<uint8_t>(value_length) - 1);
|
2016-01-12 13:55:00 +01:00
|
|
|
++it;
|
|
|
|
|
ByteWriter<uint32_t, kExtensionDataLength>::WriteBigEndian(&(*it),
|
|
|
|
|
shifted_value);
|
2015-09-23 15:53:52 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
const std::vector<uint8_t> CreateRtpHeaderWithOneByteExtension(
|
2016-01-12 13:55:00 +01:00
|
|
|
int extension_id,
|
|
|
|
|
uint32_t extension_value,
|
|
|
|
|
size_t value_length) {
|
|
|
|
|
std::vector<uint8_t> header;
|
|
|
|
|
header.resize(webrtc::kRtpHeaderSize + kOneByteExtensionHeaderLength +
|
|
|
|
|
kOneByteExtensionLength);
|
2015-09-23 15:53:52 +02:00
|
|
|
header[0] = 0x80; // Version 2.
|
|
|
|
|
header[0] |= 0x10; // Set extension bit.
|
|
|
|
|
header[1] = 100; // Payload type.
|
|
|
|
|
header[1] |= 0x80; // Marker bit is set.
|
2016-01-12 13:55:00 +01:00
|
|
|
ByteWriter<uint16_t>::WriteBigEndian(&header[2], 0x1234); // Sequence number.
|
|
|
|
|
ByteWriter<uint32_t>::WriteBigEndian(&header[4], 0x5678); // Timestamp.
|
|
|
|
|
ByteWriter<uint32_t>::WriteBigEndian(&header[8], 0x4321); // SSRC.
|
|
|
|
|
|
|
|
|
|
BuildOneByteExtension(header.begin() + webrtc::kRtpHeaderSize, extension_id,
|
|
|
|
|
extension_value, value_length);
|
|
|
|
|
return header;
|
2015-09-23 15:53:52 +02:00
|
|
|
}
|
2016-04-29 00:57:13 -07:00
|
|
|
|
|
|
|
|
const std::vector<uint8_t> CreateRtcpSenderReport() {
|
|
|
|
|
std::vector<uint8_t> packet;
|
|
|
|
|
const size_t kRtcpSrLength = 28; // In bytes.
|
|
|
|
|
packet.resize(kRtcpSrLength);
|
|
|
|
|
packet[0] = 0x80; // Version 2.
|
|
|
|
|
packet[1] = 0xc8; // PT = 200, SR.
|
|
|
|
|
// Length in number of 32-bit words - 1.
|
|
|
|
|
ByteWriter<uint16_t>::WriteBigEndian(&packet[2], 6);
|
|
|
|
|
ByteWriter<uint32_t>::WriteBigEndian(&packet[4], kLocalSsrc);
|
|
|
|
|
return packet;
|
|
|
|
|
}
|
2015-10-22 10:49:27 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
2015-10-27 03:35:21 -07:00
|
|
|
TEST(AudioReceiveStreamTest, ConfigToString) {
|
|
|
|
|
AudioReceiveStream::Config config;
|
2015-11-03 10:15:49 +01:00
|
|
|
config.rtp.remote_ssrc = kRemoteSsrc;
|
|
|
|
|
config.rtp.local_ssrc = kLocalSsrc;
|
2016-11-01 03:17:16 -07:00
|
|
|
config.rtp.extensions.push_back(
|
|
|
|
|
RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId));
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(
|
2016-11-01 03:17:16 -07:00
|
|
|
"{rtp: {remote_ssrc: 1234, local_ssrc: 5678, transport_cc: off, nack: "
|
|
|
|
|
"{rtp_history_ms: 0}, extensions: [{uri: "
|
|
|
|
|
"urn:ietf:params:rtp-hdrext:ssrc-audio-level, id: 3}]}, "
|
2018-01-11 13:52:30 +01:00
|
|
|
"rtcp_send_transport: null}",
|
2015-11-03 10:15:49 +01:00
|
|
|
config.ToString());
|
2015-10-27 03:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, ConstructDestruct) {
|
2015-11-06 15:34:49 -08:00
|
|
|
ConfigHelper helper;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2016-01-12 13:55:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
TEST(AudioReceiveStreamTest, ReceiveRtpPacket) {
|
2016-01-12 13:55:00 +01:00
|
|
|
ConfigHelper helper;
|
|
|
|
|
helper.config().rtp.transport_cc = true;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2016-01-12 13:55:00 +01:00
|
|
|
const int kTransportSequenceNumberValue = 1234;
|
|
|
|
|
std::vector<uint8_t> rtp_packet = CreateRtpHeaderWithOneByteExtension(
|
|
|
|
|
kTransportSequenceNumberId, kTransportSequenceNumberValue, 2);
|
2018-08-07 11:03:12 +02:00
|
|
|
constexpr int64_t packet_time_us = 5678000;
|
2017-02-21 06:28:10 -08:00
|
|
|
|
|
|
|
|
RtpPacketReceived parsed_packet;
|
|
|
|
|
ASSERT_TRUE(parsed_packet.Parse(&rtp_packet[0], rtp_packet.size()));
|
2018-08-07 11:03:12 +02:00
|
|
|
parsed_packet.set_arrival_time_ms((packet_time_us + 500) / 1000);
|
2017-02-21 06:28:10 -08:00
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
EXPECT_CALL(*helper.channel_proxy(),
|
2017-02-21 06:28:10 -08:00
|
|
|
OnRtpPacket(testing::Ref(parsed_packet)));
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
recv_stream->OnRtpPacket(parsed_packet);
|
2015-09-23 15:53:52 +02:00
|
|
|
}
|
2015-10-22 10:49:27 +02:00
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
TEST(AudioReceiveStreamTest, ReceiveRtcpPacket) {
|
|
|
|
|
ConfigHelper helper;
|
|
|
|
|
helper.config().rtp.transport_cc = true;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2016-04-29 00:57:13 -07:00
|
|
|
std::vector<uint8_t> rtcp_packet = CreateRtcpSenderReport();
|
|
|
|
|
EXPECT_CALL(*helper.channel_proxy(),
|
|
|
|
|
ReceivedRTCPPacket(&rtcp_packet[0], rtcp_packet.size()))
|
|
|
|
|
.WillOnce(Return(true));
|
2018-01-11 13:52:30 +01:00
|
|
|
EXPECT_TRUE(recv_stream->DeliverRtcp(&rtcp_packet[0], rtcp_packet.size()));
|
2016-04-29 00:57:13 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 10:49:27 +02:00
|
|
|
TEST(AudioReceiveStreamTest, GetStats) {
|
2015-11-06 15:34:49 -08:00
|
|
|
ConfigHelper helper;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2015-11-06 15:34:49 -08:00
|
|
|
helper.SetupMockForGetStats();
|
2018-01-11 13:52:30 +01:00
|
|
|
AudioReceiveStream::Stats stats = recv_stream->GetStats();
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc);
|
|
|
|
|
EXPECT_EQ(static_cast<int64_t>(kCallStats.bytesReceived), stats.bytes_rcvd);
|
|
|
|
|
EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived),
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.packets_rcvd);
|
2015-11-03 10:15:49 +01:00
|
|
|
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),
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.jitter_ms);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(kNetworkStats.currentBufferSize, stats.jitter_buffer_ms);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.preferredBufferSize,
|
|
|
|
|
stats.jitter_buffer_preferred_ms);
|
|
|
|
|
EXPECT_EQ(static_cast<uint32_t>(kJitterBufferDelay + kPlayoutBufferDelay),
|
|
|
|
|
stats.delay_estimate_ms);
|
|
|
|
|
EXPECT_EQ(static_cast<int32_t>(kSpeechOutputLevel), stats.audio_level);
|
2017-07-14 12:17:49 -07:00
|
|
|
EXPECT_EQ(kTotalOutputEnergy, stats.total_output_energy);
|
2017-08-24 17:15:13 -07:00
|
|
|
EXPECT_EQ(kNetworkStats.totalSamplesReceived, stats.total_samples_received);
|
2017-07-14 12:17:49 -07:00
|
|
|
EXPECT_EQ(kTotalOutputDuration, stats.total_output_duration);
|
2017-08-24 17:15:13 -07:00
|
|
|
EXPECT_EQ(kNetworkStats.concealedSamples, stats.concealed_samples);
|
2017-09-18 09:28:20 +02:00
|
|
|
EXPECT_EQ(kNetworkStats.concealmentEvents, stats.concealment_events);
|
2017-10-02 12:00:34 +02:00
|
|
|
EXPECT_EQ(static_cast<double>(kNetworkStats.jitterBufferDelayMs) /
|
|
|
|
|
static_cast<double>(rtc::kNumMillisecsPerSec),
|
|
|
|
|
stats.jitter_buffer_delay_seconds);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate),
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.speech_expand_rate);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate),
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.secondary_decoded_rate);
|
2017-08-28 13:51:27 +02:00
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDiscardedRate),
|
|
|
|
|
stats.secondary_discarded_rate);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate),
|
|
|
|
|
stats.accelerate_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate),
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.preemptive_expand_rate);
|
2015-11-06 15:34:49 -08:00
|
|
|
EXPECT_EQ(kAudioDecodeStats.calls_to_silence_generator,
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.decoding_calls_to_silence_generator);
|
2015-11-06 15:34:49 -08:00
|
|
|
EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_plc, stats.decoding_plc);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng);
|
2016-09-20 01:47:12 -07:00
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_muted_output,
|
|
|
|
|
stats.decoding_muted_output);
|
2015-11-03 10:15:49 +01:00
|
|
|
EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_,
|
2015-10-22 10:49:27 +02:00
|
|
|
stats.capture_start_ntp_time_ms);
|
|
|
|
|
}
|
2016-06-17 08:30:54 -07:00
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, SetGain) {
|
|
|
|
|
ConfigHelper helper;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2016-06-17 08:30:54 -07:00
|
|
|
EXPECT_CALL(*helper.channel_proxy(),
|
|
|
|
|
SetChannelOutputVolumeScaling(FloatEq(0.765f)));
|
2018-01-11 13:52:30 +01:00
|
|
|
recv_stream->SetGain(0.765f);
|
2016-06-17 08:30:54 -07:00
|
|
|
}
|
2016-11-22 06:42:53 -08:00
|
|
|
|
2017-12-18 22:41:03 +01:00
|
|
|
TEST(AudioReceiveStreamTest, StreamsShouldBeAddedToMixerOnceOnStart) {
|
2018-01-11 13:52:30 +01:00
|
|
|
ConfigHelper helper1;
|
|
|
|
|
ConfigHelper helper2(helper1.audio_mixer());
|
|
|
|
|
auto recv_stream1 = helper1.CreateAudioReceiveStream();
|
|
|
|
|
auto recv_stream2 = helper2.CreateAudioReceiveStream();
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(*helper1.channel_proxy(), StartPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper2.channel_proxy(), StartPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper1.channel_proxy(), StopPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper2.channel_proxy(), StopPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream1.get()))
|
2016-11-22 06:42:53 -08:00
|
|
|
.WillOnce(Return(true));
|
2018-01-11 13:52:30 +01:00
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream2.get()))
|
2017-12-18 22:41:03 +01:00
|
|
|
.WillOnce(Return(true));
|
2018-01-11 13:52:30 +01:00
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream1.get()))
|
|
|
|
|
.Times(1);
|
|
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream2.get()))
|
|
|
|
|
.Times(1);
|
2017-12-18 22:41:03 +01:00
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
recv_stream1->Start();
|
|
|
|
|
recv_stream2->Start();
|
2017-12-18 22:41:03 +01:00
|
|
|
|
|
|
|
|
// One more should not result in any more mixer sources added.
|
2018-01-11 13:52:30 +01:00
|
|
|
recv_stream1->Start();
|
2016-11-22 06:42:53 -08:00
|
|
|
|
2017-12-18 22:41:03 +01:00
|
|
|
// Stop stream before it is being destructed.
|
2018-01-11 13:52:30 +01:00
|
|
|
recv_stream2->Stop();
|
2016-11-22 06:42:53 -08:00
|
|
|
}
|
2018-01-10 15:17:10 +01:00
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, ReconfigureWithSameConfig) {
|
|
|
|
|
ConfigHelper helper;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
|
|
|
|
recv_stream->Reconfigure(helper.config());
|
2018-01-10 15:17:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, ReconfigureWithUpdatedConfig) {
|
|
|
|
|
ConfigHelper helper;
|
2018-01-11 13:52:30 +01:00
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2018-01-10 15:17:10 +01:00
|
|
|
|
|
|
|
|
auto new_config = helper.config();
|
|
|
|
|
new_config.rtp.local_ssrc = kLocalSsrc + 1;
|
|
|
|
|
new_config.rtp.nack.rtp_history_ms = 300 + 20;
|
|
|
|
|
new_config.rtp.extensions.clear();
|
|
|
|
|
new_config.rtp.extensions.push_back(
|
|
|
|
|
RtpExtension(RtpExtension::kAudioLevelUri, kAudioLevelId + 1));
|
|
|
|
|
new_config.rtp.extensions.push_back(
|
|
|
|
|
RtpExtension(RtpExtension::kTransportSequenceNumberUri,
|
|
|
|
|
kTransportSequenceNumberId + 1));
|
|
|
|
|
new_config.decoder_map.emplace(1, SdpAudioFormat("foo", 8000, 1));
|
|
|
|
|
|
|
|
|
|
MockVoEChannelProxy& channel_proxy = *helper.channel_proxy();
|
|
|
|
|
EXPECT_CALL(channel_proxy, SetLocalSSRC(kLocalSsrc + 1)).Times(1);
|
|
|
|
|
EXPECT_CALL(channel_proxy, SetNACKStatus(true, 15 + 1)).Times(1);
|
|
|
|
|
EXPECT_CALL(channel_proxy, SetReceiveCodecs(new_config.decoder_map));
|
|
|
|
|
|
2018-01-11 13:52:30 +01:00
|
|
|
recv_stream->Reconfigure(new_config);
|
2018-01-10 15:17:10 +01:00
|
|
|
}
|
2015-10-22 10:49:27 +02:00
|
|
|
} // namespace test
|
2015-09-23 15:53:52 +02:00
|
|
|
} // namespace webrtc
|