Some initial epg_channel_t to channel_t linking.

This commit is contained in:
Adam Sutton 2012-05-21 11:00:51 +01:00
parent 1e21969095
commit 6cb00158c6
5 changed files with 64 additions and 68 deletions

View file

@ -32,9 +32,8 @@
#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"
@ -164,7 +163,6 @@ static channel_t *
channel_create(const char *name, int number)
{
channel_t *ch, *x;
//xmltv_channel_t *xc;
int id;
ch = RB_LAST(&channel_identifier_tree);
@ -175,12 +173,6 @@ channel_create(const char *name, int number)
}
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;
@ -190,13 +182,7 @@ channel_create(const char *name, int 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;
@ -242,7 +228,6 @@ static void
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;
@ -262,22 +247,9 @@ channel_load_one(htsmsg_t *c, int id)
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"));
@ -332,11 +304,6 @@ channel_save(channel_t *ch)
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);
@ -411,7 +378,7 @@ channel_delete(channel_t *ch)
s->ths_channel = NULL;
}
//epg_unlink_from_channel(ch);
epg_rem_channel(ch);
hts_settings_remove("channels/%d", ch->ch_id);
@ -420,8 +387,6 @@ channel_delete(channel_t *ch)
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);
@ -517,31 +482,14 @@ channel_set_number(channel_t *ch, int number)
/**
*
*/
#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
/**
*

View file

@ -44,11 +44,7 @@ typedef struct channel {
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;
@ -117,6 +113,8 @@ void channel_delete(channel_t *ch);
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);

View file

@ -26,6 +26,7 @@
#include <assert.h>
#include "tvheadend.h"
#include "queue.h"
#include "channels.h"
#include "settings.h"
#include "epg.h"
@ -38,6 +39,11 @@ struct epg_season_tree epg_seasons;
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
* *************************************************************************/
@ -74,6 +80,18 @@ static int ptr_cmp ( void *a, void *b )
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
* *************************************************************************/
@ -141,6 +159,25 @@ void epg_updated ( void )
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
@ -637,6 +674,14 @@ epg_broadcast_t *epg_broadcast_get_next ( epg_broadcast_t *broadcast )
* 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;
@ -658,6 +703,7 @@ epg_channel_t* epg_channel_find_by_uri ( const char *id, int create )
ec = skel;
skel = NULL;
ec->ec_uri = strdup(id);
LIST_INSERT_HEAD(&epg_unlinked_channels1, ec, ec_ulink);
}
}
@ -670,7 +716,8 @@ int epg_channel_set_name ( epg_channel_t *channel, const char *name )
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;

View file

@ -241,6 +241,7 @@ typedef struct epg_channel
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)
@ -295,6 +296,12 @@ void epg_save(void);
void epg_updated ( void );
/*
* Channel linking
*/
void epg_add_channel ( channel_t *ch );
void epg_rem_channel ( channel_t *ch );
/*
* Simple lookup
*/

View file

@ -67,14 +67,10 @@ dumpchannels(htsbuf_queue_t *hq)
" 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>");
}
}