From 3c764bed52bf3c62d0f959269af76626193a858b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 8 Feb 2013 10:28:39 -0500 Subject: [PATCH] split NG stats collection into ng_call_stats() --- daemon/call.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index 16769b33d..77fb747bc 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -118,6 +118,7 @@ static char *rtp_codecs[] = { static void call_destroy(struct call *); static void unkernelize(struct peer *); static void relays_cache_port_used(struct relays_cache *c); +static void ng_call_stats(struct call *call, str *fromtag, str *totag, bencode_item_t *output); @@ -2424,11 +2425,24 @@ static void ng_stats_cb(struct peer *p, struct peer *px, void *streams) { bencode_list_add(stream, peer_stats(stream->buffer, px)); } +/* call must be locked */ +static void ng_call_stats(struct call *call, str *fromtag, str *totag, bencode_item_t *output) { + bencode_item_t *streams, *dict; + struct call_stats stats; + + bencode_dictionary_add_integer(output, "created", call->created); + + streams = bencode_dictionary_add_list(output, "streams"); + stats_query(call, fromtag, totag, &stats, ng_stats_cb, streams); + + dict = bencode_dictionary_add_dictionary(output, "totals"); + bencode_dictionary_add(dict, "input", rtp_rtcp_stats(output->buffer, &stats.totals[0], &stats.totals[1])); + bencode_dictionary_add(dict, "output", rtp_rtcp_stats(output->buffer, &stats.totals[2], &stats.totals[3])); +} + const char *call_query_ng(bencode_item_t *input, struct callmaster *m, bencode_item_t *output) { str callid, fromtag, totag; struct call *call; - bencode_item_t *streams, *dict; - struct call_stats stats; if (!bencode_dictionary_get_str(input, "call-id", &callid)) return "No call-id in message"; @@ -2439,16 +2453,8 @@ const char *call_query_ng(bencode_item_t *input, struct callmaster *m, bencode_i bencode_dictionary_get_str(input, "to-tag", &totag); bencode_dictionary_add_string(output, "result", "ok"); - bencode_dictionary_add_integer(output, "created", call->created); - - streams = bencode_dictionary_add_list(output, "streams"); - stats_query(call, &fromtag, &totag, &stats, ng_stats_cb, streams); - + ng_call_stats(call, &fromtag, &totag, output); mutex_unlock(&call->lock); - dict = bencode_dictionary_add_dictionary(output, "totals"); - bencode_dictionary_add(dict, "input", rtp_rtcp_stats(output->buffer, &stats.totals[0], &stats.totals[1])); - bencode_dictionary_add(dict, "output", rtp_rtcp_stats(output->buffer, &stats.totals[2], &stats.totals[3])); - return NULL; }