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

📄 vcd.c

📁 VLC媒体播放程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * vcd.c : VCD input module for vlc ***************************************************************************** * Copyright (C) 2000-2004 VideoLAN * $Id: vcd.c,v 1.25 2004/01/25 17:31:22 gbazin Exp $ * * Author: Johan Bilien <jobi@via.ecp.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdio.h>#include <stdlib.h>#include <vlc/vlc.h>#include <vlc/input.h>#include "../../demux/mpeg/system.h"#ifdef HAVE_UNISTD_H#   include <unistd.h>#endif#include <string.h>#include "cdrom.h"/* how many blocks VCDRead will read in each loop */#define VCD_BLOCKS_ONCE 20#define VCD_DATA_ONCE   (VCD_BLOCKS_ONCE * VCD_DATA_SIZE)/***************************************************************************** * thread_vcd_data_t: VCD information *****************************************************************************/typedef struct thread_vcd_data_s{    vcddev_t    *vcddev;                            /* vcd device descriptor */    int         i_nb_tracks;                        /* Nb of tracks (titles) */    int         i_track;                                    /* Current track */    int         i_sector;                                  /* Current Sector */    int *       p_sectors;                                  /* Track sectors */    int         i_entries_nb;                      /* Number of entry points */    int *       p_entries;                                   /* Entry points */    vlc_bool_t  b_valid_ep;                       /* Valid entry points flag */    vlc_bool_t  b_end_of_track;           /* If the end of track was reached */} thread_vcd_data_t;/***************************************************************************** * Local prototypes *****************************************************************************/static int  VCDOpen         ( vlc_object_t * );static void VCDClose        ( vlc_object_t * );static int  VCDRead         ( input_thread_t *, byte_t *, size_t );static void VCDSeek         ( input_thread_t *, off_t );static int  VCDSetArea      ( input_thread_t *, input_area_t * );static int  VCDSetProgram   ( input_thread_t *, pgrm_descriptor_t * );static int  VCDEntryPoints  ( input_thread_t * );/***************************************************************************** * Module descriptior *****************************************************************************/vlc_module_begin();    set_description( _("VCD input") );    set_capability( "access", 80 );    set_callbacks( VCDOpen, VCDClose );    add_shortcut( "svcd" );vlc_module_end();/* * Data reading functions *//***************************************************************************** * VCDOpen: open vcd *****************************************************************************/static int VCDOpen( vlc_object_t *p_this ){    input_thread_t *        p_input = (input_thread_t *)p_this;    char *                  psz_orig;    char *                  psz_parser;    char *                  psz_source;    char *                  psz_next;    thread_vcd_data_t *     p_vcd;    int                     i;    input_area_t *          p_area;    int                     i_title = 1;    int                     i_chapter = 1;    vcddev_t                *vcddev;    /* parse the options passed in command line : */    psz_orig = psz_parser = psz_source = strdup( p_input->psz_name );    if( !psz_orig )    {        return( -1 );    }    while( *psz_parser && *psz_parser != '@' )    {        psz_parser++;    }    if( *psz_parser == '@' )    {        /* Found options */        *psz_parser = '\0';        ++psz_parser;        i_title = (int)strtol( psz_parser, &psz_next, 10 );        if( *psz_next )        {            psz_parser = psz_next + 1;            i_chapter = (int)strtol( psz_parser, &psz_next, 10 );        }        i_title = i_title > 0 ? i_title : 1;        i_chapter = i_chapter > 0 ? i_chapter : 1;    }    if( !*psz_source )    {        if( !p_input->psz_access )        {            free( psz_orig );            return -1;        }        psz_source = config_GetPsz( p_input, "vcd" );        if( !psz_source ) return -1;    }    /* Open VCD */    if( !(vcddev = ioctl_Open( p_this, psz_source )) )    {        msg_Warn( p_input, "could not open %s", psz_source );        free( psz_source );        return -1;    }    p_vcd = malloc( sizeof(thread_vcd_data_t) );    if( p_vcd == NULL )    {        msg_Err( p_input, "out of memory" );        free( psz_source );        return -1;    }    free( psz_source );    p_vcd->vcddev = vcddev;    p_input->p_access_data = (void *)p_vcd;    p_input->i_mtu = VCD_DATA_ONCE;    vlc_mutex_lock( &p_input->stream.stream_lock );    p_input->stream.b_pace_control = 1;    p_input->stream.b_seekable = 1;    p_input->stream.p_selected_area->i_size = 0;    p_input->stream.p_selected_area->i_tell = 0;    vlc_mutex_unlock( &p_input->stream.stream_lock );    /* We read the Table Of Content information */    p_vcd->i_nb_tracks = ioctl_GetTracksMap( VLC_OBJECT(p_input),                                           p_vcd->vcddev, &p_vcd->p_sectors );    if( p_vcd->i_nb_tracks < 0 )        msg_Err( p_input, "unable to count tracks" );    else if( p_vcd->i_nb_tracks <= 1 )        msg_Err( p_input, "no movie tracks found" );    if( p_vcd->i_nb_tracks <= 1)    {        ioctl_Close( p_this, p_vcd->vcddev );        free( p_vcd );        return -1;    }    /* Allocate the entry points table */    p_vcd->p_entries = malloc( p_vcd->i_nb_tracks * sizeof( int ) );    if( p_vcd->p_entries == NULL )    {        msg_Err( p_input, "not enough memory" );        ioctl_Close( p_this, p_vcd->vcddev );        free( p_vcd );    }    /* Set stream and area data */    vlc_mutex_lock( &p_input->stream.stream_lock );    /* Initialize ES structures */    input_InitStream( p_input, sizeof( stream_ps_data_t ) );    /* disc input method */    p_input->stream.i_method = INPUT_METHOD_VCD;    p_input->stream.i_area_nb = 1;#define area p_input->stream.pp_areas    for( i = 1 ; i < p_vcd->i_nb_tracks; i++ )    {        /* Titles are Program Chains */        input_AddArea( p_input, i, 1 );        /* Absolute start offset and size */        area[i]->i_start = (off_t)p_vcd->p_sectors[i] * (off_t)VCD_DATA_SIZE;        area[i]->i_size = (off_t)(p_vcd->p_sectors[i+1] - p_vcd->p_sectors[i])                           * (off_t)VCD_DATA_SIZE;        /* Default Chapter */        area[i]->i_part = 1;        /* i_plugin_data is used to store which entry point is the first         * of the track (area) */        area[i]->i_plugin_data = 0;    }#undef area    p_area = p_input->stream.pp_areas[__MIN(i_title,p_vcd->i_nb_tracks -1)];    p_vcd->b_valid_ep = 1;    if( VCDEntryPoints( p_input ) < 0 )    {        msg_Warn( p_input, "could not read entry points, will not use them" );        p_vcd->b_valid_ep = 0;    }    VCDSetArea( p_input, p_area );    vlc_mutex_unlock( &p_input->stream.stream_lock );    if( !p_input->psz_demux || !*p_input->psz_demux )    {        p_input->psz_demux = "ps";    }    p_input->pf_read = VCDRead;    p_input->pf_seek = VCDSeek;    p_input->pf_set_area = VCDSetArea;    p_input->pf_set_program = VCDSetProgram;    return 0;}/***************************************************************************** * VCDClose: closes vcd *****************************************************************************/static void VCDClose( vlc_object_t *p_this ){    input_thread_t *   p_input = (input_thread_t *)p_this;    thread_vcd_data_t *p_vcd = (thread_vcd_data_t *)p_input->p_access_data;    ioctl_Close( p_this, p_vcd->vcddev );    free( p_vcd );}/***************************************************************************** * VCDRead: reads from the VCD into PES packets. ***************************************************************************** * Returns -1 in case of error, 0 in case of EOF, otherwise the number of * bytes. *****************************************************************************/static int VCDRead( input_thread_t * p_input, byte_t * p_buffer,                     size_t i_len ){    thread_vcd_data_t *     p_vcd;    int                     i_blocks;    int                     i_index;    int                     i_read;    byte_t                  p_last_sector[ VCD_DATA_SIZE ];    p_vcd = (thread_vcd_data_t *)p_input->p_access_data;    i_read = 0;    /* Compute the number of blocks we have to read */    i_blocks = i_len / VCD_DATA_SIZE;

⌨️ 快捷键说明

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