]> git.sesse.net Git - vlc/blob - modules/access/dvb/dvb.c
2a6bfc7479995884c7c7459704b0692017fe0cbf
[vlc] / modules / access / dvb / dvb.c
1 /*****************************************************************************
2  * dvb.c : functions to control a DVB card under Linux with v4l2
3  *****************************************************************************
4  * Copyright (C) 1998-2003 VideoLAN
5  *
6  * Authors: Damien Lucas <nitrox@via.ecp.fr>
7  *          Johan Bilien <jobi@via.ecp.fr>
8  *          Jean-Paul Saman <saman@natlab.research.philips.com>
9  *          Christopher Ross <ross@natlab.research.philips.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    02111, USA.
24  *****************************************************************************/
25
26 #include <vlc/vlc.h>
27 #include <vlc/input.h>
28
29 #include <sys/ioctl.h>
30 #include <stdio.h>
31 #ifdef HAVE_ERRNO_H
32 #    include <string.h>
33 #    include <errno.h>
34 #endif
35
36 #ifdef HAVE_INTTYPES_H
37 #   include <inttypes.h>                                       /* int16_t .. */
38 #endif
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <fcntl.h>
42 #include <time.h>
43 #include <unistd.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <sys/poll.h>
47
48 /* DVB Card Drivers */
49 #include <linux/dvb/dmx.h>
50 #include <linux/dvb/frontend.h>
51
52 #include <linux/errno.h>
53
54 #include "dvb.h"
55
56 struct diseqc_cmd_t
57 {
58         struct dvb_diseqc_master_cmd cmd;
59         uint32_t wait;
60 };
61
62 struct diseqc_cmd_t switch_cmds[] =
63 {
64         { { { 0xe0, 0x10, 0x38, 0xf0, 0x00, 0x00 }, 4 }, 0 },
65         { { { 0xe0, 0x10, 0x38, 0xf2, 0x00, 0x00 }, 4 }, 0 },
66         { { { 0xe0, 0x10, 0x38, 0xf1, 0x00, 0x00 }, 4 }, 0 },
67         { { { 0xe0, 0x10, 0x38, 0xf3, 0x00, 0x00 }, 4 }, 0 },
68         { { { 0xe0, 0x10, 0x38, 0xf4, 0x00, 0x00 }, 4 }, 0 },
69         { { { 0xe0, 0x10, 0x38, 0xf6, 0x00, 0x00 }, 4 }, 0 },
70         { { { 0xe0, 0x10, 0x38, 0xf5, 0x00, 0x00 }, 4 }, 0 },
71         { { { 0xe0, 0x10, 0x38, 0xf7, 0x00, 0x00 }, 4 }, 0 },
72         { { { 0xe0, 0x10, 0x38, 0xf8, 0x00, 0x00 }, 4 }, 0 },
73         { { { 0xe0, 0x10, 0x38, 0xfa, 0x00, 0x00 }, 4 }, 0 },
74         { { { 0xe0, 0x10, 0x38, 0xf9, 0x00, 0x00 }, 4 }, 0 },
75         { { { 0xe0, 0x10, 0x38, 0xfb, 0x00, 0x00 }, 4 }, 0 },
76         { { { 0xe0, 0x10, 0x38, 0xfc, 0x00, 0x00 }, 4 }, 0 },
77         { { { 0xe0, 0x10, 0x38, 0xfe, 0x00, 0x00 }, 4 }, 0 },
78         { { { 0xe0, 0x10, 0x38, 0xfd, 0x00, 0x00 }, 4 }, 0 },
79         { { { 0xe0, 0x10, 0x38, 0xff, 0x00, 0x00 }, 4 }, 0 }
80 };
81
82 static int ioctl_CheckQPSK(input_thread_t * p_input, int front);
83
84 /*****************************************************************************
85  * ioctl_FrontendControl : commands the SEC device
86  *****************************************************************************/
87 int ioctl_FrontendControl(input_thread_t * p_input, int freq, int pol, int lnb_slof,
88                                                                           int diseqc, unsigned int u_adapter, unsigned int u_device)
89 {
90     struct dvb_diseqc_master_cmd  cmd;
91     fe_sec_tone_mode_t tone;
92     fe_sec_voltage_t voltage;
93     int frontend;
94           char front[] = FRONTEND;
95           int i_len;
96
97           i_len = sizeof(FRONTEND);
98                 if (snprintf(front, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
99                 {
100                   msg_Err(p_input, "snprintf() truncated string for FRONTEND" );
101                         front[sizeof(FRONTEND)] = '\0';
102     }
103
104           msg_Dbg(p_input, "Opening frontend %s",front);          
105     if((frontend = open(front,O_RDWR)) < 0)
106     {
107 #   ifdef HAVE_ERRNO_H
108                         msg_Err(p_input, "ioctl_FrontEndControl: Opening frontend failed (%s)",strerror(errno));
109 #   else
110                         msg_Err(p_input, "ioctl_FrontEndControl: Opening frontend failed");
111 #   endif
112         return -1;
113     }
114
115     /* Set the frequency of the transponder, taking into account the
116        local frequencies of the LNB */
117     tone = (freq<lnb_slof) ? SEC_TONE_OFF : SEC_TONE_ON;
118
119     /* Set the polarisation of the transponder by setting the correct
120        voltage on the universal LNB */
121     voltage = (pol) ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13;
122     
123     /* In case we have a DiSEqC, set it to the correct address */
124     cmd.msg[0] =0x0;  /* framing */
125     cmd.msg[1] =0x10; /* address */
126     cmd.msg[2] =0x38; /* command */
127     /* command parameters start at index 3 */
128     cmd.msg[3] = 0xF0 | ((diseqc * 4) & 0x0F);   
129     cmd.msg_len = 4;
130
131     /* Reset everything before sending. */
132 #ifdef HAVE_ERRNO_H 
133 #   define CHECK_IOCTL(X) if(X<0) \
134     { \
135         msg_Err( p_input, "InfoFrontend: ioctl failed (%s)", strerror(errno)); \
136         close(frontend); \
137         return -1; \
138     }
139 #else
140 #   define CHECK_IOCTL(X) if(X<0) \
141     { \
142         msg_Err( p_input, "InfoFrontend: ioctl failed"); \
143         close(frontend); \
144         return -1; \
145     }
146 #endif
147
148     CHECK_IOCTL(ioctl(frontend, FE_SET_TONE, SEC_TONE_OFF));   
149     CHECK_IOCTL(ioctl(frontend, FE_SET_VOLTAGE, voltage));
150     msleep(15);
151     
152     /* Send the data to the SEC device to prepare the LNB for tuning  */
153     CHECK_IOCTL(ioctl(frontend, FE_DISEQC_SEND_MASTER_CMD, &cmd));
154     msleep(15);
155     CHECK_IOCTL(ioctl(frontend, FE_DISEQC_SEND_BURST, &cmd));
156     msleep(15);
157     CHECK_IOCTL(ioctl(frontend, FE_SET_TONE, tone));
158 #undef CHECK_IOCTL
159
160     close(frontend);
161     return 0;
162 }
163
164 /*****************************************************************************
165  * ioctl_InfoFrontend : return information about given frontend
166  *****************************************************************************/
167 int ioctl_InfoFrontend(input_thread_t * p_input, struct dvb_frontend_info *info,
168                        unsigned int u_adapter, unsigned int u_device)
169 {
170     int front;
171     int ret;
172           char frontend[] = FRONTEND;
173           int i_len;
174
175           i_len = sizeof(FRONTEND);
176                 if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
177                 {
178                   msg_Err(p_input, "snprintf() truncated string for FRONTEND" );
179                         frontend[sizeof(FRONTEND)] = '\0';
180     }
181
182           msg_Dbg(p_input, "Opening device %s", frontend);
183     if((front = open(frontend,O_RDWR)) < 0)
184     {
185 #   ifdef HAVE_ERRNO_H
186                   msg_Err(p_input, "ioctl_InfoFrontEnd: opening device failed (%s)", strerror(errno));
187 #   else
188                   msg_Err(p_input, "ioctl_InfoFrontEnd: opening device failed");
189 #   endif
190       return -1;
191     }
192
193     /* Determine type of frontend */
194     if ((ret=ioctl(front, FE_GET_INFO, info)) < 0)
195     {
196         close(front);
197 #   ifdef HAVE_ERRNO_H
198         msg_Err(p_input, "ioctl FE_GET_INFO failed (%d) %s", ret, strerror(errno));
199 #   else
200         msg_Err(p_input, "ioctl FE_GET_INFO failed (%d)", ret);
201 #   endif
202         return -1;
203     }
204     msg_Dbg(p_input,  "Frontend Info:\tname = %s\n\t\tfrequency_min = %d\n\t\tfrequency_max = %d\n\t\tfrequency_stepsize = %d\n\t\tfrequency_tolerance = %d\n\t\tsymbol_rate_min = %d\n\t\tsymbol_rate_max = %d\n\t\tsymbol_rate_tolerance (ppm) = %d\n\t\tnotifier_delay (ms)= %d\n",
205                         info->name,
206                         info->frequency_min,
207                         info->frequency_max,
208                         info->frequency_stepsize,
209                         info->frequency_tolerance,
210                         info->symbol_rate_min,
211                         info->symbol_rate_max,
212                         info->symbol_rate_tolerance,
213                         info->notifier_delay );
214
215     close(front);
216     return 0;
217 }
218
219 int ioctl_DiseqcSendMsg (input_thread_t *p_input, int fd, fe_sec_voltage_t v, struct diseqc_cmd_t **cmd,
220                      fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
221 {
222     int err;
223
224         if ((err = ioctl(fd, FE_SET_TONE, SEC_TONE_OFF))<0)
225         {
226 #   ifdef HAVE_ERRNO_H
227                 msg_Err(p_input, "ioclt FE_SET_TONE failed, tone=%s (%d) %s", SEC_TONE_ON ? "on" : "off", err, strerror(errno));
228 #   else
229                   msg_Err(p_input, "ioclt FE_SET_TONE failed, tone=%s (%d)", SEC_TONE_ON ? "on" : "off", err);
230 #   endif
231                   return err;
232     }
233         if ((err = ioctl(fd, FE_SET_VOLTAGE, v))<0)
234         {
235 #   ifdef HAVE_ERRNO_H
236                   msg_Err(p_input, "ioclt FE_SET_VOLTAGE failed, voltage=%d (%d) %s", v, err, strerror(errno));
237 #   else
238                   msg_Err(p_input, "ioclt FE_SET_VOLTAGE failed, voltage=%d (%d)", v, err);
239 #   endif
240                   return err;
241     }
242
243         msleep(15);
244         while (*cmd)
245         {
246                 msg_Dbg(p_input, "msg: %02x %02x %02x %02x %02x %02x",
247                     (*cmd)->cmd.msg[0], (*cmd)->cmd.msg[1],
248                     (*cmd)->cmd.msg[2], (*cmd)->cmd.msg[3],
249                     (*cmd)->cmd.msg[4], (*cmd)->cmd.msg[5]);
250
251                 if ((err = ioctl(fd, FE_DISEQC_SEND_MASTER_CMD, &(*cmd)->cmd))<0)
252                 {
253 #       ifdef HAVE_ERRNO_H
254                           msg_Err(p_input, "ioclt FE_DISEQC_SEND_MASTER_CMD failed (%d) %s", err, strerror(errno));
255 #       else
256                           msg_Err(p_input, "ioclt FE_DISEQC_SEND_MASTER_CMD failed (%d)", err);
257 #       endif
258                         return err;
259         }
260
261                 msleep((*cmd)->wait);
262                 cmd++;
263         }
264
265         msleep(15);
266
267         if ((err = ioctl(fd, FE_DISEQC_SEND_BURST, b))<0)
268         {
269 #   ifdef HAVE_ERRNO_H
270                   msg_Err(p_input, "ioctl FE_DISEQC_SEND_BURST failed, burst=%d (%d) %s",b, err, strerror(errno));
271 #   else
272                   msg_Err(p_input, "ioctl FE_DISEQC_SEND_BURST failed, burst=%d (%d)",b, err);
273 #   endif
274       return err;
275     }
276         msleep(15);
277
278     if ((err = ioctl(fd, FE_SET_TONE, t))<0)
279     {
280 #   ifdef HAVE_ERRNO_H
281                   msg_Err(p_input, "ioctl FE_SET_TONE failed, tone=%d (%d) %s", t, err, strerror(errno));
282 #   else
283                   msg_Err(p_input, "ioctl FE_SET_TONE failed, tone=%d (%d)", t, err);
284 #   endif
285                   return err;
286         }
287         return err; 
288 }
289
290 int ioctl_SetupSwitch (input_thread_t *p_input, int frontend_fd, int switch_pos, int voltage_18, int hiband)
291 {
292     int ret;
293         struct diseqc_cmd_t *cmd[2] = { NULL, NULL };
294         int i = 4 * switch_pos + 2 * hiband + (voltage_18 ? 1 : 0);
295
296         msg_Dbg(p_input, "ioctl_SetupSwitch: switch pos %i, %sV, %sband",
297                 switch_pos, voltage_18 ? "18" : "13", hiband ? "hi" : "lo");
298         msg_Dbg(p_input, "ioctl_SetupSwitch: index %i", i);
299
300         if ((i < 0) || (i >= (int)(sizeof(switch_cmds)/sizeof(struct diseqc_cmd_t))))
301         return -EINVAL;
302
303         cmd[0] = &switch_cmds[i];
304
305         if ((ret = ioctl_DiseqcSendMsg (p_input, frontend_fd,
306                                 (i % 2) ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13,
307                                 cmd,
308                                 (i/2) % 2 ? SEC_TONE_ON : SEC_TONE_OFF,
309                                 (i/4) % 2 ? SEC_MINI_B : SEC_MINI_A))<0)
310         {
311                 msg_Err(p_input, "ioctl_DiseqcSendMsg() failed (%d)", ret);
312                 return ret;
313         }
314
315         return ret;
316 }
317
318 #define SWITCHFREQ 11700000
319 #define LOF_HI     10600000
320 #define LOF_LO      9750000
321
322 /*****************************************************************************
323  * ioctl_SetQPSKFrontend : controls the FE device
324  *****************************************************************************/
325 int ioctl_SetQPSKFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
326                            int b_polarisation, unsigned int u_adapter, unsigned int u_device  )
327 {
328     int front;
329     int ret;
330     int i;
331     int hiband;
332           char frontend[] = FRONTEND;
333           int i_len;
334
335           i_len = sizeof(FRONTEND);
336                 if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
337                 {
338                   msg_Err(p_input,  "error: snprintf() truncated string for FRONTEND" );
339                         frontend[sizeof(FRONTEND)] = '\0';
340     }
341     
342     /* Open the frontend device */
343           msg_Dbg(p_input, "Opening frontend %s", frontend);
344     if((front = open(frontend,O_RDWR)) < 0)
345     {
346 #   ifdef HAVE_ERRNO_H
347         msg_Err(p_input, "failed to open frontend (%s)", strerror(errno));
348 #   else
349         msg_Err(p_input, "failed to open frontend");
350 #   endif
351         return -1;
352     }
353     
354     /* Set the frequency of the transponder, taking into account the
355        local frequencies of the LNB */
356     hiband = (fep.frequency >= SWITCHFREQ);
357     if ((ret=ioctl_SetupSwitch (p_input, front, 0, b_polarisation, hiband))<0)
358     {
359                         msg_Err(p_input, "ioctl_SetupSwitch failed (%d)", ret);
360                         return -1;
361                 }
362
363     if (hiband)
364         fep.frequency -= LOF_HI;
365     else
366         fep.frequency -= LOF_LO;
367
368     /* Now send it all to the frontend device */
369     if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0)
370     {
371         close(front);
372 #   ifdef HAVE_ERRNO_H
373                           msg_Err(p_input, "ioctl_SetQPSKFrontend: ioctl FE_SET_FRONTEND failed (%d) %s", ret, strerror(errno));
374 #   else
375                           msg_Err(p_input, "ioctl_SetQPSKFrontend: ioctl FE_SET_FRONTEND failed (%d)", ret);
376 #   endif
377         return -1;
378     }
379
380     for (i=0; i<3; i++)
381     {
382         fe_status_t s;
383         if ((ret=ioctl(front, FE_READ_STATUS, &s))<0)
384         {
385 #       ifdef HAVE_ERRNO_H
386             msg_Err(p_input, "ioctl FE_READ_STATUS failed (%d) %s", ret, strerror(errno));
387 #       else
388             msg_Err(p_input, "ioctl FE_READ_STATUS failed (%d)", ret);
389 #       endif                             
390                                 }
391
392         if (s & FE_HAS_LOCK)
393         {
394                         msg_Dbg(p_input, "ioctl_SetQPSKFrontend: tuning status == 0x%02x!!! ..."
395                              "tuning succeeded", s);
396                   ret = 0;
397         }
398         else
399         {
400                         msg_Dbg(p_input, "ioctl_SetQPSKFrontend: tuning status == 0x%02x!!! ..."
401                              "tuning failed", s);
402                         ret = -1;
403         }
404         usleep( 500000 );
405     }
406
407     /* Close front end device */
408     close(front);
409     return ret;
410 }
411
412 /******************************************************************
413  * Check completion of the frontend control sequence
414  ******************************************************************/
415 static int ioctl_CheckQPSK(input_thread_t * p_input, int front)
416 {
417     int ret;
418     struct pollfd pfd[1];
419     struct dvb_frontend_event event;
420     /* poll for QPSK event to check if tuning worked */
421     pfd[0].fd = front;
422     pfd[0].events = POLLIN;
423
424     if (poll(pfd,1,3000))
425     {
426         if (pfd[0].revents & POLLIN)
427         {
428             if ( (ret=ioctl(front, FE_GET_EVENT, &event)) < 0)
429             {
430 #           ifdef HAVE_ERRNO_H
431                 msg_Err(p_input, "ioctl_CheckQPSK: ioctl FE_GET_EVENT failed (%d) %s", ret, strerror(errno));
432 #           else
433                 msg_Err(p_input, "ioctl_CheckQPSK: ioctl FE_GET_EVENT failed (%d)", ret);
434 #           endif
435                 return -5;
436             }
437
438             switch(event.status)
439             {
440                 case FE_HAS_SIGNAL:  /* found something above the noise level */
441                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_HAS_SIGNAL");
442                                                           break;
443                 case FE_HAS_CARRIER: /* found a DVB signal  */
444                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_HAS_CARRIER");
445                                                           break;
446                 case FE_HAS_VITERBI: /* FEC is stable  */
447                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_HAS_VITERBI");
448                                                           break;              
449                 case FE_HAS_SYNC:    /* found sync bytes  */
450                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_HAS_SYNC");
451                                                           break;              
452                 case FE_HAS_LOCK:    /* everything's working... */
453                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_HAS_LOCK");
454                                                           break;
455                 case FE_TIMEDOUT:    /*  no lock within the last ~2 seconds */
456                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_TIMEDOUT");
457                   return -2;
458                 case FE_REINIT:      /*  frontend was reinitialized,  */
459                                      /*  application is recommned to reset */
460                                          /*  DiSEqC, tone and parameters */
461                                                           msg_Dbg(p_input, "ioctl_CheckQPSK: FE_REINIT");
462                       return -1;
463             }
464         }
465         else
466         {
467             /* should come here */
468             msg_Err(p_input, "ioctl_CheckQPSK: event() failed");
469             return -3;
470         }
471     }
472     else
473     {
474 #   ifdef HAVE_ERRNO_H
475         msg_Err(p_input, "ioctl_CheckQPSK: poll() failed (%s)", strerror(errno));
476 #   else
477         msg_Err(p_input, "ioctl_CheckQPSK: poll() failed");
478 #   endif
479         return -4;
480     }
481
482     return 0;
483 }
484
485 /*****************************************************************************
486  * ioctl_SetDMXFilter : controls the demux to add a filter
487  *****************************************************************************/
488 int ioctl_SetDMXFilter(input_thread_t * p_input, int i_pid, int * pi_fd , int i_type,
489                        unsigned int u_adapter, unsigned int u_device )
490 {
491     struct dmx_pes_filter_params s_filter_params;
492     char dmx[] = DMX;
493           int i_len;
494           int result;
495
496     /* We first open the device */
497           i_len = sizeof(DMX);
498                 if (snprintf( dmx, sizeof(DMX), DMX, u_adapter, u_device) >= i_len)
499                 {
500                   msg_Err(p_input,  "snprintf() truncated string for DMX" );
501                         dmx[sizeof(DMX)] = '\0';
502     }
503
504     msg_Dbg(p_input, "Opening demux device %s", dmx);
505     if ((*pi_fd = open(dmx, O_RDWR|O_NONBLOCK))  < 0)
506     {
507 #   ifdef HAVE_ERRNO_H
508                           msg_Err(p_input, "ioctl_SetDMXFIlter: opening device failed (%s)", strerror(errno));
509 #   else
510                           msg_Err(p_input, "ioctl_SetDMXFIlter: opening device failed");
511 #   endif
512         return -1;
513     }
514
515     /* We fill the DEMUX structure : */
516     s_filter_params.pid     =   i_pid;
517     s_filter_params.input   =   DMX_IN_FRONTEND;
518     s_filter_params.output  =   DMX_OUT_TS_TAP;
519     switch ( i_type )
520     {
521         case 1:
522             msg_Dbg(p_input, "ioctl_SetDMXFIlter: DMX_PES_VIDEO for PMT %d", i_pid);
523             s_filter_params.pes_type = DMX_PES_VIDEO;
524             break;
525         case 2:
526             msg_Dbg(p_input, "ioctl_SetDMXFIlter: DMX_PES_AUDIO for PMT %d", i_pid);
527             s_filter_params.pes_type = DMX_PES_AUDIO;
528             break;
529         case 3:
530             msg_Dbg(p_input, "ioctl_SetDMXFIlter: DMX_PES_OTHER for PMT %d", i_pid);
531             s_filter_params.pes_type = DMX_PES_OTHER;
532             break;
533         default:
534             msg_Err(p_input, "trying to set PMT id to=%d for unknown type %d", i_pid, i_type );
535             break;
536     }
537     s_filter_params.flags = DMX_IMMEDIATE_START;
538
539     /* We then give the order to the device : */
540     if ((result = ioctl(*pi_fd, DMX_SET_PES_FILTER, &s_filter_params)) < 0)
541     {
542 #   ifdef HAVE_ERRNO_H
543                     msg_Err(p_input, "ioctl_SetDMXFIlter: ioctl failed with %d (%s)",result, strerror(errno));
544 #   else
545                     msg_Err(p_input, "ioctl_SetDMXFIlter: ioctl failed with %d",result);
546 #   endif
547         return -1;
548     }
549     return 0;
550 }
551
552 /*****************************************************************************
553  * ioctl_UnsetDMXFilter : removes a filter
554  *****************************************************************************/
555 int ioctl_UnsetDMXFilter(input_thread_t * p_input, int demux)
556 {
557     int ret;
558     
559     if ((ret=ioctl(demux, DMX_STOP))<0)
560     {
561 #   ifdef HAVE_ERRNO_H
562         msg_Err(p_input, "ioctl DMX_STOP failed for demux %d (%d) %s", demux, ret, strerror(errno));
563 #   else
564         msg_Err(p_input, "ioctl DMX_STOP failed for demux %d (%d)", demux, ret);
565 #   endif
566                         return -1;
567     }
568     close(demux);
569     return 0;
570 }