Modernize RtpRtcp factory function: use unique_ptr as return type

to clearly signal passed ownership.
Drop support for accepting nullptr clock to avoid copying the Configuration structure.
Update all calls in webrtc to the new factory function

Bug: None
Change-Id: Ic5a78da8e59ba3988a757a9d9634fa31499ce0db
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/125901
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Oskar Sundbom <ossu@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26994}
diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc
index 679666e..b3d771a 100644
--- a/audio/channel_receive.cc
+++ b/audio/channel_receive.cc
@@ -489,7 +489,7 @@
 
   configuration.event_log = event_log_;
 
-  _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
+  _rtpRtcpModule = RtpRtcp::Create(configuration);
   _rtpRtcpModule->SetSendingMediaStatus(false);
   _rtpRtcpModule->SetRemoteSSRC(remote_ssrc_);
 
diff --git a/audio/channel_send.cc b/audio/channel_send.cc
index 8269fd5..705827d 100644
--- a/audio/channel_send.cc
+++ b/audio/channel_send.cc
@@ -700,7 +700,7 @@
   configuration.extmap_allow_mixed = extmap_allow_mixed;
   configuration.rtcp_report_interval_ms = rtcp_report_interval_ms;
 
-  _rtpRtcpModule.reset(RtpRtcp::CreateRtpRtcp(configuration));
+  _rtpRtcpModule = RtpRtcp::Create(configuration);
   _rtpRtcpModule->SetSendingMediaStatus(false);
 
   // We want to invoke the 'TargetRateObserver' and |OnOverheadChanged|
diff --git a/call/flexfec_receive_stream_impl.cc b/call/flexfec_receive_stream_impl.cc
index 645df78..fedb64d 100644
--- a/call/flexfec_receive_stream_impl.cc
+++ b/call/flexfec_receive_stream_impl.cc
@@ -130,8 +130,7 @@
   configuration.receive_statistics = receive_statistics;
   configuration.outgoing_transport = rtcp_send_transport;
   configuration.rtt_stats = rtt_stats;
-  std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration));
-  return rtp_rtcp;
+  return RtpRtcp::Create(configuration);
 }
 
 }  // namespace
diff --git a/call/rtp_video_sender.cc b/call/rtp_video_sender.cc
index e5098db..9dc3003 100644
--- a/call/rtp_video_sender.cc
+++ b/call/rtp_video_sender.cc
@@ -119,7 +119,7 @@
     auto playout_delay_oracle = absl::make_unique<PlayoutDelayOracle>();
 
     configuration.ack_observer = playout_delay_oracle.get();
-    auto rtp_rtcp = absl::WrapUnique(RtpRtcp::CreateRtpRtcp(configuration));
+    auto rtp_rtcp = RtpRtcp::Create(configuration);
     rtp_rtcp->SetSendingStatus(false);
     rtp_rtcp->SetSendingMediaStatus(false);
     rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound);
diff --git a/modules/rtp_rtcp/include/rtp_rtcp.h b/modules/rtp_rtcp/include/rtp_rtcp.h
index 6e1b4a5..8e1f98b 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp.h
+++ b/modules/rtp_rtcp/include/rtp_rtcp.h
@@ -11,6 +11,7 @@
 #ifndef MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_H_
 #define MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_H_
 
+#include <memory>
 #include <set>
 #include <string>
 #include <utility>
@@ -119,8 +120,10 @@
     RTC_DISALLOW_COPY_AND_ASSIGN(Configuration);
   };
 
-  // Create a RTP/RTCP module object using the system clock.
-  // |configuration|  - Configuration of the RTP/RTCP module.
+  // Creates an RTP/RTCP module object using provided |configuration|.
+  static std::unique_ptr<RtpRtcp> Create(const Configuration& configuration);
+  // Prefer factory function just above.
+  RTC_DEPRECATED
   static RtpRtcp* CreateRtpRtcp(const RtpRtcp::Configuration& configuration);
 
   // **************************************************************************
diff --git a/modules/rtp_rtcp/source/nack_rtx_unittest.cc b/modules/rtp_rtcp/source/nack_rtx_unittest.cc
index 864befe..b47ef85 100644
--- a/modules/rtp_rtcp/source/nack_rtx_unittest.cc
+++ b/modules/rtp_rtcp/source/nack_rtx_unittest.cc
@@ -136,7 +136,7 @@
     configuration.receive_statistics = receive_statistics_.get();
     configuration.outgoing_transport = &transport_;
     configuration.retransmission_rate_limiter = &retransmission_rate_limiter_;
-    rtp_rtcp_module_ = absl::WrapUnique(RtpRtcp::CreateRtpRtcp(configuration));
+    rtp_rtcp_module_ = RtpRtcp::Create(configuration);
     rtp_sender_video_ = absl::make_unique<RTPSenderVideo>(
         &fake_clock, rtp_rtcp_module_->RtpSender(), nullptr,
         &playout_delay_oracle_, nullptr, false, FieldTrialBasedConfig());
diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
index 2adddff..4e06002 100644
--- a/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
+++ b/modules/rtp_rtcp/source/rtp_rtcp_impl.cc
@@ -41,6 +41,11 @@
 
 RtpRtcp::Configuration::Configuration() = default;
 
+std::unique_ptr<RtpRtcp> RtpRtcp::Create(const Configuration& configuration) {
+  RTC_DCHECK(configuration.clock);
+  return absl::make_unique<ModuleRtpRtcpImpl>(configuration);
+}
+
 RtpRtcp* RtpRtcp::CreateRtpRtcp(const RtpRtcp::Configuration& configuration) {
   if (configuration.clock) {
     return new ModuleRtpRtcpImpl(configuration);
diff --git a/video/end_to_end_tests/bandwidth_tests.cc b/video/end_to_end_tests/bandwidth_tests.cc
index e7550a4..3ee0e2b 100644
--- a/video/end_to_end_tests/bandwidth_tests.cc
+++ b/video/end_to_end_tests/bandwidth_tests.cc
@@ -193,7 +193,7 @@
       config.clock = clock_;
       config.outgoing_transport = receive_transport_;
       config.retransmission_rate_limiter = &retransmission_rate_limiter_;
-      rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config));
+      rtp_rtcp_ = RtpRtcp::Create(config);
       rtp_rtcp_->SetRemoteSSRC((*receive_configs)[0].rtp.remote_ssrc);
       rtp_rtcp_->SetSSRC((*receive_configs)[0].rtp.local_ssrc);
       rtp_rtcp_->SetRTCPStatus(RtcpMode::kReducedSize);
diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc
index 65ec75d..de8e2dc 100644
--- a/video/rtp_video_stream_receiver.cc
+++ b/video/rtp_video_stream_receiver.cc
@@ -76,7 +76,7 @@
   configuration.bandwidth_callback = nullptr;
   configuration.transport_feedback_callback = nullptr;
 
-  std::unique_ptr<RtpRtcp> rtp_rtcp(RtpRtcp::CreateRtpRtcp(configuration));
+  std::unique_ptr<RtpRtcp> rtp_rtcp = RtpRtcp::Create(configuration);
   rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound);
 
   return rtp_rtcp;
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc
index 4aa68f7..a5f5c1a 100644
--- a/video/video_send_stream_tests.cc
+++ b/video/video_send_stream_tests.cc
@@ -1619,9 +1619,10 @@
         const std::vector<VideoReceiveStream*>& receive_streams) override {
       stream_ = send_stream;
       RtpRtcp::Configuration config;
+      config.clock = Clock::GetRealTimeClock();
       config.outgoing_transport = feedback_transport_.get();
       config.retransmission_rate_limiter = &retranmission_rate_limiter_;
-      rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config));
+      rtp_rtcp_ = RtpRtcp::Create(config);
       rtp_rtcp_->SetRTCPStatus(RtcpMode::kReducedSize);
     }