1 /*
2 * Tvheadend - DVB support routines and defines
3 * Copyright (C) 2007 Andreas Öman
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * Based on:
21 *
22 * ITU-T Recommendation H.222.0 / ISO standard 13818-1
23 * EN 300 468 - V1.7.1
24 */
25
26 #ifndef __TVH_DVB_SUPPORT_H__
27 #define __TVH_DVB_SUPPORT_H__
28
29 struct mpegts_table;
30 struct mpegts_table_state;
31 struct mpegts_network;
32 struct mpegts_mux;
33 struct lang_str;
34
35 /* PIDs */
36
37 #define DVB_PAT_PID 0x00
38 #define DVB_CAT_PID 0x01
39 #define DVB_TSDT_PID 0x02
40 #define DVB_NIT_PID 0x10
41 #define DVB_SDT_PID 0x11
42 #define DVB_BAT_PID 0x11
43 #define DVB_EIT_PID 0x12
44 #define DVB_RST_PID 0x13
45 #define DVB_TDT_PID 0x14
46 #define DVB_SNC_PID 0x15
47 #define DVB_RNT_PID 0x16
48 #define DVB_INB_PID 0x1C
49 #define DVB_MSR_PID 0x1D
50 #define DVB_DIT_PID 0x1E
51 #define DVB_SIT_PID 0x1F
52 #define DVB_VCT_PID 0x1FFB
53 #define DVB_ATSC_STT_PID 0x1FFB
54 #define DVB_ATSC_MGT_PID 0x1FFB
55
56 /* Tables */
57
58 #define DVB_PAT_BASE 0x00
59 #define DVB_PAT_MASK 0x00
60
61 #define DVB_CAT_BASE 0x01
62 #define DVB_CAT_MASK 0xFF
63
64 #define DVB_PMT_BASE 0x02
65 #define DVB_PMT_MASK 0xFF
66
67 #define DVB_NIT_BASE 0x00
68 #define DVB_NIT_MASK 0x00
69
70 #define DVB_SDT_BASE 0x40
71 #define DVB_SDT_MASK 0xF8
72
73 #define DVB_BAT_BASE 0x48
74 #define DVB_BAT_MASK 0xF8
75
76 #define DVB_TDT_BASE 0x70
77 #define DVB_TDT_MASK 0xFF
78
79 #define DVB_TOT_BASE 0x73
80 #define DVB_TOT_MASK 0xFF
81
82 #define DVB_HBBTV_BASE 0x74
83 #define DVB_HBBTV_MASK 0xFF
84
85 #define DVB_FASTSCAN_NIT_BASE 0xBC
86 #define DVB_FASTSCAN_SDT_BASE 0xBD
87 #define DVB_FASTSCAN_MASK 0xFF
88
89 #define DVB_VCT_T_BASE 0xC8
90 #define DVB_VCT_C_BASE 0xC9
91 #define DVB_VCT_MASK 0xFF
92
93 #define DVB_ATSC_MGT_BASE 0xC7
94 #define DVB_ATSC_MGT_MASK 0xFF
95
96 #define DVB_ATSC_EIT_BASE 0xCB
97 #define DVB_ATSC_EIT_MASK 0xFF
98
99 #define DVB_ATSC_ETT_BASE 0xCC
100 #define DVB_ATSC_ETT_MASK 0xFF
101
102 #define DVB_ATSC_STT_BASE 0xCD
103 #define DVB_ATSC_STT_MASK 0xFF
104
105 #define DVB_TELETEXT_BASE 0x2000
106
107 /* Descriptors */
108
109 #define DVB_DESC_VIDEO_STREAM 0x02
110 #define DVB_DESC_REGISTRATION 0x05
111 #define DVB_DESC_CA 0x09
112 #define DVB_DESC_LANGUAGE 0x0A
113
114 /* Descriptors defined in EN 300 468 */
115
116 #define DVB_DESC_NETWORK_NAME 0x40
117 #define DVB_DESC_SERVICE_LIST 0x41
118 #define DVB_DESC_STUFFING 0x42
119 #define DVB_DESC_SAT_DEL 0x43
120 #define DVB_DESC_CABLE_DEL 0x44
121 #define DVB_DESC_VBI_DATA 0x45
122 #define DVB_DESC_VBI_TELETEXT 0x46
123 #define DVB_DESC_BOUQUET_NAME 0x47
124 #define DVB_DESC_SERVICE 0x48
125 #define DVB_DESC_COUNTRY_AVAILABILITY 0x49
126 #define DVB_DESC_LINKAGE 0x4A
127 #define DVB_DESC_NVOD_REFERENCE 0x4B
128 #define DVB_DESC_TIME_SHIFTED_SERVICE 0x4C
129 #define DVB_DESC_SHORT_EVENT 0x4D
130 #define DVB_DESC_EXT_EVENT 0x4E
131 #define DVB_DESC_TIME_SHIFTED_EVENT 0x4F
132 #define DVB_DESC_COMPONENT 0x50
133 #define DVB_DESC_MOSAIC 0x51
134 #define DVB_DESC_STREAM_ID 0x52
135 #define DVB_DESC_CA_ID 0x53
136 #define DVB_DESC_CONTENT 0x54
137 #define DVB_DESC_PARENTAL_RAT 0x55
138 #define DVB_DESC_TELETEXT 0x56
139 #define DVB_DESC_TELEPHONE 0x57
140 #define DVB_DESC_LOCAL_TIME_OFFSET 0x58
141 #define DVB_DESC_SUBTITLE 0x59
142 #define DVB_DESC_TERR_DEL 0x5A
143 #define DVB_DESC_MULTI_NETWORK_NAME 0x5B
144 #define DVB_DESC_MULTI_BOUQUET_NAME 0x5C
145 #define DVB_DESC_MULTI_SERVICE_NAME 0x5D
146 #define DVB_DESC_MULTI_COMPONENT_NAME 0x5E
147 #define DVB_DESC_PRIVATE_DATA 0x5F
148 #define DVB_DESC_SERVICE_MOVE 0x60
149 #define DVB_DESC_SHORT_SMOOTHING_BUF 0x61
150 #define DVB_DESC_FREQ_LIST 0x62
151 #define DVB_DESC_PARTIAL_TRANSPORT_STREAM 0x63
152 #define DVB_DESC_DATA_BROADCAST 0x64
153 #define DVB_DESC_SCRAMBLING 0x65
154 #define DVB_DESC_DATA_BROADCAST_ID 0x66
155 #define DVB_DESC_TRANSPORT_STREAM 0x67
156 #define DVB_DESC_DSNG 0x68
157 #define DVB_DESC_PDC 0x69
158 #define DVB_DESC_AC3 0x6A
159 #define DVB_DESC_ANCILLARY_DATA 0x6B
160 #define DVB_DESC_CALL_LIST 0x6C
161 #define DVB_DESC_CALL_FREQ_LINK 0x6D
162 #define DVB_DESC_ANNOUNCEMENT_SUPPORT 0x6E
163 #define DVB_DESC_DEF_AUTHORITY 0x73
164 #define DVB_DESC_CRID 0x76
165 #define DVB_DESC_EAC3 0x7A
166 #define DVB_DESC_AAC 0x7C
167
168 #define DVB_DESC_BSKYB_LCN 0xB1
169
170 #define DVB_DESC_BSKYB_NVOD 0xC0
171
172 #define DVB_DESC_FREESAT_LCN 0xD3
173 #define DVB_DESC_FREESAT_REGIONS 0xD4
174
175 /* Descriptors defined in A/65:2009 */
176
177 #define ATSC_DESC_STUFFING 0x80
178 #define ATSC_DESC_AC3 0x81
179 #define ATSC_DESC_CAPTION 0x86
180 #define ATSC_DESC_CONTENT_ADVISORY 0x87
181 #define ATSC_DESC_EXT_CHANNEL_NAME 0xA0
182 #define ATSC_DESC_SERVICE_LOCATION 0xA1
183 #define ATSC_DESC_TIMESHIFTED_SVC 0xA2
184 #define ATSC_DESC_COMPONENT_NAME 0xA3
185 #define ATSC_DESC_DCC_DEPARTING 0xA8
186 #define ATSC_DESC_DCC_ARRIVING 0xA9
187 #define ATSC_DESC_REDISTRIB_CTRL 0xAA
188 #define ATSC_DESC_GENRE 0xAB
189 #define ATSC_DESC_PRIVATE_INFO 0xAD
190
191 /* Service type lookup */
192
193 int dvb_servicetype_lookup ( int t );
194
195 /* String Extraction */
196
197 typedef struct dvb_string_conv
198 {
199 uint8_t type;
200 size_t (*func) ( char *dst, size_t *dstlen,
201 const uint8_t* src, size_t srclen );
202 } dvb_string_conv_t;
203
204 int dvb_get_string
205 (char *dst, size_t dstlen, const uint8_t *src, const size_t srclen,
206 const char *dvb_charset, dvb_string_conv_t *conv);
207
208 int dvb_get_string_with_len
209 (char *dst, size_t dstlen, const uint8_t *buf, size_t buflen,
210 const char *dvb_charset, dvb_string_conv_t *conv);
211
212 struct lang_str *atsc_get_string
213 (const uint8_t *src, size_t srclen);
214
215 /* Conversion */
216
bcdtoint(const uint32_t i)217 static inline uint32_t bcdtoint(const uint32_t i) {
218 return ((((i & 0xf0) >> 4) * 10) + (i & 0x0f));
219 }
bcdtoint4(const uint8_t * ptr)220 static inline uint32_t bcdtoint4(const uint8_t *ptr) {
221 return (bcdtoint(ptr[0]) * 1000000) +
222 (bcdtoint(ptr[1]) * 10000) +
223 (bcdtoint(ptr[2]) * 100) +
224 bcdtoint(ptr[3]);
225 }
bcdtoint41(const uint8_t * ptr)226 static inline uint32_t bcdtoint41(const uint8_t *ptr) {
227 return (bcdtoint(ptr[0]) * 100000) +
228 (bcdtoint(ptr[1]) * 1000) +
229 (bcdtoint(ptr[2]) * 10) +
230 ((ptr[3]) >> 4);
231 }
232
233 htsmsg_t *dvb_timezone_enum(void *p, const char *lang);
234
235 time_t dvb_convert_date(const uint8_t *dvb_buf, int tmzone);
236 time_t atsc_convert_gpstime(uint32_t gpstime);
237 void atsc_utf16_to_utf8(const uint8_t *src, int len, char *buf, int buflen);
238
239 /*
240 * PSI processing
241 */
242
243 #define DVB_LOOP_INIT(mt, ptr, len, off, lptr, llen)\
244 do {\
245 llen = ((ptr[off] & 0xF) << 8) | ptr[off+1];\
246 lptr = 2 + off + ptr;\
247 ptr += 2 + off + llen;\
248 len -= 2 + off + llen;\
249 if (len < 0) {tvhtrace(mt->mt_subsys, "%s: len < 0", mt->mt_name); return -1; }\
250 } while(0)
251
252 #define DVB_LOOP_EACH(ptr, len, min)\
253 for ( ; len > min ; )\
254
255 #define DVB_LOOP_FOREACH(mt, ptr, len, off, lptr, llen, min)\
256 DVB_LOOP_INIT(mt, ptr, len, off, lptr, llen);\
257 DVB_LOOP_EACH(lptr, llen, min)
258
259 #define DVB_DESC_EACH(mt, ptr, len, dtag, dlen, dptr)\
260 DVB_LOOP_EACH(ptr, len, 2)\
261 if (!(dtag = ptr[0])) {tvhtrace(mt->mt_subsys, "%s: 1", mt->mt_name);return -1;}\
262 else if ((dlen = ptr[1]) < 0) {tvhtrace(mt->mt_subsys, "%s: 2", mt->mt_name);return -1;}\
263 else if (!(dptr = ptr+2)) {tvhtrace(mt->mt_subsys, "%s: 3", mt->mt_name);return -1;}\
264 else if ( (len -= 2 + dlen) < 0) {tvhtrace(mt->mt_subsys, "%s: 4", mt->mt_name);return -1;}\
265 else if (!(ptr += 2 + dlen)) {tvhtrace(mt->mt_subsys, "%s: 5", mt->mt_name);return -1;}\
266 else
267
268 #define DVB_DESC_FOREACH(mt, ptr, len, off, lptr, llen, dtag, dlen, dptr)\
269 DVB_LOOP_INIT(mt, ptr, len, off, lptr, llen);\
270 DVB_DESC_EACH(mt, lptr, llen, dtag, dlen, dptr)\
271
272 /*
273 * SI typedefs
274 */
275
276 #define MPEGTS_PSI_SECTION_SIZE 5000
277 #define MPEGTS_PSI_VERSION_NONE 255
278
279 typedef struct mpegts_psi_section
280 {
281 uint8_t ps_table; // SI table ID
282 uint8_t ps_mask; // mask
283 int8_t ps_cc;
284 int8_t ps_cco;
285 int ps_offset;
286 int ps_lock;
287 uint8_t ps_data[MPEGTS_PSI_SECTION_SIZE];
288 } mpegts_psi_section_t;
289
290 typedef void (*mpegts_psi_section_callback_t)
291 ( const uint8_t *tsb, size_t len, void *opaque );
292
293 typedef struct mpegts_psi_table_state
294 {
295 int tableid;
296 uint64_t extraid;
297 int version;
298 int last;
299 int complete;
300 int working;
301 uint32_t sections[8];
302 RB_ENTRY(mpegts_psi_table_state) link;
303 } mpegts_psi_table_state_t;
304
305 typedef struct mpegts_psi_table
306 {
307 LIST_ENTRY(mpegts_table) mt_link;
308 RB_HEAD(,mpegts_psi_table_state) mt_state;
309
310 int mt_subsys;
311 char *mt_name;
312 void *mt_opaque;
313
314 uint8_t mt_table; // SI table id (base)
315 uint8_t mt_mask; // mask
316
317 int mt_pid;
318
319 int mt_complete;
320 int mt_incomplete;
321 uint8_t mt_finished;
322
323 mpegts_psi_section_t mt_sect;
324
325 tvhlog_limit_t mt_err_log;
326
327 } mpegts_psi_table_t;
328
329 /*
330 * Assemble SI section
331 */
332 void mpegts_psi_section_reassemble
333 ( mpegts_psi_table_t *mt, const char *logpref, const uint8_t *tsb, int crc,
334 mpegts_psi_section_callback_t cb, void *opaque );
335
336 /* PSI table parser helpers */
337
338 int dvb_table_end
339 (mpegts_psi_table_t *mt, mpegts_psi_table_state_t *st, int sect );
340 int dvb_table_begin
341 (mpegts_psi_table_t *mt, const uint8_t *ptr, int len,
342 int tableid, uint64_t extraid, int minlen,
343 mpegts_psi_table_state_t **st, int *sect, int *last, int *ver);
344 void dvb_table_reset (mpegts_psi_table_t *mt);
345 void dvb_table_release (mpegts_psi_table_t *mt);
346
347 /* all-in-one parser */
348
349 typedef void (*mpegts_psi_parse_callback_t)
350 ( mpegts_psi_table_t *, const uint8_t *buf, int len );
351
352 void dvb_table_parse_init
353 ( mpegts_psi_table_t *mt, const char *name, int subsys, int pid,
354 uint8_t table, uint8_t mask, void *opaque );
355
356 void dvb_table_parse_done ( mpegts_psi_table_t *mt);
357
358 void dvb_table_parse
359 (mpegts_psi_table_t *mt, const char *logprefix,
360 const uint8_t *tsb, int len, int crc, int full,
361 mpegts_psi_parse_callback_t cb);
362
363 int dvb_table_append_crc32(uint8_t *dst, int off, int maxlen);
364
365 int dvb_table_remux
366 (mpegts_psi_table_t *mt, const uint8_t *buf, int len, uint8_t **out);
367
368 extern htsmsg_t *satellites;
369
370 /* Delivery systems */
371
372 typedef enum dvb_fe_delivery_system {
373 DVB_SYS_NONE = 0,
374 DVB_SYS_DVBC_ANNEX_A = 100,
375 DVB_SYS_DVBC_ANNEX_B,
376 DVB_SYS_DVBC_ANNEX_C,
377 DVB_SYS_DVBT = 200,
378 DVB_SYS_DVBT2,
379 DVB_SYS_DVBS = 300,
380 DVB_SYS_DVBS2,
381 DVB_SYS_DVBH = 400,
382 DVB_SYS_DSS = 500,
383 DVB_SYS_ISDBT = 600,
384 DVB_SYS_ISDBS,
385 DVB_SYS_ISDBC,
386 DVB_SYS_ATSC = 700,
387 DVB_SYS_ATSCMH,
388 DVB_SYS_DTMB = 800,
389 DVB_SYS_CMMB = 900,
390 DVB_SYS_DAB = 1000,
391 DVB_SYS_TURBO = 1100,
392 /* TVH internal */
393 DVB_SYS_ATSC_ALL = 9998,
394 DVB_SYS_UNKNOWN = 9999
395 } dvb_fe_delivery_system_t;
396
397 /*
398 *
399 */
400 #if ENABLE_MPEGTS_DVB
401
402 typedef enum dvb_fe_type {
403 DVB_TYPE_NONE = 0,
404 DVB_TYPE_T = 1, /* terrestrial */
405 DVB_TYPE_C, /* cable */
406 DVB_TYPE_S, /* satellite */
407 DVB_TYPE_ATSC_T, /* terrestrial - north america */
408 DVB_TYPE_ATSC_C, /* cable - north america */
409 DVB_TYPE_ISDB_T, /* terrestrial - japan, brazil */
410 DVB_TYPE_ISDB_C, /* cable - japan, brazil */
411 DVB_TYPE_ISDB_S, /* satellite - japan, brazil */
412 DVB_TYPE_DAB, /* digital radio (europe) */
413 DVB_TYPE_LAST = DVB_TYPE_DAB
414 } dvb_fe_type_t;
415
416 typedef enum dvb_fe_spectral_inversion {
417 DVB_INVERSION_UNDEFINED,
418 DVB_INVERSION_AUTO,
419 DVB_INVERSION_OFF,
420 DVB_INVERSION_ON,
421 } dvb_fe_spectral_inversion_t;
422
423 typedef enum dvb_fe_code_rate {
424 DVB_FEC_NONE = 0,
425 DVB_FEC_AUTO,
426 DVB_FEC_1_2 = 102,
427 DVB_FEC_1_3 = 103,
428 DVB_FEC_1_5 = 105,
429 DVB_FEC_2_3 = 203,
430 DVB_FEC_2_5 = 205,
431 DVB_FEC_2_9 = 209,
432 DVB_FEC_3_4 = 304,
433 DVB_FEC_3_5 = 305,
434 DVB_FEC_4_5 = 405,
435 DVB_FEC_4_15 = 415,
436 DVB_FEC_5_6 = 506,
437 DVB_FEC_5_9 = 509,
438 DVB_FEC_6_7 = 607,
439 DVB_FEC_7_8 = 708,
440 DVB_FEC_7_9 = 709,
441 DVB_FEC_7_15 = 715,
442 DVB_FEC_8_9 = 809,
443 DVB_FEC_8_15 = 815,
444 DVB_FEC_9_10 = 910,
445 DVB_FEC_9_20 = 920,
446 DVB_FEC_11_15 = 1115,
447 DVB_FEC_11_20 = 1120,
448 DVB_FEC_11_45 = 1145,
449 DVB_FEC_13_18 = 1318,
450 DVB_FEC_13_45 = 1345,
451 DVB_FEC_14_45 = 1445,
452 DVB_FEC_23_36 = 2336,
453 DVB_FEC_25_36 = 2536,
454 DVB_FEC_26_45 = 2645,
455 DVB_FEC_28_45 = 2845,
456 DVB_FEC_29_45 = 2945,
457 DVB_FEC_31_45 = 3145,
458 DVB_FEC_32_45 = 3245,
459 DVB_FEC_77_90 = 7790,
460 } dvb_fe_code_rate_t;
461
462 typedef enum dvb_fe_modulation {
463 DVB_MOD_NONE = 0,
464 DVB_MOD_AUTO,
465 DVB_MOD_QPSK = 1001,
466 DVB_MOD_QAM_4_NR = 2004,
467 DVB_MOD_QAM_AUTO = 3000,
468 DVB_MOD_QAM_16 = 3016,
469 DVB_MOD_QAM_32 = 3032,
470 DVB_MOD_QAM_64 = 3064,
471 DVB_MOD_QAM_128 = 3128,
472 DVB_MOD_QAM_256 = 3256,
473 DVB_MOD_VSB_8 = 4008,
474 DVB_MOD_VSB_16 = 4016,
475 DVB_MOD_PSK_8 = 5008,
476 DVB_MOD_DQPSK = 6001,
477 DVB_MOD_BPSK = 7001,
478 DVB_MOD_BPSK_S = 8001,
479 DVB_MOD_APSK_16 = 9016,
480 DVB_MOD_APSK_32 = 9032,
481 DVB_MOD_APSK_64 = 9064,
482 DVB_MOD_APSK_128 = 9128,
483 DVB_MOD_APSK_256 = 9256,
484 DVB_MOD_APSK_8_L = 10008,
485 DVB_MOD_APSK_16_L = 10016,
486 DVB_MOD_APSK_32_L = 10032,
487 DVB_MOD_APSK_64_L = 10064,
488 DVB_MOD_APSK_128_L = 10128,
489 DVB_MOD_APSK_256_L = 10256,
490 } dvb_fe_modulation_t;
491
492 typedef enum dvb_fe_transmit_mode {
493 DVB_TRANSMISSION_MODE_NONE = 0,
494 DVB_TRANSMISSION_MODE_AUTO,
495 DVB_TRANSMISSION_MODE_1K = 100,
496 DVB_TRANSMISSION_MODE_2K,
497 DVB_TRANSMISSION_MODE_4K,
498 DVB_TRANSMISSION_MODE_8K,
499 DVB_TRANSMISSION_MODE_16K,
500 DVB_TRANSMISSION_MODE_32K,
501 DVB_TRANSMISSION_MODE_C1 = 10001,
502 DVB_TRANSMISSION_MODE_C3780 = 13780,
503 } dvb_fe_transmit_mode_t;
504
505 typedef enum dvb_fe_bandwidth {
506 DVB_BANDWIDTH_NONE = 0,
507 DVB_BANDWIDTH_AUTO,
508 DVB_BANDWIDTH_1_712_MHZ = 1712,
509 DVB_BANDWIDTH_5_MHZ = 5000,
510 DVB_BANDWIDTH_6_MHZ = 6000,
511 DVB_BANDWIDTH_7_MHZ = 7000,
512 DVB_BANDWIDTH_8_MHZ = 8000,
513 DVB_BANDWIDTH_10_MHZ = 10000,
514 } dvb_fe_bandwidth_t;
515
516 typedef enum dvb_fe_guard_interval {
517 DVB_GUARD_INTERVAL_NONE = 0,
518 DVB_GUARD_INTERVAL_AUTO,
519 DVB_GUARD_INTERVAL_1_4 = 1004,
520 DVB_GUARD_INTERVAL_1_8 = 1008,
521 DVB_GUARD_INTERVAL_1_16 = 1016,
522 DVB_GUARD_INTERVAL_1_32 = 1032,
523 DVB_GUARD_INTERVAL_1_128 = 1128,
524 DVB_GUARD_INTERVAL_19_128 = 19128,
525 DVB_GUARD_INTERVAL_19_256 = 19256,
526 DVB_GUARD_INTERVAL_PN420 = 90420,
527 DVB_GUARD_INTERVAL_PN595 = 90595,
528 DVB_GUARD_INTERVAL_PN945 = 90945,
529 } dvb_fe_guard_interval_t;
530
531 typedef enum dvb_fe_hierarchy {
532 DVB_HIERARCHY_NONE = 0,
533 DVB_HIERARCHY_AUTO,
534 DVB_HIERARCHY_1 = 1001,
535 DVB_HIERARCHY_2 = 1002,
536 DVB_HIERARCHY_4 = 1004,
537 } dvb_fe_hierarchy_t;
538
539 typedef enum dvb_fe_pilot {
540 DVB_PILOT_NONE = 0,
541 DVB_PILOT_AUTO,
542 DVB_PILOT_ON,
543 DVB_PILOT_OFF,
544 } dvb_fe_pilot_t;
545
546 typedef enum dvb_fe_rolloff {
547 DVB_ROLLOFF_NONE = 0,
548 DVB_ROLLOFF_AUTO,
549 DVB_ROLLOFF_20 = 200,
550 DVB_ROLLOFF_25 = 250,
551 DVB_ROLLOFF_35 = 350,
552 } dvb_fe_rolloff_t;
553
554 typedef enum dvb_fe_pls_mode {
555 DVB_PLS_ROOT = 0,
556 DVB_PLS_GOLD,
557 DVB_PLS_COMBO,
558 } dvb_fe_pls_mode_t;
559
560 typedef enum dvb_polarisation {
561 DVB_POLARISATION_HORIZONTAL = 0x00,
562 DVB_POLARISATION_VERTICAL = 0x01,
563 DVB_POLARISATION_CIRCULAR_LEFT = 0x02,
564 DVB_POLARISATION_CIRCULAR_RIGHT = 0x03,
565 DVB_POLARISATION_OFF = 0x04
566 } dvb_polarisation_t;
567
568 #define DVB_NO_STREAM_ID_FILTER (-1)
569
570 typedef struct dvb_qpsk_config {
571 dvb_polarisation_t polarisation;
572 int orbital_pos;
573 uint32_t symbol_rate;
574 dvb_fe_code_rate_t fec_inner;
575 } dvb_qpsk_config_t;
576
577 typedef struct dvb_qam_config {
578 uint32_t symbol_rate;
579 dvb_fe_code_rate_t fec_inner;
580 } dvb_qam_config_t;
581
582 typedef struct dvb_ofdm_config {
583 dvb_fe_bandwidth_t bandwidth;
584 dvb_fe_code_rate_t code_rate_HP;
585 dvb_fe_code_rate_t code_rate_LP;
586 dvb_fe_transmit_mode_t transmission_mode;
587 dvb_fe_guard_interval_t guard_interval;
588 dvb_fe_hierarchy_t hierarchy_information;
589 } dvb_ofdm_config_t;
590
591 typedef struct dvb_isdbt_config {
592 dvb_fe_bandwidth_t bandwidth;
593 dvb_fe_guard_interval_t guard_interval;
594 struct {
595 dvb_fe_code_rate_t fec;
596 dvb_fe_modulation_t modulation;
597 uint32_t segment_count;
598 uint32_t time_interleaving;
599 } layers[3];
600 } dvb_isdbt_config_t;
601
602 typedef struct dvb_mux_conf
603 {
604 dvb_fe_type_t dmc_fe_type;
605 dvb_fe_delivery_system_t dmc_fe_delsys;
606 dvb_fe_modulation_t dmc_fe_modulation;
607 uint32_t dmc_fe_freq;
608 dvb_fe_spectral_inversion_t dmc_fe_inversion;
609 dvb_fe_rolloff_t dmc_fe_rolloff;
610 dvb_fe_pilot_t dmc_fe_pilot;
611 int32_t dmc_fe_stream_id;
612 dvb_fe_pls_mode_t dmc_fe_pls_mode;
613 uint32_t dmc_fe_pls_code;
614 uint32_t dmc_fe_data_slice;
615 union {
616 dvb_qpsk_config_t dmc_fe_qpsk;
617 dvb_qam_config_t dmc_fe_qam;
618 dvb_ofdm_config_t dmc_fe_ofdm;
619 dvb_isdbt_config_t dmc_fe_isdbt;
620 } u;
621
622 // For scan file configurations
623 LIST_ENTRY(dvb_mux_conf) dmc_link;
624
625 } dvb_mux_conf_t;
626
627 /* conversion routines */
628 const char *dvb_rolloff2str ( int rolloff );
629 const char *dvb_delsys2str ( int delsys );
630 const char *dvb_fec2str ( int fec );
631 const char *dvb_qam2str ( int qam );
632 const char *dvb_bw2str ( int bw );
633 const char *dvb_mode2str ( int mode );
634 const char *dvb_inver2str ( int inver );
635 const char *dvb_guard2str ( int guard );
636 const char *dvb_hier2str ( int hier );
637 const char *dvb_pol2str ( int pol );
638 const char *dvb_type2str ( int type );
639 const char *dvb_pilot2str ( int pilot );
640 const char *dvb_plsmode2str ( int pls_mode );
641 #define dvb_feclo2str dvb_fec2str
642 #define dvb_fechi2str dvb_fec2str
643
644 int dvb_str2rolloff ( const char *str );
645 int dvb_str2delsys ( const char *str );
646 int dvb_str2fec ( const char *str );
647 int dvb_str2qam ( const char *str );
648 int dvb_str2bw ( const char *str );
649 int dvb_str2inver ( const char *str );
650 int dvb_str2mode ( const char *str );
651 int dvb_str2guard ( const char *str );
652 int dvb_str2hier ( const char *str );
653 int dvb_str2pol ( const char *str );
654 int dvb_str2type ( const char *str );
655 int dvb_str2pilot ( const char *str );
656 int dvb_str2plsmode ( const char *str );
657 #define dvb_str2feclo dvb_str2fec
658 #define dvb_str2fechi dvb_str2fec
659
dvb_bandwidth(dvb_fe_bandwidth_t bw)660 static inline int dvb_bandwidth( dvb_fe_bandwidth_t bw )
661 {
662 return bw < 1000 ? 0 : bw * 1000;
663 }
664
665 int dvb_delsys2type ( struct mpegts_network *ln, enum dvb_fe_delivery_system ds );
666
667 void dvb_mux_conf_init ( struct mpegts_network *ln, dvb_mux_conf_t *dmc,
668 dvb_fe_delivery_system_t delsys );
669
670 int dvb_mux_conf_str ( dvb_mux_conf_t *conf, char *buf, size_t bufsize );
671
672 const char *dvb_sat_position_to_str( int position, char *buf, size_t buflen );
673
674 int dvb_sat_position_from_str( const char *buf );
675
dvb_modulation_is_none_or_auto(int modulation)676 static inline int dvb_modulation_is_none_or_auto ( int modulation )
677 {
678 return modulation == DVB_MOD_NONE ||
679 modulation == DVB_MOD_AUTO ||
680 modulation == DVB_MOD_QAM_AUTO;
681 }
682
683 uint32_t dvb_sat_pls( dvb_mux_conf_t *dmc );
684
685 #endif /* ENABLE_MPEGTS_DVB */
686
687 void dvb_init ( void );
688 void dvb_done ( void );
689
690 #endif /* DVB_SUPPORT_H */
691