1 /*
2 * IPTV Input
3 *
4 * Copyright (C) 2013 Andreas Öman
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "iptv_private.h"
21 #include "settings.h"
22 #include "config.h"
23
24 extern const idclass_t mpegts_service_class;
25
26 static htsmsg_t *
iptv_service_config_save(service_t * s,char * filename,size_t fsize)27 iptv_service_config_save ( service_t *s, char *filename, size_t fsize )
28 {
29 mpegts_mux_t *mm = ((mpegts_service_t *)s)->s_dvb_mux;
30 idnode_changed(&mm->mm_id);
31 return NULL;
32 }
33
34 static void
iptv_service_delete(service_t * s,int delconf)35 iptv_service_delete ( service_t *s, int delconf )
36 {
37 mpegts_mux_t *mm = ((mpegts_service_t *)s)->s_dvb_mux;
38 idnode_changed(&mm->mm_id);
39 /* Note - do no pass the delconf flag - another file location */
40 mpegts_service_delete(s, 0);
41 }
42
43 static const char *
iptv_service_channel_name(service_t * s)44 iptv_service_channel_name ( service_t *s )
45 {
46 iptv_service_t *is = (iptv_service_t *)s;
47 iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux;
48 if (im->mm_iptv_svcname && im->mm_iptv_svcname[0])
49 return im->mm_iptv_svcname;
50 return is->s_dvb_svcname;
51 }
52
53 static int64_t
iptv_service_channel_number(service_t * s)54 iptv_service_channel_number ( service_t *s )
55 {
56 iptv_service_t *is = (iptv_service_t *)s;
57 iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux;
58 if (im->mm_iptv_chnum)
59 return im->mm_iptv_chnum;
60 return mpegts_service_channel_number(s);
61 }
62
63 static const char *
iptv_service_channel_icon(service_t * s)64 iptv_service_channel_icon ( service_t *s )
65 {
66 iptv_service_t *is = (iptv_service_t *)s;
67 iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux;
68 iptv_network_t *in = (iptv_network_t *)im->mm_network;
69 const char *ic = im->mm_iptv_icon;
70 const char *dir = NULL;
71 if (ic && ic[0]) {
72 if (strncmp(ic, "http://", 7) == 0 ||
73 strncmp(ic, "https://", 8) == 0 ||
74 strncmp(ic, "file:///", 8) == 0)
75 return ic;
76 if (strncmp(ic, "file://", 7) == 0) {
77 const char *chicon = config.chicon_path;
78 ic += 7;
79 if (chicon && chicon[0] >= ' ' && chicon[0] <= 122) {
80 dir = chicon;
81 } else {
82 dir = "file:///";
83 }
84 } else {
85 if (in && in->in_icon_url && in->in_icon_url[0])
86 dir = in->in_icon_url;
87 }
88 if (dir && ic) {
89 while (ic[0] == '/') ic++;
90 snprintf(prop_sbuf, PROP_SBUF_LEN, "%s/%s", in->in_icon_url, ic);
91 return prop_sbuf;
92 }
93 }
94 return NULL;
95 }
96
97 static const char *
iptv_service_channel_epgid(service_t * s)98 iptv_service_channel_epgid ( service_t *s )
99 {
100 iptv_service_t *is = (iptv_service_t *)s;
101 iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux;
102 return im->mm_iptv_epgid;
103 }
104
105 static htsmsg_t *
iptv_service_channel_tags(service_t * s)106 iptv_service_channel_tags ( service_t *s )
107 {
108 iptv_service_t *is = (iptv_service_t *)s;
109 iptv_mux_t *im = (iptv_mux_t *)is->s_dvb_mux;
110 char *p = im->mm_iptv_tags, *x;
111 htsmsg_t *r = NULL;
112 if (p) {
113 r = htsmsg_create_list();
114 while (*p) {
115 while (*p && *p <= ' ') p++;
116 x = p;
117 while (*p && *p >= ' ') p++;
118 if (*p) { *p = '\0'; p++; }
119 if (*x)
120 htsmsg_add_str(r, NULL, x);
121 }
122 }
123 return r;
124 }
125
126 /*
127 * Create
128 */
129 iptv_service_t *
iptv_service_create0(iptv_mux_t * im,uint16_t sid,uint16_t pmt,const char * uuid,htsmsg_t * conf)130 iptv_service_create0
131 ( iptv_mux_t *im, uint16_t sid, uint16_t pmt,
132 const char *uuid, htsmsg_t *conf )
133 {
134 iptv_network_t *in = (iptv_network_t *)im->mm_network;
135 iptv_service_t *is = (iptv_service_t*)
136 mpegts_service_create0(calloc(1, sizeof(mpegts_service_t)),
137 &mpegts_service_class, uuid,
138 (mpegts_mux_t*)im, sid, pmt, conf);
139
140 is->s_config_save = iptv_service_config_save;
141 is->s_delete = iptv_service_delete;
142 is->s_channel_name = iptv_service_channel_name;
143 is->s_channel_number = iptv_service_channel_number;
144 is->s_channel_icon = iptv_service_channel_icon;
145 is->s_channel_epgid = iptv_service_channel_epgid;
146 is->s_channel_tags = iptv_service_channel_tags;
147
148 /* Set default service name */
149 if (!is->s_dvb_svcname || !*is->s_dvb_svcname)
150 if (im->mm_iptv_svcname)
151 is->s_dvb_svcname = strdup(im->mm_iptv_svcname);
152
153 if (in->in_bouquet)
154 iptv_bouquet_trigger(in, 1);
155
156 return is;
157 }
158