2007-08-09 15:42:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* tvheadend, channel functions
|
|
|
|
|
* Copyright (C) 2007 Andreas <EFBFBD>man
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <fcntl.h>
|
2007-11-27 17:22:54 +00:00
|
|
|
|
#include <ctype.h>
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <libhts/htscfg.h>
|
|
|
|
|
|
|
|
|
|
#include "tvhead.h"
|
2007-08-16 11:19:18 +00:00
|
|
|
|
#include "dvb.h"
|
|
|
|
|
#include "v4l.h"
|
|
|
|
|
#include "iptv_input.h"
|
2007-12-02 11:12:58 +00:00
|
|
|
|
#include "psi.h"
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#include "channels.h"
|
|
|
|
|
#include "transports.h"
|
|
|
|
|
|
|
|
|
|
struct th_channel_queue channels;
|
2007-08-16 10:59:06 +00:00
|
|
|
|
struct th_transport_list all_transports;
|
2007-08-18 08:21:40 +00:00
|
|
|
|
int nchannels;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
void scanner_init(void);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
|
|
|
|
th_channel_t *
|
|
|
|
|
channel_find(const char *name, int create)
|
|
|
|
|
{
|
2007-11-27 17:22:54 +00:00
|
|
|
|
const char *n2;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
th_channel_t *ch;
|
2007-11-27 17:22:54 +00:00
|
|
|
|
int l, i;
|
|
|
|
|
char *cp, c;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
TAILQ_FOREACH(ch, &channels, ch_global_link)
|
|
|
|
|
if(!strcasecmp(name, ch->ch_name))
|
2007-08-09 15:42:01 +00:00
|
|
|
|
return ch;
|
2007-08-16 10:59:06 +00:00
|
|
|
|
|
2007-08-09 15:42:01 +00:00
|
|
|
|
if(create == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ch = calloc(1, sizeof(th_channel_t));
|
|
|
|
|
ch->ch_name = strdup(name);
|
2007-11-27 17:22:54 +00:00
|
|
|
|
|
|
|
|
|
l = strlen(name);
|
|
|
|
|
ch->ch_sname = cp = malloc(l + 1);
|
|
|
|
|
|
|
|
|
|
n2 = utf8toprintable(name);
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < strlen(n2); i++) {
|
|
|
|
|
c = tolower(n2[i]);
|
|
|
|
|
if(isalnum(c))
|
|
|
|
|
*cp++ = c;
|
|
|
|
|
else
|
|
|
|
|
*cp++ = '-';
|
|
|
|
|
}
|
|
|
|
|
*cp = 0;
|
|
|
|
|
|
2007-11-28 08:08:46 +00:00
|
|
|
|
free((void *)n2);
|
|
|
|
|
|
2007-08-18 08:21:40 +00:00
|
|
|
|
ch->ch_index = nchannels;
|
2007-08-16 10:59:06 +00:00
|
|
|
|
TAILQ_INIT(&ch->ch_epg_events);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
TAILQ_INSERT_TAIL(&channels, ch, ch_global_link);
|
|
|
|
|
ch->ch_tag = tag_get();
|
2007-08-18 08:21:40 +00:00
|
|
|
|
nchannels++;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
return ch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
transportcmp(th_transport_t *a, th_transport_t *b)
|
|
|
|
|
{
|
|
|
|
|
return a->tht_prio - b->tht_prio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
int
|
2007-09-19 12:30:08 +00:00
|
|
|
|
transport_set_channel(th_transport_t *t, th_channel_t *ch)
|
2007-08-16 10:59:06 +00:00
|
|
|
|
{
|
2007-10-27 07:40:30 +00:00
|
|
|
|
th_stream_t *st;
|
2007-08-16 12:23:15 +00:00
|
|
|
|
char *chname;
|
2007-12-02 11:12:58 +00:00
|
|
|
|
const char *n;
|
2007-08-16 10:59:06 +00:00
|
|
|
|
t->tht_channel = ch;
|
|
|
|
|
LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp);
|
|
|
|
|
|
2007-08-16 12:23:15 +00:00
|
|
|
|
chname = utf8toprintable(ch->ch_name);
|
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
syslog(LOG_DEBUG, "Added service \"%s\" for channel \"%s\"",
|
2007-08-16 12:23:15 +00:00
|
|
|
|
t->tht_name, chname);
|
|
|
|
|
free(chname);
|
|
|
|
|
|
2007-12-02 11:12:58 +00:00
|
|
|
|
LIST_FOREACH(st, &t->tht_streams, st_link) {
|
|
|
|
|
if(st->st_caid != 0) {
|
|
|
|
|
n = psi_caid2name(st->st_caid);
|
|
|
|
|
} else {
|
|
|
|
|
n = htstvstreamtype2txt(st->st_type);
|
|
|
|
|
}
|
|
|
|
|
syslog(LOG_DEBUG, " Stream [%s] - pid %d", n, st->st_pid);
|
|
|
|
|
}
|
2007-08-16 10:59:06 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
service_load(struct config_head *head)
|
|
|
|
|
{
|
2007-08-11 05:37:56 +00:00
|
|
|
|
const char *name, *v;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
th_transport_t *t;
|
2007-09-19 12:30:08 +00:00
|
|
|
|
int r = 1;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
|
|
|
|
if((name = config_get_str_sub(head, "channel", NULL)) == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
t = calloc(1, sizeof(th_transport_t));
|
2007-10-27 07:40:30 +00:00
|
|
|
|
|
2007-09-19 12:30:08 +00:00
|
|
|
|
t->tht_prio = atoi(config_get_str_sub(head, "prio", ""));
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-08-11 05:37:56 +00:00
|
|
|
|
if(0) {
|
|
|
|
|
#ifdef ENABLE_INPUT_DVB
|
|
|
|
|
} else if((v = config_get_str_sub(head, "dvbmux", NULL)) != NULL) {
|
2007-09-19 12:30:08 +00:00
|
|
|
|
r = dvb_configure_transport(t, v, name);
|
2007-08-11 05:37:56 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef ENABLE_INPUT_IPTV
|
2007-09-19 12:30:08 +00:00
|
|
|
|
} else if((v = config_get_str_sub(head, "iptv", NULL)) != NULL) {
|
|
|
|
|
r = iptv_configure_transport(t, v, head, name);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#endif
|
2007-08-11 05:37:56 +00:00
|
|
|
|
#ifdef ENABLE_INPUT_V4L
|
|
|
|
|
} else if((v = config_get_str_sub(head, "v4lmux", NULL)) != NULL) {
|
2007-09-19 12:30:08 +00:00
|
|
|
|
r = v4l_configure_transport(t, v, name);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2007-09-19 12:30:08 +00:00
|
|
|
|
if(r)
|
|
|
|
|
free(t);
|
|
|
|
|
}
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-09-19 12:30:08 +00:00
|
|
|
|
void
|
|
|
|
|
transport_link(th_transport_t *t, th_channel_t *ch)
|
|
|
|
|
{
|
|
|
|
|
transport_set_channel(t, ch);
|
2007-08-16 10:59:06 +00:00
|
|
|
|
transport_monitor_init(t);
|
|
|
|
|
LIST_INSERT_HEAD(&all_transports, t, tht_global_link);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
channel_load(struct config_head *head)
|
|
|
|
|
{
|
|
|
|
|
const char *name, *v;
|
|
|
|
|
th_channel_t *ch;
|
|
|
|
|
|
|
|
|
|
if((name = config_get_str_sub(head, "name", NULL)) == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ch = channel_find(name, 1);
|
|
|
|
|
|
|
|
|
|
syslog(LOG_DEBUG, "Added channel \"%s\"", name);
|
|
|
|
|
|
|
|
|
|
if((v = config_get_str_sub(head, "teletext-rundown", NULL)) != NULL) {
|
|
|
|
|
ch->ch_teletext_rundown = atoi(v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
|
channel_load(&ce->ce_sub);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ce, &config_list, ce_link) {
|
|
|
|
|
if(ce->ce_type == CFG_SUB && !strcasecmp("service", ce->ce_key)) {
|
|
|
|
|
service_load(&ce->ce_sub);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
th_channel_t *
|
2007-08-16 10:59:06 +00:00
|
|
|
|
channel_by_index(uint32_t index)
|
2007-08-09 15:42:01 +00:00
|
|
|
|
{
|
2007-08-16 10:59:06 +00:00
|
|
|
|
th_channel_t *ch;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
TAILQ_FOREACH(ch, &channels, ch_global_link)
|
|
|
|
|
if(ch->ch_index == index)
|
|
|
|
|
return ch;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2007-08-16 10:59:06 +00:00
|
|
|
|
return NULL;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
}
|
2007-11-20 07:58:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
th_channel_t *
|
|
|
|
|
channel_by_tag(uint32_t tag)
|
|
|
|
|
{
|
|
|
|
|
th_channel_t *ch;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ch, &channels, ch_global_link)
|
|
|
|
|
if(ch->ch_tag == tag)
|
|
|
|
|
return ch;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|