fix rtx payload type remapping issue

If we reference a remote codec that was offered without rtx we need
to change the reference of our local rtx codec in a reoffer.
This only happens with stopped transceivers.

BUG=chromium:1201441

Change-Id: I60dc4908ba7ba2c0249a2a05b03a7b35af504e18
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238382
Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35487}
diff --git a/pc/media_session.cc b/pc/media_session.cc
index 054d570..45cedfb 100644
--- a/pc/media_session.cc
+++ b/pc/media_session.cc
@@ -2381,6 +2381,22 @@
                                          filtered_codecs, codec, nullptr)) {
         // Use the `found_codec` from `video_codecs` because it has the
         // correctly mapped payload type.
+        if (IsRtxCodec(codec)) {
+          // For RTX we might need to adjust the apt parameter if we got a
+          // remote offer without RTX for a codec for which we support RTX.
+          auto referenced_codec =
+              GetAssociatedCodecForRtx(supported_video_codecs, codec);
+          RTC_DCHECK(referenced_codec);
+
+          // Find the codec we should be referencing and point to it.
+          VideoCodec changed_referenced_codec;
+          if (FindMatchingCodec<VideoCodec>(supported_video_codecs,
+                                            filtered_codecs, *referenced_codec,
+                                            &changed_referenced_codec)) {
+            found_codec.SetParam(kCodecParamAssociatedPayloadType,
+                                 changed_referenced_codec.id);
+          }
+        }
         filtered_codecs.push_back(found_codec);
       }
     }