Audio coding: Don't choke when RTP timestamp rate > sample rate

Bug: webrtc:10631
Change-Id: If0422786172502f039acc2cac5e8c13b637af54c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/137048
Reviewed-by: Minyue Li <minyue@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27998}
diff --git a/modules/audio_coding/acm2/audio_coding_module.cc b/modules/audio_coding/acm2/audio_coding_module.cc
index 0dc4fcf..741cef9 100644
--- a/modules/audio_coding/acm2/audio_coding_module.cc
+++ b/modules/audio_coding/acm2/audio_coding_module.cc
@@ -328,13 +328,13 @@
 
   // Scale the timestamp to the codec's RTP timestamp rate.
   uint32_t rtp_timestamp =
-      first_frame_ ? input_data.input_timestamp
-                   : last_rtp_timestamp_ +
-                         rtc::CheckedDivExact(
-                             input_data.input_timestamp - last_timestamp_,
-                             static_cast<uint32_t>(rtc::CheckedDivExact(
-                                 encoder_stack_->SampleRateHz(),
-                                 encoder_stack_->RtpTimestampRateHz())));
+      first_frame_
+          ? input_data.input_timestamp
+          : last_rtp_timestamp_ +
+                rtc::dchecked_cast<uint32_t>(rtc::CheckedDivExact(
+                    int64_t{input_data.input_timestamp - last_timestamp_} *
+                        encoder_stack_->RtpTimestampRateHz(),
+                    int64_t{encoder_stack_->SampleRateHz()}));
   last_timestamp_ = input_data.input_timestamp;
   last_rtp_timestamp_ = rtp_timestamp;
   first_frame_ = false;