]> git.sesse.net Git - vlc/blob - modules/access/dvb/dvb.h
Added DVB scan capability.
[vlc] / modules / access / dvb / dvb.h
1 /*****************************************************************************
2  * dvb.h : functions to control a DVB card under Linux with v4l2
3  *****************************************************************************
4  * Copyright (C) 1998-2005 the VideoLAN team
5  *
6  * Authors: Johan Bilien <jobi@via.ecp.fr>
7  *          Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
8  *          Christopher Ross <chris@tebibyte.org>
9  *          Christophe Massiot <massiot@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    02111, USA.
24  *****************************************************************************/
25
26
27 #include "scan.h"
28
29 /*****************************************************************************
30  * Devices location
31  *****************************************************************************/
32 #define DMX      "/dev/dvb/adapter%d/demux%d"
33 #define FRONTEND "/dev/dvb/adapter%d/frontend%d"
34 #define DVR      "/dev/dvb/adapter%d/dvr%d"
35 #define CA       "/dev/dvb/adapter%d/ca%d"
36
37 /*****************************************************************************
38  * Local structures
39  *****************************************************************************/
40 typedef struct demux_handle_t
41 {
42     int i_pid;
43     int i_handle;
44     int i_type;
45 } demux_handle_t;
46
47 typedef struct frontend_t frontend_t;
48 typedef struct
49 {
50     int i_snr;              /**< Signal Noise ratio */
51     int i_ber;              /**< Bitrate error ratio */
52     int i_signal_strenth;   /**< Signal strength */
53 } frontend_statistic_t;
54
55 typedef struct
56 {
57     bool b_has_signal;
58     bool b_has_carrier;
59     bool b_has_lock;
60 } frontend_status_t;
61
62 typedef struct en50221_session_t
63 {
64     int i_slot;
65     int i_resource_id;
66     void (* pf_handle)( access_t *, int, uint8_t *, int );
67     void (* pf_close)( access_t *, int );
68     void (* pf_manage)( access_t *, int );
69     void *p_sys;
70 } en50221_session_t;
71
72 #define EN50221_MMI_NONE 0
73 #define EN50221_MMI_ENQ 1
74 #define EN50221_MMI_ANSW 2
75 #define EN50221_MMI_MENU 3
76 #define EN50221_MMI_MENU_ANSW 4
77 #define EN50221_MMI_LIST 5
78
79 typedef struct en50221_mmi_object_t
80 {
81     int i_object_type;
82
83     union
84     {
85         struct
86         {
87             bool b_blind;
88             char *psz_text;
89         } enq;
90
91         struct
92         {
93             bool b_ok;
94             char *psz_answ;
95         } answ;
96
97         struct
98         {
99             char *psz_title, *psz_subtitle, *psz_bottom;
100             char **ppsz_choices;
101             int i_choices;
102         } menu; /* menu and list are the same */
103
104         struct
105         {
106             int i_choice;
107         } menu_answ;
108     } u;
109 } en50221_mmi_object_t;
110
111 static __inline__ void en50221_MMIFree( en50221_mmi_object_t *p_object )
112 {
113     int i;
114
115     switch ( p_object->i_object_type )
116     {
117     case EN50221_MMI_ENQ:
118         FREENULL( p_object->u.enq.psz_text );
119         break;
120
121     case EN50221_MMI_ANSW:
122         if ( p_object->u.answ.b_ok )
123         {
124             FREENULL( p_object->u.answ.psz_answ );
125         }
126         break;
127
128     case EN50221_MMI_MENU:
129     case EN50221_MMI_LIST:
130         FREENULL( p_object->u.menu.psz_title );
131         FREENULL( p_object->u.menu.psz_subtitle );
132         FREENULL( p_object->u.menu.psz_bottom );
133         for ( i = 0; i < p_object->u.menu.i_choices; i++ )
134         {
135             FREENULL( p_object->u.menu.ppsz_choices[i] );
136         }
137         FREENULL( p_object->u.menu.ppsz_choices );
138         break;
139
140     default:
141         break;
142     }
143 }
144
145 #define MAX_DEMUX 256
146 #define MAX_CI_SLOTS 16
147 #define MAX_SESSIONS 32
148 #define MAX_PROGRAMS 24
149
150 struct access_sys_t
151 {
152     int i_handle, i_frontend_handle;
153     demux_handle_t p_demux_handles[MAX_DEMUX];
154     frontend_t *p_frontend;
155     bool b_budget_mode;
156     bool b_scan_mode;
157
158     /* CA management */
159     int i_ca_handle;
160     int i_ca_type;
161     int i_nb_slots;
162     bool pb_active_slot[MAX_CI_SLOTS];
163     bool pb_tc_has_data[MAX_CI_SLOTS];
164     bool pb_slot_mmi_expected[MAX_CI_SLOTS];
165     bool pb_slot_mmi_undisplayed[MAX_CI_SLOTS];
166     en50221_session_t p_sessions[MAX_SESSIONS];
167     mtime_t i_ca_timeout, i_ca_next_event, i_frontend_timeout;
168     dvbpsi_pmt_t *pp_selected_programs[MAX_PROGRAMS];
169     int i_selected_programs;
170
171     /* */
172     int i_read_once;
173
174 #ifdef ENABLE_HTTPD
175     /* Local HTTP server */
176     httpd_host_t        *p_httpd_host;
177     httpd_file_sys_t    *p_httpd_file;
178     httpd_redirect_t    *p_httpd_redir;
179
180     vlc_mutex_t         httpd_mutex;
181     vlc_cond_t          httpd_cond;
182     mtime_t             i_httpd_timeout;
183     bool          b_request_frontend_info, b_request_mmi_info;
184     char                *psz_frontend_info, *psz_mmi_info;
185     char                *psz_request;
186 #endif
187
188     /* Scan */
189     scan_t scan;
190 };
191
192 #define VIDEO0_TYPE     1
193 #define AUDIO0_TYPE     2
194 #define TELETEXT0_TYPE  3
195 #define SUBTITLE0_TYPE  4
196 #define PCR0_TYPE       5
197 #define TYPE_INTERVAL   5
198 #define OTHER_TYPE     21
199
200 /*****************************************************************************
201  * Prototypes
202  *****************************************************************************/
203
204 int  FrontendOpen( access_t * );
205 void FrontendPoll( access_t *p_access );
206 int  FrontendSet( access_t * );
207 void FrontendClose( access_t * );
208 #ifdef ENABLE_HTTPD
209 void FrontendStatus( access_t * );
210 #endif
211
212 int  FrontendGetStatistic( access_t *, frontend_statistic_t * );
213 void FrontendGetStatus( access_t *, frontend_status_t * );
214 int  FrontendGetScanParameter( access_t *, scan_parameter_t * );
215
216 int DMXSetFilter( access_t *, int i_pid, int * pi_fd, int i_type );
217 int DMXUnsetFilter( access_t *, int i_fd );
218
219 int  DVROpen( access_t * );
220 void DVRClose( access_t * );
221
222 int  CAMOpen( access_t * );
223 int  CAMPoll( access_t * );
224 int  CAMSet( access_t *, dvbpsi_pmt_t * );
225 void CAMClose( access_t * );
226 #ifdef ENABLE_HTTPD
227 void CAMStatus( access_t * );
228 #endif
229
230 int en50221_Init( access_t * );
231 int en50221_Poll( access_t * );
232 int en50221_SetCAPMT( access_t *, dvbpsi_pmt_t * );
233 int en50221_OpenMMI( access_t * p_access, int i_slot );
234 int en50221_CloseMMI( access_t * p_access, int i_slot );
235 en50221_mmi_object_t *en50221_GetMMIObject( access_t * p_access,
236                                                 int i_slot );
237 void en50221_SendMMIObject( access_t * p_access, int i_slot,
238                                 en50221_mmi_object_t *p_object );
239 void en50221_End( access_t * );
240
241 char *dvbsi_to_utf8( char *psz_instring, size_t i_length );
242
243 #ifdef ENABLE_HTTPD
244 int HTTPOpen( access_t *p_access );
245 void HTTPClose( access_t *p_access );
246 char *HTTPExtractValue( char *psz_uri, const char *psz_name,
247                             char *psz_value, int i_value_max );
248 #endif
249 /*****************************************************************************
250  * Hacks
251  *****************************************************************************/
252 #define STRINGIFY( z )   UGLY_KLUDGE( z )
253 #define UGLY_KLUDGE( z ) #z
254