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 {
|
|
67 "", 1, "", 0, 0, "channels.conf"
|
|
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 },
|
|
82 {"filename", ST_OFF(card), CONF_TYPE_INT, M_OPT_RANGE, 1, 4, NULL},
|
|
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},
|
|
98 {"type", &stream_defaults.type, CONF_TYPE_STRING, 0, 0 ,0, NULL},
|
|
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);
|
|
111 extern int dvb_get_tuner_type(dvb_priv_t *priv);
|
|
112
|
9610
|
113 extern int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone,
|
|
114 fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval,
|
|
115 fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate);
|
10560
|
116 extern char *dvb_dvrdev[4], *dvb_demuxdev[4];
|
|
117
|
|
118 dvb_channels_list *dvb_list_ptr = NULL;
|
9610
|
119
|
|
120
|
10560
|
121 static dvb_channels_list *dvb_get_channels(char *filename, int type)
|
9610
|
122 {
|
|
123 dvb_channels_list *list;
|
|
124 FILE *f;
|
10560
|
125 uint8_t line[CHANNEL_LINE_LEN];
|
|
126
|
9610
|
127 int fields, row_count;
|
|
128 dvb_channel_t *ptr;
|
|
129 char *tmp_lcr, *tmp_hier, *inv, *bw, *cr, *mod, *transm, *gi;
|
10560
|
130 const char *cbl_conf = "%a[^:]:%d:%c:%d:%a[^:]:%a[^:]:%d:%d\n";
|
9610
|
131 const char *sat_conf = "%a[^:]:%d:%c:%d:%d:%d:%d:%d:%d:%d\n";
|
|
132 const char *ter_conf = "%a[^:]:%d:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%a[^:]:%d:%d\n";
|
|
133
|
10560
|
134 if(type != TUNER_SAT && type != TUNER_TER && type != TUNER_CBL)
|
|
135 {
|
|
136 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: wrong tuner type, exit\n");
|
|
137 return 0;
|
|
138 }
|
|
139
|
9610
|
140 list = malloc(sizeof(dvb_channels_list));
|
|
141 if(list == NULL)
|
|
142 {
|
|
143 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_GET_CHANNELS: couldn't malloc enough memory\n");
|
|
144 return NULL;
|
|
145 }
|
|
146
|
10560
|
147 bzero(list, sizeof(dvb_channels_list));
|
|
148 mp_msg(MSGT_DEMUX, MSGL_V, "CONFIG_READ FILE: %s, type: %d\n", filename, type);
|
9610
|
149 if((f=fopen(filename, "r"))==NULL)
|
|
150 {
|
|
151 mp_msg(MSGT_DEMUX, MSGL_FATAL, "CAN'T READ CONFIG FILE %s\n", filename);
|
|
152 return NULL;
|
|
153 }
|
|
154
|
|
155 list->NUM_CHANNELS = 0;
|
|
156 row_count = 0;
|
|
157 while(! feof(f) && row_count < 512)
|
|
158 {
|
10560
|
159 if( fgets(line, CHANNEL_LINE_LEN, f) == NULL ) continue;
|
9610
|
160
|
|
161 if(line[0] == '#')
|
10560
|
162 continue;
|
9610
|
163
|
10560
|
164 ptr = &(list->channels[list->NUM_CHANNELS]);
|
9610
|
165
|
10560
|
166 if(type == TUNER_TER)
|
9610
|
167 {
|
|
168 fields = sscanf(line, ter_conf,
|
10560
|
169 &ptr->name, &ptr->freq, &inv, &bw, &cr, &tmp_lcr, &mod,
|
9610
|
170 &transm, &gi, &tmp_hier, &ptr->vpid, &ptr->apid1);
|
10560
|
171 }
|
|
172 else if(type == TUNER_CBL)
|
|
173 {
|
|
174 fields = sscanf(line, cbl_conf,
|
|
175 &ptr->name, &ptr->freq, &inv, &ptr->srate,
|
|
176 &cr, &mod, &ptr->vpid, &ptr->apid1);
|
|
177 }
|
|
178 else //SATELLITE
|
|
179 {
|
|
180 fields = sscanf(line, sat_conf,
|
|
181 &ptr->name, &ptr->freq, &ptr->pol, &ptr->diseqc, &ptr->srate, &ptr->vpid, &ptr->apid1,
|
|
182 &ptr->tpid, &ptr->ca, &ptr->progid);
|
|
183 ptr->pol = toupper(ptr->pol);
|
|
184 ptr->freq *= 1000UL;
|
|
185 ptr->srate *= 1000UL;
|
|
186 ptr->tone = -1;
|
|
187 mp_msg(MSGT_DEMUX, MSGL_V,
|
|
188 "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",
|
|
189 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);
|
|
190 }
|
9610
|
191
|
10560
|
192
|
|
193 if((type == TUNER_TER) || (type == TUNER_CBL))
|
|
194 {
|
9610
|
195 if(! strcmp(inv, "INVERSION_ON"))
|
|
196 ptr->inv = INVERSION_ON;
|
|
197 else if(! strcmp(inv, "INVERSION_OFF"))
|
|
198 ptr->inv = INVERSION_OFF;
|
|
199 else
|
|
200 ptr->inv = INVERSION_AUTO;
|
|
201
|
|
202
|
|
203 if(! strcmp(cr, "FEC_1_2"))
|
|
204 ptr->cr =FEC_1_2;
|
|
205 else if(! strcmp(cr, "FEC_2_3"))
|
|
206 ptr->cr =FEC_2_3;
|
|
207 else if(! strcmp(cr, "FEC_3_4"))
|
|
208 ptr->cr =FEC_3_4;
|
|
209 #ifdef HAVE_DVB_HEAD
|
|
210 else if(! strcmp(cr, "FEC_4_5"))
|
|
211 ptr->cr =FEC_4_5;
|
|
212 else if(! strcmp(cr, "FEC_6_7"))
|
|
213 ptr->cr =FEC_6_7;
|
|
214 else if(! strcmp(cr, "FEC_8_9"))
|
|
215 ptr->cr =FEC_8_9;
|
|
216 #endif
|
|
217 else if(! strcmp(cr, "FEC_5_6"))
|
|
218 ptr->cr =FEC_5_6;
|
|
219 else if(! strcmp(cr, "FEC_7_8"))
|
|
220 ptr->cr =FEC_7_8;
|
|
221 else if(! strcmp(cr, "FEC_NONE"))
|
|
222 ptr->cr =FEC_NONE;
|
|
223 else ptr->cr =FEC_AUTO;
|
|
224
|
|
225 if(! strcmp(mod, "QAM_128"))
|
|
226 ptr->mod = QAM_128;
|
|
227 else if(! strcmp(mod, "QAM_256"))
|
|
228 ptr->mod = QAM_256;
|
|
229 else if(! strcmp(mod, "QAM_64"))
|
|
230 ptr->mod = QAM_64;
|
|
231 else if(! strcmp(mod, "QAM_32"))
|
|
232 ptr->mod = QAM_32;
|
|
233 else if(! strcmp(mod, "QAM_16"))
|
|
234 ptr->mod = QAM_16;
|
10560
|
235 //else ptr->mod = QPSK;
|
|
236 }
|
|
237
|
|
238
|
|
239 if(type == TUNER_TER)
|
|
240 {
|
|
241 if(! strcmp(bw, "BANDWIDTH_6_MHZ"))
|
|
242 ptr->bw = BANDWIDTH_6_MHZ;
|
|
243 else if(! strcmp(bw, "BANDWIDTH_7_MHZ"))
|
|
244 ptr->bw = BANDWIDTH_7_MHZ;
|
|
245 else if(! strcmp(bw, "BANDWIDTH_8_MHZ"))
|
|
246 ptr->bw = BANDWIDTH_8_MHZ;
|
9610
|
247
|
|
248
|
|
249 if(! strcmp(transm, "TRANSMISSION_MODE_2K"))
|
|
250 ptr->trans = TRANSMISSION_MODE_2K;
|
|
251 else if(! strcmp(transm, "TRANSMISSION_MODE_8K"))
|
|
252 ptr->trans = TRANSMISSION_MODE_8K;
|
|
253
|
10560
|
254
|
9610
|
255 if(! strcmp(gi, "GUARD_INTERVAL_1_32"))
|
|
256 ptr->gi = GUARD_INTERVAL_1_32;
|
|
257 else if(! strcmp(gi, "GUARD_INTERVAL_1_16"))
|
|
258 ptr->gi = GUARD_INTERVAL_1_16;
|
|
259 else if(! strcmp(gi, "GUARD_INTERVAL_1_8"))
|
|
260 ptr->gi = GUARD_INTERVAL_1_8;
|
|
261 else ptr->gi = GUARD_INTERVAL_1_4;
|
|
262 }
|
|
263
|
|
264 list->NUM_CHANNELS++;
|
|
265 row_count++;
|
|
266 }
|
|
267
|
|
268 fclose(f);
|
10560
|
269 list->current = 0;
|
9610
|
270 return list;
|
|
271 }
|
|
272
|
|
273
|
|
274
|
10560
|
275 static int dvb_streaming_read(stream_t *stream, char *buffer, int size)
|
9610
|
276 {
|
|
277 struct pollfd pfds[1];
|
10560
|
278 int pos=0, tries, rk;
|
|
279 int fd = stream->fd;
|
|
280 dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
|
9610
|
281
|
10560
|
282 mp_msg(MSGT_DEMUX, MSGL_V, "dvb_streaming_read(%d)\n", size);
|
9610
|
283
|
10560
|
284 if(priv->retry)
|
|
285 tries = 5;
|
|
286 else
|
|
287 tries = 1;
|
9610
|
288 while(pos < size)
|
|
289 {
|
10560
|
290 pfds[0].fd = fd;
|
|
291 pfds[0].events = POLLIN | POLLPRI;
|
9610
|
292
|
10560
|
293 poll(pfds, 1, 500);
|
|
294 rk = size - pos;
|
|
295 if((rk = read(fd, &buffer[pos], rk)) > 0)
|
|
296 {
|
|
297 pos += rk;
|
|
298 mp_msg(MSGT_DEMUX, MSGL_V, "ret (%d) bytes\n", pos);
|
|
299 }
|
|
300 else
|
|
301 {
|
|
302 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);
|
|
303 if(--tries > 0)
|
|
304 {
|
|
305 errno = 0;
|
|
306 //reset_demuxers(priv);
|
|
307 continue;
|
|
308 }
|
|
309 else
|
|
310 {
|
|
311 errno = 0;
|
|
312 break;
|
|
313 }
|
|
314 }
|
|
315 }
|
9610
|
316
|
10560
|
317 if(! pos)
|
|
318 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_streaming_read, return %d bytes\n", pos);
|
9610
|
319
|
|
320 return pos;
|
|
321 }
|
|
322
|
|
323
|
10560
|
324 static int reset_demuxers(dvb_priv_t *priv)
|
9610
|
325 {
|
10560
|
326 dvb_channel_t *channel;
|
|
327 dvb_channels_list *list = priv->list;
|
|
328
|
|
329 channel = &(list->channels[list->current]);
|
|
330
|
|
331 if(priv->is_on) //the fds are already open and we have to stop the demuxers
|
|
332 {
|
|
333 dvb_demux_stop(priv->demux_fd[0]);
|
|
334 dvb_demux_stop(priv->demux_fd[1]);
|
|
335 }
|
|
336
|
|
337 if(channel->vpid)
|
|
338 if(! dvb_set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_VIDEO))
|
|
339 return 0;
|
|
340 //dvb_demux_start(priv->demux_fd[0]);
|
|
341
|
|
342 if(channel->apid1)
|
|
343 if(! dvb_set_ts_filt(priv->demux_fd[1], channel->apid1, DMX_PES_AUDIO))
|
|
344 return 0;
|
|
345
|
|
346 printf("RESET DEMUXERS SUCCEDED, errno=%d\n\n\n", errno);
|
|
347 }
|
|
348
|
|
349
|
|
350 int dvb_set_channel(dvb_priv_t *priv, int n)
|
|
351 {
|
|
352 dvb_channels_list *list;
|
|
353 dvb_channel_t *channel;
|
|
354 int do_tuning;
|
|
355 stream_t *stream = (stream_t*) priv->stream;
|
|
356 char buf[4096];
|
9610
|
357
|
10560
|
358 if(priv->is_on) //the fds are already open and we have to stop the demuxers
|
|
359 {
|
|
360 dvb_demux_stop(priv->demux_fd[0]);
|
|
361 dvb_demux_stop(priv->demux_fd[1]);
|
|
362 priv->retry = 0;
|
|
363 while(stream_read(stream, buf, 4096)); //empty both the stream's and driver's buffer
|
|
364 }
|
|
365
|
|
366 priv->retry = 1;
|
|
367 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: channel %d\n", n);
|
|
368 list = priv->list;
|
|
369 if(list == NULL)
|
|
370 {
|
|
371 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: LIST NULL PTR, quit\n");
|
|
372 return 0;
|
|
373 }
|
|
374
|
|
375 if((n > list->NUM_CHANNELS) || (n < 0))
|
|
376 {
|
|
377 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_set_channel: INVALID CHANNEL NUMBER: %d, abort\n", n);
|
|
378 return 0;
|
|
379 }
|
9610
|
380
|
10560
|
381 list->current = n;
|
|
382 channel = &(list->channels[list->current]);
|
|
383 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_SET_CHANNEL: new channel name=%s\n", channel->name);
|
|
384
|
|
385 switch(priv->tuner_type)
|
|
386 {
|
|
387 case TUNER_SAT:
|
|
388 sprintf(priv->new_tuning, "%d|%09d|%09d|%d|%c", priv->card, channel->freq, channel->srate, channel->diseqc, channel->pol);
|
|
389 break;
|
9610
|
390
|
10560
|
391 case TUNER_TER:
|
|
392 sprintf(priv->new_tuning, "%d|%09d|%d|%d|%d|%d|%d|%d", priv->card, channel->freq, channel->inv,
|
|
393 channel->bw, channel->cr, channel->mod, channel->trans, channel->gi);
|
|
394 break;
|
|
395
|
|
396 case TUNER_CBL:
|
|
397 sprintf(priv->new_tuning, "%d|%09d|%d|%d|%d|%d", priv->card, channel->freq, channel->inv, channel->srate,
|
|
398 channel->cr, channel->mod);
|
|
399 break;
|
|
400 }
|
|
401
|
|
402
|
9610
|
403
|
10560
|
404 if(strcmp(priv->prev_tuning, priv->new_tuning))
|
|
405 {
|
|
406 mp_msg(MSGT_DEMUX, MSGL_V, "DIFFERENT TUNING THAN THE PREVIOUS: %s -> %s\n", priv->prev_tuning, priv->new_tuning);
|
|
407 strcpy(priv->prev_tuning, priv->new_tuning);
|
|
408 do_tuning = 1;
|
|
409 }
|
|
410 else
|
|
411 {
|
|
412 mp_msg(MSGT_DEMUX, MSGL_V, "SAME TUNING, NO TUNING\n");
|
|
413 do_tuning = 0;
|
|
414 }
|
|
415
|
|
416 stream->eof=1;
|
|
417 stream_reset(stream);
|
|
418
|
9610
|
419
|
10560
|
420 if(do_tuning)
|
|
421 if (! dvb_tune(priv, channel->freq, channel->pol, channel->srate, channel->diseqc, channel->tone,
|
|
422 channel->inv, channel->mod, channel->gi, channel->trans, channel->bw, channel->cr))
|
|
423 return 0;
|
|
424
|
|
425
|
|
426 priv->is_on = 1;
|
|
427
|
|
428 //sets demux filters and restart the stream
|
|
429 if(channel->vpid)
|
|
430 if(! dvb_set_ts_filt(priv->demux_fd[0], channel->vpid, DMX_PES_VIDEO))
|
|
431 return 0;
|
|
432 //dvb_demux_start(priv->demux_fd[0]);
|
|
433
|
|
434 if(channel->apid1)
|
|
435 if(! dvb_set_ts_filt(priv->demux_fd[1], channel->apid1, DMX_PES_AUDIO))
|
|
436 return 0;
|
|
437 //dvb_demux_start(priv->demux_fd[1]);
|
|
438
|
|
439 return 1;
|
|
440 }
|
|
441
|
|
442
|
9610
|
443
|
10560
|
444 int dvb_step_channel(dvb_priv_t *priv, int dir)
|
|
445 {
|
|
446 int new_current;
|
|
447 dvb_channels_list *list;
|
|
448
|
|
449 mp_msg(MSGT_DEMUX, MSGL_V, "DVB_STEP_CHANNEL dir %d\n", dir);
|
9610
|
450
|
10560
|
451 if(priv == NULL)
|
|
452 {
|
|
453 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL priv_ptr, quit\n");
|
|
454 return 0;
|
|
455 }
|
9610
|
456
|
10560
|
457 list = priv->list;
|
|
458 if(list == NULL)
|
|
459 {
|
|
460 mp_msg(MSGT_DEMUX, MSGL_ERR, "dvb_step_channel: NULL list_ptr, quit\n");
|
|
461 return 0;
|
|
462 }
|
9610
|
463
|
10560
|
464
|
|
465 if(dir == DVB_CHANNEL_HIGHER)
|
|
466 {
|
|
467 if(list->current == list->NUM_CHANNELS-1)
|
|
468 return 0;
|
9610
|
469
|
10560
|
470 new_current = list->current + 1;
|
|
471 }
|
|
472 else
|
|
473 {
|
|
474 if(list->current == 0)
|
|
475 return 0;
|
9610
|
476
|
10560
|
477 new_current = list->current - 1;
|
|
478 }
|
|
479
|
|
480 return dvb_set_channel(priv, new_current);
|
9610
|
481 }
|
|
482
|
|
483
|
10560
|
484
|
|
485
|
9610
|
486 extern char *get_path(char *);
|
|
487
|
10560
|
488 static void dvbin_close(stream_t *stream)
|
9610
|
489 {
|
10560
|
490 dvb_priv_t *priv = (dvb_priv_t *) stream->priv;
|
9610
|
491
|
10560
|
492 close(priv->dvr_fd);
|
|
493 close(priv->demux_fd[0]);
|
|
494 close(priv->demux_fd[1]);
|
|
495 priv->is_on = 0;
|
|
496 priv->stream = NULL;
|
|
497 if(dvb_list_ptr)
|
|
498 free(dvb_list_ptr);
|
|
499
|
|
500 dvb_list_ptr = NULL;
|
|
501 }
|
9610
|
502
|
|
503
|
10560
|
504 static int dvb_streaming_start(dvb_priv_t *priv, struct stream_priv_s *opts, int tuner_type)
|
|
505 {
|
|
506 int pids[MAX_CHANNELS], pestypes[MAX_CHANNELS], npids = 0, i;
|
|
507 dvb_channel_t *channel = NULL;
|
|
508 stream_t *stream = (stream_t*) priv->stream;
|
9610
|
509
|
|
510
|
|
511 mp_msg(MSGT_DEMUX, MSGL_INFO, "code taken from dvbstream for mplayer v0.4pre1 - (C) Dave Chapman 2001\n");
|
|
512 mp_msg(MSGT_DEMUX, MSGL_INFO, "Released under the GPL.\n");
|
|
513 mp_msg(MSGT_DEMUX, MSGL_INFO, "Latest version available from http://www.linuxstb.org/\n");
|
10560
|
514 mp_msg(MSGT_DEMUX, MSGL_V, "PROG: %s, CARD: %d, VID: %d, AID: %d, TYPE: %s, FILE: %s\n",
|
|
515 opts->prog, opts->card, opts->vid, opts->aid, opts->type, opts->file);
|
9610
|
516
|
10560
|
517 priv->is_on = 0;
|
9610
|
518
|
10560
|
519 if(strlen(opts->prog))
|
9610
|
520 {
|
10560
|
521 if(dvb_list_ptr != NULL)
|
|
522 {
|
|
523 i = 0;
|
|
524 while((channel == NULL) && i < dvb_list_ptr->NUM_CHANNELS)
|
|
525 {
|
|
526 if(! strcmp(dvb_list_ptr->channels[i].name, opts->prog))
|
|
527 channel = &(dvb_list_ptr->channels[i]);
|
9610
|
528
|
10560
|
529 i++;
|
|
530 }
|
9610
|
531
|
10560
|
532 if(channel != NULL)
|
|
533 {
|
|
534 dvb_list_ptr->current = i-1;
|
|
535 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,
|
|
536 channel->name, channel->vpid, channel->apid1,
|
|
537 channel->freq, channel->srate, channel->pol, channel->diseqc, channel->tone);
|
|
538 }
|
|
539 else if(opts->prog)
|
|
540 {
|
|
541 mp_msg(MSGT_DEMUX, MSGL_ERR, "\n\nDVBIN: no such channel \"%s\"\n\n", opts->prog);
|
|
542 return 0;
|
|
543 }
|
|
544 }
|
|
545 else
|
|
546 {
|
|
547 mp_msg(MSGT_DEMUX, MSGL_ERR, "DVBIN: chanel %s requested, but no channel list supplied %s\n", opts->prog);
|
|
548 return 0;
|
|
549 }
|
9610
|
550 }
|
|
551
|
|
552
|
10560
|
553
|
|
554 if(opts->vid > 0)
|
9610
|
555 {
|
10560
|
556 pids[npids] = opts->vid;
|
9610
|
557 }
|
|
558 else if(channel != NULL)
|
|
559 {
|
10560
|
560 pids[npids] = channel->vpid;
|
9610
|
561 }
|
|
562 pestypes[npids] = DMX_PES_VIDEO;
|
|
563 npids++;
|
|
564
|
10560
|
565 if(opts->aid > 0)
|
9610
|
566 {
|
10560
|
567 pids[npids] = opts->aid;
|
9610
|
568 }
|
|
569 else if(channel != NULL)
|
|
570 {
|
10560
|
571 pids[npids] = channel->apid1;
|
9610
|
572 }
|
|
573 pestypes[npids] = DMX_PES_AUDIO;
|
|
574 npids++;
|
|
575
|
|
576
|
|
577
|
10560
|
578 priv->demux_fd[0] = open(dvb_demuxdev[priv->card], O_RDWR);
|
|
579 if(priv->demux_fd[0] < 0)
|
9610
|
580 {
|
10560
|
581 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 0: %d\n", errno);
|
|
582 return 0;
|
9610
|
583 }
|
|
584
|
10560
|
585 priv->demux_fd[1] = open(dvb_demuxdev[priv->card], O_RDWR);
|
|
586 if(priv->demux_fd[1] < 0)
|
9610
|
587 {
|
10560
|
588 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DEMUX 1: %d\n", errno);
|
|
589 return 0;
|
9610
|
590 }
|
|
591
|
|
592
|
10560
|
593 priv->dvr_fd = open(dvb_dvrdev[priv->card], O_RDONLY| O_NONBLOCK);
|
|
594 if(priv->dvr_fd < 0)
|
9610
|
595 {
|
10560
|
596 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR OPENING DVR DEVICE %s: %d\n", dvb_dvrdev[priv->card], errno);
|
|
597 return 0;
|
9610
|
598 }
|
|
599
|
|
600
|
10560
|
601 strcpy(priv->prev_tuning, "");
|
|
602 if(!dvb_set_channel(priv, dvb_list_ptr->current))
|
|
603 {
|
|
604 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR, COULDN'T SET CHANNEL %i: ", dvb_list_ptr->current);
|
|
605 dvbin_close(stream);
|
|
606 return 0;
|
|
607 }
|
|
608
|
9610
|
609 stream->fd = priv->dvr_fd;
|
|
610
|
10560
|
611 mp_msg(MSGT_DEMUX, MSGL_V, "SUCCESSFUL EXIT from dvb_streaming_start\n");
|
9610
|
612
|
|
613 return 1;
|
|
614 }
|
|
615
|
|
616
|
10560
|
617
|
|
618
|
|
619 static int dvb_open(stream_t *stream, int mode, void *opts, int *file_format)
|
9610
|
620 {
|
10560
|
621 // I don't force the file format bacause, although it's almost always TS,
|
|
622 // there are some providers that stream an IP multicast with M$ Mpeg4 inside
|
|
623 struct stream_priv_s* p = (struct stream_priv_s*)opts;
|
|
624 char *name = NULL, *filename;
|
|
625 dvb_priv_t *priv;
|
|
626 int tuner_type;
|
|
627
|
|
628
|
|
629
|
|
630 if(mode != STREAM_READ)
|
|
631 return STREAM_UNSUPORTED;
|
|
632
|
|
633 stream->priv = (dvb_priv_t*) malloc(sizeof(dvb_priv_t));
|
|
634 if(stream->priv == NULL)
|
|
635 return STREAM_ERROR;
|
|
636
|
|
637 priv = (dvb_priv_t *)stream->priv;
|
|
638 priv->stream = stream;
|
|
639
|
|
640 name = malloc(sizeof(char)*128);
|
|
641
|
|
642 if(name == NULL)
|
|
643 {
|
|
644 mp_msg(MSGT_DEMUX, MSGL_ERR, "COULDN'T MALLOC SOME TMP MEMORY, EXIT!\n");
|
|
645 return STREAM_ERROR;
|
|
646 }
|
|
647
|
|
648 priv->card = p->card - 1;
|
|
649
|
|
650 if(!strncmp(p->type, "CBL", 3))
|
|
651 {
|
|
652 tuner_type = TUNER_CBL;
|
|
653 }
|
|
654 else if(!strncmp(p->type, "TER", 3))
|
|
655 {
|
|
656 tuner_type = TUNER_TER;
|
|
657 }
|
|
658 else if(!strncmp(p->type, "SAT", 3))
|
|
659 {
|
|
660 tuner_type = TUNER_SAT;
|
|
661 }
|
|
662 else
|
|
663 {
|
|
664 int t = dvb_get_tuner_type(priv);
|
|
665
|
|
666 if((t==TUNER_SAT) || (t==TUNER_TER) || (t==TUNER_CBL))
|
|
667 {
|
|
668 tuner_type = t;
|
|
669 }
|
|
670 }
|
|
671
|
|
672 priv->tuner_type = tuner_type;
|
|
673
|
|
674 mp_msg(MSGT_DEMUX, MSGL_V, "OPEN_DVB: prog=%s, card=%d, type=%d, vid=%d, aid=%d, file=%s\n",
|
|
675 p->prog, priv->card+1, priv->tuner_type, p->vid, p->aid, p->file);
|
|
676
|
|
677 if(dvb_list_ptr == NULL)
|
|
678 {
|
|
679 filename = get_path(p->file);
|
|
680 if(filename)
|
|
681 {
|
|
682 if((dvb_list_ptr = dvb_get_channels(filename, tuner_type)) == NULL)
|
|
683 mp_msg(MSGT_DEMUX, MSGL_ERR, "EMPTY CHANNELS LIST FROM FILE %s!\n", filename);
|
|
684 else
|
|
685 {
|
|
686 priv->list = dvb_list_ptr;
|
|
687 }
|
|
688 }
|
|
689 else
|
|
690 {
|
|
691 dvb_list_ptr = NULL;
|
|
692 mp_msg(MSGT_DEMUX, MSGL_WARN, "NO CHANNELS FILE FOUND!\n");
|
|
693 }
|
|
694 }
|
|
695 else
|
|
696 priv->list = dvb_list_ptr;
|
|
697
|
|
698
|
|
699 if(! strcmp(p->prog, ""))
|
|
700 {
|
|
701 if(dvb_list_ptr != NULL)
|
|
702 {
|
|
703 dvb_channel_t *channel;
|
|
704
|
|
705 channel = &(dvb_list_ptr->channels[dvb_list_ptr->current]);
|
|
706 p->prog = channel->name;
|
|
707 }
|
|
708 }
|
|
709
|
|
710
|
|
711 if(! dvb_streaming_start(priv, p, tuner_type))
|
|
712 {
|
|
713 free(stream->priv);
|
|
714 stream->priv = NULL;
|
|
715 return STREAM_ERROR;
|
|
716 }
|
|
717
|
|
718 stream->type = STREAMTYPE_DVB;
|
|
719 stream->fill_buffer = dvb_streaming_read;
|
|
720 stream->close = dvbin_close;
|
|
721 m_struct_free(&stream_opts, opts);
|
|
722
|
|
723 return STREAM_OK;
|
9610
|
724 }
|
10560
|
725
|
|
726
|
|
727
|
|
728 stream_info_t stream_info_dvb = {
|
|
729 "Dvb Input",
|
|
730 "dvbin",
|
|
731 "Nico",
|
|
732 "based on the code from ??? (probably Arpi)",
|
|
733 dvb_open,
|
|
734 { "dvb", NULL },
|
|
735 &stream_opts,
|
|
736 1 // Urls are an option string
|
|
737 };
|
|
738
|
|
739
|
|
740
|
|
741
|