diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-12-09 14:21:33 +0100 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2017-12-09 14:21:33 +0100 |
commit | 1110ecaeee1be1a7d13f12d193086bbddf9a7f4a (patch) | |
tree | 6af6c4a9b4710a6e08580e4601c1fb63dd90f248 /modules | |
parent | 9d8ce318ba0207059e705da7589b61fe699d515c (diff) |
ua: add UA_EVENT_CALL_RTCP event
this event is called for every received RTCP report.
mqtt: add JSON encoding of RTCP stats
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mqtt/publish.c | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/modules/mqtt/publish.c b/modules/mqtt/publish.c index 068400a..dd250c2 100644 --- a/modules/mqtt/publish.c +++ b/modules/mqtt/publish.c @@ -16,8 +16,54 @@ */ +static int add_rtcp_stats(struct odict *od_parent, const struct rtcp_stats *rs) +{ + struct odict *od = NULL, *tx = NULL, *rx = NULL; + int err = 0; + + if (!od_parent || !rs) + return EINVAL; + + err = odict_alloc(&od, 8); + err |= odict_alloc(&tx, 8); + err |= odict_alloc(&rx, 8); + if (err) + goto out; + + err = odict_entry_add(tx, "sent", ODICT_INT, (int64_t)rs->tx.sent); + err |= odict_entry_add(tx, "lost", ODICT_INT, (int64_t)rs->tx.lost); + err |= odict_entry_add(tx, "jit", ODICT_INT, (int64_t)rs->tx.jit); + if (err) + goto out; + + err = odict_entry_add(rx, "sent", ODICT_INT, (int64_t)rs->rx.sent); + err |= odict_entry_add(rx, "lost", ODICT_INT, (int64_t)rs->rx.lost); + err |= odict_entry_add(rx, "jit", ODICT_INT, (int64_t)rs->rx.jit); + if (err) + goto out; + + err = odict_entry_add(od, "tx", ODICT_OBJECT, tx); + err |= odict_entry_add(od, "rx", ODICT_OBJECT, rx); + err |= odict_entry_add(od, "rtt", ODICT_INT, (int64_t)rs->rtt); + if (err) + goto out; + + /* add object to the parent */ + err = odict_entry_add(od_parent, "rtcp_stats", ODICT_OBJECT, od); + if (err) + goto out; + + out: + mem_deref(od); + + return err; +} + + /* * Relay UA events as publish messages to the Broker + * + * XXX: move JSON encoding to baresip core */ static void ua_event_handler(struct ua *ua, enum ua_event ev, struct call *call, const char *prm, void *arg) @@ -42,9 +88,30 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev, dir = call_is_outgoing(call) ? "outgoing" : "incoming"; - err |= odict_entry_add(od, "direction", ODICT_STRING, dir ); + err |= odict_entry_add(od, "direction", ODICT_STRING, dir); err |= odict_entry_add(od, "peeruri", ODICT_STRING, call_peeruri(call)); + if (err) + goto out; + } + + if (str_isset(prm)) { + err = odict_entry_add(od, "param", ODICT_STRING, prm); + if (err) + goto out; + } + + if (ev == UA_EVENT_CALL_RTCP) { + struct stream *strm = NULL; + + if (0 == str_casecmp(prm, "audio")) + strm = audio_strm(call_audio(call)); + else if (0 == str_casecmp(prm, "video")) + strm = video_strm(call_video(call)); + + err = add_rtcp_stats(od, stream_rtcp_stats(strm)); + if (err) + goto out; } err = mqtt_publish_message(mqtt, "/baresip/event", "%H", |