root/trunk/tvheadend/src/dvb/dvb.h @ 3084

Revision 3084, 5.2 KB (checked in by andoma, 15 months ago)

If we are unable to create a demultiplex filter in hardware for a table,
put the table on a pending queue and cycle through all tables.

Fixes problems with low-end adapters that does not support that many
filter in hardware.

Line 
1/*
2 *  TV Input - Linux DVB interface
3 *  Copyright (C) 2007 Andreas �an
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 DVB_H_
20#define DVB_H_
21
22#include <linux/dvb/frontend.h>
23
24TAILQ_HEAD(th_dvb_adapter_queue, th_dvb_adapter);
25RB_HEAD(th_dvb_mux_instance_tree, th_dvb_mux_instance);
26TAILQ_HEAD(th_dvb_mux_instance_queue, th_dvb_mux_instance);
27
28
29enum polarisation {
30        POLARISATION_HORIZONTAL     = 0x00,
31        POLARISATION_VERTICAL       = 0x01,
32        POLARISATION_CIRCULAR_LEFT  = 0x02,
33        POLARISATION_CIRCULAR_RIGHT = 0x03
34};
35
36#define DVB_FEC_ERROR_LIMIT 20
37
38
39/**
40 * DVB Mux instance
41 */
42typedef struct th_dvb_mux_instance {
43
44  RB_ENTRY(th_dvb_mux_instance) tdmi_global_link;
45  RB_ENTRY(th_dvb_mux_instance) tdmi_adapter_link;
46
47
48  struct th_dvb_adapter *tdmi_adapter;
49
50  uint16_t tdmi_snr, tdmi_signal;
51  uint32_t tdmi_ber, tdmi_uncorrected_blocks;
52
53#define TDMI_FEC_ERR_HISTOGRAM_SIZE 10
54  uint32_t tdmi_fec_err_histogram[TDMI_FEC_ERR_HISTOGRAM_SIZE];
55  int      tdmi_fec_err_ptr;
56
57  time_t tdmi_time;
58  LIST_HEAD(, th_dvb_table) tdmi_tables;
59  TAILQ_HEAD(, th_dvb_table) tdmi_table_queue;
60
61  enum {
62    TDMI_FE_UNKNOWN,
63    TDMI_FE_NO_SIGNAL,
64    TDMI_FE_FAINT_SIGNAL,
65    TDMI_FE_BAD_SIGNAL,
66    TDMI_FE_CONSTANT_FEC,
67    TDMI_FE_BURSTY_FEC,
68    TDMI_FE_OK,
69  } tdmi_fe_status;
70
71  int tdmi_quality;
72
73  time_t tdmi_got_adapter;
74  time_t tdmi_lost_adapter;
75
76  struct dvb_frontend_parameters tdmi_fe_params;
77  uint8_t tdmi_polarisation;  /* for DVB-S */
78  uint8_t tdmi_switchport;    /* for DVB-S */
79
80  uint16_t tdmi_transport_stream_id;
81
82  char *tdmi_identifier;
83  char *tdmi_network;     /* Name of network, from NIT table */
84
85  struct th_transport_list tdmi_transports; /* via tht_mux_link */
86
87
88  TAILQ_ENTRY(th_dvb_mux_instance) tdmi_scan_link;
89  struct th_dvb_mux_instance_queue *tdmi_scan_queue;
90
91} th_dvb_mux_instance_t;
92
93
94#define DVB_MUX_SCAN_BAD 0      /* On the bad queue */
95#define DVB_MUX_SCAN_OK  1      /* Ok, don't need to scan that often */
96#define DVB_MUX_SCAN_INITIAL 2  /* To get a scan directly when a mux
97                                   is discovered */
98
99/**
100 * DVB Adapter (one of these per physical adapter)
101 */
102typedef struct th_dvb_adapter {
103
104  TAILQ_ENTRY(th_dvb_adapter) tda_global_link;
105
106  struct th_dvb_mux_instance_tree tda_muxes;
107
108  /**
109   * We keep our muxes on three queues in order to select how
110   * they are to be idle-scanned
111   */
112  struct th_dvb_mux_instance_queue tda_scan_queues[3];
113  int tda_scan_selector;  /* To alternate between bad and ok queue */
114
115  th_dvb_mux_instance_t *tda_mux_current;
116
117  int tda_table_epollfd;
118
119  const char *tda_rootpath;
120  char *tda_identifier;
121  uint32_t tda_autodiscovery;
122  char *tda_displayname;
123
124  int tda_fe_fd;
125  int tda_type;
126  struct dvb_frontend_info *tda_fe_info;
127
128  char *tda_demux_path;
129
130  char *tda_dvr_path;
131
132  gtimer_t tda_mux_scanner_timer;
133
134  pthread_mutex_t tda_delivery_mutex;
135  struct th_transport_list tda_transports; /* Currently bound transports */
136
137  gtimer_t tda_fe_monitor_timer;
138  int tda_fe_monitor_hold;
139
140} th_dvb_adapter_t;
141
142
143
144extern struct th_dvb_adapter_queue dvb_adapters;
145extern struct th_dvb_mux_instance_tree dvb_muxes;
146
147void dvb_init(void);
148
149/**
150 * DVB Adapter
151 */
152void dvb_adapter_init(void);
153
154void dvb_adapter_mux_scanner(void *aux);
155
156void dvb_adapter_notify_reload(th_dvb_adapter_t *tda);
157
158void dvb_adapter_set_displayname(th_dvb_adapter_t *tda, const char *s);
159
160void dvb_adapter_set_auto_discovery(th_dvb_adapter_t *tda, int on);
161
162void dvb_adapter_clone(th_dvb_adapter_t *dst, th_dvb_adapter_t *src);
163
164void dvb_adapter_clean(th_dvb_adapter_t *tda);
165
166int dvb_adapter_destroy(th_dvb_adapter_t *tda);
167
168/**
169 * DVB Multiplex
170 */
171void dvb_mux_save(th_dvb_mux_instance_t *tdmi);
172
173void dvb_mux_load(th_dvb_adapter_t *tda);
174
175void dvb_mux_destroy(th_dvb_mux_instance_t *tdmi);
176
177th_dvb_mux_instance_t *dvb_mux_create(th_dvb_adapter_t *tda,
178                                      struct dvb_frontend_parameters *fe_param,
179                                      int polarisation, int switchport,
180                                      uint16_t tsid, const char *network,
181                                      const char *logprefix);
182
183void dvb_mux_set_networkname(th_dvb_mux_instance_t *tdmi, const char *name);
184
185/**
186 * DVB Transport (aka DVB service)
187 */
188void dvb_transport_load(th_dvb_mux_instance_t *tdmi);
189
190th_transport_t *dvb_transport_find(th_dvb_mux_instance_t *tdmi,
191                                   uint16_t sid, int pmt_pid, int *created);
192
193
194/**
195 * DVB Frontend
196 */
197void dvb_fe_tune(th_dvb_mux_instance_t *tdmi, const char *reason);
198
199void dvb_fe_stop(th_dvb_mux_instance_t *tdmi);
200
201
202/**
203 * DVB Tables
204 */
205void dvb_table_init(th_dvb_adapter_t *tda);
206
207void dvb_table_add_default(th_dvb_mux_instance_t *tdmi);
208
209void dvb_table_add_transport(th_dvb_mux_instance_t *tdmi, th_transport_t *t,
210                             int pmt_pid);
211
212void dvb_table_flush_all(th_dvb_mux_instance_t *tdmi);
213
214#endif /* DVB_H_ */
Note: See TracBrowser for help on using the browser.