Make AV sync robust to failures to set a desired minimum delay

Setting a minimum delay can fail in some cases. It is important that the
AV sync code is aware of failures and can act accordingly to recover and
prevent sync delays that keep increasing indefinitely.

Bug: webrtc:11805
Change-Id: I0deed951dc6c6d0905536a949af875e0a6d9f7fa
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/183360
Commit-Queue: Ivo Creusen <ivoc@webrtc.org>
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32062}
diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc
index 8831164..0bd6ce6 100644
--- a/audio/audio_receive_stream.cc
+++ b/audio/audio_receive_stream.cc
@@ -329,7 +329,7 @@
                                                       time_ms);
 }
 
-void AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
+bool AudioReceiveStream::SetMinimumPlayoutDelay(int delay_ms) {
   RTC_DCHECK_RUN_ON(&module_process_thread_checker_);
   return channel_receive_->SetMinimumPlayoutDelay(delay_ms);
 }
diff --git a/audio/audio_receive_stream.h b/audio/audio_receive_stream.h
index 0b91efe..b58f600 100644
--- a/audio/audio_receive_stream.h
+++ b/audio/audio_receive_stream.h
@@ -87,7 +87,7 @@
                               int64_t* time_ms) const override;
   void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
                                          int64_t time_ms) override;
-  void SetMinimumPlayoutDelay(int delay_ms) override;
+  bool SetMinimumPlayoutDelay(int delay_ms) override;
 
   void AssociateSendStream(AudioSendStream* send_stream);
   void DeliverRtcp(const uint8_t* packet, size_t length);
diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc
index 9cbaabb..14184be 100644
--- a/audio/channel_receive.cc
+++ b/audio/channel_receive.cc
@@ -133,7 +133,7 @@
 
   // Audio+Video Sync.
   uint32_t GetDelayEstimate() const override;
-  void SetMinimumPlayoutDelay(int delayMs) override;
+  bool SetMinimumPlayoutDelay(int delayMs) override;
   bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
                               int64_t* time_ms) const override;
   void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
@@ -822,7 +822,7 @@
   return acm_receiver_.FilteredCurrentDelayMs() + playout_delay_ms_;
 }
 
-void ChannelReceive::SetMinimumPlayoutDelay(int delay_ms) {
+bool ChannelReceive::SetMinimumPlayoutDelay(int delay_ms) {
   RTC_DCHECK(module_process_thread_checker_.IsCurrent());
   // Limit to range accepted by both VoE and ACM, so we're at least getting as
   // close as possible, instead of failing.
@@ -831,7 +831,9 @@
   if (acm_receiver_.SetMinimumDelay(delay_ms) != 0) {
     RTC_DLOG(LS_ERROR)
         << "SetMinimumPlayoutDelay() failed to set min playout delay";
+    return false;
   }
+  return true;
 }
 
 bool ChannelReceive::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
diff --git a/audio/channel_receive.h b/audio/channel_receive.h
index bc02ff3..8a65861 100644
--- a/audio/channel_receive.h
+++ b/audio/channel_receive.h
@@ -104,7 +104,7 @@
 
   // Audio+Video Sync.
   virtual uint32_t GetDelayEstimate() const = 0;
-  virtual void SetMinimumPlayoutDelay(int delay_ms) = 0;
+  virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0;
   virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
                                       int64_t* time_ms) const = 0;
   virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
diff --git a/audio/mock_voe_channel_proxy.h b/audio/mock_voe_channel_proxy.h
index 542358f..97d1069 100644
--- a/audio/mock_voe_channel_proxy.h
+++ b/audio/mock_voe_channel_proxy.h
@@ -76,7 +76,7 @@
               GetSyncInfo,
               (),
               (const, override));
-  MOCK_METHOD(void, SetMinimumPlayoutDelay, (int delay_ms), (override));
+  MOCK_METHOD(bool, SetMinimumPlayoutDelay, (int delay_ms), (override));
   MOCK_METHOD(bool, SetBaseMinimumPlayoutDelayMs, (int delay_ms), (override));
   MOCK_METHOD(int, GetBaseMinimumPlayoutDelayMs, (), (const, override));
   MOCK_METHOD((absl::optional<std::pair<int, SdpAudioFormat>>),