Commit 3475fc64 authored by Sam Hocevar's avatar Sam Hocevar

   * Heavy butchery in the VCD plugin. It should no longer segfault when
     reaching end of title.
parent 7756c6e8
......@@ -9,7 +9,7 @@
* -dvd_udf to find files
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
* $Id: input_dvd.c,v 1.108 2001/12/19 18:14:23 sam Exp $
* $Id: input_dvd.c,v 1.109 2001/12/19 23:19:20 sam Exp $
*
* Author: Stphane Borel <stef@via.ecp.fr>
*
......@@ -955,6 +955,7 @@ intf_WarnMsg( 2, "Sector: 0x%x Read: %d Chapter: %d", p_dvd->i_sector, i_block_o
/* MPEG-2 Pack header. */
i_packet_size = 8;
}
if( i_pos != 0 )
{
pp_packets[i_packet] = input_ShareBuffer(
......
......@@ -7,7 +7,7 @@
# Objects
#
PLUGIN_VCD = vcd.o input_vcd.o linux_cdrom_tools.o $(OBJ_VCD)
PLUGIN_VCD = vcd.o input_vcd.o linux_cdrom_tools.o
BUILTIN_VCD = $(PLUGIN_VCD:%.o=BUILTIN_%.o)
ALL_OBJ = $(PLUGIN_VCD) $(BUILTIN_VCD)
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* input_vcd.h: thread structure of the VCD plugin
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
* $Id: input_vcd.h,v 1.1 2001/10/23 03:17:49 jobi Exp $
* $Id: input_vcd.h,v 1.2 2001/12/19 23:19:20 sam Exp $
*
* Author: Johan Bilien <jobi@via.ecp.fr>
*
......@@ -21,25 +21,17 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
/*****************************************************************************
* thread_vcd_data_t: VCD information
*****************************************************************************/
typedef struct thread_vcd_data_s
{
int vcdhandle; // File descriptor
int nb_tracks; // Nb of tracks (titles)
int current_track; // Current track
int current_sector; // Current Sector
int * tracks_sector; // index of tracks
boolean_t b_end_of_track; // if the end of track is
// reached
} thread_vcd_data_t ;
int i_handle; /* File descriptor */
int nb_tracks; /* Nb of tracks (titles) */
int i_track; /* Current track */
int i_sector; /* Current Sector */
int * p_sectors; /* Track sectors */
boolean_t b_end_of_track; /* If the end of track was reached */
} thread_vcd_data_t;
......@@ -20,11 +20,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
/*****************************************************************************
* Functions declared in this file use lots of ioctl calls, thus they are
* Linux-specific.
****************************************************************************/
#define MODULE_NAME vcd
#include "modules_inner.h"
/*****************************************************************************
* Preamble
*****************************************************************************/
#include "defs.h"
#include <stdio.h>
......@@ -74,126 +75,88 @@
#include "input_vcd.h"
#include "linux_cdrom_tools.h"
static void lba2msf( struct cdrom_msf0 *p_msf, int lba );
/*****************************************************************************
* read_toc : Reads the Table of Content of a CD-ROM and fills p_vcd with *
* the read information *
*****************************************************************************/
int read_toc ( thread_vcd_data_t * p_vcd )
{
int i ;
struct cdrom_tochdr tochdr ;
struct cdrom_tocentry tocent ;
int fd = p_vcd->vcdhandle ;
/* first we read the TOC header */
if (ioctl(fd, CDROMREADTOCHDR, &tochdr) == -1)
* VCDReadToc: Read the Table of Contents and fill p_vcd.
*****************************************************************************/
int VCDReadToc( thread_vcd_data_t * p_vcd )
{
int i;
struct cdrom_tochdr tochdr;
struct cdrom_tocentry tocent;
/* First we read the TOC header */
if( ioctl( p_vcd->i_handle, CDROMREADTOCHDR, &tochdr ) == -1 )
{
intf_ErrMsg("problem occured when reading CD's TOCHDR\n") ;
return -1 ;
intf_ErrMsg( "vcd error: could not read TOCHDR" );
return -1;
}
p_vcd->nb_tracks = tochdr.cdth_trk1;
p_vcd->nb_tracks = tochdr.cdth_trk1 - tochdr.cdth_trk0 + 1;
/* nb_tracks + 1 because we put the lead_out tracks for computing last
track's size */
p_vcd->tracks_sector = malloc( ( p_vcd->nb_tracks + 1 )
* sizeof( int ) );
if ( p_vcd->tracks_sector == NULL )
* track's size */
p_vcd->p_sectors = malloc( ( p_vcd->nb_tracks + 1 ) * sizeof( int ) );
if ( p_vcd->p_sectors == NULL )
{
intf_ErrMsg("could not malloc tracks_sector");
intf_ErrMsg( "vcd error: could not allocate p_sectors" );
return -1;
}
/* then for each track we read its TOC entry */
for( i=tochdr.cdth_trk0 ; i <= tochdr.cdth_trk1 ; i++ )
/* Fill the p_sectors structure with the track/sector matches */
for( i = 0 ; i <= p_vcd->nb_tracks ; i++ )
{
tocent.cdte_track = i;
tocent.cdte_format = CDROM_LBA;
if (ioctl( fd, CDROMREADTOCENTRY, &tocent) == -1 )
tocent.cdte_track =
( i == p_vcd->nb_tracks ) ? CDROM_LEADOUT : tochdr.cdth_trk0 + i;
if( ioctl( p_vcd->i_handle, CDROMREADTOCENTRY, &tocent ) == -1 )
{
intf_ErrMsg( "problem occured when reading CD's TOCENTRY\n" );
free ( p_vcd->tracks_sector );
return -1;
intf_ErrMsg( "vcd error: could not read TOCENTRY" );
free ( p_vcd->p_sectors );
return -1;
}
p_vcd->tracks_sector[i-1] = tocent.cdte_addr.lba ;
p_vcd->p_sectors[ i ] = tocent.cdte_addr.lba;
}
/* finally we read the lead-out track toc entry */
tocent.cdte_track = CDROM_LEADOUT ;
tocent.cdte_format = CDROM_LBA ;
if (ioctl(fd, CDROMREADTOCENTRY, &tocent) == -1)
{
intf_ErrMsg("problem occured when readind CD's
lead-out track TOC entry") ;
free (p_vcd->tracks_sector) ;
return -1 ;
}
p_vcd->tracks_sector[p_vcd->nb_tracks] = tocent.cdte_addr.lba ;
return 1 ;
return 1;
}
/****************************************************************************
* VCD_sector_read : Function that reads a sector (2324 bytes) from VCD
* VCDReadSector: Read a sector (2324 bytes)
****************************************************************************/
int VCD_sector_read ( struct thread_vcd_data_s * p_vcd, byte_t * p_buffer )
int VCDReadSector( struct thread_vcd_data_s * p_vcd, byte_t * p_buffer )
{
byte_t p_read_block[VCD_SECTOR_SIZE] ;
struct cdrom_msf0 msf_cursor ;
lba2msf( &msf_cursor, p_vcd->current_sector ) ;
byte_t p_block[ VCD_SECTOR_SIZE ];
int i_dummy = p_vcd->i_sector + 2 * CD_FRAMES;
#define p_msf ((struct cdrom_msf0 *)p_block)
p_msf->minute = i_dummy / (CD_FRAMES * CD_SECS);
p_msf->second = ( i_dummy % (CD_FRAMES * CD_SECS) ) / CD_FRAMES;
p_msf->frame = ( i_dummy % (CD_FRAMES * CD_SECS) ) % CD_FRAMES;
#undef p_msf
#ifdef DEBUG
intf_DbgMsg("Playing frame %d:%d-%d\n", msf_cursor.minute,
msf_cursor.second, msf_cursor.frame) ;
intf_DbgMsg( "vcd debug: playing frame %d:%d-%d",
p_msf->minute, p_msf->second, p_msf->frame);
#endif
memcpy(p_read_block, &msf_cursor, sizeof(struct cdrom_msf0)) ;
if (ioctl(p_vcd->vcdhandle, CDROMREADRAW, p_read_block) == -1)
if( ioctl(p_vcd->i_handle, CDROMREADRAW, p_block) == -1 )
{
intf_ErrMsg("problem occured when reading CD") ;
free (p_read_block) ;
return -1 ;
intf_ErrMsg( "vcd error: could not read block from disc" );
return -1;
}
/* we don't want to keep the header of the read sector */
memcpy( p_buffer, &p_read_block[VCD_DATA_START],
VCD_DATA_SIZE );
p_vcd->current_sector ++;
if ( p_vcd->current_sector ==
p_vcd->tracks_sector[p_vcd->current_track + 1] )
/* We don't want to keep the header of the read sector */
p_main->fast_memcpy( p_buffer, p_block + VCD_DATA_START, VCD_DATA_SIZE );
p_vcd->i_sector++;
if( p_vcd->i_sector >= p_vcd->p_sectors[p_vcd->i_track + 1] )
{
p_vcd->b_end_of_track = 1;
}
return 1;
}
/*****************************************************************************
* lba2msf : converts a logical block address into a minute/second/frame
* address.
*****************************************************************************/
static void lba2msf( struct cdrom_msf0 *p_msf, int lba )
{
/* we add 2*CD_FRAMES since the 2 first seconds are not played */
p_msf->minute = (lba+2*CD_FRAMES) / ( CD_FRAMES * CD_SECS ) ;
p_msf->second = ( (lba+2*CD_FRAMES) % ( CD_FRAMES * CD_SECS ) )
/ CD_FRAMES ;
p_msf->frame = ( (lba+2*CD_FRAMES) % ( CD_FRAMES * CD_SECS ) )
% CD_FRAMES ;
return 1;
}
......@@ -36,7 +36,6 @@
/******************************************************************************
* Prototypes *
******************************************************************************/
int read_toc ( struct thread_vcd_data_s *);
int VCD_sector_read ( struct thread_vcd_data_s *, byte_t *) ;
int VCDReadToc ( struct thread_vcd_data_s * );
int VCDReadSector ( struct thread_vcd_data_s *, byte_t * );
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment