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 #ifndef __IPTV_PRIVATE_H__
21 #define __IPTV_PRIVATE_H__
22 
23 #include "input.h"
24 #include "htsbuf.h"
25 #include "url.h"
26 #include "udp.h"
27 
28 #define IPTV_BUF_SIZE    (300*188)
29 #define IPTV_PKTS        32
30 #define IPTV_PKT_PAYLOAD 1472
31 
32 #define IPTV_KILL_KILL   0
33 #define IPTV_KILL_TERM   1
34 #define IPTV_KILL_INT    2
35 #define IPTV_KILL_HUP    3
36 #define IPTV_KILL_USR1   4
37 #define IPTV_KILL_USR2   5
38 
39 struct bouquet;
40 
41 extern pthread_mutex_t iptv_lock;
42 
43 typedef struct iptv_input   iptv_input_t;
44 typedef struct iptv_network iptv_network_t;
45 typedef struct iptv_mux     iptv_mux_t;
46 typedef struct iptv_service iptv_service_t;
47 typedef struct iptv_handler iptv_handler_t;
48 
49 struct iptv_handler
50 {
51   const char *scheme;
52 
53   uint32_t buffer_limit;
54 
55   int     (*start) ( iptv_mux_t *im, const char *raw, const url_t *url );
56   void    (*stop)  ( iptv_mux_t *im );
57   ssize_t (*read)  ( iptv_mux_t *im );
58   void    (*pause) ( iptv_mux_t *im, int pause );
59 
60   RB_ENTRY(iptv_handler) link;
61 };
62 
63 void iptv_handler_register ( iptv_handler_t *ih, int num );
64 
65 struct iptv_input
66 {
67   mpegts_input_t;
68 };
69 
70 int  iptv_input_fd_started ( iptv_mux_t *im );
71 void iptv_input_mux_started ( iptv_mux_t *im );
72 int  iptv_input_recv_packets ( iptv_mux_t *im, ssize_t len );
73 void iptv_input_recv_flush ( iptv_mux_t *im );
74 void iptv_input_pause_handler ( iptv_mux_t *im, int pause );
75 
76 struct iptv_network
77 {
78   mpegts_network_t;
79 
80   int in_bps;
81   int in_bw_limited;
82 
83   int in_scan_create;
84   int in_priority;
85   int in_streaming_priority;
86   int in_remove_scrambled_bits;
87 
88   uint16_t in_service_id;
89 
90   uint32_t in_max_streams;
91   uint32_t in_max_bandwidth;
92   uint32_t in_max_timeout;
93 
94   char    *in_url;
95   char    *in_url_sane;
96   int      in_bouquet;
97   mtimer_t in_bouquet_timer;
98   char    *in_ctx_charset;
99   int64_t  in_channel_number;
100   uint32_t in_refetch_period;
101   char    *in_icon_url;
102   char    *in_icon_url_sane;
103   int      in_ssl_peer_verify;
104   char    *in_remove_args;
105   int      in_tsid_accept_zero_value;
106 
107   void    *in_auto; /* private structure for auto-network */
108 };
109 
110 iptv_network_t *iptv_network_create0 ( const char *uuid, htsmsg_t *conf, const idclass_t *idc );
111 
112 struct iptv_mux
113 {
114   mpegts_mux_t;
115 
116   int                   mm_iptv_priority;
117   int                   mm_iptv_streaming_priority;
118   int                   mm_iptv_fd;
119   udp_connection_t     *mm_iptv_connection;
120   int                   mm_iptv_fd2;
121   udp_connection_t     *mm_iptv_connection2;
122   char                 *mm_iptv_url;
123   char                 *mm_iptv_url_sane;
124   char                 *mm_iptv_url_raw;
125   char                 *mm_iptv_interface;
126 
127   int                   mm_iptv_substitute;
128   int                   mm_iptv_atsc;
129 
130   char                 *mm_iptv_muxname;
131   char                 *mm_iptv_svcname;
132   int64_t               mm_iptv_chnum;
133   char                 *mm_iptv_icon;
134   char                 *mm_iptv_epgid;
135 
136   int                   mm_iptv_respawn;
137   time_t                mm_iptv_respawn_last;
138   int                   mm_iptv_kill;
139   int                   mm_iptv_kill_timeout;
140   char                 *mm_iptv_env;
141   char                 *mm_iptv_hdr;
142   char                 *mm_iptv_tags;
143   uint32_t              mm_iptv_satip_dvbt_freq;
144   uint32_t              mm_iptv_satip_dvbc_freq;
145   uint32_t              mm_iptv_satip_dvbs_freq;
146 
147   uint32_t              mm_iptv_rtp_seq;
148 
149   sbuf_t                mm_iptv_buffer;
150 
151   uint32_t              mm_iptv_buffer_limit;
152 
153   iptv_handler_t       *im_handler;
154   mtimer_t              im_pause_timer;
155 
156   int64_t               im_pcr;
157   int64_t               im_pcr_start;
158   int64_t               im_pcr_end;
159   uint16_t              im_pcr_pid;
160 
161   void                 *im_data;
162 
163   int                   im_delete_flag;
164 };
165 
166 iptv_mux_t* iptv_mux_create0
167   ( iptv_network_t *in, const char *uuid, htsmsg_t *conf );
168 
169 struct iptv_service
170 {
171   mpegts_service_t;
172   char * s_iptv_svcname;
173 };
174 
175 iptv_service_t *iptv_service_create0
176   ( iptv_mux_t *im, uint16_t sid, uint16_t pmt_pid,
177     const char *uuid, htsmsg_t *conf );
178 
179 extern const idclass_t iptv_network_class;
180 extern const idclass_t iptv_auto_network_class;
181 extern const idclass_t iptv_mux_class;
182 
183 extern iptv_input_t   *iptv_input;
184 extern iptv_network_t *iptv_network;
185 
186 
187 void iptv_bouquet_trigger(iptv_network_t *in, int timeout);
188 int iptv_url_set ( char **url, char **sane_url, const char *str, int allow_file, int allow_pipe );
189 
190 void iptv_mux_load_all ( void );
191 
192 void iptv_auto_network_trigger( iptv_network_t *in );
193 void iptv_auto_network_init( iptv_network_t *in );
194 void iptv_auto_network_done( iptv_network_t *in );
195 
196 void iptv_http_init    ( void );
197 void iptv_udp_init     ( void );
198 void iptv_rtsp_init    ( void );
199 void iptv_pipe_init    ( void );
200 void iptv_file_init    ( void );
201 
202 ssize_t iptv_rtp_read ( iptv_mux_t *im, udp_multirecv_t *um,
203                         void (*pkt_cb)(iptv_mux_t *im, uint8_t *buf, int len) );
204 
205 void iptv_input_unpause ( void *aux );
206 
207 #endif /* __IPTV_PRIVATE_H__ */
208 
209 /******************************************************************************
210  * Editor Configuration
211  *
212  * vim:sts=2:ts=2:sw=2:et
213  *****************************************************************************/
214