[asterisk-commits] file: branch file/rtp_engine r129107 - in /team/file/rtp_engine: include/aste...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 8 13:20:27 CDT 2008


Author: file
Date: Tue Jul  8 13:20:26 2008
New Revision: 129107

URL: http://svn.digium.com/view/asterisk?view=rev&rev=129107
Log:
Decouple payload and packetization stuff from the RTP instance so a full instance does not need to exist to do it.

Modified:
    team/file/rtp_engine/include/asterisk/rtp_engine.h
    team/file/rtp_engine/main/rtp_engine.c
    team/file/rtp_engine/res/res_rtp_asterisk.c

Modified: team/file/rtp_engine/include/asterisk/rtp_engine.h
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/include/asterisk/rtp_engine.h?view=diff&rev=129107&r1=129106&r2=129107
==============================================================================
--- team/file/rtp_engine/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine/include/asterisk/rtp_engine.h Tue Jul  8 13:20:26 2008
@@ -89,15 +89,22 @@
 	AST_RWLIST_ENTRY(ast_rtp_engine) entry;                                                         /*!< Linked list information */
 };
 
+struct ast_rtp_codecs {
+	struct ast_codec_pref pref;                           /*!< Codec packetization preferences */
+	struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]; /*!< Payloads present */
+};
+
 struct ast_rtp_instance {
 	struct ast_rtp_engine *engine;                        /*!< Engine handling this RTP session instance */
 	struct ast_rtp_glue *glue;                            /*!< Glue that interfaces with the channel driver */
 	void *data;                                           /*!< Unique data for the RTP engine */
 	int properties[AST_RTP_PROPERTY_MAX];                 /*!< Properties and their values */
-	struct ast_codec_pref pref;                           /*!< Codec packetization preferences */
 	struct sockaddr_in local_address;                     /*!< The address we are expecting RTP to be received on */
 	struct sockaddr_in remote_address;                    /*!< The address we are sending RTP to */
-	struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]; /*!< Payloads present */
+	struct ast_rtp_codecs codecs;                         /*!< Codec information */
+	int timeout;                                          /*!< RTP timeout time (negative or zero means disabled, negative value means temporarily disabled) */
+	int holdtimeout;                                      /*!< RTP timeout when on hold (negative or zero means disabled, negative value means temporarily disabled). */
+	int keepalive;                                        /*!< Send RTP comfort noice packets for keepalive */
 };
 
 struct ast_rtp_glue {
@@ -180,38 +187,32 @@
  */
 void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
 
-/*! \brief Clear payload information from an RTP instance
- *
- * \param instance The RTP instance to clear payload information from
- */
-void ast_rtp_instance_payloads_clear(struct ast_rtp_instance *instance);
-
-/*! \brief Set payload information on an RTP instance to the default
- *
- * \param instance The RTP instance to set default payload information on
- */
-void ast_rtp_instance_payloads_default(struct ast_rtp_instance *instance);
+/*! \brief Clear payload information from an RTP instance */
+void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
+
+/*! \brief Set payload information on an RTP instance to the default */
+void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
 
 /*! \brief Copy payload information from one RTP instance to another */
-void ast_rtp_instance_payloads_copy(struct ast_rtp_instance *src, struct ast_rtp_instance *dest);
+void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
 
 /*! \brief Record payload information that was seen in an m= SDP line */
-void ast_rtp_instance_payloads_set_m_type(struct ast_rtp_instance *instance, int payload);
+void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
 
 /*! \brief Record payload information that was seen in an a=rtpmap: SDP line */
-int ast_rtp_instance_payloads_set_rtpmap_type(struct ast_rtp_instance *instance, int payload, const char *mimeType, const char *mimeSubtype, enum ast_rtp_options options);
+int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, const char *mimeType, const char *mimeSubtype, enum ast_rtp_options options);
 
 /*! \brief Remove payload information */
-void ast_rtp_instance_payloads_unset(struct ast_rtp_instance *instance, int payload);
+void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
 
 /*! \brief Retrieve payload information by payload */
-struct ast_rtp_payload_type ast_rtp_instance_payload_lookup(struct ast_rtp_instance *instance, int payload);
+struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload);
 
 /*! \brief Retrieve all formats that were found */
-void ast_rtp_instance_payload_formats(struct ast_rtp_instance *instance, int *AstFormats, int *nonAstFormats);
+void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, int *AstFormats, int *nonAstFormats);
 
 /*! \brief Retrieve a payload based on whether it is an Asterisk format and the code */
-int ast_rtp_instance_payload_code(struct ast_rtp_instance *instance, const int isAstFormat, const int code);
+int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, const int isAstFormat, const int code);
 
 /*! \brief Retrieve mime subtype information on a payload */
 const char *ast_rtp_lookup_mime_subtype(const int isAstFormat, const int code, enum ast_rtp_options options);
@@ -220,7 +221,7 @@
 char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability, const int isAstFormat, enum ast_rtp_options options);
 
 /*! \brief Set codec packetization preferences */
-void ast_rtp_instance_packetization_set(struct ast_rtp_instance *instance, struct ast_codec_pref *prefs);
+void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs);
 
 /*! \brief Begin sending a DTMF digit
  *

Modified: team/file/rtp_engine/main/rtp_engine.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/main/rtp_engine.c?view=diff&rev=129107&r1=129106&r2=129107
==============================================================================
--- team/file/rtp_engine/main/rtp_engine.c (original)
+++ team/file/rtp_engine/main/rtp_engine.c Tue Jul  8 13:20:26 2008
@@ -269,14 +269,14 @@
 	return;
 }
 
-void ast_rtp_instance_payloads_clear(struct ast_rtp_instance *instance)
-{
-	int i;
-
-	for (i = 0; i < AST_RTP_MAX_PT; i++) {
-		instance->payloads[i].isAstFormat = 0;
-		instance->payloads[i].code = 0;
-		if (instance->engine && instance->engine->payload_set) {
+void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
+{
+	int i;
+
+	for (i = 0; i < AST_RTP_MAX_PT; i++) {
+		codecs->payloads[i].isAstFormat = 0;
+		codecs->payloads[i].code = 0;
+		if (instance && instance->engine && instance->engine->payload_set) {
 			instance->engine->payload_set(instance, i, 0, 0);
 		}
 	}
@@ -284,52 +284,52 @@
 	return;
 }
 
-void ast_rtp_instance_payloads_default(struct ast_rtp_instance *instance)
-{
-	int i;
-
-	for (i = 0; i < AST_RTP_MAX_PT; i++) {
-		instance->payloads[i].isAstFormat = static_RTP_PT[i].isAstFormat;
-		instance->payloads[i].code = static_RTP_PT[i].code;
-		if (instance->engine && instance->engine->payload_set) {
-			instance->engine->payload_set(instance, i, instance->payloads[i].isAstFormat, instance->payloads[i].code);
-		}
-	}
-
-	return;
-}
-
-void ast_rtp_instance_payloads_copy(struct ast_rtp_instance *src, struct ast_rtp_instance *dest)
+void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
+{
+	int i;
+
+	for (i = 0; i < AST_RTP_MAX_PT; i++) {
+		codecs->payloads[i].isAstFormat = static_RTP_PT[i].isAstFormat;
+		codecs->payloads[i].code = static_RTP_PT[i].code;
+		if (instance && instance->engine && instance->engine->payload_set) {
+			instance->engine->payload_set(instance, i, codecs->payloads[i].isAstFormat, codecs->payloads[i].code);
+		}
+	}
+
+	return;
+}
+
+void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 {
 	int i;
 
 	for (i = 0; i < AST_RTP_MAX_PT; i++) {
 		dest->payloads[i].isAstFormat = src->payloads[i].isAstFormat;
 		dest->payloads[i].code = src->payloads[i].code;
-		if (dest->engine && dest->engine->payload_set) {
-			dest->engine->payload_set(dest, i, dest->payloads[i].isAstFormat, dest->payloads[i].code);
-		}
-	}
-
-	return;
-}
-
-void ast_rtp_instance_payloads_set_m_type(struct ast_rtp_instance *instance, int payload)
+		if (instance && instance->engine && instance->engine->payload_set) {
+			instance->engine->payload_set(instance, i, dest->payloads[i].isAstFormat, dest->payloads[i].code);
+		}
+	}
+
+	return;
+}
+
+void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 {
 	if (payload < 0 || payload > AST_RTP_MAX_PT || !static_RTP_PT[payload].code) {
 		return;
 	}
 
-	instance->payloads[payload] = static_RTP_PT[payload];
-
-	if (instance->engine && instance->engine->payload_set) {
-		instance->engine->payload_set(instance, payload, instance->payloads[payload].isAstFormat, instance->payloads[payload].code);
-	}
-
-	return;
-}
-
-int ast_rtp_instance_payloads_set_rtpmap_type(struct ast_rtp_instance *instance, int payload, const char *mimeType, const char *mimeSubtype, enum ast_rtp_options options)
+	codecs->payloads[payload] = static_RTP_PT[payload];
+
+	if (instance && instance->engine && instance->engine->payload_set) {
+		instance->engine->payload_set(instance, payload, codecs->payloads[payload].isAstFormat, codecs->payloads[payload].code);
+	}
+
+	return;
+}
+
+int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, const char *mimeType, const char *mimeSubtype, enum ast_rtp_options options)
 {
 	int i;
 
@@ -339,9 +339,9 @@
 
 	for (i = 0; i < AST_RTP_MAX_PT; i++) {
 		if (!strcasecmp(mimeTypes[i].subtype, mimeSubtype) && !strcasecmp(mimeTypes[i].type, mimeType)) {
-			instance->payloads[i] = mimeTypes[i].payloadType;
-			if (instance->engine && instance->engine->payload_set) {
-				instance->engine->payload_set(instance, i, instance->payloads[i].isAstFormat, instance->payloads[i].code);
+			codecs->payloads[i] = mimeTypes[i].payloadType;
+			if (instance && instance->engine && instance->engine->payload_set) {
+				instance->engine->payload_set(instance, i, codecs->payloads[i].isAstFormat, codecs->payloads[i].code);
 			}
 			return 0;
 		}
@@ -350,23 +350,23 @@
 	return -1;
 }
 
-void ast_rtp_instance_payloads_unset(struct ast_rtp_instance *instance, int payload)
+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) {
 		return;
 	}
 
-	instance->payloads[payload].isAstFormat = 0;
-	instance->payloads[payload].code = 0;
-
-	if (instance->engine && instance->engine->payload_set) {
+	codecs->payloads[payload].isAstFormat = 0;
+	codecs->payloads[payload].code = 0;
+
+	if (instance && instance->engine && instance->engine->payload_set) {
 		instance->engine->payload_set(instance, payload, 0, 0);
 	}
 
 	return;
 }
 
-struct ast_rtp_payload_type ast_rtp_instance_payload_lookup(struct ast_rtp_instance *instance, int payload)
+struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload)
 {
 	struct ast_rtp_payload_type result = { .isAstFormat = 0, };
 
@@ -374,7 +374,7 @@
 		return result;
 	}
 
-	result = instance->payloads[payload];
+	result = codecs->payloads[payload];
 
 	if (!result.code) {
 		result = static_RTP_PT[payload];
@@ -383,29 +383,29 @@
 	return result;
 }
 
-void ast_rtp_instance_payload_formats(struct ast_rtp_instance *instance, int *AstFormats, int *nonAstFormats)
+void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, int *AstFormats, int *nonAstFormats)
 {
 	int i;
 
 	*AstFormats = *nonAstFormats = 0;
 
 	for (i = 0; i < AST_RTP_MAX_PT; i++) {
-		if (instance->payloads[i].isAstFormat) {
-			*AstFormats |= instance->payloads[i].code;
+		if (codecs->payloads[i].isAstFormat) {
+			*AstFormats |= codecs->payloads[i].code;
 		} else {
-			*nonAstFormats |= instance->payloads[i].code;
-		}
-	}
-
-	return;
-}
-
-int ast_rtp_instance_payload_code(struct ast_rtp_instance *instance, const int isAstFormat, const int code)
-{
-	int i;
-
-	for (i = 0; i < AST_RTP_MAX_PT; i++) {
-		if (instance->payloads[i].isAstFormat == isAstFormat && instance->payloads[i].code == code) {
+			*nonAstFormats |= codecs->payloads[i].code;
+		}
+	}
+
+	return;
+}
+
+int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, const int isAstFormat, const int code)
+{
+	int i;
+
+	for (i = 0; i < AST_RTP_MAX_PT; i++) {
+		if (codecs->payloads[i].isAstFormat == isAstFormat && codecs->payloads[i].code == code) {
 			return i;
 		}
 	}
@@ -473,17 +473,17 @@
 	return buf;
 }
 
-void ast_rtp_instance_packetization_set(struct ast_rtp_instance *instance, struct ast_codec_pref *prefs)
+void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs)
 {
 	int i;
 
 	for (i = 0; i < 32; i++) {
-		instance->pref.order[i] = prefs->order[i];
-		instance->pref.framing[i] = prefs->framing[i];
-	}
-
-	if (instance->engine->packetization_set) {
-		instance->engine->packetization_set(instance, &instance->pref);
+		codecs->pref.order[i] = prefs->order[i];
+		codecs->pref.framing[i] = prefs->framing[i];
+	}
+
+	if (instance && instance->engine->packetization_set) {
+		instance->engine->packetization_set(instance, &instance->codecs.pref);
 	}
 
 	return;

Modified: team/file/rtp_engine/res/res_rtp_asterisk.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/res/res_rtp_asterisk.c?view=diff&rev=129107&r1=129106&r2=129107
==============================================================================
--- team/file/rtp_engine/res/res_rtp_asterisk.c (original)
+++ team/file/rtp_engine/res/res_rtp_asterisk.c Tue Jul  8 13:20:26 2008
@@ -371,7 +371,7 @@
 	}
 
 	/* Grab the payload that they expect the RFC2833 packet to be received in */
-	payload = ast_rtp_instance_payload_code(instance, 0, AST_RTP_DTMF);
+	payload = ast_rtp_codecs_payload_code(&instance->codecs, 0, AST_RTP_DTMF);
 
 	/* Create the actual packet that we will be sending */
 	rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno));
@@ -655,7 +655,7 @@
 	if (frame->frametype == AST_FRAME_VIDEO) {
 		subclass &= ~0x1;
 	}
-	if ((codec = ast_rtp_instance_payload_code(instance, 1, subclass)) < 0) {
+	if ((codec = ast_rtp_codecs_payload_code(&instance->codecs, 1, subclass)) < 0) {
 		ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(frame->subclass));
 		return -1;
 	}
@@ -672,7 +672,7 @@
 
 	/* If no smoother is present see if we have to set one up */
 	if (!rtp->smoother && subclass != AST_FORMAT_SLINEAR && subclass != AST_FORMAT_G723_1) {
-		struct ast_format_list fmt = ast_codec_pref_getsize(&instance->pref, subclass);
+		struct ast_format_list fmt = ast_codec_pref_getsize(&instance->codecs.pref, subclass);
 		if (fmt.inc_ms) {
 			if (!(rtp->smoother = ast_smoother_new((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms))) {
 				ast_log(LOG_WARNING, "Unable to create smoother: format %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms));
@@ -838,7 +838,7 @@
 			    ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen);
 	}
 
-	payload = ast_rtp_instance_payload_lookup(instance, payloadtype);
+	payload = ast_rtp_codecs_payload_lookup(&instance->codecs, payloadtype);
 
 	/* If the payload is not actually an Asterisk one but a special one pass it off to the respective handler */
 	if (!payload.isAstFormat) {




More information about the asterisk-commits mailing list