introduce 'channel group' concept. Not used yet though

This commit is contained in:
Andreas Öman 2007-12-02 14:31:28 +00:00
parent 80f5555d03
commit 47a39092fe
9 changed files with 115 additions and 21 deletions

View file

@ -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;

View file

@ -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);

2
epg.c
View file

@ -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 */

View file

@ -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;

View file

@ -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, "<div class=\"content3\">");

View file

@ -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;

2
rpc.c
View file

@ -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;

2
rtsp.c
View file

@ -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;

View file

@ -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;