Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
store the byte count during the last second for each subscription and…
… include it in subscription status messages. This way a client who wants to poll for the average bitrate of a subscription doesn't have to use the comet poller to get an accurate bitrate reading.
  • Loading branch information
Sam Stenvall authored and perexg committed Sep 2, 2015
1 parent 50f950c commit 26dabb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/subscriptions.c
Expand Up @@ -889,6 +889,9 @@ subscription_create_msg(th_subscription_t *s)
else if(s->ths_dvrfile != NULL)
htsmsg_add_str(m, "service", s->ths_dvrfile ?: "");

htsmsg_add_u32(m, "in", s->ths_bytes_in_prev);
htsmsg_add_u32(m, "out", s->ths_bytes_out_prev);

return m;
}

Expand All @@ -906,14 +909,11 @@ subscription_status_callback ( void *p )
subscription_status_callback, NULL, 1);

LIST_FOREACH(s, &subscriptions, ths_global_link) {
int errors = s->ths_total_err;
int in = atomic_exchange(&s->ths_bytes_in, 0);
int out = atomic_exchange(&s->ths_bytes_out, 0);
/* Store the previous periods byte count */
s->ths_bytes_in_prev = atomic_exchange(&s->ths_bytes_in, 0);
s->ths_bytes_out_prev = atomic_exchange(&s->ths_bytes_out, 0);

htsmsg_t *m = subscription_create_msg(s);
htsmsg_delete_field(m, "errors");
htsmsg_add_u32(m, "errors", errors);
htsmsg_add_u32(m, "in", in);
htsmsg_add_u32(m, "out", out);
htsmsg_add_u32(m, "updateEntry", 1);
notify_by_msg("subscriptions", m);
count++;
Expand Down
2 changes: 2 additions & 0 deletions src/subscriptions.h
Expand Up @@ -90,6 +90,8 @@ typedef struct th_subscription {
uint64_t ths_total_bytes_out; /* total bytes since the subscription started */
int ths_bytes_in; // Reset every second to get aprox. bandwidth (in)
int ths_bytes_out; // Reset every second to get approx bandwidth (out)
int ths_bytes_in_prev; /* Bytes received during the last second */
int ths_bytes_out_prev; /* Bytes sent during the last second */

streaming_target_t ths_input;

Expand Down

0 comments on commit 26dabb7

Please sign in to comment.