[asterisk-commits] branch group/5162_rtp_packetization r16614 - in /team/group/5162_rtp_packetiz...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Mar 30 17:22:14 MST 2006


Author: oej
Date: Thu Mar 30 18:22:12 2006
New Revision: 16614

URL: http://svn.digium.com/view/asterisk?rev=16614&view=rev
Log:
Including patch from bug tracker

Modified:
    team/group/5162_rtp_packetization/channels/chan_sip.c
    team/group/5162_rtp_packetization/configs/sip.conf.sample
    team/group/5162_rtp_packetization/frame.c
    team/group/5162_rtp_packetization/include/asterisk/frame.h
    team/group/5162_rtp_packetization/include/asterisk/rtp.h
    team/group/5162_rtp_packetization/rtp.c

Modified: team/group/5162_rtp_packetization/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/5162_rtp_packetization/channels/chan_sip.c?rev=16614&r1=16613&r2=16614&view=diff
==============================================================================
--- team/group/5162_rtp_packetization/channels/chan_sip.c (original)
+++ team/group/5162_rtp_packetization/channels/chan_sip.c Thu Mar 30 18:22:12 2006
@@ -402,6 +402,7 @@
 static int srvlookup;			/*!< SRV Lookup on or off. Default is off, RFC behavior is on */
 static int pedanticsipchecking;		/*!< Extra checking ?  Default off */
 static int autocreatepeer;		/*!< Auto creation of peers at registration? Default off. */
+static int global_framems = 0;
 static int global_relaxdtmf;			/*!< Relax DTMF */
 static int global_rtptimeout;		/*!< Time out call if no RTP */
 static int global_rtpholdtimeout;
@@ -745,6 +746,7 @@
 	struct ast_variable *chanvars;		/*!< Channel variables to set for call */
 	struct sip_pvt *next;			/*!< Next dialog in chain */
 	struct sip_invite_param *options;	/*!< Options for INVITE */
+	int framems;				/*!< Packetization */
 } *iflist = NULL;
 
 #define FLAG_RESPONSE (1 << 0)
@@ -791,6 +793,7 @@
 	int call_limit;			/*!< Limit of concurrent calls */
 	struct ast_ha *ha;		/*!< ACL setting */
 	struct ast_variable *chanvars;	/*!< Variables to set for channel created by user */
+	int framems;			/*!< Packetization */
 	int maxcallbitrate;		/*!< Maximum Bitrate for a video call */
 };
 
@@ -849,6 +852,7 @@
 	struct ast_variable *chanvars;	/*!<  Variables to set for channel created by user */
 	struct sip_pvt *mwipvt;		/*!<  Subscription for MWI */
 	int lastmsg;
+	int framems;                /* Packetization */
 };
 
 
@@ -1964,6 +1968,12 @@
 			ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(&r->flags[0], SIP_NAT) & SIP_NAT_ROUTE));
 		ast_rtp_setnat(r->vrtp, (ast_test_flag(&r->flags[0], SIP_NAT) & SIP_NAT_ROUTE));
 	}
+	r->framems = peer->framems;
+	/* Set Frame packetization, use default if it doesn't exist. */
+	if (r->rtp && r->framems) {
+		ast_rtp_set_framems(r->rtp, r->framems);
+	}
+
 	ast_string_field_set(r, peername, peer->username);
 	ast_string_field_set(r, authname, peer->username);
 	ast_string_field_set(r, username, peer->username);
@@ -6612,6 +6622,12 @@
 			ASTOBJ_UNREF(peer, sip_destroy_peer);
 	}
 	if (peer) {
+		p->framems = peer->framems;
+		/* Set Frame packetization, use default if it doesn't exist. */
+		if (p->rtp && p->framems) {
+			ast_rtp_set_framems(p->rtp, p->framems);
+		}
+
 		if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) {
 			ast_log(LOG_ERROR, "Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->name);
 		} else {
@@ -7260,6 +7276,12 @@
 			}
 		}
 		p->prefs = user->prefs;
+		p->framems = user->framems;
+		/* Set Frame packetization, use default if it doesn't exist. */
+		if (p->rtp && p->framems) {
+			ast_rtp_set_framems(p->rtp, p->framems);
+		}
+
 		/* replace callerid if rpid found, and not restricted */
 		if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) {
 			char *tmp;
@@ -7363,6 +7385,12 @@
 			peer = find_peer(NULL, &p->recv, 1);
 
 		if (peer) {
+			p->framems = peer->framems;
+			/* Set Frame packetization, use default if it doesn't exist. */
+			if (p->rtp && p->framems) {
+				ast_rtp_set_framems(p->rtp, p->framems);
+			}
+
 			if (debug)
 				ast_verbose("Found peer '%s'\n", peer->name);
 
@@ -8279,6 +8307,7 @@
 		ast_cli(fd, "%s\n",status);
  		ast_cli(fd, "  Useragent    : %s\n", peer->useragent);
  		ast_cli(fd, "  Reg. Contact : %s\n", peer->fullcontact);
+ 		ast_cli(fd, "  Packetization: %d\n", peer->framems);
 		if (peer->chanvars) {
  			ast_cli(fd, "  Variables    :\n");
 			for (v = peer->chanvars ; v ; v = v->next)
@@ -12251,6 +12280,7 @@
 	if (!(user = ast_calloc(1, sizeof(*user))))
 		return NULL;
 		
+	user->framems = global_framems;
 	suserobjs++;
 	ASTOBJ_INIT(user);
 	ast_copy_string(user->name, name, sizeof(user->name));
@@ -12316,6 +12346,8 @@
 			ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 1);
 		} else if (!strcasecmp(v->name, "disallow")) {
 			ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 0);
+		} else if (!strcasecmp(v->name, "packetization")) {
+			user->framems = atoi(v->value);
 		} else if (!strcasecmp(v->name, "callingpres")) {
 			user->callingpres = ast_parse_caller_presentation(v->value);
 			if (user->callingpres == -1)
@@ -12354,6 +12386,7 @@
 	peer->addr.sin_family = AF_INET;
 	peer->defaddr.sin_family = AF_INET;
 	peer->capability = global_capability;
+	peer->framems = global_framems;
 	peer->maxcallbitrate = default_maxcallbitrate;
 	peer->rtptimeout = global_rtptimeout;
 	peer->rtpholdtimeout = global_rtpholdtimeout;
@@ -12425,6 +12458,8 @@
 		if (!(peer = ast_calloc(1, sizeof(*peer))))
 			return NULL;
 
+		peer->framems = global_framems;
+		
 		if (realtime)
 			rpeerobjs++;
 		else
@@ -12476,6 +12511,8 @@
 			ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE);
 		} else if (!strcasecmp(v->name, "fromuser")) {
 			ast_copy_string(peer->fromuser, v->value, sizeof(peer->fromuser));
+		} else if (!strcasecmp(v->name, "packetization")) {
+			peer->framems = atoi(v->value);
 		} else if (!strcasecmp(v->name, "host") || !strcasecmp(v->name, "outboundproxy")) {
 			if (!strcasecmp(v->value, "dynamic")) {
 				if (!strcasecmp(v->name, "outboundproxy") || obproxyfound) {
@@ -12746,6 +12783,8 @@
 		} else if (!strcasecmp(v->name, "useragent")) {
 			ast_copy_string(global_useragent, v->value, sizeof(global_useragent));
 			ast_log(LOG_DEBUG, "Setting SIP channel User-Agent Name to %s\n", global_useragent);
+		} else if (!strcasecmp(v->name, "packetization")) {
+			global_framems = atoi(v->value);
 		} else if (!strcasecmp(v->name, "rtcachefriends")) {
 			ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS);	
 		} else if (!strcasecmp(v->name, "rtupdate")) {

Modified: team/group/5162_rtp_packetization/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/team/group/5162_rtp_packetization/configs/sip.conf.sample?rev=16614&r1=16613&r2=16614&view=diff
==============================================================================
--- team/group/5162_rtp_packetization/configs/sip.conf.sample (original)
+++ team/group/5162_rtp_packetization/configs/sip.conf.sample Thu Mar 30 18:22:12 2006
@@ -111,6 +111,7 @@
 ;compactheaders = yes		; send compact sip headers.
 ;sipdebug = yes			; Turn on SIP debugging by default, from
 				; the moment the channel loads this configuration
+;packetization = 20		; The global size in ms of the rtp packets
 ;subscribecontext = default	; Set a specific context for SUBSCRIBE requests
 				; Useful to limit subscriptions to local extensions
 				; Settable per peer/user also
@@ -451,7 +452,7 @@
 ;disallow=all
 ;allow=ulaw                     ; dtmfmode=inband only works with ulaw or alaw!
 ;progressinband=no		; Polycom phones don't work properly with "never"
-
+;packetization = 20		; the size in ms of the rtp packets
 
 ;[pingtel]
 ;type=friend

Modified: team/group/5162_rtp_packetization/frame.c
URL: http://svn.digium.com/view/asterisk/team/group/5162_rtp_packetization/frame.c?rev=16614&r1=16613&r2=16614&view=diff
==============================================================================
--- team/group/5162_rtp_packetization/frame.c (original)
+++ team/group/5162_rtp_packetization/frame.c Thu Mar 30 18:22:12 2006
@@ -135,6 +135,11 @@
 void ast_smoother_set_flags(struct ast_smoother *s, int flags)
 {
 	s->flags = flags;
+}
+
+int ast_smoother_test_flag(struct ast_smoother *s, int flag)
+{
+	return (s->flags & flag);
 }
 
 int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap)

Modified: team/group/5162_rtp_packetization/include/asterisk/frame.h
URL: http://svn.digium.com/view/asterisk/team/group/5162_rtp_packetization/include/asterisk/frame.h?rev=16614&r1=16613&r2=16614&view=diff
==============================================================================
--- team/group/5162_rtp_packetization/include/asterisk/frame.h (original)
+++ team/group/5162_rtp_packetization/include/asterisk/frame.h Thu Mar 30 18:22:12 2006
@@ -275,6 +275,7 @@
 #define AST_CONTROL_VIDUPDATE		18
 
 #define AST_SMOOTHER_FLAG_G729		(1 << 0)
+#define AST_SMOOTHER_FLAG_BE		(1 << 1)
 
 /* Option identifiers and flags */
 #define AST_OPTION_FLAG_REQUEST		0
@@ -434,6 +435,7 @@
 extern struct ast_format_list *ast_get_format_list(size_t *size);
 extern struct ast_smoother *ast_smoother_new(int bytes);
 extern void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);
+extern int ast_smoother_test_flag(struct ast_smoother *s, int flag);
 extern int ast_smoother_get_flags(struct ast_smoother *smoother);
 extern void ast_smoother_free(struct ast_smoother *s);
 extern void ast_smoother_reset(struct ast_smoother *s, int bytes);

Modified: team/group/5162_rtp_packetization/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/team/group/5162_rtp_packetization/include/asterisk/rtp.h?rev=16614&r1=16613&r2=16614&view=diff
==============================================================================
--- team/group/5162_rtp_packetization/include/asterisk/rtp.h (original)
+++ team/group/5162_rtp_packetization/include/asterisk/rtp.h Thu Mar 30 18:22:12 2006
@@ -162,6 +162,8 @@
 
 int ast_rtp_reload(void);
 
+int ast_rtp_set_framems(struct ast_rtp *rtp, int ms);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/group/5162_rtp_packetization/rtp.c
URL: http://svn.digium.com/view/asterisk/team/group/5162_rtp_packetization/rtp.c?rev=16614&r1=16613&r2=16614&view=diff
==============================================================================
--- team/group/5162_rtp_packetization/rtp.c (original)
+++ team/group/5162_rtp_packetization/rtp.c Thu Mar 30 18:22:12 2006
@@ -106,6 +106,8 @@
 	unsigned int dtmfduration;
 	int nat;
 	unsigned int flags;
+	int framems;
+	int rtplen;
 	struct sockaddr_in us;		/*!< Socket representation of the local endpoint. */
 	struct sockaddr_in them;	/*!< Socket representation of the remote endpoint. */
 	struct timeval rxcore;
@@ -145,6 +147,50 @@
 /*! \brief List of current sessions */
 static AST_LIST_HEAD_STATIC(protos, ast_rtp_protocol);
 
+struct rtp_codec_table {
+	int format;
+	int len;
+	int defaultms;
+	int increment;
+	unsigned int flags;
+};
+
+struct rtp_codec_table RTP_CODEC_TABLE[] = {
+	{AST_FORMAT_SLINEAR, 160, 20, 10, AST_SMOOTHER_FLAG_BE},
+	{AST_FORMAT_ULAW, 80, 20, 10},
+	{AST_FORMAT_G726, 40, 20, 10},
+	{AST_FORMAT_ILBC, 50, 30, 30},
+	{AST_FORMAT_G729A, 10, 20, 10, AST_SMOOTHER_FLAG_G729},
+	{AST_FORMAT_GSM, 33, 20, 20},
+	{0,0,0,0,0}
+};
+
+static struct rtp_codec_table *lookup_rtp_smoother_codec(int format, int *ms, int *len)
+{
+	int x;
+	int res;
+	struct rtp_codec_table *ent = NULL;
+
+	*len = 0;
+	for(x = 0 ; RTP_CODEC_TABLE[x].format ; x++) {
+		if (RTP_CODEC_TABLE[x].format == format) {
+			ent = &RTP_CODEC_TABLE[x];
+			if (! *ms) {
+				*ms = ent->defaultms;
+			}
+			while((res = (*ms % ent->increment))) {
+				(*ms)++;
+			}
+			while((*len = (*ms / ent->increment) * ent->len) > RTP_MTU) {
+				*ms -= ent->increment;
+			}
+			break;
+		}
+	}
+
+	return ent;
+}
+
 int ast_rtp_fd(struct ast_rtp *rtp)
 {
 	return rtp->s;
@@ -170,6 +216,20 @@
 void ast_rtp_setnat(struct ast_rtp *rtp, int nat)
 {
 	rtp->nat = nat;
+}
+
+int ast_rtp_set_framems(struct ast_rtp *rtp, int ms) 
+{
+	if (ms) {
+		if (rtp->smoother) {
+            ast_smoother_free(rtp->smoother);
+			rtp->smoother = NULL;
+		}
+
+		rtp->framems = ms;
+	}
+
+	return rtp->framems;
 }
 
 static struct ast_frame *send_dtmf(struct ast_rtp *rtp)
@@ -1426,99 +1486,43 @@
 		rtp->smoother = NULL;
 	}
 
-
-	switch(subclass) {
-	case AST_FORMAT_SLINEAR:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(320);
-		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create smoother :(\n");
-			return -1;
-		}
-		ast_smoother_feed_be(rtp->smoother, _f);
-		
-		while((f = ast_smoother_read(rtp->smoother)))
+	
+	if (!rtp->smoother) {
+		struct rtp_codec_table *ent;
+		int ms = rtp->framems;
+		int len;
+
+		if ((ent = lookup_rtp_smoother_codec(subclass, &rtp->framems, &len))) {
+			
+			if (rtp->framems != ms) {
+				ast_log(LOG_DEBUG, "Had to change frame MS from %d to %d\n", ms, rtp->framems);
+			}
+
+			if (!(rtp->smoother = ast_smoother_new(len))) {
+				ast_log(LOG_WARNING, "Unable to create smoother ms: %d len: %d:(\n", rtp->framems, len);
+				return -1;
+			}
+
+			if (ent->flags) {
+				ast_smoother_set_flags(rtp->smoother, ent->flags);			
+			}
+
+			ast_log(LOG_DEBUG, "Able to create smoother :) ms: %d len %d\n", rtp->framems, len);
+		}
+	}
+
+	if (rtp->smoother) {
+		if (ast_smoother_test_flag(rtp->smoother, AST_SMOOTHER_FLAG_BE)) {
+			ast_smoother_feed_be(rtp->smoother, _f);
+		} else {
+			ast_smoother_feed(rtp->smoother, _f);
+		}
+
+		while((f = ast_smoother_read(rtp->smoother))) {
 			ast_rtp_raw_write(rtp, f, codec);
-		break;
-	case AST_FORMAT_ULAW:
-	case AST_FORMAT_ALAW:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(160);
-		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create smoother :(\n");
-			return -1;
-		}
-		ast_smoother_feed(rtp->smoother, _f);
-		
-		while((f = ast_smoother_read(rtp->smoother)))
-			ast_rtp_raw_write(rtp, f, codec);
-		break;
-	case AST_FORMAT_ADPCM:
-	case AST_FORMAT_G726:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(80);
-		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create smoother :(\n");
-			return -1;
-		}
-		ast_smoother_feed(rtp->smoother, _f);
-		
-		while((f = ast_smoother_read(rtp->smoother)))
-			ast_rtp_raw_write(rtp, f, codec);
-		break;
-	case AST_FORMAT_G729A:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(20);
-			if (rtp->smoother)
-				ast_smoother_set_flags(rtp->smoother, AST_SMOOTHER_FLAG_G729);
-		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create g729 smoother :(\n");
-			return -1;
-		}
-		ast_smoother_feed(rtp->smoother, _f);
-		
-		while((f = ast_smoother_read(rtp->smoother)))
-			ast_rtp_raw_write(rtp, f, codec);
-		break;
-	case AST_FORMAT_GSM:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(33);
-		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create GSM smoother :(\n");
-			return -1;
-		}
-		ast_smoother_feed(rtp->smoother, _f);
-		while((f = ast_smoother_read(rtp->smoother)))
-			ast_rtp_raw_write(rtp, f, codec);
-		break;
-	case AST_FORMAT_ILBC:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(50);
-		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create ILBC smoother :(\n");
-			return -1;
-		}
-		ast_smoother_feed(rtp->smoother, _f);
-		while((f = ast_smoother_read(rtp->smoother)))
-			ast_rtp_raw_write(rtp, f, codec);
-		break;
-	default:	
-		ast_log(LOG_WARNING, "Not sure about sending format %s packets\n", ast_getformatname(subclass));
-		/* fall through to... */
-	case AST_FORMAT_H261:
-	case AST_FORMAT_H263:
-	case AST_FORMAT_H263_PLUS:
-	case AST_FORMAT_H264:
-	case AST_FORMAT_G723_1:
-	case AST_FORMAT_LPC10:
-	case AST_FORMAT_SPEEX:
-	        /* Don't buffer outgoing frames; send them one-per-packet: */
+		} 
+	} else {
+		/* Don't buffer outgoing frames; send them one-per-packet: */
 		if (_f->offset < hdrlen) {
 			f = ast_frdup(_f);
 		} else {



More information about the asterisk-commits mailing list