Index: channels/chan_sip.c
===================================================================
--- channels/chan_sip.c	(revision 39774)
+++ channels/chan_sip.c	(working copy)
@@ -539,6 +539,8 @@
 
 static struct ast_flags global_flags[2] = {{0}};	/*!< global SIP_ flags */
 
+static int global_autoframing = 0;
+
 /*! \brief Protect the SIP dialog list (of sip_pvt's) */
 AST_MUTEX_DEFINE_STATIC(iflock);
 
@@ -957,6 +959,7 @@
 	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
 	struct sip_pvt *next;			/*!< Next dialog in chain */
 	struct sip_invite_param *options;	/*!< Options for INVITE */
+	int autoframing;
 } *iflist = NULL;
 
 #define FLAG_RESPONSE (1 << 0)
@@ -1006,6 +1009,7 @@
 	struct ast_ha *ha;		/*!< ACL setting */
 	struct ast_variable *chanvars;	/*!< Variables to set for channel created by user */
 	int maxcallbitrate;		/*!< Maximum Bitrate for a video call */
+	int autoframing;
 };
 
 /*! \brief Structure for SIP peer data, we place calls to peers if registered  or fixed IP address (host) */
@@ -1068,6 +1072,7 @@
 	struct ast_variable *chanvars;	/*!<  Variables to set for channel created by user */
 	struct sip_pvt *mwipvt;		/*!<  Subscription for MWI */
 	int lastmsg;
+	int autoframing;
 };
 
 
@@ -2524,6 +2529,11 @@
 			ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", natflags ? "On" : "Off");
 		ast_udptl_setnat(r->udptl, natflags);
 	}
+	/* Set Frame packetization */
+	if (r->rtp) {
+		ast_rtp_codec_setpref(r->rtp, &r->prefs);
+		r->autoframing = peer->autoframing;
+	}
 	ast_string_field_set(r, peername, peer->username);
 	ast_string_field_set(r, authname, peer->username);
 	ast_string_field_set(r, username, peer->username);
@@ -4650,6 +4660,8 @@
 	 */
 	/* XXX This needs to be done per media stream, since it's media stream specific */
 	iterator = req->sdp_start;
+	int found_rtpmap_codecs[32];
+	int last_rtpmap_codec=0;
 	while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') {
 		char* mimeSubtype = ast_strdupa(a); /* ensures we have enough space */
 		if (option_debug > 1) {
@@ -4700,17 +4712,49 @@
 		}  else if (!strcasecmp(a, "sendrecv")) {
 			sendonly = 0;
 			continue;
-		} else if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) 
+		} else if (strlen(a) > 5 && !strncasecmp(a, "ptime", 5)) {
+			char *tmp = strrchr(a, ':');
+			int framing = 0;
+			if (tmp) {
+			    tmp++;
+			    framing = strtol(tmp, NULL, 10);
+			    if (framing == LONG_MIN || framing == LONG_MAX) {
+				    framing = 0;
+				    ast_log(LOG_DEBUG, "Can't read framing from SDP: %s\n", a);
+			    }
+			}
+			if (framing && found_rtpmap_codecs[last_rtpmap_codec]) {
+				if (p->autoframing || global_autoframing) {
+					struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
+					int codec_n;
+					int format = 0;
+					for (codec_n = 0; codec_n < last_rtpmap_codec; codec_n++) {
+						format = ast_rtp_codec_getformat(found_rtpmap_codecs[codec_n]);
+						if (!format)	/* non-codec or not found */
+							continue;
+						if (option_debug)
+							ast_log(LOG_DEBUG, "Setting framing for %d to %d\n", format, framing);
+						ast_codec_pref_setsize(pref, format, framing);
+					}
+					ast_rtp_codec_setpref(p->rtp, pref);
+				}
+			}
+			memset(&found_rtpmap_codecs, 0, sizeof(found_rtpmap_codecs));
+			last_rtpmap_codec = 0;
 			continue;
-		/* We have a rtpmap to handle */
-		if (debug)
-			ast_verbose("Found description format %s for ID %d\n", mimeSubtype, codec);
+		} else if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) == 2) {
+			/* We have a rtpmap to handle */
+			if (debug)
+				ast_verbose("Found description format %s for ID %d\n", mimeSubtype, codec);
+			found_rtpmap_codecs[last_rtpmap_codec] = codec;
+			last_rtpmap_codec++;
 
-		/* Note: should really look at the 'freq' and '#chans' params too */
-		ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype,
+			/* Note: should really look at the 'freq' and '#chans' params too */
+			ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype,
 					ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0);
-		if (p->vrtp)
-			ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype, 0);
+			if (p->vrtp)
+				ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype, 0);
+		}
 	}
 	
 	if (udptlportno != -1) {
@@ -5557,12 +5601,18 @@
 			     int debug)
 {
 	int rtp_code;
+	struct ast_format_list fmt;
 
+
 	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)
 		return;
 
+	if (p->rtp) {
+		struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
+		fmt = ast_codec_pref_getsize(pref, codec);
+	}
 	ast_build_string(m_buf, m_size, " %d", rtp_code);
 	ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
 			 ast_rtp_lookup_mime_subtype(1, codec,
@@ -5572,10 +5622,13 @@
 		/* Indicate that we don't support VAD (G.729 annex B) */
 		ast_build_string(a_buf, a_size, "a=fmtp:%d annexb=no\r\n", rtp_code);
 	} else if (codec == AST_FORMAT_ILBC) {
-		/* Add information about us using only 20 ms packetization */
-		ast_build_string(a_buf, a_size, "a=fmtp:%d mode=20\r\n", rtp_code);
-	
+		/* Add information about us using only 20/30 ms packetization */
+		ast_build_string(a_buf, a_size, "a=fmtp:%d mode=%d\r\n", rtp_code, fmt.cur_ms);
 	}
+
+	if (codec != AST_FORMAT_ILBC) {
+		ast_build_string(a_buf, a_size, "a=ptime:%d\r\n", fmt.cur_ms);
+	}
 }
 
 /*! \brief Get Max T.38 Transmission rate from T38 capabilities */
@@ -6050,6 +6103,11 @@
 	}
 	respprep(&resp, p, msg, req);
 	if (p->rtp) {
+		if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
+			if (option_debug)
+				ast_log(LOG_DEBUG, "Setting framing from config on incoming call\n");
+			ast_rtp_codec_setpref(p->rtp, &p->prefs);
+		}
 		try_suggested_sip_codec(p);	
 		add_sdp(&resp, p);
 	} else {
@@ -7899,6 +7957,11 @@
 			ASTOBJ_UNREF(peer, sip_destroy_peer);
 	}
 	if (peer) {
+		/* Set Frame packetization */
+		if (p->rtp) {
+			ast_rtp_codec_setpref(p->rtp, &peer->prefs);
+			p->autoframing = peer->autoframing;
+		}
 		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 {
@@ -8632,6 +8695,11 @@
 			}
 		}
 		p->prefs = user->prefs;
+		/* Set Frame packetization */
+		if (p->rtp) {
+			ast_rtp_codec_setpref(p->rtp, &p->prefs);
+			p->autoframing = user->autoframing;
+		}
 		/* replace callerid if rpid found, and not restricted */
 		if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) {
 			char *tmp;
@@ -8740,6 +8808,11 @@
 			peer = find_peer(NULL, &p->recv, 1);
 
 		if (peer) {
+			/* Set Frame packetization */
+			if (p->rtp) {
+				ast_rtp_codec_setpref(p->rtp, &peer->prefs);
+				p->autoframing = peer->autoframing;
+			}
 			if (debug)
 				ast_verbose("Found peer '%s'\n", peer->name);
 
@@ -9497,6 +9570,7 @@
 		if (!codec)
 			break;
 		ast_cli(fd, "%s", ast_getformatname(codec));
+		ast_cli(fd, ":%d", pref->framing[x]);
 		if (x < 31 && ast_codec_pref_index(pref, x + 1))
 			ast_cli(fd, ",");
 	}
@@ -9686,7 +9760,6 @@
 		ast_cli(fd, "%s\n", codec_buf);
 		ast_cli(fd, "  Codec Order  : (");
 		print_codec_to_cli(fd, &peer->prefs);
-
 		ast_cli(fd, ")\n");
 
 		ast_cli(fd, "  Status       : ");
@@ -9789,9 +9862,8 @@
 {
 	char cbuf[256];
 	struct sip_user *user;
-	struct ast_codec_pref *pref;
 	struct ast_variable *v;
-	int x = 0, codec = 0, load_realtime;
+	int load_realtime;
 
 	if (argc < 4)
 		return RESULT_SHOWUSAGE;
@@ -9821,18 +9893,7 @@
 		ast_cli(fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>"));
 		ast_cli(fd, "  ACL          : %s\n", (user->ha?"Yes":"No"));
 		ast_cli(fd, "  Codec Order  : (");
-		pref = &user->prefs;
-		for(x = 0; x < 32 ; x++) {
-			codec = ast_codec_pref_index(pref,x);
-			if (!codec)
-				break;
-			ast_cli(fd, "%s", ast_getformatname(codec));
-			if (x < 31 && ast_codec_pref_index(pref,x+1))
-				ast_cli(fd, "|");
-		}
-
-		if (!x)
-			ast_cli(fd, "none");
+		print_codec_to_cli(fd, &user->prefs);
 		ast_cli(fd, ")\n");
 
 		if (user->chanvars) {
@@ -15091,6 +15152,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, "autoframing")) {
+			user->autoframing = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "callingpres")) {
 			user->callingpres = ast_parse_caller_presentation(v->value);
 			if (user->callingpres == -1)
@@ -15362,6 +15425,8 @@
 			ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 1);
 		} else if (!strcasecmp(v->name, "disallow")) {
 			ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 0);
+		} else if (!strcasecmp(v->name, "autoframing")) {
+			peer->autoframing = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "rtptimeout")) {
 			if ((sscanf(v->value, "%d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) {
 				ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d.  Using default.\n", v->value, v->lineno);
@@ -15723,6 +15788,8 @@
 			ast_parse_allow_disallow(&default_prefs, &global_capability, v->value, 1);
 		} else if (!strcasecmp(v->name, "disallow")) {
 			ast_parse_allow_disallow(&default_prefs, &global_capability, v->value, 0);
+		} else if (!strcasecmp(v->name, "autoframing")) {
+			global_autoframing = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "allowexternaldomains")) {
 			allow_external_domains = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "autodomain")) {
Index: include/asterisk/rtp.h
===================================================================
--- include/asterisk/rtp.h	(revision 39774)
+++ include/asterisk/rtp.h	(working copy)
@@ -192,6 +192,12 @@
 
 int ast_rtp_reload(void);
 
+int ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs);
+
+struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp);
+
+int ast_rtp_codec_getformat(int pt);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
Index: include/asterisk/frame.h
===================================================================
--- include/asterisk/frame.h	(revision 39774)
+++ include/asterisk/frame.h	(working copy)
@@ -35,6 +35,7 @@
 
 struct ast_codec_pref {
 	char order[32];
+	char framing[32];
 };
 
 /*! \page Def_Frame AST Multimedia and signalling frames
@@ -272,6 +273,7 @@
 };
 
 #define AST_SMOOTHER_FLAG_G729		(1 << 0)
+#define AST_SMOOTHER_FLAG_BE		(1 << 1)
 
 /* Option identifiers and flags */
 #define AST_OPTION_FLAG_REQUEST		0
@@ -337,6 +339,23 @@
 		u_int8_t data[0];
 };
 
+
+/*! \brief Definition of supported media formats (codecs) */
+struct ast_format_list {
+	int visible;    /*!< Can we see this entry */
+	int bits;       /*!< bitmask value */
+	char *name;     /*!< short name */
+	char *desc;     /*!< Description */
+	int fr_len;	/*!< Single frame length in bytes */
+	int min_ms;	/*!< Min value */
+	int max_ms;	/*!< Max value */
+	int inc_ms;	/*!< Increment */
+	int def_ms;	/*!< Default value */
+	unsigned int flags;	/*!< Smoother flags */
+	int cur_ms;	/*!< Current value */
+};
+
+
 /*! \brief  Requests a frame to be allocated 
  * 
  * \param source 
@@ -443,6 +462,7 @@
 struct ast_smoother *ast_smoother_new(int bytes);
 void ast_smoother_set_flags(struct ast_smoother *smoother, int flags);
 int ast_smoother_get_flags(struct ast_smoother *smoother);
+int ast_smoother_test_flag(struct ast_smoother *s, int flag);
 void ast_smoother_free(struct ast_smoother *s);
 void ast_smoother_reset(struct ast_smoother *s, int bytes);
 int __ast_smoother_feed(struct ast_smoother *s, struct ast_frame *f, int swap);
@@ -489,6 +509,14 @@
    the format list is selected, otherwise 0 is returned. */
 int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best);
 
+/*! \brief Set packet size for codec
+*/
+int ast_codec_pref_setsize(struct ast_codec_pref *pref, int format, int framems);
+
+/*! \brief Get packet size for codec
+*/
+struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, int format);
+
 /*! \brief Parse an "allow" or "deny" line in a channel or device configuration 
         and update the capabilities mask and pref if provided.
 	Video codecs are not added to codec preference lists, since we can not transcode
Index: rtp.c
===================================================================
--- rtp.c	(revision 39774)
+++ rtp.c	(working copy)
@@ -155,6 +155,7 @@
 	int rtp_lookup_code_cache_code;
 	int rtp_lookup_code_cache_result;
 	struct ast_rtcp *rtcp;
+	struct ast_codec_pref pref;
 };
 
 /* Forward declarations */
@@ -2305,6 +2306,35 @@
 	return 0;
 }
 
+int ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs)
+{
+	int x;
+	for (x = 0; x < 32; x++) {   /* Ugly way */
+		rtp->pref.order[x] = prefs->order[x];
+		rtp->pref.framing[x] = prefs->framing[x];
+	}
+	if (rtp->smoother)
+		ast_smoother_free(rtp->smoother);
+	rtp->smoother = NULL;
+	return 0;
+}
+
+struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp)
+{
+	return &rtp->pref;
+}
+
+int ast_rtp_codec_getformat(int pt)
+{
+	if (pt < 0 || pt > MAX_RTP_PT)
+		return 0; /* bogus payload type */
+
+	if (static_RTP_PT[pt].isAstFormat)
+		return static_RTP_PT[pt].code;
+	else
+		return 0;
+}
+
 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
 {
 	struct ast_frame *f;
@@ -2347,99 +2377,29 @@
 		rtp->smoother = NULL;
 	}
 
-
-	switch(subclass) {
-	case AST_FORMAT_SLINEAR:
-		if (!rtp->smoother) {
-			rtp->smoother = ast_smoother_new(320);
+	if (!rtp->smoother) {
+		struct ast_format_list fmt = ast_codec_pref_getsize(&rtp->pref, subclass);
+		if (fmt.inc_ms) { /* if codec parameters is set / avoid division by zero */
+			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));
+				return -1;
+			}
+			if (fmt.flags)
+				ast_smoother_set_flags(rtp->smoother, fmt.flags);
+			if (option_debug)
+				ast_log(LOG_DEBUG, "Created smoother: format: %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms));
 		}
-		if (!rtp->smoother) {
-			ast_log(LOG_WARNING, "Unable to create smoother :(\n");
-			return -1;
+	}
+	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);
 		}
-		ast_smoother_feed_be(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:
-	case AST_FORMAT_G726_AAL2:
-		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:
+	} else {
 	        /* Don't buffer outgoing frames; send them one-per-packet: */
 		if (_f->offset < hdrlen) {
 			f = ast_frdup(_f);
Index: frame.c
===================================================================
--- frame.c	(revision 39774)
+++ frame.c	(working copy)
@@ -75,23 +75,18 @@
 };
 
 /*! \brief Definition of supported media formats (codecs) */
-static struct ast_format_list {
-	int visible;	/*!< Can we see this entry */
-	int bits;	/*!< bitmask value */
-	char *name;	/*!< short name */
-	char *desc;	/*!< Description */
-} AST_FORMAT_LIST[] = {					/*!< Bit number: comment  - Bit numbers are hard coded in show_codec() */
-	{ 1, AST_FORMAT_G723_1 , "g723" , "G.723.1"},	/*!<  1 */
-	{ 1, AST_FORMAT_GSM, "gsm" , "GSM"},		/*!<  2: codec_gsm.c */
-	{ 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law" },	/*!<  3: codec_ulaw.c */
-	{ 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law" },	/*!<  4: codec_alaw.c */
-	{ 1, AST_FORMAT_G726, "g726", "G.726 RFC3551" },/*!<  5: codec_g726.c */
-	{ 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM"},	/*!<  6: codec_adpcm.c */
-	{ 1, AST_FORMAT_SLINEAR, "slin",  "16 bit Signed Linear PCM"},	/*!< 7 */
-	{ 1, AST_FORMAT_LPC10, "lpc10", "LPC10" },	/*!<  8: codec_lpc10.c */
-	{ 1, AST_FORMAT_G729A, "g729", "G.729A" },	/*!<  9: Binary commercial distribution */
+static struct ast_format_list AST_FORMAT_LIST[] = {					/*!< Bit number: comment  - Bit numbers are hard coded in show_codec() */
+	{ 1, AST_FORMAT_G723_1 , "g723" , "G.723.1", 24, 30, 300, 30, 30 },	/*!<  1 */
+	{ 1, AST_FORMAT_GSM, "gsm" , "GSM", 33, 10, 70, 10, 10 },		/*!<  2: codec_gsm.c */
+	{ 1, AST_FORMAT_ULAW, "ulaw", "G.711 u-law", 80, 10, 30, 10, 20 },	/*!<  3: codec_ulaw.c */
+	{ 1, AST_FORMAT_ALAW, "alaw", "G.711 A-law", 80, 10, 30, 10, 20 },	/*!<  4: codec_alaw.c */
+	{ 1, AST_FORMAT_G726, "g726", "G.726 RFC3551", 40, 10, 50, 10, 20 },/*!<  5: codec_g726.c */
+	{ 1, AST_FORMAT_ADPCM, "adpcm" , "ADPCM" },	/*!<  6: codec_adpcm.c */
+	{ 1, AST_FORMAT_SLINEAR, "slin",  "16 bit Signed Linear PCM", 160, 10, 70, 10, 20, AST_SMOOTHER_FLAG_BE },	/*!< 7 */
+	{ 1, AST_FORMAT_LPC10, "lpc10", "LPC10" },	/*!<  8: codec_lpc10.c */ 
+	{ 1, AST_FORMAT_G729A, "g729", "G.729A", 10, 10, 230, 10, 20, AST_SMOOTHER_FLAG_G729 },	/*!<  9: Binary commercial distribution */
 	{ 1, AST_FORMAT_SPEEX, "speex", "SpeeX" },	/*!< 10: codec_speex.c */
-	{ 1, AST_FORMAT_ILBC, "ilbc", "iLBC"},		/*!< 11: codec_ilbc.c */
+	{ 1, AST_FORMAT_ILBC, "ilbc", "iLBC", 50, 30, 30, 30, 30 },		/*!< 11: codec_ilbc.c */ /* inc=30ms - workaround */
 	{ 1, AST_FORMAT_G726_AAL2, "g726aal2", "G.726 AAL2" },	/*!<  12: codec_g726.c */
 	{ 0, 0, "nothing", "undefined" },
 	{ 0, 0, "nothing", "undefined" },
@@ -138,6 +133,11 @@
 	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)
 {
 	if (f->frametype != AST_FRAME_VOICE) {
@@ -971,6 +971,7 @@
 	struct ast_codec_pref oldorder;
 	int x, y = 0;
 	int slot;
+	int size;
 
 	if(!pref->order[0])
 		return;
@@ -980,10 +981,13 @@
 
 	for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
 		slot = oldorder.order[x];
+		size = oldorder.framing[x];
 		if(! slot)
 			break;
-		if(AST_FORMAT_LIST[slot-1].bits != format)
-			pref->order[y++] = slot;
+		if(AST_FORMAT_LIST[slot-1].bits != format) {
+			pref->order[y] = slot;
+			pref->framing[y++] = size;
+		}
 	}
 	
 }
@@ -1015,6 +1019,84 @@
 }
 
 
+/*! \brief Set packet size for codec */
+int ast_codec_pref_setsize(struct ast_codec_pref *pref, int format, int framems)
+{
+        int x, index = -1;
+
+        for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
+                if(AST_FORMAT_LIST[x].bits == format) {
+                        index = x;
+                        break;
+                }
+        }
+
+	if(index < 0)
+		return -1;
+
+	/* size validation */
+	if(!framems)
+		framems = AST_FORMAT_LIST[index].def_ms;
+
+	if(AST_FORMAT_LIST[index].inc_ms && framems % AST_FORMAT_LIST[index].inc_ms) /* avoid division by zero */
+		framems -= framems % AST_FORMAT_LIST[index].inc_ms;
+
+	if(framems < AST_FORMAT_LIST[index].min_ms)
+		framems = AST_FORMAT_LIST[index].min_ms;
+
+	if(framems > AST_FORMAT_LIST[index].max_ms)
+		framems = AST_FORMAT_LIST[index].max_ms;
+
+
+        for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
+                if(pref->order[x] == (index + 1)) {
+                        pref->framing[x] = framems;
+                        break;
+                }
+        }
+
+        return x;
+}
+
+/*! \brief Get packet size for codec */
+struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, int format)
+{
+        int x, index = -1, framems = 0;
+	struct ast_format_list fmt;
+
+        for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
+                if(AST_FORMAT_LIST[x].bits == format) {
+                        fmt = AST_FORMAT_LIST[x];
+			index = x;
+                        break;
+                }
+        }
+
+        for (x = 0; x < sizeof(AST_FORMAT_LIST) / sizeof(AST_FORMAT_LIST[0]); x++) {
+                if(pref->order[x] == (index + 1)) {
+                        framems = pref->framing[x];
+                        break;
+                }
+        }
+
+	/* size validation */
+	if(!framems)
+		framems = AST_FORMAT_LIST[index].def_ms;
+
+	if(AST_FORMAT_LIST[index].inc_ms && framems % AST_FORMAT_LIST[index].inc_ms) /* avoid division by zero */
+		framems -= framems % AST_FORMAT_LIST[index].inc_ms;
+
+	if(framems < AST_FORMAT_LIST[index].min_ms)
+		framems = AST_FORMAT_LIST[index].min_ms;
+
+	if(framems > AST_FORMAT_LIST[index].max_ms)
+		framems = AST_FORMAT_LIST[index].max_ms;
+
+	fmt.cur_ms = framems;
+
+	return fmt;
+}
+
 /*! \brief Pick a codec */
 int ast_codec_choose(struct ast_codec_pref *pref, int formats, int find_best)
 {
@@ -1044,9 +1126,22 @@
 	char *parse;
 	char *this;
 	int format;
+	char *psize;
+	int framems;
 
 	parse = ast_strdupa(list);
 	while ((this = strsep(&parse, ","))) {
+		framems = 0;
+                if ((psize = strrchr(this, ':'))) {
+                        *psize = '\0';
+                        psize++;
+			if (option_debug)
+				ast_log(LOG_DEBUG,"Packetization for codec: %s is %s\n", this, psize);
+                        framems = strtol(psize,NULL,10);
+                        if (framems == LONG_MIN || framems == LONG_MAX) {
+                                framems = 0;
+                        }
+                }
 		if (!(format = ast_getformatbyname(this))) {
 			ast_log(LOG_WARNING, "Cannot %s unknown format '%s'\n", allowing ? "allow" : "disallow", this);
 			continue;
@@ -1064,8 +1159,10 @@
 		 */
 		if (pref && (format & AST_FORMAT_AUDIO_MASK)) {
 			if (strcasecmp(this, "all")) {
-				if (allowing)
+				if (allowing) {
 					ast_codec_pref_append(pref, format);
+					ast_codec_pref_setsize(pref, format, framems);
+				}
 				else
 					ast_codec_pref_remove(pref, format);
 			} else if (!allowing) {
