Allow setting volume on unstarted AudioRtpReceivers

This was the behaviour before https://webrtc-review.googlesource.com/c/src/+/218605,
and is currently relied upon by Chrome to mute received audio tracks
by default, until they should be played out.

Bug: chromium:1272566
Change-Id: I8a288a287e7c01392f4af1db5b083e8d7ee7b2a8
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238665
Commit-Queue: Tony Herre <toprice@chromium.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35401}
diff --git a/pc/audio_rtp_receiver.cc b/pc/audio_rtp_receiver.cc
index 4efab24..cfaee40 100644
--- a/pc/audio_rtp_receiver.cc
+++ b/pc/audio_rtp_receiver.cc
@@ -93,11 +93,14 @@
   RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
   RTC_DCHECK_GE(volume, 0);
   RTC_DCHECK_LE(volume, 10);
+
+  // Update the cached_volume_ even when stopped_, to allow clients to set the
+  // volume before starting/restarting, eg see crbug.com/1272566.
+  cached_volume_ = volume;
+
   if (stopped_)
     return;
 
-  cached_volume_ = volume;
-
   // When the track is disabled, the volume of the source, which is the
   // corresponding WebRtc Voice Engine channel will be 0. So we do not allow
   // setting the volume to the source when the track is disabled.