Mercurial > mplayer.hg
annotate libmpdemux/dvbin.c @ 12625:d81145997036
More information about modifications to comply more closely with GPL 2a.
author | diego |
---|---|
date | Wed, 23 Jun 2004 13:50:53 +0000 |
parents | 44152bfdc002 |
children | 168238f8c715 |
rev | line source |
---|---|
9610 | 1 /* |
2 | |
3 dvbstream | |
4 (C) Dave Chapman <dave@dchapman.com> 2001, 2002. | |
5 | |
6 The latest version can be found at http://www.linuxstb.org/dvbstream | |
7 | |
8 Copyright notice: | |
9 | |
10 This program is free software; you can redistribute it and/or modify | |
11 it under the terms of the GNU General Public License as published by | |
12 the Free Software Foundation; either version 2 of the License, or | |
13 (at your option) any later version. | |
14 | |
15 This program is distributed in the hope that it will be useful, | |
16 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 GNU General Public License for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with this program; if not, write to the Free Software | |
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 */ | |
25 | |
10560 | 26 #include "config.h" |
9610 | 27 #include <stdio.h> |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include <ctype.h> | |
31 #include <sys/ioctl.h> | |
32 #include <sys/time.h> | |
33 #include <sys/poll.h> | |
10560 | 34 #include <unistd.h> |
9610 | 35 #include <fcntl.h> |
36 #include <string.h> | |
37 #include <errno.h> | |
38 #include <fcntl.h> | |
39 | |
40 #include "stream.h" | |
41 #include "demuxer.h" | |
10560 | 42 #include "help_mp.h" |
43 #include "../m_option.h" | |
44 #include "../m_struct.h" | |
9610 | 45 |
46 #include "dvbin.h" | |
47 | |
48 | |
49 #define MAX_CHANNELS 8 | |
10560 | 50 #define CHANNEL_LINE_LEN 256 |
9610 | 51 #define min(a, b) ((a) <= (b) ? (a) : (b)) |
52 | |
10560 | 53 |
54 //TODO: CAMBIARE list_ptr e da globale a per_priv | |
55 | |
56 | |
57 static struct stream_priv_s | |
58 { | |
59 char *prog; | |
60 int card; | |
61 char *type; | |
62 int vid, aid; | |
63 char *file; | |
64 } | |
65 stream_defaults = | |
66 { | |
12108
06c4780332bc
disallow non-sense type parameter; added support for absolute file path; prefer channels.conf.{sat,ter,cbl} over channels.conf if the file is available
nicodvb
parents:
12047
diff
changeset
|
67 "", 1, "", 0, 0, NULL |
10560 | 68 }; |
69 | |
70 #define ST_OFF(f) M_ST_OFF(struct stream_priv_s, f) | |
9610 | 71 |
10560 | 72 /// URL definition |
73 static m_option_t stream_params[] = { | |
74 {"prog", ST_OFF(prog), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
75 {"card", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL}, | |
76 {"type", ST_OFF(type), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
77 {"vid", ST_OFF(vid), CONF_TYPE_INT, 0, 0 ,0, NULL}, | |
78 {"aid", ST_OFF(aid), CONF_TYPE_INT, 0, 0 ,0, NULL}, | |
79 {"file", ST_OFF(file), CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
80 | |
81 {"hostname", ST_OFF(prog), CONF_TYPE_STRING, 0, 0, 0, NULL }, | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
82 {"username", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL}, |
10560 | 83 {NULL, NULL, 0, 0, 0, 0, NULL} |
84 }; | |
85 | |
86 static struct m_struct_st stream_opts = { | |
87 "dvbin", | |
88 sizeof(struct stream_priv_s), | |
89 &stream_defaults, | |
90 stream_params | |
9610 | 91 }; |
92 | |
93 | |
10560 | 94 |
95 m_option_t dvbin_opts_conf[] = { | |
96 {"prog", &stream_defaults.prog, CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
97 {"card", &stream_defaults.card, CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL}, | |
12108
06c4780332bc
disallow non-sense type parameter; added support for absolute file path; prefer channels.conf.{sat,ter,cbl} over channels.conf if the file is available
nicodvb
parents:
12047
diff
changeset
|
98 {"type", "DVB card type is autodetected and can't be overridden\n", CONF_TYPE_PRINT, CONF_NOCFG, 0 ,0, NULL}, |
10560 | 99 {"vid", &stream_defaults.vid, CONF_TYPE_INT, 0, 0 ,0, NULL}, |
100 {"aid", &stream_defaults.aid, CONF_TYPE_INT, 0, 0 ,0, NULL}, | |
101 {"file", &stream_defaults.file, CONF_TYPE_STRING, 0, 0 ,0, NULL}, | |
9610 | 102 |
10560 | 103 {NULL, NULL, 0, 0, 0, 0, NULL} |
104 }; | |
105 | |
106 | |
107 | |
108 | |
109 extern int dvb_set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype); | |
110 extern int dvb_demux_stop(int fd); | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
111 extern int dvb_get_tuner_type(int fd); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
112 int dvb_open_devices(dvb_priv_t *priv, int n); |
10560 | 113 |
9610 | 114 extern int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone, |
115 fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval, | |
116 fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate); | |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
117 extern char *dvb_dvrdev[4], *dvb_demuxdev[4], *dvb_frontenddev[4]; |
10560 | 118 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
119 static dvb_config_t *dvb_config = NULL; |
9610 | 120 |
121 | |
10560 | 122 static dvb_channels_list *dvb_get_channels(char *filename, int type) |
9610 | 123 { |
124 dvb_channels_list *list; | |
125 FILE *f; | |
10560 | 126 uint8_t line[CHANNEL_LINE_LEN]; |
127 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
128 int fields; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
129 dvb_channel_t *ptr, *tmp, chn; |
9610 | 130 char *tmp_lcr, *tmp_hier, *inv, *bw, *cr, *mod, *transm, *gi; |
11352 | 131 const char *cbl_conf = "%a[^:]:%d:%a[^:]:%d:%a[^:]:%a[^:]:%d:%d\n"; |
9610 | 132 const char *sat_conf = "%a[^:]:%d:%c:%d:%d:%d:%d:%d:%d:%d\n"; |
133 const char *ter_conf = "%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%d:%d\n"; | |
134 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
135 mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
136 if((f=fopen(filename, "r"))==NULL) |
10560 | 137 { |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
138 mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
139 return NULL; |
10560 | 140 } |
141 | |
9610 | 142 list = malloc(sizeof(dvb_channels_list)); |
143 if(list == NULL) | |
144 { | |
145 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: couldn't malloc enough memory\n"); | |
146 return NULL; | |
147 } | |
148 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
149 ptr = &chn; |
9610 | 150 list->NUM_CHANNELS = 0; |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
151 list->channels = NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
152 while(! feof(f)) |
9610 | 153 { |
10708 | 154 if( fgets(line, CHANNEL_LINE_LEN, f) == NULL ) |
155 continue; | |
9610 | 156 |
10708 | 157 if((line[0] == '#') || (strlen(line) == 0)) |
10560 | 158 continue; |
9610 | 159 |
160 | |
10560 | 161 if(type == TUNER_TER) |
9610 | 162 { |
163 fields = sscanf(line, ter_conf, | |
10560 | 164 &ptr->name, &ptr->freq, &inv, &bw, &cr, &tmp_lcr, &mod, |
9610 | 165 &transm, &gi, &tmp_hier, &ptr->vpid, &ptr->apid1); |
10708 | 166 mp_msg(MSGT_DEMUX, MSGL_V, |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
167 "TER, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, VPID: %d, APID1: %d\n", |
10708 | 168 list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->vpid, ptr->apid1); |
10560 | 169 } |
170 else if(type == TUNER_CBL) | |
171 { | |
172 fields = sscanf(line, cbl_conf, | |
173 &ptr->name, &ptr->freq, &inv, &ptr->srate, | |
174 &cr, &mod, &ptr->vpid, &ptr->apid1); | |
10708 | 175 mp_msg(MSGT_DEMUX, MSGL_V, |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
176 "CBL, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, VPID: %d, APID1: %d\n", |
10708 | 177 list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->srate, ptr->vpid, ptr->apid1); |
10560 | 178 } |
179 else //SATELLITE | |
180 { | |
181 fields = sscanf(line, sat_conf, | |
182 &ptr->name, &ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, &ptr->vpid, &ptr->apid1, | |
183 &ptr->tpid, &ptr->ca, &ptr->progid); | |
184 ptr->pol = toupper(ptr->pol); | |
185 ptr->freq *= 1000UL; | |
186 ptr->srate *= 1000UL; | |
187 ptr->tone = -1; | |
12047
6fbcdac049c6
added missing tuning parameters (inversion and coderate) and changed debug level in dvb_streaming_read()
nicodvb
parents:
11872
diff
changeset
|
188 ptr->inv = INVERSION_AUTO; |
6fbcdac049c6
added missing tuning parameters (inversion and coderate) and changed debug level in dvb_streaming_read()
nicodvb
parents:
11872
diff
changeset
|
189 ptr->cr = FEC_AUTO; |
12116 | 190 if((ptr->diseqc > 4) || (ptr->diseqc < 0)) |
12047
6fbcdac049c6
added missing tuning parameters (inversion and coderate) and changed debug level in dvb_streaming_read()
nicodvb
parents:
11872
diff
changeset
|
191 continue; |
12116 | 192 if(ptr->diseqc > 0) |
193 ptr->diseqc--; | |
10560 | 194 mp_msg(MSGT_DEMUX, MSGL_V, |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
195 "SAT, NUM: %d, NUM_FIELDS: %d, NAME: %s, FREQ: %d, SRATE: %d, POL: %c, DISEQC: %d, TONE: %d, VPID: %d, APID1: %d, APID2: %d, TPID: %d, PROGID: %d\n", |
10708 | 196 list->NUM_CHANNELS, fields, ptr->name, ptr->freq, ptr->srate, ptr->pol, ptr->diseqc, ptr->tone, ptr->vpid, ptr->apid1, ptr->apid2, ptr->tpid, ptr->progid); |
10560 | 197 } |
9610 | 198 |
10560 | 199 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
200 if((fields < 3) || ((ptr->vpid <= 0) && (ptr->apid1 <=0)) || (ptr->freq == 0) || (strlen(ptr->name) == 0)) |
10708 | 201 continue; |
202 | |
203 | |
10560 | 204 if((type == TUNER_TER) || (type == TUNER_CBL)) |
205 { | |
9610 | 206 if(! strcmp(inv, "INVERSION_ON")) |
207 ptr->inv = INVERSION_ON; | |
208 else if(! strcmp(inv, "INVERSION_OFF")) | |
209 ptr->inv = INVERSION_OFF; | |
210 else | |
211 ptr->inv = INVERSION_AUTO; | |
212 | |
213 | |
214 if(! strcmp(cr, "FEC_1_2")) | |
215 ptr->cr =FEC_1_2; | |
216 else if(! strcmp(cr, "FEC_2_3")) | |
217 ptr->cr =FEC_2_3; | |
218 else if(! strcmp(cr, "FEC_3_4")) | |
219 ptr->cr =FEC_3_4; | |
220 #ifdef HAVE_DVB_HEAD | |
221 else if(! strcmp(cr, "FEC_4_5")) | |
222 ptr->cr =FEC_4_5; | |
223 else if(! strcmp(cr, "FEC_6_7")) | |
224 ptr->cr =FEC_6_7; | |
225 else if(! strcmp(cr, "FEC_8_9")) | |
226 ptr->cr =FEC_8_9; | |
227 #endif | |
228 else if(! strcmp(cr, "FEC_5_6")) | |
229 ptr->cr =FEC_5_6; | |
230 else if(! strcmp(cr, "FEC_7_8")) | |
231 ptr->cr =FEC_7_8; | |
232 else if(! strcmp(cr, "FEC_NONE")) | |
233 ptr->cr =FEC_NONE; | |
234 else ptr->cr =FEC_AUTO; | |
235 | |
236 if(! strcmp(mod, "QAM_128")) | |
237 ptr->mod = QAM_128; | |
238 else if(! strcmp(mod, "QAM_256")) | |
239 ptr->mod = QAM_256; | |
240 else if(! strcmp(mod, "QAM_64")) | |
241 ptr->mod = QAM_64; | |
242 else if(! strcmp(mod, "QAM_32")) | |
243 ptr->mod = QAM_32; | |
244 else if(! strcmp(mod, "QAM_16")) | |
245 ptr->mod = QAM_16; | |
10560 | 246 //else ptr->mod = QPSK; |
247 } | |
248 | |
249 | |
250 if(type == TUNER_TER) | |
251 { | |
252 if(! strcmp(bw, "BANDWIDTH_6_MHZ")) | |
253 ptr->bw = BANDWIDTH_6_MHZ; | |
254 else if(! strcmp(bw, "BANDWIDTH_7_MHZ")) | |
255 ptr->bw = BANDWIDTH_7_MHZ; | |
256 else if(! strcmp(bw, "BANDWIDTH_8_MHZ")) | |
257 ptr->bw = BANDWIDTH_8_MHZ; | |
9610 | 258 |
259 | |
260 if(! strcmp(transm, "TRANSMISSION_MODE_2K")) | |
261 ptr->trans = TRANSMISSION_MODE_2K; | |
262 else if(! strcmp(transm, "TRANSMISSION_MODE_8K")) | |
263 ptr->trans = TRANSMISSION_MODE_8K; | |
264 | |
10560 | 265 |
9610 | 266 if(! strcmp(gi, "GUARD_INTERVAL_1_32")) |
267 ptr->gi = GUARD_INTERVAL_1_32; | |
268 else if(! strcmp(gi, "GUARD_INTERVAL_1_16")) | |
269 ptr->gi = GUARD_INTERVAL_1_16; | |
270 else if(! strcmp(gi, "GUARD_INTERVAL_1_8")) | |
271 ptr->gi = GUARD_INTERVAL_1_8; | |
272 else ptr->gi = GUARD_INTERVAL_1_4; | |
273 } | |
274 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
275 tmp = (dvb_channel_t*)realloc(list->channels, sizeof(dvb_channel_t) * (list->NUM_CHANNELS + 1)); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
276 if(tmp == NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
277 break; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
278 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
279 list->channels = tmp; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
280 memcpy(&(list->channels[list->NUM_CHANNELS]), ptr, sizeof(dvb_channel_t)); |
9610 | 281 list->NUM_CHANNELS++; |
282 } | |
283 | |
284 fclose(f); | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
285 if(list->NUM_CHANNELS == 0) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
286 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
287 if(list->channels != NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
288 free(list->channels); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
289 free(list); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
290 return NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
291 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
292 |
10560 | 293 list->current = 0; |
9610 | 294 return list; |
295 } | |
296 | |
297 | |
298 | |
10560 | 299 static int dvb_streaming_read(stream_t *stream, char *buffer, int size) |
9610 | 300 { |
301 struct pollfd pfds[1]; | |
10560 | 302 int pos=0, tries, rk; |
303 int fd = stream->fd; | |
304 dvb_priv_t *priv = (dvb_priv_t *) stream->priv; | |
9610 | 305 |
12047
6fbcdac049c6
added missing tuning parameters (inversion and coderate) and changed debug level in dvb_streaming_read()
nicodvb
parents:
11872
diff
changeset
|
306 mp_msg(MSGT_DEMUX, MSGL_DBG3, "dvb_streaming_read(%d)\n", size); |
9610 | 307 |
11352 | 308 tries = priv->retry + 1; |
309 | |
9610 | 310 while(pos < size) |
311 { | |
10560 | 312 pfds[0].fd = fd; |
313 pfds[0].events = POLLIN | POLLPRI; | |
9610 | 314 |
10560 | 315 poll(pfds, 1, 500); |
316 rk = size - pos; | |
317 if((rk = read(fd, &buffer[pos], rk)) > 0) | |
318 { | |
319 pos += rk; | |
12047
6fbcdac049c6
added missing tuning parameters (inversion and coderate) and changed debug level in dvb_streaming_read()
nicodvb
parents:
11872
diff
changeset
|
320 mp_msg(MSGT_DEMUX, MSGL_DBG3, "ret (%d) bytes\n", pos); |
10560 | 321 } |
322 else | |
323 { | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
324 errno = 0; |
10560 | 325 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, attempt N. %d failed with errno %d when reading %d bytes\n", tries, errno, size-pos); |
326 if(--tries > 0) | |
327 continue; | |
328 else | |
329 break; | |
330 } | |
331 } | |
9610 | 332 |
10560 | 333 if(! pos) |
334 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, return %d bytes\n", pos); | |
9610 | 335 |
336 return pos; | |
337 } | |
338 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
339 static void dvbin_close(stream_t *stream); |
10560 | 340 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
341 int dvb_set_channel(dvb_priv_t *priv, int card, int n) |
10560 | 342 { |
343 dvb_channels_list *list; | |
344 dvb_channel_t *channel; | |
345 int do_tuning; | |
346 stream_t *stream = (stream_t*) priv->stream; | |
347 char buf[4096]; | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
348 dvb_config_t *conf = (dvb_config_t *) priv->config; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
349 int devno = conf->cards[card].devno; |
9610 | 350 |
10560 | 351 if(priv->is_on) //the fds are already open and we have to stop the demuxers |
352 { | |
353 dvb_demux_stop(priv->demux_fd[0]); | |
354 dvb_demux_stop(priv->demux_fd[1]); | |
355 priv->retry = 0; | |
11352 | 356 while(dvb_streaming_read(stream, buf, 4096) > 0); //empty both the stream's and driver's buffer |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
357 if(priv->card != card) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
358 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
359 dvbin_close(stream); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
360 if(! dvb_open_devices(priv, devno)) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
361 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
362 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB_SET_CHANNEL, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
363 return 0; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
364 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
365 priv->card = card; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
366 strcpy(priv->prev_tuning, ""); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
367 priv->list = priv->config->cards[priv->card].list; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
368 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
369 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
370 else |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
371 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
372 if(! dvb_open_devices(priv, devno)) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
373 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
374 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB_SET_CHANNEL2, COULDN'T OPEN DEVICES OF CARD: %d, EXIT\n", card); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
375 return 0; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
376 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
377 priv->card = card; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
378 strcpy(priv->prev_tuning, ""); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
379 priv->list = priv->config->cards[priv->card].list; |
10560 | 380 } |
381 | |
11352 | 382 priv->retry = 5; |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
383 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: card: %d, channel %d\n", card, n); |
10560 | 384 list = priv->list; |
385 if(list == NULL) | |
386 { | |
387 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n"); | |
388 return 0; | |
389 } | |
390 | |
391 if((n > list->NUM_CHANNELS) || (n < 0)) | |
392 { | |
393 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, abort\n", n); | |
394 return 0; | |
395 } | |
9610 | 396 |
10560 | 397 list->current = n; |
398 channel = &(list->channels[list->current]); | |
399 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: new channel name=%s\n", channel->name); | |
400 | |
401 switch(priv->tuner_type) | |
402 { | |
403 case TUNER_SAT: | |
404 sprintf(priv->new_tuning, "%d|%09d|%09d|%d|%c", priv->card, channel->freq, channel->srate, channel->diseqc, channel->pol); | |
405 break; | |
9610 | 406 |
10560 | 407 case TUNER_TER: |
408 sprintf(priv->new_tuning, "%d|%09d|%d|%d|%d|%d|%d|%d", priv->card, channel->freq, channel->inv, | |
409 channel->bw, channel->cr, channel->mod, channel->trans, channel->gi); | |
410 break; | |
411 | |
412 case TUNER_CBL: | |
413 sprintf(priv->new_tuning, "%d|%09d|%d|%d|%d|%d", priv->card, channel->freq, channel->inv, channel->srate, | |
414 channel->cr, channel->mod); | |
415 break; | |
416 } | |
417 | |
418 | |
9610 | 419 |
10560 | 420 if(strcmp(priv->prev_tuning, priv->new_tuning)) |
421 { | |
422 mp_msg(MSGT_DEMUX, MSGL_V, "DIFFERENT TUNING THAN THE PREVIOUS: %s -> %s\n", priv->prev_tuning, priv->new_tuning); | |
423 strcpy(priv->prev_tuning, priv->new_tuning); | |
424 do_tuning = 1; | |
425 } | |
426 else | |
427 { | |
11352 | 428 mp_msg(MSGT_DEMUX, MSGL_V, "SAME TUNING PARAMETERS, NO TUNING\n"); |
10560 | 429 do_tuning = 0; |
430 } | |
431 | |
432 stream->eof=1; | |
433 stream_reset(stream); | |
434 | |
9610 | 435 |
10560 | 436 if(do_tuning) |
437 if (! dvb_tune(priv, channel->freq, channel->pol, channel->srate, channel->diseqc, channel->tone, | |
438 channel->inv, channel->mod, channel->gi, channel->trans, channel->bw, channel->cr)) | |
439 return 0; | |
440 | |
441 | |
442 priv->is_on = 1; | |
443 | |
444 //sets demux filters and restart the stream | |
445 if(channel->vpid) | |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
446 if(! dvb_set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_OTHER)) |
10560 | 447 return 0; |
448 | |
449 if(channel->apid1) | |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
450 if(! dvb_set_ts_filt(priv->demux_fd[1], channel->apid1, DMX_PES_OTHER)) |
10560 | 451 return 0; |
452 | |
453 return 1; | |
454 } | |
455 | |
456 | |
9610 | 457 |
10560 | 458 int dvb_step_channel(dvb_priv_t *priv, int dir) |
459 { | |
460 int new_current; | |
461 dvb_channels_list *list; | |
462 | |
463 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_STEP_CHANNEL dir %d\n", dir); | |
9610 | 464 |
10560 | 465 if(priv == NULL) |
466 { | |
467 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL priv_ptr, quit\n"); | |
468 return 0; | |
469 } | |
9610 | 470 |
10560 | 471 list = priv->list; |
472 if(list == NULL) | |
473 { | |
474 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL list_ptr, quit\n"); | |
475 return 0; | |
476 } | |
9610 | 477 |
10560 | 478 |
479 if(dir == DVB_CHANNEL_HIGHER) | |
480 { | |
481 if(list->current == list->NUM_CHANNELS-1) | |
482 return 0; | |
9610 | 483 |
10560 | 484 new_current = list->current + 1; |
485 } | |
486 else | |
487 { | |
488 if(list->current == 0) | |
489 return 0; | |
9610 | 490 |
10560 | 491 new_current = list->current - 1; |
492 } | |
493 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
494 return dvb_set_channel(priv, priv->card, new_current); |
9610 | 495 } |
496 | |
497 | |
10560 | 498 |
499 | |
9610 | 500 extern char *get_path(char *); |
501 | |
10560 | 502 static void dvbin_close(stream_t *stream) |
9610 | 503 { |
10560 | 504 dvb_priv_t *priv = (dvb_priv_t *) stream->priv; |
9610 | 505 |
10560 | 506 close(priv->dvr_fd); |
507 close(priv->demux_fd[0]); | |
508 close(priv->demux_fd[1]); | |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
509 |
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
510 close(priv->fe_fd); |
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
511 #ifdef HAVE_DVB |
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
512 close(priv->sec_fd); |
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
513 #endif |
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
514 |
10560 | 515 priv->is_on = 0; |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
516 dvb_config->priv = NULL; |
10560 | 517 } |
9610 | 518 |
519 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
520 static int dvb_streaming_start(dvb_priv_t *priv, struct stream_priv_s *opts, int tuner_type, char *progname) |
10560 | 521 { |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
522 int i; |
10560 | 523 dvb_channel_t *channel = NULL; |
524 stream_t *stream = (stream_t*) priv->stream; | |
9610 | 525 |
526 | |
527 mp_msg(MSGT_DEMUX, MSGL_INFO, "code taken from dvbstream for mplayer v0.4pre1 - (C) Dave Chapman 2001\n"); | |
528 mp_msg(MSGT_DEMUX, MSGL_INFO, "Released under the GPL.\n"); | |
529 mp_msg(MSGT_DEMUX, MSGL_INFO, "Latest version available from http://www.linuxstb.org/\n"); | |
10560 | 530 mp_msg(MSGT_DEMUX, MSGL_V, "PROG: %s, CARD: %d, VID: %d, AID: %d, TYPE: %s, FILE: %s\n", |
531 opts->prog, opts->card, opts->vid, opts->aid, opts->type, opts->file); | |
9610 | 532 |
10560 | 533 priv->is_on = 0; |
9610 | 534 |
10560 | 535 i = 0; |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
536 while((channel == NULL) && i < priv->list->NUM_CHANNELS) |
10560 | 537 { |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
538 if(! strcmp(priv->list->channels[i].name, progname)) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
539 channel = &(priv->list->channels[i]); |
9610 | 540 |
10560 | 541 i++; |
542 } | |
9610 | 543 |
10560 | 544 if(channel != NULL) |
545 { | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
546 priv->list->current = i-1; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
547 mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, vid=%d, aid=%d, freq=%u, srate=%u, pol=%c, diseqc: %d, tone: %d\n", i-1, |
10560 | 548 channel->name, channel->vpid, channel->apid1, |
549 channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone); | |
550 } | |
551 else | |
552 { | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
553 mp_msg(MSGT_DEMUX, MSGL_ERR, "\n\nDVBIN: no such channel \"%s\"\n\n", progname); |
10560 | 554 return 0; |
9610 | 555 } |
556 | |
557 | |
10560 | 558 strcpy(priv->prev_tuning, ""); |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
559 if(!dvb_set_channel(priv, priv->card, priv->list->current)) |
10560 | 560 { |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
561 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR, COULDN'T SET CHANNEL %i: ", priv->list->current); |
10560 | 562 dvbin_close(stream); |
563 return 0; | |
564 } | |
565 | |
9610 | 566 stream->fd = priv->dvr_fd; |
567 | |
10560 | 568 mp_msg(MSGT_DEMUX, MSGL_V, "SUCCESSFUL EXIT from dvb_streaming_start\n"); |
9610 | 569 |
570 return 1; | |
571 } | |
572 | |
573 | |
10560 | 574 |
575 | |
576 static int dvb_open(stream_t *stream, int mode, void *opts, int *file_format) | |
9610 | 577 { |
10560 | 578 // I don't force the file format bacause, although it's almost always TS, |
579 // there are some providers that stream an IP multicast with M$ Mpeg4 inside | |
580 struct stream_priv_s* p = (struct stream_priv_s*)opts; | |
581 dvb_priv_t *priv; | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
582 char *progname; |
11352 | 583 int tuner_type = 0; |
10560 | 584 |
585 | |
586 if(mode != STREAM_READ) | |
587 return STREAM_UNSUPORTED; | |
588 | |
589 stream->priv = (dvb_priv_t*) malloc(sizeof(dvb_priv_t)); | |
590 if(stream->priv == NULL) | |
591 return STREAM_ERROR; | |
592 | |
593 priv = (dvb_priv_t *)stream->priv; | |
594 priv->stream = stream; | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
595 dvb_config = dvb_get_config(); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
596 if(dvb_config == NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
597 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
598 free(priv); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
599 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVB CONFIGURATION IS EMPTY, exit\n"); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
600 return STREAM_ERROR; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
601 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
602 dvb_config->priv = priv; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
603 priv->config = dvb_config; |
10560 | 604 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
605 if(p->card < 1 || p->card > priv->config->count) |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
606 { |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
607 free(priv); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
608 mp_msg(MSGT_DEMUX, MSGL_ERR, "NO CONFIGURATION FOUND FOR CARD N. %d, exit\n", p->card); |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
609 return STREAM_ERROR; |
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
610 } |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
611 priv->card = p->card - 1; |
11872
d158978a3d3c
Compliance with the DVB power management specification (doesn't close
attila
parents:
11352
diff
changeset
|
612 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
613 tuner_type = priv->config->cards[priv->card].type; |
10560 | 614 |
11352 | 615 if(tuner_type == 0) |
616 { | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
617 free(priv); |
11352 | 618 mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: UNKNOWN OR UNDETECTABLE TUNER TYPE, EXIT\n"); |
619 return STREAM_ERROR; | |
620 } | |
621 | |
622 | |
10560 | 623 priv->tuner_type = tuner_type; |
624 | |
12108
06c4780332bc
disallow non-sense type parameter; added support for absolute file path; prefer channels.conf.{sat,ter,cbl} over channels.conf if the file is available
nicodvb
parents:
12047
diff
changeset
|
625 mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: prog=%s, card=%d, type=%d, vid=%d, aid=%d\n", |
06c4780332bc
disallow non-sense type parameter; added support for absolute file path; prefer channels.conf.{sat,ter,cbl} over channels.conf if the file is available
nicodvb
parents:
12047
diff
changeset
|
626 p->prog, priv->card+1, priv->tuner_type, p->vid, p->aid); |
10560 | 627 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
628 priv->list = priv->config->cards[priv->card].list; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
629 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
630 if((! strcmp(p->prog, "")) && (priv->list != NULL)) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
631 progname = priv->list->channels[0].name; |
10560 | 632 else |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
633 progname = p->prog; |
10560 | 634 |
635 | |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
636 if(! dvb_streaming_start(priv, p, tuner_type, progname)) |
10560 | 637 { |
638 free(stream->priv); | |
639 stream->priv = NULL; | |
640 return STREAM_ERROR; | |
641 } | |
642 | |
643 stream->type = STREAMTYPE_DVB; | |
644 stream->fill_buffer = dvb_streaming_read; | |
645 stream->close = dvbin_close; | |
646 m_struct_free(&stream_opts, opts); | |
647 | |
648 return STREAM_OK; | |
9610 | 649 } |
10560 | 650 |
12307
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
651 #define MAX_CARDS 4 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
652 dvb_config_t *dvb_get_config() |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
653 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
654 int i, fd, type, size; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
655 char filename[30], *conf_file, *name; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
656 dvb_channels_list *list; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
657 dvb_card_config_t *cards = NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
658 dvb_config_t *conf = NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
659 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
660 if(dvb_config != NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
661 return dvb_config; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
662 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
663 conf = (dvb_config_t*) malloc(sizeof(dvb_config_t)); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
664 if(conf == NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
665 return NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
666 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
667 conf->priv = NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
668 conf->count = 0; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
669 conf->cards = NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
670 for(i=0; i<MAX_CARDS; i++) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
671 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
672 sprintf(filename, "/dev/dvb/adapter%d/frontend0", i); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
673 fd = open(filename, O_RDWR | O_NONBLOCK); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
674 if(fd < 0) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
675 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
676 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't open device %s, skipping\n", filename); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
677 continue; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
678 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
679 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
680 type = dvb_get_tuner_type(fd); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
681 close(fd); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
682 if(type != TUNER_SAT && type != TUNER_TER && type != TUNER_CBL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
683 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
684 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_CONFIG, can't detect tuner type of card %d, skipping\n", i); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
685 continue; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
686 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
687 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
688 switch(type) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
689 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
690 case TUNER_TER: |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
691 conf_file = get_path("channels.conf.ter"); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
692 break; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
693 case TUNER_CBL: |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
694 conf_file = get_path("channels.conf.cbl"); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
695 break; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
696 case TUNER_SAT: |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
697 conf_file = get_path("channels.conf.sat"); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
698 break; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
699 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
700 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
701 if((access(conf_file, F_OK | R_OK) != 0)) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
702 conf_file = get_path("channels.conf"); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
703 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
704 list = dvb_get_channels(conf_file, type); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
705 if(list == NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
706 continue; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
707 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
708 size = sizeof(dvb_card_config_t) * (conf->count + 1); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
709 cards = realloc(conf->cards, size); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
710 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
711 if(cards == NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
712 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
713 fprintf(stderr, "DVB_CONFIG, can't realloc %d bytes, skipping\n", size); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
714 continue; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
715 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
716 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
717 name = (char*) malloc(20); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
718 if(name==NULL) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
719 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
720 fprintf(stderr, "DVB_CONFIG, can't realloc 20 bytes, skipping\n"); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
721 continue; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
722 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
723 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
724 conf->cards = cards; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
725 conf->cards[conf->count].devno = i; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
726 conf->cards[conf->count].list = list; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
727 conf->cards[conf->count].type = type; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
728 sprintf(name, "DVB-%c card n. %d", type==TUNER_TER ? 'T' : (type==TUNER_CBL ? 'C' : 'S'), conf->count+1); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
729 conf->cards[conf->count].name = name; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
730 conf->count++; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
731 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
732 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
733 if(conf->count == 0) |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
734 { |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
735 free(conf); |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
736 conf = NULL; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
737 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
738 |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
739 dvb_config = conf; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
740 return conf; |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
741 } |
44152bfdc002
new configuration structure, dvb_set_channel takes 2 parameters, 1000l memleak fix
nicodvb
parents:
12116
diff
changeset
|
742 |
10560 | 743 |
744 | |
745 stream_info_t stream_info_dvb = { | |
746 "Dvb Input", | |
747 "dvbin", | |
748 "Nico", | |
749 "based on the code from ??? (probably Arpi)", | |
750 dvb_open, | |
751 { "dvb", NULL }, | |
752 &stream_opts, | |
753 1 // Urls are an option string | |
754 }; | |
755 | |
756 | |
757 | |
758 |