1 /****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
7 * Authors: Johan Bilien <jobi@via.ecp.fr>
8 * Gildas Bazin <gbazin@netcourrier.com>
9 * Jon Lech Johansen <jon-vl@nanocrew.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
43 /*****************************************************************************
45 *****************************************************************************/
46 static void cd_log_handler (cdio_log_level_t level, const char message[]);
48 /*****************************************************************************
49 * ioctl_Open: Opens a VCD device or file and returns an opaque handle
50 *****************************************************************************/
51 cddev_t *ioctl_Open( vlc_object_t *p_this, const char *psz_dev )
55 if( !psz_dev ) return NULL;
58 * Initialize structure with default values
60 p_cddev = (cddev_t *)malloc( sizeof(cddev_t) );
63 msg_Err( p_this, "out of memory" );
67 /* Set where to log errors messages from libcdio. */
68 cdio_log_set_handler ( cd_log_handler );
70 p_cddev->cdio = cdio_open(psz_dev, DRIVER_UNKNOWN);
72 if( p_cddev->cdio == NULL )
81 /*****************************************************************************
82 * ioctl_Close: Closes an already opened VCD device or file.
83 *****************************************************************************/
84 void ioctl_Close( cddev_t *p_cddev )
86 cdio_destroy(p_cddev->cdio);
89 /*****************************************************************************
90 * ioctl_GetTracksMap: Read the Table of Contents, fill in the pp_sectors map
91 * if pp_sectors is not null and return the number of
93 * We allocate and fill one more track than are on
94 * the CD. The last "track" is leadout track information.
95 * This makes finding the end of the last track uniform
96 * how it is done for other tracks.
97 *****************************************************************************/
98 track_t ioctl_GetTracksMap( vlc_object_t *p_this, const CdIo *p_cdio,
101 track_t i_tracks = cdio_get_num_tracks(p_cdio);
102 track_t first_track = cdio_get_first_track_num(p_cdio);
105 if (CDIO_INVALID_TRACK == i_tracks)
108 *pp_sectors = malloc( (i_tracks + 1) * sizeof(lsn_t) );
109 if( *pp_sectors == NULL )
111 msg_Err( p_this, "out of memory" );
115 /* Fill the p_sectors structure with the track/sector matches.
116 Note cdio_get_track_lsn when given num_tracks + 1 will return
119 for( i = 0 ; i <= i_tracks ; i++ )
121 (*pp_sectors)[ i ] = cdio_get_track_lsn(p_cdio, first_track+i);
127 /****************************************************************************
128 * ioctl_ReadSector: Read a sector (2324 bytes)
129 ****************************************************************************/
130 int ioctl_ReadSector( vlc_object_t *p_this, const cddev_t *p_cddev,
131 int i_sector, byte_t * p_buffer )
134 uint8_t subheader [8];
135 uint8_t data [M2F2_SECTOR_SIZE];
137 vcdsector_t vcd_sector;
139 if( cdio_read_mode2_sector(p_cddev->cdio, &vcd_sector, i_sector, VLC_TRUE)
142 // msg_Err( p_this, "Could not read sector %d", i_sector );
146 memcpy (p_buffer, vcd_sector.data, M2F2_SECTOR_SIZE);
151 /****************************************************************************
153 ****************************************************************************/
155 /* For now we're going to just discard error messages from libcdio... */
157 cd_log_handler (cdio_log_level_t level, const char message[])