From 8026d60ea96eb8de02fb9a923903c8fe1df34a77 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Mon, 4 Mar 2019 19:39:01 +0100 Subject: [PATCH] Injecting Clock in video receive. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:10365 Change-Id: Id20fca5b8ad13c133e05efa8972d8f5679507064 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125192 Commit-Queue: Sebastian Jansson Reviewed-by: Åsa Persson Cr-Commit-Position: refs/heads/master@{#26958} --- call/call.cc | 4 ++-- call/flexfec_receive_stream_impl.cc | 21 ++++++++++++------- call/flexfec_receive_stream_impl.h | 2 ++ call/flexfec_receive_stream_unittest.cc | 10 ++++----- modules/rtp_rtcp/include/flexfec_receiver.h | 4 ++++ modules/rtp_rtcp/source/flexfec_receiver.cc | 12 ++++++++++- .../source/flexfec_receiver_unittest.cc | 10 +++++---- video/rtp_video_stream_receiver.cc | 10 ++++++--- video/rtp_video_stream_receiver.h | 1 + video/rtp_video_stream_receiver_unittest.cc | 4 ++-- video/video_receive_stream.cc | 10 +++++---- video/video_receive_stream.h | 3 ++- 12 files changed, 61 insertions(+), 30 deletions(-) diff --git a/call/call.cc b/call/call.cc index fc32205514..35727b3b3d 100644 --- a/call/call.cc +++ b/call/call.cc @@ -890,7 +890,7 @@ webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( VideoReceiveStream* receive_stream = new VideoReceiveStream( task_queue_factory_, &video_receiver_controller_, num_cpu_cores_, transport_send_ptr_->packet_router(), std::move(configuration), - module_process_thread_.get(), call_stats_.get()); + module_process_thread_.get(), call_stats_.get(), clock_); const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); { @@ -962,7 +962,7 @@ FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( // TODO(nisse): Fix constructor so that it can be moved outside of // this locked scope. receive_stream = new FlexfecReceiveStreamImpl( - &video_receiver_controller_, config, recovered_packet_receiver, + clock_, &video_receiver_controller_, config, recovered_packet_receiver, call_stats_.get(), module_process_thread_.get()); RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) == diff --git a/call/flexfec_receive_stream_impl.cc b/call/flexfec_receive_stream_impl.cc index 8154715490..645df784ce 100644 --- a/call/flexfec_receive_stream_impl.cc +++ b/call/flexfec_receive_stream_impl.cc @@ -80,6 +80,7 @@ namespace { // TODO(brandtr): Update this function when we support multistream protection. std::unique_ptr MaybeCreateFlexfecReceiver( + Clock* clock, const FlexfecReceiveStream::Config& config, RecoveredPacketReceiver* recovered_packet_receiver) { if (config.payload_type < 0) { @@ -112,19 +113,20 @@ std::unique_ptr MaybeCreateFlexfecReceiver( return nullptr; } RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size()); - return std::unique_ptr( - new FlexfecReceiver(config.remote_ssrc, config.protected_media_ssrcs[0], - recovered_packet_receiver)); + return std::unique_ptr(new FlexfecReceiver( + clock, config.remote_ssrc, config.protected_media_ssrcs[0], + recovered_packet_receiver)); } std::unique_ptr CreateRtpRtcpModule( + Clock* clock, ReceiveStatistics* receive_statistics, Transport* rtcp_send_transport, RtcpRttStats* rtt_stats) { RtpRtcp::Configuration configuration; configuration.audio = false; configuration.receiver_only = true; - configuration.clock = Clock::GetRealTimeClock(); + configuration.clock = clock; configuration.receive_statistics = receive_statistics; configuration.outgoing_transport = rtcp_send_transport; configuration.rtt_stats = rtt_stats; @@ -135,16 +137,19 @@ std::unique_ptr CreateRtpRtcpModule( } // namespace FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl( + Clock* clock, RtpStreamReceiverControllerInterface* receiver_controller, const Config& config, RecoveredPacketReceiver* recovered_packet_receiver, RtcpRttStats* rtt_stats, ProcessThread* process_thread) : config_(config), - receiver_(MaybeCreateFlexfecReceiver(config_, recovered_packet_receiver)), - rtp_receive_statistics_( - ReceiveStatistics::Create(Clock::GetRealTimeClock())), - rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_.get(), + receiver_(MaybeCreateFlexfecReceiver(clock, + config_, + recovered_packet_receiver)), + rtp_receive_statistics_(ReceiveStatistics::Create(clock)), + rtp_rtcp_(CreateRtpRtcpModule(clock, + rtp_receive_statistics_.get(), config_.rtcp_send_transport, rtt_stats)), process_thread_(process_thread) { diff --git a/call/flexfec_receive_stream_impl.h b/call/flexfec_receive_stream_impl.h index 6bcbc7c9ca..d4fdc7431a 100644 --- a/call/flexfec_receive_stream_impl.h +++ b/call/flexfec_receive_stream_impl.h @@ -15,6 +15,7 @@ #include "call/flexfec_receive_stream.h" #include "call/rtp_packet_sink_interface.h" +#include "system_wrappers/include/clock.h" namespace webrtc { @@ -31,6 +32,7 @@ class RtpStreamReceiverInterface; class FlexfecReceiveStreamImpl : public FlexfecReceiveStream { public: FlexfecReceiveStreamImpl( + Clock* clock, RtpStreamReceiverControllerInterface* receiver_controller, const Config& config, RecoveredPacketReceiver* recovered_packet_receiver, diff --git a/call/flexfec_receive_stream_unittest.cc b/call/flexfec_receive_stream_unittest.cc index a1bacf9c2e..4728c8f2b9 100644 --- a/call/flexfec_receive_stream_unittest.cc +++ b/call/flexfec_receive_stream_unittest.cc @@ -89,8 +89,8 @@ class FlexfecReceiveStreamTest : public ::testing::Test { : config_(CreateDefaultConfig(&rtcp_send_transport_)) { EXPECT_CALL(process_thread_, RegisterModule(_, _)).Times(1); receive_stream_ = absl::make_unique( - &rtp_stream_receiver_controller_, config_, &recovered_packet_receiver_, - &rtt_stats_, &process_thread_); + Clock::GetRealTimeClock(), &rtp_stream_receiver_controller_, config_, + &recovered_packet_receiver_, &rtt_stats_, &process_thread_); } ~FlexfecReceiveStreamTest() { @@ -145,9 +145,9 @@ TEST_F(FlexfecReceiveStreamTest, RecoversPacket) { testing::StrictMock recovered_packet_receiver; EXPECT_CALL(process_thread_, RegisterModule(_, _)).Times(1); - FlexfecReceiveStreamImpl receive_stream(&rtp_stream_receiver_controller_, - config_, &recovered_packet_receiver, - &rtt_stats_, &process_thread_); + FlexfecReceiveStreamImpl receive_stream( + Clock::GetRealTimeClock(), &rtp_stream_receiver_controller_, config_, + &recovered_packet_receiver, &rtt_stats_, &process_thread_); EXPECT_CALL(recovered_packet_receiver, OnRecoveredPacket(_, kRtpHeaderSize + kPayloadLength[1])); diff --git a/modules/rtp_rtcp/include/flexfec_receiver.h b/modules/rtp_rtcp/include/flexfec_receiver.h index f0ed576c87..2426559b0d 100644 --- a/modules/rtp_rtcp/include/flexfec_receiver.h +++ b/modules/rtp_rtcp/include/flexfec_receiver.h @@ -30,6 +30,10 @@ class FlexfecReceiver { FlexfecReceiver(uint32_t ssrc, uint32_t protected_media_ssrc, RecoveredPacketReceiver* recovered_packet_receiver); + FlexfecReceiver(Clock* clock, + uint32_t ssrc, + uint32_t protected_media_ssrc, + RecoveredPacketReceiver* recovered_packet_receiver); ~FlexfecReceiver(); // Inserts a received packet (can be either media or FlexFEC) into the diff --git a/modules/rtp_rtcp/source/flexfec_receiver.cc b/modules/rtp_rtcp/source/flexfec_receiver.cc index 4cf58d139d..17509275a3 100644 --- a/modules/rtp_rtcp/source/flexfec_receiver.cc +++ b/modules/rtp_rtcp/source/flexfec_receiver.cc @@ -33,6 +33,16 @@ constexpr int kPacketLogIntervalMs = 10000; } // namespace FlexfecReceiver::FlexfecReceiver( + uint32_t ssrc, + uint32_t protected_media_ssrc, + RecoveredPacketReceiver* recovered_packet_receiver) + : FlexfecReceiver(Clock::GetRealTimeClock(), + ssrc, + protected_media_ssrc, + recovered_packet_receiver) {} + +FlexfecReceiver::FlexfecReceiver( + Clock* clock, uint32_t ssrc, uint32_t protected_media_ssrc, RecoveredPacketReceiver* recovered_packet_receiver) @@ -41,7 +51,7 @@ FlexfecReceiver::FlexfecReceiver( erasure_code_( ForwardErrorCorrection::CreateFlexfec(ssrc, protected_media_ssrc)), recovered_packet_receiver_(recovered_packet_receiver), - clock_(Clock::GetRealTimeClock()), + clock_(clock), last_recovered_packet_ms_(-1) { // It's OK to create this object on a different thread/task queue than // the one used during main operation. diff --git a/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc b/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc index 378cf7d6df..d19e575202 100644 --- a/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc +++ b/modules/rtp_rtcp/source/flexfec_receiver_unittest.cc @@ -49,8 +49,10 @@ class FlexfecReceiverForTest : public FlexfecReceiver { FlexfecReceiverForTest(uint32_t ssrc, uint32_t protected_media_ssrc, RecoveredPacketReceiver* recovered_packet_receiver) - : FlexfecReceiver(ssrc, protected_media_ssrc, recovered_packet_receiver) { - } + : FlexfecReceiver(Clock::GetRealTimeClock(), + ssrc, + protected_media_ssrc, + recovered_packet_receiver) {} // Expose methods for tests. using FlexfecReceiver::AddReceivedPacket; using FlexfecReceiver::ProcessReceivedPacket; @@ -466,7 +468,7 @@ TEST_F(FlexfecReceiverTest, SurvivesOldRecoveredPacketBeingReinserted) { } loopback_recovered_packet_receiver; // Feed recovered packets back into |receiver|. - FlexfecReceiver receiver(kFlexfecSsrc, kMediaSsrc, + FlexfecReceiver receiver(Clock::GetRealTimeClock(), kFlexfecSsrc, kMediaSsrc, &loopback_recovered_packet_receiver); loopback_recovered_packet_receiver.SetReceiver(&receiver); @@ -590,7 +592,7 @@ TEST_F(FlexfecReceiverTest, RecoveryCallbackDoesNotLoopInfinitely) { } loopback_recovered_packet_receiver; // Feed recovered packets back into |receiver|. - FlexfecReceiver receiver(kFlexfecSsrc, kMediaSsrc, + FlexfecReceiver receiver(Clock::GetRealTimeClock(), kFlexfecSsrc, kMediaSsrc, &loopback_recovered_packet_receiver); loopback_recovered_packet_receiver.SetReceiver(&receiver); diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc index 5032f0e980..65ec75db8e 100644 --- a/video/rtp_video_stream_receiver.cc +++ b/video/rtp_video_stream_receiver.cc @@ -52,12 +52,14 @@ constexpr int kPacketBufferMaxSize = 2048; } // namespace std::unique_ptr CreateRtpRtcpModule( + Clock* clock, ReceiveStatistics* receive_statistics, Transport* outgoing_transport, RtcpRttStats* rtt_stats, RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer, TransportSequenceNumberAllocator* transport_sequence_number_allocator) { RtpRtcp::Configuration configuration; + configuration.clock = clock; configuration.audio = false; configuration.receiver_only = true; configuration.receive_statistics = receive_statistics; @@ -83,6 +85,7 @@ std::unique_ptr CreateRtpRtcpModule( static const int kPacketLogIntervalMs = 10000; RtpVideoStreamReceiver::RtpVideoStreamReceiver( + Clock* clock, Transport* transport, RtcpRttStats* rtt_stats, PacketRouter* packet_router, @@ -94,17 +97,18 @@ RtpVideoStreamReceiver::RtpVideoStreamReceiver( KeyFrameRequestSender* keyframe_request_sender, video_coding::OnCompleteFrameCallback* complete_frame_callback, rtc::scoped_refptr frame_decryptor) - : clock_(Clock::GetRealTimeClock()), + : clock_(clock), config_(*config), packet_router_(packet_router), process_thread_(process_thread), - ntp_estimator_(clock_), + ntp_estimator_(clock), rtp_header_extensions_(config_.rtp.extensions), rtp_receive_statistics_(rtp_receive_statistics), ulpfec_receiver_(UlpfecReceiver::Create(config->rtp.remote_ssrc, this)), receiving_(false), last_packet_log_ms_(-1), - rtp_rtcp_(CreateRtpRtcpModule(rtp_receive_statistics_, + rtp_rtcp_(CreateRtpRtcpModule(clock, + rtp_receive_statistics_, transport, rtt_stats, receive_stats_proxy, diff --git a/video/rtp_video_stream_receiver.h b/video/rtp_video_stream_receiver.h index 9e50dd3b7b..3824680fca 100644 --- a/video/rtp_video_stream_receiver.h +++ b/video/rtp_video_stream_receiver.h @@ -67,6 +67,7 @@ class RtpVideoStreamReceiver : public LossNotificationSender, public OnDecryptionStatusChangeCallback { public: RtpVideoStreamReceiver( + Clock* clock, Transport* transport, RtcpRttStats* rtt_stats, PacketRouter* packet_router, diff --git a/video/rtp_video_stream_receiver_unittest.cc b/video/rtp_video_stream_receiver_unittest.cc index c6fb13d2d0..8521732e0e 100644 --- a/video/rtp_video_stream_receiver_unittest.cc +++ b/video/rtp_video_stream_receiver_unittest.cc @@ -130,8 +130,8 @@ class RtpVideoStreamReceiverTest : public testing::Test { rtp_receive_statistics_ = absl::WrapUnique(ReceiveStatistics::Create(Clock::GetRealTimeClock())); rtp_video_stream_receiver_ = absl::make_unique( - &mock_transport_, nullptr, &packet_router_, &config_, - rtp_receive_statistics_.get(), nullptr, process_thread_.get(), + Clock::GetRealTimeClock(), &mock_transport_, nullptr, &packet_router_, + &config_, rtp_receive_statistics_.get(), nullptr, process_thread_.get(), &mock_nack_sender_, &mock_key_frame_request_sender_, &mock_on_complete_frame_callback_, nullptr); } diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc index 9d84fd3147..904e0a509d 100644 --- a/video/video_receive_stream.cc +++ b/video/video_receive_stream.cc @@ -192,7 +192,8 @@ VideoReceiveStream::VideoReceiveStream( timing_.get(), this, // NackSender this), // KeyFrameRequestSender - rtp_video_stream_receiver_(&transport_adapter_, + rtp_video_stream_receiver_(clock_, + &transport_adapter_, call_stats, packet_router, &config_, @@ -259,7 +260,8 @@ VideoReceiveStream::VideoReceiveStream( PacketRouter* packet_router, VideoReceiveStream::Config config, ProcessThread* process_thread, - CallStats* call_stats) + CallStats* call_stats, + Clock* clock) : VideoReceiveStream(task_queue_factory, receiver_controller, num_cpu_cores, @@ -267,8 +269,8 @@ VideoReceiveStream::VideoReceiveStream( std::move(config), process_thread, call_stats, - Clock::GetRealTimeClock(), - new VCMTiming(Clock::GetRealTimeClock())) {} + clock, + new VCMTiming(clock)) {} VideoReceiveStream::~VideoReceiveStream() { RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_sequence_checker_); diff --git a/video/video_receive_stream.h b/video/video_receive_stream.h index ada5b7bb5d..3730505e11 100644 --- a/video/video_receive_stream.h +++ b/video/video_receive_stream.h @@ -68,7 +68,8 @@ class VideoReceiveStream : public webrtc::VideoReceiveStream, PacketRouter* packet_router, VideoReceiveStream::Config config, ProcessThread* process_thread, - CallStats* call_stats); + CallStats* call_stats, + Clock* clock); ~VideoReceiveStream() override; const Config& config() const { return config_; }