[asterisk-commits] file: branch file/rtp_engine r130956 - in /team/file/rtp_engine: channels/ in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 15 12:07:42 CDT 2008


Author: file
Date: Tue Jul 15 12:07:42 2008
New Revision: 130956

URL: http://svn.digium.com/view/asterisk?view=rev&rev=130956
Log:
Add all the statistics we will be providing along with a method to retrieve them plus make res_rtp_asterisk provide them.

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

Modified: team/file/rtp_engine/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/channels/chan_sip.c?view=diff&rev=130956&r1=130955&r2=130956
==============================================================================
--- team/file/rtp_engine/channels/chan_sip.c (original)
+++ team/file/rtp_engine/channels/chan_sip.c Tue Jul 15 12:07:42 2008
@@ -5931,15 +5931,15 @@
 	p->ocseq = INITIAL_CSEQ;
 
 	if (sip_methods[intended_method].need_rtp) {
-		p->rtp = ast_rtp_instance_new(NULL, NULL, sched, &bindaddr);
+		p->rtp = ast_rtp_instance_new(NULL, sched, &bindaddr);
 		ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1);
 		/* 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_instance_new(NULL, NULL, sched, &bindaddr);
+			p->vrtp = ast_rtp_instance_new(NULL, sched, &bindaddr);
 			ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 1);
 		}
  		if (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT)) {
-			p->trtp = ast_rtp_instance_new(NULL, NULL, sched, &bindaddr);
+			p->trtp = ast_rtp_instance_new(NULL, sched, &bindaddr);
 			ast_rtp_instance_set_prop(p->trtp, AST_RTP_PROPERTY_RTCP, 1);
 		}
 		if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))

Modified: team/file/rtp_engine/include/asterisk/rtp_engine.h
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/include/asterisk/rtp_engine.h?view=diff&rev=130956&r1=130955&r2=130956
==============================================================================
--- team/file/rtp_engine/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine/include/asterisk/rtp_engine.h Tue Jul 15 12:07:42 2008
@@ -52,6 +52,42 @@
 	AST_RTP_GLUE_RESULT_FORBID = 0,
 	AST_RTP_GLUE_RESULT_REMOTE,
 	AST_RTP_GLUE_RESULT_LOCAL,
+};
+
+enum ast_rtp_instance_stat {
+	AST_RTP_INSTANCE_STAT_ALL = 0,
+	AST_RTP_INSTANCE_STAT_TXCOUNT,
+	AST_RTP_INSTANCE_STAT_RXCOUNT,
+	AST_RTP_INSTANCE_STAT_COMBINED_LOSS, /*!< Special stat which grabs only loss values */
+	AST_RTP_INSTANCE_STAT_TXPLOSS,
+	AST_RTP_INSTANCE_STAT_RXPLOSS,
+	AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS,
+	AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
+	AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS,
+	AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS,
+	AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS,
+	AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
+	AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS,
+	AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS,
+	AST_RTP_INSTANCE_STAT_COMBINED_JITTER, /*!< Special stat which grabs only jitter values */
+	AST_RTP_INSTANCE_STAT_TXJITTER,
+	AST_RTP_INSTANCE_STAT_RXJITTER,
+	AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER,
+	AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER,
+	AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
+	AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER,
+	AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER,
+	AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER,
+	AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
+	AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER,
+	AST_RTP_INSTANCE_STAT_COMBINED_RTT, /*!< Special stat which grabs only round trip time values */
+	AST_RTP_INSTANCE_STAT_RTT,
+	AST_RTP_INSTANCE_STAT_MAX_RTT,
+	AST_RTP_INSTANCE_STAT_MIN_RTT,
+	AST_RTP_INSTANCE_STAT_NORMDEVRTT,
+	AST_RTP_INSTANCE_STAT_STDEVRTT,
+	AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
+	AST_RTP_INSTANCE_STAT_REMOTE_SSRC,
 };
 
 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
@@ -70,7 +106,54 @@
 };
 
 struct ast_rtp_instance_stats {
-};
+	/* Packet count parts */
+	unsigned int txcount; /*!< Number of packets transmitted */
+	unsigned int rxcount; /*!< Number of packets received */
+	/* Jitter parts */
+	unsigned int txjitter; /*!< Jitter on transmitted packets */
+	unsigned int rxjitter; /*!< Jitter on received packets */
+	double remote_maxjitter; /*!< Maximum jitter on remote side */
+	double remote_minjitter; /*!< Minimum jitter on remote side */
+	double remote_normdevjitter; /*!< Normal deviation jitter on remote side */
+	double remote_stdevjitter; /*!< Standard deviation jitter on remote side */
+	double local_maxjitter; /*!< Maximum jitter on local side */
+	double local_minjitter; /*!< Minimum jitter on local side */
+	double local_normdevjitter; /*!< Normal deviation jitter on local side */
+	double local_stdevjitter; /*!< Standard deviation jitter on local side */
+	/* Packet loss parts */
+	unsigned int txploss; /*!< Number of transmitted packets lost */
+	unsigned int rxploss; /*!< Number of received packets lost */
+	double remote_maxrxploss; /*!< Maximum number of packets lost on remote side */
+	double remote_minrxploss; /*!< Minimum number of packets lost on remote side */
+	double remote_normdevrxploss; /*!< Normal deviation of packets lost on remote side */
+	double remote_stdevrxploss; /*!< Standard deviation of packets lost on remote side */
+	double local_maxrxploss; /*!< Maximum number of packets lost on local side */
+	double local_minrxploss; /*!< Minimum number of packets lost on local side */
+	double local_normdevrxploss; /*!< Normal deviation of packets lost on local side */
+	double local_stdevrxploss; /*!< Standard deviation of packets lost on local side */
+	/* Round trip time parts */
+	unsigned int rtt; /*!< Total round trip time */
+	double maxrtt; /*!< Maximum round trip time */
+	double minrtt; /*!< Minimum round trip time */
+	double normdevrtt; /*!< Normal deviation round trip time */
+	double stdevrtt; /*!< Standard deviation round trip time */
+	/* Source parts */
+	unsigned int local_ssrc; /*!< Our SSRC */
+	unsigned int remote_ssrc; /*!< SSRC of the other side */
+};
+
+#define AST_RTP_STAT_SET(current_stat, combined, placement, value) \
+if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == current_stat)) { \
+placement = value; \
+if (stat == current_stat) { \
+return 0; \
+} \
+}
+
+#define AST_RTP_STAT_TERMINATOR(combined) \
+if (stat == combined) { \
+return 0; \
+}
 
 struct ast_rtp_engine {
 	const char *name;                                                                               /*!< Name of the RTP engine */
@@ -86,7 +169,7 @@
 	void (*payload_set)(struct ast_rtp_instance *instance, int payload, int AstFormat, int format); /*!< Callback for when a payload is set */
 	void (*packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref);      /*!< Callback for setting codec packetization preferences */
 	void (*remote_address_set)(struct ast_rtp_instance *instance, struct sockaddr_in *sin);         /*!< Callback for when the remote address is set on an RTP instance */
-	int (*get_stats)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats);      /*!< Callback for retrieving statistics about the session */
+	int (*get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);      /*!< Callback for retrieving statistics about the session */
 	int (*qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);              /*!< Callback for setting QoS parameters on the RTP session */
 	int (*fd)(struct ast_rtp_instance *instance, int rtcp);                                         /*!< Callback for retrieving a file descriptor for RTP or RTCP */
 	int (*red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations); /*!< Callback for initializing RED support */
@@ -103,7 +186,6 @@
 
 struct ast_rtp_instance {
 	struct ast_rtp_engine *engine;                        /*!< Engine handling this RTP session instance */
-	struct ast_rtp_glue *glue;                            /*!< Glue that interfaces with the channel driver */
 	void *data;                                           /*!< Unique data for the RTP engine */
 	int properties[AST_RTP_PROPERTY_MAX];                 /*!< Properties and their values */
 	struct sockaddr_in local_address;                     /*!< The address we are expecting RTP to be received on */
@@ -171,14 +253,13 @@
 /*! \brief Create a new RTP instance
  *
  * \param engine_name Name of the engine to use for the RTP instance
- * \param glue The glue to use when bridging
  * \param sched Scheduler context that the RTP engine may want to use
  * \param sin Address we want to bind to
  *
  * \retval non-NULL success
  * \retval NULL failure
  */
-struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct ast_rtp_glue *glue, struct sched_context *sched, struct sockaddr_in *sin);
+struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct sched_context *sched, struct sockaddr_in *sin);
 
 /*! \brief Destroy an RTP instance
  *
@@ -308,6 +389,9 @@
 /*! \brief Buffer a frame in an RTP instance for RED */
 int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame);
 
+/*! \brief Retrieve statistics about an RTP instance */
+int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/file/rtp_engine/main/rtp_engine.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/main/rtp_engine.c?view=diff&rev=130956&r1=130955&r2=130956
==============================================================================
--- team/file/rtp_engine/main/rtp_engine.c (original)
+++ team/file/rtp_engine/main/rtp_engine.c Tue Jul 15 12:07:42 2008
@@ -239,7 +239,7 @@
 	return current_glue ? 0 : -1;
 }
 
-struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct ast_rtp_glue *glue, struct sched_context *sched, struct sockaddr_in *sin)
+struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct sched_context *sched, struct sockaddr_in *sin)
 {
 	struct ast_rtp_instance *instance = NULL;
 	struct ast_rtp_engine *engine = NULL;
@@ -274,7 +274,6 @@
 		return NULL;
 	}
 	instance->engine = engine;
-	instance->glue = glue;
 	memcpy(&instance->local_address, sin, sizeof(instance->local_address));
 
 	ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
@@ -1125,3 +1124,8 @@
 {
 	return instance->engine->red_buffer ? instance->engine->red_buffer(instance, frame) : -1;
 }
+
+int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
+{
+	return instance->engine->get_stat ? instance->engine->get_stat(instance, stats, stat) : -1;
+}

Modified: team/file/rtp_engine/res/res_rtp_asterisk.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/res/res_rtp_asterisk.c?view=diff&rev=130956&r1=130955&r2=130956
==============================================================================
--- team/file/rtp_engine/res/res_rtp_asterisk.c (original)
+++ team/file/rtp_engine/res/res_rtp_asterisk.c Tue Jul 15 12:07:42 2008
@@ -253,6 +253,7 @@
 static int rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
 static int rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame);
 static int ast_rtp_local_bridge(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1);
+static int ast_rtp_get_stat(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
 
 /* RTP Engine Declaration */
 static struct ast_rtp_engine asterisk_rtp_engine = {
@@ -270,6 +271,7 @@
 	.red_init = rtp_red_init,
 	.red_buffer = rtp_red_buffer,
 	.local_bridge = ast_rtp_local_bridge,
+	.get_stat = ast_rtp_get_stat,
 };
 
 static inline int rtp_debug_test_addr(struct sockaddr_in *addr)
@@ -2133,6 +2135,54 @@
 	return 0;
 }
 
+static int ast_rtp_get_stat(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
+{
+	struct ast_rtp *rtp = instance->data;
+
+	if (!rtp->rtcp) {
+		return -1;
+	}
+
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_TXCOUNT, -1, stats->txcount, rtp->txcount);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_RXCOUNT, -1, stats->rxcount, rtp->rxcount);
+
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_TXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->txploss, rtp->rtcp->reported_lost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_RXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->rxploss, rtp->rtcp->expected_prior - rtp->rtcp->received_prior);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->remote_maxrxploss, rtp->rtcp->reported_maxlost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->remote_minrxploss, rtp->rtcp->reported_minlost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->remote_normdevrxploss, rtp->rtcp->reported_normdev_lost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->remote_stdevrxploss, rtp->rtcp->reported_stdev_lost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->local_maxrxploss, rtp->rtcp->maxrxlost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->local_minrxploss, rtp->rtcp->minrxlost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->local_normdevrxploss, rtp->rtcp->normdev_rxlost);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, stats->local_stdevrxploss, rtp->rtcp->stdev_rxlost);
+	AST_RTP_STAT_TERMINATOR(AST_RTP_INSTANCE_STAT_COMBINED_LOSS);
+
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_TXJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->txjitter, rtp->rxjitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_RXJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->rxjitter, rtp->rtcp->reported_jitter / (unsigned int) 65536.0);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->remote_maxjitter, rtp->rtcp->reported_maxjitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->remote_minjitter, rtp->rtcp->reported_minjitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->remote_normdevjitter, rtp->rtcp->reported_normdev_jitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->remote_stdevjitter, rtp->rtcp->reported_stdev_jitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->local_maxjitter, rtp->rtcp->maxrxjitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->local_minjitter, rtp->rtcp->minrxjitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->local_normdevjitter, rtp->rtcp->normdev_rxjitter);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, stats->local_stdevjitter, rtp->rtcp->stdev_rxjitter);
+	AST_RTP_STAT_TERMINATOR(AST_RTP_INSTANCE_STAT_COMBINED_JITTER);
+
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_RTT, AST_RTP_INSTANCE_STAT_COMBINED_RTT, stats->rtt, rtp->rtcp->rtt);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_MAX_RTT, AST_RTP_INSTANCE_STAT_COMBINED_RTT, stats->maxrtt, rtp->rtcp->maxrtt);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_MIN_RTT, AST_RTP_INSTANCE_STAT_COMBINED_RTT, stats->minrtt, rtp->rtcp->minrtt);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_NORMDEVRTT, AST_RTP_INSTANCE_STAT_COMBINED_RTT, stats->normdevrtt, rtp->rtcp->normdevrtt);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_STDEVRTT, AST_RTP_INSTANCE_STAT_COMBINED_RTT, stats->stdevrtt, rtp->rtcp->stdevrtt);
+	AST_RTP_STAT_TERMINATOR(AST_RTP_INSTANCE_STAT_COMBINED_RTT);
+
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_LOCAL_SSRC, -1, stats->local_ssrc, rtp->ssrc);
+	AST_RTP_STAT_SET(AST_RTP_INSTANCE_STAT_REMOTE_SSRC, -1, stats->remote_ssrc, rtp->themssrc);
+
+	return 0;
+}
+
 static char *rtp_do_debug_ip(struct ast_cli_args *a)
 {
 	struct hostent *hp;




More information about the asterisk-commits mailing list