diff options
author | Alfred E. Heggestad <aeh@db.org> | 2014-05-20 23:53:30 +0200 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2014-05-20 23:53:30 +0200 |
commit | b62e2c17893d0c8b47d15faa8e26cb8b0ebc31d7 (patch) | |
tree | e6ea22b00de0204e272a5121a9b4321bf10a7d56 | |
parent | dd2e332a65af6dce2e540f27fdb2b815f4358574 (diff) | |
parent | bbc2959d86e93fc73fcaacede130daa06e7c9cc2 (diff) |
Merge branch 'lmangani-master'
-rw-r--r-- | src/audio.c | 66 | ||||
-rw-r--r-- | src/call.c | 18 | ||||
-rw-r--r-- | src/core.h | 2 | ||||
-rw-r--r-- | src/stream.c | 6 |
4 files changed, 92 insertions, 0 deletions
diff --git a/src/audio.c b/src/audio.c index 4f03591..36f9c6a 100644 --- a/src/audio.c +++ b/src/audio.c @@ -1391,3 +1391,69 @@ void audio_set_devicename(struct audio *a, const char *src, const char *play) str_ncpy(a->tx.device, src, sizeof(a->tx.device)); str_ncpy(a->rx.device, play, sizeof(a->rx.device)); } + + +/* + * Reference: + * + * https://www.avm.de/de/Extern/files/x-rtp/xrtpv32.pdf + */ +int audio_print_rtpstat(struct re_printf *pf, const struct audio *a) +{ + const struct stream *s; + const struct rtcp_stats *rtcp; + int srate_tx = 8000; + int srate_rx = 8000; + int err; + + if (!a) + return 1; + + s = a->strm; + rtcp = &s->rtcp_stats; + + if (!rtcp->tx.sent) + return 1; + + if (a->tx.ac) + srate_tx = get_srate(a->tx.ac); + if (a->rx.ac) + srate_rx = get_srate(a->rx.ac); + + err = re_hprintf(pf, + "EX=BareSip;" /* Reporter Identifier */ + "CS=%d;" /* Call Setup in milliseconds */ + "CD=%d;" /* Call Duration in seconds */ + "PR=%u;PS=%u;" /* Packets RX, TX */ + "PL=%d,%d;" /* Packets Lost RX, TX */ + "PD=%d,%d;" /* Packets Discarded, RX, TX */ + "JI=%.1f,%.1f;" /* Jitter RX, TX in timestamp units */ + "IP=%J,%J" /* Local, Remote IPs */ + , + call_setup_duration(s->call) * 1000, + call_duration(s->call), + + s->metric_rx.n_packets, + s->metric_tx.n_packets, + + rtcp->rx.lost, rtcp->tx.lost, + + s->metric_rx.n_err, s->metric_tx.n_err, + + /* timestamp units (ie: 8 ts units = 1 ms @ 8KHZ) */ + 1.0 * rtcp->rx.jit/1000 * (srate_rx/1000), + 1.0 * rtcp->tx.jit/1000 * (srate_tx/1000), + + sdp_media_laddr(s->sdp), + sdp_media_raddr(s->sdp) + ); + + if (a->tx.ac) { + err |= re_hprintf(pf, ";EN=%s/%d", a->tx.ac->name, srate_tx ); + } + if (a->rx.ac) { + err |= re_hprintf(pf, ";DE=%s/%d", a->rx.ac->name, srate_rx ); + } + + return err; +} @@ -73,6 +73,8 @@ struct call { call_event_h *eh; /**< Event handler */ call_dtmf_h *dtmfh; /**< DTMF handler */ void *arg; /**< Handler argument */ + + struct config_avt config_avt; }; @@ -440,6 +442,8 @@ int call_alloc(struct call **callp, const struct config *cfg, struct list *lst, MAGIC_INIT(call); + call->config_avt = cfg->avt; + tmr_init(&call->tmr_inv); call->acc = mem_ref(acc); @@ -619,6 +623,9 @@ int call_hangup(struct call *call, uint16_t scode, const char *reason) if (!call) return EINVAL; + if (call->config_avt.rtp_stats) + call_set_xrtpstat(call); + switch (call->state) { case STATE_INCOMING: @@ -1619,3 +1626,14 @@ void call_set_handlers(struct call *call, call_event_h *eh, if (arg) call->arg = arg; } + + +void call_set_xrtpstat(struct call *call) +{ + if (!call) + return; + + sipsess_set_close_headers(call->sess, + "X-RTP-Stat: %H\r\n", + audio_print_rtpstat, call->audio); +} @@ -124,6 +124,7 @@ int audio_decoder_set(struct audio *a, const struct aucodec *ac, struct stream *audio_strm(const struct audio *a); int audio_send_digit(struct audio *a, char key); void audio_sdp_attr_decode(struct audio *a); +int audio_print_rtpstat(struct re_printf *pf, const struct audio *au); /* @@ -168,6 +169,7 @@ int call_reset_transp(struct call *call); int call_notify_sipfrag(struct call *call, uint16_t scode, const char *reason, ...); int call_af(const struct call *call); +void call_set_xrtpstat(struct call *call); /* diff --git a/src/stream.c b/src/stream.c index fcd4da4..e9cf871 100644 --- a/src/stream.c +++ b/src/stream.c @@ -172,6 +172,10 @@ static void rtcp_handler(const struct sa *src, struct rtcp_msg *msg, void *arg) case RTCP_SR: (void)rtcp_stats(s->rtp, msg->r.sr.ssrc, &s->rtcp_stats); + + if (s->cfg.rtp_stats) + call_set_xrtpstat(s->call); + break; } } @@ -553,3 +557,5 @@ int stream_print(struct re_printf *pf, const struct stream *s) s->metric_tx.cur_bitrate, s->metric_rx.cur_bitrate); } + + |