diff --git a/daemon/kernel.c b/daemon/kernel.c index afe00e010..e86c89d5d 100644 --- a/daemon/kernel.c +++ b/daemon/kernel.c @@ -272,23 +272,20 @@ unsigned int kernel_add_intercept_stream(unsigned int call_idx, const char *id) return cmd.stream.idx.stream_idx; } -int kernel_update_stats(const struct re_address *a, struct rtpengine_stats_info *out) { - struct rtpengine_command_stats cmd; +// cmd->local must be filled in +int kernel_update_stats(struct rtpengine_command_stats *cmd) { ssize_t ret; if (!kernel.is_open) return -1; - cmd.cmd = REMG_GET_RESET_STATS; - cmd.local = *a; + cmd->cmd = REMG_GET_RESET_STATS; - ret = read(kernel.fd, &cmd, sizeof(cmd)); + ret = read(kernel.fd, cmd, sizeof(*cmd)); if (ret <= 0) { ilog(LOG_ERROR, "Failed to get stream stats from kernel: %s", strerror(errno)); return -1; } - *out = cmd.stats; - return 0; } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 53bee6b1b..020a16ef9 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1682,42 +1682,40 @@ struct ssrc_ctx *__hunt_ssrc_ctx(uint32_t ssrc, struct ssrc_ctx *list[RTPE_NUM_S // must be called with appropriate locks (master lock and/or in_lock) static void __stream_update_stats(struct packet_stream *ps, bool have_in_lock) { - struct re_address local; - if (!have_in_lock) mutex_lock(&ps->in_lock); - __re_address_translate_ep(&local, &ps->selected_sfd->socket.local); - struct rtpengine_stats_info stats_info; - if (kernel_update_stats(&local, &stats_info)) { + struct rtpengine_command_stats stats_info; + __re_address_translate_ep(&stats_info.local, &ps->selected_sfd->socket.local); + if (kernel_update_stats(&stats_info)) { if (!have_in_lock) mutex_unlock(&ps->in_lock); return; } - for (unsigned int u = 0; u < G_N_ELEMENTS(stats_info.ssrc); u++) { + for (unsigned int u = 0; u < G_N_ELEMENTS(stats_info.stats.ssrc); u++) { // check for the right SSRC association - if (!stats_info.ssrc[u]) // end of list + if (!stats_info.stats.ssrc[u]) // end of list break; - uint32_t ssrc = ntohl(stats_info.ssrc[u]); + uint32_t ssrc = ntohl(stats_info.stats.ssrc[u]); struct ssrc_ctx *ssrc_ctx = __hunt_ssrc_ctx(ssrc, ps->ssrc_in, u); if (!ssrc_ctx) continue; struct ssrc_entry_call *parent = ssrc_ctx->parent; - if (!stats_info.ssrc_stats[u].basic_stats.packets) // no change + if (!stats_info.stats.ssrc_stats[u].basic_stats.packets) // no change continue; - atomic64_add(&ssrc_ctx->packets, stats_info.ssrc_stats[u].basic_stats.packets); - atomic64_add(&ssrc_ctx->octets, stats_info.ssrc_stats[u].basic_stats.bytes); - parent->packets_lost += stats_info.ssrc_stats[u].total_lost; // XXX should be atomic? - atomic64_set(&ssrc_ctx->last_seq, stats_info.ssrc_stats[u].ext_seq); - atomic64_set(&ssrc_ctx->last_ts, stats_info.ssrc_stats[u].timestamp); - parent->jitter = stats_info.ssrc_stats[u].jitter; + atomic64_add(&ssrc_ctx->packets, stats_info.stats.ssrc_stats[u].basic_stats.packets); + atomic64_add(&ssrc_ctx->octets, stats_info.stats.ssrc_stats[u].basic_stats.bytes); + parent->packets_lost += stats_info.stats.ssrc_stats[u].total_lost; // XXX should be atomic? + atomic64_set(&ssrc_ctx->last_seq, stats_info.stats.ssrc_stats[u].ext_seq); + atomic64_set(&ssrc_ctx->last_ts, stats_info.stats.ssrc_stats[u].timestamp); + parent->jitter = stats_info.stats.ssrc_stats[u].jitter; - RTPE_STATS_ADD(packets_lost, stats_info.ssrc_stats[u].total_lost); + RTPE_STATS_ADD(packets_lost, stats_info.stats.ssrc_stats[u].total_lost); atomic64_add(&ps->selected_sfd->local_intf->stats.s.packets_lost, - stats_info.ssrc_stats[u].total_lost); + stats_info.stats.ssrc_stats[u].total_lost); uint32_t ssrc_map_out = ssrc_ctx->ssrc_map_out; @@ -1735,8 +1733,8 @@ static void __stream_update_stats(struct packet_stream *ps, bool have_in_lock) { if (ssrc_ctx) { parent = ssrc_ctx->parent; - atomic64_add(&ssrc_ctx->packets, stats_info.ssrc_stats[u].basic_stats.packets); - atomic64_add(&ssrc_ctx->octets, stats_info.ssrc_stats[u].basic_stats.bytes); + atomic64_add(&ssrc_ctx->packets, stats_info.stats.ssrc_stats[u].basic_stats.packets); + atomic64_add(&ssrc_ctx->octets, stats_info.stats.ssrc_stats[u].basic_stats.bytes); } mutex_unlock(&sink->out_lock); diff --git a/include/kernel.h b/include/kernel.h index dbaf3c919..b63ea5e96 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -39,7 +39,7 @@ int kernel_add_stream(struct rtpengine_target_info *); int kernel_add_destination(struct rtpengine_destination_info *); int kernel_del_stream(const struct re_address *); GList *kernel_list(void); -int kernel_update_stats(const struct re_address *a, struct rtpengine_stats_info *out); +int kernel_update_stats(struct rtpengine_command_stats *); unsigned int kernel_add_call(const char *id); int kernel_del_call(unsigned int);