[asterisk-commits] file: branch group/media_formats r411576 - in /team/group/media_formats: chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 31 09:08:44 CDT 2014


Author: file
Date: Mon Mar 31 09:08:32 2014
New Revision: 411576

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=411576
Log:
Begin to vectorize RTP reality.

Modified:
    team/group/media_formats/channels/chan_sip.c
    team/group/media_formats/include/asterisk/rtp_engine.h
    team/group/media_formats/main/rtp_engine.c

Modified: team/group/media_formats/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/channels/chan_sip.c?view=diff&rev=411576&r1=411575&r2=411576
==============================================================================
--- team/group/media_formats/channels/chan_sip.c (original)
+++ team/group/media_formats/channels/chan_sip.c Mon Mar 31 09:08:32 2014
@@ -10089,7 +10089,7 @@
 
 	int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0;
 
-	struct ast_rtp_codecs newaudiortp = { 0, }, newvideortp = { 0, }, newtextrtp = { 0, };
+	struct ast_rtp_codecs newaudiortp, newvideortp, newtextrtp;
 	struct ast_format_cap *newjointcapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT); /* Negotiated capability */
 	struct ast_format_cap *newpeercapability = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
 	int newnoncodeccapability;

Modified: team/group/media_formats/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/include/asterisk/rtp_engine.h?view=diff&rev=411576&r1=411575&r2=411576
==============================================================================
--- team/group/media_formats/include/asterisk/rtp_engine.h (original)
+++ team/group/media_formats/include/asterisk/rtp_engine.h Mon Mar 31 09:08:32 2014
@@ -75,13 +75,7 @@
 #include "asterisk/sched.h"
 #include "asterisk/res_srtp.h"
 #include "asterisk/stasis.h"
-
-/* Maximum number of payloads supported */
-#if defined(LOW_MEMORY)
-#define AST_RTP_MAX_PT 128
-#else
-#define AST_RTP_MAX_PT 196
-#endif
+#include "asterisk/vector.h"
 
 /* Maximum number of generations */
 #define AST_RED_MAX_GENERATION 5
@@ -550,8 +544,12 @@
 
 /*! Structure that represents codec and packetization information */
 struct ast_rtp_codecs {
-	/*! Payloads present */
-	struct ao2_container *payloads;
+	/*! Vector of mappings from payload to format */
+	AST_VECTOR(, struct ast_format *) payload2format;
+	/*! Vector of mappings from format to payload */
+	AST_VECTOR(, unsigned int) format2payload;
+	/*! Vector of mappings from payload to non-Asterisk format */
+	AST_VECTOR(, unsigned int) payload2internalformat;
 };
 
 /*! Structure that represents the glue that binds an RTP instance to a channel */

Modified: team/group/media_formats/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/main/rtp_engine.c?view=diff&rev=411576&r1=411575&r2=411576
==============================================================================
--- team/group/media_formats/main/rtp_engine.c (original)
+++ team/group/media_formats/main/rtp_engine.c Mon Mar 31 09:08:32 2014
@@ -526,119 +526,96 @@
 	return &instance->codecs;
 }
 
-static int rtp_payload_type_hash(const void *obj, const int flags)
-{
-	const struct ast_rtp_payload_type *type = obj;
-	const int *payload = obj;
-
-	return (flags & OBJ_KEY) ? *payload : type->payload;
-}
-
-static int rtp_payload_type_cmp(void *obj, void *arg, int flags)
-{
-	struct ast_rtp_payload_type *type1 = obj, *type2 = arg;
-	const int *payload = arg;
-
-	return (type1->payload == (OBJ_KEY ? *payload : type2->payload)) ? CMP_MATCH | CMP_STOP : 0;
-}
-
 int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
 {
-	if (!(codecs->payloads = ao2_container_alloc(AST_RTP_MAX_PT, rtp_payload_type_hash, rtp_payload_type_cmp))) {
-		return -1;
-	}
+	AST_VECTOR_INIT(&codecs->payload2format, 0);
+	AST_VECTOR_INIT(&codecs->format2payload, 0);
+	AST_VECTOR_INIT(&codecs->payload2internalformat, 0);
 
 	return 0;
 }
 
 void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
 {
-	ao2_cleanup(codecs->payloads);
+	int idx;
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload2format); idx++) {
+		struct ast_format *format = AST_VECTOR_GET(&codecs->payload2format, idx);
+
+		ao2_cleanup(format);
+	}
+
+	AST_VECTOR_FREE(&codecs->payload2format);
+	AST_VECTOR_FREE(&codecs->format2payload);
+	AST_VECTOR_FREE(&codecs->payload2internalformat);
 }
 
 void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 {
+	if (instance && instance->engine && instance->engine->payload_set) {
+		int idx;
+
+		for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload2format); idx++) {
+			if (AST_VECTOR_GET(&codecs->payload2format, idx)) {
+				instance->engine->payload_set(instance, idx, 0, NULL, 0);
+			}
+		}
+
+		for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload2internalformat); idx++) {
+			if (AST_VECTOR_GET(&codecs->payload2internalformat)) {
+				instance->engine->payload_set(instance, idx, 0, NULL, 0);
+			}
+		}
+	}
+
 	ast_rtp_codecs_payloads_destroy(codecs);
-
-	if (instance && instance->engine && instance->engine->payload_set) {
-		int i;
-		for (i = 0; i < AST_RTP_MAX_PT; i++) {
-			instance->engine->payload_set(instance, i, 0, NULL, 0);
-		}
-	}
-
 	ast_rtp_codecs_payloads_initialize(codecs);
 }
 
 void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 {
-	int i;
-
-	ast_rwlock_rdlock(&static_RTP_PT_lock);
-	for (i = 0; i < AST_RTP_MAX_PT; i++) {
-		if (static_RTP_PT[i].rtp_code || static_RTP_PT[i].asterisk_format) {
-			struct ast_rtp_payload_type *type;
-
-			if (!(type = ao2_alloc(sizeof(*type), NULL))) {
-				/* Unfortunately if this occurs the payloads container will not contain all possible default payloads
-				 * but we err on the side of doing what we can in the hopes that the extreme memory conditions which
-				 * caused this to occur will go away.
-				 */
-				continue;
-			}
-
-			type->payload = i;
-			type->asterisk_format = static_RTP_PT[i].asterisk_format;
-			type->rtp_code = static_RTP_PT[i].rtp_code;
-			ast_format_copy(&type->format, &static_RTP_PT[i].format);
-
-			ao2_link_flags(codecs->payloads, type, OBJ_NOLOCK);
-
-			if (instance && instance->engine && instance->engine->payload_set) {
-				instance->engine->payload_set(instance, i, type->asterisk_format, &type->format, type->rtp_code);
-			}
-
-			ao2_ref(type, -1);
-		}
-	}
-	ast_rwlock_unlock(&static_RTP_PT_lock);
+	/* Can this go away? */
 }
 
 void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 {
-	int i;
-	struct ast_rtp_payload_type *type;
-
-	for (i = 0; i < AST_RTP_MAX_PT; i++) {
-		struct ast_rtp_payload_type *new_type;
-
-		if (!(type = ao2_find(src->payloads, &i, OBJ_KEY | OBJ_NOLOCK))) {
+	int idx;
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload2format); idx++) {
+		struct ast_format *format = AST_VECTOR_GET(&src->payload2format, idx);
+
+		if (!format) {
 			continue;
 		}
 
-		if (!(new_type = ao2_alloc(sizeof(*new_type), NULL))) {
+		ast_debug(2, "Copying payload %d from %p to %p\n", idx, src, dest);
+		AST_VECTOR_INSERT(&dest->payload2format, idx, ao2_bump(format));
+
+		if (instance && instance->engine && instance->engine->payload_set) {
+			instance->engine->payload_set(instance, idx, 0, format, idx);
+		}
+	}
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload2internalformat); idx++) {
+		if (!AST_VECTOR_GET(&src->payload2internalformat, idx)) {
 			continue;
 		}
 
-		ast_debug(2, "Copying payload %d from %p to %p\n", i, src, dest);
-
-		new_type->payload = i;
-		*new_type = *type;
-
-		ao2_link_flags(dest->payloads, new_type, OBJ_NOLOCK);
-
-		ao2_ref(new_type, -1);
+		ast_debug(2, "Copying payload %d from %p to %p\n", idx, src, dest);
+		AST_VECTOR_INSERT(&dest->payload2internalformat, idx, AST_VECTOR_GET(&src->payload2internalformat, idx));
 
 		if (instance && instance->engine && instance->engine->payload_set) {
-			instance->engine->payload_set(instance, i, type->asterisk_format, &type->format, type->rtp_code);
-		}
-
-		ao2_ref(type, -1);
+			instance->engine->payload_set(instance, idx, AST_VECTOR_GET(&src->payload2internalformat, idx), NULL, idx);
+		}
 	}
 }
 
 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 {
+	if (payload < 0) {
+		return;
+	}
+
 	struct ast_rtp_payload_type *type;
 
 	ast_rwlock_rdlock(&static_RTP_PT_lock);
@@ -742,13 +719,19 @@
 
 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 {
-	if (payload < 0 || payload >= AST_RTP_MAX_PT) {
+	struct ast_format *format;
+
+	if (payload < 0 || payload >= AST_VECTOR_SIZE(&codecs->payload2format)) {
 		return;
 	}
 
 	ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
 
-	ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK | OBJ_NODATA | OBJ_UNLINK);
+	format = AST_VECTOR_GET(&codecs->payload2format, payload);
+	if (format) {
+		ao2_cleanup(format);
+		AST_VECTOR_INSERT(&codecs->payload2format, payload, NULL);
+	}
 
 	if (instance && instance->engine && instance->engine->payload_set) {
 		instance->engine->payload_set(instance, payload, 0, NULL, 0);
@@ -780,22 +763,11 @@
 
 struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload)
 {
-	struct ast_rtp_payload_type *type;
-	struct ast_format *format;
-
-	if (payload < 0 || payload >= AST_RTP_MAX_PT) {
+	if ((payload < 0) || (payload >= AST_VECTOR_SIZE(&codecs->payload2format))) {
 		return NULL;
 	}
 
-	if (!(type = ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK))) {
-		return NULL;
-	}
-
-	format = type->asterisk_format ? &type->format : NULL;
-
-	ao2_ref(type, -1);
-
-	return format;
+	return AST_VECTOR_GET(&codecs->payload2format, payload);
 }
 
 static int rtp_payload_type_add_ast(void *obj, void *arg, int flags)




More information about the asterisk-commits mailing list