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
|
|
26 // Linux includes:
|
|
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>
|
|
34 #include <sys/stat.h>
|
|
35 #include <resolv.h>
|
|
36 #include <fcntl.h>
|
|
37 #include <unistd.h>
|
|
38 #include <signal.h>
|
|
39 #include <values.h>
|
|
40 #include <string.h>
|
|
41 #include <sys/socket.h>
|
|
42 #include <netinet/in.h>
|
|
43 #include <netdb.h>
|
|
44 #include <errno.h>
|
|
45 #include <fcntl.h>
|
|
46 #include <unistd.h>
|
|
47 #include "config.h"
|
|
48
|
|
49 // DVB includes:
|
|
50
|
|
51 #include "stream.h"
|
|
52 #include "demuxer.h"
|
|
53
|
|
54 #include "../cfgparser.h"
|
|
55
|
|
56 #include "dvbin.h"
|
|
57 #include "dvb_defaults.h"
|
|
58
|
|
59 extern int video_id, audio_id, demuxer_type;
|
|
60
|
|
61
|
|
62 #define MAX_CHANNELS 8
|
|
63
|
|
64
|
|
65 #define min(a, b) ((a) <= (b) ? (a) : (b))
|
|
66
|
|
67 int dvbin_param_card, dvbin_param_freq, dvbin_param_srate, dvbin_param_diseqc = 0,
|
|
68 dvbin_param_tone = -1, dvbin_param_vid, dvbin_param_aid, dvbin_is_active = 0;
|
|
69 int dvbin_param_mod, dvbin_param_gi, dvbin_param_tm, dvbin_param_bw, dvbin_param_cr;
|
|
70 char *dvbin_param_pol = "", *dvbin_param_inv="INVERSION_AUTO",
|
|
71 *dvbin_param_type="SAT ",
|
|
72 *dvbin_param_prog = " ";
|
|
73 dvb_history_t dvb_prev_next;
|
|
74
|
|
75 struct config dvbin_opts_conf[] = {
|
|
76 {"on", &dvbin_param_on, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
77 {"type", &dvbin_param_type, CONF_TYPE_STRING, 0, 0, 1, NULL},
|
|
78 {"card", &dvbin_param_card, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
|
|
79 {"freq", &dvbin_param_freq, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
80 {"pol", &dvbin_param_pol, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
81 {"srate", &dvbin_param_srate, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
82 {"diseqc", &dvbin_param_diseqc, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
|
|
83 {"tone", &dvbin_param_tone, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
84 {"vid", &dvbin_param_vid, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
85 {"aid", &dvbin_param_aid, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
86 {"prog", &dvbin_param_prog, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
87 {"inv", &dvbin_param_inv, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
|
88 {"mod", &dvbin_param_mod, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
89 {"gi", &dvbin_param_gi, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
90 {"tm", &dvbin_param_tm, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
91 {"bw", &dvbin_param_bw, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
92 {"cr", &dvbin_param_cr, CONF_TYPE_INT, 0, 0, 1, NULL},
|
|
93 {NULL, NULL, 0, 0, 0, 0, NULL}
|
|
94 };
|
|
95
|
|
96
|
|
97 int card=0;
|
|
98
|
|
99 extern int open_fe(int* fd_frontend, int* fd_sec);
|
|
100 extern int set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype);
|
|
101 extern int demux_stop(int fd);
|
|
102 extern void make_nonblock(int f);
|
|
103 extern int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
|
|
104 fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
|
|
105 fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate);
|
|
106 extern char *frontenddev[4], *dvrdev[4], *secdev[4], *demuxdev[4];
|
|
107
|
|
108
|
|
109 dvb_channels_list *dvb_get_channels(char *filename, const char *type)
|
|
110 {
|
|
111 dvb_channels_list *list;
|
|
112 FILE *f;
|
|
113 uint8_t line[128];
|
|
114 int fields, row_count;
|
|
115 dvb_channel_t *ptr;
|
|
116 char *tmp_lcr, *tmp_hier, *inv, *bw, *cr, *mod, *transm, *gi;
|
|
117 //const char *cbl_conf = "%a[^:]:%d:%c:%d:%a[^:]:%a[^:]:%d:%d\n";
|
|
118 const char *sat_conf = "%a[^:]:%d:%c:%d:%d:%d:%d:%d:%d:%d\n";
|
|
119 const char *ter_conf = "%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%d:%d\n";
|
|
120
|
|
121 list = malloc(sizeof(dvb_channels_list));
|
|
122 if(list == NULL)
|
|
123 {
|
|
124 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: couldn't malloc enough memory\n");
|
|
125 return NULL;
|
|
126 }
|
|
127
|
|
128 mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %s\n", filename, type);
|
|
129 if((f=fopen(filename, "r"))==NULL)
|
|
130 {
|
|
131 mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename);
|
|
132 return NULL;
|
|
133 }
|
|
134
|
|
135 list->NUM_CHANNELS = 0;
|
|
136 row_count = 0;
|
|
137 while(! feof(f) && row_count < 512)
|
|
138 {
|
|
139 if( fgets(line, 128, f) == NULL ) continue;
|
|
140
|
|
141 if(line[0] == '#')
|
|
142 continue; //comment line
|
|
143
|
|
144 ptr = &(list->channels[ list->NUM_CHANNELS ]);
|
|
145
|
|
146 if(! strcmp(type, "TER"))
|
|
147 {
|
|
148 fields = sscanf(line, ter_conf,
|
|
149 &ptr->name, &ptr->freq, &inv, &bw, &cr, tmp_lcr, &mod,
|
|
150 &transm, &gi, &tmp_hier, &ptr->vpid, &ptr->apid1);
|
|
151
|
|
152 if(! strcmp(inv, "INVERSION_ON"))
|
|
153 ptr->inv = INVERSION_ON;
|
|
154 else if(! strcmp(inv, "INVERSION_OFF"))
|
|
155 ptr->inv = INVERSION_OFF;
|
|
156 else
|
|
157 ptr->inv = INVERSION_AUTO;
|
|
158
|
|
159 if(! strcmp(bw, "BANDWIDTH_6_MHZ"))
|
|
160 ptr->bw = BANDWIDTH_6_MHZ;
|
|
161 else if(! strcmp(bw, "BANDWIDTH_7_MHZ"))
|
|
162 ptr->bw = BANDWIDTH_7_MHZ;
|
|
163 else if(! strcmp(bw, "BANDWIDTH_8_MHZ"))
|
|
164 ptr->bw = BANDWIDTH_8_MHZ;
|
|
165
|
|
166
|
|
167 if(! strcmp(cr, "FEC_1_2"))
|
|
168 ptr->cr =FEC_1_2;
|
|
169 else if(! strcmp(cr, "FEC_2_3"))
|
|
170 ptr->cr =FEC_2_3;
|
|
171 else if(! strcmp(cr, "FEC_3_4"))
|
|
172 ptr->cr =FEC_3_4;
|
|
173 #ifdef HAVE_DVB_HEAD
|
|
174 else if(! strcmp(cr, "FEC_4_5"))
|
|
175 ptr->cr =FEC_4_5;
|
|
176 else if(! strcmp(cr, "FEC_6_7"))
|
|
177 ptr->cr =FEC_6_7;
|
|
178 else if(! strcmp(cr, "FEC_8_9"))
|
|
179 ptr->cr =FEC_8_9;
|
|
180 #endif
|
|
181 else if(! strcmp(cr, "FEC_5_6"))
|
|
182 ptr->cr =FEC_5_6;
|
|
183 else if(! strcmp(cr, "FEC_7_8"))
|
|
184 ptr->cr =FEC_7_8;
|
|
185 else if(! strcmp(cr, "FEC_NONE"))
|
|
186 ptr->cr =FEC_NONE;
|
|
187 else ptr->cr =FEC_AUTO;
|
|
188
|
|
189 if(! strcmp(mod, "QAM_128"))
|
|
190 ptr->mod = QAM_128;
|
|
191 else if(! strcmp(mod, "QAM_256"))
|
|
192 ptr->mod = QAM_256;
|
|
193 else if(! strcmp(mod, "QAM_64"))
|
|
194 ptr->mod = QAM_64;
|
|
195 else if(! strcmp(mod, "QAM_32"))
|
|
196 ptr->mod = QAM_32;
|
|
197 else if(! strcmp(mod, "QAM_16"))
|
|
198 ptr->mod = QAM_16;
|
|
199 else ptr->mod = QPSK;
|
|
200
|
|
201
|
|
202 if(! strcmp(transm, "TRANSMISSION_MODE_2K"))
|
|
203 ptr->trans = TRANSMISSION_MODE_2K;
|
|
204 else if(! strcmp(transm, "TRANSMISSION_MODE_8K"))
|
|
205 ptr->trans = TRANSMISSION_MODE_8K;
|
|
206
|
|
207 if(! strcmp(gi, "GUARD_INTERVAL_1_32"))
|
|
208 ptr->gi = GUARD_INTERVAL_1_32;
|
|
209 else if(! strcmp(gi, "GUARD_INTERVAL_1_16"))
|
|
210 ptr->gi = GUARD_INTERVAL_1_16;
|
|
211 else if(! strcmp(gi, "GUARD_INTERVAL_1_8"))
|
|
212 ptr->gi = GUARD_INTERVAL_1_8;
|
|
213 else ptr->gi = GUARD_INTERVAL_1_4;
|
|
214
|
|
215
|
|
216 }
|
|
217 /*
|
|
218 else if(! strcmp(type, "CBL"))
|
|
219 {
|
|
220 fields = sscanf(line, cbl_conf,
|
|
221 &ptr->name, &ptr->freq, &ptr->inv, &ptr->qam,
|
|
222 &ptr->fec, &ptr->mod, &ptr->vpid, &ptr->apid1);
|
|
223
|
|
224
|
|
225 }
|
|
226 */
|
|
227 else //SATELLITE
|
|
228 {
|
|
229 fields = sscanf(line, sat_conf,
|
|
230 &ptr->name, &ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, &ptr->vpid, &ptr->apid1,
|
|
231 &ptr->tpid, &ptr->ca, &ptr->progid);
|
|
232 ptr->pol = toupper(ptr->pol);
|
|
233 ptr->freq *= 1000UL;
|
|
234 ptr->srate *= 1000UL;
|
|
235 ptr->tone = -1;
|
|
236 mp_msg(MSGT_DEMUX, MSGL_V,
|
|
237 "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, NUM: %d\n",
|
|
238 fields, ptr->name, ptr->freq, ptr->srate, ptr->pol, ptr->diseqc, ptr->tone, ptr->vpid, ptr->apid1, ptr->apid2, ptr->tpid, ptr->progid, list->NUM_CHANNELS);
|
|
239 }
|
|
240
|
|
241 list->NUM_CHANNELS++;
|
|
242 row_count++;
|
|
243 }
|
|
244
|
|
245 fclose(f);
|
|
246 return list;
|
|
247 }
|
|
248
|
|
249
|
|
250 static long getmsec()
|
|
251 {
|
|
252 struct timeval tv;
|
|
253 gettimeofday(&tv, (struct timezone*) NULL);
|
|
254 return(tv.tv_sec%1000000)*1000 + tv.tv_usec/1000;
|
|
255 }
|
|
256
|
|
257
|
|
258
|
|
259 int dvb_streaming_read(int fd, char *buffer, unsigned int size, dvb_priv_t *priv)
|
|
260 {
|
|
261 struct pollfd pfds[1];
|
|
262 uint32_t ok = 0, pos = 0, tot = 0, rk, d, r, m;
|
|
263
|
|
264 mp_msg(MSGT_DEMUX, MSGL_DBG2, "dvb_streaming_read(%u)\n", fd);
|
|
265
|
|
266 while(pos < size)
|
|
267 {
|
|
268 ok = 0;
|
|
269 tot = 0;
|
|
270 //int m = min((size-pos), 188);
|
|
271 m = size - pos;
|
|
272 d = (int) (m / 188);
|
|
273 r = m % 188;
|
|
274
|
|
275 m = d * 188;
|
|
276 m = (m ? m : r);
|
|
277
|
|
278 pfds[0].fd = fd;
|
|
279 pfds[0].events = POLLIN | POLLPRI;
|
|
280
|
|
281 mp_msg(MSGT_DEMUX, MSGL_DBG2, "DEVICE: %d, DVR: %d, PIPE: %d <-> %d\n", fd, priv->dvr_fd, priv->input, priv->output);
|
|
282
|
|
283 poll(pfds, 1, 500);
|
|
284 if((rk = read(fd, &buffer[pos], m)) > 0)
|
|
285 pos += rk;
|
|
286 }
|
|
287
|
|
288 return pos;
|
|
289 }
|
|
290
|
|
291
|
|
292
|
|
293 dvb_history_t *dvb_step_channel(dvb_priv_t *priv, int dir, dvb_history_t *h)
|
|
294 {
|
|
295 //int new_freq, new_srate, new_diseqc, new_tone, new_vpid, new_apid;
|
|
296 //char new_pol;
|
|
297 int new_current;
|
|
298 dvb_channel_t *next;
|
|
299 dvb_channels_list *list;
|
|
300
|
|
301 if(priv == NULL)
|
|
302 {
|
|
303 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: PRIV NULL PTR, quit\n");
|
|
304 return 0;
|
|
305 }
|
|
306
|
|
307 list = priv->list;
|
|
308 if(list == NULL)
|
|
309 {
|
|
310 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: LIST NULL PTR, quit\n");
|
|
311 return 0;
|
|
312 }
|
|
313
|
|
314 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_STEP_CHANNEL dir %d\n", dir);
|
|
315
|
|
316 if(dir == DVB_CHANNEL_HIGHER)
|
|
317 {
|
|
318 if(list->current == list->NUM_CHANNELS)
|
|
319 return 0;
|
|
320
|
|
321 new_current = list->current + 1;
|
|
322 next = &(list->channels[new_current]);
|
|
323 }
|
|
324 else
|
|
325 {
|
|
326 if(list->current == 0)
|
|
327 return 0;
|
|
328
|
|
329 new_current = list->current - 1;
|
|
330 next = &(list->channels[new_current]);
|
|
331
|
|
332 }
|
|
333
|
|
334 demux_stop(priv->demux_fd[0]);
|
|
335 demux_stop(priv->demux_fd[1]);
|
|
336
|
|
337 h->prev = list->current;
|
|
338 h->next = new_current;
|
|
339
|
|
340 list->current = new_current;
|
|
341
|
|
342 return h;
|
|
343 }
|
|
344
|
|
345
|
|
346 extern char *get_path(char *);
|
|
347
|
|
348 dvb_channels_list *list_ptr = NULL;
|
|
349
|
|
350 int dvb_streaming_start(stream_t *stream)
|
|
351 {
|
|
352 int pids[MAX_CHANNELS];
|
|
353 int pestypes[MAX_CHANNELS];
|
|
354 int npids, i;
|
|
355 char *filename, type[80];
|
|
356 unsigned long freq = 0;
|
|
357 char pol = 0;
|
|
358 unsigned long srate = 0;
|
|
359 int diseqc = 0, old_diseqc = 0;
|
|
360 int tone = -1;
|
|
361
|
|
362 dvb_priv_t *priv;
|
|
363 dvb_channel_t *channel = NULL;
|
|
364 fe_spectral_inversion_t specInv = INVERSION_AUTO;
|
|
365 fe_modulation_t modulation = CONSTELLATION_DEFAULT;
|
|
366 fe_transmit_mode_t TransmissionMode = TRANSMISSION_MODE_DEFAULT;
|
|
367 fe_bandwidth_t bandWidth = BANDWIDTH_DEFAULT;
|
|
368 fe_guard_interval_t guardInterval = GUARD_INTERVAL_DEFAULT;
|
|
369 fe_code_rate_t HP_CodeRate = HP_CODERATE_DEFAULT;
|
|
370
|
|
371
|
|
372 stream->priv = (dvb_priv_t*) malloc(sizeof(dvb_priv_t));
|
|
373 if(stream->priv == NULL)
|
|
374 return 0;
|
|
375 priv = (dvb_priv_t*) stream->priv;
|
|
376
|
|
377 if(!strncmp(dvbin_param_type, "CBL", 3))
|
|
378 strncpy(type, "CBL", 3);
|
|
379 else if(!strncmp(dvbin_param_type, "TER", 3))
|
|
380 strncpy(type, "TER", 3);
|
|
381 else
|
|
382 strncpy(type, "SAT", 3);
|
|
383
|
|
384
|
|
385 filename = get_path("channels.conf");
|
|
386
|
|
387 if(list_ptr == NULL)
|
|
388 {
|
|
389 if(filename)
|
|
390 {
|
|
391 if((list_ptr = dvb_get_channels(filename, type)) == NULL)
|
|
392 mp_msg(MSGT_DEMUX, MSGL_WARN, "EMPTY CHANNELS LIST!\n");
|
|
393 else
|
|
394 {
|
|
395 priv->list = list_ptr;
|
|
396 priv->list->current = 0;
|
|
397 }
|
|
398 }
|
|
399 else
|
|
400 {
|
|
401 list_ptr = NULL;
|
|
402 mp_msg(MSGT_DEMUX, MSGL_WARN, "NO CHANNELS FILE FOUND!\n");
|
|
403 }
|
|
404 }
|
|
405
|
|
406
|
|
407 mp_msg(MSGT_DEMUX, MSGL_INFO, "code taken from dvbstream for mplayer v0.4pre1 - (C) Dave Chapman 2001\n");
|
|
408 mp_msg(MSGT_DEMUX, MSGL_INFO, "Released under the GPL.\n");
|
|
409 mp_msg(MSGT_DEMUX, MSGL_INFO, "Latest version available from http://www.linuxstb.org/\n");
|
|
410 mp_msg(MSGT_DEMUX, MSGL_V, "ON: %d, CARD: %d, FREQ: %d, SRATE: %d, POL: %s, VID: %d, AID: %d\n", dvbin_param_on,
|
|
411 dvbin_param_card, dvbin_param_freq, dvbin_param_srate, dvbin_param_pol, dvbin_param_vid, dvbin_param_aid);
|
|
412
|
|
413 npids = 0;
|
|
414
|
|
415 if((dvb_prev_next.next > -1) && (dvb_prev_next.prev > -1) && (list_ptr != NULL)) //We are after a channel stepping
|
|
416 {
|
|
417 list_ptr->current = dvb_prev_next.next;
|
|
418 channel = &(list_ptr->channels[dvb_prev_next.next]);
|
|
419 mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, vid=%d, aid=%d, freq=%lu, srate=%lu, pol=%c, diseqc: %d, tone: %d\n", dvb_prev_next.next,
|
|
420 channel->name, channel->vpid, channel->apid1,
|
|
421 channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone);
|
|
422
|
|
423
|
|
424 if((dvb_prev_next.prev >= 0) && (dvb_prev_next.prev < list_ptr->NUM_CHANNELS))
|
|
425 {
|
|
426 dvb_channel_t *tmp = &(list_ptr->channels[dvb_prev_next.prev]);
|
|
427 old_diseqc = tmp->diseqc;
|
|
428 }
|
|
429 }
|
|
430 else if(list_ptr != NULL && strlen(dvbin_param_prog))
|
|
431 {
|
|
432 i = 0;
|
|
433 while((channel == NULL) && i < list_ptr->NUM_CHANNELS)
|
|
434 {
|
|
435 if(! strcmp(list_ptr->channels[i].name, dvbin_param_prog))
|
|
436 channel = &(list_ptr->channels[i]);
|
|
437
|
|
438 i++;
|
|
439 }
|
|
440 if(channel != NULL)
|
|
441 {
|
|
442 list_ptr->current = i-1;
|
|
443 mp_msg(MSGT_DEMUX, MSGL_V, "PROGRAM NUMBER %d: name=%s, vid=%d, aid=%d, freq=%lu, srate=%lu, pol=%c, diseqc: %d, tone: %d\n", i-1,
|
|
444 channel->name, channel->vpid, channel->apid1,
|
|
445 channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone);
|
|
446
|
|
447 }
|
|
448 }
|
|
449
|
|
450
|
|
451 if(dvbin_param_vid > 0)
|
|
452 {
|
|
453 pids[npids] = priv->channel.vpid = dvbin_param_vid;
|
|
454 }
|
|
455 else if(channel != NULL)
|
|
456 {
|
|
457 pids[npids] = priv->channel.vpid = channel->vpid;
|
|
458 }
|
|
459 pestypes[npids] = DMX_PES_VIDEO;
|
|
460 npids++;
|
|
461
|
|
462 if(dvbin_param_aid > 0)
|
|
463 {
|
|
464 pids[npids] = priv->channel.apid1 = dvbin_param_aid;
|
|
465 }
|
|
466 else if(channel != NULL)
|
|
467 {
|
|
468 pids[npids] = priv->channel.vpid = channel->apid1;
|
|
469 }
|
|
470 pestypes[npids] = DMX_PES_AUDIO;
|
|
471 npids++;
|
|
472
|
|
473
|
|
474
|
|
475 if(dvbin_param_freq)
|
|
476 freq = dvbin_param_freq * 1000UL;
|
|
477 else if(channel != NULL)
|
|
478 freq = channel->freq;
|
|
479
|
|
480
|
|
481 if(dvbin_param_srate)
|
|
482 srate = dvbin_param_srate * 1000UL;
|
|
483 else if(channel != NULL)
|
|
484 srate = channel->srate;
|
|
485
|
|
486 if((1<= dvbin_param_diseqc) && (dvbin_param_diseqc <= 4))
|
|
487 diseqc = dvbin_param_diseqc;
|
|
488 else
|
|
489 if(channel != NULL)
|
|
490 if(channel->diseqc != old_diseqc)
|
|
491 diseqc = channel->diseqc;
|
|
492 else
|
|
493 diseqc = 0;
|
|
494 else
|
|
495 diseqc = 0;
|
|
496 mp_msg(MSGT_DEMUX, MSGL_INFO, "DISEQC: %d\n", diseqc);
|
|
497
|
|
498 if((dvbin_param_tone == 0) || (dvbin_param_tone == 1))
|
|
499 tone = dvbin_param_tone;
|
|
500 else
|
|
501 if(channel != NULL)
|
|
502 tone = channel->tone;
|
|
503 else
|
|
504 tone = -1;
|
|
505
|
|
506 if(! strcmp(dvbin_param_pol, "V")) pol = 'V';
|
|
507 else if(! strcmp(dvbin_param_pol, "H")) pol = 'H';
|
|
508 else if(channel != NULL) pol = channel->pol;
|
|
509 else pol='V';
|
|
510 pol = toupper(pol);
|
|
511
|
|
512
|
|
513 if(!strcmp(dvbin_param_inv, "INVERSION_ON"))
|
|
514 specInv = INVERSION_ON;
|
|
515 else if(!strcmp(dvbin_param_inv, "INVERSION_OFF"))
|
|
516 specInv = INVERSION_OFF;
|
|
517 else if(!strcmp(dvbin_param_inv, "INVERSION_AUTO"))
|
|
518 specInv = INVERSION_AUTO;
|
|
519 else if(channel != NULL)
|
|
520 specInv = channel->inv;
|
|
521 else
|
|
522 specInv = INVERSION_AUTO;
|
|
523
|
|
524
|
|
525 if(dvbin_param_mod)
|
|
526 {
|
|
527 switch(dvbin_param_mod)
|
|
528 {
|
|
529 case 16: modulation=QAM_16; break;
|
|
530 case 32: modulation=QAM_32; break;
|
|
531 case 64: modulation=QAM_64; break;
|
|
532 case 128: modulation=QAM_128; break;
|
|
533 case 256: modulation=QAM_256; break;
|
|
534 default:
|
|
535 mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid QAM rate: %s\n", dvbin_param_mod);
|
|
536 modulation=CONSTELLATION_DEFAULT;
|
|
537 }
|
|
538 }
|
|
539 else if(channel != NULL)
|
|
540 modulation = channel->mod;
|
|
541 else
|
|
542 modulation=CONSTELLATION_DEFAULT;
|
|
543
|
|
544
|
|
545 if(dvbin_param_gi)
|
|
546 {
|
|
547 switch(dvbin_param_gi)
|
|
548 {
|
|
549 case 32: guardInterval=GUARD_INTERVAL_1_32; break;
|
|
550 case 16: guardInterval=GUARD_INTERVAL_1_16; break;
|
|
551 case 8: guardInterval=GUARD_INTERVAL_1_8; break;
|
|
552 case 4: guardInterval=GUARD_INTERVAL_1_4; break;
|
|
553 default:
|
|
554 mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid Guard Interval: %s\n", dvbin_param_gi);
|
|
555 guardInterval=GUARD_INTERVAL_DEFAULT;
|
|
556 }
|
|
557 }
|
|
558 else if(channel != NULL)
|
|
559 guardInterval = channel->gi;
|
|
560 else
|
|
561 guardInterval=GUARD_INTERVAL_DEFAULT;
|
|
562
|
|
563 if(dvbin_param_tm)
|
|
564 {
|
|
565 switch(dvbin_param_tm)
|
|
566 {
|
|
567 case 8: TransmissionMode=TRANSMISSION_MODE_8K; break;
|
|
568 case 2: TransmissionMode=TRANSMISSION_MODE_2K; break;
|
|
569 default:
|
|
570 TransmissionMode=TRANSMISSION_MODE_DEFAULT;
|
|
571 mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid Transmission Mode: %s\n", dvbin_param_tm);
|
|
572 }
|
|
573 }
|
|
574 else if(channel != NULL)
|
|
575 TransmissionMode = channel->trans;
|
|
576 else
|
|
577 TransmissionMode=TRANSMISSION_MODE_DEFAULT;
|
|
578
|
|
579
|
|
580 if(dvbin_param_bw)
|
|
581 {
|
|
582 switch(dvbin_param_bw)
|
|
583 {
|
|
584 case 8: bandWidth=BANDWIDTH_8_MHZ; break;
|
|
585 case 7: bandWidth=BANDWIDTH_7_MHZ; break;
|
|
586 case 6: bandWidth=BANDWIDTH_6_MHZ; break;
|
|
587 default:
|
|
588 mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid DVB-T bandwidth: %s\n", dvbin_param_bw);
|
|
589 bandWidth=BANDWIDTH_DEFAULT;
|
|
590 }
|
|
591 }
|
|
592 else if(channel != NULL)
|
|
593 bandWidth = channel->bw;
|
|
594 else
|
|
595 bandWidth=BANDWIDTH_DEFAULT;
|
|
596
|
|
597
|
|
598 if(dvbin_param_cr)
|
|
599 {
|
|
600 switch(dvbin_param_cr)
|
|
601 {
|
|
602 case -1: HP_CodeRate=FEC_AUTO; break;
|
|
603 case 12: HP_CodeRate=FEC_1_2; break;
|
|
604 case 23: HP_CodeRate=FEC_2_3; break;
|
|
605 case 34: HP_CodeRate=FEC_3_4; break;
|
|
606 case 56: HP_CodeRate=FEC_5_6; break;
|
|
607 case 78: HP_CodeRate=FEC_7_8; break;
|
|
608 default:
|
|
609 mp_msg(MSGT_DEMUX, MSGL_ERR, "Invalid Code Rate: %s\n", dvbin_param_cr);
|
|
610 HP_CodeRate=HP_CODERATE_DEFAULT;
|
|
611 }
|
|
612 }
|
|
613 else if(channel != NULL)
|
|
614 HP_CodeRate = channel->cr;
|
|
615 else
|
|
616 HP_CodeRate=HP_CODERATE_DEFAULT;
|
|
617
|
|
618
|
|
619
|
|
620 card = dvbin_param_card - 1;
|
|
621 if((card < 0) || (card > 4))
|
|
622 card = 0;
|
|
623
|
|
624
|
|
625 dvbin_param_on = 1;
|
|
626
|
|
627 mp_msg(MSGT_DEMUX, MSGL_V, "CARD: %d, FREQ: %d, POL: %c, SRATE: %d, DISEQC: %d, TONE: %d, VPID: %d, APID: %d\n", card, freq, pol, srate, diseqc, tone, pids[0], pids[1]);
|
|
628
|
|
629 priv->channel.freq = freq;
|
|
630 priv->channel.srate = srate;
|
|
631 priv->channel.diseqc = diseqc;
|
|
632 priv->channel.pol = pol;
|
|
633 priv->channel.tone = tone;
|
|
634 priv->channel.inv = specInv;
|
|
635 priv->channel.mod = modulation;
|
|
636 priv->channel.gi = guardInterval;
|
|
637 priv->channel.trans = TransmissionMode;
|
|
638 priv->channel.bw = bandWidth;
|
|
639 priv->channel.cr = HP_CodeRate;
|
|
640
|
|
641 if(freq && pol && srate)
|
|
642 if (! dvb_tune(priv, freq, pol, srate, diseqc, tone, specInv, modulation, guardInterval, TransmissionMode, bandWidth, HP_CodeRate))
|
|
643 return 0;
|
|
644
|
|
645 for (i=0; i < npids; i++)
|
|
646 {
|
|
647 if((priv->demux_fd[i] = open(demuxdev[card], O_RDWR)) < 0)
|
|
648 {
|
|
649 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX %i: ", i);
|
|
650 return -1;
|
|
651 }
|
|
652 }
|
|
653
|
|
654 if((priv->dvr_fd = open(dvrdev[card], O_RDONLY| O_NONBLOCK)) < 0)
|
|
655 {
|
|
656 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVR DEVICE: ");
|
|
657 return -1;
|
|
658 }
|
|
659
|
|
660
|
|
661 /* Now we set the filters */
|
|
662 for (i=0; i< npids; i++)
|
|
663 {
|
|
664 set_ts_filt(priv->demux_fd[i], pids[i], pestypes[i]);
|
|
665 //make_nonblock(fd[i]);
|
|
666 }
|
|
667
|
|
668
|
|
669 stream->fd = priv->dvr_fd;
|
|
670
|
|
671 dvbin_is_active = 1;
|
|
672
|
|
673 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ESCO da dvb_streaming_start(s)\n");
|
|
674
|
|
675 return 1;
|
|
676 }
|
|
677
|
|
678
|
|
679 int dvbin_close(dvb_priv_t *priv)
|
|
680 {
|
|
681 //close(priv->dvr_fd);
|
|
682 close(priv->demux_fd[0]);
|
|
683 close(priv->demux_fd[1]);
|
|
684 }
|