From 47a39092fe7d1fd4ab7445a6b60828d2491117c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=96man?= Date: Sun, 2 Dec 2007 14:31:28 +0000 Subject: [PATCH] introduce 'channel group' concept. Not used yet though --- channels.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++---- channels.h | 2 -- epg.c | 2 +- epg_xmltv.c | 2 +- htmlui.c | 4 +-- htsclient.c | 5 ++- rpc.c | 2 +- rtsp.c | 2 +- tvhead.h | 27 +++++++++++++--- 9 files changed, 115 insertions(+), 21 deletions(-) diff --git a/channels.c b/channels.c index 386402ae..07bb4c63 100644 --- a/channels.c +++ b/channels.c @@ -38,12 +38,63 @@ #include "channels.h" #include "transports.h" -struct th_channel_queue channels; +struct th_channel_list channels; struct th_transport_list all_transports; int nchannels; +struct th_channel_group_list all_channel_groups; + void scanner_init(void); +/** + * + */ +static int +ch_order_cmp(th_channel_t *a, th_channel_t *b) +{ + return a->ch_order - b->ch_order; +} + +/** + * + */ +th_channel_group_t * +channel_group_find(const char *name, int create) +{ + th_channel_group_t *tcg; + + LIST_FOREACH(tcg, &all_channel_groups, tcg_global_link) { + if(!strcmp(name, tcg->tcg_name)) + break; + } + if(!create) + return NULL; + + tcg = calloc(1, sizeof(th_channel_group_t)); + tcg->tcg_name = strdup(name); + LIST_INSERT_HEAD(&all_channel_groups, tcg, tcg_global_link); + return tcg; +} + +/** + * + */ +void +channel_set_group(th_channel_t *ch, const char *groupname) +{ + th_channel_group_t *tcg; + + if(ch->ch_group != NULL) + LIST_REMOVE(ch, ch_group_link); + + tcg = channel_group_find(groupname, 1); + ch->ch_group = tcg; + LIST_INSERT_SORTED(&tcg->tcg_channels, ch, ch_group_link, ch_order_cmp); +} + +/** + * + */ th_channel_t * channel_find(const char *name, int create) { @@ -52,7 +103,7 @@ channel_find(const char *name, int create) int l, i; char *cp, c; - TAILQ_FOREACH(ch, &channels, ch_global_link) + LIST_FOREACH(ch, &channels, ch_global_link) if(!strcasecmp(name, ch->ch_name)) return ch; @@ -81,13 +132,20 @@ channel_find(const char *name, int create) ch->ch_index = nchannels; TAILQ_INIT(&ch->ch_epg_events); - TAILQ_INSERT_TAIL(&channels, ch, ch_global_link); + ch->ch_order = nchannels + 1000; + LIST_INSERT_SORTED(&channels, ch, ch_global_link, ch_order_cmp); + + channel_set_group(ch, "Default"); + ch->ch_tag = tag_get(); nchannels++; return ch; } +/** + * + */ static int transportcmp(th_transport_t *a, th_transport_t *b) { @@ -95,6 +153,9 @@ transportcmp(th_transport_t *a, th_transport_t *b) } +/** + * + */ int transport_set_channel(th_transport_t *t, th_channel_t *ch) { @@ -125,6 +186,9 @@ transport_set_channel(th_transport_t *t, th_channel_t *ch) +/** + * + */ static void service_load(struct config_head *head) { @@ -157,6 +221,9 @@ service_load(struct config_head *head) free(t); } +/** + * + */ void transport_link(th_transport_t *t, th_channel_t *ch) { @@ -167,6 +234,9 @@ transport_link(th_transport_t *t, th_channel_t *ch) +/** + * + */ static void channel_load(struct config_head *head) { @@ -186,11 +256,13 @@ channel_load(struct config_head *head) } +/** + * + */ void channels_load(void) { config_entry_t *ce; - TAILQ_INIT(&channels); TAILQ_FOREACH(ce, &config_list, ce_link) { if(ce->ce_type == CFG_SUB && !strcasecmp("channel", ce->ce_key)) { @@ -206,12 +278,15 @@ channels_load(void) } +/** + * The index stuff should go away + */ th_channel_t * channel_by_index(uint32_t index) { th_channel_t *ch; - TAILQ_FOREACH(ch, &channels, ch_global_link) + LIST_FOREACH(ch, &channels, ch_global_link) if(ch->ch_index == index) return ch; @@ -220,12 +295,15 @@ channel_by_index(uint32_t index) +/** + * + */ th_channel_t * channel_by_tag(uint32_t tag) { th_channel_t *ch; - TAILQ_FOREACH(ch, &channels, ch_global_link) + LIST_FOREACH(ch, &channels, ch_global_link) if(ch->ch_tag == tag) return ch; diff --git a/channels.h b/channels.h index 58bd79a3..b8c3a7ef 100644 --- a/channels.h +++ b/channels.h @@ -19,8 +19,6 @@ #ifndef CHANNELS_H #define CHANNELS_H -extern struct th_channel_queue channels; - void channels_load(void); th_channel_t *channel_by_index(uint32_t id); diff --git a/epg.c b/epg.c index 34a6ebd1..c73c9f8c 100644 --- a/epg.c +++ b/epg.c @@ -407,7 +407,7 @@ epg_channel_maintain(void *aux, int64_t clk) epg_lock(); - TAILQ_FOREACH(ch, &channels, ch_global_link) { + LIST_FOREACH(ch, &channels, ch_global_link) { /* Age out any old events */ diff --git a/epg_xmltv.c b/epg_xmltv.c index f78f0d19..c97faadb 100644 --- a/epg_xmltv.c +++ b/epg_xmltv.c @@ -308,7 +308,7 @@ xmltv_resolve_by_events(xmltv_channel_t *xc) if(ex == NULL) break; - TAILQ_FOREACH(ch, &channels, ch_global_link) { + LIST_FOREACH(ch, &channels, ch_global_link) { ec = epg_event_find_by_time0(&ch->ch_epg_events, now); cnt = 0; diff --git a/htmlui.c b/htmlui.c index d1ab8c0a..eb74a435 100644 --- a/htmlui.c +++ b/htmlui.c @@ -404,7 +404,7 @@ page_root(http_connection_t *hc, const char *remain, void *opaque) tcp_init_queue(&tq, -1); - TAILQ_FOREACH(ch, &channels, ch_global_link) { + LIST_FOREACH(ch, &channels, ch_global_link) { e = epg_event_find_current_or_upcoming(ch); if(e && e->e_start + e->e_duration < firstend) { firstend = e->e_start + e->e_duration; @@ -418,7 +418,7 @@ page_root(http_connection_t *hc, const char *remain, void *opaque) html_header(&tq, "HTS/tvheadend", !simple, 700, i); top_menu(hc, &tq); - TAILQ_FOREACH(ch, &channels, ch_global_link) { + LIST_FOREACH(ch, &channels, ch_global_link) { box_top(&tq, "box"); tcp_qprintf(&tq, "
"); diff --git a/htsclient.c b/htsclient.c index 90ed244b..8a734018 100644 --- a/htsclient.c +++ b/htsclient.c @@ -222,8 +222,7 @@ cr_show(client_t *c, char **argv, int argc) if(!strcasecmp(subcmd, "channel")) { - - TAILQ_FOREACH(ch, &channels, ch_global_link) { + LIST_FOREACH(ch, &channels, ch_global_link) { tmp = utf8toprintable(ch->ch_name); cprintf(c, "%3d: \"%s\"\n", ch->ch_index, tmp); @@ -491,7 +490,7 @@ cr_channels_list(client_t *c, char **argv, int argc) { th_channel_t *ch; - TAILQ_FOREACH(ch, &channels, ch_global_link) + LIST_FOREACH(ch, &channels, ch_global_link) cprintf(c, "channel = %d\n", ch->ch_index); return 0; diff --git a/rpc.c b/rpc.c index fae09c97..d6f8c05f 100644 --- a/rpc.c +++ b/rpc.c @@ -150,7 +150,7 @@ rpc_channels_list(rpc_session_t *ses, htsmsg_t *in, void *opaque) out = htsmsg_create(); htsmsg_add_u32(out, "seq", ses->rs_seq); - TAILQ_FOREACH(ch, &channels, ch_global_link) + LIST_FOREACH(ch, &channels, ch_global_link) htsmsg_add_msg(out, "channel", rpc_build_channel_msg(ch)); return out; diff --git a/rtsp.c b/rtsp.c index ffcec08b..891385d6 100644 --- a/rtsp.c +++ b/rtsp.c @@ -104,7 +104,7 @@ rtsp_channel_by_url(char *url) return NULL; c++; - TAILQ_FOREACH(ch, &channels, ch_global_link) + LIST_FOREACH(ch, &channels, ch_global_link) if(!strcasecmp(ch->ch_sname, c)) return ch; diff --git a/tvhead.h b/tvhead.h index f9a47a36..5636b614 100644 --- a/tvhead.h +++ b/tvhead.h @@ -69,6 +69,8 @@ typedef struct dtimer { LIST_HEAD(th_subscription_list, th_subscription); TAILQ_HEAD(th_channel_queue, th_channel); +LIST_HEAD(th_channel_list, th_channel); +LIST_HEAD(th_channel_group_list, th_channel_group); LIST_HEAD(th_dvb_adapter_list, th_dvb_adapter); LIST_HEAD(th_v4l_adapter_list, th_v4l_adapter); LIST_HEAD(event_list, event); @@ -88,7 +90,7 @@ LIST_HEAD(th_muxstream_list, th_muxstream); extern time_t dispatch_clock; extern int startupcounter; extern struct th_transport_list all_transports; -extern struct th_channel_queue channels; +extern struct th_channel_list channels; extern struct pvr_rec_list pvrr_global_list; extern struct th_subscription_list subscriptions; @@ -613,22 +615,39 @@ typedef struct tt_decoder { } tt_decoder_t; +/** + * Channel groups + */ +typedef struct th_channel_group { + LIST_ENTRY(th_channel_group) tcg_global_link; + + const char *tcg_name; + struct th_channel_list tcg_channels; + +} th_channel_group_t; + + /* * Channel definition */ typedef struct th_channel { - TAILQ_ENTRY(th_channel) ch_global_link; + LIST_ENTRY(th_channel) ch_global_link; + + int ch_order; + + LIST_ENTRY(th_channel) ch_group_link; + th_channel_group_t *ch_group; + LIST_HEAD(, th_transport) ch_transports; LIST_HEAD(, th_subscription) ch_subscriptions; + int ch_index; const char *ch_name; const char *ch_sname; - struct pvr_rec *ch_rec; - struct tt_decoder ch_tt; int ch_tag;