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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/call.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2024-09-02 20:55:52 +00:00
|
|
|
#include <cstdint>
|
2015-10-16 14:35:07 -07:00
|
|
|
#include <list>
|
2016-03-12 06:10:44 -08:00
|
|
|
#include <memory>
|
2024-09-02 20:55:52 +00:00
|
|
|
#include <string>
|
2017-05-08 11:52:38 -07:00
|
|
|
#include <utility>
|
2024-09-02 20:55:52 +00:00
|
|
|
#include <vector>
|
2015-10-16 14:35:07 -07:00
|
|
|
|
2022-05-17 11:48:46 +02:00
|
|
|
#include "absl/strings/string_view.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "api/adaptation/resource.h"
|
2023-11-27 17:57:44 +01:00
|
|
|
#include "api/environment/environment.h"
|
|
|
|
|
#include "api/environment/environment_factory.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "api/make_ref_counted.h"
|
2023-03-28 17:27:47 +02:00
|
|
|
#include "api/media_types.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "api/scoped_refptr.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/test/mock_audio_mixer.h"
|
2020-06-11 12:07:14 +02:00
|
|
|
#include "api/test/video/function_video_encoder_factory.h"
|
2023-03-28 17:27:47 +02:00
|
|
|
#include "api/units/timestamp.h"
|
2020-06-11 12:07:14 +02:00
|
|
|
#include "api/video/builtin_video_bitrate_allocator_factory.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "api/video_codecs/sdp_video_format.h"
|
2018-01-11 13:52:30 +01:00
|
|
|
#include "audio/audio_receive_stream.h"
|
|
|
|
|
#include "audio/audio_send_stream.h"
|
2020-06-11 12:07:14 +02:00
|
|
|
#include "call/adaptation/test/fake_resource.h"
|
2020-07-01 15:48:46 +02:00
|
|
|
#include "call/adaptation/test/mock_resource_listener.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "call/audio_receive_stream.h"
|
|
|
|
|
#include "call/audio_send_stream.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/audio_state.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "call/call_config.h"
|
|
|
|
|
#include "call/flexfec_receive_stream.h"
|
|
|
|
|
#include "call/video_send_stream.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/audio_device/include/mock_audio_device.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_processing/include/mock_audio_processing.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/fake_encoder.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "test/gmock.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gtest.h"
|
|
|
|
|
#include "test/mock_audio_decoder_factory.h"
|
|
|
|
|
#include "test/mock_transport.h"
|
2020-05-05 15:35:45 +02:00
|
|
|
#include "test/run_loop.h"
|
2024-09-02 20:55:52 +00:00
|
|
|
#include "video/config/video_encoder_config.h"
|
2015-10-16 14:35:07 -07:00
|
|
|
|
2023-10-13 13:53:00 +02:00
|
|
|
namespace webrtc {
|
2015-10-16 14:35:07 -07:00
|
|
|
namespace {
|
|
|
|
|
|
2020-07-01 15:48:46 +02:00
|
|
|
using ::testing::_;
|
2023-03-28 17:27:47 +02:00
|
|
|
using ::testing::MockFunction;
|
2020-12-03 11:30:34 -05:00
|
|
|
using ::testing::NiceMock;
|
2020-07-01 15:48:46 +02:00
|
|
|
using ::testing::StrictMock;
|
2024-04-11 18:10:31 +02:00
|
|
|
using ::webrtc::test::FakeEncoder;
|
|
|
|
|
using ::webrtc::test::FunctionVideoEncoderFactory;
|
2023-10-13 13:53:00 +02:00
|
|
|
using ::webrtc::test::MockAudioDeviceModule;
|
|
|
|
|
using ::webrtc::test::MockAudioMixer;
|
|
|
|
|
using ::webrtc::test::MockAudioProcessing;
|
|
|
|
|
using ::webrtc::test::RunLoop;
|
2020-06-11 12:07:14 +02:00
|
|
|
|
2015-10-16 14:35:07 -07:00
|
|
|
struct CallHelper {
|
2020-04-26 23:56:17 +02:00
|
|
|
explicit CallHelper(bool use_null_audio_processing) {
|
2023-10-13 13:53:00 +02:00
|
|
|
AudioState::Config audio_state_config;
|
|
|
|
|
audio_state_config.audio_mixer = rtc::make_ref_counted<MockAudioMixer>();
|
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
|
|
|
audio_state_config.audio_processing =
|
2020-04-26 23:56:17 +02:00
|
|
|
use_null_audio_processing
|
|
|
|
|
? nullptr
|
2023-10-13 13:53:00 +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
|
|
|
audio_state_config.audio_device_module =
|
2023-10-13 13:53:00 +02:00
|
|
|
rtc::make_ref_counted<MockAudioDeviceModule>();
|
2023-11-27 17:57:44 +01:00
|
|
|
CallConfig config(CreateEnvironment());
|
2023-10-13 13:53:00 +02:00
|
|
|
config.audio_state = AudioState::Create(audio_state_config);
|
2024-07-29 07:54:20 +02:00
|
|
|
call_ = Call::Create(std::move(config));
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-13 13:53:00 +02:00
|
|
|
Call* operator->() { return call_.get(); }
|
2015-10-16 14:35:07 -07:00
|
|
|
|
|
|
|
|
private:
|
2023-10-13 13:53:00 +02:00
|
|
|
RunLoop loop_;
|
|
|
|
|
std::unique_ptr<Call> call_;
|
2015-10-16 14:35:07 -07:00
|
|
|
};
|
2020-07-01 15:48:46 +02:00
|
|
|
|
|
|
|
|
rtc::scoped_refptr<Resource> FindResourceWhoseNameContains(
|
|
|
|
|
const std::vector<rtc::scoped_refptr<Resource>>& resources,
|
2022-05-17 11:48:46 +02:00
|
|
|
absl::string_view name_contains) {
|
2020-07-01 15:48:46 +02:00
|
|
|
for (const auto& resource : resources) {
|
2022-05-17 11:48:46 +02:00
|
|
|
if (resource->Name().find(std::string(name_contains)) != std::string::npos)
|
2020-07-01 15:48:46 +02:00
|
|
|
return resource;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2015-10-16 14:35:07 -07:00
|
|
|
TEST(CallTest, ConstructDestruct) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
|
|
|
|
}
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, CreateDestroy_AudioSendStream) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
|
|
|
|
MockTransport send_transport;
|
|
|
|
|
AudioSendStream::Config config(&send_transport);
|
|
|
|
|
config.rtp.ssrc = 42;
|
|
|
|
|
AudioSendStream* stream = call->CreateAudioSendStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
call->DestroyAudioSendStream(stream);
|
|
|
|
|
}
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, CreateDestroy_AudioReceiveStream) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
2022-05-22 20:47:28 +02:00
|
|
|
AudioReceiveStreamInterface::Config config;
|
2020-04-26 23:56:17 +02:00
|
|
|
MockTransport rtcp_send_transport;
|
|
|
|
|
config.rtp.remote_ssrc = 42;
|
|
|
|
|
config.rtcp_send_transport = &rtcp_send_transport;
|
|
|
|
|
config.decoder_factory =
|
2021-04-22 19:21:43 +02:00
|
|
|
rtc::make_ref_counted<webrtc::MockAudioDecoderFactory>();
|
2022-05-22 20:47:28 +02:00
|
|
|
AudioReceiveStreamInterface* stream =
|
|
|
|
|
call->CreateAudioReceiveStream(config);
|
2020-04-26 23:56:17 +02:00
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
call->DestroyAudioReceiveStream(stream);
|
|
|
|
|
}
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, CreateDestroy_AudioSendStreams) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
|
|
|
|
MockTransport send_transport;
|
|
|
|
|
AudioSendStream::Config config(&send_transport);
|
|
|
|
|
std::list<AudioSendStream*> streams;
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
|
|
|
|
|
config.rtp.ssrc = ssrc;
|
|
|
|
|
AudioSendStream* stream = call->CreateAudioSendStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
if (ssrc & 1) {
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
} else {
|
|
|
|
|
streams.push_front(stream);
|
|
|
|
|
}
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
2020-04-26 23:56:17 +02:00
|
|
|
for (auto s : streams) {
|
|
|
|
|
call->DestroyAudioSendStream(s);
|
|
|
|
|
}
|
|
|
|
|
streams.clear();
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
2022-05-22 20:47:28 +02:00
|
|
|
AudioReceiveStreamInterface::Config config;
|
2020-04-26 23:56:17 +02:00
|
|
|
MockTransport rtcp_send_transport;
|
|
|
|
|
config.rtcp_send_transport = &rtcp_send_transport;
|
|
|
|
|
config.decoder_factory =
|
2021-04-22 19:21:43 +02:00
|
|
|
rtc::make_ref_counted<webrtc::MockAudioDecoderFactory>();
|
2022-05-22 20:47:28 +02:00
|
|
|
std::list<AudioReceiveStreamInterface*> streams;
|
2020-04-26 23:56:17 +02:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
|
|
|
|
|
config.rtp.remote_ssrc = ssrc;
|
2022-05-22 20:47:28 +02:00
|
|
|
AudioReceiveStreamInterface* stream =
|
|
|
|
|
call->CreateAudioReceiveStream(config);
|
2020-04-26 23:56:17 +02:00
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
if (ssrc & 1) {
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
} else {
|
|
|
|
|
streams.push_front(stream);
|
|
|
|
|
}
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
2020-04-26 23:56:17 +02:00
|
|
|
for (auto s : streams) {
|
|
|
|
|
call->DestroyAudioReceiveStream(s);
|
|
|
|
|
}
|
|
|
|
|
streams.clear();
|
2015-10-16 14:35:07 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-23 23:37:14 -07:00
|
|
|
|
|
|
|
|
TEST(CallTest, CreateDestroy_FlexfecReceiveStream) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
|
|
|
|
MockTransport rtcp_send_transport;
|
|
|
|
|
FlexfecReceiveStream::Config config(&rtcp_send_transport);
|
|
|
|
|
config.payload_type = 118;
|
2021-06-14 10:54:20 +02:00
|
|
|
config.rtp.remote_ssrc = 38837212;
|
2020-04-26 23:56:17 +02:00
|
|
|
config.protected_media_ssrcs = {27273};
|
|
|
|
|
|
|
|
|
|
FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
call->DestroyFlexfecReceiveStream(stream);
|
|
|
|
|
}
|
2016-10-23 23:37:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
|
|
|
|
MockTransport rtcp_send_transport;
|
|
|
|
|
FlexfecReceiveStream::Config config(&rtcp_send_transport);
|
|
|
|
|
config.payload_type = 118;
|
|
|
|
|
std::list<FlexfecReceiveStream*> streams;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
|
2021-06-14 10:54:20 +02:00
|
|
|
config.rtp.remote_ssrc = ssrc;
|
2020-04-26 23:56:17 +02:00
|
|
|
config.protected_media_ssrcs = {ssrc + 1};
|
|
|
|
|
FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
if (ssrc & 1) {
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
} else {
|
|
|
|
|
streams.push_front(stream);
|
|
|
|
|
}
|
2016-10-23 23:37:14 -07:00
|
|
|
}
|
2020-04-26 23:56:17 +02:00
|
|
|
for (auto s : streams) {
|
|
|
|
|
call->DestroyFlexfecReceiveStream(s);
|
|
|
|
|
}
|
|
|
|
|
streams.clear();
|
2016-10-23 23:37:14 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) {
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
|
|
|
|
MockTransport rtcp_send_transport;
|
|
|
|
|
FlexfecReceiveStream::Config config(&rtcp_send_transport);
|
|
|
|
|
config.payload_type = 118;
|
|
|
|
|
config.protected_media_ssrcs = {1324234};
|
|
|
|
|
FlexfecReceiveStream* stream;
|
|
|
|
|
std::list<FlexfecReceiveStream*> streams;
|
|
|
|
|
|
2021-06-14 10:54:20 +02:00
|
|
|
config.rtp.remote_ssrc = 838383;
|
2020-04-26 23:56:17 +02:00
|
|
|
stream = call->CreateFlexfecReceiveStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
|
2021-06-14 10:54:20 +02:00
|
|
|
config.rtp.remote_ssrc = 424993;
|
2020-04-26 23:56:17 +02:00
|
|
|
stream = call->CreateFlexfecReceiveStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
|
2021-06-14 10:54:20 +02:00
|
|
|
config.rtp.remote_ssrc = 99383;
|
2020-04-26 23:56:17 +02:00
|
|
|
stream = call->CreateFlexfecReceiveStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
|
2021-06-14 10:54:20 +02:00
|
|
|
config.rtp.remote_ssrc = 5548;
|
2020-04-26 23:56:17 +02:00
|
|
|
stream = call->CreateFlexfecReceiveStream(config);
|
|
|
|
|
EXPECT_NE(stream, nullptr);
|
|
|
|
|
streams.push_back(stream);
|
|
|
|
|
|
|
|
|
|
for (auto s : streams) {
|
|
|
|
|
call->DestroyFlexfecReceiveStream(s);
|
|
|
|
|
}
|
2016-10-23 23:37:14 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-28 17:27:47 +02:00
|
|
|
TEST(CallTest,
|
|
|
|
|
DeliverRtpPacketOfTypeAudioTriggerOnUndemuxablePacketHandlerIfNotDemuxed) {
|
|
|
|
|
CallHelper call(/*use_null_audio_processing=*/false);
|
|
|
|
|
MockFunction<bool(const RtpPacketReceived& parsed_packet)>
|
|
|
|
|
un_demuxable_packet_handler;
|
|
|
|
|
|
|
|
|
|
RtpPacketReceived packet;
|
|
|
|
|
packet.set_arrival_time(Timestamp::Millis(1));
|
|
|
|
|
EXPECT_CALL(un_demuxable_packet_handler, Call);
|
|
|
|
|
call->Receiver()->DeliverRtpPacket(
|
|
|
|
|
MediaType::AUDIO, packet, un_demuxable_packet_handler.AsStdFunction());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest,
|
|
|
|
|
DeliverRtpPacketOfTypeVideoTriggerOnUndemuxablePacketHandlerIfNotDemuxed) {
|
|
|
|
|
CallHelper call(/*use_null_audio_processing=*/false);
|
|
|
|
|
MockFunction<bool(const RtpPacketReceived& parsed_packet)>
|
|
|
|
|
un_demuxable_packet_handler;
|
|
|
|
|
|
|
|
|
|
RtpPacketReceived packet;
|
|
|
|
|
packet.set_arrival_time(Timestamp::Millis(1));
|
|
|
|
|
EXPECT_CALL(un_demuxable_packet_handler, Call);
|
|
|
|
|
call->Receiver()->DeliverRtpPacket(
|
|
|
|
|
MediaType::VIDEO, packet, un_demuxable_packet_handler.AsStdFunction());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest,
|
|
|
|
|
DeliverRtpPacketOfTypeAnyDoesNotTriggerOnUndemuxablePacketHandler) {
|
|
|
|
|
CallHelper call(/*use_null_audio_processing=*/false);
|
|
|
|
|
MockFunction<bool(const RtpPacketReceived& parsed_packet)>
|
|
|
|
|
un_demuxable_packet_handler;
|
|
|
|
|
|
|
|
|
|
RtpPacketReceived packet;
|
|
|
|
|
packet.set_arrival_time(Timestamp::Millis(1));
|
|
|
|
|
EXPECT_CALL(un_demuxable_packet_handler, Call).Times(0);
|
|
|
|
|
call->Receiver()->DeliverRtpPacket(
|
|
|
|
|
MediaType::ANY, packet, un_demuxable_packet_handler.AsStdFunction());
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 06:07:11 -07:00
|
|
|
TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) {
|
|
|
|
|
constexpr uint32_t kSSRC = 12345;
|
2020-04-26 23:56:17 +02:00
|
|
|
for (bool use_null_audio_processing : {false, true}) {
|
|
|
|
|
CallHelper call(use_null_audio_processing);
|
2017-05-23 06:07:11 -07:00
|
|
|
|
2020-04-26 23:56:17 +02:00
|
|
|
auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) {
|
|
|
|
|
MockTransport send_transport;
|
|
|
|
|
AudioSendStream::Config config(&send_transport);
|
|
|
|
|
config.rtp.ssrc = ssrc;
|
|
|
|
|
AudioSendStream* stream = call->CreateAudioSendStream(config);
|
|
|
|
|
const RtpState rtp_state =
|
|
|
|
|
static_cast<internal::AudioSendStream*>(stream)->GetRtpState();
|
|
|
|
|
call->DestroyAudioSendStream(stream);
|
|
|
|
|
return rtp_state;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC);
|
|
|
|
|
const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
|
|
|
|
|
EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
|
|
|
|
|
EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
|
2023-04-26 10:46:10 +02:00
|
|
|
EXPECT_EQ(rtp_state1.capture_time, rtp_state2.capture_time);
|
|
|
|
|
EXPECT_EQ(rtp_state1.last_timestamp_time, rtp_state2.last_timestamp_time);
|
2020-04-26 23:56:17 +02:00
|
|
|
}
|
2017-05-23 06:07:11 -07:00
|
|
|
}
|
2018-01-11 13:52:30 +01:00
|
|
|
|
2020-06-11 12:07:14 +02:00
|
|
|
TEST(CallTest, AddAdaptationResourceAfterCreatingVideoSendStream) {
|
|
|
|
|
CallHelper call(true);
|
|
|
|
|
// Create a VideoSendStream.
|
2024-04-11 18:10:31 +02:00
|
|
|
FunctionVideoEncoderFactory fake_encoder_factory(
|
2024-10-29 14:47:48 +02:00
|
|
|
[](const Environment& env, const SdpVideoFormat& /* format */) {
|
2024-04-11 18:10:31 +02:00
|
|
|
return std::make_unique<FakeEncoder>(env);
|
|
|
|
|
});
|
2020-06-11 12:07:14 +02:00
|
|
|
auto bitrate_allocator_factory = CreateBuiltinVideoBitrateAllocatorFactory();
|
|
|
|
|
MockTransport send_transport;
|
|
|
|
|
VideoSendStream::Config config(&send_transport);
|
|
|
|
|
config.rtp.payload_type = 110;
|
|
|
|
|
config.rtp.ssrcs = {42};
|
|
|
|
|
config.encoder_settings.encoder_factory = &fake_encoder_factory;
|
|
|
|
|
config.encoder_settings.bitrate_allocator_factory =
|
|
|
|
|
bitrate_allocator_factory.get();
|
|
|
|
|
VideoEncoderConfig encoder_config;
|
|
|
|
|
encoder_config.max_bitrate_bps = 1337;
|
2020-07-01 15:48:46 +02:00
|
|
|
VideoSendStream* stream1 =
|
|
|
|
|
call->CreateVideoSendStream(config.Copy(), encoder_config.Copy());
|
|
|
|
|
EXPECT_NE(stream1, nullptr);
|
|
|
|
|
config.rtp.ssrcs = {43};
|
|
|
|
|
VideoSendStream* stream2 =
|
|
|
|
|
call->CreateVideoSendStream(config.Copy(), encoder_config.Copy());
|
|
|
|
|
EXPECT_NE(stream2, nullptr);
|
|
|
|
|
// Add a fake resource.
|
2020-06-11 12:07:14 +02:00
|
|
|
auto fake_resource = FakeResource::Create("FakeResource");
|
|
|
|
|
call->AddAdaptationResource(fake_resource);
|
2021-07-26 12:40:21 +02:00
|
|
|
// An adapter resource mirroring the `fake_resource` should now be present on
|
2020-07-01 15:48:46 +02:00
|
|
|
// both streams.
|
|
|
|
|
auto injected_resource1 = FindResourceWhoseNameContains(
|
|
|
|
|
stream1->GetAdaptationResources(), fake_resource->Name());
|
|
|
|
|
EXPECT_TRUE(injected_resource1);
|
|
|
|
|
auto injected_resource2 = FindResourceWhoseNameContains(
|
|
|
|
|
stream2->GetAdaptationResources(), fake_resource->Name());
|
|
|
|
|
EXPECT_TRUE(injected_resource2);
|
|
|
|
|
// Overwrite the real resource listeners with mock ones to verify the signal
|
|
|
|
|
// gets through.
|
|
|
|
|
injected_resource1->SetResourceListener(nullptr);
|
|
|
|
|
StrictMock<MockResourceListener> resource_listener1;
|
|
|
|
|
EXPECT_CALL(resource_listener1, OnResourceUsageStateMeasured(_, _))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce([injected_resource1](rtc::scoped_refptr<Resource> resource,
|
|
|
|
|
ResourceUsageState usage_state) {
|
|
|
|
|
EXPECT_EQ(injected_resource1, resource);
|
|
|
|
|
EXPECT_EQ(ResourceUsageState::kOveruse, usage_state);
|
|
|
|
|
});
|
|
|
|
|
injected_resource1->SetResourceListener(&resource_listener1);
|
|
|
|
|
injected_resource2->SetResourceListener(nullptr);
|
|
|
|
|
StrictMock<MockResourceListener> resource_listener2;
|
|
|
|
|
EXPECT_CALL(resource_listener2, OnResourceUsageStateMeasured(_, _))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce([injected_resource2](rtc::scoped_refptr<Resource> resource,
|
|
|
|
|
ResourceUsageState usage_state) {
|
|
|
|
|
EXPECT_EQ(injected_resource2, resource);
|
|
|
|
|
EXPECT_EQ(ResourceUsageState::kOveruse, usage_state);
|
|
|
|
|
});
|
|
|
|
|
injected_resource2->SetResourceListener(&resource_listener2);
|
|
|
|
|
// The kOveruse signal should get to our resource listeners.
|
|
|
|
|
fake_resource->SetUsageState(ResourceUsageState::kOveruse);
|
|
|
|
|
call->DestroyVideoSendStream(stream1);
|
|
|
|
|
call->DestroyVideoSendStream(stream2);
|
2020-06-11 12:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(CallTest, AddAdaptationResourceBeforeCreatingVideoSendStream) {
|
|
|
|
|
CallHelper call(true);
|
|
|
|
|
// Add a fake resource.
|
|
|
|
|
auto fake_resource = FakeResource::Create("FakeResource");
|
|
|
|
|
call->AddAdaptationResource(fake_resource);
|
|
|
|
|
// Create a VideoSendStream.
|
2024-04-11 18:10:31 +02:00
|
|
|
FunctionVideoEncoderFactory fake_encoder_factory(
|
2024-10-29 14:47:48 +02:00
|
|
|
[](const Environment& env, const SdpVideoFormat& /* format */) {
|
2024-04-11 18:10:31 +02:00
|
|
|
return std::make_unique<FakeEncoder>(env);
|
|
|
|
|
});
|
2020-06-11 12:07:14 +02:00
|
|
|
auto bitrate_allocator_factory = CreateBuiltinVideoBitrateAllocatorFactory();
|
|
|
|
|
MockTransport send_transport;
|
|
|
|
|
VideoSendStream::Config config(&send_transport);
|
|
|
|
|
config.rtp.payload_type = 110;
|
|
|
|
|
config.rtp.ssrcs = {42};
|
|
|
|
|
config.encoder_settings.encoder_factory = &fake_encoder_factory;
|
|
|
|
|
config.encoder_settings.bitrate_allocator_factory =
|
|
|
|
|
bitrate_allocator_factory.get();
|
|
|
|
|
VideoEncoderConfig encoder_config;
|
|
|
|
|
encoder_config.max_bitrate_bps = 1337;
|
2020-07-01 15:48:46 +02:00
|
|
|
VideoSendStream* stream1 =
|
|
|
|
|
call->CreateVideoSendStream(config.Copy(), encoder_config.Copy());
|
|
|
|
|
EXPECT_NE(stream1, nullptr);
|
|
|
|
|
config.rtp.ssrcs = {43};
|
|
|
|
|
VideoSendStream* stream2 =
|
|
|
|
|
call->CreateVideoSendStream(config.Copy(), encoder_config.Copy());
|
|
|
|
|
EXPECT_NE(stream2, nullptr);
|
2021-07-26 12:40:21 +02:00
|
|
|
// An adapter resource mirroring the `fake_resource` should be present on both
|
2020-07-01 15:48:46 +02:00
|
|
|
// streams.
|
|
|
|
|
auto injected_resource1 = FindResourceWhoseNameContains(
|
|
|
|
|
stream1->GetAdaptationResources(), fake_resource->Name());
|
|
|
|
|
EXPECT_TRUE(injected_resource1);
|
|
|
|
|
auto injected_resource2 = FindResourceWhoseNameContains(
|
|
|
|
|
stream2->GetAdaptationResources(), fake_resource->Name());
|
|
|
|
|
EXPECT_TRUE(injected_resource2);
|
|
|
|
|
// Overwrite the real resource listeners with mock ones to verify the signal
|
|
|
|
|
// gets through.
|
|
|
|
|
injected_resource1->SetResourceListener(nullptr);
|
|
|
|
|
StrictMock<MockResourceListener> resource_listener1;
|
|
|
|
|
EXPECT_CALL(resource_listener1, OnResourceUsageStateMeasured(_, _))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce([injected_resource1](rtc::scoped_refptr<Resource> resource,
|
|
|
|
|
ResourceUsageState usage_state) {
|
|
|
|
|
EXPECT_EQ(injected_resource1, resource);
|
|
|
|
|
EXPECT_EQ(ResourceUsageState::kUnderuse, usage_state);
|
|
|
|
|
});
|
|
|
|
|
injected_resource1->SetResourceListener(&resource_listener1);
|
|
|
|
|
injected_resource2->SetResourceListener(nullptr);
|
|
|
|
|
StrictMock<MockResourceListener> resource_listener2;
|
|
|
|
|
EXPECT_CALL(resource_listener2, OnResourceUsageStateMeasured(_, _))
|
|
|
|
|
.Times(1)
|
|
|
|
|
.WillOnce([injected_resource2](rtc::scoped_refptr<Resource> resource,
|
|
|
|
|
ResourceUsageState usage_state) {
|
|
|
|
|
EXPECT_EQ(injected_resource2, resource);
|
|
|
|
|
EXPECT_EQ(ResourceUsageState::kUnderuse, usage_state);
|
|
|
|
|
});
|
|
|
|
|
injected_resource2->SetResourceListener(&resource_listener2);
|
|
|
|
|
// The kUnderuse signal should get to our resource listeners.
|
|
|
|
|
fake_resource->SetUsageState(ResourceUsageState::kUnderuse);
|
|
|
|
|
call->DestroyVideoSendStream(stream1);
|
|
|
|
|
call->DestroyVideoSendStream(stream2);
|
2020-06-11 12:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-16 14:35:07 -07:00
|
|
|
} // namespace webrtc
|