Mercurial > mplayer.hg
comparison libmpdemux/dvb_tune.c @ 9610:76c6d8f1ebf5
this is a combo patch that:
1) adds an experimental TS demuxer to mplayer
2) adds an input (streaming) interface from DVB cards.
It compiles and runs with the following versions of the drivers:
dvb-kernel (HEAD) (with stock kernel 2.4.20) and 0.9.4 (with kernel 2.4.18)
patch by Nico <nsabbi@libero.it>
some cleanups, ts demuxer fixes by me
author | arpi |
---|---|
date | Sun, 16 Mar 2003 20:13:28 +0000 |
parents | |
children | 11826d9f90c7 |
comparison
equal
deleted
inserted
replaced
9609:bb8593ea37cb | 9610:76c6d8f1ebf5 |
---|---|
1 /* dvbtune - tune.c | |
2 | |
3 Copyright (C) Dave Chapman 2001,2002 | |
4 | |
5 This program is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU General Public License | |
7 as published by the Free Software Foundation; either version 2 | |
8 of the License, or (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 Or, point your browser to http://www.gnu.org/copyleft/gpl.html | |
19 | |
20 */ | |
21 | |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <ctype.h> | |
25 #include <sys/ioctl.h> | |
26 #include <sys/poll.h> | |
27 #include <unistd.h> | |
28 #include <fcntl.h> | |
29 #include <error.h> | |
30 #include "config.h" | |
31 | |
32 #ifdef HAVE_DVB_HEAD | |
33 #include <linux/dvb/dmx.h> | |
34 #include <linux/dvb/frontend.h> | |
35 char* frontenddev[4]={"/dev/dvb/adapter0/frontend0","/dev/dvb/adapter1/frontend0","/dev/dvb/adapter2/frontend0","/dev/dvb/adapter3/frontend0"}; | |
36 char* dvrdev[4]={"/dev/dvb/adapter0/dvr0","/dev/dvb/adapter1/dvr0","/dev/dvb/adapter2/dvr0","/dev/dvb/adapter3/dvr0"}; | |
37 char* demuxdev[4]={"/dev/dvb/adapter0/demux0","/dev/dvb/adapter1/demux0","/dev/dvb/adapter2/demux0","/dev/dvb/adapter3/demux0"}; | |
38 char* secdev[4]={"","","",""}; //UNUSED, ONLY FOR UNIFORMITY | |
39 #else | |
40 #include <ost/dmx.h> | |
41 #include <ost/sec.h> | |
42 #include <ost/frontend.h> | |
43 char* frontenddev[4]={"/dev/ost/frontend0","/dev/ost/frontend1","/dev/ost/frontend2","/dev/ost/frontend3"}; | |
44 char* dvrdev[4]={"/dev/ost/dvr0","/dev/ost/dvr1","/dev/ost/dvr2","/dev/ost/dvr3"}; | |
45 char* secdev[4]={"/dev/ost/sec0","/dev/ost/sec1","/dev/ost/sec2","/dev/ost/sec3"}; | |
46 char* demuxdev[4]={"/dev/ost/demux0","/dev/ost/demux1","/dev/ost/demux2","/dev/ost/demux3"}; | |
47 #endif | |
48 | |
49 #include "dvbin.h" | |
50 #include "dvb_defaults.h" | |
51 #include "../mp_msg.h" | |
52 | |
53 | |
54 extern int card; | |
55 | |
56 int open_fe(int* fd_frontend, int* fd_sec) | |
57 { | |
58 if((*fd_frontend = open(frontenddev[card], O_RDWR)) < 0) | |
59 { | |
60 perror("ERROR IN OPENING FRONTEND DEVICE: "); | |
61 return -1; | |
62 } | |
63 #ifdef HAVE_DVB_HEAD | |
64 fd_sec=0; | |
65 #else | |
66 if (fd_sec != 0) | |
67 { | |
68 if((*fd_sec = open(secdev[card], O_RDWR)) < 0) | |
69 { | |
70 perror("ERROR IN OPENING SEC DEVICE: "); | |
71 return -1; | |
72 } | |
73 } | |
74 #endif | |
75 return 1; | |
76 } | |
77 | |
78 | |
79 | |
80 int set_ts_filt(int fd, uint16_t pid, dmx_pes_type_t pestype) | |
81 { | |
82 int i; | |
83 struct dmx_pes_filter_params pesFilterParams; | |
84 | |
85 pesFilterParams.pid = pid; | |
86 pesFilterParams.input = DMX_IN_FRONTEND; | |
87 pesFilterParams.output = DMX_OUT_TS_TAP; | |
88 #ifdef HAVE_DVB_HEAD | |
89 pesFilterParams.pes_type = pestype; | |
90 #else | |
91 pesFilterParams.pesType = pestype; | |
92 #endif | |
93 | |
94 //pesFilterParams.pesType = pestype; | |
95 | |
96 pesFilterParams.flags = DMX_IMMEDIATE_START; | |
97 | |
98 if ((i = ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams)) < 0) | |
99 { | |
100 mp_msg(MSGT_DEMUX, MSGL_DBG2, "ERROR IN SETTING DMX_FILTER %i: ", pid); | |
101 } | |
102 | |
103 mp_msg(MSGT_DEMUX, MSGL_V, "SET PES FILTER ON PID %d, RESULT: %d\n", pid, i ); | |
104 return 1; | |
105 } | |
106 | |
107 | |
108 int demux_stop(int fd) | |
109 { | |
110 int i; | |
111 i = ioctl(fd, DMX_STOP); | |
112 | |
113 mp_msg(MSGT_DEMUX, MSGL_DBG2, "STOPPING FD: %d, RESULT: %d\n", fd, i); | |
114 | |
115 return (i==0); | |
116 } | |
117 | |
118 | |
119 | |
120 void make_nonblock(int f) | |
121 { | |
122 int oldflags; | |
123 | |
124 if ((oldflags=fcntl(f, F_GETFL, 0)) < 0) | |
125 { | |
126 perror("ERROR IN F_GETFL"); | |
127 } | |
128 | |
129 oldflags|=O_NONBLOCK; | |
130 if (fcntl(f, F_SETFL, oldflags) < 0) | |
131 { | |
132 perror("F_SETFL"); | |
133 } | |
134 } | |
135 | |
136 | |
137 static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone, | |
138 fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate, | |
139 fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth); | |
140 | |
141 | |
142 //int dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone) | |
143 dvb_tune(dvb_priv_t *priv, int freq, char pol, int srate, int diseqc, int tone, | |
144 fe_spectral_inversion_t specInv, fe_modulation_t modulation, fe_guard_interval_t guardInterval, | |
145 fe_transmit_mode_t TransmissionMode, fe_bandwidth_t bandWidth, fe_code_rate_t HP_CodeRate) | |
146 { | |
147 mp_msg(MSGT_DEMUX, MSGL_DBG2, "dvb_tune con Freq: %lu, pol: %c, srate: %lu, diseqc %d, tone %d\n", freq, pol, srate, diseqc, tone); | |
148 /* INPUT: frequency, polarization, srate */ | |
149 if(freq > 100000000) | |
150 { | |
151 if(open_fe(&(priv->fe_fd), 0)) | |
152 { | |
153 //tune_it(fd_frontend, 0, freq, 0, 0, tone, specInv, diseqc,modulation,HP_CodeRate,TransmissionMode,guardInterval,bandWidth); | |
154 tune_it(priv->fe_fd, 0, freq, 0, 0, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth); | |
155 | |
156 close(priv->fe_fd); | |
157 } | |
158 else | |
159 return 0; | |
160 } | |
161 else if ((freq != 0) && (pol != 0) && (srate != 0)) | |
162 { | |
163 if (open_fe(&(priv->fe_fd), &(priv->sec_fd))) | |
164 { | |
165 tune_it(priv->fe_fd, priv->sec_fd, freq, srate, pol, tone, specInv, diseqc, modulation, HP_CodeRate, TransmissionMode, guardInterval, bandWidth); | |
166 close(priv->fe_fd); | |
167 close(priv->sec_fd); | |
168 } | |
169 else | |
170 return 0; | |
171 } | |
172 | |
173 priv->channel.freq = freq; | |
174 priv->channel.srate = srate; | |
175 priv->channel.pol = pol; | |
176 priv->channel.diseqc = diseqc; | |
177 priv->channel.tone = tone; | |
178 priv->channel.inv = specInv; | |
179 priv->channel.mod = modulation; | |
180 priv->channel.gi = guardInterval; | |
181 priv->channel.trans = TransmissionMode; | |
182 priv->channel.bw = bandWidth; | |
183 priv->channel.cr = HP_CodeRate; | |
184 | |
185 return 1; | |
186 } | |
187 | |
188 | |
189 | |
190 | |
191 | |
192 #ifndef HAVE_DVB_HEAD | |
193 static int OSTSelftest(int fd) | |
194 { | |
195 int ans; | |
196 | |
197 if ((ans = ioctl(fd, FE_SELFTEST,0) < 0)) | |
198 { | |
199 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE SELF TEST: "); | |
200 return -1; | |
201 } | |
202 | |
203 return 0; | |
204 } | |
205 | |
206 static int OSTSetPowerState(int fd, uint32_t state) | |
207 { | |
208 int ans; | |
209 | |
210 if ((ans = ioctl(fd,FE_SET_POWER_STATE,state) < 0)) | |
211 { | |
212 mp_msg(MSGT_DEMUX, MSGL_ERR, "OST SET POWER STATE: "); | |
213 return -1; | |
214 } | |
215 | |
216 return 0; | |
217 } | |
218 | |
219 static int OSTGetPowerState(int fd, uint32_t *state) | |
220 { | |
221 int ans; | |
222 | |
223 if ((ans = ioctl(fd,FE_GET_POWER_STATE,state) < 0)) | |
224 { | |
225 mp_msg(MSGT_DEMUX, MSGL_ERR, "OST GET POWER STATE: "); | |
226 return -1; | |
227 } | |
228 | |
229 switch(*state) | |
230 { | |
231 case FE_POWER_ON: | |
232 mp_msg(MSGT_DEMUX, MSGL_V, "POWER ON (%d)\n",*state); | |
233 break; | |
234 case FE_POWER_STANDBY: | |
235 mp_msg(MSGT_DEMUX, MSGL_V, "POWER STANDBY (%d)\n",*state); | |
236 break; | |
237 case FE_POWER_SUSPEND: | |
238 mp_msg(MSGT_DEMUX, MSGL_V, "POWER SUSPEND (%d)\n",*state); | |
239 break; | |
240 case FE_POWER_OFF: | |
241 mp_msg(MSGT_DEMUX, MSGL_V, "POWER OFF (%d)\n",*state); | |
242 break; | |
243 default: | |
244 mp_msg(MSGT_DEMUX, MSGL_V, "unknown (%d)\n",*state); | |
245 break; | |
246 } | |
247 | |
248 return 0; | |
249 } | |
250 | |
251 | |
252 static int SecGetStatus (int fd, struct secStatus *state) | |
253 { | |
254 int ans; | |
255 | |
256 if ((ans = ioctl(fd, SEC_GET_STATUS, state) < 0)) | |
257 { | |
258 mp_msg(MSGT_DEMUX, MSGL_ERR, ("SEC GET STATUS: ")); | |
259 return -1; | |
260 } | |
261 | |
262 switch (state->busMode) | |
263 { | |
264 case SEC_BUS_IDLE: | |
265 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: IDLE (%d)\n",state->busMode); | |
266 break; | |
267 case SEC_BUS_BUSY: | |
268 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: BUSY (%d)\n",state->busMode); | |
269 break; | |
270 case SEC_BUS_OFF: | |
271 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: OFF (%d)\n",state->busMode); | |
272 break; | |
273 case SEC_BUS_OVERLOAD: | |
274 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: OVERLOAD (%d)\n",state->busMode); | |
275 break; | |
276 default: | |
277 mp_msg(MSGT_DEMUX, MSGL_V, "SEC BUS MODE: unknown (%d)\n",state->busMode); | |
278 break; | |
279 } | |
280 | |
281 switch (state->selVolt) | |
282 { | |
283 case SEC_VOLTAGE_OFF: | |
284 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: OFF (%d)\n",state->selVolt); | |
285 break; | |
286 case SEC_VOLTAGE_LT: | |
287 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: LT (%d)\n",state->selVolt); | |
288 break; | |
289 case SEC_VOLTAGE_13: | |
290 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 13 (%d)\n",state->selVolt); | |
291 break; | |
292 case SEC_VOLTAGE_13_5: | |
293 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 13.5 (%d)\n",state->selVolt); | |
294 break; | |
295 case SEC_VOLTAGE_18: | |
296 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 18 (%d)\n",state->selVolt); | |
297 break; | |
298 case SEC_VOLTAGE_18_5: | |
299 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: 18.5 (%d)\n",state->selVolt); | |
300 break; | |
301 default: | |
302 mp_msg(MSGT_DEMUX, MSGL_V, "SEC VOLTAGE: unknown (%d)\n",state->selVolt); | |
303 break; | |
304 } | |
305 | |
306 mp_msg(MSGT_DEMUX, MSGL_V, "SEC CONT TONE: %s\n", (state->contTone == SEC_TONE_ON ? "ON" : "OFF")); | |
307 return 0; | |
308 } | |
309 | |
310 #endif | |
311 | |
312 static void print_status(fe_status_t festatus) | |
313 { | |
314 mp_msg(MSGT_DEMUX, MSGL_V, "FE_STATUS:"); | |
315 if (festatus & FE_HAS_SIGNAL) mp_msg(MSGT_DEMUX, MSGL_V," FE_HAS_SIGNAL"); | |
316 #ifdef HAVE_DVB_HEAD | |
317 if (festatus & FE_TIMEDOUT) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TIMEDOUT"); | |
318 #else | |
319 if (festatus & FE_HAS_POWER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_POWER"); | |
320 if (festatus & FE_SPECTRUM_INV) mp_msg(MSGT_DEMUX, MSGL_V, " FE_SPECTRUM_INV"); | |
321 if (festatus & FE_TUNER_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TUNER_HAS_LOCK"); | |
322 #endif | |
323 if (festatus & FE_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_LOCK"); | |
324 if (festatus & FE_HAS_CARRIER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_CARRIER"); | |
325 if (festatus & FE_HAS_VITERBI) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_VITERBI"); | |
326 if (festatus & FE_HAS_SYNC) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SYNC"); | |
327 mp_msg(MSGT_DEMUX, MSGL_V, "\n"); | |
328 } | |
329 | |
330 | |
331 #ifdef HAVE_DVB_HEAD | |
332 static int check_status(int fd_frontend,struct dvb_frontend_parameters* feparams,int tone) | |
333 { | |
334 int i,res; | |
335 int32_t strength; | |
336 fe_status_t festatus; | |
337 struct dvb_frontend_event event; | |
338 struct dvb_frontend_info fe_info; | |
339 struct pollfd pfd[1]; | |
340 | |
341 if (ioctl(fd_frontend,FE_SET_FRONTEND,feparams) < 0) | |
342 { | |
343 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR tuning channel\n"); | |
344 return -1; | |
345 } | |
346 | |
347 pfd[0].fd = fd_frontend; | |
348 pfd[0].events = POLLIN; | |
349 | |
350 event.status=0; | |
351 while (((event.status & FE_TIMEDOUT)==0) && ((event.status & FE_HAS_LOCK)==0)) | |
352 { | |
353 mp_msg(MSGT_DEMUX, MSGL_V, "polling....\n"); | |
354 if (poll(pfd,1,10000)) | |
355 { | |
356 if (pfd[0].revents & POLLIN) | |
357 { | |
358 mp_msg(MSGT_DEMUX, MSGL_V, "Getting frontend event\n"); | |
359 if ( ioctl(fd_frontend, FE_GET_EVENT, &event) < 0) | |
360 { | |
361 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_EVENT"); | |
362 return -1; | |
363 } | |
364 } | |
365 print_status(event.status); | |
366 } | |
367 } | |
368 | |
369 if (event.status & FE_HAS_LOCK) | |
370 { | |
371 switch(fe_info.type) | |
372 { | |
373 case FE_OFDM: | |
374 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.parameters.frequency); | |
375 break; | |
376 case FE_QPSK: | |
377 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",(unsigned int)((event.parameters.frequency)+(tone==SEC_TONE_OFF ? LOF1 : LOF2))); | |
378 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate); | |
379 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.parameters.u.qpsk.fec_inner); | |
380 mp_msg(MSGT_DEMUX, MSGL_V, "\n"); | |
381 break; | |
382 case FE_QAM: | |
383 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.parameters.frequency); | |
384 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.parameters.u.qpsk.symbol_rate); | |
385 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.parameters.u.qpsk.fec_inner); | |
386 break; | |
387 default: | |
388 break; | |
389 } | |
390 | |
391 strength=0; | |
392 ioctl(fd_frontend,FE_READ_BER,&strength); | |
393 mp_msg(MSGT_DEMUX, MSGL_V, "Bit error rate: %d\n",strength); | |
394 | |
395 strength=0; | |
396 ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength); | |
397 mp_msg(MSGT_DEMUX, MSGL_V, "Signal strength: %d\n",strength); | |
398 | |
399 strength=0; | |
400 ioctl(fd_frontend,FE_READ_SNR,&strength); | |
401 mp_msg(MSGT_DEMUX, MSGL_V, "SNR: %d\n",strength); | |
402 | |
403 festatus=0; | |
404 ioctl(fd_frontend,FE_READ_STATUS,&festatus); | |
405 print_status(festatus); | |
406 } | |
407 else | |
408 { | |
409 mp_msg(MSGT_DEMUX, MSGL_V, "Not able to lock to the signal on the given frequency\n"); | |
410 return -1; | |
411 } | |
412 return 0; | |
413 } | |
414 | |
415 #else | |
416 | |
417 static int check_status(int fd_frontend,FrontendParameters* feparams,int tone) | |
418 { | |
419 int i,res; | |
420 int32_t strength; | |
421 fe_status_t festatus; | |
422 FrontendEvent event; | |
423 FrontendInfo fe_info; | |
424 struct pollfd pfd[1]; | |
425 | |
426 i = 0; res = -1; | |
427 while ((i < 3) && (res < 0)) | |
428 { | |
429 if (ioctl(fd_frontend,FE_SET_FRONTEND,feparams) < 0) | |
430 { | |
431 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR tuning channel\n"); | |
432 return -1; | |
433 } | |
434 | |
435 pfd[0].fd = fd_frontend; | |
436 pfd[0].events = POLLIN; | |
437 | |
438 if (poll(pfd,1,10000)) | |
439 { | |
440 if (pfd[0].revents & POLLIN) | |
441 { | |
442 mp_msg(MSGT_DEMUX, MSGL_V, "Getting frontend event\n"); | |
443 if ( ioctl(fd_frontend, FE_GET_EVENT, &event) < 0) | |
444 { | |
445 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_EVENT"); | |
446 return -1; | |
447 } | |
448 mp_msg(MSGT_DEMUX, MSGL_V, "Received "); | |
449 switch(event.type) | |
450 { | |
451 case FE_UNEXPECTED_EV: | |
452 mp_msg(MSGT_DEMUX, MSGL_V, "unexpected event\n"); | |
453 res = -1; | |
454 break; | |
455 | |
456 case FE_FAILURE_EV: | |
457 mp_msg(MSGT_DEMUX, MSGL_V, "failure event\n"); | |
458 res = -1; | |
459 break; | |
460 | |
461 case FE_COMPLETION_EV: | |
462 mp_msg(MSGT_DEMUX, MSGL_V, "completion event\n"); | |
463 res = 0; | |
464 break; | |
465 } | |
466 } | |
467 i++; | |
468 } | |
469 } | |
470 | |
471 if (res > 0) | |
472 switch (event.type) | |
473 { | |
474 case FE_UNEXPECTED_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_UNEXPECTED_EV\n"); | |
475 break; | |
476 case FE_COMPLETION_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_COMPLETION_EV\n"); | |
477 break; | |
478 case FE_FAILURE_EV: mp_msg(MSGT_DEMUX, MSGL_V, "FE_FAILURE_EV\n"); | |
479 break; | |
480 } | |
481 | |
482 if (event.type == FE_COMPLETION_EV) | |
483 { | |
484 switch(fe_info.type) | |
485 { | |
486 case FE_OFDM: | |
487 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.u.completionEvent.Frequency); | |
488 break; | |
489 | |
490 case FE_QPSK: | |
491 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",(unsigned int)((event.u.completionEvent.Frequency)+(tone==SEC_TONE_OFF ? LOF1 : LOF2))); | |
492 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.u.completionEvent.u.qpsk.SymbolRate); | |
493 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner); | |
494 mp_msg(MSGT_DEMUX, MSGL_V, "\n"); | |
495 break; | |
496 | |
497 case FE_QAM: | |
498 mp_msg(MSGT_DEMUX, MSGL_V, "Event: Frequency: %d\n",event.u.completionEvent.Frequency); | |
499 mp_msg(MSGT_DEMUX, MSGL_V, " SymbolRate: %d\n",event.u.completionEvent.u.qpsk.SymbolRate); | |
500 mp_msg(MSGT_DEMUX, MSGL_V, " FEC_inner: %d\n",event.u.completionEvent.u.qpsk.FEC_inner); | |
501 break; | |
502 | |
503 default: | |
504 break; | |
505 } | |
506 | |
507 strength=0; | |
508 ioctl(fd_frontend,FE_READ_BER,&strength); | |
509 mp_msg(MSGT_DEMUX, MSGL_V, "Bit error rate: %d\n",strength); | |
510 | |
511 strength=0; | |
512 ioctl(fd_frontend,FE_READ_SIGNAL_STRENGTH,&strength); | |
513 mp_msg(MSGT_DEMUX, MSGL_V, "Signal strength: %d\n",strength); | |
514 | |
515 strength=0; | |
516 ioctl(fd_frontend,FE_READ_SNR,&strength); | |
517 mp_msg(MSGT_DEMUX, MSGL_V, "SNR: %d\n",strength); | |
518 | |
519 festatus=0; | |
520 ioctl(fd_frontend,FE_READ_STATUS,&festatus); | |
521 | |
522 mp_msg(MSGT_DEMUX, MSGL_V, "FE_STATUS:"); | |
523 if (festatus & FE_HAS_POWER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_POWER"); | |
524 if (festatus & FE_HAS_SIGNAL) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SIGNAL"); | |
525 if (festatus & FE_SPECTRUM_INV) mp_msg(MSGT_DEMUX, MSGL_V, " FE_SPECTRUM_INV"); | |
526 if (festatus & FE_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_LOCK"); | |
527 if (festatus & FE_HAS_CARRIER) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_CARRIER"); | |
528 if (festatus & FE_HAS_VITERBI) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_VITERBI"); | |
529 if (festatus & FE_HAS_SYNC) mp_msg(MSGT_DEMUX, MSGL_V, " FE_HAS_SYNC"); | |
530 if (festatus & FE_TUNER_HAS_LOCK) mp_msg(MSGT_DEMUX, MSGL_V, " FE_TUNER_HAS_LOCK"); | |
531 mp_msg(MSGT_DEMUX, MSGL_V, "\n"); | |
532 } | |
533 else | |
534 { | |
535 mp_msg(MSGT_DEMUX, MSGL_V, "Not able to lock to the signal on the given frequency\n"); | |
536 return -1; | |
537 } | |
538 return 0; | |
539 } | |
540 #endif | |
541 | |
542 #ifdef HAVE_DVB_HEAD | |
543 | |
544 struct diseqc_cmd { | |
545 struct dvb_diseqc_master_cmd cmd; | |
546 uint32_t wait; | |
547 }; | |
548 | |
549 static void diseqc_send_msg(int fd, fe_sec_voltage_t v, struct diseqc_cmd *cmd, | |
550 fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b) | |
551 { | |
552 ioctl(fd, FE_SET_TONE, SEC_TONE_OFF); | |
553 ioctl(fd, FE_SET_VOLTAGE, v); | |
554 usleep(15 * 1000); | |
555 ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &cmd->cmd); | |
556 usleep(cmd->wait * 1000); | |
557 usleep(15 * 1000); | |
558 ioctl(fd, FE_DISEQC_SEND_BURST, b); | |
559 usleep(15 * 1000); | |
560 ioctl(fd, FE_SET_TONE, t); | |
561 } | |
562 | |
563 | |
564 | |
565 | |
566 /* digital satellite equipment control, | |
567 * specification is available from http://www.eutelsat.com/ | |
568 */ | |
569 static int head_diseqc(int secfd, int sat_no, int pol, int hi_lo) | |
570 { | |
571 struct diseqc_cmd cmd = { {{0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00}, 4}, 0 }; | |
572 | |
573 /* param: high nibble: reset bits, low nibble set bits, | |
574 * bits are: option, position, polarizaion, band | |
575 */ | |
576 cmd.cmd.msg[3] = | |
577 0xf0 | (((sat_no * 4) & 0x0f) | (hi_lo ? 1 : 0) | (pol ? 0 : 2)); | |
578 | |
579 diseqc_send_msg(secfd, pol ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18, | |
580 &cmd, hi_lo ? SEC_TONE_ON : SEC_TONE_OFF, | |
581 (sat_no / 4) % 2 ? SEC_MINI_B : SEC_MINI_A); | |
582 | |
583 return 1; | |
584 } | |
585 | |
586 #endif | |
587 | |
588 | |
589 static int tune_it(int fd_frontend, int fd_sec, unsigned int freq, unsigned int srate, char pol, int tone, | |
590 fe_spectral_inversion_t specInv, unsigned int diseqc, fe_modulation_t modulation, fe_code_rate_t HP_CodeRate, | |
591 fe_transmit_mode_t TransmissionMode, fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth) | |
592 { | |
593 int res; | |
594 #ifdef HAVE_DVB_HEAD | |
595 struct dvb_frontend_parameters feparams; | |
596 struct dvb_frontend_info fe_info; | |
597 fe_sec_voltage_t voltage; | |
598 #else | |
599 FrontendParameters feparams; | |
600 FrontendInfo fe_info; | |
601 secVoltage voltage; | |
602 struct secStatus sec_state; | |
603 #endif | |
604 | |
605 | |
606 mp_msg(MSGT_DEMUX, MSGL_V, "TUNE_IT, fd_frontend %d, fd_sec %d, freq %lu, srate %lu, pol %c, tone %i, specInv, diseqc %u, fe_modulation_t modulation,fe_code_rate_t HP_CodeRate, fe_transmit_mode_t TransmissionMode,fe_guard_interval_t guardInterval, fe_bandwidth_t bandwidth\n", | |
607 fd_frontend, fd_sec, freq, srate, pol, tone, diseqc); | |
608 | |
609 | |
610 if ( (res = ioctl(fd_frontend,FE_GET_INFO, &fe_info) < 0)) | |
611 { | |
612 mp_msg(MSGT_DEMUX, MSGL_ERR, "FE_GET_INFO: "); | |
613 return -1; | |
614 } | |
615 | |
616 | |
617 #ifdef HAVE_DVB_HEAD | |
618 mp_msg(MSGT_DEMUX, MSGL_V, "Using DVB card \"%s\"\n",fe_info.name); | |
619 #endif | |
620 | |
621 switch(fe_info.type) | |
622 { | |
623 case FE_OFDM: | |
624 #ifdef HAVE_DVB_HEAD | |
625 if (freq < 1000000) freq*=1000UL; | |
626 feparams.frequency=freq; | |
627 feparams.inversion=INVERSION_OFF; | |
628 feparams.u.ofdm.bandwidth=bandwidth; | |
629 feparams.u.ofdm.code_rate_HP=HP_CodeRate; | |
630 feparams.u.ofdm.code_rate_LP=LP_CODERATE_DEFAULT; | |
631 feparams.u.ofdm.constellation=modulation; | |
632 feparams.u.ofdm.transmission_mode=TransmissionMode; | |
633 feparams.u.ofdm.guard_interval=guardInterval; | |
634 feparams.u.ofdm.hierarchy_information=HIERARCHY_DEFAULT; | |
635 #else | |
636 if (freq < 1000000) freq*=1000UL; | |
637 feparams.Frequency=freq; | |
638 feparams.Inversion=INVERSION_OFF; | |
639 feparams.u.ofdm.bandWidth=bandwidth; | |
640 feparams.u.ofdm.HP_CodeRate=HP_CodeRate; | |
641 feparams.u.ofdm.LP_CodeRate=LP_CODERATE_DEFAULT; | |
642 feparams.u.ofdm.Constellation=modulation; | |
643 feparams.u.ofdm.TransmissionMode=TransmissionMode; | |
644 feparams.u.ofdm.guardInterval=guardInterval; | |
645 feparams.u.ofdm.HierarchyInformation=HIERARCHY_DEFAULT; | |
646 #endif | |
647 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-T (%s) to %d Hz\n",DVB_T_LOCATION,freq); | |
648 break; | |
649 case FE_QPSK: | |
650 #ifdef HAVE_DVB_HEAD | |
651 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-S to L-Band:%d, Pol:%c Srate=%d, 22kHz=%s\n",feparams.frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off"); | |
652 #else | |
653 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-S to L-Band:%d, Pol:%c Srate=%d, 22kHz=%s\n",feparams.Frequency,pol,srate,tone == SEC_TONE_ON ? "on" : "off"); | |
654 #endif | |
655 if ((pol=='h') || (pol=='H')) | |
656 { | |
657 voltage = SEC_VOLTAGE_18; | |
658 } | |
659 else | |
660 { | |
661 voltage = SEC_VOLTAGE_13; | |
662 } | |
663 #ifdef HAVE_DVB_HEAD | |
664 if (ioctl(fd_frontend,FE_SET_VOLTAGE,voltage) < 0) | |
665 { | |
666 #else | |
667 if (ioctl(fd_sec,SEC_SET_VOLTAGE,voltage) < 0) | |
668 { | |
669 #endif | |
670 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR setting voltage\n"); | |
671 } | |
672 | |
673 if (freq > 2200000) | |
674 { | |
675 // this must be an absolute frequency | |
676 if (freq < SLOF) | |
677 { | |
678 #ifdef HAVE_DVB_HEAD | |
679 feparams.frequency=(freq-LOF1); | |
680 #else | |
681 feparams.Frequency=(freq-LOF1); | |
682 #endif | |
683 if (tone < 0) tone = SEC_TONE_OFF; | |
684 } | |
685 else | |
686 { | |
687 #ifdef HAVE_DVB_HEAD | |
688 feparams.frequency=(freq-LOF2); | |
689 #else | |
690 feparams.Frequency=(freq-LOF2); | |
691 #endif | |
692 if (tone < 0) tone = SEC_TONE_ON; | |
693 } | |
694 } | |
695 else | |
696 { | |
697 // this is an L-Band frequency | |
698 #ifdef HAVE_DVB_HEAD | |
699 feparams.frequency=freq; | |
700 #else | |
701 feparams.Frequency=freq; | |
702 #endif | |
703 } | |
704 | |
705 #ifdef HAVE_DVB_HEAD | |
706 feparams.inversion=specInv; | |
707 feparams.u.qpsk.symbol_rate=srate; | |
708 feparams.u.qpsk.fec_inner=FEC_AUTO; | |
709 #else | |
710 feparams.Inversion=specInv; | |
711 feparams.u.qpsk.SymbolRate=srate; | |
712 feparams.u.qpsk.FEC_inner=FEC_AUTO; | |
713 #endif | |
714 | |
715 #ifdef HAVE_DVB_HEAD | |
716 if (ioctl(fd_frontend, FE_SET_TONE,tone) < 0) | |
717 { | |
718 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR setting tone\n"); | |
719 } | |
720 #else | |
721 if (ioctl(fd_sec, SEC_SET_TONE,tone) < 0) | |
722 { | |
723 mp_msg(MSGT_DEMUX, MSGL_ERR, "ERROR setting tone\n"); | |
724 } | |
725 #endif | |
726 | |
727 #ifdef HAVE_DVB_HEAD | |
728 //#warning DISEQC is unimplemented for HAVE_DVB_HEAD | |
729 if(diseqc > 0) | |
730 { | |
731 int ipol = (pol == 'V' ? 1 : 0); | |
732 int hiband = (freq >= SLOF); | |
733 | |
734 if(head_diseqc(fd_frontend, diseqc-1, ipol, hiband)) | |
735 { | |
736 mp_msg(MSGT_DEMUX, MSGL_V, "DISEQC SETTING SUCCEDED\n"); | |
737 } | |
738 else | |
739 { | |
740 mp_msg(MSGT_DEMUX, MSGL_V, "DISEQC SETTING FAILED\n"); | |
741 } | |
742 } | |
743 #else | |
744 if (diseqc > 0) | |
745 { | |
746 struct secCommand scmd; | |
747 struct secCmdSequence scmds; | |
748 | |
749 scmds.continuousTone = tone; | |
750 scmds.voltage = voltage; | |
751 /* | |
752 scmds.miniCommand = toneBurst ? SEC_MINI_B : SEC_MINI_A; | |
753 */ | |
754 scmds.miniCommand = SEC_MINI_NONE; | |
755 | |
756 scmd.type = 0; | |
757 scmds.numCommands = 1; | |
758 scmds.commands = &scmd; | |
759 | |
760 scmd.u.diseqc.addr = 0x10; | |
761 scmd.u.diseqc.cmd = 0x38; | |
762 scmd.u.diseqc.numParams = 1; | |
763 scmd.u.diseqc.params[0] = 0xf0 | | |
764 (((diseqc - 1) << 2) & 0x0c) | | |
765 (voltage==SEC_VOLTAGE_18 ? 0x02 : 0) | | |
766 (tone==SEC_TONE_ON ? 0x01 : 0); | |
767 | |
768 if (ioctl(fd_sec,SEC_SEND_SEQUENCE,&scmds) < 0) | |
769 { | |
770 mp_msg(MSGT_DEMUX, MSGL_ERR, "Error sending DisEqC"); | |
771 return -1; | |
772 } | |
773 } | |
774 #endif | |
775 break; | |
776 case FE_QAM: | |
777 mp_msg(MSGT_DEMUX, MSGL_V, "tuning DVB-C to %d, srate=%d\n",freq,srate); | |
778 #ifdef HAVE_DVB_HEAD | |
779 feparams.frequency=freq; | |
780 feparams.inversion=INVERSION_OFF; | |
781 feparams.u.qam.symbol_rate = srate; | |
782 feparams.u.qam.fec_inner = FEC_AUTO; | |
783 feparams.u.qam.modulation = QAM_64; | |
784 #else | |
785 feparams.Frequency=freq; | |
786 feparams.Inversion=INVERSION_OFF; | |
787 feparams.u.qam.SymbolRate = srate; | |
788 feparams.u.qam.FEC_inner = FEC_AUTO; | |
789 feparams.u.qam.QAM = QAM_64; | |
790 #endif | |
791 break; | |
792 default: | |
793 mp_msg(MSGT_DEMUX, MSGL_V, "Unknown FE type. Aborting\n"); | |
794 exit(-1); | |
795 } | |
796 usleep(100000); | |
797 | |
798 #ifndef HAVE_DVB_HEAD | |
799 if (fd_sec) SecGetStatus(fd_sec, &sec_state); | |
800 #endif | |
801 | |
802 return(check_status(fd_frontend,&feparams,tone)); | |
803 } |