Test fixes

Get webrtc unit tests building again, and fix some failures.
This commit is contained in:
Miriam Zimmerman 2024-06-11 10:30:46 -04:00 committed by GitHub
parent 7c9970cacb
commit 84b959dd20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 134 additions and 36 deletions

View file

@ -25,7 +25,9 @@ FakeFrameDecryptor::Result FakeFrameDecryptor::Decrypt(
const std::vector<uint32_t>& csrcs,
rtc::ArrayView<const uint8_t> additional_data,
rtc::ArrayView<const uint8_t> encrypted_frame,
rtc::ArrayView<uint8_t> frame) {
rtc::ArrayView<uint8_t> frame,
// RingRTC change to encrypt media header
bool has_encrypted_media_header) {
if (fail_decryption_) {
return Result(Status::kFailedToDecrypt, 0);
}

View file

@ -38,7 +38,9 @@ class FakeFrameDecryptor : public FrameDecryptorInterface {
const std::vector<uint32_t>& csrcs,
rtc::ArrayView<const uint8_t> additional_data,
rtc::ArrayView<const uint8_t> encrypted_frame,
rtc::ArrayView<uint8_t> frame) override;
rtc::ArrayView<uint8_t> frame,
// RingRTC change to encrypt media header
bool has_encrypted_media_header=false) override;
// Always returns 1 less than the size of the encrypted frame.
size_t GetMaxPlaintextByteSize(cricket::MediaType media_type,
size_t encrypted_frame_size) override;

View file

@ -26,7 +26,9 @@ class MockFrameDecryptor : public FrameDecryptorInterface {
const std::vector<uint32_t>&,
rtc::ArrayView<const uint8_t>,
rtc::ArrayView<const uint8_t>,
rtc::ArrayView<uint8_t>),
rtc::ArrayView<uint8_t>,
// RingRTC change to encrypt media header
bool),
(override));
MOCK_METHOD(size_t,

View file

@ -204,17 +204,14 @@ class MockPeerConnectionInterface : public webrtc::PeerConnectionInterface {
MOCK_METHOD(void, Close, (), (override));
// RingRTC changes for added methods
MOCK_METHOD0(CreateSharedIceGatherer,
rtc::scoped_refptr<webrtc::IceGathererInterface>());
MOCK_METHOD1(UseSharedIceGatherer,
bool(rtc::scoped_refptr<webrtc::IceGathererInterface>));
MOCK_METHOD1(SendRtp,
bool(std::unique_ptr<RtpPacket>));
MOCK_METHOD2(ReceiveRtp,
bool(uint8_t),
bool(bool));
MOCK_METHOD1(SetIncomingRtpEnabled,
bool(bool));
MOCK_METHOD(rtc::scoped_refptr<webrtc::IceGathererInterface>,
CreateSharedIceGatherer, (), (override));
MOCK_METHOD(bool, UseSharedIceGatherer,
(rtc::scoped_refptr<webrtc::IceGathererInterface>), (override));
MOCK_METHOD(bool, SendRtp, (std::unique_ptr<RtpPacket>), (override));
MOCK_METHOD(bool, ReceiveRtp, (uint8_t, bool), (override));
MOCK_METHOD(bool, SetIncomingRtpEnabled, (bool), (override));
MOCK_METHOD(uint32_t, GetLastBandwidthEstimateBps, (), (override));
};
static_assert(

View file

@ -118,7 +118,8 @@ struct Params {
absl::optional<AudioConfig> audio_config;
// Flags to set on `cricket::PortAllocator`. These flags will be added
// to the default ones that are presented on the port allocator.
uint32_t port_allocator_extra_flags = cricket::kDefaultPortAllocatorFlags;
// RingRTC change to avoid incorrect use of flag in non-test code.
uint32_t port_allocator_extra_flags = 0;
// If `rtc_event_log_path` is set, an RTCEventLog will be saved in that
// location and it will be available for further analysis.
absl::optional<std::string> rtc_event_log_path;

View file

@ -67,6 +67,9 @@ class ChannelReceiveTest : public Test {
/* jitter_buffer_max_packets= */ 0,
/* jitter_buffer_fast_playout= */ false,
/* jitter_buffer_min_delay_ms= */ 0,
// RingRTC change to get tests building again.
/* jitter_buffer_max_target_delay_ms= */ 0,
/* rtcp_report_interval_ms= */0,
/* enable_non_sender_rtt= */ false, audio_decoder_factory_,
/* codec_pair_id= */ absl::nullopt,
/* frame_decryptor_interface= */ nullptr, crypto_options,

View file

@ -45,6 +45,9 @@ class MockChannelReceive : public voe::ChannelReceiveInterface {
GetDecodingCallStatistics,
(),
(const, override));
// RingRTC change to get tests building again.
MOCK_METHOD(void, SetIncomingAudioMuted, (bool), (override));
MOCK_METHOD(int, GetSpeechOutputLevelFullRange, (), (const, override));
MOCK_METHOD(double, GetTotalOutputEnergy, (), (const, override));
MOCK_METHOD(double, GetTotalOutputDuration, (), (const, override));

View file

@ -484,6 +484,14 @@ class FakeVoiceMediaReceiveChannel
absl::optional<int> GetBaseMinimumPlayoutDelayMs(
uint32_t ssrc) const override;
// RingRTC change to disable CNG for muted incoming streams.
void SetIncomingAudioMuted(uint32_t ssrc, bool muted) override {}
// RingRTC change to get audio levels
absl::optional<cricket::ReceivedAudioLevel> GetReceivedAudioLevel() override {
return absl::nullopt;
}
bool GetStats(VoiceMediaReceiveInfo* info,
bool get_and_clear_legacy_stats) override;
@ -578,6 +586,12 @@ class FakeVoiceMediaSendChannel
absl::AnyInvocable<void()> callback) override {}
absl::optional<Codec> GetSendCodec() const override;
// RingRTC change to configure opus
void ConfigureEncoders(const webrtc::AudioEncoder::Config& config) override {}
// RingRTC change to get audio levels
void GetCapturedAudioLevel(cricket::AudioLevel* captured_out) override {}
bool GetStats(VoiceMediaSendInfo* stats) override;
private:

View file

@ -113,6 +113,9 @@ class FakeAudioReceiveStream final
config_.sync_group = std::string(sync_group);
}
// RingRTC change to disable CNG for muted incoming streams.
void SetIncomingAudioMuted(bool muted) override {}
uint32_t remote_ssrc() const override { return config_.rtp.remote_ssrc; }
void Start() override { started_ = true; }
void Stop() override { started_ = false; }

View file

@ -123,6 +123,10 @@ rtc_library("red") {
"../../api:array_view",
"../../api:field_trials_view",
"../../api/audio_codecs:audio_codecs_api",
# RingRTC: This creates an Opus Config.
# TODO: Remove libred dependency on opus: This target uses audio_encoder_opus,
# but that is "poisoned" to prevent dependencies in audio_coding.
"../../api/audio_codecs/opus:audio_encoder_opus_config",
"../../api/units:time_delta",
"../../common_audio",
"../../rtc_base:buffer",
@ -992,6 +996,11 @@ if (rtc_include_tests) {
}
if (!build_with_mozilla && !build_with_chromium) {
audio_coding_deps += [ ":red" ]
# RingRTC: `:red` depends on this but cannot directly declare that.
audio_coding_deps += [
"../../api/audio_codecs/opus:audio_decoder_opus",
"../../api/audio_codecs/opus:audio_encoder_opus",
]
}
rtc_source_set("mocks") {

View file

@ -224,12 +224,14 @@ class FakePortAllocator : public cricket::PortAllocator {
public:
FakePortAllocator(rtc::Thread* network_thread,
rtc::PacketSocketFactory* factory,
webrtc::FieldTrialsView* field_trials)
// RingRTC change to get tests to build.
const webrtc::FieldTrialsView* field_trials)
: FakePortAllocator(network_thread, factory, nullptr, field_trials) {}
FakePortAllocator(rtc::Thread* network_thread,
std::unique_ptr<rtc::PacketSocketFactory> factory,
webrtc::FieldTrialsView* field_trials)
// RingRTC change to get tests to build.
const webrtc::FieldTrialsView* field_trials)
: FakePortAllocator(network_thread,
nullptr,
std::move(factory),
@ -247,10 +249,11 @@ class FakePortAllocator : public cricket::PortAllocator {
component, std::string(ice_ufrag), std::string(ice_pwd), field_trials_);
}
// RingRTC change to enable ICE forking.
rtc::scoped_refptr<webrtc::IceGathererInterface> CreateIceGatherer(
const std::string& content_name) override {
auto new_allocator = std::make_unique<FakePortAllocator>(
network_thread_, nullptr /* factory */);
network_thread_, factory_.get(), field_trials_);
IceParameters parameters =
cricket::IceCredentialsIterator::CreateRandomIceCredentials();
auto session = new_allocator->CreateSession(
@ -273,7 +276,8 @@ class FakePortAllocator : public cricket::PortAllocator {
FakePortAllocator(rtc::Thread* network_thread,
rtc::PacketSocketFactory* factory,
std::unique_ptr<rtc::PacketSocketFactory> owned_factory,
webrtc::FieldTrialsView* field_trials)
// RingRTC change to get tests building.
const webrtc::FieldTrialsView* field_trials)
: network_thread_(network_thread),
factory_(std::move(owned_factory), factory),
field_trials_(field_trials) {

View file

@ -83,6 +83,9 @@ static const int kDefaultTimeout = 10000;
static const int kMediumTimeout = 3000;
static const int kShortTimeout = 1000;
// RingRTC change to avoid incorrect use of flag (only used for tests).
const uint32_t kDefaultPortAllocatorFlags = 0;
static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
cricket::PORTALLOCATOR_DISABLE_RELAY |
cricket::PORTALLOCATOR_DISABLE_TCP;
@ -4540,6 +4543,8 @@ TEST_F(P2PTransportChannelPingTest,
ch.MaybeStartGathering();
Connection* conn =
CreateConnectionWithCandidate(&ch, &clock, "1.1.1.1", 1, 10, false);
// RingRTC change to prevent segfault.
ASSERT_NE(conn, nullptr);
ReceivePingOnConnection(conn, kIceUfrag[1], 1, 2U);
EXPECT_EQ(2U, conn->remote_nomination());
// Smaller nomination is ignored.
@ -6180,21 +6185,25 @@ TEST(P2PTransportChannel, InjectActiveIceController) {
/* component= */ 77, std::move(init));
}
// RingRTC change to enable ICE forking.
TEST_F(P2PTransportChannelPingTest, Forking) {
// Prepare two transports with a shared gatherer
rtc::ScopedFakeClock clock;
FakePortAllocator fake_port_allocator1(rtc::Thread::Current(), nullptr);
FakePortAllocator fake_port_allocator1(rtc::Thread::Current(), packet_socket_factory(),
&field_trials_);
auto transport1 = std::make_unique<P2PTransportChannel>(
"transport1", 1, &fake_port_allocator1);
PrepareChannel(transport1.get());
FakePortAllocator fake_port_allocator2(rtc::Thread::Current(), nullptr);
FakePortAllocator fake_port_allocator2(rtc::Thread::Current(), packet_socket_factory(),
&field_trials_);
auto transport2 = std::make_unique<P2PTransportChannel>(
"transport2", 1, &fake_port_allocator2);
PrepareChannel(transport2.get());
auto shared_pa =
std::make_unique<FakePortAllocator>(rtc::Thread::Current(), nullptr);
std::make_unique<FakePortAllocator>(rtc::Thread::Current(), packet_socket_factory(),
&field_trials_);
auto gatherer = shared_pa->CreateIceGatherer("test");
EXPECT_EQ(IceGatheringState::kIceGatheringNew, transport1->gathering_state());

View file

@ -100,8 +100,8 @@ enum class IceRegatheringReason {
MAX_VALUE
};
// RingRTC change to avoid incorrect use of flag (enable for test builds)
//const uint32_t kDefaultPortAllocatorFlags = 0;
// RingRTC change to avoid incorrect use of flag
// const uint32_t kDefaultPortAllocatorFlags = 0;
const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay.
// As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain

View file

@ -1987,6 +1987,9 @@ if (rtc_include_tests && !build_with_chromium) {
":used_ids",
":video_rtp_receiver",
"../api:array_view",
# RingRTC: Transitive dep on opus encode/decode via audio_coding:red.
"../api/audio_codecs:builtin_audio_decoder_factory",
"../api/audio_codecs:builtin_audio_encoder_factory",
"../api:audio_options_api",
"../api:candidate",
"../api:dtls_transport_interface",

View file

@ -216,6 +216,9 @@ class FakePeerConnectionBase : public PeerConnectionInternal {
return false;
}
// RingRTC change to get upload bandwidth estimate
uint32_t GetLastBandwidthEstimateBps() { return 0; }
RTCError SetBitrate(const BitrateSettings& bitrate) override {
return RTCError(RTCErrorType::UNSUPPORTED_OPERATION, "Not implemented");
}

View file

@ -169,6 +169,8 @@ class MockPeerConnectionInternal : public PeerConnectionInternal {
RemoveIceCandidates,
(const std::vector<cricket::Candidate>&),
(override));
// RingRTC change to get unit tests building.
MOCK_METHOD(uint32_t, GetLastBandwidthEstimateBps, (), (override));
MOCK_METHOD(RTCError, SetBitrate, (const BitrateSettings&), (override));
MOCK_METHOD(void, SetAudioPlayout, (bool), (override));
MOCK_METHOD(void, SetAudioRecording, (bool), (override));

View file

@ -63,6 +63,13 @@ class MockVoiceMediaReceiveChannelInterface
SetDefaultRawAudioSink,
(std::unique_ptr<webrtc::AudioSinkInterface> sink),
(override));
// RingRTC change to disable CNG for muted incoming streams.
MOCK_METHOD(void, SetIncomingAudioMuted, (uint32_t, bool), (override));
// RingRTC change to get audio levels
MOCK_METHOD(absl::optional<cricket::ReceivedAudioLevel>,
GetReceivedAudioLevel,
(),
(override));
MOCK_METHOD(bool,
GetStats,
(VoiceMediaReceiveInfo * stats, bool reset_legacy),

View file

@ -191,6 +191,9 @@ if (!is_component_build) {
]
deps = [
# RingRTC: Transitive dep on opus encode/decode via audio_coding:red.
"..//api/audio_codecs:builtin_audio_decoder_factory",
"..//api/audio_codecs:builtin_audio_encoder_factory",
"..//api/video_codecs:video_decoder_factory_template",
"..//api/video_codecs:video_decoder_factory_template_dav1d_adapter",
"..//api/video_codecs:video_decoder_factory_template_libvpx_vp8_adapter",
@ -256,6 +259,9 @@ if (!is_component_build) {
deps = [
"../api:field_trials",
"../api:rtp_parameters",
# RingRTC: Transitive dep on opus encode/decode via audio_coding:red.
"../api/audio_codecs:builtin_audio_decoder_factory",
"../api/audio_codecs:builtin_audio_encoder_factory",
"../api/environment",
"../api/environment:environment_factory",
"../api/task_queue",

View file

@ -82,6 +82,10 @@ const absl::string_view kResourcesDirName = "resources";
// Finds the WebRTC src dir.
// The returned path always ends with a path separator.
absl::optional<std::string> ProjectRootPath() {
// RingRTC change to locate resources directory correctly.
const std::string ringrtc_path_change =
std::string(kPathDelimiter) + "src" + std::string(kPathDelimiter) +
"webrtc" + std::string(kPathDelimiter) + "src";
#if defined(WEBRTC_ANDROID)
return std::string(kAndroidChromiumTestsRoot);
#elif defined WEBRTC_IOS
@ -92,7 +96,8 @@ absl::optional<std::string> ProjectRootPath() {
std::string exe_dir = DirName(path);
// On Mac, tests execute in out/Whatever, so src is two levels up except if
// the test is bundled (which our tests are not), in which case it's 5 levels.
return DirName(DirName(exe_dir)) + std::string(kPathDelimiter);
// RingRTC change to locate resources directory correctly.
return DirName(DirName(exe_dir)) + ringrtc_path_change + std::string(kPathDelimiter);
#elif defined(WEBRTC_POSIX)
// Fuchsia uses POSIX defines as well but does not have full POSIX
// functionality.
@ -107,7 +112,8 @@ absl::optional<std::string> ProjectRootPath() {
}
// On POSIX, tests execute in out/Whatever, so src is two levels up.
std::string exe_dir = DirName(absl::string_view(buf, count));
return DirName(DirName(exe_dir)) + std::string(kPathDelimiter);
// RingRTC change to locate resources directory correctly.
return DirName(DirName(exe_dir)) + ringrtc_path_change + std::string(kPathDelimiter);
#endif
#elif defined(WEBRTC_WIN)
wchar_t buf[MAX_PATH];
@ -117,7 +123,8 @@ absl::optional<std::string> ProjectRootPath() {
std::string exe_path = rtc::ToUtf8(std::wstring(buf));
std::string exe_dir = DirName(exe_path);
return DirName(DirName(exe_dir)) + std::string(kPathDelimiter);
// RingRTC change to locate resources directory correctly.
return DirName(DirName(exe_dir)) + ringrtc_path_change + std::string(kPathDelimiter);
#endif
}
@ -131,7 +138,10 @@ std::string OutputPath() {
#else
absl::optional<std::string> path_opt = ProjectRootPath();
RTC_DCHECK(path_opt);
std::string path = *path_opt + "out";
// RingRTC change to locate resources directory correctly.
// e.g. ringrtc/src/webrtc/src should become ringrtc/out
std::string ringrtc_path_change = DirName(DirName(DirName(*path_opt)));
std::string path = ringrtc_path_change + std::string(kPathDelimiter) + "out";
if (!CreateDir(path)) {
return "./";
}

View file

@ -19,15 +19,19 @@
#include "api/stats/rtcstats_objects.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/video_codecs/video_decoder_factory_template.h"
#include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
// RingRTC change to exclude av1 and h264 factories
// #include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_decoder_factory_template_open_h264_adapter.h"
// RingRTC change to exclude av1 and h264 factories
// #include "api/video_codecs/video_decoder_factory_template_open_h264_adapter.h"
#include "api/video_codecs/video_encoder_factory_template.h"
#include "api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h"
// RingRTC change to exclude av1 and h264 factories
// #include "api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h"
#include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
// RingRTC change to exclude av1 and h264 factories
// #include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h"
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_processing/include/audio_processing.h"
@ -40,14 +44,28 @@ void CreateSomeMediaDeps(PeerConnectionFactoryDependencies& media_deps) {
webrtc::CreateAudioEncoderFactory<webrtc::AudioEncoderOpus>();
media_deps.audio_decoder_factory =
webrtc::CreateAudioDecoderFactory<webrtc::AudioDecoderOpus>();
// RingRTC change to exclude av1 and h264 factories
media_deps.video_encoder_factory =
std::make_unique<VideoEncoderFactoryTemplate<
LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter,
OpenH264EncoderTemplateAdapter, LibaomAv1EncoderTemplateAdapter>>();
LibvpxVp8EncoderTemplateAdapter,
#if defined(WEBRTC_USE_H264)
webrtc::OpenH264EncoderTemplateAdapter,
#endif
#if defined(RTC_USE_LIBAOM_AV1_ENCODER)
webrtc::LibaomAv1EncoderTemplateAdapter,
#endif
webrtc::LibvpxVp9EncoderTemplateAdapter>>();
// RingRTC change to exclude av1 and h264 factories
media_deps.video_decoder_factory =
std::make_unique<VideoDecoderFactoryTemplate<
LibvpxVp8DecoderTemplateAdapter, LibvpxVp9DecoderTemplateAdapter,
OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>();
LibvpxVp8DecoderTemplateAdapter,
#if defined(WEBRTC_USE_H264)
OpenH264DecoderTemplateAdapter,
#endif
#if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
Dav1dDecoderTemplateAdapter,
#endif
LibvpxVp9DecoderTemplateAdapter>>();
media_deps.audio_processing = webrtc::AudioProcessingBuilder().Create();
}