⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pvr.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
                               strlen( "bitratemode=" ) ) )            {                char *psz_parser_init;                psz_parser += strlen( "bitratemode=" );                psz_parser_init = psz_parser;                while ( *psz_parser != ':' && *psz_parser != ','                         && *psz_parser != '\0' )                {                    psz_parser++;                }                if ( !strncmp( psz_parser_init, "vbr" ,                               psz_parser - psz_parser_init ) )                {                     p_sys->i_bitrate_mode = 0;                }                else if ( !strncmp( psz_parser_init, "cbr" ,                                    psz_parser - psz_parser_init ) )                {                    p_sys->i_bitrate_mode = 1;                }            }            else if( !strncmp( psz_parser, "size=",                               strlen( "size=" ) ) )            {                p_sys->i_width =                    strtol( psz_parser + strlen( "size=" ),                            &psz_parser, 0 );                p_sys->i_height =                    strtol( psz_parser + 1 ,                            &psz_parser, 0 );            }            else            {                char *psz_parser_init;                psz_parser_init = psz_parser;                while ( *psz_parser != ':' && *psz_parser != ',' && *psz_parser != '\0' )                {                    psz_parser++;                }                psz_device = calloc( psz_parser - psz_parser_init + 1, 1 );                strncpy( psz_device, psz_parser_init,                         psz_parser - psz_parser_init );            }            if( *psz_parser )                psz_parser++;            else                break;        }    }    //give a default value to psz_device if none has been specified    if ( psz_device == NULL )    {        psz_device = calloc( strlen( "/dev/videox" ) + 1, 1 );        strcpy( psz_device, "/dev/video0" );    }    free( psz_tofree );    /* open the device */    if( ( p_sys->i_fd = open( psz_device, O_RDWR ) ) < 0 )    {        msg_Err( p_access, "cannot open device (%s)", strerror( errno ) );        free( p_sys );        return VLC_EGENERIC;    }    else    {        msg_Dbg( p_access, "using video device: %s",psz_device);    }    free( psz_device );    /* set the input */    if ( p_sys->i_input != -1 )    {        if ( ioctl( p_sys->i_fd, VIDIOC_S_INPUT, &p_sys->i_input ) < 0 )        {            msg_Warn( p_access, "VIDIOC_S_INPUT failed" );        }        else        {            msg_Dbg( p_access, "input set to: %d", p_sys->i_input);        }    }    /* set the video standard */    if ( p_sys->i_standard != V4L2_STD_UNKNOWN )    {        if ( ioctl( p_sys->i_fd, VIDIOC_S_STD, &p_sys->i_standard ) < 0 )        {            msg_Warn( p_access, "VIDIOC_S_STD failed" );        }        else        {            msg_Dbg( p_access, "video standard set to: %x", p_sys->i_standard);        }    }    /* set the picture size */    if ( p_sys->i_width != -1 || p_sys->i_height != -1 )    {        struct v4l2_format vfmt;        vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;        if ( ioctl( p_sys->i_fd, VIDIOC_G_FMT, &vfmt ) < 0 )        {            msg_Warn( p_access, "VIDIOC_G_FMT failed" );        }        else        {            if ( p_sys->i_width != -1 )            {                vfmt.fmt.pix.width = p_sys->i_width;            }            if ( p_sys->i_height != -1 )            {                vfmt.fmt.pix.height = p_sys->i_height;            }            if ( ioctl( p_sys->i_fd, VIDIOC_S_FMT, &vfmt ) < 0 )            {                msg_Warn( p_access, "VIDIOC_S_FMT failed" );            }            else            {                msg_Dbg( p_access, "picture size set to: %dx%d",                         vfmt.fmt.pix.width, vfmt.fmt.pix.height );            }        }    }    /* set the frequency */    if ( p_sys->i_frequency != -1 )    {        int i_fd;        struct v4l2_tuner vt;        vt.index = 0; /* TODO: let the user choose the tuner */        memset( &vt.reserved, 0, sizeof(vt.reserved) );        if ( p_sys->i_frequency >= pi_radio_range[0]              && p_sys->i_frequency <= pi_radio_range[1] )        {            if( ( p_sys->i_radio_fd = open( psz_radio_device, O_RDWR ) ) < 0 )            {                msg_Err( p_access, "cannot open radio device (%s)",                         strerror( errno ) );                close( p_sys->i_fd );                free( p_sys );                return VLC_EGENERIC;            }            else            {                msg_Dbg( p_access, "using radio device: %s", psz_radio_device );            }            i_fd = p_sys->i_radio_fd;        }        else        {            i_fd = p_sys->i_fd;            p_sys->i_radio_fd = -1;        }        if ( ioctl( i_fd, VIDIOC_G_TUNER, &vt ) < 0 )        {            msg_Warn( p_access, "VIDIOC_G_TUNER failed (%s)",                      strerror( errno ) );        }        else        {            struct v4l2_frequency vf;            vf.tuner = vt.index;            if ( ioctl( i_fd, VIDIOC_G_FREQUENCY, &vf ) < 0 )            {                msg_Warn( p_access, "VIDIOC_G_FREQUENCY failed (%s)",                          strerror( errno ) );            }            else            {                if( vt.capability & V4L2_TUNER_CAP_LOW )                    vf.frequency = p_sys->i_frequency * 16;                else                    vf.frequency = (p_sys->i_frequency * 16 + 500) / 1000;                if( ioctl( i_fd, VIDIOC_S_FREQUENCY, &vf ) < 0 )                {                    msg_Warn( p_access, "VIDIOC_S_FREQUENCY failed (%s)",                              strerror( errno ) );                }                else                {                    msg_Dbg( p_access, "tuner frequency set to: %d",                             p_sys->i_frequency );                }            }        }    }    /* control parameters */    if ( p_sys->i_volume != -1 )    {        struct v4l2_control ctrl;        ctrl.id = V4L2_CID_AUDIO_VOLUME;        ctrl.value = p_sys->i_volume;        if ( ioctl( p_sys->i_fd, VIDIOC_S_CTRL, &ctrl ) < 0 )        {            msg_Warn( p_access, "VIDIOC_S_CTRL failed" );        }    }    /* codec parameters */    if ( p_sys->i_framerate != -1            || p_sys->i_bitrate_mode != -1            || p_sys->i_bitrate_peak != -1            || p_sys->i_keyint != -1            || p_sys->i_bframes != -1            || p_sys->i_bitrate != -1            || p_sys->i_audio_bitmask != -1 )    {        struct ivtv_ioctl_codec codec;        if ( ioctl( p_sys->i_fd, IVTV_IOC_G_CODEC, &codec ) < 0 )        {            msg_Warn( p_access, "IVTV_IOC_G_CODEC failed" );        }        else        {            if ( p_sys->i_framerate != -1 )            {                switch ( p_sys->i_framerate )                {                    case 30:                        codec.framerate = 0;                        break;                    case 25:                        codec.framerate = 1;                        break;                    default:                        msg_Warn( p_access, "invalid framerate, reverting to 25" );                        codec.framerate = 1;                        break;                }            }            if ( p_sys->i_bitrate != -1 )            {                codec.bitrate = p_sys->i_bitrate;            }            if ( p_sys->i_bitrate_peak != -1 )            {                codec.bitrate_peak = p_sys->i_bitrate_peak;            }            if ( p_sys->i_bitrate_mode != -1 )            {                codec.bitrate_mode = p_sys->i_bitrate_mode;            }            if ( p_sys->i_audio_bitmask != -1 )            {                codec.audio_bitmask = p_sys->i_audio_bitmask;            }            if ( p_sys->i_keyint != -1 )            {                codec.framespergop = p_sys->i_keyint;            }            if ( p_sys->i_bframes != -1 )            {                codec.bframes = p_sys->i_bframes;            }            if( ioctl( p_sys->i_fd, IVTV_IOC_S_CODEC, &codec ) < 0 )            {                msg_Warn( p_access, "IVTV_IOC_S_CODEC failed" );            }            else            {                msg_Dbg( p_access, "Setting codec parameters to:  framerate: %d, bitrate: %d/%d/%d",               codec.framerate, codec.bitrate, codec.bitrate_peak, codec.bitrate_mode );            }        }    }    /* do a quick read */#if 0    if ( p_sys->i_fd )    {        if ( read( p_sys->i_fd, psz_tmp, 1 ) )        {            msg_Dbg(p_input, "Could read byte from device");        }        else        {            msg_Warn(p_input, "Could not read byte from device");        }    }#endif    return VLC_SUCCESS;}/***************************************************************************** * Close: close the device *****************************************************************************/static void Close( vlc_object_t * p_this ){    access_t *p_access = (access_t*) p_this;    access_sys_t * p_sys = p_access->p_sys;    close( p_sys->i_fd );    if ( p_sys->i_radio_fd != -1 )        close( p_sys->i_radio_fd );    free( p_sys );}/***************************************************************************** * Read *****************************************************************************/static int Read( access_t * p_access, uint8_t * p_buffer, int i_len ){    access_sys_t * p_sys = p_access->p_sys;    int i_ret;    struct pollfd ufd;    ufd.fd = p_sys->i_fd;    ufd.events = POLLIN;    if( p_access->info.b_eof )        return 0;    do    {        if( p_access->b_die )            return 0;        ufd.revents = 0;    }    while( ( i_ret = poll( &ufd, 1, 500 ) ) == 0 );    if( i_ret < 0 )    {        msg_Err( p_access, "select error (%s)", strerror( errno ) );        return -1;    }    i_ret = read( p_sys->i_fd, p_buffer, i_len );    if( i_ret == 0 )    {        p_access->info.b_eof = VLC_TRUE;    }    else if( i_ret > 0 )    {        p_access->info.i_pos += i_ret;    }    return i_ret;}/***************************************************************************** * Control *****************************************************************************/static int Control( access_t *p_access, int i_query, va_list args ){    vlc_bool_t   *pb_bool;    int          *pi_int;    int64_t      *pi_64;    switch( i_query )    {        /* */        case ACCESS_CAN_SEEK:        case ACCESS_CAN_FASTSEEK:            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );            *pb_bool = VLC_FALSE;            break;        case ACCESS_CAN_PAUSE:            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );            *pb_bool = VLC_FALSE;            break;        case ACCESS_CAN_CONTROL_PACE:            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );            *pb_bool = VLC_FALSE;            break;        /* */        case ACCESS_GET_MTU:            pi_int = (int*)va_arg( args, int * );            *pi_int = 0;            break;        case ACCESS_GET_PTS_DELAY:            pi_64 = (int64_t*)va_arg( args, int64_t * );            *pi_64 = (int64_t)var_GetInteger( p_access, "pvr-caching" ) * 1000;            break;        /* */        case ACCESS_SET_PAUSE_STATE:            /* Nothing to do */            break;        case ACCESS_GET_TITLE_INFO:        case ACCESS_SET_TITLE:        case ACCESS_SET_SEEKPOINT:        case ACCESS_SET_PRIVATE_ID_STATE:            return VLC_EGENERIC;        default:            msg_Warn( p_access, "unimplemented query in control" );            return VLC_EGENERIC;    }    return VLC_SUCCESS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -