Create the payload type if it does not exist when setting information based on the...
authorJoshua Colp <jcolp@digium.com>
Wed, 8 Aug 2012 20:47:29 +0000 (20:47 +0000)
committerJoshua Colp <jcolp@digium.com>
Wed, 8 Aug 2012 20:47:29 +0000 (20:47 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370927 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/rtp_engine.c

index c624945..4861387 100644 (file)
@@ -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;