* Fixed a few string errors
[vlc.git] / modules / access / pvr / pvr.c
1 /*****************************************************************************
2  * pvr.c
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id$
6  *
7  * Authors: Eric Petit <titer@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <vlc/input.h>
29
30 #include <stdlib.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include <linux/types.h>
37 #include <sys/ioctl.h>
38 #include "videodev2.h"
39
40 /*****************************************************************************
41  * Module descriptor
42  *****************************************************************************/
43 static int  Open ( vlc_object_t * );
44 static void Close( vlc_object_t * );
45
46 #define DEVICE_TEXT N_( "Device" )
47 #define DEVICE_LONGTEXT N_( "PVR video device" )
48
49 #define NORM_TEXT N_( "Norm" )
50 #define NORM_LONGTEXT N_( "Defines the norm of the stream (Automatic, SECAM, PAL, or NTSC)" )
51 static int i_norm_list[] = { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL,
52                              V4L2_STD_NTSC };
53 static char *psz_norm_list_text[] = { N_("Automatic"), N_("SECAM"),
54                                       N_("PAL"),  N_("NSTC") };
55
56 #define WIDTH_TEXT N_( "Width" )
57 #define WIDTH_LONGTEXT N_( "Width of the stream to capture (-1 for " \
58                            "autodetect)" )
59 #define HEIGHT_TEXT N_( "Height" )
60 #define HEIGHT_LONGTEXT N_( "Height of the stream to capture (-1 for " \
61                            "autodetect)" )
62 #define FREQUENCY_TEXT N_( "Frequency" )
63 #define FREQUENCY_LONGTEXT N_( "Frequency to capture (in kHz), if applicable" )
64 #define FRAMERATE_TEXT N_( "Framerate" )
65 #define FRAMERATE_LONGTEXT N_( "Framerate to capture, if applicable (-1 for " \
66                                "auto)" )
67 #define KEYINT_TEXT N_( "Key interval" )
68 #define KEYINT_LONGTEXT N_( "Interval between keyframes (-1 for " \
69                                 " auto)" )
70 #define BFRAMES_TEXT N_( "B Frames" )
71 #define BFRAMES_LONGTEXT N_("If this option is set, B-Frames will be used." \
72                             "Use this option to set the number of B-Frames.")
73 #define BITRATE_TEXT N_( "Bitrate" )
74 #define BITRATE_LONGTEXT N_( "Bitrate to use (-1 for default)" )
75 #define BITRATE_PEAK_TEXT N_( "Bitrate peak" )
76 #define BITRATE_PEAK_LONGTEXT N_( "Peak bitrate in VBR mode" )
77 #define BITRATE_MODE_TEXT N_( "Bitrate mode (vbr or cbr)" )
78 #define BITRATE_MODE_LONGTEXT N_( "Bitrate mode to use" )
79 #define BITMASK_TEXT N_( "Audio bitmask" )
80 #define BITMASK_LONGTEXT N_("This option allows setting of bitmask that will get used by the audio part of the card." )
81 #define CHAN_TEXT N_( "Channel" )
82 #define CHAN_LONGTEXT N_( "Channel of the card to use (Usually, 0 = tuner, " \
83                           "1 = composite, 2 = svideo )" )
84
85 static int i_bitrates[] = { 0, 1 };
86 static char *psz_bitrates_list_text[] = { N_("vbr"), N_("cbr") };
87
88 vlc_module_begin();
89     set_shortname( _("PVR") );
90     set_description( _("MPEG Encoding cards input (with ivtv drivers)") );
91     set_capability( "access2", 0 );
92     add_shortcut( "pvr" );
93
94     add_string( "pvr-device", "/dev/video0", NULL, DEVICE_TEXT,
95                             DEVICE_LONGTEXT, VLC_FALSE );
96
97     add_integer( "pvr-norm", V4L2_STD_UNKNOWN , NULL, NORM_TEXT,
98                              NORM_LONGTEXT, VLC_FALSE );
99        change_integer_list( i_norm_list, psz_norm_list_text, 0 );
100
101     add_integer( "pvr-width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
102     add_integer( "pvr-height", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT,
103                                          VLC_TRUE );
104     add_integer( "pvr-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
105                                          VLC_FALSE );
106     add_integer( "pvr-framerate", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
107                                          VLC_TRUE );
108     add_integer( "pvr-keyint", -1, NULL, KEYINT_TEXT, KEYINT_LONGTEXT,
109                                          VLC_TRUE );
110     add_integer( "pvr-bframes", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
111                                          VLC_TRUE );
112     add_integer( "pvr-bitrate", -1, NULL, BITRATE_TEXT, BITRATE_LONGTEXT,
113                                          VLC_FALSE );
114     add_integer( "pvr-bitrate-peak", -1, NULL, BITRATE_PEAK_TEXT,
115                                          BITRATE_PEAK_LONGTEXT, VLC_TRUE );
116     add_integer( "pvr-bitrate-mode", -1, NULL, BITRATE_MODE_TEXT,
117                                          BITRATE_MODE_LONGTEXT, VLC_TRUE );
118         change_integer_list( i_bitrates, psz_bitrates_list_text, 0 );
119     add_integer( "pvr-audio-bitmask", -1, NULL, BITMASK_TEXT,
120                                          BITMASK_LONGTEXT, VLC_TRUE );
121     add_integer( "pvr-channel", -1, NULL, CHAN_TEXT,
122                                           CHAN_LONGTEXT, VLC_TRUE );
123
124     set_callbacks( Open, Close );
125 vlc_module_end();
126
127 /*****************************************************************************
128  * Prototypes
129  *****************************************************************************/
130 static int Read   ( access_t *, uint8_t *, int );
131 static int Control( access_t *, int, va_list );
132
133 /* ivtv specific ioctls */
134 #define IVTV_IOC_G_CODEC    0xFFEE7703
135 #define IVTV_IOC_S_CODEC    0xFFEE7704
136
137 /* for use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */
138
139 struct ivtv_ioctl_codec {
140         uint32_t aspect;
141         uint32_t audio_bitmask;
142         uint32_t bframes;
143         uint32_t bitrate_mode;
144         uint32_t bitrate;
145         uint32_t bitrate_peak;
146         uint32_t dnr_mode;
147         uint32_t dnr_spatial;
148         uint32_t dnr_temporal;
149         uint32_t dnr_type;
150         uint32_t framerate;
151         uint32_t framespergop;
152         uint32_t gop_closure;
153         uint32_t pulldown;
154         uint32_t stream_type;
155 };
156
157 struct access_sys_t
158 {
159     /* file descriptor */
160     int i_fd;
161
162     /* options */
163     int i_standard;
164     int i_width;
165     int i_height;
166     int i_frequency;
167     int i_framerate;
168     int i_keyint;
169     int i_bframes;
170     int i_bitrate;
171     int i_bitrate_peak;
172     int i_bitrate_mode;
173     int i_audio_bitmask;
174     int i_input;
175 };
176
177 /*****************************************************************************
178  * Open: open the device
179  *****************************************************************************/
180 static int Open( vlc_object_t * p_this )
181 {
182     access_t *p_access = (access_t*) p_this;
183     access_sys_t * p_sys;
184     char * psz_tofree, * psz_parser, * psz_device;
185
186     vlc_value_t val;
187
188     struct v4l2_format vfmt;
189     struct v4l2_frequency vf;
190     struct ivtv_ioctl_codec codec;
191
192     //psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
193
194     p_access->pf_read = Read;
195     p_access->pf_block = NULL;
196     p_access->pf_seek = NULL;
197     p_access->pf_control = Control;
198     p_access->info.i_update = 0;
199     p_access->info.i_size = 0;
200     p_access->info.i_pos = 0;
201     p_access->info.b_eof = VLC_FALSE;
202     p_access->info.i_title = 0;
203     p_access->info.i_seekpoint = 0;
204
205     /* create private access data */
206     p_sys = calloc( sizeof( access_sys_t ), 1 );
207     p_access->p_sys = p_sys;
208
209     /* defaults values */
210     var_Create( p_access, "pvr-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
211     var_Get( p_access, "pvr-device" , &val);
212     psz_device = val.psz_string;
213
214     var_Create( p_access, "pvr-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
215     var_Get( p_access, "pvr-norm" , &val);
216     p_sys->i_standard = val.i_int;
217
218     var_Create( p_access, "pvr-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
219     var_Get( p_access, "pvr-width" , &val);
220     p_sys->i_width = val.i_int;
221
222     var_Create( p_access, "pvr-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
223     var_Get( p_access, "pvr-height" , &val);
224     p_sys->i_height = val.i_int;
225
226     var_Create( p_access, "pvr-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
227     var_Get( p_access, "pvr-frequency" , &val);
228     p_sys->i_frequency = val.i_int;
229
230     var_Create( p_access, "pvr-framerate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
231     var_Get( p_access, "pvr-framerate" , &val);
232     p_sys->i_framerate = val.i_int;
233
234     var_Create( p_access, "pvr-keyint", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
235     var_Get( p_access, "pvr-keyint" , &val);
236     p_sys->i_keyint = val.i_int;
237
238     var_Create( p_access, "pvr-bframes", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
239     var_Get( p_access, "pvr-bframes" , &val);
240     p_sys->i_bframes = val.b_bool;
241
242     var_Create( p_access, "pvr-bitrate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
243     var_Get( p_access, "pvr-bitrate" , &val);
244     p_sys->i_bitrate = val.i_int;
245
246     var_Create( p_access, "pvr-bitrate-peak", VLC_VAR_INTEGER |
247                                               VLC_VAR_DOINHERIT );
248     var_Get( p_access, "pvr-bitrate-peak" , &val);
249     p_sys->i_bitrate_peak = val.i_int;
250
251     var_Create( p_access, "pvr-bitrate-mode", VLC_VAR_INTEGER |
252                                               VLC_VAR_DOINHERIT );
253     var_Get( p_access, "pvr-bitrate-mode" , &val);
254     p_sys->i_bitrate_mode = val.i_int;
255
256     var_Create( p_access, "pvr-audio-bitmask", VLC_VAR_INTEGER |
257                                               VLC_VAR_DOINHERIT );
258     var_Get( p_access, "pvr-audio-bitmask" , &val);
259     p_sys->i_audio_bitmask = val.i_int;
260     var_Create( p_access, "pvr-channel", VLC_VAR_INTEGER |
261                                               VLC_VAR_DOINHERIT );
262     var_Get( p_access, "pvr-channel" , &val);
263     p_sys->i_input = val.i_int;
264
265     /* parse command line options */
266     psz_tofree = strdup( p_access->psz_path );
267     psz_parser = psz_tofree;
268
269     if( *psz_parser )
270     {
271         for( ;; )
272         {
273             if ( !strncmp( psz_parser, "norm=", strlen( "norm=" ) ) )
274             {
275                 char *psz_parser_init;
276                 psz_parser += strlen( "norm=" );
277                 psz_parser_init = psz_parser;
278                 while ( *psz_parser != ':' && *psz_parser != ','
279                                                     && *psz_parser != '\0' )
280                 {
281                     psz_parser++;
282                 }
283
284                 if ( !strncmp( psz_parser_init, "secam" ,
285                                psz_parser - psz_parser_init ) )
286                 {
287                     p_sys->i_standard = V4L2_STD_SECAM;
288                 }
289                 else if ( !strncmp( psz_parser_init, "pal" ,
290                                     psz_parser - psz_parser_init ) )
291                 {
292                     p_sys->i_standard = V4L2_STD_PAL;
293                 }
294                 else if ( !strncmp( psz_parser_init, "ntsc" ,
295                                     psz_parser - psz_parser_init ) )
296                 {
297                     p_sys->i_standard = V4L2_STD_NTSC;
298                 }
299                 else
300                 {
301                     p_sys->i_standard = strtol( psz_parser_init ,
302                                                 &psz_parser, 0 );
303                 }
304             }
305             else if( !strncmp( psz_parser, "channel=",
306                                strlen( "channel=" ) ) )
307             {
308                 p_sys->i_input =
309                   strtol( psz_parser + strlen( "channel=" ),
310                             &psz_parser, 0 );
311             }
312             else if( !strncmp( psz_parser, "device=", strlen( "device=" ) ) )
313             {
314                 psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
315                 sprintf( psz_device, "/dev/video%ld",
316                             strtol( psz_parser + strlen( "device=" ),
317                             &psz_parser, 0 ) );
318             }
319             else if( !strncmp( psz_parser, "frequency=",
320                                strlen( "frequency=" ) ) )
321             {
322                 p_sys->i_frequency =
323                   strtol( psz_parser + strlen( "frequency=" ),
324                             &psz_parser, 0 );
325             }
326             else if( !strncmp( psz_parser, "framerate=",
327                                strlen( "framerate=" ) ) )
328             {
329                 p_sys->i_framerate =
330                     strtol( psz_parser + strlen( "framerate=" ),
331                             &psz_parser, 0 );
332             }
333             else if( !strncmp( psz_parser, "keyint=",
334                                strlen( "keyint=" ) ) )
335             {
336                 p_sys->i_keyint =
337                     strtol( psz_parser + strlen( "keyint=" ),
338                             &psz_parser, 0 );
339             }
340             else if( !strncmp( psz_parser, "bframes=",
341                                strlen( "bframes=" ) ) )
342             {
343                 p_sys->i_bframes =
344                     strtol( psz_parser + strlen( "bframes=" ),
345                             &psz_parser, 0 );
346             }
347
348             else if( !strncmp( psz_parser, "width=",
349                                strlen( "width=" ) ) )
350             {
351                 p_sys->i_width =
352                     strtol( psz_parser + strlen( "width=" ),
353                             &psz_parser, 0 );
354             }
355             else if( !strncmp( psz_parser, "height=",
356                                strlen( "height=" ) ) )
357             {
358                 p_sys->i_height =
359                     strtol( psz_parser + strlen( "height=" ),
360                             &psz_parser, 0 );
361             }
362             else if( !strncmp( psz_parser, "audio=",
363                                strlen( "audio=" ) ) )
364             {
365                 p_sys->i_audio_bitmask =
366                     strtol( psz_parser + strlen( "audio=" ),
367                             &psz_parser, 0 );
368             }
369             else if( !strncmp( psz_parser, "bitrate=",
370                                strlen( "bitrate=" ) ) )
371             {
372                 p_sys->i_bitrate =
373                     strtol( psz_parser + strlen( "bitrate=" ),
374                             &psz_parser, 0 );
375             }
376             else if( !strncmp( psz_parser, "maxbitrate=",
377                                strlen( "maxbitrate=" ) ) )
378             {
379                 p_sys->i_bitrate_peak =
380                     strtol( psz_parser + strlen( "maxbitrate=" ),
381                             &psz_parser, 0 );
382             }
383             else if( !strncmp( psz_parser, "bitratemode=",
384                                strlen( "bitratemode=" ) ) )
385             {
386                 char *psz_parser_init;
387                 psz_parser += strlen( "bitratemode=" );
388                 psz_parser_init = psz_parser;
389                 while ( *psz_parser != ':' && *psz_parser != ','
390                          && *psz_parser != '\0' )
391                 {
392                     psz_parser++;
393                 }
394
395                 if ( !strncmp( psz_parser_init, "vbr" ,
396                                psz_parser - psz_parser_init ) )
397                 {
398                      p_sys->i_bitrate_mode = 0;
399                 }
400                 else if ( !strncmp( psz_parser_init, "cbr" ,
401                                     psz_parser - psz_parser_init ) )
402                 {
403                     p_sys->i_bitrate_mode = 1;
404                 }
405             }
406             else if( !strncmp( psz_parser, "size=",
407                                strlen( "size=" ) ) )
408             {
409                 p_sys->i_width =
410                     strtol( psz_parser + strlen( "size=" ),
411                             &psz_parser, 0 );
412                 p_sys->i_height =
413                     strtol( psz_parser + 1 ,
414                             &psz_parser, 0 );
415             }
416             else
417             {
418                 char *psz_parser_init;
419                 psz_parser_init = psz_parser;
420                 while ( *psz_parser != ':' && *psz_parser != ',' && *psz_parser != '\0' )
421                 {
422                     psz_parser++;
423                 }
424                 psz_device = calloc( psz_parser - psz_parser_init + 1, 1 );
425                 strncpy( psz_device, psz_parser_init,
426                          psz_parser - psz_parser_init );
427             }
428             if( *psz_parser )
429                 psz_parser++;
430             else
431                 break;
432         }
433     }
434
435     //give a default value to psz_device if none has bee specified
436
437     if (!psz_device)
438     {
439         psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
440         strcpy( psz_device, "/dev/video0" );
441     }
442
443     free( psz_tofree );
444
445     /* open the device */
446     if( ( p_sys->i_fd = open( psz_device, O_RDWR ) ) < 0 )
447     {
448         msg_Err( p_access, "cannot open device (%s)", strerror( errno ) );
449         return VLC_EGENERIC;
450     }
451     else
452     {
453         msg_Dbg( p_access, "using video device: %s",psz_device);
454     }
455
456     free( psz_device );
457
458     /* set the input */
459     if ( p_sys->i_input != -1 )
460     {
461         if ( ioctl( p_sys->i_fd, VIDIOC_S_INPUT, &p_sys->i_input ) < 0 )
462         {
463             msg_Warn( p_access, "VIDIOC_S_INPUT failed" );
464         }
465         else
466         {
467             msg_Dbg( p_access, "input set to:%d", p_sys->i_input);
468         }
469     }
470
471     /* set the video standard */
472     if ( p_sys->i_standard != V4L2_STD_UNKNOWN )
473     {
474         if ( ioctl( p_sys->i_fd, VIDIOC_S_STD, &p_sys->i_standard ) < 0 )
475         {
476             msg_Warn( p_access, "VIDIOC_S_STD failed" );
477         }
478         else
479         {
480             msg_Dbg( p_access, "video standard set to:%x", p_sys->i_standard);
481         }
482     }
483
484     /* set the picture size */
485     if ( p_sys->i_width != -1 || p_sys->i_height != -1 )
486     {
487         if ( ioctl( p_sys->i_fd, VIDIOC_G_FMT, &vfmt ) < 0 )
488         {
489             msg_Warn( p_access, "VIDIOC_G_FMT failed" );
490         }
491         else
492         {
493             if ( p_sys->i_width != -1 )
494             {
495                 vfmt.fmt.pix.width = p_sys->i_width;
496             }
497
498             if ( p_sys->i_height != -1 )
499             {
500                 vfmt.fmt.pix.height = p_sys->i_height;
501             }
502
503             if ( ioctl( p_sys->i_fd, VIDIOC_S_FMT, &vfmt ) < 0 )
504             {
505                 msg_Warn( p_access, "VIDIOC_S_FMT failed" );
506             }
507             else
508             {
509                 msg_Dbg( p_access, "picture size set to:%dx%d",
510                          vfmt.fmt.pix.width, vfmt.fmt.pix.height );
511             }
512         }
513     }
514
515     /* set the frequency */
516     if ( p_sys->i_frequency != -1 )
517     {
518         vf.tuner = 0; /* TODO: let the user choose the tuner */
519         if ( ioctl( p_sys->i_fd, VIDIOC_G_FREQUENCY, &vf ) < 0 )
520         {
521             msg_Warn( p_access, "VIDIOC_G_FREQUENCY failed (%s)",
522                       strerror( errno ) );
523         }
524         else
525         {
526             vf.frequency = p_sys->i_frequency * 16 / 1000;
527             if( ioctl( p_sys->i_fd, VIDIOC_S_FREQUENCY, &vf ) < 0 )
528             {
529                 msg_Warn( p_access, "VIDIOC_S_FREQUENCY failed (%s)",
530                           strerror( errno ) );
531             }
532             else
533             {
534                 msg_Dbg( p_access, "Tuner frequency set to:%d",
535                          p_sys->i_frequency);
536             }
537         }
538     }
539
540     /* codec parameters */
541     if ( p_sys->i_framerate != -1
542             || p_sys->i_bitrate_mode != -1
543             || p_sys->i_bitrate_peak != -1
544             || p_sys->i_keyint != -1
545             || p_sys->i_bframes != -1
546             || p_sys->i_bitrate != -1
547             || p_sys->i_audio_bitmask != -1 )
548     {
549         if ( ioctl( p_sys->i_fd, IVTV_IOC_G_CODEC, &codec ) < 0 )
550         {
551             msg_Warn( p_access, "IVTV_IOC_G_CODEC failed" );
552         }
553         else
554         {
555             if ( p_sys->i_framerate != -1 )
556             {
557                 switch ( p_sys->i_framerate )
558                 {
559                     case 30:
560                         codec.framerate = 0;
561                         break;
562
563                     case 25:
564                         codec.framerate = 1;
565                         break;
566
567                     default:
568                         msg_Warn( p_access, "invalid framerate, reverting to 25" );
569                         codec.framerate = 1;
570                         break;
571                 }
572             }
573
574             if ( p_sys->i_bitrate != -1 )
575             {
576                 codec.bitrate = p_sys->i_bitrate;
577             }
578
579             if ( p_sys->i_bitrate_peak != -1 )
580             {
581                 codec.bitrate_peak = p_sys->i_bitrate_peak;
582             }
583
584             if ( p_sys->i_bitrate_mode != -1 )
585             {
586                 codec.bitrate_mode = p_sys->i_bitrate_mode;
587             }
588
589             if ( p_sys->i_audio_bitmask != -1 )
590             {
591                 codec.audio_bitmask = p_sys->i_audio_bitmask;
592             }
593             if ( p_sys->i_keyint != -1 )
594             {
595                 codec.framespergop = p_sys->i_keyint;
596             }
597
598             if ( p_sys->i_bframes != -1 )
599             {
600                 codec.bframes = p_sys->i_bframes;
601             }
602             if( ioctl( p_sys->i_fd, IVTV_IOC_S_CODEC, &codec ) < 0 )
603             {
604                 msg_Warn( p_access, "IVTV_IOC_S_CODEC failed" );
605             }
606             else
607             {
608                 msg_Dbg( p_access, "Setting codec parameters to:  framerate: %d, bitrate: %d/%d/%d",
609                codec.framerate, codec.bitrate, codec.bitrate_peak, codec.bitrate_mode );
610             }
611         }
612     }
613
614     /* do a quick read */
615 #if 0
616     if ( p_sys->i_fd )
617     {
618         if ( read( p_sys->i_fd, psz_tmp, 1 ) )
619         {
620             msg_Dbg(p_input, "Could read byte from device");
621         }
622         else
623         {
624             msg_Warn(p_input, "Could not read byte from device");
625         }
626     }
627 #endif
628     return VLC_SUCCESS;
629 }
630
631 /*****************************************************************************
632  * Close: close the device
633  *****************************************************************************/
634 static void Close( vlc_object_t * p_this )
635 {
636     access_t *p_access = (access_t*) p_this;
637     access_sys_t * p_sys = p_access->p_sys;
638
639     close( p_sys->i_fd );
640     free( p_sys );
641 }
642
643 /*****************************************************************************
644  * Read
645  *****************************************************************************/
646 static int Read( access_t * p_access, uint8_t * p_buffer, int i_len )
647 {
648     access_sys_t * p_sys = p_access->p_sys;
649
650     int i_ret;
651
652     struct timeval timeout;
653     fd_set fds;
654
655     FD_ZERO( &fds );
656     FD_SET( p_sys->i_fd, &fds );
657     timeout.tv_sec = 0;
658     timeout.tv_usec = 500000;
659
660     if( p_access->info.b_eof )
661         return 0;
662
663     while( !( i_ret = select( p_sys->i_fd + 1, &fds, NULL, NULL, &timeout) ) )
664     {
665         FD_ZERO( &fds );
666         FD_SET( p_sys->i_fd, &fds );
667         timeout.tv_sec = 0;
668         timeout.tv_usec = 500000;
669
670         if( p_access->b_die )
671             return 0;
672     }
673
674     if( i_ret < 0 )
675     {
676         msg_Err( p_access, "select error (%s)", strerror( errno ) );
677         return -1;
678     }
679
680     i_ret = read( p_sys->i_fd, p_buffer, i_len );
681     if( i_ret == 0 )
682     {
683         p_access->info.b_eof = VLC_TRUE;
684     }
685     else if( i_ret > 0 )
686     {
687         p_access->info.i_pos += i_ret;
688     }
689
690     return i_ret;
691 }
692
693 /*****************************************************************************
694  * Control
695  *****************************************************************************/
696 static int Control( access_t *p_access, int i_query, va_list args )
697 {
698     access_sys_t *p_sys = p_access->p_sys;
699     vlc_bool_t   *pb_bool;
700     int          *pi_int;
701     int64_t      *pi_64;
702
703     switch( i_query )
704     {
705         /* */
706         case ACCESS_CAN_SEEK:
707         case ACCESS_CAN_FASTSEEK:
708             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
709             *pb_bool = VLC_FALSE;
710             break;
711         case ACCESS_CAN_PAUSE:
712             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
713             *pb_bool = VLC_FALSE;
714             break;
715         case ACCESS_CAN_CONTROL_PACE:
716             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
717             *pb_bool = VLC_FALSE;
718             break;
719
720         /* */
721         case ACCESS_GET_MTU:
722             pi_int = (int*)va_arg( args, int * );
723             *pi_int = 0;
724             break;
725
726         case ACCESS_GET_PTS_DELAY:
727             pi_64 = (int64_t*)va_arg( args, int64_t * );
728             *pi_64 = 1000000;
729             break;
730
731         /* */
732         case ACCESS_SET_PAUSE_STATE:
733             /* Nothing to do */
734             break;
735
736         case ACCESS_GET_TITLE_INFO:
737         case ACCESS_SET_TITLE:
738         case ACCESS_SET_SEEKPOINT:
739         case ACCESS_SET_PRIVATE_ID_STATE:
740             return VLC_EGENERIC;
741
742         default:
743             msg_Warn( p_access, "unimplemented query in control" );
744             return VLC_EGENERIC;
745
746     }
747     return VLC_SUCCESS;
748 }
749