#include <fcntl.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <string.h>
#include <errno.h>
-#ifdef STRNCASECMP_IN_STRINGS_H
-# include <strings.h>
-#endif
-
#if defined( WIN32 )
# include <io.h> /* read() */
#else
/* called from outside */
static int VCDInit ( struct input_thread_s * );
static void VCDEnd ( struct input_thread_s * );
-static int PSDemux ( struct input_thread_s * );
+static int VCDDemux ( struct input_thread_s * );
static int VCDRewind ( struct input_thread_s * );
static int VCDOpen ( struct input_thread_s *);
static int VCDSetArea ( struct input_thread_s *, struct input_area_s * );
static int VCDSetProgram ( struct input_thread_s *, pgrm_descriptor_t * );
-static ssize_t PSRead ( struct input_thread_s *, data_packet_t ** );
/*****************************************************************************
* Functions exported as capabilities. They are declared as static so that
* we don't pollute the namespace too much.
#define demux p_function_list->functions.demux
demux.pf_init = VCDInit;
demux.pf_end = VCDEnd;
- demux.pf_demux = PSDemux;
+ demux.pf_demux = VCDDemux;
demux.pf_rewind = VCDRewind;
#undef demux
}
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;
-
- p_vcd = malloc( sizeof(thread_vcd_data_t) );
-
- if( p_vcd == NULL )
- {
- intf_ErrMsg( "vcd error: out of memory" );
- return -1;
- }
+ struct stat stat_info;
+ thread_vcd_data_t * p_vcd;
+ int i;
+ input_area_t * p_area;
+ int i_title = 1;
+ int i_chapter = 1;
- p_input->i_mtu = VCD_DATA_ONCE;
- p_input->p_access_data = (void *)p_vcd;
+
/* parse the options passed in command line : */
psz_orig = psz_parser = psz_source = strdup( p_input->psz_name );
free( psz_orig );
return -1;
}
- psz_source = config_GetPszVariable( INPUT_VCD_DEVICE_VAR );
+ psz_source = config_GetPszVariable( "vcd_device" );
}
-
+
+ /* test the type of file given */
+
+ if( stat( psz_source, &stat_info ) == -1 )
+ {
+ intf_ErrMsg( "input: vcd: cannot stat() source `%s' (%s)",
+ psz_source, strerror(errno));
+ return( -1 );
+ }
+
+ if( !S_ISBLK(stat_info.st_mode) )
+ {
+ intf_WarnMsg( 3, "input : VCD plugin discarded"
+ " (not a valid drive)" );
+ return -1;
+ }
+
+
+ p_vcd = malloc( sizeof(thread_vcd_data_t) );
+
+ if( p_vcd == NULL )
+ {
+ intf_ErrMsg( "vcd error: out of memory" );
+ return -1;
+ }
+
+ p_input->p_access_data = (void *)p_vcd;
+
+ p_input->i_mtu = VCD_DATA_ONCE;
+
vlc_mutex_lock( &p_input->stream.stream_lock );
- /* If we are here we can control the pace... */
p_input->stream.b_pace_control = 1;
p_input->stream.b_seekable = 1;
if( p_vcd->nb_tracks < 0 )
{
intf_ErrMsg( "input: vcd: was unable to count tracks" );
+ close( p_vcd->i_handle );
free( p_vcd );
return -1;
}
else if( p_vcd->nb_tracks <= 1 )
{
intf_ErrMsg( "input: vcd: no movie tracks found" );
+ close( p_vcd->i_handle );
free( p_vcd );
return -1;
}
p_vcd->p_sectors = ioctl_GetSectors( p_vcd->i_handle,
psz_source );
- if ( p_vcd->p_sectors == NULL )
+ if( p_vcd->p_sectors == NULL )
{
input_BuffersEnd( p_input->p_method_data );
+ close( p_vcd->i_handle );
free( p_vcd );
return -1;
}
vlc_mutex_unlock( &p_input->stream.stream_lock );
p_input->psz_demux = "vcd";
-
+
return 0;
}
-
-
/*****************************************************************************
* VCDClose: closes vcd
*****************************************************************************/
static void VCDClose( struct input_thread_s *p_input )
{
- thread_vcd_data_t * p_vcd
- = (thread_vcd_data_t *)p_input->p_access_data;
+ thread_vcd_data_t *p_vcd = (thread_vcd_data_t *)p_input->p_access_data;
+
close( p_vcd->i_handle );
free( p_vcd );
}
p_vcd->i_sector ++;
if ( p_vcd->i_sector == p_vcd->p_sectors[p_vcd->i_track + 1] )
{
- /* FIXME we should go to next track */
- return 0;
+ input_area_t *p_area;
+
+ if ( p_vcd->i_track >= p_vcd->nb_tracks - 1 )
+ return 0; /* EOF */
+
+ p_area = p_input->stream.pp_areas[
+ p_input->stream.p_selected_area->i_id + 1 ];
+
+ intf_WarnMsg( 4, "input: vcd info: new title" );
+
+ p_area->i_part = 1;
+ VCDSetArea( p_input, p_area );
+
}
i_read += VCD_DATA_SIZE;
}
{
es_descriptor_t * p_es;
+ if( p_input->stream.i_method != INPUT_METHOD_VCD )
+ {
+ return -1;
+ }
+
vlc_mutex_lock( &p_input->stream.stream_lock );
/* Set program information. */
*****************************************************************************/
static void VCDEnd( input_thread_t * p_input )
{
- thread_vcd_data_t * p_vcd;
-
- input_BuffersEnd( p_input->p_method_data );
-
- p_vcd = (thread_vcd_data_t*)p_input->p_access_data;
-
- free( p_vcd );
+ ;
}
/*****************************************************************************
- * PSDemux: reads and demuxes data packets
+ * VCDDemux: reads and demuxes data packets
*****************************************************************************
* Returns -1 in case of error, 0 in case of EOF, otherwise the number of
* packets.
*****************************************************************************/
-static int PSDemux( input_thread_t * p_input )
+static int VCDDemux( input_thread_t * p_input )
{
int i;