Debian Codegraph @

src/stats.c

raw symbols SCIP
1 /* librist. Copyright © 2019-2020 SipRadius LLC. All right reserved.
2 * Author: Daniele Lacamera <[email protected]>
3 * Author: Kuldeep Singh Dhaka <[email protected]>
4 * Author: Sergio Ammirata <[email protected]>
5 * Author: Gijs Peskens <[email protected]>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 */
9
10 #include "rist-private.h"
11 #include "log-private.h"
12 #include "udp-private.h"
13 #include "proto/rist_time.h"
14 #include <string.h>
15 #include "cjson/cJSON.h"
16
17 /* Bump on any incompatible shape change to the stats JSON payloads. */
18 #define RIST_STATS_JSON_SCHEMA_VERSION 4
19
20 static double round_two_digits(double number)
21 {
22 long new_number = (long)(number * 100);
23 return (double)(new_number) / 100;
24 }
25
26 static const char *rist_profile_name(int profile)
27 {
28 switch (profile) {
29 case RIST_PROFILE_SIMPLE: return "simple";
30 case RIST_PROFILE_MAIN: return "main";
31 case RIST_PROFILE_ADVANCED: return "advanced";
32 default: return "unknown";
33 }
34 }
35
36 void rist_sender_flow_statistics(struct rist_sender *ctx)
37 {
38 cJSON *stats = cJSON_CreateObject();
39 cJSON_AddNumberToObject(stats, "schema_version", RIST_STATS_JSON_SCHEMA_VERSION);
40 cJSON *rist_sender_stats = cJSON_AddObjectToObject(stats, "sender-stats");
41 cJSON *peers = cJSON_AddArrayToObject(rist_sender_stats, "peers");
42
43 pthread_mutex_lock(&ctx->common.peerlist_lock);
44 for (size_t j = 0; j < ctx->peer_lst_len; j++) {
45 struct rist_peer *peer = ctx->peer_lst[j];
46 if (!peer->dead && peer->authenticated) {
47 cJSON *peer_obj = rist_sender_peer_statistics(peer);
48 cJSON_AddItemToArray(peers, peer_obj);
49 }
50 }
51 pthread_mutex_unlock(&ctx->common.peerlist_lock);
52
53 cJSON *udp_queue_obj = cJSON_AddObjectToObject(rist_sender_stats, "incoming_queue");
54 cJSON_AddNumberToObject(udp_queue_obj, "size", ctx->sender_queue_size);
55 cJSON_AddNumberToObject(udp_queue_obj, "bytesize", ctx->sender_queue_bytesize);
56 cJSON_AddNumberToObject(udp_queue_obj, "time_length", ctx->sender_queue_timelength);
57 if (ctx->sender_queue_timelength > 0)
58 cJSON_AddNumberToObject(udp_queue_obj, "packets_per_second", 1000 * ctx->sender_queue_size / ctx->sender_queue_timelength);
59 else
60 cJSON_AddNumberToObject(udp_queue_obj, "packets_per_second", 0);
61
62 if (ctx->split_mode != LIBRIST_SPLIT_MODE_OFF) {
63 cJSON *split_obj = cJSON_AddObjectToObject(rist_sender_stats, "split");
64 const char *mode_str = ctx->split_mode == LIBRIST_SPLIT_MODE_AUTO ? "auto" : "half";
65 cJSON_AddStringToObject(split_obj, "mode", mode_str);
66 cJSON_AddNumberToObject(split_obj, "pairs_emitted", (double)ctx->stats_pairs_emitted);
67 cJSON_AddNumberToObject(split_obj, "fallback_not_ts", (double)ctx->stats_split_fallback_not_ts);
68 }
69
70 char *stats_json = cJSON_PrintUnformatted(stats);
71 cJSON_Delete(stats);
72
73 if (ctx->sender_stats_callback != NULL)
74 ctx->sender_stats_callback(ctx->sender_stats_callback_argument, RIST_SENDER_STATS_VERSION, stats_json, (uint32_t)strlen(stats_json));
75
76 free(stats_json);
77 }
78
79 cJSON *rist_sender_peer_statistics(struct rist_peer *peer)
80 {
81 pthread_mutex_lock(&(get_cctx(peer)->stats_lock));
82 struct rist_stats *stats_container = malloc(sizeof(struct rist_stats));
83 stats_container->stats_type = RIST_STATS_SENDER_PEER;
84 stats_container->version = RIST_STATS_VERSION;
85
86 peer->stats_sender_total.received += peer->stats_sender_instant.received;
87
88 size_t retry_buf_size = rist_get_sender_retry_queue_size(peer->sender_ctx);
89
90 struct rist_bandwidth_estimation *cli_bw = &peer->bw;
91 struct rist_bandwidth_estimation *retry_bw = &peer->retry_bw;
92 struct rist_bandwidth_estimation *ts_nulls_bw = &peer->ts_nulls_bw;
93
94 // Refresh stats value just in case
95 rist_calculate_bitrate(0, cli_bw);
96 rist_calculate_bitrate(0, retry_bw);
97 rist_calculate_bitrate(0, ts_nulls_bw);
98
99 double Q = 100;
100 if (peer->stats_sender_instant.sent > 0)
101 {
102 Q = (double)((peer->stats_sender_instant.sent) * 100.0) /
103 (double)(peer->stats_sender_instant.sent + peer->stats_sender_instant.bloat_skip + peer->stats_sender_instant.bandwidth_skip + peer->stats_sender_instant.retrans_skip + peer->stats_sender_instant.retrans);
104 Q = round_two_digits(Q);
105 }
106
107 uint32_t time_left = 0;
108 if (peer->sender_ctx->cooldown_time > 0)
109 {
110 time_left = (uint32_t)(timestampNTP_u64() - peer->sender_ctx->cooldown_time) / 1000;
111 }
112
113 size_t bitrate = cli_bw->eight_times_bitrate_fast / 8;
114 size_t retry_bitrate = retry_bw->eight_times_bitrate_fast / 8;
115 size_t ts_nulls_bitrate = ts_nulls_bw->eight_times_bitrate_fast / 8;
116 double avg_rtt = ((double)peer->eight_times_rtt / 8);
117
118 struct rist_common_ctx *cctx = get_cctx(peer);
119
120 cJSON *peer_obj = cJSON_CreateObject();
121 cJSON_AddNumberToObject(peer_obj, "flow_id", peer->adv_flow_id);
122 cJSON_AddNumberToObject(peer_obj, "id", peer->adv_peer_id);
123 cJSON_AddStringToObject(peer_obj, "cname", peer->receiver_name);
124 cJSON_AddStringToObject(peer_obj, "type", peer->is_data ? "data" : "rtcp");
125 cJSON_AddNumberToObject(peer_obj, "profile", cctx->profile);
126 cJSON_AddStringToObject(peer_obj, "profile_name", rist_profile_name(cctx->profile));
127 cJSON_AddBoolToObject(peer_obj, "advanced_active", peer->is_advanced ? 1 : 0);
128 if (peer->miface[0])
129 cJSON_AddStringToObject(peer_obj, "miface", peer->miface);
130 cJSON *json_stats = cJSON_AddObjectToObject(peer_obj, "stats");
131 cJSON_AddNumberToObject(json_stats, "quality", Q);
132 cJSON_AddNumberToObject(json_stats, "sent", (double)peer->stats_sender_instant.sent);
133 cJSON_AddNumberToObject(json_stats, "ts_null", (double)peer->stats_sender_instant.ts_null);
134 cJSON_AddNumberToObject(json_stats, "received", (double)peer->stats_sender_instant.received);
135 cJSON_AddNumberToObject(json_stats, "retransmitted", (double)peer->stats_sender_instant.retrans);
136 cJSON_AddNumberToObject(json_stats, "sent_bytes", (double)peer->stats_sender_instant.sent_bytes);
137 cJSON_AddNumberToObject(json_stats, "retransmitted_bytes", (double)peer->stats_sender_instant.retransmitted_bytes);
138 cJSON_AddNumberToObject(json_stats, "bandwidth", (double)bitrate);
139 cJSON_AddNumberToObject(json_stats, "retry_bandwidth", (double)retry_bitrate);
140 cJSON_AddNumberToObject(json_stats, "ts_nulls_bandwidth", (double)ts_nulls_bitrate);
141 cJSON_AddNumberToObject(json_stats, "bandwidth_skipped", (double)peer->stats_sender_instant.bandwidth_skip);
142 cJSON_AddNumberToObject(json_stats, "bloat_skipped", (double)peer->stats_sender_instant.bloat_skip);
143 cJSON_AddNumberToObject(json_stats, "retransmit_skipped", (double)peer->stats_sender_instant.retrans_skip);
144 cJSON_AddNumberToObject(json_stats, "rtt", (double)peer->last_rtt / RIST_CLOCK);
145 cJSON_AddNumberToObject(json_stats, "avg_rtt", (double)avg_rtt / RIST_CLOCK);
146 cJSON_AddNumberToObject(json_stats, "retry_buffer_size", (double)retry_buf_size);
147 cJSON_AddNumberToObject(json_stats, "cooldown_time", (double)time_left);
148 cJSON *stats = cJSON_CreateObject();
149 cJSON_AddNumberToObject(stats, "schema_version", RIST_STATS_JSON_SCHEMA_VERSION);
150 cJSON *rist_sender_stats = cJSON_AddObjectToObject(stats, "sender-stats");
151 cJSON *peers = cJSON_AddArrayToObject(rist_sender_stats, "peers");
152 cJSON_AddItemToArray(peers, cJSON_Duplicate(peer_obj, true));
153 char *stats_string = cJSON_PrintUnformatted(stats);
154 cJSON_Delete(stats);
155
156 stats_container->stats_json = stats_string;
157 stats_container->json_size = (uint32_t)strlen(stats_string);
158 strncpy(stats_container->stats.sender_peer.cname,
159 peer->receiver_name,
160 sizeof(stats_container->stats.sender_peer.cname) - 1);
161 stats_container->stats.sender_peer.cname[sizeof(stats_container->stats.sender_peer.cname) - 1] = '\0';
162 stats_container->stats.sender_peer.peer_id = peer->adv_peer_id;
163 stats_container->stats.sender_peer.bandwidth = bitrate;
164 stats_container->stats.sender_peer.retry_bandwidth = retry_bitrate;
165 //stats_container->stats.sender_peer.ts_nulls_bandwidth = ts_nulls_bitrate;
166 stats_container->stats.sender_peer.sent = peer->stats_sender_instant.sent;
167 stats_container->stats.sender_peer.received = peer->stats_sender_instant.received;
168 stats_container->stats.sender_peer.retransmitted = peer->stats_sender_instant.retrans;
169 stats_container->stats.sender_peer.quality = Q;
170 stats_container->stats.sender_peer.rtt = avg_rtt / RIST_CLOCK;
171 stats_container->stats.sender_peer.sent_bytes = peer->stats_sender_instant.sent_bytes;
172 stats_container->stats.sender_peer.retransmitted_bytes = peer->stats_sender_instant.retransmitted_bytes;
173 stats_container->stats.sender_peer.profile = (uint8_t)cctx->profile;
174 stats_container->stats.sender_peer.advanced_active = peer->is_advanced ? 1 : 0;
175
176 if (cctx->stats_callback != NULL)
177 cctx->stats_callback(cctx->stats_callback_argument, stats_container);
178 else
179 rist_stats_free(stats_container);
180
181 memset(&peer->stats_sender_instant, 0, sizeof(peer->stats_sender_instant));
182 pthread_mutex_unlock(&(get_cctx(peer)->stats_lock));
183
184 return peer_obj;
185 }
186
187 void rist_receiver_flow_statistics(struct rist_receiver *ctx, struct rist_flow *flow)
188 {
189 if (!flow)
190 return;
191 pthread_mutex_lock(&ctx->common.stats_lock);
192 //Log errors that used to be packet
193 if (flow->stats_instant.dropped_full)
194 rist_log_priv(&ctx->common, RIST_LOG_ERROR, "Dropped %u packets due to buffers being full\n", flow->stats_instant.dropped_full );
195 if (flow->stats_instant.dropped_late)
196 rist_log_priv(&ctx->common, RIST_LOG_ERROR, "Dropped %u late packets\n", flow->stats_instant.dropped_late);
197 if (flow->stats_instant.lost)
198 rist_log_priv(&ctx->common, RIST_LOG_ERROR, "Lost %u packets\n", flow->stats_instant.lost);
199
200 struct rist_stats *stats_container = malloc(sizeof(struct rist_stats));
201 stats_container->stats_type = RIST_STATS_RECEIVER_FLOW;
202 stats_container->version = RIST_STATS_VERSION;
203
204 if (flow->stats_instant.avg_count)
205 {
206 flow->stats_instant.cur_ips = (flow->stats_instant.total_ips / flow->stats_instant.avg_count);
207 }
208
209 stats_container->stats.receiver_flow.peers = calloc(flow->peer_lst_len, sizeof(struct rist_stats_receiver_peer));
210
211 cJSON *stats = cJSON_CreateObject();
212 cJSON_AddNumberToObject(stats, "schema_version", RIST_STATS_JSON_SCHEMA_VERSION);
213 cJSON *stats_obj = cJSON_AddObjectToObject(stats, "receiver-stats");
214 cJSON *flow_obj = cJSON_AddObjectToObject(stats_obj, "flowinstant");
215 cJSON_AddNumberToObject(flow_obj, "flow_id", flow->flow_id);
216 cJSON_AddNumberToObject(flow_obj, "dead", flow->dead);
217 cJSON_AddNumberToObject(flow_obj, "profile", ctx->common.profile);
218 cJSON_AddStringToObject(flow_obj, "profile_name", rist_profile_name(ctx->common.profile));
219 cJSON_AddNumberToObject(flow_obj, "seq_bits", flow->short_seq ? 16 : 32);
220 cJSON_AddBoolToObject(flow_obj, "advanced_active",
221 (ctx->common.profile >= RIST_PROFILE_ADVANCED && !flow->short_seq) ? 1 : 0);
222 cJSON *json_stats = cJSON_AddObjectToObject(flow_obj, "stats");
223 cJSON *peers = cJSON_AddArrayToObject(flow_obj, "peers");
224 uint32_t flow_rtt = 0;
225 uint32_t flow_sent_instant = 0;
226 for (size_t i = 0; i < flow->peer_lst_len; i++)
227 {
228 struct rist_peer *peer = flow->peer_lst[i];
229 if (!peer->is_data && peer->peer_data)
230 peer = peer->peer_data;
231 double avg_rtt = ((double)peer->eight_times_rtt / 8);
232
233 size_t bitrate = peer->bw.eight_times_bitrate_fast / 8;
234 size_t avg_bitrate = peer->bw.eight_times_bitrate / 8;
235 flow_sent_instant += peer->stats_receiver_instant.sent_rtcp;
236 flow_rtt += (uint32_t)(peer->eight_times_rtt / 8);
237
238 cJSON *peer_obj = cJSON_CreateObject();
239 cJSON_AddNumberToObject(peer_obj, "id", peer->adv_peer_id);
240 cJSON_AddNumberToObject(peer_obj, "dead", peer->dead);
241 /* Listener-mode children have url=NULL; the configured URL
242 * lives on the parent peer. */
243 const char *peer_url_str = peer->url;
244 if ((peer_url_str == NULL || peer_url_str[0] == '\0') && peer->parent && peer->parent->url) {
245 peer_url_str = peer->parent->url;
246 }
247 cJSON_AddStringToObject(peer_obj, "url", peer_url_str ? peer_url_str : "");
248 cJSON *peer_stats = cJSON_AddObjectToObject(peer_obj, "stats");
249 cJSON_AddNumberToObject(peer_stats, "received_data", (double)peer->stats_receiver_instant.received);
250 cJSON_AddNumberToObject(peer_stats, "received_bytes", (double)peer->stats_receiver_instant.received_bytes);
251 cJSON_AddNumberToObject(peer_stats, "ts_null", (double)peer->stats_receiver_instant.ts_null);
252 cJSON_AddNumberToObject(peer_stats, "received_rtcp", (double)peer->stats_receiver_instant.received_rtcp);
253 cJSON_AddNumberToObject(peer_stats, "sent_rtcp", (double)peer->stats_receiver_instant.sent_rtcp);
254 cJSON_AddNumberToObject(peer_stats, "rtt", (double)peer->last_rtt / RIST_CLOCK);
255 cJSON_AddNumberToObject(peer_stats, "avg_rtt", (double)avg_rtt / RIST_CLOCK);
256 cJSON_AddNumberToObject(peer_stats, "bitrate", (double)bitrate);
257 cJSON_AddNumberToObject(peer_stats, "avg_bitrate", (double)avg_bitrate);
258 cJSON_AddItemToArray(peers, peer_obj);
259
260 stats_container->stats.receiver_flow.peers[i].peer_id = peer->adv_peer_id;
261 stats_container->stats.receiver_flow.peers[i].received_data = peer->stats_receiver_instant.received;
262 stats_container->stats.receiver_flow.peers[i].received_bytes = peer->stats_receiver_instant.received_bytes;
263 stats_container->stats.receiver_flow.peers[i].received_rtcp = peer->stats_receiver_instant.received_rtcp;
264 stats_container->stats.receiver_flow.peers[i].sent_rtcp = peer->stats_receiver_instant.sent_rtcp;
265 stats_container->stats.receiver_flow.peers[i].rtt = peer->last_rtt / RIST_CLOCK;
266 stats_container->stats.receiver_flow.peers[i].avg_rtt = avg_rtt / RIST_CLOCK;
267 stats_container->stats.receiver_flow.peers[i].bandwidth = bitrate;
268 stats_container->stats.receiver_flow.peers[i].avg_bandwidth = avg_bitrate;
269
270 // Clear peer instant stats
271 memset(&peer->stats_receiver_instant, 0, sizeof(peer->stats_receiver_instant));
272 }
273
274 flow->stats_instant.recovered_average = (flow->stats_instant.recovered_sum * 100) - flow->stats_instant.recovered;
275 flow->stats_instant.recovered_slope = flow->stats_instant.recovered_3nack - flow->stats_instant.recovered_0nack;
276 if ((int32_t)(flow->stats_instant.recovered_1nack - flow->stats_instant.recovered_0nack) > 0 &&
277 flow->stats_instant.recovered_1nack != 0 && flow->stats_instant.recovered_0nack != 0)
278 {
279 flow->stats_instant.recovered_slope_inverted++;
280 }
281
282 if ((int32_t)(flow->stats_instant.recovered_2nack - flow->stats_instant.recovered_1nack) > 0 &&
283 flow->stats_instant.recovered_2nack != 0 && flow->stats_instant.recovered_1nack != 0)
284 {
285 flow->stats_instant.recovered_slope_inverted++;
286 }
287
288 if ((int32_t)(flow->stats_instant.recovered_3nack - flow->stats_instant.recovered_2nack) > 0 &&
289 flow->stats_instant.recovered_3nack != 0 && flow->stats_instant.recovered_2nack != 0)
290 {
291 flow->stats_instant.recovered_slope_inverted++;
292 }
293
294 double Q = 100;
295 if (flow->stats_instant.received > 0)
296 {
297 Q = (double)((flow->stats_instant.received)*100.0) /
298 (double)(flow->stats_instant.received + flow->stats_instant.missing);
299 Q = round_two_digits(Q);
300 }
301
302 // This last one should trigger buffer protection immediately
303 if ((flow->missing_counter == 0 || flow->stats_instant.recovered == 0 ||
304 (flow->stats_instant.recovered * 10) < flow->stats_instant.missing) &&
305 flow->stats_instant.received > 10 &&
306 flow->stats_instant.received < flow->stats_instant.missing)
307 {
308 rist_log_priv(&ctx->common, RIST_LOG_INFO, "\tThe flow link is dead %" PRIu32 " > %" PRIu64 ", deleting all missing queue elements!\n",
309 flow->stats_instant.missing, flow->stats_instant.received);
310 /* Delete all missing queue elements (if any) */
311 rist_flush_missing_flow_queue(flow);
312 }
313
314 uint64_t avg_buffer_duration = 0;
315 if (flow->stats_instant.buffer_duration_count > 0)
316 {
317
318 for (size_t i = 0; i < flow->stats_instant.buffer_duration_count; i++)
319 {
320 avg_buffer_duration += flow->stats_instant.buffer_duration[i];
321 }
322 avg_buffer_duration /= flow->stats_instant.buffer_duration_count;
323 flow->stats_instant.buffer_duration_count = 0;
324 }
325 cJSON_AddNumberToObject(json_stats, "quality", Q);
326 cJSON_AddNumberToObject(json_stats, "received", (double)flow->stats_instant.received);
327 cJSON_AddNumberToObject(json_stats, "received_bytes", (double)flow->stats_instant.received_bytes);
328 cJSON_AddNumberToObject(json_stats, "dropped_late", (double)flow->stats_instant.dropped_late);
329 cJSON_AddNumberToObject(json_stats, "dropped_full", (double)flow->stats_instant.dropped_full);
330 cJSON_AddNumberToObject(json_stats, "missing", (double)flow->stats_instant.missing);
331 cJSON_AddNumberToObject(json_stats, "recovered_total", (double)flow->stats_instant.recovered);
332 cJSON_AddNumberToObject(json_stats, "reordered", (double)flow->stats_instant.reordered);
333 cJSON_AddNumberToObject(json_stats, "retries", (double)flow->stats_instant.retries);
334 cJSON_AddNumberToObject(json_stats, "recovered_one_nack", (double)flow->stats_instant.recovered_0nack);
335 cJSON_AddNumberToObject(json_stats, "recovered_two_nacks", (double)flow->stats_instant.recovered_1nack);
336 cJSON_AddNumberToObject(json_stats, "recovered_three_nacks", (double)flow->stats_instant.recovered_2nack);
337 cJSON_AddNumberToObject(json_stats, "recovered_four_nacks", (double)flow->stats_instant.recovered_3nack);
338 cJSON_AddNumberToObject(json_stats, "recovered_more_nacks", (double)flow->stats_instant.recovered_morenack);
339 cJSON_AddNumberToObject(json_stats, "lost", (double)flow->stats_instant.lost);
340 cJSON_AddNumberToObject(json_stats, "avg_buffer_time", (double)avg_buffer_duration);
341 cJSON_AddNumberToObject(json_stats, "duplicates", (double)flow->stats_instant.dupe);
342 cJSON_AddNumberToObject(json_stats, "missing_queue", (double)flow->missing_counter);
343 cJSON_AddNumberToObject(json_stats, "missing_queue_max", (double)flow->missing_counter_max);
344 cJSON_AddNumberToObject(json_stats, "min_inter_packet_spacing", (double)flow->stats_instant.min_ips);
345 cJSON_AddNumberToObject(json_stats, "cur_inter_packet_spacing", (double)flow->stats_instant.cur_ips);
346 cJSON_AddNumberToObject(json_stats, "max_inter_packet_spacing", (double)flow->stats_instant.max_ips);
347 /* Decay flow bitrate counters when no traffic has arrived since the last tick. */
348 rist_refresh_flow_bitrate(&flow->bw);
349 rist_refresh_flow_bitrate(&flow->bw_retries);
350 rist_refresh_flow_bitrate(&flow->bw_rejected);
351 rist_refresh_flow_bitrate(&flow->bw_tsnull);
352 cJSON_AddNumberToObject(json_stats, "bitrate", (double)flow->bw.bitrate);
353 cJSON_AddNumberToObject(json_stats, "bitrate_retries", (double)flow->bw_retries.bitrate);
354 cJSON_AddNumberToObject(json_stats, "bitrate_rejected", (double)flow->bw_rejected.bitrate);
355 cJSON_AddNumberToObject(json_stats, "bitrate_ts_nulls", (double)flow->bw_tsnull.bitrate);
356 cJSON_AddNumberToObject(json_stats, "bitrate_payload", (double)flow->bw.bitrate + (double)flow->bw_tsnull.bitrate);
357
358 if (ctx->merge_mode != LIBRIST_MERGE_MODE_OFF) {
359 cJSON *merge_obj = cJSON_AddObjectToObject(flow_obj, "merge");
360 const char *mode_str = ctx->merge_mode == LIBRIST_MERGE_MODE_AUTO ? "auto" : "pairs";
361 cJSON_AddStringToObject(merge_obj, "mode", mode_str);
362 cJSON_AddNumberToObject(merge_obj, "pairs_merged", (double)ctx->stats_pairs_merged);
363 cJSON_AddNumberToObject(merge_obj, "orphan_first_delivered", (double)ctx->stats_orphan_first_delivered);
364 cJSON_AddNumberToObject(merge_obj, "orphan_last_delivered", (double)ctx->stats_orphan_last_delivered);
365 }
366
367 char *stats_string = cJSON_PrintUnformatted(stats);
368 cJSON_Delete(stats);
369
370 stats_container->stats_json = stats_string;
371 stats_container->json_size = (uint32_t)strlen(stats_string);
372
373 stats_container->stats.receiver_flow.peer_count = (uint32_t)flow->peer_lst_len;
374 // TODO: populate stats_receiver_flow->cname
375 stats_container->stats.receiver_flow.cname[0] = '\0';
376 stats_container->stats.receiver_flow.flow_id = flow->flow_id;
377 stats_container->stats.receiver_flow.status = flow->dead;
378 stats_container->stats.receiver_flow.bandwidth = flow->bw.bitrate;
379 stats_container->stats.receiver_flow.retry_bandwidth = flow->bw_retries.bitrate;
380 //stats_container->stats.receiver_flow.ts_nulls_bandwidth = flow->bw_tsnull.bitrate;
381 stats_container->stats.receiver_flow.sent = flow->peer_lst_len ? flow_sent_instant / flow->peer_lst_len : 0;
382 stats_container->stats.receiver_flow.received = flow->stats_instant.received;
383 stats_container->stats.receiver_flow.received_bytes = flow->stats_instant.received_bytes;
384 stats_container->stats.receiver_flow.missing = flow->stats_instant.missing;
385 stats_container->stats.receiver_flow.reordered = flow->stats_instant.reordered;
386 stats_container->stats.receiver_flow.recovered = flow->stats_instant.recovered;
387 stats_container->stats.receiver_flow.recovered_one_retry = flow->stats_instant.recovered_0nack;
388 stats_container->stats.receiver_flow.lost = flow->stats_instant.lost;
389 stats_container->stats.receiver_flow.quality = Q;
390 stats_container->stats.receiver_flow.min_inter_packet_spacing = flow->stats_instant.min_ips;
391 stats_container->stats.receiver_flow.cur_inter_packet_spacing = flow->stats_instant.cur_ips;
392 stats_container->stats.receiver_flow.max_inter_packet_spacing = flow->stats_instant.max_ips;
393 stats_container->stats.receiver_flow.rtt = flow->peer_lst_len ? (flow_rtt / flow->peer_lst_len)/RIST_CLOCK : 0;
394 stats_container->stats.receiver_flow.avg_buffer_time = avg_buffer_duration;
395 stats_container->stats.receiver_flow.profile = (uint8_t)ctx->common.profile;
396 stats_container->stats.receiver_flow.seq_bits = flow->short_seq ? 16 : 32;
397 stats_container->stats.receiver_flow.advanced_active =
398 (ctx->common.profile >= RIST_PROFILE_ADVANCED && !flow->short_seq) ? 1 : 0;
399
400 /* CALLBACK CALL */
401 if (ctx->common.stats_callback != NULL)
402 ctx->common.stats_callback(ctx->common.stats_callback_argument, stats_container);
403 else
404 rist_stats_free(stats_container);
405
406 memset(&flow->stats_instant, 0, sizeof(flow->stats_instant));
407 flow->stats_instant.min_ips = 0xFFFFFFFFFFFFFFFFULL;
408 pthread_mutex_unlock(&ctx->common.stats_lock);
409 }