Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV: mux - add channel number, autonet - channel numbers from
  • Loading branch information
perexg committed Oct 13, 2015
1 parent 527b1fd commit 5d4133b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/input/mpegts/iptv/iptv.c
Expand Up @@ -22,6 +22,7 @@
#include "tcp.h"
#include "settings.h"
#include "htsstr.h"
#include "channels.h"

#include <sys/socket.h>
#include <sys/types.h>
Expand Down Expand Up @@ -559,6 +560,13 @@ const idclass_t iptv_auto_network_class = {
.name = N_("URL"),
.off = offsetof(iptv_network_t, in_url),
},
{
.type = PT_S64,
.intsplit = CHANNEL_SPLIT,
.id = "channel_number",
.name = N_("Channel numbers from"),
.off = offsetof(iptv_network_t, in_channel_number),
},
{
.type = PT_U32,
.id = "refetch_period",
Expand Down
22 changes: 18 additions & 4 deletions src/input/mpegts/iptv/iptv_auto.c
Expand Up @@ -20,6 +20,7 @@
#include "tvheadend.h"
#include "http.h"
#include "iptv_private.h"
#include "channels.h"

#include <fcntl.h>
#include <sys/stat.h>
Expand All @@ -31,7 +32,7 @@ static void
iptv_auto_network_process_m3u_item(iptv_network_t *in,
const http_arg_list_t *remove_args,
const char *url, const char *name,
int *total, int *count)
int64_t chnum, int *total, int *count)
{
htsmsg_t *conf;
mpegts_mux_t *mm;
Expand All @@ -50,6 +51,13 @@ iptv_auto_network_process_m3u_item(iptv_network_t *in,
strncmp(url, "https://", 8)))
return;

if (chnum) {
if (chnum % CHANNEL_SPLIT)
chnum += *total;
else
chnum += (int64_t)*total * CHANNEL_SPLIT;
}

memset(&u, 0, sizeof(u));
if (urlparse(url, &u))
return;
Expand Down Expand Up @@ -102,6 +110,10 @@ iptv_auto_network_process_m3u_item(iptv_network_t *in,
im->mm_iptv_svcname = name ? strdup(name) : NULL;
change = 1;
}
if (im->mm_iptv_chnum != chnum) {
im->mm_iptv_chnum = chnum;
change = 1;
}
if (change)
idnode_notify_changed(&im->mm_id);
(*total)++;
Expand Down Expand Up @@ -129,7 +141,8 @@ iptv_auto_network_process_m3u_item(iptv_network_t *in,
*/
static int
iptv_auto_network_process_m3u(iptv_network_t *in, char *data,
http_arg_list_t *remove_args)
http_arg_list_t *remove_args,
int64_t chnum)
{
char *url, *name = NULL;
int total = 0, count = 0;
Expand All @@ -156,7 +169,8 @@ iptv_auto_network_process_m3u(iptv_network_t *in, char *data,
while (*data && *data != '\n') data++;
if (*data) { *data = '\0'; data++; }
if (*url)
iptv_auto_network_process_m3u_item(in, remove_args, url, name, &total, &count);
iptv_auto_network_process_m3u_item(in, remove_args, url, name,
chnum, &total, &count);
}

if (total == 0)
Expand Down Expand Up @@ -195,7 +209,7 @@ iptv_auto_network_process(iptv_network_t *in, char *data, size_t len)
while (*data && *data <= ' ') data++;

if (!strncmp(data, "#EXTM3U", 7))
r = iptv_auto_network_process_m3u(in, data, &remove_args);
r = iptv_auto_network_process_m3u(in, data, &remove_args, in->in_channel_number);

if (r == 0) {
count = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/input/mpegts/iptv/iptv_mux.c
Expand Up @@ -19,6 +19,7 @@

#include "iptv_private.h"
#include "settings.h"
#include "channels.h"

/*
* Class
Expand Down Expand Up @@ -153,6 +154,13 @@ const idclass_t iptv_mux_class =
.name = N_("Mux Name"),
.off = offsetof(iptv_mux_t, mm_iptv_muxname),
},
{
.type = PT_S64,
.intsplit = CHANNEL_SPLIT,
.id = "channel_number",
.name = N_("Channel number"),
.off = offsetof(iptv_mux_t, mm_iptv_chnum),
},
{
.type = PT_STR,
.id = "iptv_sname",
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/iptv/iptv_private.h
Expand Up @@ -82,6 +82,7 @@ struct iptv_network
uint32_t in_max_timeout;

char *in_url;
int64_t in_channel_number;
uint32_t in_refetch_period;
int in_ssl_peer_verify;
char *in_remove_args;
Expand Down Expand Up @@ -112,6 +113,7 @@ struct iptv_mux

char *mm_iptv_muxname;
char *mm_iptv_svcname;
int64_t mm_iptv_chnum;

int mm_iptv_respawn;
time_t mm_iptv_respawn_last;
Expand Down
17 changes: 14 additions & 3 deletions src/input/mpegts/iptv/iptv_service.c
Expand Up @@ -67,6 +67,16 @@ iptv_service_channel_name ( service_t *s )
return is->s_dvb_svcname;
}

static int64_t
iptv_service_channel_number ( service_t *s )
{
iptv_service_t *is = (iptv_service_t *)s;
iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux;
if (im->mm_iptv_chnum)
return im->mm_iptv_chnum;
return mpegts_service_channel_number(s);
}

/*
* Create
*/
Expand All @@ -80,9 +90,10 @@ iptv_service_create0
&mpegts_service_class, uuid,
(mpegts_mux_t*)im, sid, pmt, conf);

is->s_config_save = iptv_service_config_save;
is->s_delete = iptv_service_delete;
is->s_channel_name = iptv_service_channel_name;
is->s_config_save = iptv_service_config_save;
is->s_delete = iptv_service_delete;
is->s_channel_name = iptv_service_channel_name;
is->s_channel_number = iptv_service_channel_number;

/* Set default service name */
if (!is->s_dvb_svcname || !*is->s_dvb_svcname)
Expand Down
5 changes: 5 additions & 0 deletions src/input/mpegts/mpegts_dvb.h
Expand Up @@ -78,4 +78,9 @@ dvb_mux_t *dvb_mux_create0
#define dvb_mux_create1(n, u, c)\
dvb_mux_create0(n, MPEGTS_ONID_NONE, MPEGTS_TSID_NONE, NULL, u, c)

/*
*
*/
int64_t mpegts_service_channel_number ( service_t *s );

#endif /* __TVH_MPEGTS_DVB_H__ */
2 changes: 1 addition & 1 deletion src/input/mpegts/mpegts_service.c
Expand Up @@ -439,7 +439,7 @@ mpegts_service_grace_period(service_t *t)
/*
* Channel number
*/
static int64_t
int64_t
mpegts_service_channel_number ( service_t *s )
{
mpegts_service_t *ms = (mpegts_service_t*)s;
Expand Down

0 comments on commit 5d4133b

Please sign in to comment.