Remove config() getter from VideoReceiveStream2.

Instead offer getters for the sync_group and rtp struct. Both are
a part of the config but expose much less of the config, which has
mutable parts.

Bug: none
Change-Id: Icc8007246e9776a5d20f30cda1a2df3fb7252ffc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/229980
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#34838}
diff --git a/call/call.cc b/call/call.cc
index 00f58d3..39fb3cf 100644
--- a/call/call.cc
+++ b/call/call.cc
@@ -1120,6 +1120,9 @@
 
   EnsureStarted();
 
+  event_log_->Log(std::make_unique<RtcEventVideoReceiveStreamConfig>(
+      CreateRtcLogStreamConfig(configuration)));
+
   // TODO(bugs.webrtc.org/11993): Move the registration between `receive_stream`
   // and `video_receiver_controller_` out of VideoReceiveStream2 construction
   // and set it up asynchronously on the network thread (the registration and
@@ -1133,22 +1136,21 @@
   // thread.
   receive_stream->RegisterWithTransport(&video_receiver_controller_);
 
-  const webrtc::VideoReceiveStream::Config& config = receive_stream->config();
-  if (config.rtp.rtx_ssrc) {
+  const webrtc::VideoReceiveStream::Config::Rtp& rtp = receive_stream->rtp();
+  if (rtp.rtx_ssrc) {
     // We record identical config for the rtx stream as for the main
     // stream. Since the transport_send_cc negotiation is per payload
     // type, we may get an incorrect value for the rtx stream, but
     // that is unlikely to matter in practice.
-    receive_rtp_config_.emplace(config.rtp.rtx_ssrc, receive_stream);
+    receive_rtp_config_.emplace(rtp.rtx_ssrc, receive_stream);
   }
-  receive_rtp_config_.emplace(config.rtp.remote_ssrc, receive_stream);
+  receive_rtp_config_.emplace(rtp.remote_ssrc, receive_stream);
   video_receive_streams_.insert(receive_stream);
-  ConfigureSync(config.sync_group);
+
+  ConfigureSync(receive_stream->sync_group());
 
   receive_stream->SignalNetworkState(video_network_state_);
   UpdateAggregateNetworkState();
-  event_log_->Log(std::make_unique<RtcEventVideoReceiveStreamConfig>(
-      CreateRtcLogStreamConfig(config)));
   return receive_stream;
 }
 
@@ -1162,19 +1164,20 @@
   // TODO(bugs.webrtc.org/11993): Unregister on the network thread.
   receive_stream_impl->UnregisterFromTransport();
 
-  const VideoReceiveStream::Config& config = receive_stream_impl->config();
+  const webrtc::VideoReceiveStream::Config::Rtp& rtp =
+      receive_stream_impl->rtp();
 
   // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a
   // separate SSRC there can be either one or two.
-  receive_rtp_config_.erase(config.rtp.remote_ssrc);
-  if (config.rtp.rtx_ssrc) {
-    receive_rtp_config_.erase(config.rtp.rtx_ssrc);
+  receive_rtp_config_.erase(rtp.remote_ssrc);
+  if (rtp.rtx_ssrc) {
+    receive_rtp_config_.erase(rtp.rtx_ssrc);
   }
   video_receive_streams_.erase(receive_stream_impl);
-  ConfigureSync(config.sync_group);
+  ConfigureSync(receive_stream_impl->sync_group());
 
-  receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config.rtp))
-      ->RemoveStream(config.rtp.remote_ssrc);
+  receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(rtp))
+      ->RemoveStream(rtp.remote_ssrc);
 
   UpdateAggregateNetworkState();
   delete receive_stream_impl;
@@ -1458,7 +1461,7 @@
     sync_stream_mapping_[sync_group] = sync_audio_stream;
   size_t num_synced_streams = 0;
   for (VideoReceiveStream2* video_stream : video_receive_streams_) {
-    if (video_stream->config().sync_group != sync_group)
+    if (video_stream->sync_group() != sync_group)
       continue;
     ++num_synced_streams;
     if (num_synced_streams > 1) {
diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc
index c605eca..3127069 100644
--- a/video/video_receive_stream2.cc
+++ b/video/video_receive_stream2.cc
@@ -303,6 +303,16 @@
   rtx_receiver_.reset();
 }
 
+const VideoReceiveStream2::Config::Rtp& VideoReceiveStream2::rtp() const {
+  RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
+  return config_.rtp;
+}
+
+const std::string& VideoReceiveStream2::sync_group() const {
+  RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
+  return config_.sync_group;
+}
+
 void VideoReceiveStream2::SignalNetworkState(NetworkState state) {
   RTC_DCHECK_RUN_ON(&worker_sequence_checker_);
   rtp_video_stream_receiver_.SignalNetworkState(state);
diff --git a/video/video_receive_stream2.h b/video/video_receive_stream2.h
index 8a1418a..ace5de2 100644
--- a/video/video_receive_stream2.h
+++ b/video/video_receive_stream2.h
@@ -12,6 +12,7 @@
 #define VIDEO_VIDEO_RECEIVE_STREAM2_H_
 
 #include <memory>
+#include <string>
 #include <vector>
 
 #include "api/sequence_checker.h"
@@ -116,7 +117,13 @@
   // network thread.
   void UnregisterFromTransport();
 
-  const Config& config() const { return config_; }
+  // Convenience getters for parts of the receive stream's config.
+  // The accessors must be called on the packet delivery thread in accordance
+  // to documentation for RtpConfig (see receive_stream.h), the returned
+  // values should not be cached and should just be used within the calling
+  // context as some values might change.
+  const Config::Rtp& rtp() const;
+  const std::string& sync_group() const;
 
   void SignalNetworkState(NetworkState state);
   bool DeliverRtcp(const uint8_t* packet, size_t length);