#include "tvheadend.h"
#include "psi.h"
-#include "channels.h"
#include "epg.h"
-//#include "xmltv.h"
+#include "channels.h"
#include "dtable.h"
#include "notify.h"
#include "dvr/dvr.h"
channel_create(const char *name, int number)
{
channel_t *ch, *x;
- //xmltv_channel_t *xc;
int id;
ch = RB_LAST(&channel_identifier_tree);
}
ch = calloc(1, sizeof(channel_t));
-#if TODO_EPG_CHANNEL
- RB_INIT(&ch->ch_epg_events);
-#endif
-#if TODO_XMLTV
- LIST_INSERT_HEAD(&channels_not_xmltv_mapped, ch, ch_xc_link);
-#endif
channel_set_name(ch, name);
ch->ch_number = number;
assert(x == NULL);
-#if TODO_XMLTV
- if((xc = xmltv_channel_find_by_displayname(name)) != NULL) {
- channel_set_xmltv_source(ch, xc);
- if(xc->xc_icon != NULL)
- channel_set_icon(ch, xc->xc_icon);
- }
-#endif
+ epg_add_channel(ch);
htsp_channel_add(ch);
return ch;
channel_load_one(htsmsg_t *c, int id)
{
channel_t *ch;
- //const char *s;
const char *name = htsmsg_get_str(c, "name");
htsmsg_t *tags;
htsmsg_field_t *f;
return;
}
-#if TODO_EPG_CHANNEL
- RB_INIT(&ch->ch_epg_events);
-#endif
-
channel_set_name(ch, name);
-#if TODO_XMLTV
- if((s = htsmsg_get_str(c, "xmltv-channel")) != NULL &&
- (ch->ch_xc = xmltv_channel_find(s, 0)) != NULL) {
- LIST_INSERT_HEAD(&ch->ch_xc->xc_channels, ch, ch_xc_link);
- tvh_str_update(&ch->ch_icon, ch->ch_xc->xc_icon);
- } else {
- LIST_INSERT_HEAD(&channels_not_xmltv_mapped, ch, ch_xc_link);
- }
-#endif
-
+ epg_add_channel(ch);
tvh_str_update(&ch->ch_icon, htsmsg_get_str(c, "icon"));
htsmsg_add_str(m, "name", ch->ch_name);
-#if TODO_XMLTV
- if(ch->ch_xc != NULL)
- htsmsg_add_str(m, "xmltv-channel", ch->ch_xc->xc_identifier);
-#endif
-
if(ch->ch_icon != NULL)
htsmsg_add_str(m, "icon", ch->ch_icon);
s->ths_channel = NULL;
}
- //epg_unlink_from_channel(ch);
+ epg_rem_channel(ch);
hts_settings_remove("channels/%d", ch->ch_id);
RB_REMOVE(&channel_name_tree, ch, ch_name_link);
RB_REMOVE(&channel_identifier_tree, ch, ch_identifier_link);
- //LIST_REMOVE(ch, ch_xc_link);
-
free(ch->ch_name);
free(ch->ch_sname);
free(ch->ch_icon);
/**
*
*/
-#if TODO_XMLTV
void
-channel_set_xmltv_source(channel_t *ch, xmltv_channel_t *xc)
+channel_set_epg_source(channel_t *ch, epg_channel_t *ec)
{
lock_assert(&global_lock);
- if(xc == ch->ch_xc)
+ if(ec == ch->ch_epg_channel)
return;
-
- LIST_REMOVE(ch, ch_xc_link);
-
- if(xc == NULL) {
- LIST_INSERT_HEAD(&channels_not_xmltv_mapped, ch, ch_xc_link);
- } else {
- LIST_INSERT_HEAD(&xc->xc_channels, ch, ch_xc_link);
- }
- ch->ch_xc = xc;
-
- if(xc != NULL)
- tvh_str_update(&ch->ch_icon, xc->xc_icon);
-
- channel_save(ch);
}
-#endif
-
/**
*
LIST_HEAD(, th_subscription) ch_subscriptions;
struct epg_channel *ch_epg_channel;
-#if TODO_EPG_CHANNEL
- struct event_tree ch_epg_events;
- struct event *ch_epg_current;
- struct event *ch_epg_next;
-#endif
+ LIST_ENTRY(channel) ch_eulink;
gtimer_t ch_epg_timer_head;
gtimer_t ch_epg_timer_current;
void channel_merge(channel_t *dst, channel_t *src);
+void channel_set_epg_source(channel_t *ch, struct epg_channel *ec);
+
void channel_set_epg_postpre_time(channel_t *ch, int pre, int mins);
void channel_set_number(channel_t *ch, int number);
#include <assert.h>
#include "tvheadend.h"
+#include "queue.h"
#include "channels.h"
#include "settings.h"
#include "epg.h"
struct epg_episode_tree epg_episodes;
struct epg_channel_tree epg_channels;
+LIST_HEAD(epg_unlinked_channel_list1, epg_channel);
+LIST_HEAD(epg_unlinked_channel_list2, channel);
+struct epg_unlinked_channel_list1 epg_unlinked_channels1;
+struct epg_unlinked_channel_list2 epg_unlinked_channels2;
+
/* **************************************************************************
* Comparators
* *************************************************************************/
return a - b;
}
+static int epg_channel_match ( epg_channel_t *ec, channel_t *ch )
+{
+ int ret = 0;
+ if ( !strcmp(ec->ec_name, ch->ch_name) ) ret = 1;
+ if ( ret ) {
+ LIST_REMOVE(ec, ec_ulink);
+ channel_set_epg_source(ch, ec);
+ ec->ec_channel = ch;
+ }
+ return ret;
+}
+
/* **************************************************************************
* Testing/Debug
* *************************************************************************/
if (0)_epg_dump();
}
+void epg_add_channel ( channel_t *ch )
+{
+ epg_channel_t *ec;
+ LIST_FOREACH(ec, &epg_unlinked_channels1, ec_ulink) {
+ if ( epg_channel_match(ec, ch) ) break;
+ }
+ LIST_INSERT_HEAD(&epg_unlinked_channels2, ch, ch_eulink);
+}
+
+void epg_rem_channel ( channel_t *ch )
+{
+ if ( ch->ch_epg_channel ) {
+ ch->ch_epg_channel->ec_channel = NULL;
+ // TODO: free the channel?
+ } else {
+ LIST_REMOVE(ch, ch_eulink);
+ }
+}
+
/* **************************************************************************
* Brand
* Channel
* *************************************************************************/
+static void _epg_channel_link ( epg_channel_t *ec )
+{
+ channel_t *ch;
+ LIST_FOREACH(ch, &epg_unlinked_channels2, ch_eulink) {
+ if ( epg_channel_match(ec, ch) ) break;
+ }
+}
+
epg_channel_t* epg_channel_find_by_uri ( const char *id, int create )
{
epg_channel_t *ec;
ec = skel;
skel = NULL;
ec->ec_uri = strdup(id);
+ LIST_INSERT_HEAD(&epg_unlinked_channels1, ec, ec_ulink);
}
}
if ( !channel || !name ) return 0;
if ( !channel->ec_name || strcmp(channel->ec_name, name) ) {
channel->ec_name = strdup(name);
- // TODO: lookup real channel
+ _epg_channel_link(channel);
+ // TODO: will this cope with an already linked channel?
save = 1;
}
return save;
int **ec_sid; ///< DVB svc ids (to map)
channel_t *ec_channel; ///< Link to real channel
+ LIST_ENTRY(epg_channel) ec_ulink; ///< Unlinked list
struct epg_broadcast_tree ec_schedule; ///< Schedule (broadcasts)
void epg_updated ( void );
+/*
+ * Channel linking
+ */
+void epg_add_channel ( channel_t *ch );
+void epg_rem_channel ( channel_t *ch );
+
/*
* Simple lookup
*/
" refcount = %d\n"
" zombie = %d\n"
" number = %d\n"
- " xmltv source = %s\n"
" icon = %s\n\n",
ch->ch_refcount,
ch->ch_zombie,
ch->ch_number,
-#if TODO_XMLTV
- ch->ch_xc ? ch->ch_xc->xc_displayname : "<none set>",
-#endif
ch->ch_icon ?: "<none set>");
}
}