X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fvcd%2Fcdrom.c;h=d1ac990aa584380778874409e0b5082a664be1f9;hb=6ee1e193fd896ab9a4729fde14f009d9ce629815;hp=b6cf06a37a40a5b5150ea53860794c4bbe21e9ca;hpb=235dfe295a7526232b8297f22e256d82d64aa801;p=vlc diff --git a/modules/access/vcd/cdrom.c b/modules/access/vcd/cdrom.c index b6cf06a37a..d1ac990aa5 100644 --- a/modules/access/vcd/cdrom.c +++ b/modules/access/vcd/cdrom.c @@ -1,8 +1,8 @@ /**************************************************************************** * cdrom.c: cdrom tools ***************************************************************************** - * Copyright (C) 1998-2001 VideoLAN - * $Id: cdrom.c,v 1.4 2002/10/15 19:56:59 gbazin Exp $ + * Copyright (C) 1998-2001 the VideoLAN team + * $Id$ * * Authors: Johan Bilien * Gildas Bazin @@ -12,7 +12,7 @@ * 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 @@ -20,50 +20,58 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** * Preamble *****************************************************************************/ -#include -#include - #include +#include #ifdef HAVE_UNISTD_H # include #endif -#include -#include -#include #include - -#ifdef HAVE_SYS_IOCTL_H -# include +#ifdef HAVE_SYS_TYPES_H +# include +#endif +#ifdef HAVE_SYS_STAT_H +# include +#endif +#ifdef HAVE_FCNTL_H +# include #endif #if defined( SYS_BSDI ) # include -#elif defined ( SYS_DARWIN ) +#elif defined ( __APPLE__ ) # include # include # include # include # include +#elif defined( HAVE_SCSIREQ_IN_SYS_SCSIIO_H ) +# include +# include +# include #elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H ) # include # include #elif defined( WIN32 ) # include # include -#else +#elif defined (__linux__) +# include # include +#else +# error FIXME #endif +#include "cdrom_internals.h" #include "cdrom.h" -#include "vcd.h" +#include /***************************************************************************** * ioctl_Open: Opens a VCD device or file and returns an opaque handle @@ -96,8 +104,7 @@ vcddev_t *ioctl_Open( vlc_object_t *p_this, const char *psz_dev ) * Check if we are dealing with a device or a file (vcd image) */ #ifdef WIN32 - if( strlen( psz_dev ) == 1 || - (strlen( psz_dev ) == 2 && psz_dev[1] == ':') ) + if( (strlen( psz_dev ) == 2 && psz_dev[1] == ':') ) { b_is_file = 0; } @@ -217,18 +224,18 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, * vcd device mode */ -#if defined( SYS_DARWIN ) +#if defined( __APPLE__ ) CDTOC *pTOC; int i_descriptors; - if( ( pTOC = darwin_getTOC( p_this, p_vcddev->psz_dev ) ) == NULL ) + if( ( pTOC = darwin_getTOC( p_this, p_vcddev ) ) == NULL ) { msg_Err( p_this, "failed to get the TOC" ); return 0; } - i_descriptors = darwin_getNumberOfDescriptors( pTOC ); + i_descriptors = CDTOCGetDescriptorCount( pTOC ); i_tracks = darwin_getNumberOfTracks( pTOC, i_descriptors ); if( pp_sectors ) @@ -247,7 +254,7 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, pTrackDescriptors = pTOC->descriptors; - for( i_tracks = 0, i = 0; i <= i_descriptors; i++ ) + for( i_tracks = 0, i = 0; i < i_descriptors; i++ ) { track = pTrackDescriptors[i].point; @@ -257,7 +264,7 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, if( track > CD_MAX_TRACK_NO || track < CD_MIN_TRACK_NO ) continue; - (*pp_sectors)[i_tracks++] = + (*pp_sectors)[i_tracks++] = CDConvertMSFToLBA( pTrackDescriptors[i].p ); } @@ -270,7 +277,7 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, } /* set leadout sector */ - (*pp_sectors)[i_tracks] = + (*pp_sectors)[i_tracks] = CDConvertMSFToLBA( pTrackDescriptors[i_leadout].p ); } @@ -428,11 +435,12 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, } } -#elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H ) +#elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H ) \ + || defined( HAVE_SCSIREQ_IN_SYS_SCSIIO_H ) struct ioc_toc_header tochdr; struct ioc_read_toc_entry toc_entries; - if( ioctl( p_vcddev->i_devicd_handle, CDIOREADTOCHEADER, &tochdr ) + if( ioctl( p_vcddev->i_device_handle, CDIOREADTOCHEADER, &tochdr ) == -1 ) { msg_Err( p_this, "could not read TOCHDR" ); @@ -455,7 +463,7 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, toc_entries.address_format = CD_LBA_FORMAT; toc_entries.starting_track = 0; toc_entries.data_len = ( i_tracks + 1 ) * - sizeof( struct cd_toc_entry ); + sizeof( struct cd_toc_entry ); toc_entries.data = (struct cd_toc_entry *) malloc( toc_entries.data_len ); if( toc_entries.data == NULL ) @@ -464,7 +472,7 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, free( *pp_sectors ); return 0; } - + /* Read the TOC */ if( ioctl( p_vcddev->i_device_handle, CDIOREADTOCENTRYS, &toc_entries ) == -1 ) @@ -474,11 +482,16 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, free( toc_entries.data ); return 0; } - + /* Fill the p_sectors structure with the track/sector matches */ for( i = 0 ; i <= i_tracks ; i++ ) { +#if defined( HAVE_SCSIREQ_IN_SYS_SCSIIO_H ) + /* FIXME: is this ok? */ + (*pp_sectors)[ i ] = toc_entries.data[i].addr.lba; +#else (*pp_sectors)[ i ] = ntohl( toc_entries.data[i].addr.lba ); +#endif } } #else @@ -531,12 +544,16 @@ int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev, } /**************************************************************************** - * ioctl_ReadSector: Read a sector (2324 bytes) + * ioctl_ReadSector: Read VCD or CDDA sectors ****************************************************************************/ -int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, - int i_sector, byte_t * p_buffer ) +int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev, + int i_sector, byte_t * p_buffer, int i_nb, int i_type ) { - byte_t p_block[ VCD_SECTOR_SIZE ]; + byte_t *p_block; + int i; + + if( i_type == VCD_TYPE ) p_block = malloc( VCD_SECTOR_SIZE * i_nb ); + else p_block = p_buffer; if( p_vcddev->i_vcdimage_handle != -1 ) { @@ -547,20 +564,18 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, SEEK_SET ) == -1 ) { msg_Err( p_this, "Could not lseek to sector %d", i_sector ); + if( i_type == VCD_TYPE ) free( p_block ); return -1; } - if( read( p_vcddev->i_vcdimage_handle, p_block, VCD_SECTOR_SIZE ) + if( read( p_vcddev->i_vcdimage_handle, p_block, VCD_SECTOR_SIZE * i_nb) == -1 ) { - // msg_Err( p_this, "Could not read sector %d", i_sector ); + msg_Err( p_this, "Could not read sector %d", i_sector ); + if( i_type == VCD_TYPE ) free( p_block ); return -1; } - /* We don't want to keep the header of the read sector */ - memcpy( p_buffer, p_block + VCD_DATA_START, VCD_DATA_SIZE ); - - return 0; } else { @@ -569,7 +584,7 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, * vcd device mode */ -#if defined( SYS_DARWIN ) +#if defined( __APPLE__ ) dk_cd_read_t cd_read; memset( &cd_read, 0, sizeof(cd_read) ); @@ -581,11 +596,12 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, cd_read.sectorType = kCDSectorTypeUnknown; cd_read.buffer = p_block; - cd_read.bufferLength = sizeof(p_block); + cd_read.bufferLength = VCD_SECTOR_SIZE * i_nb; if( ioctl( p_vcddev->i_device_handle, DKIOCCDREAD, &cd_read ) == -1 ) { msg_Err( p_this, "could not read block %d", i_sector ); + if( i_type == VCD_TYPE ) free( p_block ); return -1; } @@ -599,6 +615,7 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); if( hEvent == NULL ) { + if( i_type == VCD_TYPE ) free( p_block ); return -1; } @@ -616,6 +633,10 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, /* Operation code */ ssc.CDBByte[ 0 ] = READ_CD; + /* Sector type */ + ssc.CDBByte[ 1 ] = i_type == VCD_TYPE ? SECTOR_TYPE_MODE2_FORM2 : + SECTOR_TYPE_CDDA; + /* Start of LBA */ ssc.CDBByte[ 2 ] = ( i_sector >> 24 ) & 0xff; ssc.CDBByte[ 3 ] = ( i_sector >> 16 ) & 0xff; @@ -623,16 +644,17 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, ssc.CDBByte[ 5 ] = ( i_sector ) & 0xff; /* Transfer length */ - ssc.CDBByte[ 6 ] = 0; - ssc.CDBByte[ 7 ] = 0; - ssc.CDBByte[ 8 ] = 1; + ssc.CDBByte[ 6 ] = ( i_nb >> 16 ) & 0xff; + ssc.CDBByte[ 7 ] = ( i_nb >> 8 ) & 0xff; + ssc.CDBByte[ 8 ] = ( i_nb ) & 0xff; /* Data selection */ - ssc.CDBByte[ 9 ] = READ_CD_USERDATA_MODE2; + ssc.CDBByte[ 9 ] = i_type == VCD_TYPE ? READ_CD_RAW_MODE2 : + READ_CD_USERDATA; /* Result buffer */ ssc.SRB_BufPointer = p_block; - ssc.SRB_BufLen = VCD_SECTOR_SIZE; + ssc.SRB_BufLen = VCD_SECTOR_SIZE * i_nb; /* Initiate transfer */ ResetEvent( hEvent ); @@ -649,12 +671,9 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, /* check that the transfer went as planned */ if( ssc.SRB_Status != SS_COMP ) { + if( i_type == VCD_TYPE ) free( p_block ); return -1; } - - /* We don't want to keep the footer of the read sector */ - memcpy( p_buffer, p_block, VCD_DATA_SIZE ); - return 0; } else { @@ -663,32 +682,80 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, /* Initialize CDROM_RAW_READ structure */ cdrom_raw.DiskOffset.QuadPart = CD_SECTOR_SIZE * i_sector; - cdrom_raw.SectorCount = 1; - cdrom_raw.TrackMode = XAForm2; + cdrom_raw.SectorCount = i_nb; + cdrom_raw.TrackMode = i_type == VCD_TYPE ? XAForm2 : CDDA; if( DeviceIoControl( p_vcddev->h_device_handle, IOCTL_CDROM_RAW_READ, &cdrom_raw, sizeof(RAW_READ_INFO), p_block, - sizeof(p_block), &dwBytesReturned, NULL ) - == 0 ) + VCD_SECTOR_SIZE * i_nb, &dwBytesReturned, + NULL ) == 0 ) { - return -1; + if( i_type == VCD_TYPE ) + { + /* Retry in YellowMode2 */ + cdrom_raw.TrackMode = YellowMode2; + if( DeviceIoControl( p_vcddev->h_device_handle, + IOCTL_CDROM_RAW_READ, &cdrom_raw, + sizeof(RAW_READ_INFO), p_block, + VCD_SECTOR_SIZE * i_nb, &dwBytesReturned, + NULL ) == 0 ) + { + free( p_block ); + return -1; + } + } + else return -1; } - - /* We don't want to keep the header of the read sector */ - memcpy( p_buffer, p_block + VCD_DATA_START, VCD_DATA_SIZE ); + } - return 0; +#elif defined( HAVE_SCSIREQ_IN_SYS_SCSIIO_H ) + struct scsireq sc; + int i_ret; + + memset( &sc, 0, sizeof(sc) ); + sc.cmd[0] = 0xBE; + sc.cmd[1] = i_type == VCD_TYPE ? SECTOR_TYPE_MODE2_FORM2: + SECTOR_TYPE_CDDA; + sc.cmd[2] = (i_sector >> 24) & 0xff; + sc.cmd[3] = (i_sector >> 16) & 0xff; + sc.cmd[4] = (i_sector >> 8) & 0xff; + sc.cmd[5] = (i_sector >> 0) & 0xff; + sc.cmd[6] = (i_nb >> 16) & 0xff; + sc.cmd[7] = (i_nb >> 8) & 0xff; + sc.cmd[8] = (i_nb ) & 0xff; + sc.cmd[9] = i_type == VCD_TYPE ? READ_CD_RAW_MODE2 : READ_CD_USERDATA; + sc.cmd[10] = 0; /* sub channel */ + sc.cmdlen = 12; + sc.databuf = (caddr_t)p_block; + sc.datalen = VCD_SECTOR_SIZE * i_nb; + sc.senselen = sizeof( sc.sense ); + sc.flags = SCCMD_READ; + sc.timeout = 10000; + + i_ret = ioctl( i_fd, SCIOCCOMMAND, &sc ); + if( i_ret == -1 ) + { + msg_Err( p_this, "SCIOCCOMMAND failed" ); + if( i_type == VCD_TYPE ) free( p_block ); + return -1; + } + if( sc.retsts || sc.error ) + { + msg_Err( p_this, "SCSI command failed: status %d error %d\n", + sc.retsts, sc.error ); + if( i_type == VCD_TYPE ) free( p_block ); + return -1; } #elif defined( HAVE_IOC_TOC_HEADER_IN_SYS_CDIO_H ) - int i_size = VCD_SECTOR_SIZE; if( ioctl( p_vcddev->i_device_handle, CDRIOCSETBLOCKSIZE, &i_size ) == -1 ) { msg_Err( p_this, "Could not set block size" ); + if( i_type == VCD_TYPE ) free( p_block ); return( -1 ); } @@ -696,36 +763,60 @@ int ioctl_ReadSector( vlc_object_t *p_this, const vcddev_t *p_vcddev, i_sector * VCD_SECTOR_SIZE, SEEK_SET ) == -1 ) { msg_Err( p_this, "Could not lseek to sector %d", i_sector ); + if( i_type == VCD_TYPE ) free( p_block ); return( -1 ); } - if( read( p_vcddev->i_device_handle, p_block, VCD_SECTOR_SIZE ) == -1 ) + if( read( p_vcddev->i_device_handle, + p_block, VCD_SECTOR_SIZE * i_nb ) == -1 ) { msg_Err( p_this, "Could not read sector %d", i_sector ); + if( i_type == VCD_TYPE ) free( p_block ); return( -1 ); } #else - int i_dummy = i_sector + 2 * CD_FRAMES; + for( i = 0; i < i_nb; i++ ) + { + int i_dummy = i_sector + i + 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; +#define p_msf ((struct cdrom_msf0 *)(p_block + i * VCD_SECTOR_SIZE)) + 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 - if( ioctl(p_vcddev->i_device_handle, CDROMREADRAW, p_block) == -1 ) - { - msg_Err( p_this, "could not read block %i from disc", i_sector ); - return( -1 ); + if( ioctl( p_vcddev->i_device_handle, CDROMREADRAW, + p_block + i * VCD_SECTOR_SIZE ) == -1 ) + { + msg_Err( p_this, "could not read block %i from disc", + i_sector ); + + if( i == 0 ) + { + if( i_type == VCD_TYPE ) free( p_block ); + return( -1 ); + } + else break; + } } #endif + } - /* We don't want to keep the header of the read sector */ - memcpy( p_buffer, p_block + VCD_DATA_START, VCD_DATA_SIZE ); - - return( 0 ); + /* For VCDs, we don't want to keep the header and footer of the + * sectors read */ + if( i_type == VCD_TYPE ) + { + for( i = 0; i < i_nb; i++ ) + { + memcpy( p_buffer + i * VCD_DATA_SIZE, + p_block + i * VCD_SECTOR_SIZE + VCD_DATA_START, + VCD_DATA_SIZE ); + } + free( p_block ); } + + return( 0 ); } /**************************************************************************** @@ -742,13 +833,26 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev, char *p_pos; char *psz_vcdfile = NULL; char *psz_cuefile = NULL; - FILE *cuefile; + FILE *cuefile = NULL; char line[1024]; /* Check if we are dealing with a .cue file */ p_pos = strrchr( psz_dev, '.' ); if( p_pos && !strcmp( p_pos, ".cue" ) ) { + /* psz_dev must be the cue file. Let's assume there's a .bin + * file with the same filename */ + if( p_pos ) + { + psz_vcdfile = malloc( p_pos - psz_dev + 5 /* ".bin" */ ); + strncpy( psz_vcdfile, psz_dev, p_pos - psz_dev ); + strcpy( psz_vcdfile + (p_pos - psz_dev), ".bin"); + } + else + { + psz_vcdfile = malloc( strlen(psz_dev) + 5 /* ".bin" */ ); + sprintf( psz_vcdfile, "%s.bin", psz_dev ); + } psz_cuefile = strdup( psz_dev ); } else @@ -766,21 +870,38 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev, psz_cuefile = malloc( strlen(psz_dev) + 5 /* ".cue" */ ); sprintf( psz_cuefile, "%s.cue", psz_dev ); } + /* If we need to look up the .cue file, then we don't have to look for the vcd */ + psz_vcdfile = strdup( psz_dev ); } /* Open the cue file and try to parse it */ - msg_Dbg( p_this,"using .cue file: %s", psz_cuefile ); - cuefile = fopen( psz_cuefile, "rt" ); - if( cuefile && fscanf( cuefile, "FILE %c", line ) && + msg_Dbg( p_this,"trying .cue file: %s", psz_cuefile ); + cuefile = utf8_fopen( psz_cuefile, "rt" ); + if( cuefile == NULL ) + { + i_ret = -1; + msg_Dbg( p_this, "could not find .cue file" ); + goto error; + } + + msg_Dbg( p_this,"using vcd image file: %s", psz_vcdfile ); + p_vcddev->i_vcdimage_handle = utf8_open( psz_vcdfile, + O_RDONLY | O_NONBLOCK | O_BINARY, 0666 ); + + if( p_vcddev->i_vcdimage_handle == -1 && + fscanf( cuefile, "FILE %c", line ) && fgets( line, 1024, cuefile ) ) { + /* We have a cue file, but no valid vcd file yet */ + free( psz_vcdfile ); p_pos = strchr( line, '"' ); if( p_pos ) { *p_pos = 0; /* Take care of path standardization */ - if( *line != '/' && (p_pos = strrchr( psz_cuefile, '/' )) ) + if( *line != '/' && ((p_pos = strrchr( psz_cuefile, '/' )) + || (p_pos = strrchr( psz_cuefile, '\\' ) )) ) { psz_vcdfile = malloc( strlen(line) + (p_pos - psz_cuefile + 1) + 1 ); @@ -789,15 +910,17 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev, } else psz_vcdfile = strdup( line ); } + msg_Dbg( p_this,"using vcd image file: %s", psz_vcdfile ); + p_vcddev->i_vcdimage_handle = utf8_open( psz_vcdfile, + O_RDONLY | O_NONBLOCK | O_BINARY, 0666 ); } - if( psz_vcdfile ) + if( p_vcddev->i_vcdimage_handle == -1) { - msg_Dbg( p_this,"using vcd image file: %s", psz_vcdfile ); - p_vcddev->i_vcdimage_handle = open( psz_vcdfile, - O_RDONLY | O_NONBLOCK | O_BINARY ); - i_ret = (p_vcddev->i_vcdimage_handle == -1) ? -1 : 0; + i_ret = -1; + goto error; } + else i_ret = 0; /* Try to parse the i_tracks and p_sectors info so we can just forget * about the cuefile */ @@ -843,6 +966,7 @@ static int OpenVCDImage( vlc_object_t * p_this, const char *psz_dev, } +error: if( cuefile ) fclose( cuefile ); if( psz_cuefile ) free( psz_cuefile ); if( psz_vcdfile ) free( psz_vcdfile ); @@ -864,11 +988,11 @@ static void CloseVCDImage( vlc_object_t * p_this, vcddev_t *p_vcddev ) free( p_vcddev->p_sectors ); } -#if defined( SYS_DARWIN ) +#if defined( __APPLE__ ) /**************************************************************************** * darwin_getTOC: get the TOC ****************************************************************************/ -static CDTOC *darwin_getTOC( vlc_object_t * p_this, vcddev_t *p_vcddev ) +static CDTOC *darwin_getTOC( vlc_object_t * p_this, const vcddev_t *p_vcddev ) { mach_port_t port; char *psz_devname; @@ -876,7 +1000,7 @@ static CDTOC *darwin_getTOC( vlc_object_t * p_this, vcddev_t *p_vcddev ) CDTOC *pTOC = NULL; io_iterator_t iterator; io_registry_entry_t service; - CFDictionaryRef properties; + CFMutableDictionaryRef properties; CFDataRef data; /* get the device name */ @@ -897,7 +1021,7 @@ static CDTOC *darwin_getTOC( vlc_object_t * p_this, vcddev_t *p_vcddev ) } /* get service iterator for the device */ - if( ( ret = IOServiceGetMatchingServices( + if( ( ret = IOServiceGetMatchingServices( port, IOBSDNameMatching( port, 0, psz_devname ), &iterator ) ) != KERN_SUCCESS ) { @@ -909,10 +1033,10 @@ static CDTOC *darwin_getTOC( vlc_object_t * p_this, vcddev_t *p_vcddev ) service = IOIteratorNext( iterator ); IOObjectRelease( iterator ); - /* search for kIOCDMediaClass */ + /* search for kIOCDMediaClass */ while( service && !IOObjectConformsTo( service, kIOCDMediaClass ) ) { - if( ( ret = IORegistryEntryGetParentIterator( service, + if( ( ret = IORegistryEntryGetParentIterator( service, kIOServicePlane, &iterator ) ) != KERN_SUCCESS ) { msg_Err( p_this, "IORegistryEntryGetParentIterator: 0x%08x", ret ); @@ -961,55 +1085,35 @@ static CDTOC *darwin_getTOC( vlc_object_t * p_this, vcddev_t *p_vcddev ) } CFRelease( properties ); - IOObjectRelease( service ); - - return( pTOC ); -} - -/**************************************************************************** - * darwin_getNumberOfDescriptors: get number of descriptors in TOC - ****************************************************************************/ -static int darwin_getNumberOfDescriptors( CDTOC *pTOC ) -{ - int i_descriptors; - - /* get TOC length */ - i_descriptors = pTOC->length; - - /* remove the first and last session */ - i_descriptors -= ( sizeof(pTOC->sessionFirst) + - sizeof(pTOC->sessionLast) ); - - /* divide the length by the size of a single descriptor */ - i_descriptors /= sizeof(CDTOCDescriptor); + IOObjectRelease( service ); - return( i_descriptors ); + return( pTOC ); } /**************************************************************************** - * darwin_getNumberOfTracks: get number of tracks in TOC + * darwin_getNumberOfTracks: get number of tracks in TOC ****************************************************************************/ static int darwin_getNumberOfTracks( CDTOC *pTOC, int i_descriptors ) { u_char track; - int i, i_tracks = 0; - CDTOCDescriptor *pTrackDescriptors; + int i, i_tracks = 0; + CDTOCDescriptor *pTrackDescriptors = NULL; - pTrackDescriptors = pTOC->descriptors; + pTrackDescriptors = (CDTOCDescriptor *)pTOC->descriptors; - for( i = i_descriptors; i >= 0; i-- ) + for( i = i_descriptors; i > 0; i-- ) { track = pTrackDescriptors[i].point; if( track > CD_MAX_TRACK_NO || track < CD_MIN_TRACK_NO ) continue; - i_tracks++; + i_tracks++; } return( i_tracks ); } -#endif /* SYS_DARWIN */ +#endif /* __APPLE__ */ #if defined( WIN32 ) /***************************************************************************** @@ -1135,7 +1239,7 @@ static int win32_vcd_open( vlc_object_t * p_this, const char *psz_dev, else { FreeLibrary( hASPI ); - msg_Dbg( p_this, "%s: is not a cdrom drive", + msg_Dbg( p_this, "%c: is not a cdrom drive", psz_dev[0] ); return -1; }