diff --git a/audio/BUILD.gn b/audio/BUILD.gn index 2523c32b93..412d51e288 100644 --- a/audio/BUILD.gn +++ b/audio/BUILD.gn @@ -39,6 +39,7 @@ rtc_library("audio") { deps = [ "../api:array_view", + "../api:bitrate_allocation", "../api:call_api", "../api:field_trials_view", "../api:frame_transformer_interface", @@ -67,6 +68,8 @@ rtc_library("audio") { "../api/task_queue", "../api/task_queue:pending_task_safety_flag", "../api/transport/rtp:rtp_source", + "../api/units:data_rate", + "../api/units:data_size", "../api/units:time_delta", "../api/units:timestamp", "../call:audio_sender_interface", diff --git a/audio/channel_send.cc b/audio/channel_send.cc index fa8a42146c..d65f321285 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -11,39 +11,62 @@ #include "audio/channel_send.h" #include -#include +#include +#include +#include #include +#include #include #include #include +#include "absl/strings/string_view.h" #include "api/array_view.h" +#include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/call/bitrate_allocation.h" #include "api/call/transport.h" +#include "api/crypto/crypto_options.h" #include "api/crypto/frame_encryptor_interface.h" -#include "api/rtc_event_log/rtc_event_log.h" +#include "api/environment/environment.h" +#include "api/frame_transformer_interface.h" +#include "api/function_view.h" +#include "api/make_ref_counted.h" +#include "api/media_types.h" +#include "api/rtp_headers.h" +#include "api/scoped_refptr.h" #include "api/sequence_checker.h" +#include "api/task_queue/task_queue_base.h" #include "api/task_queue/task_queue_factory.h" +#include "api/units/data_rate.h" +#include "api/units/data_size.h" +#include "api/units/time_delta.h" +#include "api/units/timestamp.h" #include "audio/channel_send_frame_transformer_delegate.h" #include "audio/utility/audio_frame_operations.h" #include "call/rtp_transport_controller_send_interface.h" -#include "logging/rtc_event_log/events/rtc_event_audio_playout.h" -#include "modules/audio_coding/audio_network_adaptor/include/audio_network_adaptor_config.h" #include "modules/audio_coding/include/audio_coding_module.h" +#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_processing/rms_level.h" #include "modules/pacing/packet_router.h" +#include "modules/rtp_rtcp/include/report_block_data.h" +#include "modules/rtp_rtcp/include/rtcp_statistics.h" +#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" +#include "modules/rtp_rtcp/source/rtp_header_extensions.h" +#include "modules/rtp_rtcp/source/rtp_packet_to_send.h" #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h" +#include "modules/rtp_rtcp/source/rtp_sender_audio.h" +#include "rtc_base/buffer.h" #include "rtc_base/checks.h" #include "rtc_base/event.h" #include "rtc_base/logging.h" -#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/race_checker.h" #include "rtc_base/rate_limiter.h" #include "rtc_base/strings/string_builder.h" #include "rtc_base/synchronization/mutex.h" #include "rtc_base/system/no_unique_address.h" -#include "rtc_base/time_utils.h" +#include "rtc_base/thread_annotations.h" #include "rtc_base/trace_event.h" -#include "system_wrappers/include/clock.h" #include "system_wrappers/include/metrics.h" namespace webrtc { @@ -51,8 +74,8 @@ namespace voe { namespace { -constexpr int64_t kMaxRetransmissionWindowMs = 1000; -constexpr int64_t kMinRetransmissionWindowMs = 30; +constexpr TimeDelta kMaxRetransmissionWindow = TimeDelta::Seconds(1); +constexpr TimeDelta kMinRetransmissionWindow = TimeDelta::Millis(30); class RtpPacketSenderProxy; class TransportSequenceNumberProxy; @@ -173,8 +196,6 @@ class ChannelSend : public ChannelSendInterface, // packet. void ProcessAndEncodeAudio(std::unique_ptr audio_frame) override; - int64_t GetRTT() const override; - // E2EE Custom Audio Frame Encryption void SetFrameEncryptor( rtc::scoped_refptr frame_encryptor) override; @@ -474,7 +495,7 @@ ChannelSend::ChannelSend( ssrc_(ssrc), rtp_packet_pacer_proxy_(new RtpPacketSenderProxy()), retransmission_rate_limiter_( - new RateLimiter(&env_.clock(), kMaxRetransmissionWindowMs)), + new RateLimiter(&env_.clock(), kMaxRetransmissionWindow.ms())), frame_encryptor_(frame_encryptor), crypto_options_(crypto_options), encoder_queue_(env_.task_queue_factory().CreateTaskQueue( @@ -646,21 +667,16 @@ void ChannelSend::ReceivedRTCPPacket(const uint8_t* data, size_t length) { // Deliver RTCP packet to RTP/RTCP module for parsing rtp_rtcp_->IncomingRtcpPacket(rtc::MakeArrayView(data, length)); - int64_t rtt = GetRTT(); - if (rtt == 0) { + std::optional rtt = rtp_rtcp_->LastRtt(); + if (!rtt.has_value()) { // Waiting for valid RTT. return; } - int64_t nack_window_ms = rtt; - if (nack_window_ms < kMinRetransmissionWindowMs) { - nack_window_ms = kMinRetransmissionWindowMs; - } else if (nack_window_ms > kMaxRetransmissionWindowMs) { - nack_window_ms = kMaxRetransmissionWindowMs; - } - retransmission_rate_limiter_->SetWindowSize(nack_window_ms); + retransmission_rate_limiter_->SetWindowSize( + rtt->Clamped(kMinRetransmissionWindow, kMaxRetransmissionWindow).ms()); - OnReceivedRtt(rtt); + OnReceivedRtt(rtt->ms()); } void ChannelSend::SetInputMute(bool enable) { @@ -759,7 +775,7 @@ std::vector ChannelSend::GetRemoteRTCPReportBlocks() const { CallSendStatistics ChannelSend::GetRTCPStatistics() const { RTC_DCHECK_RUN_ON(&worker_thread_checker_); CallSendStatistics stats = {0}; - stats.rttMs = GetRTT(); + stats.rttMs = rtp_rtcp_->LastRtt().value_or(TimeDelta::Zero()).ms(); StreamDataCounters rtp_stats; StreamDataCounters rtx_stats; @@ -888,18 +904,6 @@ RtpRtcpInterface* ChannelSend::GetRtpRtcp() const { return rtp_rtcp_.get(); } -int64_t ChannelSend::GetRTT() const { - std::vector report_blocks = - rtp_rtcp_->GetLatestReportBlockData(); - if (report_blocks.empty()) { - return 0; - } - - // We don't know in advance the remote ssrc used by the other end's receiver - // reports, so use the first report block for the RTT. - return report_blocks.front().last_rtt().ms(); -} - void ChannelSend::SetFrameEncryptor( rtc::scoped_refptr frame_encryptor) { RTC_DCHECK_RUN_ON(&worker_thread_checker_); diff --git a/audio/channel_send.h b/audio/channel_send.h index 02215e49cb..8cd5b4e875 100644 --- a/audio/channel_send.h +++ b/audio/channel_send.h @@ -11,19 +11,27 @@ #ifndef AUDIO_CHANNEL_SEND_H_ #define AUDIO_CHANNEL_SEND_H_ +#include +#include #include -#include +#include #include +#include "absl/strings/string_view.h" #include "api/audio/audio_frame.h" #include "api/audio_codecs/audio_encoder.h" +#include "api/audio_codecs/audio_format.h" +#include "api/call/bitrate_allocation.h" #include "api/crypto/crypto_options.h" #include "api/environment/environment.h" #include "api/frame_transformer_interface.h" #include "api/function_view.h" +#include "api/scoped_refptr.h" +#include "api/units/data_rate.h" +#include "api/units/time_delta.h" #include "modules/rtp_rtcp/include/report_block_data.h" +#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" -#include "modules/rtp_rtcp/source/rtp_sender_audio.h" namespace webrtc { @@ -87,17 +95,6 @@ class ChannelSendInterface { std::unique_ptr audio_frame) = 0; virtual RtpRtcpInterface* GetRtpRtcp() const = 0; - // In RTP we currently rely on RTCP packets (`ReceivedRTCPPacket`) to inform - // about RTT. - // In media transport we rely on the TargetTransferRateObserver instead. - // In other words, if you are using RTP, you should expect - // `ReceivedRTCPPacket` to be called, if you are using media transport, - // `OnTargetTransferRate` will be called. - // - // In future, RTP media will move to the media transport implementation and - // these conditions will be removed. - // Returns the RTT in milliseconds. - virtual int64_t GetRTT() const = 0; virtual void StartSend() = 0; virtual void StopSend() = 0; diff --git a/audio/mock_voe_channel_proxy.h b/audio/mock_voe_channel_proxy.h index e1b0ad0e1e..31d99844d8 100644 --- a/audio/mock_voe_channel_proxy.h +++ b/audio/mock_voe_channel_proxy.h @@ -185,7 +185,6 @@ class MockChannelSend : public voe::ChannelSendInterface { (override)); MOCK_METHOD(RtpRtcpInterface*, GetRtpRtcp, (), (const, override)); MOCK_METHOD(int, GetTargetBitrate, (), (const, override)); - MOCK_METHOD(int64_t, GetRTT, (), (const, override)); MOCK_METHOD(void, StartSend, (), (override)); MOCK_METHOD(void, StopSend, (), (override)); MOCK_METHOD(void,