[svn-commits] file: branch file/rtp_engine r131132 - in /team/file/rtp_engine: include/aste...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 15 19:00:16 CDT 2008


Author: file
Date: Tue Jul 15 19:00:15 2008
New Revision: 131132

URL: http://svn.digium.com/view/asterisk?view=rev&rev=131132
Log:
Add an API call which produces a string of various quality metrics.

Modified:
    team/file/rtp_engine/include/asterisk/rtp_engine.h
    team/file/rtp_engine/main/rtp_engine.c

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=131132&r1=131131&r2=131132
==============================================================================
--- team/file/rtp_engine/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine/include/asterisk/rtp_engine.h Tue Jul 15 19:00:15 2008
@@ -101,6 +101,18 @@
 	AST_RTP_GLUE_RESULT_REMOTE,
 	/*! Perform RTP engine level bridging if possible */
 	AST_RTP_GLUE_RESULT_LOCAL,
+};
+
+/*! Field statistics that can be retrieved from an RTP instance */
+enum ast_rtp_instance_stat_field {
+	/*! Retrieve quality information */
+	AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0,
+	/*! Retrieve quality information about jitter */
+	AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER,
+	/*! Retrieve quality information about packet loss */
+	AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS,
+	/*! Retrieve quality information about round trip time */
+	AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT,
 };
 
 /*! Statistics that can be retrieved from an RTP instance */
@@ -961,8 +973,8 @@
  * \param stats Structure to put results into
  * \param stat What statistic(s) to retrieve
  *
- * \retval 0 on success
- * \retval -1 on failure
+ * \retval 0 success
+ * \retval -1 failure
  *
  * Example usage:
  *
@@ -975,6 +987,27 @@
  * stats structure.
  */
 int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
+
+/*! \brief Retrieve quality statistics about an RTP instance
+ *
+ * \param instance Instance to get statistics on
+ * \param field What quality statistic to retrieve
+ * \param buf What buffer to put the result into
+ * \param size Size of the above buffer
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * Example usage:
+ *
+ * \code
+ * char quality[AST_MAX_USER_FIELD];
+ * ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf));
+ * \endcode
+ *
+ * This retrieves general quality statistics and places a text representation into the buf pointed to by buf.
+ */
+char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 }

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=131132&r1=131131&r2=131132
==============================================================================
--- team/file/rtp_engine/main/rtp_engine.c (original)
+++ team/file/rtp_engine/main/rtp_engine.c Tue Jul 15 19:00:15 2008
@@ -26,6 +26,8 @@
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <math.h>
 
 #include "asterisk/channel.h"
 #include "asterisk/frame.h"
@@ -1129,3 +1131,43 @@
 {
 	return instance->engine->get_stat ? instance->engine->get_stat(instance, stats, stat) : -1;
 }
+
+char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
+{
+	struct ast_rtp_instance_stats stats;
+	enum ast_rtp_instance_stat stat;
+
+	/* Determine what statistics we will need to retrieve based on field passed in */
+	if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
+		stat = AST_RTP_INSTANCE_STAT_ALL;
+	} else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
+		stat = AST_RTP_INSTANCE_STAT_COMBINED_JITTER;
+	} else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
+		stat = AST_RTP_INSTANCE_STAT_COMBINED_LOSS;
+	} else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
+		stat = AST_RTP_INSTANCE_STAT_COMBINED_RTT;
+	} else {
+		return NULL;
+	}
+
+	/* Attempt to actually retrieve the statistics we need to generate the quality string */
+	if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
+		return NULL;
+	}
+
+	/* Now actually fill the buffer with the good information */
+	if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
+		snprintf(buf, size, "ssrc=%i;themssrc=%u;lp=%u;rxjitter=%u;rxcount=%u;txjitter=%u;txcount=%u;rlp=%u;rtt=%u",
+			 stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.txjitter, stats.rxcount, stats.rxjitter, stats.txcount, stats.txploss, stats.rtt);
+	} else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
+		snprintf(buf, size, "minrxjitter=%f;maxrxjitter=%f;avgrxjitter=%f;stdevrxjitter=%f;reported_minjitter=%f;reported_maxjitter=%f;reported_avgjitter=%f;reported_stdevjitter=%f;",
+			 stats.local_minjitter, stats.local_maxjitter, stats.local_normdevjitter, sqrt(stats.local_stdevjitter), stats.remote_minjitter, stats.remote_maxjitter, stats.remote_normdevjitter, sqrt(stats.remote_stdevjitter));
+	} else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
+		snprintf(buf, size, "minrxlost=%f;maxrxlost=%f;avgrxlost=%f;stdevrxlost=%f;reported_minlost=%f;reported_maxlost=%f;reported_avglost=%f;reported_stdevlost=%f;",
+			 stats.local_minrxploss, stats.local_maxrxploss, stats.local_normdevrxploss, sqrt(stats.local_stdevrxploss), stats.remote_minrxploss, stats.remote_maxrxploss, stats.remote_normdevrxploss, sqrt(stats.remote_stdevrxploss));
+	} else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
+		snprintf(buf, size, "minrtt=%f;maxrtt=%f;avgrtt=%f;stdevrtt=%f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
+	}
+
+	return buf;
+}




More information about the svn-commits mailing list