[svn-commits] file: branch file/rtp_engine-mark2 r183645 - in /team/file/rtp_engine-mark2: ...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Mar 21 20:50:54 CDT 2009


Author: file
Date: Sat Mar 21 20:50:50 2009
New Revision: 183645

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183645
Log:
Convert chan_sip over to use the RTP engine architecture. Calls still seem happy but it will require more testing. Additionally remove the RTP stack from the core so it does not conflict.

Modified:
    team/file/rtp_engine-mark2/channels/chan_sip.c
    team/file/rtp_engine-mark2/configs/sip.conf.sample
    team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
    team/file/rtp_engine-mark2/main/Makefile
    team/file/rtp_engine-mark2/main/asterisk.c
    team/file/rtp_engine-mark2/main/loader.c
    team/file/rtp_engine-mark2/main/rtp_engine.c

Modified: team/file/rtp_engine-mark2/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_sip.c?view=diff&rev=183645&r1=183644&r2=183645
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_sip.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_sip.c Sat Mar 21 20:50:50 2009
@@ -229,7 +229,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/sched.h"
 #include "asterisk/io.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
 #include "asterisk/udptl.h"
 #include "asterisk/acl.h"
 #include "asterisk/manager.h"
@@ -271,6 +271,7 @@
 #include "asterisk/ast_version.h"
 #include "asterisk/event.h"
 #include "asterisk/tcptls.h"
+#include "asterisk/stun.h"
 
 /*** DOCUMENTATION
 	<application name="SIPDtmfMode" language="en_US">
@@ -691,6 +692,7 @@
 	AUTH_PEER_NOT_DYNAMIC = -6,
 	AUTH_ACL_FAILED = -7,
 	AUTH_BAD_TRANSPORT = -8,
+	AUTH_RTP_FAILED = 9,
 };
 
 /*! \brief States for outbound registrations (with register= lines in sip.conf */
@@ -1011,6 +1013,7 @@
 #define DEFAULT_USERAGENT "Asterisk PBX"	/*!< Default Useragent: header unless re-defined in sip.conf */
 #define DEFAULT_SDPSESSION "Asterisk PBX"	/*!< Default SDP session name, (s=) header unless re-defined in sip.conf */
 #define DEFAULT_SDPOWNER "root"			/*!< Default SDP username field in (o=) header unless re-defined in sip.conf */
+#define DEFAULT_ENGINE "asterisk"               /*!< Default RTP engine to use for sessions */
 #endif
 /*@}*/ 
 
@@ -1029,6 +1032,7 @@
 static char default_mohsuggest[MAX_MUSICCLASS];	   /*!< Global setting for moh class to suggest when putting 
                                                     *   a bridged channel on hold */
 static char default_parkinglot[AST_MAX_CONTEXT]; /*!< Parkinglot */
+static char default_engine[256];        /*!< Default RTP engine */
 static int default_maxcallbitrate;	/*!< Maximum bitrate for call */
 static struct ast_codec_pref default_prefs;		/*!< Default codec prefs */
 static unsigned int default_transports;			/*!< Default Transports (enum sip_transport) that are acceptable */
@@ -1610,6 +1614,7 @@
 		AST_STRING_FIELD(rpid_from);	/*!< Our RPID From header */
 		AST_STRING_FIELD(url);		/*!< URL to be sent with next message to peer */
 		AST_STRING_FIELD(parkinglot);		/*!< Parkinglot */
+		AST_STRING_FIELD(engine);       /*!< RTP engine to use */
 	);
 	char via[128];                          /*!< Via: header */
 	struct sip_socket socket;		/*!< The socket used for this dialog */
@@ -1696,9 +1701,9 @@
 	struct sip_peer *relatedpeer;		/*!< If this dialog is related to a peer, which one 
 							Used in peerpoke, mwi subscriptions */
 	struct sip_registry *registry;		/*!< If this is a REGISTER dialog, to which registry */
-	struct ast_rtp *rtp;			/*!< RTP Session */
-	struct ast_rtp *vrtp;			/*!< Video RTP session */
-	struct ast_rtp *trtp;			/*!< Text RTP session */
+	struct ast_rtp_instance *rtp;			/*!< RTP Session */
+	struct ast_rtp_instance *vrtp;			/*!< Video RTP session */
+	struct ast_rtp_instance *trtp;			/*!< Text RTP session */
 	struct sip_pkt *packets;		/*!< Packets scheduled for re-transmission */
 	struct sip_history_head *history;	/*!< History of this SIP dialog */
 	size_t history_entries;			/*!< Number of entires in the history */
@@ -1841,6 +1846,7 @@
 		AST_STRING_FIELD(mohsuggest);		/*!<  Music on Hold class */
 		AST_STRING_FIELD(parkinglot);		/*!<  Parkinglot */
 		AST_STRING_FIELD(useragent);		/*!<  User agent in SIP request (saved from registration) */
+		AST_STRING_FIELD(engine);               /*!<  RTP Engine to use */
 		);
 	struct sip_socket socket;	/*!< Socket used for this peer */
 	unsigned int transports:3;      /*!< Transports (enum sip_transport) that are acceptable for this peer */
@@ -2561,14 +2567,6 @@
 static int handle_response_register(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
 static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno);
 
-/*----- RTP interface functions */
-static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp,  struct ast_rtp *trtp, int codecs, int nat_active);
-static enum ast_rtp_get_result sip_get_rtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static enum ast_rtp_get_result sip_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static enum ast_rtp_get_result sip_get_trtp_peer(struct ast_channel *chan, struct ast_rtp **rtp);
-static int sip_get_codec(struct ast_channel *chan);
-static struct ast_frame *sip_rtp_read(struct ast_channel *ast, struct sip_pvt *p, int *faxdetect);
-
 /*------ T38 Support --------- */
 static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans);
 static struct ast_udptl *sip_get_udptl_peer(struct ast_channel *chan);
@@ -2588,6 +2586,9 @@
 static enum st_refresher st_get_refresher(struct sip_pvt *);
 static enum st_mode st_get_mode(struct sip_pvt *);
 static struct sip_st_dlg* sip_st_alloc(struct sip_pvt *const p);
+
+/*------- RTP Glue functions -------- */
+static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, int codecs, int nat_active);
 
 /*!--- SIP MWI Subscription support */
 static int sip_subscribe_mwi(const char *value, int lineno);
@@ -2617,8 +2618,8 @@
 	.fixup = sip_fixup,			/* called with chan locked */
 	.send_digit_begin = sip_senddigit_begin,	/* called with chan unlocked */
 	.send_digit_end = sip_senddigit_end,
-	.bridge = ast_rtp_bridge,			/* XXX chan unlocked ? */
-	.early_bridge = ast_rtp_early_bridge,
+	.bridge = ast_rtp_instance_bridge,			/* XXX chan unlocked ? */
+	.early_bridge = ast_rtp_instance_early_bridge,
 	.send_text = sip_sendtext,		/* called with chan locked */
 	.func_channel_read = acf_channel_read,
 	.queryoption = sip_queryoption,
@@ -2690,17 +2691,6 @@
 			return cur->x;
 	return errorvalue;
 }
-
-
-/*! \brief Interface structure with callbacks used to connect to RTP module */
-static struct ast_rtp_protocol sip_rtp = {
-	.type = "SIP",
-	.get_rtp_info = sip_get_rtp_peer,
-	.get_vrtp_info = sip_get_vrtp_peer,
-	.get_trtp_info = sip_get_trtp_peer,
-	.set_rtp_peer = sip_set_rtp_peer,
-	.get_codec = sip_get_codec,
-};
 
 /*!
  * duplicate a list of channel variables, \return the copy.
@@ -4591,11 +4581,11 @@
 
 	if (p->rtp) {
 		ast_debug(1, "Setting NAT on RTP to %s\n", mode);
-		ast_rtp_setnat(p->rtp, natflags);
+		ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_NAT, natflags);
 	}
 	if (p->vrtp) {
 		ast_debug(1, "Setting NAT on VRTP to %s\n", mode);
-		ast_rtp_setnat(p->vrtp, natflags);
+		ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_NAT, natflags);
 	}
 	if (p->udptl) {
 		ast_debug(1, "Setting NAT on UDPTL to %s\n", mode);
@@ -4603,7 +4593,7 @@
 	}
 	if (p->trtp) {
 		ast_debug(1, "Setting NAT on TRTP to %s\n", mode);
-		ast_rtp_setnat(p->trtp, natflags);
+		ast_rtp_instance_set_prop(p->trtp, AST_RTP_PROPERTY_NAT, natflags);
 	}
 }
 
@@ -4691,6 +4681,50 @@
 	*to_sock = *from_sock;
 }
 
+/*! \brief Initialize RTP portion of a dialog
+ * \returns -1 on failure, 0 on success
+ */
+static int dialog_initialize_rtp(struct sip_pvt *dialog)
+{
+	if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
+		return -1;
+	}
+
+	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (dialog->capability & AST_FORMAT_VIDEO_MASK)) {
+		if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
+			return -1;
+		}
+		dialog->vrtp->timeout = global_rtptimeout;
+		dialog->vrtp->holdtimeout = global_rtpholdtimeout;
+		dialog->vrtp->keepalive = global_rtpkeepalive;
+
+		ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, 1);
+	}
+
+	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_TEXTSUPPORT)) {
+		if (!(dialog->trtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr, NULL))) {
+			return -1;
+		}
+		dialog->trtp->timeout = global_rtptimeout;
+		dialog->trtp->holdtimeout = global_rtpholdtimeout;
+		dialog->trtp->keepalive = global_rtpkeepalive;
+
+		ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, 1);
+	}
+
+	dialog->rtp->timeout = global_rtptimeout;
+	dialog->rtp->holdtimeout = global_rtpholdtimeout;
+	dialog->rtp->keepalive = global_rtpkeepalive;
+
+	ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, 1);
+	ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
+	ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+
+	ast_rtp_instance_set_qos(dialog->rtp, global_tos_audio, 0, "SIP RTP");
+
+	return 0;
+}
+
 /*! \brief Create address structure from peer reference.
  *	This function copies data from peer to the dialog, so we don't have to look up the peer
  *	again from memory or database during the life time of the dialog.
@@ -4718,17 +4752,6 @@
 	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
 	ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
 	dialog->capability = peer->capability;
-	if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) &&
-			(!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) ||
-				!(dialog->capability & AST_FORMAT_VIDEO_MASK)) &&
-			dialog->vrtp) {
-		ast_rtp_destroy(dialog->vrtp);
-		dialog->vrtp = NULL;
-	}
-	if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_TEXTSUPPORT) && dialog->trtp) {
-		ast_rtp_destroy(dialog->trtp);
-		dialog->trtp = NULL;
-	}
 	dialog->prefs = peer->prefs;
 	if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
 		if (!dialog->udptl) {
@@ -4744,29 +4767,31 @@
 	}
 	do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE);
 
+	ast_string_field_set(dialog, engine, peer->engine);
+
+	if (dialog_initialize_rtp(dialog)) {
+		return -1;
+	}
+
 	if (dialog->rtp) { /* Audio */
-		ast_rtp_setdtmf(dialog->rtp, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
-		ast_rtp_setdtmfcompensate(dialog->rtp, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
-		ast_rtp_set_rtptimeout(dialog->rtp, peer->rtptimeout);
-		ast_rtp_set_rtpholdtimeout(dialog->rtp, peer->rtpholdtimeout);
-		ast_rtp_set_rtpkeepalive(dialog->rtp, peer->rtpkeepalive);
+		ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
+		ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+		dialog->rtp->timeout = peer->rtptimeout;
+		dialog->rtp->holdtimeout = peer->rtpholdtimeout;
+		dialog->rtp->keepalive = peer->rtpkeepalive;
 		/* Set Frame packetization */
-		ast_rtp_codec_setpref(dialog->rtp, &dialog->prefs);
+		ast_rtp_codecs_packetization_set(&dialog->rtp->codecs, dialog->rtp, &dialog->prefs);
 		dialog->autoframing = peer->autoframing;
 	}
 	if (dialog->vrtp) { /* Video */
-		ast_rtp_setdtmf(dialog->vrtp, 0);
-		ast_rtp_setdtmfcompensate(dialog->vrtp, 0);
-		ast_rtp_set_rtptimeout(dialog->vrtp, peer->rtptimeout);
-		ast_rtp_set_rtpholdtimeout(dialog->vrtp, peer->rtpholdtimeout);
-		ast_rtp_set_rtpkeepalive(dialog->vrtp, peer->rtpkeepalive);
+                dialog->vrtp->timeout = peer->rtptimeout;
+		dialog->vrtp->holdtimeout = peer->rtpholdtimeout;
+		dialog->vrtp->keepalive = peer->rtpkeepalive;
 	}
 	if (dialog->trtp) { /* Realtime text */
-		ast_rtp_setdtmf(dialog->trtp, 0);
-		ast_rtp_setdtmfcompensate(dialog->trtp, 0);
-		ast_rtp_set_rtptimeout(dialog->trtp, peer->rtptimeout);
-		ast_rtp_set_rtpholdtimeout(dialog->trtp, peer->rtpholdtimeout);
-		ast_rtp_set_rtpkeepalive(dialog->trtp, peer->rtpkeepalive);
+		dialog->trtp->timeout = peer->rtptimeout;
+		dialog->trtp->holdtimeout = peer->rtpholdtimeout;
+		dialog->trtp->keepalive = peer->rtpkeepalive;
 	}
 
 	ast_string_field_set(dialog, peername, peer->name);
@@ -4780,6 +4805,7 @@
 	ast_string_field_set(dialog, fullcontact, peer->fullcontact);
 	ast_string_field_set(dialog, context, peer->context);
 	ast_string_field_set(dialog, parkinglot, peer->parkinglot);
+	ast_string_field_set(dialog, engine, peer->engine);
 	ref_proxy(dialog, obproxy_get(dialog, peer));
 	dialog->callgroup = peer->callgroup;
 	dialog->pickupgroup = peer->pickupgroup;
@@ -4873,6 +4899,10 @@
 		}
 		unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup");
 		return res;
+	}
+
+	if (dialog_initialize_rtp(dialog)) {
+		return -1;
 	}
 
 	ast_string_field_set(dialog, tohost, peername);
@@ -5150,15 +5180,13 @@
 		p->notify_headers = NULL;
 	}
 	if (p->rtp) {
-		ast_rtp_destroy(p->rtp);
+		ast_rtp_instance_destroy(p->rtp);
 	}
 	if (p->vrtp) {
-		ast_rtp_destroy(p->vrtp);
+		ast_rtp_instance_destroy(p->vrtp);
 	}
 	if (p->trtp) {
-		while (ast_rtp_get_bridged(p->trtp))
-			usleep(1);
-		ast_rtp_destroy(p->trtp);
+		ast_rtp_instance_destroy(p->trtp);
 	}
 	if (p->udptl)
 		ast_udptl_destroy(p->udptl);
@@ -5677,42 +5705,50 @@
 
 			if (!p->pendinginvite) {
 				struct ast_channel *bridge = ast_bridged_channel(oldowner);
-				char *audioqos = "";
-				char *videoqos = "";
-				char *textqos = "";
-
-				if (p->rtp)
-					ast_rtp_set_vars(oldowner, p->rtp);
+				char quality_buf[AST_MAX_USER_FIELD], *quality;
+
+				if (p->rtp) {
+					ast_rtp_instance_set_stats_vars(oldowner, p->rtp);
+				}
 
 				if (bridge) {
 					struct sip_pvt *q = bridge->tech_pvt;
 
-					if (IS_SIP_TECH(bridge->tech) && q)
-						ast_rtp_set_vars(bridge, q->rtp);
+					if (IS_SIP_TECH(bridge->tech) && q) {
+						ast_rtp_instance_set_stats_vars(bridge, q->rtp);
+					}
 				}
 
-				if (p->vrtp)
-					videoqos = ast_rtp_get_quality(p->vrtp, NULL, RTPQOS_SUMMARY);
-				if (p->trtp)
-					textqos = ast_rtp_get_quality(p->trtp, NULL, RTPQOS_SUMMARY);
+				if (p->do_history || oldowner) {
+					if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+						if (p->do_history) {
+							append_history(p, "RTCPaudio", "Quality:%s", quality);
+						}
+						if (oldowner) {
+							pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", quality);
+						}
+					}
+					if (p->vrtp && (quality = ast_rtp_instance_get_quality(p->vrtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+						if (p->do_history) {
+							append_history(p, "RTCPvideo", "Quality:%s", quality);
+						}
+						if (oldowner) {
+							pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", quality);
+						}
+					}
+					if (p->trtp && (quality = ast_rtp_instance_get_quality(p->trtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+						if (p->do_history) {
+							append_history(p, "RTCPtext", "Quality:%s", quality);
+						}
+						if (oldowner) {
+							pbx_builtin_setvar_helper(oldowner, "RTPTEXTQOS", quality);
+						}
+					}
+				}
+
 				/* Send a hangup */
 				transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
 
-				/* Get RTCP quality before end of call */
-				if (p->do_history) {
-					if (p->rtp)
-						append_history(p, "RTCPaudio", "Quality:%s", audioqos);
-					if (p->vrtp)
-						append_history(p, "RTCPvideo", "Quality:%s", videoqos);
-					if (p->trtp)
-						append_history(p, "RTCPtext", "Quality:%s", textqos);
-				}
-				if (p->rtp && oldowner)
-					pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", audioqos);
-				if (p->vrtp && oldowner)
-					pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", videoqos);
-				if (p->trtp && oldowner)
-					pbx_builtin_setvar_helper(oldowner, "RTPTEXTQOS", textqos);
 			} else {
 				/* Note we will need a BYE when this all settles out
 				   but we can't send one while we have "INVITE" outstanding. */
@@ -5772,7 +5808,7 @@
 			res = transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL);
 			ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
 		} else {
-			ast_rtp_new_source(p->rtp);
+			ast_rtp_instance_new_source(p->rtp);
 			res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL, FALSE);
 			ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
 		}
@@ -5808,13 +5844,13 @@
 				if ((ast->_state != AST_STATE_UP) &&
 				    !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) &&
 				    !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
-					ast_rtp_new_source(p->rtp);
+					ast_rtp_instance_new_source(p->rtp);
 					p->invitestate = INV_EARLY_MEDIA;
 					transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE, FALSE);
 					ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);	
 				}
 				p->lastrtptx = time(NULL);
-				res = ast_rtp_write(p->rtp, frame);
+				res = ast_rtp_instance_write(p->rtp, frame);
 			}
 			sip_pvt_unlock(p);
 		}
@@ -5832,7 +5868,7 @@
 					ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);	
 				}
 				p->lastrtptx = time(NULL);
-				res = ast_rtp_write(p->vrtp, frame);
+				res = ast_rtp_instance_write(p->vrtp, frame);
 			}
 			sip_pvt_unlock(p);
 		}
@@ -5841,7 +5877,7 @@
 		if (p) {
 			sip_pvt_lock(p);
 			if (p->red) {
-				ast_red_buffer_t140(p->trtp, frame);
+				ast_rtp_red_buffer(p->trtp, frame);
 			} else {
 				if (p->trtp) {
 					/* Activate text early media */
@@ -5853,7 +5889,7 @@
 						ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);	
 					}
 					p->lastrtptx = time(NULL);
-					res = ast_rtp_write(p->trtp, frame);
+					res = ast_rtp_instance_write(p->trtp, frame);
 				}
 			}
 			sip_pvt_unlock(p);
@@ -5933,11 +5969,15 @@
 	sip_pvt_lock(p);
 	switch (ast_test_flag(&p->flags[0], SIP_DTMF)) {
 	case SIP_DTMF_INBAND:
-		res = -1; /* Tell Asterisk to generate inband indications */
+		if (p->rtp && p->rtp->dtmf_mode == AST_RTP_DTMF_MODE_INBAND) {
+			ast_rtp_instance_dtmf_begin(p->rtp, digit);
+		} else {
+			res = -1; /* Tell Asterisk to generate inband indications */
+		}
 		break;
 	case SIP_DTMF_RFC2833:
 		if (p->rtp)
-			ast_rtp_senddigit_begin(p->rtp, digit);
+			ast_rtp_instance_dtmf_begin(p->rtp, digit);
 		break;
 	default:
 		break;
@@ -5962,10 +6002,14 @@
 		break;
 	case SIP_DTMF_RFC2833:
 		if (p->rtp)
-			ast_rtp_senddigit_end(p->rtp, digit);
+			ast_rtp_instance_dtmf_end(p->rtp, digit);
 		break;
 	case SIP_DTMF_INBAND:
-		res = -1; /* Tell Asterisk to stop inband indications */
+		if (p->rtp && p->rtp->dtmf_mode == AST_RTP_DTMF_MODE_INBAND) {
+			ast_rtp_instance_dtmf_end(p->rtp, digit);
+		} else {
+			res = -1; /* Tell Asterisk to stop inband indications */
+		}
 		break;
 	}
 	sip_pvt_unlock(p);
@@ -6060,11 +6104,11 @@
 		res = -1;
 		break;
 	case AST_CONTROL_HOLD:
-		ast_rtp_new_source(p->rtp);
+		ast_rtp_instance_new_source(p->rtp);
 		ast_moh_start(ast, data, p->mohinterpret);
 		break;
 	case AST_CONTROL_UNHOLD:
-		ast_rtp_new_source(p->rtp);
+		ast_rtp_instance_new_source(p->rtp);
 		ast_moh_stop(ast);
 		break;
 	case AST_CONTROL_VIDUPDATE:	/* Request a video frame update */
@@ -6110,7 +6154,7 @@
 		}
 		break;
 	case AST_CONTROL_SRCUPDATE:
-		ast_rtp_new_source(p->rtp);
+		ast_rtp_instance_new_source(p->rtp);
 		break;
 	case -1:
 		res = -1;
@@ -6224,23 +6268,29 @@
 		ast_debug(3, "This channel will not be able to handle video.\n");
 
 	if ((ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
-		i->vad = ast_dsp_new();
-		ast_dsp_set_features(i->vad, DSP_FEATURE_DIGIT_DETECT);
-		if (global_relaxdtmf)
-			ast_dsp_set_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
+		if (!i->rtp || ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_INBAND)) {
+			i->vad = ast_dsp_new();
+			ast_dsp_set_features(i->vad, DSP_FEATURE_DIGIT_DETECT);
+			if (global_relaxdtmf)
+				ast_dsp_set_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
+		}
+	} else if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) {
+		if (i->rtp) {
+			ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_RFC2833);
+		}
 	}
 
 	/* Set file descriptors for audio, video, realtime text and UDPTL as needed */
 	if (i->rtp) {
-		ast_channel_set_fd(tmp, 0, ast_rtp_fd(i->rtp));
-		ast_channel_set_fd(tmp, 1, ast_rtcp_fd(i->rtp));
+		ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
+		ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
 	}
 	if (needvideo && i->vrtp) {
-		ast_channel_set_fd(tmp, 2, ast_rtp_fd(i->vrtp));
-		ast_channel_set_fd(tmp, 3, ast_rtcp_fd(i->vrtp));
+		ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
+		ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1));
 	}
 	if (needtext && i->trtp) 
-		ast_channel_set_fd(tmp, 4, ast_rtp_fd(i->trtp));
+		ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0));
 	if (i->udptl)
 		ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl));
 
@@ -6468,19 +6518,19 @@
 
 	switch(ast->fdno) {
 	case 0:
-		f = ast_rtp_read(p->rtp);	/* RTP Audio */
+		f = ast_rtp_instance_read(p->rtp, 0);	/* RTP Audio */
 		break;
 	case 1:
-		f = ast_rtcp_read(p->rtp);	/* RTCP Control Channel */
+		f = ast_rtp_instance_read(p->rtp, 1);	/* RTCP Control Channel */
 		break;
 	case 2:
-		f = ast_rtp_read(p->vrtp);	/* RTP Video */
+		f = ast_rtp_instance_read(p->vrtp, 0);	/* RTP Video */
 		break;
 	case 3:
-		f = ast_rtcp_read(p->vrtp);	/* RTCP Control Channel for video */
+		f = ast_rtp_instance_read(p->vrtp, 1);	/* RTCP Control Channel for video */
 		break;
 	case 4:
-		f = ast_rtp_read(p->trtp);	/* RTP Text */
+		f = ast_rtp_instance_read(p->trtp, 0);	/* RTP Text */
 		if (sipdebug_text) {
 			int i;
 			unsigned char* arr = f->data.ptr;
@@ -6687,50 +6737,11 @@
 	p->ocseq = INITIAL_CSEQ;
 
 	if (sip_methods[intended_method].need_rtp) {
-		p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
-		/* If the global videosupport flag is on, we always create a RTP interface for video */
-		if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT))
-			p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- 		if (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT))
- 			p->trtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
-		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
-			p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
- 		if (!p->rtp|| (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp) 
-				|| (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) && !p->trtp)) {
- 			ast_log(LOG_WARNING, "Unable to create RTP audio %s%ssession: %s\n",
- 				ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video " : "",
- 				ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "and text " : "", strerror(errno));
-			if (p->chanvars) {
-				ast_variables_destroy(p->chanvars);
-				p->chanvars = NULL;
-			}
-			ao2_t_ref(p, -1, "failed to create RTP audio session, drop p");
-			return NULL;
-		}
-		ast_rtp_setqos(p->rtp, global_tos_audio, global_cos_audio, "SIP RTP");
-		ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
-		ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
-		ast_rtp_set_rtptimeout(p->rtp, global_rtptimeout);
-		ast_rtp_set_rtpholdtimeout(p->rtp, global_rtpholdtimeout);
-		ast_rtp_set_rtpkeepalive(p->rtp, global_rtpkeepalive);
-		if (p->vrtp) {
-			ast_rtp_setqos(p->vrtp, global_tos_video, global_cos_video, "SIP VRTP");
-			ast_rtp_setdtmf(p->vrtp, 0);
-			ast_rtp_setdtmfcompensate(p->vrtp, 0);
-			ast_rtp_set_rtptimeout(p->vrtp, global_rtptimeout);
-			ast_rtp_set_rtpholdtimeout(p->vrtp, global_rtpholdtimeout);
-			ast_rtp_set_rtpkeepalive(p->vrtp, global_rtpkeepalive);
-		}
-		if (p->trtp) {
-			ast_rtp_setqos(p->trtp, global_tos_text, global_cos_text, "SIP TRTP");
-			ast_rtp_setdtmf(p->trtp, 0);
-			ast_rtp_setdtmfcompensate(p->trtp, 0);
-		}
-		if (p->udptl)
+		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && (p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr))) {
 			ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
+		}
 		p->maxcallbitrate = default_maxcallbitrate;
 		p->autoframing = global_autoframing;
-		ast_rtp_codec_setpref(p->rtp, &p->prefs);
 	}
 
 	if (useglobal_nat && sin) {
@@ -6762,6 +6773,7 @@
 	}
 	ast_string_field_set(p, context, sip_cfg.default_context);
 	ast_string_field_set(p, parkinglot, default_parkinglot);
+	ast_string_field_set(p, engine, default_engine);
 
 	AST_LIST_HEAD_INIT_NOLOCK(&p->request_queue);
 
@@ -7396,7 +7408,7 @@
 	int iterator;
 	int sendonly = -1;
 	int numberofports;
-	struct ast_rtp *newaudiortp, *newvideortp, *newtextrtp;	/* Buffers for codec handling */
+	struct ast_rtp_codecs newaudiortp, newvideortp, newtextrtp;
 	int newjointcapability;				/* Negotiated capability */
 	int newpeercapability;
 	int newnoncodeccapability;
@@ -7421,33 +7433,10 @@
 		return -1;
 	}
 
-	/* Initialize the temporary RTP structures we use to evaluate the offer from the peer */
-#ifdef LOW_MEMORY
-	newaudiortp = ast_threadstorage_get(&ts_audio_rtp, ast_rtp_alloc_size());
-#else
-	newaudiortp = alloca(ast_rtp_alloc_size());
-#endif
-	memset(newaudiortp, 0, ast_rtp_alloc_size());
-	ast_rtp_new_init(newaudiortp);
-	ast_rtp_pt_clear(newaudiortp);
-
-#ifdef LOW_MEMORY
-	newvideortp = ast_threadstorage_get(&ts_video_rtp, ast_rtp_alloc_size());
-#else
-	newvideortp = alloca(ast_rtp_alloc_size());
-#endif
-	memset(newvideortp, 0, ast_rtp_alloc_size());
-	ast_rtp_new_init(newvideortp);
-	ast_rtp_pt_clear(newvideortp);
-
-#ifdef LOW_MEMORY
-	newtextrtp = ast_threadstorage_get(&ts_text_rtp, ast_rtp_alloc_size());
-#else
-	newtextrtp = alloca(ast_rtp_alloc_size());
-#endif
-	memset(newtextrtp, 0, ast_rtp_alloc_size());
-	ast_rtp_new_init(newtextrtp);
-	ast_rtp_pt_clear(newtextrtp);
+	/* Make sure that the codec structures are all cleared out */
+	ast_rtp_codecs_payloads_clear(&newaudiortp, NULL);
+	ast_rtp_codecs_payloads_clear(&newvideortp, NULL);
+	ast_rtp_codecs_payloads_clear(&newtextrtp, NULL);
 
 	/* Update our last rtprx when we receive an SDP, too */
 	p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */
@@ -7529,11 +7518,13 @@
 	p->novideo = TRUE;
 	p->notext = TRUE;
 
-	if (p->vrtp)
-		ast_rtp_pt_clear(newvideortp);  /* Must be cleared in case no m=video line exists */
- 
-	if (p->trtp)
-		ast_rtp_pt_clear(newtextrtp);  /* Must be cleared in case no m=text line exists */
+	if (p->vrtp) {
+		ast_rtp_codecs_payloads_clear(&newvideortp, NULL);
+	}
+
+	if (p->trtp) {
+		ast_rtp_codecs_payloads_clear(&newtextrtp, NULL);
+	}
 
 	/* Find media streams in this SDP offer */
 	while ((m = get_sdp_iterate(&iterator, req, "m"))[0] != '\0') {
@@ -7558,7 +7549,8 @@
 				}
 				if (debug)
 					ast_verbose("Found RTP audio format %d\n", codec);
-				ast_rtp_set_m_type(newaudiortp, codec);
+				
+				ast_rtp_codecs_payloads_set_m_type(&newaudiortp, NULL, codec);
 			}
 		} else if ((sscanf(m, "video %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
 		    (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1 && len >= 0)) {
@@ -7574,7 +7566,7 @@
 				}
 				if (debug)
 					ast_verbose("Found RTP video format %d\n", codec);
-				ast_rtp_set_m_type(newvideortp, codec);
+				ast_rtp_codecs_payloads_set_m_type(&newvideortp, NULL, codec);
 			}
 		} else if ((sscanf(m, "text %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
 		    (sscanf(m, "text %d RTP/AVP %n", &x, &len) == 1 && len > 0)) {
@@ -7590,7 +7582,7 @@
 				}
 				if (debug)
 					ast_verbose("Found RTP text format %d\n", codec);
-				ast_rtp_set_m_type(newtextrtp, codec);
+				ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec);
 			}
 		} else if (p->udptl && ( (sscanf(m, "image %d udptl t38%n", &x, &len) == 1 && len > 0) || 
 			(sscanf(m, "image %d UDPTL t38%n", &x, &len) == 1 && len > 0) )) {
@@ -7655,10 +7647,8 @@
 		if (udptlportno > 0) {
 			sin.sin_port = htons(udptlportno);
 			if (ast_test_flag(&p->flags[0], SIP_NAT) && ast_test_flag(&p->flags[1], SIP_PAGE2_UDPTL_DESTINATION)) {
-				struct sockaddr_in peer;
-				ast_rtp_get_peer(p->rtp, &peer);
-				if (peer.sin_addr.s_addr) {
-					memcpy(&sin.sin_addr, &peer.sin_addr, sizeof(sin.sin_addr));
+				if (p->rtp->remote_address.sin_addr.s_addr) {
+					memcpy(&sin.sin_addr, &p->rtp->remote_address.sin_addr, sizeof(&sin.sin_addr));
 					if (debug) {
 						ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(sin.sin_addr));
 					}
@@ -7678,7 +7668,7 @@
 	if (p->rtp) {
 		if (portno > 0) {
 			sin.sin_port = htons(portno);
-			ast_rtp_set_peer(p->rtp, &sin);
+			ast_rtp_instance_set_remote_address(p->rtp, &sin);
 			if (debug)
 				ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
 		} else {
@@ -7686,7 +7676,7 @@
 				if (debug)
 					ast_verbose("Got T.38 Re-invite without audio. Keeping RTP active during T.38 session. Callid %s\n", p->callid);
 			} else {
-				ast_rtp_stop(p->rtp);
+				ast_rtp_instance_stop(p->rtp);
 				if (debug)
 					ast_verbose("Peer doesn't provide audio. Callid %s\n", p->callid);
 			}
@@ -7769,18 +7759,17 @@
 				}
 			}
 			if (framing && p->autoframing) {
-				struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
+				struct ast_codec_pref *pref = &p->rtp->codecs.pref;
 				int codec_n;
-				int format = 0;
-				for (codec_n = 0; codec_n < MAX_RTP_PT; codec_n++) {
-					format = ast_rtp_codec_getformat(codec_n);
-					if (!format)	/* non-codec or not found */
+				for (codec_n = 0; codec_n < AST_RTP_MAX_PT; codec_n++) {
+					struct ast_rtp_payload_type format = ast_rtp_codecs_payload_lookup(&p->rtp->codecs, codec_n);
+					if (!format.isAstFormat || !format.code)	/* non-codec or not found */
 						continue;
 					if (option_debug)
-						ast_log(LOG_DEBUG, "Setting framing for %d to %ld\n", format, framing);
-					ast_codec_pref_setsize(pref, format, framing);
+						ast_log(LOG_DEBUG, "Setting framing for %d to %ld\n", format.code, framing);
+					ast_codec_pref_setsize(pref, format.code, framing);
 				}
-				ast_rtp_codec_setpref(p->rtp, pref);
+				ast_rtp_codecs_packetization_set(&p->rtp->codecs, p->rtp, pref);
 			}
 			continue;
 		}
@@ -7792,7 +7781,7 @@
 
 			sscanf(red_cp, "%u", &red_data_pt[red_num_gen]);
 			red_cp = strtok(red_cp, "/");
-			while (red_cp && red_num_gen++ < RED_MAX_GENERATION) {
+			while (red_cp && red_num_gen++ < AST_RED_MAX_GENERATION) {
 				sscanf(red_cp, "%u", &red_data_pt[red_num_gen]);
 				red_cp = strtok(NULL, "/");
 			}
@@ -7801,13 +7790,13 @@
 		}
 
 		if (sscanf(a, "fmtp: %u %63s", &codec, fmtp_string) == 2) {
-			struct rtpPayloadType payload;
+			struct ast_rtp_payload_type payload;
 			unsigned int handled = 0;
 
-			payload = ast_rtp_lookup_pt(newaudiortp, codec);
+			payload = ast_rtp_codecs_payload_lookup(&newaudiortp, codec);
 			if (!payload.code) {
 				/* it wasn't found, try the video rtp */
-				payload = ast_rtp_lookup_pt(newvideortp, codec);
+				payload = ast_rtp_codecs_payload_lookup(&newvideortp, codec);
 			}
 			if (payload.code && payload.isAstFormat) {
 				unsigned int bit_rate;
@@ -7817,7 +7806,7 @@
 					if (sscanf(fmtp_string, "bitrate=%u", &bit_rate) == 1) {
 						if (bit_rate != 32000) {
 							ast_log(LOG_WARNING, "Got Siren7 offer at %d bps, but only 32000 bps supported; ignoring.\n", bit_rate);
-							ast_rtp_unset_m_type(newaudiortp, codec);
+							ast_rtp_codecs_payloads_unset(&newaudiortp, NULL, codec);
 						} else {
 							handled = 1;
 						}
@@ -7827,7 +7816,7 @@
 					if (sscanf(fmtp_string, "bitrate=%u", &bit_rate) == 1) {
 						if (bit_rate != 48000) {
 							ast_log(LOG_WARNING, "Got Siren14 offer at %d bps, but only 48000 bps supported; ignoring.\n", bit_rate);
-							ast_rtp_unset_m_type(newaudiortp, codec);
+							ast_rtp_codecs_payloads_unset(&newaudiortp, NULL, codec);
 						} else {
 							handled = 1;
 						}
@@ -7849,24 +7838,24 @@
 				/* Note: should really look at the '#chans' params too */
 				/* Note: This should all be done in the context of the m= above */
 				if (!strncasecmp(mimeSubtype, "H26", 3) || !strncasecmp(mimeSubtype, "MP4", 3)) {         /* Video */
-					if (ast_rtp_set_rtpmap_type_rate(newvideortp, codec, "video", mimeSubtype, 0, sample_rate) != -1) {
+					if(ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newvideortp, NULL, codec, "video", mimeSubtype, 0, sample_rate) != -1) {
 						if (debug)
 							ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec);
 						found_rtpmap_codecs[last_rtpmap_codec] = codec;
 						last_rtpmap_codec++;
 					} else {
-						ast_rtp_unset_m_type(newvideortp, codec);
+						ast_rtp_codecs_payloads_unset(&newvideortp, NULL, codec);
 						if (debug) 
 							ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec);
 					}
 				} else if (!strncasecmp(mimeSubtype, "T140", 4)) { /* Text */
 					if (p->trtp) {
 						/* ast_verbose("Adding t140 mimeSubtype to textrtp struct\n"); */
-						ast_rtp_set_rtpmap_type(newtextrtp, codec, "text", mimeSubtype, 0);
+						ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newtextrtp, NULL, codec, "text", mimeSubtype, 0, sample_rate);
 					}
 				} else if (!strncasecmp(mimeSubtype, "RED", 3)) { /* Text with Redudancy */
 					if (p->trtp) {
-						ast_rtp_set_rtpmap_type(newtextrtp, codec, "text", mimeSubtype, 0);
+						ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newtextrtp, NULL, codec, "text", mimeSubtype, 0, sample_rate);
 						red_pt = codec;
 						sprintf(red_fmtp, "fmtp:%d ", red_pt); 
 
@@ -7874,15 +7863,14 @@
 							ast_verbose("RED submimetype has payload type: %d\n", red_pt);
 					}
 				} else {                                          /* Must be audio?? */
-					if (ast_rtp_set_rtpmap_type_rate(newaudiortp, codec, "audio", mimeSubtype,
-									 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0,
-									 sample_rate) != -1) {
+					if(ast_rtp_codecs_payloads_set_rtpmap_type_rate(&newaudiortp, NULL, codec, "audio", mimeSubtype,
+											ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0, sample_rate) != -1) {
 						if (debug)
 							ast_verbose("Found audio description format %s for ID %d\n", mimeSubtype, codec);
 						found_rtpmap_codecs[last_rtpmap_codec] = codec;
 						last_rtpmap_codec++;
 					} else {
-						ast_rtp_unset_m_type(newaudiortp, codec);
+						ast_rtp_codecs_payloads_unset(&newaudiortp, NULL, codec);
 						if (debug) 
 							ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec);
 					}
@@ -8021,9 +8009,9 @@
 	}
 
 	/* Now gather all of the codecs that we are asked for: */
-	ast_rtp_get_current_formats(newaudiortp, &peercapability, &peernoncodeccapability);
-	ast_rtp_get_current_formats(newvideortp, &vpeercapability, &vpeernoncodeccapability);
-	ast_rtp_get_current_formats(newtextrtp, &tpeercapability, &tpeernoncodeccapability);
+	ast_rtp_codecs_payload_formats(&newaudiortp, &peercapability, &peernoncodeccapability);
+	ast_rtp_codecs_payload_formats(&newvideortp, &vpeercapability, &vpeernoncodeccapability);
+	ast_rtp_codecs_payload_formats(&newtextrtp, &tpeercapability, &tpeernoncodeccapability);
  
 	newjointcapability = p->capability & (peercapability | vpeercapability | tpeercapability);
 	newpeercapability = (peercapability | vpeercapability | tpeercapability);
@@ -8042,9 +8030,9 @@
 			    ast_getformatname_multiple(s5, SIPBUFSIZE, newjointcapability));
 
 		ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
-			    ast_rtp_lookup_mime_multiple(s1, SIPBUFSIZE, p->noncodeccapability, 0, 0),
-			    ast_rtp_lookup_mime_multiple(s2, SIPBUFSIZE, peernoncodeccapability, 0, 0),
-			    ast_rtp_lookup_mime_multiple(s3, SIPBUFSIZE, newnoncodeccapability, 0, 0));
+			    ast_rtp_lookup_mime_multiple2(s1, SIPBUFSIZE, p->noncodeccapability, 0, 0),
+			    ast_rtp_lookup_mime_multiple2(s2, SIPBUFSIZE, peernoncodeccapability, 0, 0),
+			    ast_rtp_lookup_mime_multiple2(s3, SIPBUFSIZE, newnoncodeccapability, 0, 0));
 	}
 	if (!newjointcapability) {
 		/* If T.38 was not negotiated either, totally bail out... */
@@ -8071,11 +8059,9 @@
 		p->red = 0; 
 	}
 
-	ast_rtp_pt_copy(p->rtp, newaudiortp);
-	if (p->vrtp)
-		ast_rtp_pt_copy(p->vrtp, newvideortp);
-	if (p->trtp)
-		ast_rtp_pt_copy(p->trtp, newtextrtp);
+	if (p->trtp) {
+		ast_rtp_codecs_payloads_copy(&newtextrtp, &p->trtp->codecs, p->trtp);
+	}
 
 	if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) {
 		ast_clear_flag(&p->flags[0], SIP_DTMF);
@@ -8083,8 +8069,8 @@
 			/* XXX Would it be reasonable to drop the DSP at this point? XXX */
 			ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833);
 			/* Since RFC2833 is now negotiated we need to change some properties of the RTP stream */
-			ast_rtp_setdtmf(p->rtp, 1);
-			ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
+			ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1);
+			ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
 		} else {
 			ast_set_flag(&p->flags[0], SIP_DTMF_INBAND);
 		}
@@ -8092,21 +8078,21 @@
 
 	/* Setup audio port number */
 	if (p->rtp && sin.sin_port) {
-		ast_rtp_set_peer(p->rtp, &sin);
+		ast_rtp_instance_set_remote_address(p->rtp, &sin);
 		if (debug)
 			ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
 	}
 
 	/* Setup video port number */
 	if (p->vrtp && vsin.sin_port) {
-		ast_rtp_set_peer(p->vrtp, &vsin);
+		ast_rtp_instance_set_remote_address(p->vrtp, &vsin);
 		if (debug) 
 			ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(vsin.sin_addr), ntohs(vsin.sin_port));
 	}
 
 	/* Setup text port number */
 	if (p->trtp && tsin.sin_port) {
-		ast_rtp_set_peer(p->trtp, &tsin);
+		ast_rtp_instance_set_remote_address(p->trtp, &tsin);
 		if (debug) 
 			ast_verbose("Peer text RTP is at port %s:%d\n", ast_inet_ntoa(tsin.sin_addr), ntohs(tsin.sin_port));
 	}
@@ -8153,7 +8139,7 @@
 				       S_OR(p->mohsuggest, NULL),
 				       !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
 		if (sendonly)
-			ast_rtp_stop(p->rtp);
+			ast_rtp_instance_stop(p->rtp);
 		/* RTCP needs to go ahead, even if we're on hold!!! */
 		/* Activate a re-invite */
 		ast_queue_frame(p->owner, &ast_null_frame);
@@ -8990,19 +8976,19 @@
 
 	if (debug)
 		ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
-	if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1)
+	if ((rtp_code = ast_rtp_codecs_payload_code(&p->rtp->codecs, 1, codec)) == -1)
 		return;
 
 	if (p->rtp) {
-		struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
+		struct ast_codec_pref *pref = &p->rtp->codecs.pref;
 		fmt = ast_codec_pref_getsize(pref, codec);
 	} else /* I dont see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
 		return;

[... 1165 lines stripped ...]



More information about the svn-commits mailing list