Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 244242) +++ channels/chan_sip.c (working copy) @@ -22142,7 +22142,7 @@ } else if (!strcasecmp(args.type, "text")) { rtp = p->trtp; } else { - return -1; + return -1; } if (ast_strlen_zero(args.field) || !strcasecmp(args.field, "all")) { @@ -22155,34 +22155,68 @@ ast_copy_string(buf, quality_buf, buflen); return res; } else { +#define INT 0 +#define DBL 1 struct ast_rtp_instance_stats stats; + int i; + struct { + const char *name; + int type; + union { + unsigned int *i4; + double *d8; + }; + } lookup[] = { + { "txcount", INT, { .i4 = &stats.txcount, }, }, + { "rxcount", INT, { .i4 = &stats.rxcount, }, }, + { "txjitter", INT, { .i4 = &stats.txjitter, }, }, + { "rxjitter", INT, { .i4 = &stats.rxjitter, }, }, + { "remote_maxjitter", DBL, { .d8 = &stats.remote_maxjitter, }, }, + { "remote_minjitter", DBL, { .d8 = &stats.remote_minjitter, }, }, + { "remote_normdevjitter", DBL, { .d8 = &stats.remote_normdevjitter, }, }, + { "remote_stdevjitter", DBL, { .d8 = &stats.remote_stdevjitter, }, }, + { "local_maxjitter", DBL, { .d8 = &stats.local_maxjitter, }, }, + { "local_minjitter", DBL, { .d8 = &stats.local_minjitter, }, }, + { "local_normdevjitter", DBL, { .d8 = &stats.local_normdevjitter, }, }, + { "local_stdevjitter", DBL, { .d8 = &stats.local_stdevjitter, }, }, + { "txploss", INT, { .i4 = &stats.txploss, }, }, + { "rxploss", INT, { .i4 = &stats.rxploss, }, }, + { "remote_maxrxploss", DBL, { .d8 = &stats.remote_maxrxploss, }, }, + { "remote_minrxploss", DBL, { .d8 = &stats.remote_minrxploss, }, }, + { "remote_normdevrxploss", DBL, { .d8 = &stats.remote_normdevrxploss, }, }, + { "remote_stdevrxploss", DBL, { .d8 = &stats.remote_stdevrxploss, }, }, + { "local_maxrxploss", DBL, { .d8 = &stats.local_maxrxploss, }, }, + { "local_minrxploss", DBL, { .d8 = &stats.local_minrxploss, }, }, + { "local_normdevrxploss", DBL, { .d8 = &stats.local_normdevrxploss, }, }, + { "local_stdevrxploss", DBL, { .d8 = &stats.local_stdevrxploss, }, }, + { "rtt", INT, { .i4 = &stats.rtt, }, }, + { "maxrtt", DBL, { .d8 = &stats.maxrtt, }, }, + { "minrtt", DBL, { .d8 = &stats.minrtt, }, }, + { "normdevrtt", DBL, { .d8 = &stats.normdevrtt, }, }, + { "stdevrtt", DBL, { .d8 = &stats.stdevrtt, }, }, + { "local_ssrc", INT, { .i4 = &stats.local_ssrc, }, }, + { "remote_ssrc", INT, { .i4 = &stats.remote_ssrc, }, }, + { NULL, }, + }; 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; + for (i = 0; !ast_strlen_zero(lookup[i].name); i++) { + if (!strcasecmp(args.field, lookup[i].name)) { + if (lookup[i].type == INT) { + snprintf(buf, buflen, "%u", *lookup[i].i4); + } else { + snprintf(buf, buflen, "%f", *lookup[i].d8); + } + return 0; + } } +#undef INT +#undef DBL + ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname); + return -1; } } else { res = -1;