Bug #1234 » stable.diff
src/dvb/diseqc.c | ||
---|---|---|
1 | 1 |
#include <time.h> |
2 | 2 |
#include <linux/dvb/frontend.h> |
3 | 3 |
#include <sys/ioctl.h> |
4 | 4 | |
5 |
//#include "scan.h"
|
|
5 |
#include "tvheadend.h"
|
|
6 | 6 |
#include "diseqc.h" |
7 | 7 | |
8 | ||
9 |
struct diseqc_cmd switch_commited_cmds[] = { |
|
10 |
{ { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 }, 0 }, |
|
11 |
{ { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 }, 0 }, |
|
12 |
{ { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 }, 0 }, |
|
13 |
{ { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 }, 0 }, |
|
14 |
{ { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 }, 0 }, |
|
15 |
{ { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 }, 0 }, |
|
16 |
{ { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 }, 0 }, |
|
17 |
{ { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 }, 0 }, |
|
18 |
{ { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 }, 0 }, |
|
19 |
{ { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 }, 0 }, |
|
20 |
{ { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 }, 0 }, |
|
21 |
{ { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 }, 0 }, |
|
22 |
{ { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 }, 0 }, |
|
23 |
{ { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 }, 0 }, |
|
24 |
{ { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 }, 0 }, |
|
25 |
{ { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }, 0 } |
|
26 |
}; |
|
27 | ||
28 |
struct diseqc_cmd switch_uncommited_cmds[] = { |
|
29 |
{ { { 0xe0, 0x10, 0x39, 0xf0, 0x00, 0x00 }, 4 }, 0 }, |
|
30 |
{ { { 0xe0, 0x10, 0x39, 0xf1, 0x00, 0x00 }, 4 }, 0 }, |
|
31 |
{ { { 0xe0, 0x10, 0x39, 0xf2, 0x00, 0x00 }, 4 }, 0 }, |
|
32 |
{ { { 0xe0, 0x10, 0x39, 0xf3, 0x00, 0x00 }, 4 }, 0 }, |
|
33 |
{ { { 0xe0, 0x10, 0x39, 0xf4, 0x00, 0x00 }, 4 }, 0 }, |
|
34 |
{ { { 0xe0, 0x10, 0x39, 0xf5, 0x00, 0x00 }, 4 }, 0 }, |
|
35 |
{ { { 0xe0, 0x10, 0x39, 0xf6, 0x00, 0x00 }, 4 }, 0 }, |
|
36 |
{ { { 0xe0, 0x10, 0x39, 0xf7, 0x00, 0x00 }, 4 }, 0 }, |
|
37 |
{ { { 0xe0, 0x10, 0x39, 0xf8, 0x00, 0x00 }, 4 }, 0 }, |
|
38 |
{ { { 0xe0, 0x10, 0x39, 0xf9, 0x00, 0x00 }, 4 }, 0 }, |
|
39 |
{ { { 0xe0, 0x10, 0x39, 0xfa, 0x00, 0x00 }, 4 }, 0 }, |
|
40 |
{ { { 0xe0, 0x10, 0x39, 0xfb, 0x00, 0x00 }, 4 }, 0 }, |
|
41 |
{ { { 0xe0, 0x10, 0x39, 0xfc, 0x00, 0x00 }, 4 }, 0 }, |
|
42 |
{ { { 0xe0, 0x10, 0x39, 0xfd, 0x00, 0x00 }, 4 }, 0 }, |
|
43 |
{ { { 0xe0, 0x10, 0x39, 0xfe, 0x00, 0x00 }, 4 }, 0 }, |
|
44 |
{ { { 0xe0, 0x10, 0x39, 0xff, 0x00, 0x00 }, 4 }, 0 } |
|
45 |
}; |
|
46 | ||
47 | ||
48 | 8 |
/*--------------------------------------------------------------------------*/ |
49 | 9 | |
50 |
static inline |
|
51 |
void msleep(uint32_t msec)
|
|
10 |
static inline void
|
|
11 |
msleep(uint32_t msec) |
|
52 | 12 |
{ |
53 | 13 |
struct timespec req = { msec / 1000, 1000000 * (msec % 1000) }; |
54 | 14 | |
55 | 15 |
while (nanosleep(&req, &req)) |
56 | 16 |
; |
57 | 17 |
} |
58 | 18 | |
59 |
int diseqc_send_msg (int fd, fe_sec_voltage_t v, struct diseqc_cmd **cmd, |
|
60 |
fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b) |
|
19 |
int |
|
20 |
diseqc_send_msg(int fe_fd, __u8 framing_byte, __u8 address, __u8 cmd, |
|
21 |
__u8 data_1, __u8 data_2, __u8 data_3, __u8 msg_len) |
|
61 | 22 |
{ |
62 |
int err; |
|
23 |
struct dvb_diseqc_master_cmd message; |
|
24 | ||
25 |
#if DISEQC_TRACE |
|
26 |
tvhlog(LOG_DEBUG, "diseqc", "sending %X %X %X %X %X %X", |
|
27 |
framing_byte, address, cmd, data_1, data_2, data_3); |
|
28 |
#endif |
|
29 |
|
|
30 |
message.msg[0] = framing_byte; |
|
31 |
message.msg[1] = address; |
|
32 |
message.msg[2] = cmd; |
|
33 |
message.msg[3] = data_1; |
|
34 |
message.msg[4] = data_2; |
|
35 |
message.msg[5] = data_3; |
|
36 |
message.msg_len = msg_len; |
|
37 |
return ioctl(fe_fd, FE_DISEQC_SEND_MASTER_CMD, &message); |
|
38 |
} |
|
39 | ||
40 |
int |
|
41 |
diseqc_setup(int fe_fd, int lnb_num, int voltage, int band, |
|
42 |
uint32_t version, uint32_t repeats) |
|
43 |
{ |
|
44 |
int i = (lnb_num % 4) * 4 + voltage * 2 + (band ? 1 : 0); |
|
45 |
int j = lnb_num / 4; |
|
46 |
int k, err; |
|
47 | ||
48 |
#if DISEQC_TRACE |
|
49 |
tvhlog(LOG_DEBUG, "diseqc", |
|
50 |
"fe_fd %i, lnb_num %i, voltage %i, band %i, version %i, repeats %i", |
|
51 |
fe_fd, lnb_num, voltage, band, version, repeats); |
|
52 |
#endif |
|
53 | ||
54 |
/* verify lnb number and diseqc data */ |
|
55 |
if(lnb_num < 0 || lnb_num >=64 || i < 0 || i >= 16 || j < 0 || j >= 16) |
|
56 |
return -1; |
|
63 | 57 | |
64 |
if ((err = ioctl(fd, FE_SET_TONE, SEC_TONE_OFF))) |
|
58 |
/* turn off continuous tone */ |
|
59 |
if ((err = ioctl(fe_fd, FE_SET_TONE, SEC_TONE_OFF))) |
|
65 | 60 |
return err; |
66 | 61 | |
67 |
if ((err = ioctl(fd, FE_SET_VOLTAGE, v))) |
|
62 |
/* set lnb voltage */ |
|
63 |
if ((err = ioctl(fe_fd, FE_SET_VOLTAGE, |
|
64 |
(i/2) % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13))) |
|
68 | 65 |
return err; |
66 |
msleep(15); |
|
69 | 67 | |
68 |
if (repeats == 0) { /* uncommited msg, wait 15ms, commited msg */ |
|
69 |
if ((err = diseqc_send_msg(fe_fd, 0xE0, 0x10, 0x39, 0xF0 | j, 0, 0, 4))) |
|
70 |
return err; |
|
70 | 71 |
msleep(15); |
71 |
while (*cmd) { |
|
72 |
if ((err = ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd))) |
|
72 |
if ((err = diseqc_send_msg(fe_fd, 0xE0, 0x10, 0x38, 0xF0 | i, 0, 0, 4))) |
|
73 |
return err; |
|
74 |
} else { /* commited msg, 25ms, uncommited msg, 25ms, commited msg, etc */ |
|
75 |
if ((err = diseqc_send_msg(fe_fd, 0xE0, 0x10, 0x38, 0xF0 | i, 0, 0, 4))) |
|
76 |
return err; |
|
77 |
for (k = 0; k < repeats; k++) { |
|
78 |
msleep(25); |
|
79 |
if ((err = diseqc_send_msg(fe_fd, 0xE0, 0x10, 0x39, 0xF0 | j, 0, 0, 4))) |
|
80 |
return err; |
|
81 |
msleep(25); |
|
82 |
if ((err = diseqc_send_msg(fe_fd, 0xE1, 0x10, 0x38, 0xF0 | i, 0, 0, 4))) |
|
73 | 83 |
return err; |
74 | ||
75 |
msleep((*cmd)->wait); |
|
76 |
cmd++; |
|
77 | 84 |
} |
78 | ||
85 |
} |
|
79 | 86 |
msleep(15); |
80 | 87 | |
81 |
if ((err = ioctl(fd, FE_DISEQC_SEND_BURST, b))) |
|
88 |
/* set toneburst */ |
|
89 |
if ((err = ioctl(fe_fd, FE_DISEQC_SEND_BURST, |
|
90 |
(i/4) % 2 ? SEC_MINI_B : SEC_MINI_A))) |
|
82 | 91 |
return err; |
83 | ||
84 | 92 |
msleep(15); |
85 | 93 | |
86 |
return ioctl(fd, FE_SET_TONE, t); |
|
94 |
/* set continuous tone */ |
|
95 |
if ((err = ioctl(fe_fd, FE_SET_TONE, i % 2 ? SEC_TONE_ON : SEC_TONE_OFF))) |
|
96 |
return err; |
|
97 |
return 0; |
|
87 | 98 |
} |
88 | 99 | |
89 | ||
90 | 100 |
int |
91 |
diseqc_setup(int frontend_fd, int switch_pos, int voltage_18, int hiband, |
|
92 |
int diseqc_ver) |
|
101 |
diseqc_voltage_off(int fe_fd) |
|
93 | 102 |
{ |
94 |
struct diseqc_cmd *cmd[2] = { NULL, NULL }; |
|
95 |
int i = 4 * switch_pos + 2 * hiband + (voltage_18 ? 1 : 0); |
|
96 |
|
|
97 |
if (diseqc_ver == 1) { |
|
98 |
if(switch_pos < 0 || switch_pos >= (int) (sizeof(switch_uncommited_cmds)/sizeof(struct diseqc_cmd))) |
|
99 |
return -1; |
|
100 |
cmd[0] = &switch_uncommited_cmds[switch_pos]; |
|
101 |
} else { |
|
102 |
if(i < 0 || i >= (int) (sizeof(switch_commited_cmds)/sizeof(struct diseqc_cmd))) |
|
103 |
return -1; |
|
104 |
cmd[0] = &switch_commited_cmds[i]; |
|
105 |
} |
|
106 | ||
107 |
return diseqc_send_msg (frontend_fd, |
|
108 |
i % 2 ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13, |
|
109 |
cmd, |
|
110 |
(i/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF, |
|
111 |
(i/4) % 2 ? SEC_MINI_B : SEC_MINI_A); |
|
112 |
} |
|
113 | ||
114 | ||
115 |
int diseqc_voltage_off(int frontend_fd) |
|
116 |
{ |
|
117 |
fe_sec_voltage_t v = SEC_VOLTAGE_OFF; |
|
118 |
int err; |
|
119 | ||
120 |
if ((err = ioctl(frontend_fd, FE_SET_VOLTAGE, v))) |
|
121 |
return err; |
|
122 | ||
123 |
return 0; |
|
103 |
return ioctl(fe_fd, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF); |
|
124 | 104 |
} |
src/dvb/diseqc.h | ||
---|---|---|
2 | 2 |
#define __DISEQC_H__ |
3 | 3 | |
4 | 4 |
#include <stdint.h> |
5 | 5 |
#include <linux/dvb/frontend.h> |
6 | 6 | |
7 | ||
8 |
struct diseqc_cmd { |
|
9 |
struct dvb_diseqc_master_cmd cmd; |
|
10 |
uint32_t wait; |
|
11 |
}; |
|
12 | ||
13 | ||
14 |
extern int diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd **cmd, |
|
15 |
fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b); |
|
16 | ||
17 | ||
18 | 7 |
/** |
19 | 8 |
* set up the switch to position/voltage/tone |
20 | 9 |
*/ |
21 |
int diseqc_setup(int frontend_fd, int switch_pos, int voltage_18, int hiband, |
|
22 |
int diseqc_ver); |
|
23 | ||
24 |
int diseqc_voltage_off(int frontend_fd); |
|
10 |
int diseqc_send_msg(int fe_fd, __u8 framing_byte, __u8 address, __u8 cmd, |
|
11 |
__u8 data_1, __u8 data_2, __u8 data_3, __u8 msg_len); |
|
12 |
int diseqc_setup(int fe_fd, int lnb_num, int voltage, int band, |
|
13 |
uint32_t version, uint32_t repeats); |
|
14 |
int diseqc_voltage_off(int fe_fd); |
|
25 | 15 | |
26 | 16 |
#endif |
src/dvb/dvb.c | ||
---|---|---|
18 | 18 | |
19 | 19 | |
20 | 20 |
#include "tvheadend.h" |
21 | 21 |
#include "dvb.h" |
22 | 22 |
#include "dvb_support.h" |
23 |
#include "dvb_charset.h" |
|
23 | 24 | |
24 | 25 |
void |
25 |
dvb_init(uint32_t adapter_mask) |
|
26 |
dvb_init(uint32_t adapter_mask, const char *rawfile)
|
|
26 | 27 |
{ |
27 |
dvb_adapter_init(adapter_mask); |
|
28 |
dvb_charset_init(); |
|
29 |
dvb_adapter_init(adapter_mask, rawfile); |
|
28 | 30 |
} |
src/dvb/dvb.h | ||
---|---|---|
21 | 21 | |
22 | 22 |
#include <linux/dvb/version.h> |
23 | 23 |
#include <linux/dvb/frontend.h> |
24 | 24 |
#include <pthread.h> |
25 | 25 |
#include "htsmsg.h" |
26 |
#include "psi.h" |
|
26 | 27 | |
28 |
struct service; |
|
29 |
struct th_dvb_table; |
|
30 |
struct th_dvb_mux_instance; |
|
27 | 31 | |
28 | 32 |
#define DVB_VER_INT(maj,min) (((maj) << 16) + (min)) |
29 | 33 | |
30 | 34 |
#define DVB_VER_ATLEAST(maj, min) \ |
31 | 35 |
(DVB_VER_INT(DVB_API_VERSION, DVB_API_VERSION_MINOR) >= DVB_VER_INT(maj, min)) |
... | ... | |
41 | 45 |
* Satconf |
42 | 46 |
*/ |
43 | 47 |
typedef struct dvb_satconf { |
44 | 48 |
char *sc_id; |
45 | 49 |
TAILQ_ENTRY(dvb_satconf) sc_adapter_link; |
46 |
int sc_port; // diseqc switchport (0 - 15)
|
|
50 |
int sc_port; // diseqc switchport (0 - 63)
|
|
47 | 51 | |
48 | 52 |
char *sc_name; |
49 | 53 |
char *sc_comment; |
50 | 54 |
char *sc_lnb; |
51 | 55 | |
... | ... | |
91 | 95 |
LIST_ENTRY(th_dvb_mux_instance) tdmi_adapter_link; |
92 | 96 |
LIST_ENTRY(th_dvb_mux_instance) tdmi_adapter_hash_link; |
93 | 97 | |
94 | 98 |
struct th_dvb_adapter *tdmi_adapter; |
95 | 99 | |
96 |
uint16_t tdmi_snr, tdmi_signal; |
|
97 |
uint32_t tdmi_ber, tdmi_uncorrected_blocks; |
|
100 |
uint16_t tdmi_signal; |
|
101 |
uint32_t tdmi_ber, tdmi_unc; |
|
102 |
float tdmi_unc_avg; |
|
103 |
float tdmi_snr; |
|
98 | 104 | |
99 | 105 |
#define TDMI_FEC_ERR_HISTOGRAM_SIZE 10 |
100 | 106 |
uint32_t tdmi_fec_err_histogram[TDMI_FEC_ERR_HISTOGRAM_SIZE]; |
101 | 107 |
int tdmi_fec_err_ptr; |
102 | 108 | |
103 | 109 |
time_t tdmi_time; |
104 | 110 | |
105 | 111 | |
106 | 112 |
LIST_HEAD(, th_dvb_table) tdmi_tables; |
113 |
int tdmi_num_tables; |
|
114 | ||
107 | 115 |
TAILQ_HEAD(, th_dvb_table) tdmi_table_queue; |
108 | 116 |
int tdmi_table_initial; |
109 | 117 | |
110 | 118 |
enum { |
111 | 119 |
TDMI_FE_UNKNOWN, |
... | ... | |
127 | 135 |
dvb_mux_conf_t tdmi_conf; |
128 | 136 | |
129 | 137 |
/* Linked if tdmi_conf.dmc_satconf != NULL */ |
130 | 138 |
LIST_ENTRY(th_dvb_mux_instance) tdmi_satconf_link; |
131 | 139 | |
140 |
uint32_t tdmi_network_id; |
|
132 | 141 |
uint16_t tdmi_transport_stream_id; |
133 | 142 | |
134 | 143 |
char *tdmi_identifier; |
135 | 144 |
char *tdmi_network; /* Name of network, from NIT table */ |
136 | 145 | |
146 |
char *tdmi_default_authority; |
|
147 | ||
137 | 148 |
struct service_list tdmi_transports; /* via s_mux_link */ |
138 | 149 | |
139 | 150 |
TAILQ_ENTRY(th_dvb_mux_instance) tdmi_scan_link; |
140 | 151 |
struct th_dvb_mux_instance_queue *tdmi_scan_queue; |
141 | 152 | |
142 | 153 |
TAILQ_HEAD(, epggrab_ota_mux) tdmi_epg_grab; |
143 | 154 | |
155 |
struct th_subscription_list tdmi_subscriptions; |
|
156 | ||
144 | 157 |
} th_dvb_mux_instance_t; |
145 | 158 | |
146 | 159 | |
160 | ||
161 | ||
162 |
/** |
|
163 |
* When in raw mode we need to enqueue raw TS packet |
|
164 |
* to a different thread because we need to hold |
|
165 |
* global_lock when doing delivery of the tables |
|
166 |
*/ |
|
167 |
TAILQ_HEAD(dvb_table_feed_queue, dvb_table_feed); |
|
168 | ||
169 |
typedef struct dvb_table_feed { |
|
170 |
TAILQ_ENTRY(dvb_table_feed) dtf_link; |
|
171 |
uint8_t dtf_tsb[188]; |
|
172 |
} dvb_table_feed_t; |
|
173 | ||
174 | ||
175 | ||
147 | 176 |
/** |
148 | 177 |
* DVB Adapter (one of these per physical adapter) |
149 | 178 |
*/ |
150 | 179 |
#define TDA_MUX_HASH_WIDTH 101 |
151 | 180 | |
... | ... | |
173 | 202 | |
174 | 203 |
const char *tda_rootpath; |
175 | 204 |
char *tda_identifier; |
176 | 205 |
uint32_t tda_autodiscovery; |
177 | 206 |
uint32_t tda_idlescan; |
207 |
uint32_t tda_idleclose; |
|
178 | 208 |
uint32_t tda_skip_initialscan; |
179 | 209 |
uint32_t tda_skip_checksubscr; |
180 | 210 |
uint32_t tda_qmon; |
181 | 211 |
uint32_t tda_poweroff; |
182 | 212 |
uint32_t tda_sidtochan; |
183 | 213 |
uint32_t tda_nitoid; |
184 | 214 |
uint32_t tda_diseqc_version; |
215 |
uint32_t tda_diseqc_repeats; |
|
185 | 216 |
uint32_t tda_disable_pmt_monitor; |
217 |
int32_t tda_full_mux_rx; |
|
186 | 218 |
char *tda_displayname; |
187 | 219 | |
188 | 220 |
char *tda_fe_path; |
189 | 221 |
int tda_fe_fd; |
190 | 222 |
int tda_type; |
223 |
int tda_snr_valid; |
|
191 | 224 |
struct dvb_frontend_info *tda_fe_info; |
192 | 225 | |
193 | 226 |
int tda_adapter_num; |
194 | 227 | |
195 | 228 |
char *tda_demux_path; |
196 | 229 | |
197 |
char *tda_dvr_path; |
|
198 | 230 |
pthread_t tda_dvr_thread; |
199 | 231 |
int tda_dvr_pipe[2]; |
200 | 232 | |
201 | 233 |
int tda_hostconnection; |
202 | 234 | |
... | ... | |
211 | 243 |
int tda_sat; // Set if this adapter is a satellite receiver (DVB-S, etc) |
212 | 244 | |
213 | 245 |
struct dvb_satconf_queue tda_satconfs; |
214 | 246 | |
215 | 247 | |
216 |
struct th_dvb_mux_instance_list tda_mux_hash[TDA_MUX_HASH_WIDTH]; |
|
217 | ||
218 |
uint32_t tda_dump_muxes; |
|
219 | ||
220 |
int tda_allpids_dmx_fd; |
|
221 |
int tda_dump_fd; |
|
248 |
struct th_dvb_mux_instance_list tda_mux_list; |
|
222 | 249 | |
223 | 250 |
uint32_t tda_last_fec; |
224 | 251 | |
225 | 252 |
int tda_unc_is_delta; /* 1 if we believe FE_READ_UNCORRECTED_BLOCKS |
226 | 253 |
* return dela values */ |
227 | 254 | |
228 | 255 |
uint32_t tda_extrapriority; // extra priority for choosing the best adapter/service |
229 | 256 | |
257 |
void (*tda_open_service)(struct th_dvb_adapter *tda, struct service *s); |
|
258 |
void (*tda_close_service)(struct th_dvb_adapter *tda, struct service *s); |
|
259 |
void (*tda_open_table)(struct th_dvb_mux_instance *tdmi, struct th_dvb_table *s); |
|
260 |
void (*tda_close_table)(struct th_dvb_mux_instance *tdmi, struct th_dvb_table *s); |
|
261 | ||
262 |
int tda_rawmode; |
|
263 | ||
264 |
// Full mux streaming, protected via the delivery mutex |
|
265 | ||
266 |
streaming_pad_t tda_streaming_pad; |
|
267 | ||
268 | ||
269 |
struct dvb_table_feed_queue tda_table_feed; |
|
270 |
pthread_cond_t tda_table_feed_cond; // Bound to tda_delivery_mutex |
|
271 | ||
272 |
// PIDs that needs to be requeued and processed as tables |
|
273 |
uint8_t tda_table_filter[8192]; |
|
274 | ||
275 | ||
230 | 276 |
} th_dvb_adapter_t; |
231 | 277 | |
232 | 278 |
/** |
233 | 279 |
* DVB table |
234 | 280 |
*/ |
... | ... | |
251 | 297 |
* File descriptor for filter |
252 | 298 |
*/ |
253 | 299 |
int tdt_fd; |
254 | 300 | |
255 | 301 |
LIST_ENTRY(th_dvb_table) tdt_link; |
302 |
th_dvb_mux_instance_t *tdt_tdmi; |
|
256 | 303 | |
257 | 304 |
char *tdt_name; |
258 | 305 | |
259 | 306 |
void *tdt_opaque; |
260 | 307 |
int (*tdt_callback)(th_dvb_mux_instance_t *tdmi, uint8_t *buf, int len, |
... | ... | |
262 | 309 | |
263 | 310 | |
264 | 311 |
int tdt_count; |
265 | 312 |
int tdt_pid; |
266 | 313 | |
267 |
struct dmx_sct_filter_params *tdt_fparams; |
|
268 | ||
269 | 314 |
int tdt_id; |
270 | 315 | |
316 |
int tdt_table; |
|
317 |
int tdt_mask; |
|
318 | ||
319 |
int tdt_destroyed; |
|
320 |
int tdt_refcount; |
|
321 | ||
322 |
psi_section_t tdt_sect; // Manual reassembly |
|
323 | ||
271 | 324 |
} th_dvb_table_t; |
272 | 325 | |
273 | 326 | |
274 | 327 |
extern struct th_dvb_adapter_queue dvb_adapters; |
275 | 328 |
extern struct th_dvb_mux_instance_tree dvb_muxes; |
276 | 329 | |
277 |
void dvb_init(uint32_t adapter_mask); |
|
330 |
void dvb_init(uint32_t adapter_mask, const char *rawfile);
|
|
278 | 331 | |
279 | 332 |
/** |
280 | 333 |
* DVB Adapter |
281 | 334 |
*/ |
282 |
void dvb_adapter_init(uint32_t adapter_mask); |
|
335 |
void dvb_adapter_init(uint32_t adapter_mask, const char *rawfile);
|
|
283 | 336 | |
284 | 337 |
void dvb_adapter_mux_scanner(void *aux); |
285 | 338 | |
286 | 339 |
void dvb_adapter_start (th_dvb_adapter_t *tda); |
287 | 340 | |
... | ... | |
297 | 350 | |
298 | 351 |
void dvb_adapter_set_skip_checksubscr(th_dvb_adapter_t *tda, int on); |
299 | 352 | |
300 | 353 |
void dvb_adapter_set_qmon(th_dvb_adapter_t *tda, int on); |
301 | 354 | |
302 |
void dvb_adapter_set_dump_muxes(th_dvb_adapter_t *tda, int on);
|
|
355 |
void dvb_adapter_set_idleclose(th_dvb_adapter_t *tda, int on);
|
|
303 | 356 | |
304 | 357 |
void dvb_adapter_set_poweroff(th_dvb_adapter_t *tda, int on); |
305 | 358 | |
306 | 359 |
void dvb_adapter_set_sidtochan(th_dvb_adapter_t *tda, int on); |
307 | 360 | |
308 | 361 |
void dvb_adapter_set_nitoid(th_dvb_adapter_t *tda, int nitoid); |
309 | 362 | |
310 | 363 |
void dvb_adapter_set_diseqc_version(th_dvb_adapter_t *tda, unsigned int v); |
311 | 364 | |
365 |
void dvb_adapter_set_diseqc_repeats(th_dvb_adapter_t *tda, |
|
366 |
unsigned int repeats); |
|
367 | ||
312 | 368 |
void dvb_adapter_set_disable_pmt_monitor(th_dvb_adapter_t *tda, int on); |
313 | 369 | |
370 |
void dvb_adapter_set_full_mux_rx(th_dvb_adapter_t *tda, int r); |
|
371 | ||
314 | 372 |
void dvb_adapter_clone(th_dvb_adapter_t *dst, th_dvb_adapter_t *src); |
315 | 373 | |
316 | 374 |
void dvb_adapter_clean(th_dvb_adapter_t *tda); |
317 | 375 | |
318 | 376 |
int dvb_adapter_destroy(th_dvb_adapter_t *tda); |
... | ... | |
325 | 383 | |
326 | 384 |
void dvb_adapter_set_extrapriority(th_dvb_adapter_t *tda, int extrapriority); |
327 | 385 | |
328 | 386 |
void dvb_adapter_poweroff(th_dvb_adapter_t *tda); |
329 | 387 | |
388 |
void dvb_input_filtered_setup(th_dvb_adapter_t *tda); |
|
389 | ||
390 |
void dvb_input_raw_setup(th_dvb_adapter_t *tda); |
|
391 | ||
392 | ||
393 | ||
330 | 394 |
/** |
331 | 395 |
* DVB Multiplex |
332 | 396 |
*/ |
333 | 397 |
const char* dvb_mux_fec2str(int fec); |
334 | 398 |
const char* dvb_mux_delsys2str(int delsys); |
... | ... | |
348 | 412 | |
349 | 413 |
void dvb_mux_destroy(th_dvb_mux_instance_t *tdmi); |
350 | 414 | |
351 | 415 |
th_dvb_mux_instance_t *dvb_mux_create(th_dvb_adapter_t *tda, |
352 | 416 |
const struct dvb_mux_conf *dmc, |
353 |
uint16_t tsid, const char *network, |
|
417 |
uint16_t onid, uint16_t tsid, const char *network,
|
|
354 | 418 |
const char *logprefix, int enabled, |
355 | 419 |
int initialscan, const char *identifier, |
356 | 420 |
dvb_satconf_t *satconf); |
357 | 421 | |
358 | 422 |
void dvb_mux_set_networkname(th_dvb_mux_instance_t *tdmi, const char *name); |
359 | 423 | |
360 | 424 |
void dvb_mux_set_tsid(th_dvb_mux_instance_t *tdmi, uint16_t tsid); |
361 | 425 | |
426 |
void dvb_mux_set_onid(th_dvb_mux_instance_t *tdmi, uint16_t onid); |
|
427 | ||
362 | 428 |
void dvb_mux_set_enable(th_dvb_mux_instance_t *tdmi, int enabled); |
363 | 429 | |
364 | 430 |
void dvb_mux_set_satconf(th_dvb_mux_instance_t *tdmi, const char *scid, |
365 | 431 |
int save); |
366 | 432 | |
... | ... | |
386 | 452 |
int dvb_mux_copy(th_dvb_adapter_t *dst, th_dvb_mux_instance_t *tdmi_src, |
387 | 453 |
dvb_satconf_t *satconf); |
388 | 454 | |
389 | 455 |
void dvb_mux_add_to_scan_queue (th_dvb_mux_instance_t *tdmi); |
390 | 456 | |
457 |
th_dvb_mux_instance_t *dvb_mux_find |
|
458 |
(th_dvb_adapter_t *tda, const char *netname, uint16_t onid, uint16_t tsid, |
|
459 |
int enabled ); |
|
460 | ||
391 | 461 |
/** |
392 | 462 |
* DVB Transport (aka DVB service) |
393 | 463 |
*/ |
394 |
void dvb_transport_load(th_dvb_mux_instance_t *tdmi);
|
|
464 |
void dvb_service_load(th_dvb_mux_instance_t *tdmi, const char *tdmi_identifier);
|
|
395 | 465 | |
396 |
struct service *dvb_transport_find(th_dvb_mux_instance_t *tdmi,
|
|
466 |
struct service *dvb_service_find(th_dvb_mux_instance_t *tdmi,
|
|
397 | 467 |
uint16_t sid, int pmt_pid, |
398 | 468 |
const char *identifier); |
399 | 469 | |
400 |
struct service *dvb_transport_find2(th_dvb_mux_instance_t *tdmi,
|
|
470 |
struct service *dvb_service_find2(th_dvb_mux_instance_t *tdmi,
|
|
401 | 471 |
uint16_t sid, int pmt_pid, |
402 | 472 |
const char *identifier, int *save); |
403 | 473 | |
404 |
void dvb_transport_notify(struct service *t); |
|
474 |
struct service *dvb_service_find3 |
|
475 |
(th_dvb_adapter_t *tda, th_dvb_mux_instance_t *tdmi, |
|
476 |
const char *netname, uint16_t onid, uint16_t tsid, uint16_t sid, |
|
477 |
int enabled, int epgprimary); |
|
405 | 478 | |
406 |
void dvb_transport_notify_by_adapter(th_dvb_adapter_t *tda);
|
|
479 |
void dvb_service_notify(struct service *t);
|
|
407 | 480 | |
408 |
htsmsg_t *dvb_transport_build_msg(struct service *t); |
|
481 |
void dvb_service_notify_by_adapter(th_dvb_adapter_t *tda); |
|
482 | ||
483 |
htsmsg_t *dvb_service_build_msg(struct service *t); |
|
409 | 484 | |
410 | 485 |
/** |
411 | 486 |
* DVB Frontend |
412 | 487 |
*/ |
413 | 488 |
int dvb_fe_tune(th_dvb_mux_instance_t *tdmi, const char *reason); |
... | ... | |
426 | 501 | |
427 | 502 |
void dvb_table_add_pmt(th_dvb_mux_instance_t *tdmi, int pmt_pid); |
428 | 503 | |
429 | 504 |
void dvb_table_rem_pmt(th_dvb_mux_instance_t *tdmi, int pmt_pid); |
430 | 505 | |
431 |
struct dmx_sct_filter_params *dvb_fparams_alloc(void); |
|
432 | ||
433 |
void |
|
434 |
tdt_add(th_dvb_mux_instance_t *tdmi, struct dmx_sct_filter_params *fparams, |
|
506 |
void tdt_add(th_dvb_mux_instance_t *tdmi, int table, int mask, |
|
435 | 507 |
int (*callback)(th_dvb_mux_instance_t *tdmi, uint8_t *buf, int len, |
436 | 508 |
uint8_t tableid, void *opaque), void *opaque, |
437 |
const char *name, int flags, int pid, th_dvb_table_t *tdt); |
|
509 |
const char *name, int flags, int pid); |
|
510 | ||
511 |
int dvb_pidx11_callback |
|
512 |
(th_dvb_mux_instance_t *tdmi, uint8_t *ptr, int len, |
|
513 |
uint8_t tableid, void *opaque); |
|
438 | 514 | |
439 | 515 |
#define TDT_CRC 0x1 |
440 | 516 |
#define TDT_QUICKREQ 0x2 |
441 | 517 |
#define TDT_CA 0x4 |
442 | 518 |
#define TDT_TDT 0x8 |
443 | 519 | |
520 |
void dvb_table_dispatch(uint8_t *sec, int r, th_dvb_table_t *tdt); |
|
521 | ||
522 |
void dvb_table_release(th_dvb_table_t *tdt); |
|
523 | ||
444 | 524 |
/** |
445 | 525 |
* Satellite configuration |
446 | 526 |
*/ |
447 | 527 |
void dvb_satconf_init(th_dvb_adapter_t *tda); |
448 | 528 | |
... | ... | |
454 | 534 |
const char *id, int create); |
455 | 535 | |
456 | 536 |
void dvb_lnb_get_frequencies(const char *id, |
457 | 537 |
int *f_low, int *f_hi, int *f_switch); |
458 | 538 | |
539 | ||
540 |
/** |
|
541 |
* Raw demux |
|
542 |
*/ |
|
543 |
struct th_subscription; |
|
544 |
struct th_subscription *dvb_subscription_create_from_tdmi(th_dvb_mux_instance_t *tdmi, |
|
545 |
const char *name, |
|
546 |
streaming_target_t *st); |
|
547 | ||
459 | 548 |
#endif /* DVB_H_ */ |
549 |
src/dvb/dvb_adapter.c | ||
---|---|---|
14 | 14 |
* |
15 | 15 |
* You should have received a copy of the GNU General Public License |
16 | 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
*/ |
18 | 18 | |
19 |
#define _GNU_SOURCE |
|
20 | 19 |
#include <pthread.h> |
21 | 20 |
#include <assert.h> |
22 | 21 | |
23 | 22 |
#include <sys/types.h> |
24 | 23 |
#include <sys/stat.h> |
... | ... | |
63 | 62 | |
64 | 63 |
for (i = 0; i < TDA_SCANQ_NUM; i++ ) |
65 | 64 |
TAILQ_INIT(&tda->tda_scan_queues[i]); |
66 | 65 |
TAILQ_INIT(&tda->tda_initial_scan_queue); |
67 | 66 |
TAILQ_INIT(&tda->tda_satconfs); |
68 | ||
69 |
tda->tda_allpids_dmx_fd = -1; |
|
70 |
tda->tda_dump_fd = -1; |
|
71 | ||
67 |
streaming_pad_init(&tda->tda_streaming_pad); |
|
72 | 68 |
return tda; |
73 | 69 |
} |
74 | 70 | |
75 | 71 | |
76 | 72 |
/** |
... | ... | |
85 | 81 | |
86 | 82 |
htsmsg_add_str(m, "type", dvb_adaptertype_to_str(tda->tda_type)); |
87 | 83 |
htsmsg_add_str(m, "displayname", tda->tda_displayname); |
88 | 84 |
htsmsg_add_u32(m, "autodiscovery", tda->tda_autodiscovery); |
89 | 85 |
htsmsg_add_u32(m, "idlescan", tda->tda_idlescan); |
86 |
htsmsg_add_u32(m, "idleclose", tda->tda_idleclose); |
|
90 | 87 |
htsmsg_add_u32(m, "skip_checksubscr", tda->tda_skip_checksubscr); |
88 |
htsmsg_add_u32(m, "sidtochan", tda->tda_sidtochan); |
|
91 | 89 |
htsmsg_add_u32(m, "qmon", tda->tda_qmon); |
92 |
htsmsg_add_u32(m, "dump_muxes", tda->tda_dump_muxes); |
|
93 | 90 |
htsmsg_add_u32(m, "poweroff", tda->tda_poweroff); |
94 | 91 |
htsmsg_add_u32(m, "nitoid", tda->tda_nitoid); |
95 | 92 |
htsmsg_add_u32(m, "diseqc_version", tda->tda_diseqc_version); |
93 |
htsmsg_add_u32(m, "diseqc_repeats", tda->tda_diseqc_repeats); |
|
96 | 94 |
htsmsg_add_u32(m, "extrapriority", tda->tda_extrapriority); |
97 | 95 |
htsmsg_add_u32(m, "skip_initialscan", tda->tda_skip_initialscan); |
98 | 96 |
htsmsg_add_u32(m, "disable_pmt_monitor", tda->tda_disable_pmt_monitor); |
97 |
htsmsg_add_s32(m, "full_mux_rx", tda->tda_full_mux_rx); |
|
99 | 98 |
hts_settings_save(m, "dvbadapters/%s", tda->tda_identifier); |
100 | 99 |
htsmsg_destroy(m); |
101 | 100 |
} |
102 | 101 | |
103 | 102 | |
... | ... | |
182 | 181 | |
183 | 182 |
/** |
184 | 183 |
* |
185 | 184 |
*/ |
186 | 185 |
void |
186 |
dvb_adapter_set_idleclose(th_dvb_adapter_t *tda, int on) |
|
187 |
{ |
|
188 |
if(tda->tda_idleclose == on) |
|
189 |
return; |
|
190 | ||
191 |
lock_assert(&global_lock); |
|
192 | ||
193 |
tvhlog(LOG_NOTICE, "dvb", "Adapter \"%s\" idle fd close set to: %s", |
|
194 |
tda->tda_displayname, on ? "On" : "Off"); |
|
195 | ||
196 |
tda->tda_idleclose = on; |
|
197 |
tda_save(tda); |
|
198 |
} |
|
199 | ||
200 | ||
201 |
/** |
|
202 |
* |
|
203 |
*/ |
|
204 |
void |
|
187 | 205 |
dvb_adapter_set_skip_checksubscr(th_dvb_adapter_t *tda, int on) |
188 | 206 |
{ |
189 | 207 |
if(tda->tda_skip_checksubscr == on) |
190 | 208 |
return; |
191 | 209 | |
... | ... | |
255 | 273 | |
256 | 274 |
/** |
257 | 275 |
* |
258 | 276 |
*/ |
259 | 277 |
void |
260 |
dvb_adapter_set_dump_muxes(th_dvb_adapter_t *tda, int on) |
|
261 |
{ |
|
262 |
if(tda->tda_dump_muxes == on) |
|
263 |
return; |
|
264 | ||
265 |
lock_assert(&global_lock); |
|
266 | ||
267 |
tvhlog(LOG_NOTICE, "dvb", "Adapter \"%s\" dump of DVB mux input set to: %s", |
|
268 |
tda->tda_displayname, on ? "On" : "Off"); |
|
269 | ||
270 |
tda->tda_dump_muxes = on; |
|
271 |
tda_save(tda); |
|
272 |
} |
|
273 | ||
274 | ||
275 |
/** |
|
276 |
* |
|
277 |
*/ |
|
278 |
void |
|
279 | 278 |
dvb_adapter_set_nitoid(th_dvb_adapter_t *tda, int nitoid) |
280 | 279 |
{ |
281 | 280 |
lock_assert(&global_lock); |
282 | 281 | |
283 | 282 |
if(tda->tda_nitoid == nitoid) |
... | ... | |
313 | 312 |
tda->tda_diseqc_version = v; |
314 | 313 |
tda_save(tda); |
315 | 314 |
} |
316 | 315 | |
317 | 316 |
/** |
317 |
* sets the number of diseqc repeats to perform |
|
318 |
*/ |
|
319 |
void |
|
320 |
dvb_adapter_set_diseqc_repeats(th_dvb_adapter_t *tda, unsigned int repeats) |
|
321 |
{ |
|
322 |
if(tda->tda_diseqc_repeats == repeats) |
|
323 |
return; |
|
324 |
lock_assert(&global_lock); |
|
325 |
tvhlog(LOG_NOTICE, "dvb", "Adapter \"%s\" DiSEqC repeats set to: %i", |
|
326 |
tda->tda_displayname, repeats); |
|
327 |
tda->tda_diseqc_repeats = repeats; |
|
328 |
tda_save(tda); |
|
329 |
} |
|
330 | ||
331 |
/** |
|
318 | 332 |
* |
319 | 333 |
*/ |
320 | 334 |
void |
321 | 335 |
dvb_adapter_set_extrapriority(th_dvb_adapter_t *tda, int extrapriority) |
322 | 336 |
{ |
... | ... | |
352 | 366 | |
353 | 367 | |
354 | 368 |
/** |
355 | 369 |
* |
356 | 370 |
*/ |
371 |
void |
|
372 |
dvb_adapter_set_full_mux_rx(th_dvb_adapter_t *tda, int on) |
|
373 |
{ |
|
374 |
const char* label[] = { "Auto", "Off", "On" }; |
|
375 |
|
|
376 |
if (on < -1) on = -1; |
|
377 |
if (on > 1) on = 1; |
|
378 | ||
379 |
if(tda->tda_full_mux_rx == on) |
|
380 |
return; |
|
381 | ||
382 |
lock_assert(&global_lock); |
|
383 | ||
384 |
tvhlog(LOG_NOTICE, "dvb", |
|
385 |
"Adapter \"%s\" disabled full MUX receive set to: %s", |
|
386 |
tda->tda_displayname, label[on+1]); |
|
387 | ||
388 |
tda->tda_full_mux_rx = on; |
|
389 |
tda_save(tda); |
|
390 |
} |
|
391 | ||
392 | ||
393 |
/** |
|
394 |
* |
|
395 |
*/ |
|
357 | 396 |
static void |
358 | 397 |
dvb_adapter_checkspeed(th_dvb_adapter_t *tda) |
359 | 398 |
{ |
360 | 399 |
char dev[64]; |
361 | 400 | |
362 | 401 |
snprintf(dev, sizeof(dev), "dvb/dvb%d.dvr0", tda->tda_adapter_num); |
363 | 402 |
tda->tda_hostconnection = get_device_connection(dev); |
364 | 403 |
} |
365 | 404 | |
366 | 405 | |
406 | ||
407 | ||
408 |
/** |
|
409 |
* Return 1 if an adapter is capable of receiving a full mux |
|
410 |
*/ |
|
411 |
static int |
|
412 |
check_full_stream(th_dvb_adapter_t *tda) |
|
413 |
{ |
|
414 |
struct dmx_pes_filter_params dmx_param; |
|
415 |
int r; |
|
416 | ||
417 |
if(tda->tda_full_mux_rx != -1) |
|
418 |
return tda->tda_full_mux_rx; |
|
419 | ||
420 |
if(tda->tda_hostconnection == HOSTCONNECTION_USB12) |
|
421 |
return 0; // Don't even bother, device <-> host interface is too slow |
|
422 | ||
423 |
if(tda->tda_hostconnection == HOSTCONNECTION_USB480) |
|
424 |
return 0; // USB in general appears to have CPU loading issues? |
|
425 | ||
426 |
int fd = tvh_open(tda->tda_demux_path, O_RDWR, 0); |
|
427 |
if(fd == -1) |
|
428 |
return 0; |
|
429 | ||
430 |
memset(&dmx_param, 0, sizeof(dmx_param)); |
|
431 |
dmx_param.pid = 0x2000; |
|
432 |
dmx_param.input = DMX_IN_FRONTEND; |
|
433 |
dmx_param.output = DMX_OUT_TS_TAP; |
|
434 |
dmx_param.pes_type = DMX_PES_OTHER; |
|
435 |
dmx_param.flags = DMX_IMMEDIATE_START; |
|
436 | ||
437 |
r = ioctl(fd, DMX_SET_PES_FILTER, &dmx_param); |
|
438 |
close(fd); |
|
439 |
return !r; |
|
440 |
} |
|
441 | ||
442 | ||
367 | 443 |
/** |
368 | 444 |
* |
369 | 445 |
*/ |
370 | 446 |
static void |
371 | 447 |
tda_add(int adapter_num) |
... | ... | |
390 | 466 | |
391 | 467 |
tda->tda_adapter_num = adapter_num; |
392 | 468 |
tda->tda_rootpath = strdup(path); |
393 | 469 |
tda->tda_demux_path = malloc(256); |
394 | 470 |
snprintf(tda->tda_demux_path, 256, "%s/demux0", path); |
395 |
tda->tda_dvr_path = malloc(256); |
|
396 |
snprintf(tda->tda_dvr_path, 256, "%s/dvr0", path); |
|
397 | 471 |
tda->tda_fe_path = strdup(fname); |
398 | ||
399 | 472 |
tda->tda_fe_fd = -1; |
400 | 473 |
tda->tda_dvr_pipe[0] = -1; |
474 |
tda->tda_full_mux_rx = -1; |
|
401 | 475 | |
402 | 476 |
tda->tda_fe_info = malloc(sizeof(struct dvb_frontend_info)); |
403 | 477 | |
404 | 478 |
if(ioctl(fe, FE_GET_INFO, tda->tda_fe_info)) { |
405 | 479 |
tvhlog(LOG_ALERT, "dvb", "%s: Unable to query adapter", fname); |
406 | 480 |
close(fe); |
407 | 481 |
free(tda); |
408 | 482 |
return; |
409 | 483 |
} |
484 |
if (tda->tda_idlescan || !tda->tda_idleclose) |
|
485 |
tda->tda_fe_fd = fe; |
|
486 |
else |
|
410 | 487 |
close(fe); |
411 | 488 | |
412 | 489 |
tda->tda_type = tda->tda_fe_info->type; |
413 | 490 | |
414 | 491 |
snprintf(buf, sizeof(buf), "%s_%s", tda->tda_rootpath, |
... | ... | |
431 | 508 | |
432 | 509 |
tda->tda_displayname = strdup(tda->tda_fe_info->name); |
433 | 510 | |
434 | 511 |
dvb_adapter_checkspeed(tda); |
435 | 512 | |
513 | ||
514 |
if(!strcmp(tda->tda_fe_info->name, "Sony CXD2820R (DVB-T/T2)")) |
|
515 |
tda->tda_snr_valid = 1; |
|
516 | ||
436 | 517 |
tvhlog(LOG_INFO, "dvb", |
437 |
"Found adapter %s (%s) via %s", path, tda->tda_fe_info->name, |
|
438 |
hostconnection2str(tda->tda_hostconnection)); |
|
518 |
"Found adapter %s (%s) via %s%s", path, tda->tda_fe_info->name, |
|
519 |
hostconnection2str(tda->tda_hostconnection), |
|
520 |
tda->tda_snr_valid ? ", Reports valid SNR values" : ""); |
|
439 | 521 | |
440 | 522 |
TAILQ_INSERT_TAIL(&dvb_adapters, tda, tda_global_link); |
441 | 523 | |
524 |
gtimer_arm(&tda->tda_mux_scanner_timer, dvb_adapter_mux_scanner, tda, 1); |
|
525 |
} |
|
442 | 526 | |
443 |
dvb_table_init(tda); |
|
444 | 527 | |
445 |
if(tda->tda_sat) |
|
446 |
dvb_satconf_init(tda); |
|
447 | 528 | |
448 |
gtimer_arm(&tda->tda_mux_scanner_timer, dvb_adapter_mux_scanner, tda, 1); |
|
529 |
/** |
|
530 |
* |
|
531 |
*/ |
|
532 |
static void |
|
533 |
tda_add_from_file(const char *filename) |
|
534 |
{ |
|
535 |
int i, r; |
|
536 |
th_dvb_adapter_t *tda; |
|
537 |
char buf[400]; |
|
538 | ||
539 |
tda = tda_alloc(); |
|
540 | ||
541 |
tda->tda_adapter_num = -1; |
|
542 |
tda->tda_fe_fd = -1; |
|
543 |
tda->tda_dvr_pipe[0] = -1; |
|
544 | ||
545 |
tda->tda_type = -1; |
|
546 | ||
547 |
snprintf(buf, sizeof(buf), "%s", filename); |
|
548 | ||
549 |
r = strlen(buf); |
|
550 |
for(i = 0; i < r; i++) |
|
551 |
if(!isalnum((int)buf[i])) |
|
552 |
buf[i] = '_'; |
|
553 | ||
554 |
tda->tda_identifier = strdup(buf); |
|
555 |
|
|
556 |
tda->tda_autodiscovery = 0; |
|
557 |
tda->tda_idlescan = 0; |
|
558 | ||
559 |
tda->tda_sat = 0; |
|
560 |
|
|
561 |
tda->tda_full_mux_rx = 1; |
|
562 | ||
563 |
/* Come up with an initial displayname, user can change it and it will |
|
564 |
be overridden by any stored settings later on */ |
|
565 | ||
566 |
tda->tda_displayname = strdup(filename); |
|
567 | ||
568 |
TAILQ_INSERT_TAIL(&dvb_adapters, tda, tda_global_link); |
|
449 | 569 |
} |
450 | 570 | |
571 |
/** |
|
572 |
* Initiliase input |
|
573 |
*/ |
|
574 |
static void tda_init_input (th_dvb_adapter_t *tda) |
|
575 |
{ |
|
576 |
if(tda->tda_type == -1 || check_full_stream(tda)) { |
|
577 |
tvhlog(LOG_INFO, "dvb", "Adapter %s will run in full mux mode", tda->tda_rootpath); |
|
578 |
dvb_input_raw_setup(tda); |
|
579 |
} else { |
|
580 |
tvhlog(LOG_INFO, "dvb", "Adapter %s will run in filtered mode", tda->tda_rootpath); |
|
581 |
dvb_input_filtered_setup(tda); |
|
582 |
} |
|
583 |
} |
|
584 | ||
585 | ||
586 | ||
587 |
/** |
|
588 |
* |
|
589 |
*/ |
|
451 | 590 |
void |
452 | 591 |
dvb_adapter_start ( th_dvb_adapter_t *tda ) |
453 | 592 |
{ |
454 | 593 |
/* Open front end */ |
455 | 594 |
if (tda->tda_fe_fd == -1) { |
... | ... | |
458 | 597 |
tvhlog(LOG_DEBUG, "dvb", "%s opened frontend %s", tda->tda_rootpath, tda->tda_fe_path); |
459 | 598 |
} |
460 | 599 | |
461 | 600 |
/* Start DVR thread */ |
462 | 601 |
if (tda->tda_dvr_pipe[0] == -1) { |
463 |
assert(pipe2(tda->tda_dvr_pipe, O_NONBLOCK | O_CLOEXEC) != -1); |
|
602 |
int err = pipe(tda->tda_dvr_pipe); |
|
603 |
assert(err != -1); |
|
604 | ||
605 |
fcntl(tda->tda_dvr_pipe[0], F_SETFD, fcntl(tda->tda_dvr_pipe[0], F_GETFD) | FD_CLOEXEC); |
|
606 |
fcntl(tda->tda_dvr_pipe[0], F_SETFL, fcntl(tda->tda_dvr_pipe[0], F_GETFL) | O_NONBLOCK); |
|
607 |
fcntl(tda->tda_dvr_pipe[1], F_SETFD, fcntl(tda->tda_dvr_pipe[1], F_GETFD) | FD_CLOEXEC); |
|
464 | 608 |
pthread_create(&tda->tda_dvr_thread, NULL, dvb_adapter_input_dvr, tda); |
465 | 609 |
tvhlog(LOG_DEBUG, "dvb", "%s started dvr thread", tda->tda_rootpath); |
466 | 610 |
} |
467 | 611 |
} |
468 | 612 | |
... | ... | |
470 | 614 |
dvb_adapter_stop ( th_dvb_adapter_t *tda ) |
471 | 615 |
{ |
472 | 616 |
/* Poweroff */ |
473 | 617 |
dvb_adapter_poweroff(tda); |
474 | 618 | |
619 |
/* Don't stop/close */ |
|
620 |
if (!tda->tda_idleclose) return; |
|
621 | ||
475 | 622 |
/* Close front end */ |
476 | 623 |
if (tda->tda_fe_fd != -1) { |
477 | 624 |
tvhlog(LOG_DEBUG, "dvb", "%s closing frontend", tda->tda_rootpath); |
478 | 625 |
close(tda->tda_fe_fd); |
479 | 626 |
tda->tda_fe_fd = -1; |
480 | 627 |
} |
481 | 628 | |
482 | 629 |
/* Stop DVR thread */ |
483 | 630 |
if (tda->tda_dvr_pipe[0] != -1) { |
484 | 631 |
tvhlog(LOG_DEBUG, "dvb", "%s stopping thread", tda->tda_rootpath); |
485 |
assert(write(tda->tda_dvr_pipe[1], "", 1) == 1); |
|
632 |
int err = write(tda->tda_dvr_pipe[1], "", 1); |
|
633 |
assert(err != -1); |
|
486 | 634 |
pthread_join(tda->tda_dvr_thread, NULL); |
487 | 635 |
close(tda->tda_dvr_pipe[0]); |
488 | 636 |
close(tda->tda_dvr_pipe[1]); |
489 | 637 |
tda->tda_dvr_pipe[0] = -1; |
490 | 638 |
tvhlog(LOG_DEBUG, "dvb", "%s stopped thread", tda->tda_rootpath); |
... | ... | |
493 | 641 | |
494 | 642 |
/** |
495 | 643 |
* |
496 | 644 |
*/ |
497 | 645 |
void |
498 |
dvb_adapter_init(uint32_t adapter_mask) |
|
646 |
dvb_adapter_init(uint32_t adapter_mask, const char *rawfile)
|
|
499 | 647 |
{ |
500 | 648 |
htsmsg_t *l, *c; |
501 | 649 |
htsmsg_field_t *f; |
502 | 650 |
const char *name, *s; |
503 | 651 |
int i, type; |
652 |
uint32_t u32; |
|
504 | 653 |
th_dvb_adapter_t *tda; |
505 | 654 | |
506 | 655 |
TAILQ_INIT(&dvb_adapters); |
507 | 656 | |
657 |
/* Initialise hardware */ |
|
508 | 658 |
for(i = 0; i < 32; i++) |
509 | 659 |
if ((1 << i) & adapter_mask) |
510 | 660 |
tda_add(i); |
511 | 661 | |
662 |
/* Initialise rawts test file */ |
|
663 |
if(rawfile) |
|
664 |
tda_add_from_file(rawfile); |
|
665 | ||
666 |
/* Load configuration */ |
|
512 | 667 |
l = hts_settings_load("dvbadapters"); |
513 | 668 |
if(l != NULL) { |
514 | 669 |
HTSMSG_FOREACH(f, l) { |
515 | 670 |
if((c = htsmsg_get_map_by_field(f)) == NULL) |
516 | 671 |
continue; |
... | ... | |
521 | 676 |
(type = dvb_str_to_adaptertype(s)) < 0) |
522 | 677 |
continue; |
523 | 678 | |
524 | 679 |
if((tda = dvb_adapter_find_by_identifier(f->hmf_name)) == NULL) { |
525 | 680 |
/* Not discovered by hardware, create it */ |
526 | ||
527 | 681 |
tda = tda_alloc(); |
528 | 682 |
tda->tda_identifier = strdup(f->hmf_name); |
529 | 683 |
tda->tda_type = type; |
530 | 684 |
TAILQ_INSERT_TAIL(&dvb_adapters, tda, tda_global_link); |
531 | 685 |
} else { |
... | ... | |
536 | 690 |
free(tda->tda_displayname); |
537 | 691 |
tda->tda_displayname = strdup(name); |
538 | 692 | |
539 | 693 |
htsmsg_get_u32(c, "autodiscovery", &tda->tda_autodiscovery); |
540 | 694 |
htsmsg_get_u32(c, "idlescan", &tda->tda_idlescan); |
695 |
htsmsg_get_u32(c, "idleclose", &tda->tda_idleclose); |
|
541 | 696 |
htsmsg_get_u32(c, "skip_checksubscr", &tda->tda_skip_checksubscr); |
697 |
htsmsg_get_u32(c, "sidtochan", &tda->tda_sidtochan); |
|
542 | 698 |
htsmsg_get_u32(c, "qmon", &tda->tda_qmon); |
543 |
htsmsg_get_u32(c, "dump_muxes", &tda->tda_dump_muxes); |
|
544 | 699 |
htsmsg_get_u32(c, "poweroff", &tda->tda_poweroff); |
545 | 700 |
htsmsg_get_u32(c, "nitoid", &tda->tda_nitoid); |
546 | 701 |
htsmsg_get_u32(c, "diseqc_version", &tda->tda_diseqc_version); |
702 |
htsmsg_get_u32(c, "diseqc_repeats", &tda->tda_diseqc_repeats); |
|
547 | 703 |
htsmsg_get_u32(c, "extrapriority", &tda->tda_extrapriority); |
548 | 704 |
htsmsg_get_u32(c, "skip_initialscan", &tda->tda_skip_initialscan); |
549 | 705 |
htsmsg_get_u32(c, "disable_pmt_monitor", &tda->tda_disable_pmt_monitor); |
706 |
if (htsmsg_get_s32(c, "full_mux_rx", &tda->tda_full_mux_rx)) |
|
707 |
if (!htsmsg_get_u32(c, "disable_full_mux_rx", &u32) && u32) |
|
708 |
tda->tda_full_mux_rx = 0; |
|
550 | 709 |
} |
551 | 710 |
htsmsg_destroy(l); |
552 | 711 |
} |
553 | 712 | |
554 |
TAILQ_FOREACH(tda, &dvb_adapters, tda_global_link) |
|
713 |
TAILQ_FOREACH(tda, &dvb_adapters, tda_global_link) { |
|
714 |
tda_init_input(tda); |
|
715 | ||
716 |
if(tda->tda_sat) |
|
717 |
dvb_satconf_init(tda); |
|
718 | ||
555 | 719 |
dvb_mux_load(tda); |
556 | 720 |
} |
721 |
} |
|
557 | 722 | |
558 | 723 | |
559 | 724 |
/** |
560 | 725 |
* If nobody is subscribing, cycle thru all muxes to get some stats |
561 | 726 |
* and EIT updates |
... | ... | |
581 | 746 | |
582 | 747 |
/* Someone is actively using */ |
583 | 748 |
if(service_compute_weight(&tda->tda_transports) > 0) |
584 | 749 |
return; |
585 | 750 | |
751 |
if(tda->tda_mux_current != NULL && |
|
752 |
LIST_FIRST(&tda->tda_mux_current->tdmi_subscriptions) != NULL) |
|
753 |
return; // Someone is doing full mux dump |
|
754 | ||
586 | 755 |
/* Check if we have muxes pending for quickscan, if so, choose them */ |
587 | 756 |
if((tdmi = TAILQ_FIRST(&tda->tda_initial_scan_queue)) != NULL) { |
588 | 757 |
dvb_fe_tune(tdmi, "Initial autoscan"); |
589 | 758 |
return; |
590 | 759 |
} |
... | ... | |
699 | 868 |
*/ |
700 | 869 |
static void * |
701 | 870 |
dvb_adapter_input_dvr(void *aux) |
702 | 871 |
{ |
703 | 872 |
th_dvb_adapter_t *tda = aux; |
704 |
int fd, i, r, efd, nfds;
|
|
873 |
int fd, i, r, c, efd, nfds, dmx = -1;
|
|
705 | 874 |
uint8_t tsb[188 * 10]; |
706 | 875 |
service_t *t; |
707 | 876 |
struct epoll_event ev; |
877 |
char path[256]; |
|
708 | 878 | |
709 |
fd = tvh_open(tda->tda_dvr_path, O_RDONLY | O_NONBLOCK, 0); |
|
879 |
snprintf(path, sizeof(path), "%s/dvr0", tda->tda_rootpath); |
|
880 | ||
881 |
fd = tvh_open(path, O_RDONLY | O_NONBLOCK, 0); |
|
710 | 882 |
if(fd == -1) { |
711 |
tvhlog(LOG_ALERT, "dvb", "%s: unable to open dvr", tda->tda_dvr_path);
|
|
883 |
tvhlog(LOG_ALERT, "dvb", "Unable to open %s -- %s", path, strerror(errno));
|
|
712 | 884 |
return NULL; |
713 | 885 |
} |
714 | 886 | |
887 |
if(tda->tda_rawmode) { |
|
888 | ||
889 |
// Receive unfiltered raw transport stream |
|
890 | ||
891 |
dmx = tvh_open(tda->tda_demux_path, O_RDWR, 0); |
|
892 |
if(dmx == -1) { |
|
893 |
tvhlog(LOG_ALERT, "dvb", "Unable to open %s -- %s", |
|
894 |
tda->tda_demux_path, strerror(errno)); |
|
895 |
close(fd); |
|
896 |
return NULL; |
|
897 |
} |
|
898 | ||
899 |
struct dmx_pes_filter_params dmx_param; |
|
900 | ||
901 |
memset(&dmx_param, 0, sizeof(dmx_param)); |
|
902 |
dmx_param.pid = 0x2000; |
|
903 |
dmx_param.input = DMX_IN_FRONTEND; |
|
904 |
dmx_param.output = DMX_OUT_TS_TAP; |
|
905 |
dmx_param.pes_type = DMX_PES_OTHER; |
|
906 |
dmx_param.flags = DMX_IMMEDIATE_START; |
|
907 |
|
|
908 |
if(ioctl(dmx, DMX_SET_PES_FILTER, &dmx_param)) { |
|
909 |
tvhlog(LOG_ERR, "dvb", |
|
910 |
"Unable to configure demuxer \"%s\" for all PIDs -- %s", |
|
911 |
tda->tda_demux_path, strerror(errno)); |
|
912 |
close(dmx); |
|
913 |
close(fd); |
|
914 |
return NULL; |
|
915 |
} |
|
916 |
} |
|
917 | ||
715 | 918 |
/* Create poll */ |
716 | 919 |
efd = epoll_create(2); |
920 |
memset(&ev, 0, sizeof(ev)); |
|
717 | 921 |
ev.events = EPOLLIN; |
718 | 922 |
ev.data.fd = fd; |
719 | 923 |
epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev); |
720 | 924 |
ev.data.fd = tda->tda_dvr_pipe[0]; |
721 | 925 |
epoll_ctl(efd, EPOLL_CTL_ADD, tda->tda_dvr_pipe[0], &ev); |
722 | 926 | |
927 |
r = i = 0; |
|
723 | 928 |
while(1){ |
724 | 929 | |
725 | 930 |
/* Wait for input */ |
726 | 931 |
nfds = epoll_wait(efd, &ev, 1, -1); |
727 | 932 |
if (nfds < 1) continue; |
728 | 933 |
if (ev.data.fd != fd) break; |
729 | 934 | |
730 |
r = read(fd, tsb, sizeof(tsb)); |
|
935 |
c = read(fd, tsb+r, sizeof(tsb)-r); |
|
936 |
if (c < 0) { |
|
937 |
if (errno == EAGAIN || errno == EINTR) |
|
938 |
continue; |
|
939 |
else if (errno == EOVERFLOW) { |
|
940 |
tvhlog(LOG_WARNING, "dvb", "\"%s\" read() EOVERFLOW", |
|
941 |
tda->tda_identifier); |
|
942 |
continue; |
|
943 |
} else { |
|
944 |
// TODO: should we try to recover? |
|
945 |
tvhlog(LOG_ERR, "dvb", "\"%s\" read() error %d", |
|
946 |
tda->tda_identifier, errno); |
|
947 |
break; |
|
948 |
} |
|
949 |
} |
|
950 |
r += c; |
|
951 | ||
952 |
/* not enough data */ |
|
953 |
if (r < 188) continue; |
|
954 | ||
955 |
int wakeup_table_feed = 0; // Just wanna wakeup once |
|
731 | 956 | |
732 | 957 |
pthread_mutex_lock(&tda->tda_delivery_mutex); |
733 | 958 |
|
734 |
for(i = 0; i < r; i += 188) { |
|
959 |
if(LIST_FIRST(&tda->tda_streaming_pad.sp_targets) != NULL) { |
|
960 |
streaming_message_t sm; |
|
961 |
pktbuf_t *pb = pktbuf_alloc(tsb, r); |
|
962 |
memset(&sm, 0, sizeof(sm)); |
|
963 |
sm.sm_type = SMT_MPEGTS; |
|
964 |
sm.sm_data = pb; |
|
965 |
streaming_pad_deliver(&tda->tda_streaming_pad, &sm); |
|
966 |
pktbuf_ref_dec(pb); |
|
967 |
} |
|
968 | ||
969 |
/* Process */ |
|
970 |
while (r >= 188) { |
|
971 |
|
|
972 |
/* sync */ |
|
973 |
if (tsb[i] == 0x47) { |
|
974 |
int pid = (tsb[i+1] & 0x1f) << 8 | tsb[i+2]; |
|
975 | ||
976 |
if(tda->tda_table_filter[pid]) { |
|
977 |
if(!(tsb[i+1] & 0x80)) { // Only dispatch to table parser if not error |
|
978 |
dvb_table_feed_t *dtf = malloc(sizeof(dvb_table_feed_t)); |
|
979 |
memcpy(dtf->dtf_tsb, tsb + i, 188); |
|
980 |
TAILQ_INSERT_TAIL(&tda->tda_table_feed, dtf, dtf_link); |
|
981 |
wakeup_table_feed = 1; |
|
982 |
} |
|
983 |
} else { |
|
735 | 984 |
LIST_FOREACH(t, &tda->tda_transports, s_active_link) |
736 | 985 |
if(t->s_dvb_mux_instance == tda->tda_mux_current) |
737 | 986 |
ts_recv_packet1(t, tsb + i, NULL); |
738 | 987 |
} |
739 | 988 | |
740 |
if(tda->tda_dump_fd != -1) { |
|
741 |
if(write(tda->tda_dump_fd, tsb, r) != r) { |
|
742 |
tvhlog(LOG_ERR, "dvb", |
|
743 |
"\"%s\" unable to write to mux dump file -- %s", |
|
744 |
tda->tda_identifier, strerror(errno)); |
|
745 |
close(tda->tda_dump_fd); |
|
746 |
tda->tda_dump_fd = -1; |
|
989 |
i += 188; |
|
990 |
r -= 188; |
|
991 | ||
992 |
/* no sync */ |
|
993 |
} else { |
|
994 |
tvhlog(LOG_DEBUG, "dvb", "\"%s\" ts sync lost", tda->tda_identifier); |
|
995 |
if (ts_resync(tsb, &r, &i)) break; |
|
996 |
tvhlog(LOG_DEBUG, "dvb", "\"%s\" ts sync found", tda->tda_identifier); |
|
747 | 997 |
} |
748 | 998 |
} |
749 | 999 | |
1000 |
if(wakeup_table_feed) |
|
1001 |
pthread_cond_signal(&tda->tda_table_feed_cond); |
|
1002 | ||
750 | 1003 |
pthread_mutex_unlock(&tda->tda_delivery_mutex); |
1004 | ||
1005 |
/* reset buffer */ |
|
1006 |
if (r) memmove(tsb, tsb+i, r); |
|
1007 |
i = 0; |
|
751 | 1008 |
} |
752 | 1009 | |
1010 |
if(dmx != -1) |
|
1011 |
close(dmx); |
|
753 | 1012 |
close(efd); |
754 | 1013 |
close(fd); |
755 | 1014 |
return NULL; |
756 | 1015 |
} |
757 | 1016 | |
... | ... | |
786 | 1045 |
htsmsg_add_u32(m, "services", numsvc); |
787 | 1046 |
htsmsg_add_u32(m, "muxes", nummux); |
788 | 1047 |
htsmsg_add_u32(m, "initialMuxes", tda->tda_initial_num_mux); |
789 | 1048 | |
790 | 1049 |
if(tda->tda_mux_current != NULL) { |
1050 |
th_dvb_mux_instance_t *tdmi = tda->tda_mux_current; |
|
1051 | ||
791 | 1052 |
dvb_mux_nicename(buf, sizeof(buf), tda->tda_mux_current); |
792 | 1053 |
htsmsg_add_str(m, "currentMux", buf); |
1054 | ||
1055 |
htsmsg_add_u32(m, "signal", MIN(tdmi->tdmi_signal * 100 / 65535, 100)); |
|
1056 |
htsmsg_add_u32(m, "snr", tdmi->tdmi_snr); |
|
1057 |
htsmsg_add_u32(m, "ber", tdmi->tdmi_ber); |
|
1058 |
htsmsg_add_u32(m, "unc", tdmi->tdmi_unc); |
|
1059 |
htsmsg_add_u32(m, "uncavg", tdmi->tdmi_unc_avg); |
|
793 | 1060 |
} |
794 | 1061 | |
795 | 1062 |
if(tda->tda_rootpath == NULL) |
796 | 1063 |
return m; |
797 | 1064 | |
... | ... | |
959 | 1226 |
* Turn off the adapter |
960 | 1227 |
*/ |
961 | 1228 |
void |
962 | 1229 |
dvb_adapter_poweroff(th_dvb_adapter_t *tda) |
963 | 1230 |
{ |
1231 |
if (tda->tda_fe_fd == -1) return; |
|
964 | 1232 |
lock_assert(&global_lock); |
965 | 1233 |
if (!tda->tda_poweroff || tda->tda_type != FE_QPSK) |
966 | 1234 |
return; |
967 | 1235 |
diseqc_voltage_off(tda->tda_fe_fd); |
968 | 1236 |
tvhlog(LOG_DEBUG, "dvb", "\"%s\" is off", tda->tda_rootpath); |
src/dvb/dvb_charset.c | ||
---|---|---|
1 |
/* |
|
2 |
* tvheadend, charset list |
|
3 |
* Copyright (C) 2012 Mariusz Białończyk |
|
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 |
#include <string.h> |
|
20 |
#include "tvheadend.h" |
|
21 |
#include "settings.h" |
|
22 |
#include "dvb/dvb_charset.h" |
|
23 | ||
24 |
/* |
|
25 |
* Process a file |
|
26 |
*/ |
|
27 |
static void _charset_load_file() |
|
28 |
{ |
|
29 |
htsmsg_t *l, *e; |
|
30 |
htsmsg_field_t *f; |
|
31 | ||
32 |
dvb_charset_t *enc; |
|
33 |
const char *charset; |
|
34 |
uint32_t tsid, onid, sid; |
|
35 |
int i = 0; |
|
36 | ||
37 |
l = hts_settings_load("charset"); |
|
38 |
if (l) |
|
39 |
{ |
|
40 |
HTSMSG_FOREACH(f, l) { |
|
41 |
if ((e = htsmsg_get_map_by_field(f))) { |
|
42 |
tsid = onid = sid = 0; |
|
43 |
htsmsg_get_u32(e, "onid", &onid); |
|
44 |
htsmsg_get_u32(e, "tsid", &tsid); |
|
45 |
htsmsg_get_u32(e, "sid", &sid); |
|
46 |
charset = htsmsg_get_str(e, "charset"); |
|
47 | ||
48 |
if (tsid == 0 || onid == 0 || !charset) |
|
49 |
continue; |
|
50 | ||
51 |
enc = calloc(1, sizeof(dvb_charset_t)); |
|
52 |
if (enc) |
|
53 |
{ |
|
54 |
enc->onid = onid; |
|
55 |
enc->tsid = tsid; |
|
56 |
enc->sid = sid; |
|
57 |
enc->charset = strdup(charset); |
|
58 |
LIST_INSERT_HEAD(&dvb_charset_list, enc, link); |
|
59 |
i++; |
|
60 |
} |
|
61 |
} |
|
62 |
}; |
|
63 |
htsmsg_destroy(l); |
|
64 |
}; |
|
65 | ||
66 |
if (i > 0) |
|
67 |
tvhlog(LOG_INFO, "charset", "%d entries loaded", i); |
|
68 |
} |
|
69 | ||
70 |
/* |
|
71 |
* Initialise the charset list |
|
72 |
*/ |
|
73 |
void dvb_charset_init ( void ) |
|
74 |
{ |
|
75 |
_charset_load_file(); |
|
76 |
} |
|
77 | ||
78 |
/* |
|
79 |
* Find default charset |
|
80 |
*/ |
|
81 |
const char *dvb_charset_find |
|
82 |
( uint16_t onid, uint16_t tsid, uint16_t sid ) |
|
83 |
{ |
|
84 |
dvb_charset_t *ret = NULL, *enc; |
|
85 |
LIST_FOREACH(enc, &dvb_charset_list, link) { |
|
86 |
if (onid == enc->onid && tsid == enc->tsid) { |
|
87 |
if (sid == enc->sid) { |
|
88 |
ret = enc; |
|
89 |
break; |
|
90 |
} else if (!enc->sid) { |
|
91 |
ret = enc; |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
return ret ? ret->charset : NULL; |
|
96 |
} |
src/dvb/dvb_charset.h | ||
---|---|---|
1 |
/* |
|
2 |
* tvheadend, dvb charset config |
|
3 |
* Copyright (C) 2012 Mariusz Białończyk |
|
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 |
#ifndef __TVH_DVB_CHARSET_H__ |
|
20 |
#define __TVH_DVB_CHARSET_H__ |
|
21 | ||
22 |
typedef struct dvb_charset { |
|
23 |
LIST_ENTRY(dvb_charset) link; |
|
24 |
uint16_t onid; |
|
25 |
uint16_t tsid; |
|
26 |
uint16_t sid; |
|
27 |
const char *charset; |
|
28 |
} dvb_charset_t; |
|
29 | ||
30 |
LIST_HEAD(,dvb_charset) dvb_charset_list; |
|
31 | ||
32 |
void dvb_charset_init ( void ); |
|
33 | ||
34 |
const char *dvb_charset_find |
|
35 |
(uint16_t onid, uint16_t tsid, uint16_t sid); |
|
36 | ||
37 |
#endif /* __TVH_DVB_CHARSET_H__ */ |
src/dvb/dvb_charset_tables.h | ||
---|---|---|
225 | 225 | |
226 | 226 |
// Code tables for ISO6937 two-byte sequences combining an accent byte. |
227 | 227 |
// in the range 0xc1 to 0xcf with a letter in one of the ranges |
228 | 228 |
// 0x41 to 0x5a (A-Z) or 0x61 to 0x7a (a-z) |
229 | 229 |
static const uint16_t iso6937_multi_byte[16][52] = { |
230 |
/* 0xC0 */ { |
|
231 |
0x00, |
- « Previous
- 1
- 2
- Next »