[asterisk-commits] file: branch file/rtp_engine r131167 - /team/file/rtp_engine/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 15 19:54:11 CDT 2008


Author: file
Date: Tue Jul 15 19:54:11 2008
New Revision: 131167

URL: http://svn.digium.com/view/asterisk?view=rev&rev=131167
Log:
Add RTCP stats back into chan_sip.

Modified:
    team/file/rtp_engine/channels/chan_sip.c

Modified: team/file/rtp_engine/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/channels/chan_sip.c?view=diff&rev=131167&r1=131166&r2=131167
==============================================================================
--- team/file/rtp_engine/channels/chan_sip.c (original)
+++ team/file/rtp_engine/channels/chan_sip.c Tue Jul 15 19:54:11 2008
@@ -726,6 +726,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 */
 
@@ -1276,6 +1277,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 */
 	);
 	struct sip_socket socket;		/*!< The socket used for this dialog */
 	unsigned int ocseq;			/*!< Current outgoing seqno */
@@ -1503,6 +1505,7 @@
 	char mohinterpret[MAX_MUSICCLASS];/*!<  Music on Hold class */
 	char mohsuggest[MAX_MUSICCLASS];/*!<  Music on Hold class */
 	char parkinglot[AST_MAX_CONTEXT];/*!<  Parkinglot */
+	char engine[256];               /*!< RTP Engine to use */
 	char useragent[256];		/*!<  User agent in SIP request (saved from registration) */
 	struct ast_codec_pref prefs;	/*!<  codec prefs */
 	int lastmsgssent;
@@ -2167,6 +2170,9 @@
 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);
+
 /*! \brief Definition of this channel for PBX channel registration */
 static const struct ast_channel_tech sip_tech = {
 	.type = "SIP",
@@ -4183,6 +4189,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);
 	dialog->outboundproxy = obproxy_get(dialog, peer);
 	dialog->callgroup = peer->callgroup;
 	dialog->pickupgroup = peer->pickupgroup;
@@ -4859,7 +4866,7 @@
 	struct sip_pvt *p = ast->tech_pvt;
 	int needcancel = FALSE;
 	int needdestroy = 0;
-//	struct ast_channel *oldowner = ast;
+	struct ast_channel *oldowner = ast;
 
 	if (!p) {
 		ast_debug(1, "Asked to hangup channel that was not connected\n");
@@ -4983,7 +4990,59 @@
 			}
 
 			if (!p->pendinginvite) {
-//				struct ast_channel *bridge = ast_bridged_channel(oldowner);
+				char quality_buf[AST_MAX_USER_FIELD], *quality;
+
+				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) {
+						struct ast_channel *bridge = ast_bridged_channel(oldowner);
+
+						pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", quality);
+
+						if (bridge) {
+							pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
+						}
+
+						if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
+							pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOSJITTER", quality);
+							if (bridge) {
+								pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
+							}
+						}
+						if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
+                                                        pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOSLOSS", quality);
+                                                        if (bridge) {
+                                                                pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
+                                                        }
+                                                }
+						if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
+                                                        pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOSRTT", quality);
+                                                        if (bridge) {
+                                                                pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
+                                                        }
+                                                }
+					}
+				}
+				if (p->do_history || oldowner) {
+					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, "RTCPTEXTQOS", quality);
+						}
+					}
+				}
 
 				/* Send a hangup */
 				transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
@@ -5185,7 +5244,7 @@
 		   redirect of both channels). Note that a channel can not be masqueraded *into*
 		   a native bridge. So there is no danger that this breaks a native bridge that
 		   should stay up. */
-//		sip_set_rtp_peer(newchan, NULL, NULL, 0, 0, 0);
+		sip_set_rtp_peer(newchan, NULL, NULL, 0, 0, 0);
 		ret = 0;
 	}
 	ast_debug(3, "SIP Fixup: New owner for dialogue %s: %s (Old parent: %s)\n", p->callid, p->owner->name, oldchan->name);
@@ -6014,7 +6073,7 @@
 	}
 	ast_string_field_set(p, context, default_context);
 	ast_string_field_set(p, parkinglot, default_parkinglot);
-
+	ast_string_field_set(p, engine, default_engine);
 
 	/* Add to active dialog list */
 
@@ -11661,6 +11720,7 @@
 	ast_string_field_set(p, mohinterpret, peer->mohinterpret);
 	ast_string_field_set(p, mohsuggest, peer->mohsuggest);
 	ast_string_field_set(p, parkinglot, peer->parkinglot);
+	ast_string_field_set(p, engine, peer->engine);
 	if (peer->callingpres)	/* Peer calling pres setting will override RPID */
 		p->callingpres = peer->callingpres;
 	if (peer->maxms && peer->lastms)
@@ -13295,12 +13355,11 @@
 #define FORMAT2 "%-15.15s  %-11.11s  %-8.8s %-10.10s  %-10.10s (%-2.2s) %-6.6s %-10.10s  %-10.10s ( %%) %-6.6s\n"
 #define FORMAT  "%-15.15s  %-11.11s  %-8.8s %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u %-10.10u%-1.1s %-10.10u (%-2.2u%%) %-6.6u\n"
 	struct sip_pvt *cur = __cur;
-//	unsigned int rxcount;
-//	unsigned int txcount;
-//	char durbuf[10];
-	//       int duration;
-	//  int durh, durm, durs;
-	//struct ast_channel *c = cur->owner;
+	struct ast_rtp_instance_stats stats;
+	char durbuf[10];
+	int duration;
+	int durh, durm, durs;
+	struct ast_channel *c = cur->owner;
 	struct __show_chan_arg *arg = __arg;
 	int fd = arg->fd;
 
@@ -13314,9 +13373,7 @@
 		return 0;	/* don't care, we scan all channels */
 	}
 
-/*
-	rxcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXCOUNT);
-	txcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXCOUNT);
+	ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL);
 
 	if (c && c->cdr && !ast_tvzero(c->cdr->start)) {
 		duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
@@ -13332,19 +13389,19 @@
 		ast_inet_ntoa(cur->sa.sin_addr), 
 		cur->callid, 
 		durbuf,
-		rxcount > (unsigned int) 100000 ? (unsigned int) (rxcount)/(unsigned int) 1000 : rxcount,
-		rxcount > (unsigned int) 100000 ? "K":" ",
-		ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS),
-		rxcount > ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS) ? (unsigned int) (ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS) / rxcount * 100) : 0,
-		ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXJITTER),
-		txcount > (unsigned int) 100000 ? (unsigned int) (txcount)/(unsigned int) 1000 : txcount,
-		txcount > (unsigned int) 100000 ? "K":" ",
-		ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS),
-		txcount > ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS) ? (unsigned int) (ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS)/ txcount * 100) : 0,
-		ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXJITTER)
+		stats.rxcount > (unsigned int) 100000 ? (unsigned int) (stats.rxcount)/(unsigned int) 1000 : stats.rxcount,
+		stats.rxcount > (unsigned int) 100000 ? "K":" ",
+		stats.rxploss,
+		stats.rxcount > stats.rxploss ? (stats.rxploss / stats.rxcount * 100) : 0,
+		stats.rxjitter,
+		stats.txcount > (unsigned int) 100000 ? (unsigned int) (stats.txcount)/(unsigned int) 1000 : stats.txcount,
+		stats.txcount > (unsigned int) 100000 ? "K":" ",
+		stats.txploss,
+		stats.txcount > stats.txploss ? (stats.txploss / stats.txcount * 100) : 0,
+		stats.txjitter
 	);
 	arg->numchans++;
-*/
+
 	return 0;	/* don't care, we scan all channels */
 }
 
@@ -17824,7 +17881,7 @@
 static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen)
 {
 	struct sip_pvt *p = chan->tech_pvt;
-	char /**all = "",*/ *parse = ast_strdupa(preparse);
+	char *parse = ast_strdupa(preparse);
 	int res = 0;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(param);
@@ -17876,54 +17933,61 @@
 
 		snprintf(buf, buflen, "%s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
 	} else if (!strcasecmp(args.param, "rtpqos")) {
-/*
-		struct ast_rtp_quality qos;
-		struct ast_rtp *rtp = p->rtp;
-		
-		memset(&qos, 0, sizeof(qos));
-
-		if (ast_strlen_zero(args.type))
+		struct ast_rtp_instance *rtp = NULL;
+
+		if (ast_strlen_zero(args.type)) {
 			args.type = "audio";
-		if (ast_strlen_zero(args.field))
-			args.field = "all";
-		
-		if (strcasecmp(args.type, "AUDIO") == 0) {
-			all = ast_rtp_get_quality(rtp = p->rtp, &qos, RTPQOS_SUMMARY);
-		} else if (strcasecmp(args.type, "VIDEO") == 0) {
-			all = ast_rtp_get_quality(rtp = p->vrtp, &qos, RTPQOS_SUMMARY);
-		} else if (strcasecmp(args.type, "TEXT") == 0) {
-			all = ast_rtp_get_quality(rtp = p->trtp, &qos, RTPQOS_SUMMARY);
+		}
+
+		if (!strcasecmp(args.type, "audio")) {
+			rtp = p->rtp;
+		} else if (!strcasecmp(args.type, "video")) {
+			rtp = p->vrtp;
+		} else if (!strcasecmp(args.type, "text")) {
+			rtp = p->trtp;
 		} else {
 			return -1;
 		}
-		
-		if (strcasecmp(args.field, "local_ssrc") == 0)
-			snprintf(buf, buflen, "%u", qos.local_ssrc);
-		else if (strcasecmp(args.field, "local_lostpackets") == 0)
-			snprintf(buf, buflen, "%u", qos.local_lostpackets);
-		else if (strcasecmp(args.field, "local_jitter") == 0)
-			snprintf(buf, buflen, "%.0f", qos.local_jitter * 1000.0);
-		else if (strcasecmp(args.field, "local_count") == 0)
-			snprintf(buf, buflen, "%u", qos.local_count);
-		else if (strcasecmp(args.field, "remote_ssrc") == 0)
-			snprintf(buf, buflen, "%u", qos.remote_ssrc);
-		else if (strcasecmp(args.field, "remote_lostpackets") == 0)
-			snprintf(buf, buflen, "%u", qos.remote_lostpackets);
-		else if (strcasecmp(args.field, "remote_jitter") == 0)
-			snprintf(buf, buflen, "%.0f", qos.remote_jitter * 1000.0);
-		else if (strcasecmp(args.field, "remote_count") == 0)
-			snprintf(buf, buflen, "%u", qos.remote_count);
-		else if (strcasecmp(args.field, "rtt") == 0)
-			snprintf(buf, buflen, "%.0f", qos.rtt * 1000.0);
-		else if (strcasecmp(args.field, "all") == 0)
-			ast_copy_string(buf, all, buflen);
-		else if (!ast_rtp_get_qos(rtp, args.field, buf, buflen))
-			 ;
-		else {
-			ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
-			return -1;
-		}
-*/
+
+		if (ast_strlen_zero(args.field) || !strcasecmp(args.field, "all")) {
+			char quality_buf[AST_MAX_USER_FIELD], *quality;
+
+			if (!(quality = ast_rtp_instance_get_quality(rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+				return -1;
+			}
+
+			ast_copy_string(buf, quality_buf, buflen);
+			return res;
+		} else {
+			struct ast_rtp_instance_stats stats;
+
+			if (ast_rtp_instance_get_stats(rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
+				return -1;
+			}
+
+			if (!strcasecmp(args.field, "local_ssrc")) {
+				snprintf(buf, buflen, "%u", stats.local_ssrc);
+			} else if (!strcasecmp(args.field, "local_lostpackets")) {
+				snprintf(buf, buflen, "%u", stats.rxploss);
+			} else if (!strcasecmp(args.field, "local_jitter")) {
+				snprintf(buf, buflen, "%u", stats.rxjitter);
+			} else if (!strcasecmp(args.field, "local_count")) {
+				snprintf(buf, buflen, "%u", stats.rxcount);
+			} else if (!strcasecmp(args.field, "remote_ssrc")) {
+				snprintf(buf, buflen, "%u", stats.remote_ssrc);
+			} else if (!strcasecmp(args.field, "remote_lostpackets")) {
+				snprintf(buf, buflen, "%u", stats.txploss);
+			} else if (!strcasecmp(args.field, "remote_jitter")) {
+				snprintf(buf, buflen, "%u", stats.txjitter);
+			} else if (!strcasecmp(args.field, "remote_count")) {
+				snprintf(buf, buflen, "%u", stats.txcount);
+			} else if (!strcasecmp(args.field, "rtt")) {
+				snprintf(buf, buflen, "%u", stats.rtt);
+			} else {
+				ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
+				return -1;
+			}
+		}
 	} else {
 		res = -1;
 	}
@@ -17951,56 +18015,59 @@
 	sip_alreadygone(p);
 
 	/* Get RTCP quality before end of call */
-/*
 	if (p->do_history || p->owner) {
-		struct ast_channel *bridge = ast_bridged_channel(p->owner);
-		char *videoqos, *textqos;
-
-		if (p->rtp) {	
+		char quality_buf[AST_MAX_USER_FIELD], *quality;
+
+		if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
+			struct ast_channel *bridge = ast_bridged_channel(p->owner);
+			
 			if (p->do_history) {
-				char *audioqos,
-				     *audioqos_jitter,
-				     *audioqos_loss,
-				     *audioqos_rtt;
-
-				audioqos        = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_SUMMARY);
-				audioqos_jitter = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_JITTER);
-				audioqos_loss   = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_LOSS);
-				audioqos_rtt    = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_RTT);
-
-				append_history(p, "RTCPaudio", "Quality:%s", audioqos);
-				append_history(p, "RTCPaudioJitter", "Quality:%s", audioqos_jitter);
-				append_history(p, "RTCPaudioLoss", "Quality:%s", audioqos_loss);
-				append_history(p, "RTCPaudioRTT", "Quality:%s", audioqos_rtt);
+				append_history(p, "RTCPaudio", "Quality:%s", quality);
+			}
+
+			pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOS", quality);
+			
+			if (bridge) {
+				pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
 			}
 			
-			ast_rtp_set_vars(p->owner, p->rtp);
-		}
-
-		if (bridge) {
-			struct sip_pvt *q = bridge->tech_pvt;
-
-			if (IS_SIP_TECH(bridge->tech) && q->rtp)
-				ast_rtp_set_vars(bridge, q->rtp);
-		}
-
-		if (p->vrtp) {
-			videoqos = ast_rtp_get_quality(p->vrtp, NULL, RTPQOS_SUMMARY);
-			if (p->do_history)
-				append_history(p, "RTCPvideo", "Quality:%s", videoqos);
-			if (p->owner)
-				pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos);
-		}
-
-		if (p->trtp) {
-			textqos = ast_rtp_get_quality(p->trtp, NULL, RTPQOS_SUMMARY);
-			if (p->do_history)
-				append_history(p, "RTCPtext", "Quality:%s", textqos);
-			if (p->owner)
-				pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", textqos);
-		}
-	}
-*/
+			if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
+				pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOSJITTER", quality);
+				if (bridge) {
+					pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
+				}
+			}
+			if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
+				pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOSLOSS", quality);
+				if (bridge) {
+					pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
+				}
+			}
+			if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
+				pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOSRTT", quality);
+				if (bridge) {
+					pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", 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 (p->owner) {
+				pbx_builtin_setvar_helper(p->owner, "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 (p->owner) {
+				pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", quality);
+			}
+		}
+	}
 
 	stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */
 	stop_session_timer(p); /* Stop Session-Timer */
@@ -20477,6 +20544,8 @@
 			ast_copy_string(peer->mohsuggest, v->value, sizeof(peer->mohsuggest));
 		} else if (!strcasecmp(v->name, "parkinglot")) {
 			ast_copy_string(peer->parkinglot, v->value, sizeof(peer->parkinglot));
+		} else if (!strcasecmp(v->name, "rtp_engine")) {
+			ast_copy_string(peer->engine, v->value, sizeof(peer->engine));
 		} else if (!strcasecmp(v->name, "mailbox")) {
 			add_peer_mailboxes(peer, v->value);
 		} else if (!strcasecmp(v->name, "hasvoicemail")) {




More information about the asterisk-commits mailing list