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