Ensure VideoLayersAllocation.frame_rate_fps can not overflow

Bug: webrtc:12000
Change-Id: I14d5f0f987fb20bd74e0428b3791bf370476296e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/204220
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33089}
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 4215fd9..c8d6021 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -260,8 +260,9 @@
       // Encoder may drop frames internally if `maxFramerate` is set.
       spatial_layer.frame_rate_fps = std::min<uint8_t>(
           encoder_config.simulcastStream[si].maxFramerate,
-          (current_rate.framerate_fps * frame_rate_fraction) /
-              VideoEncoder::EncoderInfo::kMaxFramerateFraction);
+          rtc::saturated_cast<uint8_t>(
+              (current_rate.framerate_fps * frame_rate_fraction) /
+              VideoEncoder::EncoderInfo::kMaxFramerateFraction));
     }
   } else if (encoder_config.numberOfSimulcastStreams == 1) {
     // TODO(bugs.webrtc.org/12000): Implement support for AV1 with
@@ -329,8 +330,9 @@
       // Encoder may drop frames internally if `maxFramerate` is set.
       spatial_layer.frame_rate_fps = std::min<uint8_t>(
           encoder_config.spatialLayers[si].maxFramerate,
-          (current_rate.framerate_fps * frame_rate_fraction) /
-              VideoEncoder::EncoderInfo::kMaxFramerateFraction);
+          rtc::saturated_cast<uint8_t>(
+              (current_rate.framerate_fps * frame_rate_fraction) /
+              VideoEncoder::EncoderInfo::kMaxFramerateFraction));
     }
   }