From 977b3351b9aa9cdcef9113f018d87f2981cbf475 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Mon, 4 Mar 2019 17:43:34 +0100 Subject: [PATCH] Injecting Clock into audio streams. Bug: webrtc:10365 Change-Id: Ia47fd806b84d94fd90b734c87c5e338e36fb695a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125191 Reviewed-by: Oskar Sundbom Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#26969} --- audio/audio_receive_stream.cc | 11 ++++++++--- audio/audio_receive_stream.h | 5 ++++- audio/audio_receive_stream_unittest.cc | 4 ++-- audio/audio_send_stream.cc | 14 +++++++++----- audio/audio_send_stream.h | 7 +++++-- audio/audio_send_stream_unittest.cc | 5 +++-- audio/channel_receive.cc | 13 ++++++++----- audio/channel_receive.h | 1 + audio/channel_send.cc | 20 +++++++++++++------- audio/channel_send.h | 1 + audio/test/media_transport_test.cc | 4 +++- call/call.cc | 10 +++++----- 12 files changed, 62 insertions(+), 33 deletions(-) diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc index a6c81fc12d..47530c3290 100644 --- a/audio/audio_receive_stream.cc +++ b/audio/audio_receive_stream.cc @@ -67,6 +67,7 @@ std::string AudioReceiveStream::Config::ToString() const { namespace internal { namespace { std::unique_ptr CreateChannelReceive( + Clock* clock, webrtc::AudioState* audio_state, ProcessThread* module_process_thread, const webrtc::AudioReceiveStream::Config& config, @@ -75,7 +76,7 @@ std::unique_ptr CreateChannelReceive( internal::AudioState* internal_audio_state = static_cast(audio_state); return voe::CreateChannelReceive( - module_process_thread, internal_audio_state->audio_device_module(), + clock, module_process_thread, internal_audio_state->audio_device_module(), config.media_transport, config.rtcp_send_transport, event_log, config.rtp.remote_ssrc, config.jitter_buffer_max_packets, config.jitter_buffer_fast_accelerate, config.jitter_buffer_min_delay_ms, @@ -85,23 +86,27 @@ std::unique_ptr CreateChannelReceive( } // namespace AudioReceiveStream::AudioReceiveStream( + Clock* clock, RtpStreamReceiverControllerInterface* receiver_controller, PacketRouter* packet_router, ProcessThread* module_process_thread, const webrtc::AudioReceiveStream::Config& config, const rtc::scoped_refptr& audio_state, webrtc::RtcEventLog* event_log) - : AudioReceiveStream(receiver_controller, + : AudioReceiveStream(clock, + receiver_controller, packet_router, config, audio_state, event_log, - CreateChannelReceive(audio_state.get(), + CreateChannelReceive(clock, + audio_state.get(), module_process_thread, config, event_log)) {} AudioReceiveStream::AudioReceiveStream( + Clock* clock, RtpStreamReceiverControllerInterface* receiver_controller, PacketRouter* packet_router, const webrtc::AudioReceiveStream::Config& config, diff --git a/audio/audio_receive_stream.h b/audio/audio_receive_stream.h index b6d0aa5fa0..1745c0f698 100644 --- a/audio/audio_receive_stream.h +++ b/audio/audio_receive_stream.h @@ -21,6 +21,7 @@ #include "call/syncable.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/thread_checker.h" +#include "system_wrappers/include/clock.h" namespace webrtc { class PacketRouter; @@ -41,7 +42,8 @@ class AudioReceiveStream final : public webrtc::AudioReceiveStream, public AudioMixer::Source, public Syncable { public: - AudioReceiveStream(RtpStreamReceiverControllerInterface* receiver_controller, + AudioReceiveStream(Clock* clock, + RtpStreamReceiverControllerInterface* receiver_controller, PacketRouter* packet_router, ProcessThread* module_process_thread, const webrtc::AudioReceiveStream::Config& config, @@ -49,6 +51,7 @@ class AudioReceiveStream final : public webrtc::AudioReceiveStream, webrtc::RtcEventLog* event_log); // For unit tests, which need to supply a mock channel receive. AudioReceiveStream( + Clock* clock, RtpStreamReceiverControllerInterface* receiver_controller, PacketRouter* packet_router, const webrtc::AudioReceiveStream::Config& config, diff --git a/audio/audio_receive_stream_unittest.cc b/audio/audio_receive_stream_unittest.cc index b64626f55a..4594e56ed8 100644 --- a/audio/audio_receive_stream_unittest.cc +++ b/audio/audio_receive_stream_unittest.cc @@ -115,8 +115,8 @@ struct ConfigHelper { std::unique_ptr CreateAudioReceiveStream() { return std::unique_ptr( new internal::AudioReceiveStream( - &rtp_stream_receiver_controller_, &packet_router_, stream_config_, - audio_state_, &event_log_, + Clock::GetRealTimeClock(), &rtp_stream_receiver_controller_, + &packet_router_, stream_config_, audio_state_, &event_log_, std::unique_ptr(channel_receive_))); } diff --git a/audio/audio_send_stream.cc b/audio/audio_send_stream.cc index 2e4830c1f2..bb791492a9 100644 --- a/audio/audio_send_stream.cc +++ b/audio/audio_send_stream.cc @@ -37,7 +37,6 @@ #include "rtc_base/logging.h" #include "rtc_base/strings/audio_format_to_string.h" #include "rtc_base/task_queue.h" -#include "rtc_base/time_utils.h" #include "system_wrappers/include/field_trial.h" namespace webrtc { @@ -83,6 +82,7 @@ void UpdateEventLogStreamConfig(RtcEventLog* event_log, } // namespace AudioSendStream::AudioSendStream( + Clock* clock, const webrtc::AudioSendStream::Config& config, const rtc::scoped_refptr& audio_state, rtc::TaskQueue* worker_queue, @@ -92,7 +92,8 @@ AudioSendStream::AudioSendStream( RtcEventLog* event_log, RtcpRttStats* rtcp_rtt_stats, const absl::optional& suspended_rtp_state) - : AudioSendStream(config, + : AudioSendStream(clock, + config, audio_state, worker_queue, rtp_transport, @@ -100,7 +101,8 @@ AudioSendStream::AudioSendStream( event_log, rtcp_rtt_stats, suspended_rtp_state, - voe::CreateChannelSend(worker_queue, + voe::CreateChannelSend(clock, + worker_queue, module_process_thread, config.media_transport, /*overhead_observer=*/this, @@ -113,6 +115,7 @@ AudioSendStream::AudioSendStream( config.rtcp_report_interval_ms)) {} AudioSendStream::AudioSendStream( + Clock* clock, const webrtc::AudioSendStream::Config& config, const rtc::scoped_refptr& audio_state, rtc::TaskQueue* worker_queue, @@ -122,7 +125,8 @@ AudioSendStream::AudioSendStream( RtcpRttStats* rtcp_rtt_stats, const absl::optional& suspended_rtp_state, std::unique_ptr channel_send) - : worker_queue_(worker_queue), + : clock_(clock), + worker_queue_(worker_queue), config_(Config(/*send_transport=*/nullptr, /*media_transport=*/nullptr)), audio_state_(audio_state), @@ -455,7 +459,7 @@ void AudioSendStream::OnPacketAdded(uint32_t ssrc, uint16_t seq_num) { // TODO(eladalon): This function call could potentially reset the window, // setting both PLR and RPLR to unknown. Consider (during upcoming // refactoring) passing an indication of such an event. - packet_loss_tracker_.OnPacketAdded(seq_num, rtc::TimeMillis()); + packet_loss_tracker_.OnPacketAdded(seq_num, clock_->TimeInMilliseconds()); } } diff --git a/audio/audio_send_stream.h b/audio/audio_send_stream.h index a1dab792dd..c227e6114f 100644 --- a/audio/audio_send_stream.h +++ b/audio/audio_send_stream.h @@ -39,7 +39,8 @@ class AudioSendStream final : public webrtc::AudioSendStream, public webrtc::PacketFeedbackObserver, public webrtc::OverheadObserver { public: - AudioSendStream(const webrtc::AudioSendStream::Config& config, + AudioSendStream(Clock* clock, + const webrtc::AudioSendStream::Config& config, const rtc::scoped_refptr& audio_state, rtc::TaskQueue* worker_queue, ProcessThread* module_process_thread, @@ -49,7 +50,8 @@ class AudioSendStream final : public webrtc::AudioSendStream, RtcpRttStats* rtcp_rtt_stats, const absl::optional& suspended_rtp_state); // For unit tests, which need to supply a mock ChannelSend. - AudioSendStream(const webrtc::AudioSendStream::Config& config, + AudioSendStream(Clock* clock, + const webrtc::AudioSendStream::Config& config, const rtc::scoped_refptr& audio_state, rtc::TaskQueue* worker_queue, RtpTransportControllerSendInterface* rtp_transport, @@ -135,6 +137,7 @@ class AudioSendStream final : public webrtc::AudioSendStream, RTC_EXCLUSIVE_LOCKS_REQUIRED(overhead_per_packet_lock_); void RegisterCngPayloadType(int payload_type, int clockrate_hz); + Clock* clock_; rtc::ThreadChecker worker_thread_checker_; rtc::ThreadChecker pacer_thread_checker_; diff --git a/audio/audio_send_stream_unittest.cc b/audio/audio_send_stream_unittest.cc index 21f22185a5..ddd8137e50 100644 --- a/audio/audio_send_stream_unittest.cc +++ b/audio/audio_send_stream_unittest.cc @@ -163,8 +163,9 @@ struct ConfigHelper { std::unique_ptr CreateAudioSendStream() { return std::unique_ptr( new internal::AudioSendStream( - stream_config_, audio_state_, &worker_queue_, &rtp_transport_, - &bitrate_allocator_, &event_log_, &rtcp_rtt_stats_, absl::nullopt, + Clock::GetRealTimeClock(), stream_config_, audio_state_, + &worker_queue_, &rtp_transport_, &bitrate_allocator_, &event_log_, + &rtcp_rtt_stats_, absl::nullopt, std::unique_ptr(channel_send_))); } diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc index 0e218edb10..79523c8280 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc @@ -76,7 +76,8 @@ class ChannelReceive : public ChannelReceiveInterface, public MediaTransportAudioSinkInterface { public: // Used for receive streams. - ChannelReceive(ProcessThread* module_process_thread, + ChannelReceive(Clock* clock, + ProcessThread* module_process_thread, AudioDeviceModule* audio_device_module, MediaTransportInterface* media_transport, Transport* rtcp_send_transport, @@ -428,6 +429,7 @@ int ChannelReceive::PreferredSampleRate() const { } ChannelReceive::ChannelReceive( + Clock* clock, ProcessThread* module_process_thread, AudioDeviceModule* audio_device_module, MediaTransportInterface* media_transport, @@ -443,11 +445,10 @@ ChannelReceive::ChannelReceive( rtc::scoped_refptr frame_decryptor, const webrtc::CryptoOptions& crypto_options) : event_log_(rtc_event_log), - rtp_receive_statistics_( - ReceiveStatistics::Create(Clock::GetRealTimeClock())), + rtp_receive_statistics_(ReceiveStatistics::Create(clock)), remote_ssrc_(remote_ssrc), _outputAudioLevel(), - ntp_estimator_(Clock::GetRealTimeClock()), + ntp_estimator_(clock), playout_timestamp_rtp_(0), playout_delay_ms_(0), rtp_ts_wraparound_handler_(new rtc::TimestampWrapAroundHandler()), @@ -480,6 +481,7 @@ ChannelReceive::ChannelReceive( rtp_receive_statistics_->EnableRetransmitDetection(remote_ssrc_, true); RtpRtcp::Configuration configuration; + configuration.clock = clock; configuration.audio = true; configuration.receiver_only = true; configuration.outgoing_transport = rtcp_send_transport; @@ -959,6 +961,7 @@ int64_t ChannelReceive::GetRTT() const { } // namespace std::unique_ptr CreateChannelReceive( + Clock* clock, ProcessThread* module_process_thread, AudioDeviceModule* audio_device_module, MediaTransportInterface* media_transport, @@ -974,7 +977,7 @@ std::unique_ptr CreateChannelReceive( rtc::scoped_refptr frame_decryptor, const webrtc::CryptoOptions& crypto_options) { return absl::make_unique( - module_process_thread, audio_device_module, media_transport, + clock, module_process_thread, audio_device_module, media_transport, rtcp_send_transport, rtc_event_log, remote_ssrc, jitter_buffer_max_packets, jitter_buffer_fast_playout, jitter_buffer_min_delay_ms, jitter_buffer_enable_rtx_handling, diff --git a/audio/channel_receive.h b/audio/channel_receive.h index 28c7c06567..b3e4f9c009 100644 --- a/audio/channel_receive.h +++ b/audio/channel_receive.h @@ -136,6 +136,7 @@ class ChannelReceiveInterface : public RtpPacketSinkInterface { }; std::unique_ptr CreateChannelReceive( + Clock* clock, ProcessThread* module_process_thread, AudioDeviceModule* audio_device_module, MediaTransportInterface* media_transport, diff --git a/audio/channel_send.cc b/audio/channel_send.cc index 2db4ff713e..813795b280 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -41,6 +41,7 @@ #include "rtc_base/task_queue.h" #include "rtc_base/thread_checker.h" #include "rtc_base/time_utils.h" +#include "system_wrappers/include/clock.h" #include "system_wrappers/include/field_trial.h" #include "system_wrappers/include/metrics.h" @@ -85,7 +86,8 @@ class ChannelSend // declaration. friend class VoERtcpObserver; - ChannelSend(rtc::TaskQueue* encoder_queue, + ChannelSend(Clock* clock, + rtc::TaskQueue* encoder_queue, ProcessThread* module_process_thread, MediaTransportInterface* media_transport, OverheadObserver* overhead_observer, @@ -606,7 +608,8 @@ int32_t ChannelSend::SendMediaTransportAudio( return 0; } -ChannelSend::ChannelSend(rtc::TaskQueue* encoder_queue, +ChannelSend::ChannelSend(Clock* clock, + rtc::TaskQueue* encoder_queue, ProcessThread* module_process_thread, MediaTransportInterface* media_transport, OverheadObserver* overhead_observer, @@ -628,8 +631,8 @@ ChannelSend::ChannelSend(rtc::TaskQueue* encoder_queue, feedback_observer_proxy_(new TransportFeedbackProxy()), seq_num_allocator_proxy_(new TransportSequenceNumberProxy()), rtp_packet_sender_proxy_(new RtpPacketSenderProxy()), - retransmission_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(), - kMaxRetransmissionWindowMs)), + retransmission_rate_limiter_( + new RateLimiter(clock, kMaxRetransmissionWindowMs)), use_twcc_plr_for_ana_( webrtc::field_trial::FindFullName("UseTwccPlrForAna") == "Enabled"), encoder_queue_(encoder_queue), @@ -659,6 +662,7 @@ ChannelSend::ChannelSend(rtc::TaskQueue* encoder_queue, configuration.transport_feedback_callback = feedback_observer_proxy_.get(); } + configuration.clock = clock; configuration.audio = true; configuration.outgoing_transport = rtp_transport; @@ -1217,6 +1221,7 @@ void ChannelSend::OnReceivedRtt(int64_t rtt_ms) { } // namespace std::unique_ptr CreateChannelSend( + Clock* clock, rtc::TaskQueue* encoder_queue, ProcessThread* module_process_thread, MediaTransportInterface* media_transport, @@ -1229,9 +1234,10 @@ std::unique_ptr CreateChannelSend( bool extmap_allow_mixed, int rtcp_report_interval_ms) { return absl::make_unique( - encoder_queue, module_process_thread, media_transport, overhead_observer, - rtp_transport, rtcp_rtt_stats, rtc_event_log, frame_encryptor, - crypto_options, extmap_allow_mixed, rtcp_report_interval_ms); + clock, encoder_queue, module_process_thread, media_transport, + overhead_observer, rtp_transport, rtcp_rtt_stats, rtc_event_log, + frame_encryptor, crypto_options, extmap_allow_mixed, + rtcp_report_interval_ms); } } // namespace voe diff --git a/audio/channel_send.h b/audio/channel_send.h index 5f3dd0fd7a..4ab53c0c45 100644 --- a/audio/channel_send.h +++ b/audio/channel_send.h @@ -115,6 +115,7 @@ class ChannelSendInterface { }; std::unique_ptr CreateChannelSend( + Clock* clock, rtc::TaskQueue* encoder_queue, ProcessThread* module_process_thread, MediaTransportInterface* media_transport, diff --git a/audio/test/media_transport_test.cc b/audio/test/media_transport_test.cc index 3fd451bc07..02e3f753cb 100644 --- a/audio/test/media_transport_test.cc +++ b/audio/test/media_transport_test.cc @@ -106,6 +106,7 @@ TEST(AudioWithMediaTransport, DeliversAudio) { ProcessThread::Create("audio recv thread"); webrtc::internal::AudioReceiveStream receive_stream( + Clock::GetRealTimeClock(), /*rtp_stream_receiver_controller=*/nullptr, /*packet_router=*/nullptr, receive_process_thread.get(), receive_config, audio_state, null_event_log.get()); @@ -120,7 +121,8 @@ TEST(AudioWithMediaTransport, DeliversAudio) { std::unique_ptr send_process_thread = ProcessThread::Create("audio send thread"); webrtc::internal::AudioSendStream send_stream( - send_config, audio_state, &send_tq, send_process_thread.get(), + Clock::GetRealTimeClock(), send_config, audio_state, &send_tq, + send_process_thread.get(), /*transport=*/nullptr, &bitrate_allocator, null_event_log.get(), /*rtcp_rtt_stats=*/nullptr, absl::optional()); diff --git a/call/call.cc b/call/call.cc index 7c807797ea..98747cf7f2 100644 --- a/call/call.cc +++ b/call/call.cc @@ -670,10 +670,10 @@ webrtc::AudioSendStream* Call::CreateAudioSendStream( // having it injected. AudioSendStream* send_stream = new AudioSendStream( - config, config_.audio_state, transport_send_ptr_->GetWorkerQueue(), - module_process_thread_.get(), transport_send_ptr_, - bitrate_allocator_.get(), event_log_, call_stats_.get(), - suspended_rtp_state); + clock_, config, config_.audio_state, + transport_send_ptr_->GetWorkerQueue(), module_process_thread_.get(), + transport_send_ptr_, bitrate_allocator_.get(), event_log_, + call_stats_.get(), suspended_rtp_state); { WriteLockScoped write_lock(*send_crit_); RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == @@ -729,7 +729,7 @@ webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( event_log_->Log(absl::make_unique( CreateRtcLogStreamConfig(config))); AudioReceiveStream* receive_stream = new AudioReceiveStream( - &audio_receiver_controller_, transport_send_ptr_->packet_router(), + clock_, &audio_receiver_controller_, transport_send_ptr_->packet_router(), module_process_thread_.get(), config, config_.audio_state, event_log_); { WriteLockScoped write_lock(*receive_crit_);