From 4a389854a4dd4f27acce2d7b7116aebb48d2cf35 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Wed, 8 Aug 2012 20:47:29 +0000
Subject: [PATCH] Create the payload type if it does not exist when setting
 information based on the 'm' line. An rtpmap attribute is not required for
 defined payload numbers.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370927 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/rtp_engine.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index c62494508b..4861387e3f 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -534,11 +534,21 @@ void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct as
 	struct ast_rtp_payload_type *type;
 
 	ast_rwlock_rdlock(&static_RTP_PT_lock);
-	if (payload < 0 || payload >= AST_RTP_MAX_PT || !(type = ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK))) {
+
+	if (payload < 0 || payload >= AST_RTP_MAX_PT) {
 		ast_rwlock_unlock(&static_RTP_PT_lock);
 		return;
 	}
 
+	if (!(type = ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK))) {
+		if (!(type = ao2_alloc(sizeof(*type), NULL))) {
+			ast_rwlock_unlock(&static_RTP_PT_lock);
+			return;
+		}
+		type->payload = payload;
+		ao2_link_flags(codecs->payloads, type, OBJ_NOLOCK);
+	}
+
 	type->asterisk_format = static_RTP_PT[payload].asterisk_format;
 	type->rtp_code = static_RTP_PT[payload].rtp_code;
 	type->payload = payload;
-- 
GitLab