From 2a16a0a30ca6cd36a57e6a2cf32de946f822b7c4 Mon Sep 17 00:00:00 2001
From: Mark Spencer <markster@digium.com>
Date: Mon, 22 Mar 2004 21:52:22 +0000
Subject: [PATCH] Use caller's negotiated values when possible.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2526 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 rtp.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/rtp.c b/rtp.c
index 5ebaf582e9..9e6395bb6c 100755
--- a/rtp.c
+++ b/rtp.c
@@ -663,14 +663,19 @@ void ast_rtp_get_current_formats(struct ast_rtp* rtp,
   }
 }
 
-struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) {
+struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) 
+{
+  struct rtpPayloadType result;
   if (pt < 0 || pt > MAX_RTP_PT) {
-    struct rtpPayloadType result;
     result.isAstFormat = result.code = 0;
     return result; // bogus payload type
   }
-  /* Gotta use our static one, since that's what we sent against */
-  return static_RTP_PT[pt];
+  /* Start with the negotiated codecs */
+  result = rtp->current_RTP_PT[pt];
+  /* If it doesn't exist, check our static RTP type list, just in case */
+  if (!result.code) 
+  	result = static_RTP_PT[pt];
+  return result;
 }
 
 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) {
@@ -684,6 +689,18 @@ int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) {
     return rtp->rtp_lookup_code_cache_result;
   }
 
+	/* Check the dynamic list first */
+  for (pt = 0; pt < MAX_RTP_PT; ++pt) {
+    if (rtp->current_RTP_PT[pt].code == code &&
+		rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) {
+      rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
+      rtp->rtp_lookup_code_cache_code = code;
+      rtp->rtp_lookup_code_cache_result = pt;
+      return pt;
+    }
+  }
+
+	/* Then the static list */
   for (pt = 0; pt < MAX_RTP_PT; ++pt) {
     if (static_RTP_PT[pt].code == code &&
 		static_RTP_PT[pt].isAstFormat == isAstFormat) {
-- 
GitLab