Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

pvr.c

00001 /*****************************************************************************
00002  * pvr.c
00003  *****************************************************************************
00004  * Copyright (C) 2001, 2002 the VideoLAN team
00005  * $Id: pvr.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Eric Petit <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <vlc/vlc.h>
00028 #include <vlc/input.h>
00029 
00030 #include <stdlib.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #include <fcntl.h>
00034 #include <unistd.h>
00035 #include <errno.h>
00036 #include <linux/types.h>
00037 #include <sys/ioctl.h>
00038 #include "videodev2.h"
00039 
00040 /*****************************************************************************
00041  * Module descriptor
00042  *****************************************************************************/
00043 static int  Open ( vlc_object_t * );
00044 static void Close( vlc_object_t * );
00045 
00046 #define CACHING_TEXT N_("Caching value in ms")
00047 #define CACHING_LONGTEXT N_( \
00048     "Allows you to modify the default caching value for pvr streams. This " \
00049     "value should be set in millisecond units." )
00050 
00051 #define DEVICE_TEXT N_( "Device" )
00052 #define DEVICE_LONGTEXT N_( "PVR video device" )
00053 
00054 #define NORM_TEXT N_( "Norm" )
00055 #define NORM_LONGTEXT N_( "Defines the norm of the stream " \
00056     "(Automatic, SECAM, PAL, or NTSC)" )
00057 
00058 #define WIDTH_TEXT N_( "Width" )
00059 #define WIDTH_LONGTEXT N_( "Width of the stream to capture " \
00060     "(-1 for autodetect)" )
00061 
00062 #define HEIGHT_TEXT N_( "Height" )
00063 #define HEIGHT_LONGTEXT N_( "Height of the stream to capture " \
00064     "(-1 for autodetect)" )
00065 
00066 #define FREQUENCY_TEXT N_( "Frequency" )
00067 #define FREQUENCY_LONGTEXT N_( "Frequency to capture (in kHz), if applicable" )
00068 
00069 #define FRAMERATE_TEXT N_( "Framerate" )
00070 #define FRAMERATE_LONGTEXT N_( "Framerate to capture, if applicable " \
00071     "(-1 for autodetect)" )
00072 
00073 #define KEYINT_TEXT N_( "Key interval" )
00074 #define KEYINT_LONGTEXT N_( "Interval between keyframes (-1 for autodetect)" )
00075 
00076 #define BFRAMES_TEXT N_( "B Frames" )
00077 #define BFRAMES_LONGTEXT N_("If this option is set, B-Frames will be used. " \
00078     "Use this option to set the number of B-Frames.")
00079 
00080 #define BITRATE_TEXT N_( "Bitrate" )
00081 #define BITRATE_LONGTEXT N_( "Bitrate to use (-1 for default)" )
00082 
00083 #define BITRATE_PEAK_TEXT N_( "Bitrate peak" )
00084 #define BITRATE_PEAK_LONGTEXT N_( "Peak bitrate in VBR mode" )
00085 
00086 #define BITRATE_MODE_TEXT N_( "Bitrate mode (vbr or cbr)" )
00087 #define BITRATE_MODE_LONGTEXT N_( "Bitrate mode to use" )
00088 
00089 #define BITMASK_TEXT N_( "Audio bitmask" )
00090 #define BITMASK_LONGTEXT N_("This option allows setting of bitmask that will "\
00091     "get used by the audio part of the card." )
00092 
00093 #define CHAN_TEXT N_( "Channel" )
00094 #define CHAN_LONGTEXT N_( "Channel of the card to use (Usually, 0 = tuner, " \
00095     "1 = composite, 2 = svideo)" )
00096 
00097 #define CACHING_TEXT N_("Caching value in ms")
00098 #define CACHING_LONGTEXT N_( \
00099     "Allows you to modify the default caching value for pvr streams. This " \
00100     "value should be set in millisecond units." )
00101 
00102 static int i_norm_list[] =
00103     { V4L2_STD_UNKNOWN, V4L2_STD_SECAM, V4L2_STD_PAL, V4L2_STD_NTSC };
00104 static char *psz_norm_list_text[] =
00105     { N_("Automatic"), N_("SECAM"), N_("PAL"),  N_("NTSC") };
00106 
00107 static int i_bitrates[] = { 0, 1 };
00108 static char *psz_bitrates_list_text[] = { N_("vbr"), N_("cbr") };
00109 
00110 vlc_module_begin();
00111     set_shortname( _("PVR") );
00112     set_description( _("MPEG Encoding cards input (with ivtv drivers)") );
00113     set_category( CAT_INPUT );
00114     set_subcategory( SUBCAT_INPUT_ACCESS );
00115     set_capability( "access2", 0 );
00116     add_shortcut( "pvr" );
00117 
00118     add_integer( "pvr-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
00119     add_string( "pvr-device", "/dev/video0", NULL, DEVICE_TEXT,
00120                  DEVICE_LONGTEXT, VLC_FALSE );
00121     add_integer( "pvr-norm", V4L2_STD_UNKNOWN , NULL, NORM_TEXT,
00122                  NORM_LONGTEXT, VLC_FALSE );
00123        change_integer_list( i_norm_list, psz_norm_list_text, 0 );
00124     add_integer( "pvr-width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, VLC_TRUE );
00125     add_integer( "pvr-height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
00126                  VLC_TRUE );
00127     add_integer( "pvr-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
00128                  VLC_FALSE );
00129     add_integer( "pvr-framerate", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
00130                  VLC_TRUE );
00131     add_integer( "pvr-keyint", -1, NULL, KEYINT_TEXT, KEYINT_LONGTEXT,
00132                  VLC_TRUE );
00133     add_integer( "pvr-bframes", -1, NULL, FRAMERATE_TEXT, FRAMERATE_LONGTEXT,
00134                  VLC_TRUE );
00135     add_integer( "pvr-bitrate", -1, NULL, BITRATE_TEXT, BITRATE_LONGTEXT,
00136                  VLC_FALSE );
00137     add_integer( "pvr-bitrate-peak", -1, NULL, BITRATE_PEAK_TEXT,
00138                  BITRATE_PEAK_LONGTEXT, VLC_TRUE );
00139     add_integer( "pvr-bitrate-mode", -1, NULL, BITRATE_MODE_TEXT,
00140                  BITRATE_MODE_LONGTEXT, VLC_TRUE );
00141         change_integer_list( i_bitrates, psz_bitrates_list_text, 0 );
00142     add_integer( "pvr-audio-bitmask", -1, NULL, BITMASK_TEXT,
00143                  BITMASK_LONGTEXT, VLC_TRUE );
00144     add_integer( "pvr-channel", -1, NULL, CHAN_TEXT, CHAN_LONGTEXT, VLC_TRUE );
00145     add_integer( "pvr-caching", DEFAULT_PTS_DELAY / 1000, NULL,
00146                  CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
00147 
00148     set_callbacks( Open, Close );
00149 vlc_module_end();
00150 
00151 /*****************************************************************************
00152  * Prototypes
00153  *****************************************************************************/
00154 static int Read   ( access_t *, uint8_t *, int );
00155 static int Control( access_t *, int, va_list );
00156 
00157 /* ivtv specific ioctls */
00158 #define IVTV_IOC_G_CODEC    0xFFEE7703
00159 #define IVTV_IOC_S_CODEC    0xFFEE7704
00160 
00161 /* for use with IVTV_IOC_G_CODEC and IVTV_IOC_S_CODEC */
00162 
00163 struct ivtv_ioctl_codec {
00164         uint32_t aspect;
00165         uint32_t audio_bitmask;
00166         uint32_t bframes;
00167         uint32_t bitrate_mode;
00168         uint32_t bitrate;
00169         uint32_t bitrate_peak;
00170         uint32_t dnr_mode;
00171         uint32_t dnr_spatial;
00172         uint32_t dnr_temporal;
00173         uint32_t dnr_type;
00174         uint32_t framerate;
00175         uint32_t framespergop;
00176         uint32_t gop_closure;
00177         uint32_t pulldown;
00178         uint32_t stream_type;
00179 };
00180 
00181 struct access_sys_t
00182 {
00183     /* file descriptor */
00184     int i_fd;
00185 
00186     /* options */
00187     int i_standard;
00188     int i_width;
00189     int i_height;
00190     int i_frequency;
00191     int i_framerate;
00192     int i_keyint;
00193     int i_bframes;
00194     int i_bitrate;
00195     int i_bitrate_peak;
00196     int i_bitrate_mode;
00197     int i_audio_bitmask;
00198     int i_input;
00199 };
00200 
00201 /*****************************************************************************
00202  * Open: open the device
00203  *****************************************************************************/
00204 static int Open( vlc_object_t * p_this )
00205 {
00206     access_t *p_access = (access_t*) p_this;
00207     access_sys_t * p_sys;
00208     char * psz_tofree, * psz_parser, * psz_device;
00209     vlc_value_t val;
00210 
00211     struct v4l2_format vfmt;
00212     struct v4l2_frequency vf;
00213     struct ivtv_ioctl_codec codec;
00214 
00215     //psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
00216 
00217     p_access->pf_read = Read;
00218     p_access->pf_block = NULL;
00219     p_access->pf_seek = NULL;
00220     p_access->pf_control = Control;
00221     p_access->info.i_update = 0;
00222     p_access->info.i_size = 0;
00223     p_access->info.i_pos = 0;
00224     p_access->info.b_eof = VLC_FALSE;
00225     p_access->info.i_title = 0;
00226     p_access->info.i_seekpoint = 0;
00227 
00228     /* create private access data */
00229     p_sys = calloc( sizeof( access_sys_t ), 1 );
00230     p_access->p_sys = p_sys;
00231 
00232     /* defaults values */
00233     var_Create( p_access, "pvr-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00234 
00235     var_Create( p_access, "pvr-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
00236     var_Get( p_access, "pvr-device" , &val);
00237     psz_device = val.psz_string;
00238 
00239     var_Create( p_access, "pvr-norm", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00240     var_Get( p_access, "pvr-norm" , &val);
00241     p_sys->i_standard = val.i_int;
00242 
00243     var_Create( p_access, "pvr-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00244     var_Get( p_access, "pvr-width" , &val);
00245     p_sys->i_width = val.i_int;
00246 
00247     var_Create( p_access, "pvr-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00248     var_Get( p_access, "pvr-height" , &val);
00249     p_sys->i_height = val.i_int;
00250 
00251     var_Create( p_access, "pvr-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00252     var_Get( p_access, "pvr-frequency" , &val);
00253     p_sys->i_frequency = val.i_int;
00254 
00255     var_Create( p_access, "pvr-framerate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00256     var_Get( p_access, "pvr-framerate" , &val);
00257     p_sys->i_framerate = val.i_int;
00258 
00259     var_Create( p_access, "pvr-keyint", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00260     var_Get( p_access, "pvr-keyint" , &val);
00261     p_sys->i_keyint = val.i_int;
00262 
00263     var_Create( p_access, "pvr-bframes", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00264     var_Get( p_access, "pvr-bframes" , &val);
00265     p_sys->i_bframes = val.b_bool;
00266 
00267     var_Create( p_access, "pvr-bitrate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00268     var_Get( p_access, "pvr-bitrate" , &val);
00269     p_sys->i_bitrate = val.i_int;
00270 
00271     var_Create( p_access, "pvr-bitrate-peak", VLC_VAR_INTEGER |
00272                                               VLC_VAR_DOINHERIT );
00273     var_Get( p_access, "pvr-bitrate-peak" , &val);
00274     p_sys->i_bitrate_peak = val.i_int;
00275 
00276     var_Create( p_access, "pvr-bitrate-mode", VLC_VAR_INTEGER |
00277                                               VLC_VAR_DOINHERIT );
00278     var_Get( p_access, "pvr-bitrate-mode" , &val);
00279     p_sys->i_bitrate_mode = val.i_int;
00280 
00281     var_Create( p_access, "pvr-audio-bitmask", VLC_VAR_INTEGER |
00282                                               VLC_VAR_DOINHERIT );
00283     var_Get( p_access, "pvr-audio-bitmask" , &val);
00284     p_sys->i_audio_bitmask = val.i_int;
00285     var_Create( p_access, "pvr-channel", VLC_VAR_INTEGER |
00286                                               VLC_VAR_DOINHERIT );
00287     var_Get( p_access, "pvr-channel" , &val);
00288     p_sys->i_input = val.i_int;
00289 
00290     /* parse command line options */
00291     psz_tofree = strdup( p_access->psz_path );
00292     psz_parser = psz_tofree;
00293 
00294     if( *psz_parser )
00295     {
00296         for( ;; )
00297         {
00298             if ( !strncmp( psz_parser, "norm=", strlen( "norm=" ) ) )
00299             {
00300                 char *psz_parser_init;
00301                 psz_parser += strlen( "norm=" );
00302                 psz_parser_init = psz_parser;
00303                 while ( *psz_parser != ':' && *psz_parser != ','
00304                                                     && *psz_parser != '\0' )
00305                 {
00306                     psz_parser++;
00307                 }
00308 
00309                 if ( !strncmp( psz_parser_init, "secam" ,
00310                                psz_parser - psz_parser_init ) )
00311                 {
00312                     p_sys->i_standard = V4L2_STD_SECAM;
00313                 }
00314                 else if ( !strncmp( psz_parser_init, "pal" ,
00315                                     psz_parser - psz_parser_init ) )
00316                 {
00317                     p_sys->i_standard = V4L2_STD_PAL;
00318                 }
00319                 else if ( !strncmp( psz_parser_init, "ntsc" ,
00320                                     psz_parser - psz_parser_init ) )
00321                 {
00322                     p_sys->i_standard = V4L2_STD_NTSC;
00323                 }
00324                 else
00325                 {
00326                     p_sys->i_standard = strtol( psz_parser_init ,
00327                                                 &psz_parser, 0 );
00328                 }
00329             }
00330             else if( !strncmp( psz_parser, "channel=",
00331                                strlen( "channel=" ) ) )
00332             {
00333                 p_sys->i_input =
00334                   strtol( psz_parser + strlen( "channel=" ),
00335                             &psz_parser, 0 );
00336             }
00337             else if( !strncmp( psz_parser, "device=", strlen( "device=" ) ) )
00338             {
00339                 psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
00340                 sprintf( psz_device, "/dev/video%ld",
00341                             strtol( psz_parser + strlen( "device=" ),
00342                             &psz_parser, 0 ) );
00343             }
00344             else if( !strncmp( psz_parser, "frequency=",
00345                                strlen( "frequency=" ) ) )
00346             {
00347                 p_sys->i_frequency =
00348                   strtol( psz_parser + strlen( "frequency=" ),
00349                             &psz_parser, 0 );
00350             }
00351             else if( !strncmp( psz_parser, "framerate=",
00352                                strlen( "framerate=" ) ) )
00353             {
00354                 p_sys->i_framerate =
00355                     strtol( psz_parser + strlen( "framerate=" ),
00356                             &psz_parser, 0 );
00357             }
00358             else if( !strncmp( psz_parser, "keyint=",
00359                                strlen( "keyint=" ) ) )
00360             {
00361                 p_sys->i_keyint =
00362                     strtol( psz_parser + strlen( "keyint=" ),
00363                             &psz_parser, 0 );
00364             }
00365             else if( !strncmp( psz_parser, "bframes=",
00366                                strlen( "bframes=" ) ) )
00367             {
00368                 p_sys->i_bframes =
00369                     strtol( psz_parser + strlen( "bframes=" ),
00370                             &psz_parser, 0 );
00371             }
00372 
00373             else if( !strncmp( psz_parser, "width=",
00374                                strlen( "width=" ) ) )
00375             {
00376                 p_sys->i_width =
00377                     strtol( psz_parser + strlen( "width=" ),
00378                             &psz_parser, 0 );
00379             }
00380             else if( !strncmp( psz_parser, "height=",
00381                                strlen( "height=" ) ) )
00382             {
00383                 p_sys->i_height =
00384                     strtol( psz_parser + strlen( "height=" ),
00385                             &psz_parser, 0 );
00386             }
00387             else if( !strncmp( psz_parser, "audio=",
00388                                strlen( "audio=" ) ) )
00389             {
00390                 p_sys->i_audio_bitmask =
00391                     strtol( psz_parser + strlen( "audio=" ),
00392                             &psz_parser, 0 );
00393             }
00394             else if( !strncmp( psz_parser, "bitrate=",
00395                                strlen( "bitrate=" ) ) )
00396             {
00397                 p_sys->i_bitrate =
00398                     strtol( psz_parser + strlen( "bitrate=" ),
00399                             &psz_parser, 0 );
00400             }
00401             else if( !strncmp( psz_parser, "maxbitrate=",
00402                                strlen( "maxbitrate=" ) ) )
00403             {
00404                 p_sys->i_bitrate_peak =
00405                     strtol( psz_parser + strlen( "maxbitrate=" ),
00406                             &psz_parser, 0 );
00407             }
00408             else if( !strncmp( psz_parser, "bitratemode=",
00409                                strlen( "bitratemode=" ) ) )
00410             {
00411                 char *psz_parser_init;
00412                 psz_parser += strlen( "bitratemode=" );
00413                 psz_parser_init = psz_parser;
00414                 while ( *psz_parser != ':' && *psz_parser != ','
00415                          && *psz_parser != '\0' )
00416                 {
00417                     psz_parser++;
00418                 }
00419 
00420                 if ( !strncmp( psz_parser_init, "vbr" ,
00421                                psz_parser - psz_parser_init ) )
00422                 {
00423                      p_sys->i_bitrate_mode = 0;
00424                 }
00425                 else if ( !strncmp( psz_parser_init, "cbr" ,
00426                                     psz_parser - psz_parser_init ) )
00427                 {
00428                     p_sys->i_bitrate_mode = 1;
00429                 }
00430             }
00431             else if( !strncmp( psz_parser, "size=",
00432                                strlen( "size=" ) ) )
00433             {
00434                 p_sys->i_width =
00435                     strtol( psz_parser + strlen( "size=" ),
00436                             &psz_parser, 0 );
00437                 p_sys->i_height =
00438                     strtol( psz_parser + 1 ,
00439                             &psz_parser, 0 );
00440             }
00441             else
00442             {
00443                 char *psz_parser_init;
00444                 psz_parser_init = psz_parser;
00445                 while ( *psz_parser != ':' && *psz_parser != ',' && *psz_parser != '\0' )
00446                 {
00447                     psz_parser++;
00448                 }
00449                 psz_device = calloc( psz_parser - psz_parser_init + 1, 1 );
00450                 strncpy( psz_device, psz_parser_init,
00451                          psz_parser - psz_parser_init );
00452             }
00453             if( *psz_parser )
00454                 psz_parser++;
00455             else
00456                 break;
00457         }
00458     }
00459 
00460     //give a default value to psz_device if none has bee specified
00461 
00462     if (!psz_device)
00463     {
00464         psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );
00465         strcpy( psz_device, "/dev/video0" );
00466     }
00467 
00468     free( psz_tofree );
00469 
00470     /* open the device */
00471     if( ( p_sys->i_fd = open( psz_device, O_RDWR ) ) < 0 )
00472     {
00473         msg_Err( p_access, "cannot open device (%s)", strerror( errno ) );
00474         return VLC_EGENERIC;
00475     }
00476     else
00477     {
00478         msg_Dbg( p_access, "using video device: %s",psz_device);
00479     }
00480 
00481     free( psz_device );
00482 
00483     /* set the input */
00484     if ( p_sys->i_input != -1 )
00485     {
00486         if ( ioctl( p_sys->i_fd, VIDIOC_S_INPUT, &p_sys->i_input ) < 0 )
00487         {
00488             msg_Warn( p_access, "VIDIOC_S_INPUT failed" );
00489         }
00490         else
00491         {
00492             msg_Dbg( p_access, "input set to:%d", p_sys->i_input);
00493         }
00494     }
00495 
00496     /* set the video standard */
00497     if ( p_sys->i_standard != V4L2_STD_UNKNOWN )
00498     {
00499         if ( ioctl( p_sys->i_fd, VIDIOC_S_STD, &p_sys->i_standard ) < 0 )
00500         {
00501             msg_Warn( p_access, "VIDIOC_S_STD failed" );
00502         }
00503         else
00504         {
00505             msg_Dbg( p_access, "video standard set to:%x", p_sys->i_standard);
00506         }
00507     }
00508 
00509     /* set the picture size */
00510     if ( p_sys->i_width != -1 || p_sys->i_height != -1 )
00511     {
00512         vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
00513         if ( ioctl( p_sys->i_fd, VIDIOC_G_FMT, &vfmt ) < 0 )
00514         {
00515             msg_Warn( p_access, "VIDIOC_G_FMT failed" );
00516         }
00517         else
00518         {
00519             if ( p_sys->i_width != -1 )
00520             {
00521                 vfmt.fmt.pix.width = p_sys->i_width;
00522             }
00523 
00524             if ( p_sys->i_height != -1 )
00525             {
00526                 vfmt.fmt.pix.height = p_sys->i_height;
00527             }
00528 
00529             if ( ioctl( p_sys->i_fd, VIDIOC_S_FMT, &vfmt ) < 0 )
00530             {
00531                 msg_Warn( p_access, "VIDIOC_S_FMT failed" );
00532             }
00533             else
00534             {
00535                 msg_Dbg( p_access, "picture size set to:%dx%d",
00536                          vfmt.fmt.pix.width, vfmt.fmt.pix.height );
00537             }
00538         }
00539     }
00540 
00541     /* set the frequency */
00542     if ( p_sys->i_frequency != -1 )
00543     {
00544         vf.tuner = 0; /* TODO: let the user choose the tuner */
00545         if ( ioctl( p_sys->i_fd, VIDIOC_G_FREQUENCY, &vf ) < 0 )
00546         {
00547             msg_Warn( p_access, "VIDIOC_G_FREQUENCY failed (%s)",
00548                       strerror( errno ) );
00549         }
00550         else
00551         {
00552             vf.frequency = p_sys->i_frequency * 16 / 1000;
00553             if( ioctl( p_sys->i_fd, VIDIOC_S_FREQUENCY, &vf ) < 0 )
00554             {
00555                 msg_Warn( p_access, "VIDIOC_S_FREQUENCY failed (%s)",
00556                           strerror( errno ) );
00557             }
00558             else
00559             {
00560                 msg_Dbg( p_access, "Tuner frequency set to:%d",
00561                          p_sys->i_frequency);
00562             }
00563         }
00564     }
00565 
00566     /* codec parameters */
00567     if ( p_sys->i_framerate != -1
00568             || p_sys->i_bitrate_mode != -1
00569             || p_sys->i_bitrate_peak != -1
00570             || p_sys->i_keyint != -1
00571             || p_sys->i_bframes != -1
00572             || p_sys->i_bitrate != -1
00573             || p_sys->i_audio_bitmask != -1 )
00574     {
00575         if ( ioctl( p_sys->i_fd, IVTV_IOC_G_CODEC, &codec ) < 0 )
00576         {
00577             msg_Warn( p_access, "IVTV_IOC_G_CODEC failed" );
00578         }
00579         else
00580         {
00581             if ( p_sys->i_framerate != -1 )
00582             {
00583                 switch ( p_sys->i_framerate )
00584                 {
00585                     case 30:
00586                         codec.framerate = 0;
00587                         break;
00588 
00589                     case 25:
00590                         codec.framerate = 1;
00591                         break;
00592 
00593                     default:
00594                         msg_Warn( p_access, "invalid framerate, reverting to 25" );
00595                         codec.framerate = 1;
00596                         break;
00597                 }
00598             }
00599 
00600             if ( p_sys->i_bitrate != -1 )
00601             {
00602                 codec.bitrate = p_sys->i_bitrate;
00603             }
00604 
00605             if ( p_sys->i_bitrate_peak != -1 )
00606             {
00607                 codec.bitrate_peak = p_sys->i_bitrate_peak;
00608             }
00609 
00610             if ( p_sys->i_bitrate_mode != -1 )
00611             {
00612                 codec.bitrate_mode = p_sys->i_bitrate_mode;
00613             }
00614 
00615             if ( p_sys->i_audio_bitmask != -1 )
00616             {
00617                 codec.audio_bitmask = p_sys->i_audio_bitmask;
00618             }
00619             if ( p_sys->i_keyint != -1 )
00620             {
00621                 codec.framespergop = p_sys->i_keyint;
00622             }
00623 
00624             if ( p_sys->i_bframes != -1 )
00625             {
00626                 codec.bframes = p_sys->i_bframes;
00627             }
00628             if( ioctl( p_sys->i_fd, IVTV_IOC_S_CODEC, &codec ) < 0 )
00629             {
00630                 msg_Warn( p_access, "IVTV_IOC_S_CODEC failed" );
00631             }
00632             else
00633             {
00634                 msg_Dbg( p_access, "Setting codec parameters to:  framerate: %d, bitrate: %d/%d/%d",
00635                codec.framerate, codec.bitrate, codec.bitrate_peak, codec.bitrate_mode );
00636             }
00637         }
00638     }
00639 
00640     /* do a quick read */
00641 #if 0
00642     if ( p_sys->i_fd )
00643     {
00644         if ( read( p_sys->i_fd, psz_tmp, 1 ) )
00645         {
00646             msg_Dbg(p_input, "Could read byte from device");
00647         }
00648         else
00649         {
00650             msg_Warn(p_input, "Could not read byte from device");
00651         }
00652     }
00653 #endif
00654 
00655     return VLC_SUCCESS;
00656 }
00657 
00658 /*****************************************************************************
00659  * Close: close the device
00660  *****************************************************************************/
00661 static void Close( vlc_object_t * p_this )
00662 {
00663     access_t *p_access = (access_t*) p_this;
00664     access_sys_t * p_sys = p_access->p_sys;
00665 
00666     close( p_sys->i_fd );
00667     free( p_sys );
00668 }
00669 
00670 /*****************************************************************************
00671  * Read
00672  *****************************************************************************/
00673 static int Read( access_t * p_access, uint8_t * p_buffer, int i_len )
00674 {
00675     access_sys_t * p_sys = p_access->p_sys;
00676 
00677     int i_ret;
00678 
00679     struct timeval timeout;
00680     fd_set fds;
00681 
00682     FD_ZERO( &fds );
00683     FD_SET( p_sys->i_fd, &fds );
00684     timeout.tv_sec = 0;
00685     timeout.tv_usec = 500000;
00686 
00687     if( p_access->info.b_eof )
00688         return 0;
00689 
00690     while( !( i_ret = select( p_sys->i_fd + 1, &fds, NULL, NULL, &timeout) ) )
00691     {
00692         FD_ZERO( &fds );
00693         FD_SET( p_sys->i_fd, &fds );
00694         timeout.tv_sec = 0;
00695         timeout.tv_usec = 500000;
00696 
00697         if( p_access->b_die )
00698             return 0;
00699     }
00700 
00701     if( i_ret < 0 )
00702     {
00703         msg_Err( p_access, "select error (%s)", strerror( errno ) );
00704         return -1;
00705     }
00706 
00707     i_ret = read( p_sys->i_fd, p_buffer, i_len );
00708     if( i_ret == 0 )
00709     {
00710         p_access->info.b_eof = VLC_TRUE;
00711     }
00712     else if( i_ret > 0 )
00713     {
00714         p_access->info.i_pos += i_ret;
00715     }
00716 
00717     return i_ret;
00718 }
00719 
00720 /*****************************************************************************
00721  * Control
00722  *****************************************************************************/
00723 static int Control( access_t *p_access, int i_query, va_list args )
00724 {
00725     vlc_bool_t   *pb_bool;
00726     int          *pi_int;
00727     int64_t      *pi_64;
00728 
00729     switch( i_query )
00730     {
00731         /* */
00732         case ACCESS_CAN_SEEK:
00733         case ACCESS_CAN_FASTSEEK:
00734             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00735             *pb_bool = VLC_FALSE;
00736             break;
00737         case ACCESS_CAN_PAUSE:
00738             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00739             *pb_bool = VLC_FALSE;
00740             break;
00741         case ACCESS_CAN_CONTROL_PACE:
00742             pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
00743             *pb_bool = VLC_FALSE;
00744             break;
00745 
00746         /* */
00747         case ACCESS_GET_MTU:
00748             pi_int = (int*)va_arg( args, int * );
00749             *pi_int = 0;
00750             break;
00751 
00752         case ACCESS_GET_PTS_DELAY:
00753             pi_64 = (int64_t*)va_arg( args, int64_t * );
00754             *pi_64 = (int64_t)var_GetInteger( p_access, "pvr-caching" ) * 1000;
00755             break;
00756 
00757         /* */
00758         case ACCESS_SET_PAUSE_STATE:
00759             /* Nothing to do */
00760             break;
00761 
00762         case ACCESS_GET_TITLE_INFO:
00763         case ACCESS_SET_TITLE:
00764         case ACCESS_SET_SEEKPOINT:
00765         case ACCESS_SET_PRIVATE_ID_STATE:
00766             return VLC_EGENERIC;
00767 
00768         default:
00769             msg_Warn( p_access, "unimplemented query in control" );
00770             return VLC_EGENERIC;
00771 
00772     }
00773     return VLC_SUCCESS;
00774 }

Generated on Tue Dec 20 10:14:26 2005 for vlc-0.8.4a by  doxygen 1.4.2