Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
stream status: add possibility to clear statistics, introduce tvh_inp…
…ut_instance_t
  • Loading branch information
perexg committed Apr 17, 2015
1 parent abb1409 commit bda5d8c
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 117 deletions.
40 changes: 40 additions & 0 deletions src/api/api_status.c
Expand Up @@ -37,8 +37,10 @@ api_status_inputs
tvh_input_stream_t *st;
tvh_input_stream_list_t stl = { 0 };

pthread_mutex_lock(&global_lock);
TVH_INPUT_FOREACH(ti)
ti->ti_get_streams(ti, &stl);
pthread_mutex_unlock(&global_lock);

l = htsmsg_create_list();
while ((st = LIST_FIRST(&stl))) {
Expand Down Expand Up @@ -67,11 +69,13 @@ api_status_subscriptions

l = htsmsg_create_list();
c = 0;
pthread_mutex_lock(&global_lock);
LIST_FOREACH(ths, &subscriptions, ths_global_link) {
e = subscription_create_msg(ths);
htsmsg_add_msg(l, NULL, e);
c++;
}
pthread_mutex_unlock(&global_lock);

*resp = htsmsg_create_map();
htsmsg_add_msg(*resp, "entries", l);
Expand Down Expand Up @@ -120,12 +124,48 @@ api_connections_cancel
return 0;
}

static void
input_clear_stats(const char *uuid)
{
tvh_input_instance_t *tii;

pthread_mutex_lock(&global_lock);
if ((tii = tvh_input_instance_find_by_uuid(uuid)) != NULL)
if (tii->tii_clear_stats)
tii->tii_clear_stats(tii);
pthread_mutex_unlock(&global_lock);
}

static int
api_status_input_clear_stats
( access_t *perm, void *opaque, const char *op, htsmsg_t *args, htsmsg_t **resp )
{
htsmsg_field_t *f;
htsmsg_t *ids;
const char *uuid;

if (!(f = htsmsg_field_find(args, "uuid")))
return EINVAL;
if (!(ids = htsmsg_field_get_list(f))) {
if ((uuid = htsmsg_field_get_str(f)) == NULL)
return EINVAL;
input_clear_stats(uuid);
} else {
HTSMSG_FOREACH(f, ids) {
if ((uuid = htsmsg_field_get_str(f)) == NULL) continue;
input_clear_stats(uuid);
}
}
return 0;
}

void api_status_init ( void )
{
static api_hook_t ah[] = {
{ "status/connections", ACCESS_ADMIN, api_status_connections, NULL },
{ "status/subscriptions", ACCESS_ADMIN, api_status_subscriptions, NULL },
{ "status/inputs", ACCESS_ADMIN, api_status_inputs, NULL },
{ "status/inputclrstats", ACCESS_ADMIN, api_status_input_clear_stats, NULL },
{ "connections/cancel", ACCESS_ADMIN, api_connections_cancel, NULL },
{ NULL },
};
Expand Down
25 changes: 25 additions & 0 deletions src/input.c
Expand Up @@ -18,10 +18,18 @@

#include "input.h"
#include "notify.h"
#include "access.h"

tvh_input_list_t tvh_inputs;
tvh_hardware_list_t tvh_hardware;

const idclass_t tvh_input_instance_class =
{
.ic_class = "tvh_input_instance",
.ic_caption = "Input Instance",
.ic_perm_def = ACCESS_ADMIN
};

/*
* Create entry
*/
Expand Down Expand Up @@ -59,6 +67,23 @@ tvh_hardware_delete ( tvh_hardware_t *th )
idnode_unlink(&th->th_id);
}

/*
*
*/

void
tvh_input_instance_clear_stats ( tvh_input_instance_t *tii )
{
tvh_input_stream_stats_t *s = &tii->tii_stats;

atomic_exchange(&s->ber, 0);
atomic_exchange(&s->unc, 0);
atomic_exchange(&s->cc, 0);
atomic_exchange(&s->te, 0);
atomic_exchange(&s->ec_block, 0);
atomic_exchange(&s->tc_block, 0);
}

/*
* Input status handling
*/
Expand Down
22 changes: 22 additions & 0 deletions src/input.h
Expand Up @@ -27,6 +27,7 @@
*/
typedef struct tvh_hardware tvh_hardware_t;
typedef struct tvh_input tvh_input_t;
typedef struct tvh_input_instance tvh_input_instance_t;
typedef struct tvh_input_stream tvh_input_stream_t;
typedef struct tvh_input_stream_stats tvh_input_stream_stats_t;

Expand Down Expand Up @@ -87,6 +88,20 @@ struct tvh_input {
void (*ti_get_streams) (struct tvh_input *, tvh_input_stream_list_t*);
};

/*
* Generic input instance super-class
*/
struct tvh_input_instance {
idnode_t tii_id;

LIST_ENTRY(tvh_input_instance) tii_input_link;

tvh_input_stream_stats_t tii_stats;

void (*tii_delete) (tvh_input_instance_t *tii);
void (*tii_clear_stats) (tvh_input_instance_t *tii);
};

/*
* Generic hardware super-class
*/
Expand All @@ -103,6 +118,7 @@ void tvh_hardware_delete ( tvh_hardware_t *th );
* Class and Global list defs
*/
extern const idclass_t tvh_input_class;
extern const idclass_t tvh_input_instance_class;

tvh_input_list_t tvh_inputs;
tvh_hardware_list_t tvh_hardware;
Expand All @@ -120,6 +136,12 @@ htsmsg_t * tvh_input_stream_create_msg ( tvh_input_stream_t *st );

void tvh_input_stream_destroy ( tvh_input_stream_t *st );

static inline tvh_input_instance_t *
tvh_input_instance_find_by_uuid(const char *uuid)
{ return (tvh_input_instance_t*)idnode_find(uuid, &tvh_input_instance_class, NULL); }

void tvh_input_instance_clear_stats ( tvh_input_instance_t *tii );

/*
* Input subsystem includes
*/
Expand Down
11 changes: 3 additions & 8 deletions src/input/mpegts.h
Expand Up @@ -548,22 +548,17 @@ struct mpegts_service
/* Physical mux instance */
struct mpegts_mux_instance
{
idnode_t mmi_id;
tvh_input_instance_t;

LIST_ENTRY(mpegts_mux_instance) mmi_mux_link;
LIST_ENTRY(mpegts_mux_instance) mmi_input_link;
LIST_ENTRY(mpegts_mux_instance) mmi_active_link;

streaming_pad_t mmi_streaming_pad;

mpegts_mux_t *mmi_mux;
mpegts_input_t *mmi_input;

tvh_input_stream_stats_t mmi_stats;

int mmi_tune_failed;

void (*mmi_delete) (mpegts_mux_instance_t *mmi);
};

struct mpegts_mux_sub
Expand Down Expand Up @@ -598,7 +593,7 @@ struct mpegts_input

mpegts_network_link_list_t mi_networks;

LIST_HEAD(,mpegts_mux_instance) mi_mux_instances;
LIST_HEAD(,tvh_input_instance) mi_mux_instances;


/*
Expand Down Expand Up @@ -795,7 +790,7 @@ mpegts_service_t *mpegts_mux_find_service(mpegts_mux_t *ms, uint16_t sid);
&type##_class, uuid,\
mi, mm);

void mpegts_mux_instance_delete ( mpegts_mux_instance_t *mmi );
void mpegts_mux_instance_delete ( tvh_input_instance_t *tii );

int mpegts_mux_instance_start
( mpegts_mux_instance_t **mmiptr );
Expand Down

0 comments on commit bda5d8c

Please sign in to comment.