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-09-15 06:47:31 +02:00
|
|
|
#include "audio/audio_receive_stream.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-03-27 07:15:49 -07:00
|
|
|
#include <map>
|
2015-12-01 11:26:34 +01:00
|
|
|
#include <string>
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
#include <utility>
|
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"
|
2018-10-25 09:52:57 -07:00
|
|
|
#include "api/test/mock_frame_decryptor.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#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/pacing/packet_router.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/byte_io.h"
|
2019-01-16 17:45:05 +01:00
|
|
|
#include "rtc_base/time_utils.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gtest.h"
|
|
|
|
|
#include "test/mock_audio_decoder_factory.h"
|
2018-10-05 11:28:38 +02:00
|
|
|
#include "test/mock_transport.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 {
|
|
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
using ::testing::_;
|
|
|
|
|
using ::testing::FloatEq;
|
2020-12-03 11:30:34 -05:00
|
|
|
using ::testing::NiceMock;
|
2019-04-09 15:11:12 +02:00
|
|
|
using ::testing::Return;
|
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;
|
2019-08-07 18:15:08 +02:00
|
|
|
audio_decode_stats.decoded_neteq_plc = 123;
|
|
|
|
|
audio_decode_stats.decoded_codec_plc = 124;
|
2015-11-06 15:34:49 -08:00
|
|
|
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;
|
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;
|
2019-10-22 15:23:44 +02:00
|
|
|
const int64_t kPlayoutNtpTimestampMs = 5678;
|
2017-07-14 12:17:49 -07:00
|
|
|
|
2019-10-09 15:01:33 +02:00
|
|
|
const CallReceiveStatistics kCallStats = {678, 234, -12, 567, 78, 890, 123};
|
2019-03-13 17:35:46 -07:00
|
|
|
const std::pair<int, SdpAudioFormat> kReceiveCodec = {
|
|
|
|
|
123,
|
|
|
|
|
{"codec_name_recv", 96000, 0}};
|
2017-10-02 12:00:34 +02:00
|
|
|
const NetworkStatistics kNetworkStats = {
|
2021-07-07 15:53:38 +02:00
|
|
|
/*currentBufferSize=*/123,
|
|
|
|
|
/*preferredBufferSize=*/456,
|
|
|
|
|
/*jitterPeaksFound=*/false,
|
|
|
|
|
/*totalSamplesReceived=*/789012,
|
|
|
|
|
/*concealedSamples=*/3456,
|
|
|
|
|
/*silentConcealedSamples=*/123,
|
|
|
|
|
/*concealmentEvents=*/456,
|
|
|
|
|
/*jitterBufferDelayMs=*/789,
|
|
|
|
|
/*jitterBufferEmittedCount=*/543,
|
|
|
|
|
/*jitterBufferTargetDelayMs=*/123,
|
|
|
|
|
/*insertedSamplesForDeceleration=*/432,
|
|
|
|
|
/*removedSamplesForAcceleration=*/321,
|
|
|
|
|
/*fecPacketsReceived=*/123,
|
|
|
|
|
/*fecPacketsDiscarded=*/101,
|
|
|
|
|
/*packetsDiscarded=*/989,
|
|
|
|
|
/*currentExpandRate=*/789,
|
|
|
|
|
/*currentSpeechExpandRate=*/12,
|
|
|
|
|
/*currentPreemptiveRate=*/345,
|
|
|
|
|
/*currentAccelerateRate =*/678,
|
|
|
|
|
/*currentSecondaryDecodedRate=*/901,
|
|
|
|
|
/*currentSecondaryDiscardedRate=*/0,
|
|
|
|
|
/*meanWaitingTimeMs=*/-1,
|
|
|
|
|
/*maxWaitingTimeMs=*/-1,
|
|
|
|
|
/*packetBufferFlushes=*/0,
|
|
|
|
|
/*delayedPacketOutageSamples=*/0,
|
|
|
|
|
/*relativePacketArrivalDelayMs=*/135,
|
|
|
|
|
/*interruptionCount=*/-1,
|
|
|
|
|
/*totalInterruptionDurationMs=*/-1};
|
2015-11-06 15:34:49 -08:00
|
|
|
const AudioDecodingCallStats kAudioDecodeStats = MakeAudioDecodeStatsForTest();
|
|
|
|
|
|
|
|
|
|
struct ConfigHelper {
|
2020-04-26 23:56:17 +02:00
|
|
|
explicit ConfigHelper(bool use_null_audio_processing)
|
2021-04-22 19:21:43 +02:00
|
|
|
: ConfigHelper(rtc::make_ref_counted<MockAudioMixer>(),
|
2020-04-26 23:56:17 +02:00
|
|
|
use_null_audio_processing) {}
|
2018-01-11 13:52:30 +01:00
|
|
|
|
2020-04-26 23:56:17 +02:00
|
|
|
ConfigHelper(rtc::scoped_refptr<MockAudioMixer> audio_mixer,
|
|
|
|
|
bool use_null_audio_processing)
|
2018-01-11 13:52:30 +01:00
|
|
|
: audio_mixer_(audio_mixer) {
|
2019-04-09 15:11:12 +02:00
|
|
|
using ::testing::Invoke;
|
2015-11-25 08:16:52 -08:00
|
|
|
|
2015-11-06 15:34:49 -08:00
|
|
|
AudioState::Config config;
|
2016-11-22 06:42:53 -08:00
|
|
|
config.audio_mixer = audio_mixer_;
|
2020-04-26 23:56:17 +02:00
|
|
|
config.audio_processing =
|
|
|
|
|
use_null_audio_processing
|
|
|
|
|
? nullptr
|
2021-04-22 19:21:43 +02:00
|
|
|
: rtc::make_ref_counted<NiceMock<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 =
|
2021-04-22 19:21:43 +02:00
|
|
|
rtc::make_ref_counted<testing::NiceMock<MockAudioDeviceModule>>();
|
2015-11-06 15:34:49 -08:00
|
|
|
audio_state_ = AudioState::Create(config);
|
2015-11-20 09:59:34 -08:00
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
channel_receive_ = new ::testing::StrictMock<MockChannelReceive>();
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, SetNACKStatus(true, 15)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_receive_,
|
2018-01-11 13:52:30 +01:00
|
|
|
RegisterReceiverCongestionControlObjects(&packet_router_))
|
|
|
|
|
.Times(1);
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, ResetReceiverCongestionControlObjects())
|
2018-01-11 13:52:30 +01:00
|
|
|
.Times(1);
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, SetAssociatedSendChannel(nullptr)).Times(1);
|
|
|
|
|
EXPECT_CALL(*channel_receive_, SetReceiveCodecs(_))
|
2018-01-11 13:52:30 +01:00
|
|
|
.WillRepeatedly(Invoke([](const std::map<int, SdpAudioFormat>& codecs) {
|
2019-04-09 15:11:12 +02:00
|
|
|
EXPECT_THAT(codecs, ::testing::IsEmpty());
|
2018-01-11 13:52:30 +01:00
|
|
|
}));
|
2021-01-23 12:27:19 +05:30
|
|
|
EXPECT_CALL(*channel_receive_, SetSourceTracker(_));
|
2018-01-11 13:52:30 +01:00
|
|
|
|
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-10-05 11:28:38 +02:00
|
|
|
stream_config_.rtcp_send_transport = &rtcp_send_transport_;
|
2018-01-11 13:52:30 +01:00
|
|
|
stream_config_.decoder_factory =
|
2021-04-22 19:21:43 +02:00
|
|
|
rtc::make_ref_counted<MockAudioDecoderFactory>();
|
2018-01-11 13:52:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<internal::AudioReceiveStream> CreateAudioReceiveStream() {
|
2021-05-31 12:57:53 +02:00
|
|
|
auto ret = std::make_unique<internal::AudioReceiveStream>(
|
|
|
|
|
Clock::GetRealTimeClock(), &packet_router_, stream_config_,
|
|
|
|
|
audio_state_, &event_log_,
|
|
|
|
|
std::unique_ptr<voe::ChannelReceiveInterface>(channel_receive_));
|
|
|
|
|
ret->RegisterWithTransport(&rtp_stream_receiver_controller_);
|
|
|
|
|
return ret;
|
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_; }
|
2018-11-16 09:50:42 +01:00
|
|
|
MockChannelReceive* channel_receive() { return channel_receive_; }
|
2015-11-06 15:34:49 -08:00
|
|
|
|
|
|
|
|
void SetupMockForGetStats() {
|
2019-04-09 15:11:12 +02:00
|
|
|
using ::testing::DoAll;
|
|
|
|
|
using ::testing::SetArgPointee;
|
2015-11-25 08:16:52 -08:00
|
|
|
|
2018-11-16 09:50:42 +01:00
|
|
|
ASSERT_TRUE(channel_receive_);
|
|
|
|
|
EXPECT_CALL(*channel_receive_, GetRTCPStatistics())
|
2015-11-27 10:46:42 -08:00
|
|
|
.WillOnce(Return(kCallStats));
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, GetDelayEstimate())
|
2015-11-27 10:46:42 -08:00
|
|
|
.WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay));
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, GetSpeechOutputLevelFullRange())
|
2015-11-27 10:46:42 -08:00
|
|
|
.WillOnce(Return(kSpeechOutputLevel));
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, GetTotalOutputEnergy())
|
2017-07-14 12:17:49 -07:00
|
|
|
.WillOnce(Return(kTotalOutputEnergy));
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, GetTotalOutputDuration())
|
2017-07-14 12:17:49 -07:00
|
|
|
.WillOnce(Return(kTotalOutputDuration));
|
2020-09-14 10:47:50 +02:00
|
|
|
EXPECT_CALL(*channel_receive_, GetNetworkStatistics(_))
|
2015-11-27 10:46:42 -08:00
|
|
|
.WillOnce(Return(kNetworkStats));
|
2018-11-16 09:50:42 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, GetDecodingCallStatistics())
|
2015-11-27 10:46:42 -08:00
|
|
|
.WillOnce(Return(kAudioDecodeStats));
|
Remove CodecInst pt.2
The following APIs on AudioCodingModule are deprecated with this CL:
static int NumberOfCodecs();
static int Codec(int, CodecInst*);
static int Codec(const char*, CodecInst*, int, size_t);
static int Codec(const char*, int, size_t);
absl::optional<CodecInst> SendCodec() const;
bool RegisterReceiveCodec(int, const SdpAudioFormat&);
int RegisterExternalReceiveCodec(int, AudioDecoder*, int, int, const std::string&);
int UnregisterReceiveCodec(uint8_t);
int32_t ReceiveCodec(CodecInst*);
absl::optional<SdpAudioFormat> ReceiveFormat();
As well as this method on RtpRtcp module:
int32_t RegisterSendPayload(const CodecInst&);
Bug: webrtc:7626
Change-Id: I1230732136f1fe9048cf74afdeab767ca57ac9ce
Reviewed-on: https://webrtc-review.googlesource.com/c/113816
Commit-Queue: Fredrik Solenberg <solenberg@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26025}
2018-12-11 12:22:10 +01:00
|
|
|
EXPECT_CALL(*channel_receive_, GetReceiveCodec())
|
|
|
|
|
.WillOnce(Return(kReceiveCodec));
|
2019-10-22 15:23:44 +02:00
|
|
|
EXPECT_CALL(*channel_receive_, GetCurrentEstimatedPlayoutNtpTimestampMs(_))
|
|
|
|
|
.WillOnce(Return(kPlayoutNtpTimestampMs));
|
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_;
|
2019-04-09 15:11:12 +02:00
|
|
|
::testing::StrictMock<MockChannelReceive>* channel_receive_ = nullptr;
|
2017-06-21 01:05:22 -07:00
|
|
|
RtpStreamReceiverController rtp_stream_receiver_controller_;
|
2018-10-05 11:28:38 +02:00
|
|
|
MockTransport rtcp_send_transport_;
|
2015-11-06 15:34:49 -08:00
|
|
|
};
|
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}]}, "
|
2019-11-26 09:19:40 -08: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) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper(use_null_audio_processing);
|
|
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
2021-05-31 12:57:53 +02:00
|
|
|
recv_stream->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2016-01-12 13:55:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-29 00:57:13 -07:00
|
|
|
TEST(AudioReceiveStreamTest, ReceiveRtcpPacket) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper(use_null_audio_processing);
|
|
|
|
|
helper.config().rtp.transport_cc = true;
|
|
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
|
|
|
|
std::vector<uint8_t> rtcp_packet = CreateRtcpSenderReport();
|
|
|
|
|
EXPECT_CALL(*helper.channel_receive(),
|
|
|
|
|
ReceivedRTCPPacket(&rtcp_packet[0], rtcp_packet.size()))
|
|
|
|
|
.WillOnce(Return());
|
|
|
|
|
recv_stream->DeliverRtcp(&rtcp_packet[0], rtcp_packet.size());
|
2021-05-31 12:57:53 +02:00
|
|
|
recv_stream->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2016-04-29 00:57:13 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 10:49:27 +02:00
|
|
|
TEST(AudioReceiveStreamTest, GetStats) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper(use_null_audio_processing);
|
|
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
|
|
|
|
helper.SetupMockForGetStats();
|
2020-09-14 10:47:50 +02:00
|
|
|
AudioReceiveStream::Stats stats =
|
|
|
|
|
recv_stream->GetStats(/*get_and_clear_legacy_stats=*/true);
|
2020-04-26 23:56:17 +02:00
|
|
|
EXPECT_EQ(kRemoteSsrc, stats.remote_ssrc);
|
|
|
|
|
EXPECT_EQ(kCallStats.payload_bytes_rcvd, stats.payload_bytes_rcvd);
|
|
|
|
|
EXPECT_EQ(kCallStats.header_and_padding_bytes_rcvd,
|
|
|
|
|
stats.header_and_padding_bytes_rcvd);
|
|
|
|
|
EXPECT_EQ(static_cast<uint32_t>(kCallStats.packetsReceived),
|
|
|
|
|
stats.packets_rcvd);
|
|
|
|
|
EXPECT_EQ(kCallStats.cumulativeLost, stats.packets_lost);
|
|
|
|
|
EXPECT_EQ(kReceiveCodec.second.name, stats.codec_name);
|
|
|
|
|
EXPECT_EQ(
|
|
|
|
|
kCallStats.jitterSamples / (kReceiveCodec.second.clockrate_hz / 1000),
|
|
|
|
|
stats.jitter_ms);
|
|
|
|
|
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);
|
|
|
|
|
EXPECT_EQ(kTotalOutputEnergy, stats.total_output_energy);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.totalSamplesReceived, stats.total_samples_received);
|
|
|
|
|
EXPECT_EQ(kTotalOutputDuration, stats.total_output_duration);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.concealedSamples, stats.concealed_samples);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.concealmentEvents, stats.concealment_events);
|
|
|
|
|
EXPECT_EQ(static_cast<double>(kNetworkStats.jitterBufferDelayMs) /
|
|
|
|
|
static_cast<double>(rtc::kNumMillisecsPerSec),
|
|
|
|
|
stats.jitter_buffer_delay_seconds);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.jitterBufferEmittedCount,
|
|
|
|
|
stats.jitter_buffer_emitted_count);
|
|
|
|
|
EXPECT_EQ(static_cast<double>(kNetworkStats.jitterBufferTargetDelayMs) /
|
|
|
|
|
static_cast<double>(rtc::kNumMillisecsPerSec),
|
|
|
|
|
stats.jitter_buffer_target_delay_seconds);
|
2021-07-07 15:53:38 +02:00
|
|
|
EXPECT_EQ(kNetworkStats.insertedSamplesForDeceleration,
|
|
|
|
|
stats.inserted_samples_for_deceleration);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.removedSamplesForAcceleration,
|
|
|
|
|
stats.removed_samples_for_acceleration);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.fecPacketsReceived, stats.fec_packets_received);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.fecPacketsDiscarded, stats.fec_packets_discarded);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.packetsDiscarded, stats.packets_discarded);
|
2020-04-26 23:56:17 +02:00
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate),
|
|
|
|
|
stats.speech_expand_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDecodedRate),
|
|
|
|
|
stats.secondary_decoded_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSecondaryDiscardedRate),
|
|
|
|
|
stats.secondary_discarded_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentAccelerateRate),
|
|
|
|
|
stats.accelerate_rate);
|
|
|
|
|
EXPECT_EQ(Q14ToFloat(kNetworkStats.currentPreemptiveRate),
|
|
|
|
|
stats.preemptive_expand_rate);
|
2021-07-07 15:53:38 +02:00
|
|
|
EXPECT_EQ(kNetworkStats.packetBufferFlushes, stats.jitter_buffer_flushes);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.delayedPacketOutageSamples,
|
|
|
|
|
stats.delayed_packet_outage_samples);
|
|
|
|
|
EXPECT_EQ(static_cast<double>(kNetworkStats.relativePacketArrivalDelayMs) /
|
|
|
|
|
static_cast<double>(rtc::kNumMillisecsPerSec),
|
|
|
|
|
stats.relative_packet_arrival_delay_seconds);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.interruptionCount, stats.interruption_count);
|
|
|
|
|
EXPECT_EQ(kNetworkStats.totalInterruptionDurationMs,
|
|
|
|
|
stats.total_interruption_duration_ms);
|
|
|
|
|
|
2020-04-26 23:56:17 +02:00
|
|
|
EXPECT_EQ(kAudioDecodeStats.calls_to_silence_generator,
|
|
|
|
|
stats.decoding_calls_to_silence_generator);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.calls_to_neteq, stats.decoding_calls_to_neteq);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_normal, stats.decoding_normal);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_neteq_plc, stats.decoding_plc);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_codec_plc, stats.decoding_codec_plc);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_cng, stats.decoding_cng);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_plc_cng, stats.decoding_plc_cng);
|
|
|
|
|
EXPECT_EQ(kAudioDecodeStats.decoded_muted_output,
|
|
|
|
|
stats.decoding_muted_output);
|
|
|
|
|
EXPECT_EQ(kCallStats.capture_start_ntp_time_ms_,
|
|
|
|
|
stats.capture_start_ntp_time_ms);
|
|
|
|
|
EXPECT_EQ(kPlayoutNtpTimestampMs, stats.estimated_playout_ntp_timestamp_ms);
|
2021-05-31 12:57:53 +02:00
|
|
|
recv_stream->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2015-10-22 10:49:27 +02:00
|
|
|
}
|
2016-06-17 08:30:54 -07:00
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, SetGain) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper(use_null_audio_processing);
|
|
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
|
|
|
|
EXPECT_CALL(*helper.channel_receive(),
|
|
|
|
|
SetChannelOutputVolumeScaling(FloatEq(0.765f)));
|
|
|
|
|
recv_stream->SetGain(0.765f);
|
2021-05-31 12:57:53 +02:00
|
|
|
recv_stream->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
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) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper1(use_null_audio_processing);
|
|
|
|
|
ConfigHelper helper2(helper1.audio_mixer(), use_null_audio_processing);
|
|
|
|
|
auto recv_stream1 = helper1.CreateAudioReceiveStream();
|
|
|
|
|
auto recv_stream2 = helper2.CreateAudioReceiveStream();
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(*helper1.channel_receive(), StartPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper2.channel_receive(), StartPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper1.channel_receive(), StopPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper2.channel_receive(), StopPlayout()).Times(1);
|
|
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream1.get()))
|
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), AddSource(recv_stream2.get()))
|
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream1.get()))
|
|
|
|
|
.Times(1);
|
|
|
|
|
EXPECT_CALL(*helper1.audio_mixer(), RemoveSource(recv_stream2.get()))
|
|
|
|
|
.Times(1);
|
|
|
|
|
|
|
|
|
|
recv_stream1->Start();
|
|
|
|
|
recv_stream2->Start();
|
|
|
|
|
|
|
|
|
|
// One more should not result in any more mixer sources added.
|
|
|
|
|
recv_stream1->Start();
|
|
|
|
|
|
|
|
|
|
// Stop stream before it is being destructed.
|
|
|
|
|
recv_stream2->Stop();
|
2021-05-31 12:57:53 +02:00
|
|
|
|
|
|
|
|
recv_stream1->UnregisterFromTransport();
|
|
|
|
|
recv_stream2->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2016-11-22 06:42:53 -08:00
|
|
|
}
|
2018-01-10 15:17:10 +01:00
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, ReconfigureWithUpdatedConfig) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper(use_null_audio_processing);
|
|
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
|
|
|
|
|
|
|
|
|
auto new_config = helper.config();
|
2021-06-09 13:46:28 +02:00
|
|
|
|
2020-04-26 23:56:17 +02:00
|
|
|
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));
|
2021-06-08 16:55:47 +02:00
|
|
|
|
2021-06-09 10:15:47 +00:00
|
|
|
MockChannelReceive& channel_receive = *helper.channel_receive();
|
2021-06-09 13:46:28 +02:00
|
|
|
|
|
|
|
|
// TODO(tommi, nisse): This applies new extensions to the internal config,
|
|
|
|
|
// but there's nothing that actually verifies that the changes take effect.
|
|
|
|
|
// In fact Call manages the extensions separately in Call::ReceiveRtpConfig
|
|
|
|
|
// and changing this config value (there seem to be a few copies), doesn't
|
|
|
|
|
// affect that logic.
|
|
|
|
|
recv_stream->ReconfigureForTesting(new_config);
|
|
|
|
|
|
|
|
|
|
new_config.decoder_map.emplace(1, SdpAudioFormat("foo", 8000, 1));
|
2021-06-09 10:15:47 +00:00
|
|
|
EXPECT_CALL(channel_receive, SetReceiveCodecs(new_config.decoder_map));
|
2021-06-09 13:46:28 +02:00
|
|
|
recv_stream->SetDecoderMap(new_config.decoder_map);
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(channel_receive, SetNACKStatus(true, 15 + 1)).Times(1);
|
|
|
|
|
recv_stream->SetUseTransportCcAndNackHistory(new_config.rtp.transport_cc,
|
|
|
|
|
300 + 20);
|
2020-04-26 23:56:17 +02:00
|
|
|
|
2021-05-31 12:57:53 +02:00
|
|
|
recv_stream->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2018-01-10 15:17:10 +01:00
|
|
|
}
|
2018-10-25 09:52:57 -07:00
|
|
|
|
|
|
|
|
TEST(AudioReceiveStreamTest, ReconfigureWithFrameDecryptor) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
ConfigHelper helper(use_null_audio_processing);
|
|
|
|
|
auto recv_stream = helper.CreateAudioReceiveStream();
|
|
|
|
|
|
|
|
|
|
auto new_config_0 = helper.config();
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> mock_frame_decryptor_0(
|
2021-04-22 19:21:43 +02:00
|
|
|
rtc::make_ref_counted<MockFrameDecryptor>());
|
2020-04-26 23:56:17 +02:00
|
|
|
new_config_0.frame_decryptor = mock_frame_decryptor_0;
|
|
|
|
|
|
2021-06-09 13:46:28 +02:00
|
|
|
// TODO(tommi): While this changes the internal config value, it doesn't
|
|
|
|
|
// actually change what frame_decryptor is used. WebRtcAudioReceiveStream
|
|
|
|
|
// recreates the whole instance in order to change this value.
|
|
|
|
|
// So, it's not clear if changing this post initialization needs to be
|
|
|
|
|
// supported.
|
|
|
|
|
recv_stream->ReconfigureForTesting(new_config_0);
|
2020-04-26 23:56:17 +02:00
|
|
|
|
|
|
|
|
auto new_config_1 = helper.config();
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> mock_frame_decryptor_1(
|
2021-04-22 19:21:43 +02:00
|
|
|
rtc::make_ref_counted<MockFrameDecryptor>());
|
2020-04-26 23:56:17 +02:00
|
|
|
new_config_1.frame_decryptor = mock_frame_decryptor_1;
|
|
|
|
|
new_config_1.crypto_options.sframe.require_frame_encryption = true;
|
2021-06-09 13:46:28 +02:00
|
|
|
recv_stream->ReconfigureForTesting(new_config_1);
|
2021-05-31 12:57:53 +02:00
|
|
|
recv_stream->UnregisterFromTransport();
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2018-10-25 09:52:57 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-22 10:49:27 +02:00
|
|
|
} // namespace test
|
2015-09-23 15:53:52 +02:00
|
|
|
} // namespace webrtc
|