Use Environment instead of Clock in ModuleRtpRtcp and its RTP subcomponents

Bug: webrtc:362762208
Change-Id: I35af5cf3ed48e2c738c12df2ed9117a640ed0ff7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/361720
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42966}
This commit is contained in:
Danil Chapovalov 2024-09-05 10:40:34 +02:00 committed by WebRTC LUCI CQ
parent e94c7da1df
commit e922cd1262
9 changed files with 75 additions and 67 deletions

View File

@ -698,6 +698,7 @@ if (rtc_include_tests) {
"../../api/video:video_bitrate_allocator",
"../../api/video:video_codec_constants",
"../../api/video:video_frame",
"../../api/video:video_frame_type",
"../../api/video:video_layers_allocation",
"../../api/video:video_rtp_headers",
"../../api/video_codecs:video_codecs_api",

View File

@ -22,10 +22,6 @@ namespace webrtc {
class [[deprecated("bugs.webrtc.org/42224904")]] RtpRtcp
: public RtpRtcpInterface {
public:
[[deprecated("bugs.webrtc.org/362762208")]] //
static std::unique_ptr<RtpRtcp>
Create(const Configuration& configuration);
[[deprecated("bugs.webrtc.org/42224904")]] //
static std::unique_ptr<RtpRtcp>
Create(const Environment& env, const Configuration& configuration);

View File

@ -18,6 +18,8 @@
#include "api/array_view.h"
#include "api/call/transport.h"
#include "api/environment/environment.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/transport/network_types.h"
#include "api/units/data_rate.h"
#include "api/units/time_delta.h"
@ -72,17 +74,17 @@ void DEPRECATED_RtpSenderEgress::NonPacedPacketSender::EnqueuePackets(
}
DEPRECATED_RtpSenderEgress::DEPRECATED_RtpSenderEgress(
const Environment& env,
const RtpRtcpInterface::Configuration& config,
RtpPacketHistory* packet_history)
: ssrc_(config.local_media_ssrc),
: env_(env),
ssrc_(config.local_media_ssrc),
rtx_ssrc_(config.rtx_send_ssrc),
flexfec_ssrc_(config.fec_generator ? config.fec_generator->FecSsrc()
: std::nullopt),
populate_network2_timestamp_(config.populate_network2_timestamp),
clock_(config.clock),
packet_history_(packet_history),
transport_(config.outgoing_transport),
event_log_(config.event_log),
need_rtp_packet_infos_(config.need_rtp_packet_infos),
transport_feedback_observer_(config.transport_feedback_callback),
send_packet_observer_(config.send_packet_observer),
@ -105,7 +107,7 @@ void DEPRECATED_RtpSenderEgress::SendPacket(
const uint32_t packet_ssrc = packet->Ssrc();
RTC_DCHECK(packet->packet_type().has_value());
RTC_DCHECK(HasCorrectSsrc(*packet));
Timestamp now = clock_->CurrentTime();
Timestamp now = env_.clock().CurrentTime();
int64_t now_ms = now.ms();
PacketOptions options;
{
@ -205,7 +207,7 @@ RtpSendRates DEPRECATED_RtpSenderEgress::GetSendRates() const {
}
RtpSendRates DEPRECATED_RtpSenderEgress::GetSendRatesLocked() const {
const Timestamp now = clock_->CurrentTime();
const Timestamp now = env_.clock().CurrentTime();
RtpSendRates current_rates;
for (size_t i = 0; i < kNumMediaTypes; ++i) {
RtpPacketMediaType type = static_cast<RtpPacketMediaType>(i);
@ -317,26 +319,18 @@ bool DEPRECATED_RtpSenderEgress::SendPacketToNetwork(
const RtpPacketToSend& packet,
const PacketOptions& options,
const PacedPacketInfo& pacing_info) {
int bytes_sent = -1;
if (transport_) {
bytes_sent = transport_->SendRtp(packet, options)
? static_cast<int>(packet.size())
: -1;
if (event_log_ && bytes_sent > 0) {
event_log_->Log(std::make_unique<RtcEventRtpPacketOutgoing>(
packet, pacing_info.probe_cluster_id));
}
}
if (bytes_sent <= 0) {
if (transport_ == nullptr || !transport_->SendRtp(packet, options)) {
RTC_LOG(LS_WARNING) << "Transport failed to send packet.";
return false;
}
env_.event_log().Log(std::make_unique<RtcEventRtpPacketOutgoing>(
packet, pacing_info.probe_cluster_id));
return true;
}
void DEPRECATED_RtpSenderEgress::UpdateRtpStats(const RtpPacketToSend& packet) {
Timestamp now = clock_->CurrentTime();
Timestamp now = env_.clock().CurrentTime();
StreamDataCounters* counters =
packet.Ssrc() == rtx_ssrc_ ? &rtx_rtp_stats_ : &rtp_stats_;

View File

@ -18,7 +18,7 @@
#include "api/array_view.h"
#include "api/call/transport.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/environment/environment.h"
#include "api/rtp_packet_sender.h"
#include "api/transport/network_types.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@ -53,7 +53,8 @@ class DEPRECATED_RtpSenderEgress {
PacketSequencer* sequence_number_assigner_;
};
DEPRECATED_RtpSenderEgress(const RtpRtcpInterface::Configuration& config,
DEPRECATED_RtpSenderEgress(const Environment& env,
const RtpRtcpInterface::Configuration& config,
RtpPacketHistory* packet_history);
~DEPRECATED_RtpSenderEgress() = default;
@ -100,14 +101,13 @@ class DEPRECATED_RtpSenderEgress {
void UpdateRtpStats(const RtpPacketToSend& packet)
RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
const Environment env_;
const uint32_t ssrc_;
const std::optional<uint32_t> rtx_ssrc_;
const std::optional<uint32_t> flexfec_ssrc_;
const bool populate_network2_timestamp_;
Clock* const clock_;
RtpPacketHistory* const packet_history_;
Transport* const transport_;
RtcEventLog* const event_log_;
const bool need_rtp_packet_infos_;
TransportFeedbackObserver* const transport_feedback_observer_;

View File

@ -56,25 +56,22 @@ constexpr TimeDelta kDefaultExpectedRetransmissionTime = TimeDelta::Millis(125);
} // namespace
ModuleRtpRtcpImpl::RtpSenderContext::RtpSenderContext(
const Environment& env,
const RtpRtcpInterface::Configuration& config)
: packet_history(config.clock,
: packet_history(&env.clock(),
RtpPacketHistory::PaddingMode::kRecentLargePacket),
sequencer_(config.local_media_ssrc,
config.rtx_send_ssrc,
/*require_marker_before_media_padding=*/!config.audio,
config.clock),
packet_sender(config, &packet_history),
&env.clock()),
packet_sender(env, config, &packet_history),
non_paced_sender(&packet_sender, &sequencer_),
packet_generator(
env,
config,
&packet_history,
config.paced_sender ? config.paced_sender : &non_paced_sender) {}
std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Configuration& configuration) {
RTC_DCHECK(configuration.clock);
return std::make_unique<ModuleRtpRtcpImpl>(configuration);
}
std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Environment& env,
const Configuration& configuration) {
RTC_DCHECK(configuration.field_trials == nullptr);
@ -85,23 +82,24 @@ std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Environment& env,
config.field_trials = &env.field_trials();
config.clock = &env.clock();
config.event_log = &env.event_log();
return std::make_unique<ModuleRtpRtcpImpl>(config);
return std::make_unique<ModuleRtpRtcpImpl>(env, config);
}
ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
: rtcp_sender_(
ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Environment& env,
const Configuration& configuration)
: env_(env),
rtcp_sender_(
RTCPSender::Configuration::FromRtpRtcpConfiguration(configuration)),
rtcp_receiver_(configuration, this),
clock_(configuration.clock),
last_bitrate_process_time_(clock_->TimeInMilliseconds()),
last_rtt_process_time_(clock_->TimeInMilliseconds()),
last_bitrate_process_time_(env_.clock().TimeInMilliseconds()),
last_rtt_process_time_(env_.clock().TimeInMilliseconds()),
packet_overhead_(28), // IPV4 UDP.
nack_last_time_sent_full_ms_(0),
nack_last_seq_number_sent_(0),
rtt_stats_(configuration.rtt_stats),
rtt_ms_(0) {
if (!configuration.receiver_only) {
rtp_sender_ = std::make_unique<RtpSenderContext>(configuration);
rtp_sender_ = std::make_unique<RtpSenderContext>(env, configuration);
// Make sure rtcp sender use same timestamp offset as rtp sender.
rtcp_sender_.SetTimestampOffset(
rtp_sender_->packet_generator.TimestampOffset());
@ -118,7 +116,7 @@ ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default;
// Process any pending tasks such as timeouts (non time critical events).
void ModuleRtpRtcpImpl::Process() {
const int64_t now = clock_->TimeInMilliseconds();
const int64_t now = env_.clock().TimeInMilliseconds();
if (rtp_sender_) {
if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
@ -576,7 +574,7 @@ int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
const uint16_t size) {
uint16_t nack_length = size;
uint16_t start_id = 0;
int64_t now_ms = clock_->TimeInMilliseconds();
int64_t now_ms = env_.clock().TimeInMilliseconds();
if (TimeToSendFullNackList(now_ms)) {
nack_last_time_sent_full_ms_ = now_ms;
} else {

View File

@ -21,6 +21,7 @@
#include "absl/base/attributes.h"
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "api/environment/environment.h"
#include "api/rtp_headers.h"
#include "api/units/time_delta.h"
#include "api/video/video_bitrate_allocation.h"
@ -46,7 +47,6 @@
namespace webrtc {
class Clock;
struct PacedPacketInfo;
struct RTPVideoHeader;
@ -57,8 +57,8 @@ class ABSL_DEPRECATED("") ModuleRtpRtcpImpl
public RTCPReceiver::ModuleRtpRtcp {
#pragma clang diagnostic pop
public:
explicit ModuleRtpRtcpImpl(
const RtpRtcpInterface::Configuration& configuration);
ModuleRtpRtcpImpl(const Environment& env,
const RtpRtcpInterface::Configuration& configuration);
~ModuleRtpRtcpImpl() override;
// Process any pending tasks such as timeouts.
@ -278,14 +278,13 @@ class ABSL_DEPRECATED("") ModuleRtpRtcpImpl
rtp_sender_->packet_sender.SetMediaHasBeenSent(media_has_been_sent);
}
Clock* clock() const { return clock_; }
private:
FRIEND_TEST_ALL_PREFIXES(RtpRtcpImplTest, Rtt);
FRIEND_TEST_ALL_PREFIXES(RtpRtcpImplTest, RttForReceiverOnly);
struct RtpSenderContext {
explicit RtpSenderContext(const RtpRtcpInterface::Configuration& config);
RtpSenderContext(const Environment& env,
const RtpRtcpInterface::Configuration& config);
// Storage of packets, for retransmissions and padding, if applicable.
RtpPacketHistory packet_history;
// Handles sequence number assignment and padding timestamp generation.
@ -311,13 +310,12 @@ class ABSL_DEPRECATED("") ModuleRtpRtcpImpl
// Returns current Receiver Reference Time Report (RTTR) status.
bool RtcpXrRrtrStatus() const;
const Environment env_;
std::unique_ptr<RtpSenderContext> rtp_sender_;
RTCPSender rtcp_sender_;
RTCPReceiver rtcp_receiver_;
Clock* const clock_;
int64_t last_bitrate_process_time_;
int64_t last_rtt_process_time_;
uint16_t packet_overhead_;

View File

@ -10,17 +10,36 @@
#include "modules/rtp_rtcp/source/rtp_rtcp_impl.h"
#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <set>
#include <optional>
#include <vector>
#include "api/array_view.h"
#include "api/call/transport.h"
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "api/rtp_headers.h"
#include "api/units/time_delta.h"
#include "api/video/video_codec_type.h"
#include "api/video/video_content_type.h"
#include "api/video/video_frame_type.h"
#include "api/video/video_rotation.h"
#include "modules/rtp_rtcp/include/receive_statistics.h"
#include "modules/rtp_rtcp/include/rtcp_statistics.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "modules/rtp_rtcp/source/rtcp_packet.h"
#include "modules/rtp_rtcp/source/rtcp_packet/nack.h"
#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
#include "modules/rtp_rtcp/source/rtp_sender_video.h"
#include "rtc_base/rate_limiter.h"
#include "modules/rtp_rtcp/source/rtp_sequence_number_map.h"
#include "modules/video_coding/codecs/interface/common_constants.h"
#include "modules/video_coding/codecs/vp8/include/vp8_globals.h"
#include "system_wrappers/include/clock.h"
#include "system_wrappers/include/ntp_time.h"
#include "test/explicit_key_value_config.h"
#include "test/gmock.h"
#include "test/gtest.h"
@ -110,13 +129,15 @@ class SendTransport : public Transport {
class RtpRtcpModule : public RtcpPacketTypeCounterObserver {
public:
RtpRtcpModule(SimulatedClock* clock, bool is_sender)
: is_sender_(is_sender),
: env_(CreateEnvironment(clock)),
is_sender_(is_sender),
receive_statistics_(ReceiveStatistics::Create(clock)),
clock_(clock) {
CreateModuleImpl();
transport_.SimulateNetworkDelay(kOneWayNetworkDelay.ms(), clock);
}
const Environment env_;
const bool is_sender_;
RtcpPacketTypeCounter packets_sent_;
RtcpPacketTypeCounter packets_received_;
@ -167,7 +188,7 @@ class RtpRtcpModule : public RtcpPacketTypeCounterObserver {
config.need_rtp_packet_infos = true;
config.non_sender_rtt_measurement = true;
impl_.reset(new ModuleRtpRtcpImpl(config));
impl_.reset(new ModuleRtpRtcpImpl(env_, config));
impl_->SetRemoteSSRC(is_sender_ ? kReceiverSsrc : kSenderSsrc);
impl_->SetRTCPStatus(RtcpMode::kCompound);
}

View File

@ -49,6 +49,7 @@ class RTPSender {
RtpPacketHistory* packet_history,
RtpPacketSender* packet_sender);
[[deprecated("bugs.webrtc.org/362762208")]] //
RTPSender(const RtpRtcpInterface::Configuration& config,
RtpPacketHistory* packet_history,
RtpPacketSender* packet_sender);

View File

@ -11,6 +11,7 @@
#include "modules/rtp_rtcp/source/rtp_sender.h"
#include <memory>
#include <utility>
#include <vector>
#include "absl/strings/string_view.h"
@ -23,7 +24,6 @@
#include "api/units/timestamp.h"
#include "api/video/video_codec_constants.h"
#include "api/video/video_timing.h"
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "modules/rtp_rtcp/include/rtp_cvo.h"
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
@ -142,13 +142,10 @@ class RtpSenderTest : public ::testing::Test {
RtpRtcpInterface::Configuration GetDefaultConfig() {
RtpRtcpInterface::Configuration config;
config.clock = &env_.clock();
config.local_media_ssrc = kSsrc;
config.rtx_send_ssrc = kRtxSsrc;
config.event_log = &mock_rtc_event_log_;
config.retransmission_rate_limiter = &retransmission_rate_limiter_;
config.paced_sender = &mock_paced_sender_;
config.field_trials = &env_.field_trials();
// Configure rid unconditionally, it has effect only if
// corresponding header extension is enabled.
config.rid = std::string(kRid);
@ -157,19 +154,18 @@ class RtpSenderTest : public ::testing::Test {
void CreateSender(const RtpRtcpInterface::Configuration& config) {
packet_history_ = std::make_unique<RtpPacketHistory>(
config.clock, RtpPacketHistory::PaddingMode::kRecentLargePacket);
&env_.clock(), RtpPacketHistory::PaddingMode::kRecentLargePacket);
sequencer_.emplace(kSsrc, kRtxSsrc,
/*require_marker_before_media_padding=*/!config.audio,
&env_.clock());
rtp_sender_ = std::make_unique<RTPSender>(config, packet_history_.get(),
config.paced_sender);
rtp_sender_ = std::make_unique<RTPSender>(
env_, config, packet_history_.get(), config.paced_sender);
sequencer_->set_media_sequence_number(kSeqNum);
rtp_sender_->SetTimestampOffset(0);
}
GlobalSimulatedTimeController time_controller_;
const Environment env_;
NiceMock<MockRtcEventLog> mock_rtc_event_log_;
MockRtpPacketPacer mock_paced_sender_;
RateLimiter retransmission_rate_limiter_;
FlexfecSender flexfec_sender_;
@ -435,7 +431,8 @@ TEST_F(RtpSenderTest, NoPaddingAsFirstPacketWithoutBweExtensions) {
TEST_F(RtpSenderTest, RequiresRtxSsrcToEnableRtx) {
RtpRtcpInterface::Configuration config = GetDefaultConfig();
config.rtx_send_ssrc = std::nullopt;
RTPSender rtp_sender(config, packet_history_.get(), config.paced_sender);
RTPSender rtp_sender(env_, config, packet_history_.get(),
config.paced_sender);
rtp_sender.SetRtxPayloadType(kRtxPayload, kPayload);
rtp_sender.SetRtxStatus(kRtxRetransmitted);
@ -446,7 +443,8 @@ TEST_F(RtpSenderTest, RequiresRtxSsrcToEnableRtx) {
TEST_F(RtpSenderTest, RequiresRtxPayloadTypesToEnableRtx) {
RtpRtcpInterface::Configuration config = GetDefaultConfig();
config.rtx_send_ssrc = kRtxSsrc;
RTPSender rtp_sender(config, packet_history_.get(), config.paced_sender);
RTPSender rtp_sender(env_, config, packet_history_.get(),
config.paced_sender);
rtp_sender.SetRtxStatus(kRtxRetransmitted);
@ -456,7 +454,8 @@ TEST_F(RtpSenderTest, RequiresRtxPayloadTypesToEnableRtx) {
TEST_F(RtpSenderTest, CanEnableRtxWhenRtxSsrcAndPayloadTypeAreConfigured) {
RtpRtcpInterface::Configuration config = GetDefaultConfig();
config.rtx_send_ssrc = kRtxSsrc;
RTPSender rtp_sender(config, packet_history_.get(), config.paced_sender);
RTPSender rtp_sender(env_, config, packet_history_.get(),
config.paced_sender);
rtp_sender.SetRtxPayloadType(kRtxPayload, kPayload);
ASSERT_EQ(rtp_sender.RtxStatus(), kRtxOff);