Mitigate scenario when VP9 HW encoder uses less spatial layers than configured

log an error and reset chain instead of propagating oversized chain diff, thus avoid DCHECK in RtpDependencyDescriptorWriter.

Bug: webrtc:11999, chromium:1467865
Change-Id: If0d186ce7d3a108799ef2b42dd4a3791db33f1a7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/314501
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40503}
diff --git a/call/rtp_payload_params.cc b/call/rtp_payload_params.cc
index f0347bc..ed7620e 100644
--- a/call/rtp_payload_params.cc
+++ b/call/rtp_payload_params.cc
@@ -657,7 +657,15 @@
       result.chain_diffs[sid] = 0;
       continue;
     }
-    result.chain_diffs[sid] = shared_frame_id - chain_last_frame_id_[sid];
+    int64_t chain_diff = shared_frame_id - chain_last_frame_id_[sid];
+    if (chain_diff >= 256) {
+      RTC_LOG(LS_ERROR)
+          << "Too many frames since last VP9 T0 frame for spatial layer #"
+          << sid << " at frame#" << shared_frame_id;
+      chain_last_frame_id_[sid] = -1;
+      chain_diff = 0;
+    }
+    result.chain_diffs[sid] = chain_diff;
   }
 
   if (temporal_index == 0) {