diff --git a/include/cdio/Makefile.am b/include/cdio/Makefile.am index 4049b403..768d13f2 100644 --- a/include/cdio/Makefile.am +++ b/include/cdio/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.16 2004/12/31 05:47:36 rocky Exp $ +# $Id: Makefile.am,v 1.17 2005/01/04 04:33:36 rocky Exp $ # # Copyright (C) 2003, 2004 Rocky Bernstein # @@ -31,6 +31,7 @@ libcdioinclude_HEADERS = \ cdtext.h \ cdtext.h \ cd_types.h \ + disc.h \ ds.h \ dvd.h \ iso9660.h \ diff --git a/include/cdio/cdio.h b/include/cdio/cdio.h index b8c72c86..d0104f2d 100644 --- a/include/cdio/cdio.h +++ b/include/cdio/cdio.h @@ -1,8 +1,8 @@ /* -*- c -*- - $Id: cdio.h,v 1.71 2005/01/02 22:43:41 rocky Exp $ + $Id: cdio.h,v 1.72 2005/01/04 04:33:36 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel - Copyright (C) 2003, 2004 Rocky Bernstein + Copyright (C) 2003, 2004, 2005 Rocky Bernstein 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 @@ -129,8 +129,6 @@ extern "C" { #define CDIO_MAX_DRIVER DRIVER_NRG #define CDIO_MAX_DEVICE_DRIVER DRIVER_WIN32 - extern const char *discmode2str[]; - /*! Printable tags for track_format_t enumeration. */ extern const char *track_format2str[6]; @@ -254,13 +252,6 @@ extern "C" { char ** cdio_get_devices_ret (/*in/out*/ driver_id_t *p_driver_id); - /*! - Get disc mode - the kind of CD (CD-DA, CD-ROM mode 1, CD-MIXED, etc. - that we've got. The notion of "CD" is extended a little to include - DVD's. - */ - discmode_t cdio_get_discmode (CdIo_t *p_cdio); - /*! Get the what kind of device we've got. @@ -309,14 +300,6 @@ extern "C" { */ driver_id_t cdio_get_driver_id (const CdIo_t *p_cdio); - /*! - Get the number of the first track. - - @return the track number or CDIO_INVALID_TRACK - on error. - */ - track_t cdio_get_first_track_num(const CdIo_t *p_cdio); - /*! Get the CD-ROM hardware info via a SCSI MMC INQUIRY command. False is returned if we had an error getting the information. @@ -325,41 +308,6 @@ extern "C" { /* out*/ cdio_hwinfo_t *p_hw_info ); - /*! - Return the Joliet level recognized for p_cdio. - */ - uint8_t cdio_get_joliet_level(const CdIo_t *p_cdio); - - /*! - Get the media catalog number (MCN) from the CD. - - @return the media catalog number r NULL if there is none or we - don't have the ability to get it. - - Note: string is malloc'd so caller has to free() the returned - string when done with it. - - */ - char * cdio_get_mcn (const CdIo_t *p_cdio); - - /*! - Get the number of tracks on the CD. - - @return the number of tracks, or CDIO_INVALID_TRACK if there is - an error. - */ - track_t cdio_get_num_tracks (const CdIo_t *p_cdio); - - /*! - Reposition read offset - Similar to (if not the same as) libc's lseek() - - @param p_cdio object to get information from - @param offset amount to seek - @param whence like corresponding parameter in libc's lseek, e.g. - SEEK_SET or SEEK_END. - @return (off_t) -1 on error. - */ off_t cdio_lseek(const CdIo_t *p_cdio, off_t offset, int whence); /*! @@ -955,5 +903,7 @@ extern "C" { /* Track-related functions. */ #include +/* Disc-related functions. */ +#include #endif /* __CDIO_H__ */ diff --git a/include/cdio/disc.h b/include/cdio/disc.h new file mode 100644 index 00000000..f6dc0691 --- /dev/null +++ b/include/cdio/disc.h @@ -0,0 +1,95 @@ +/* -*- c -*- + $Id: disc.h,v 1.1 2005/01/04 04:33:36 rocky Exp $ + + Copyright (C) 2004, 2005 Rocky Bernstein + + 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-1307 USA +*/ + +/** \file dic.h + * \brief The top-level header for disc-related libcdio calls + */ +#ifndef __CDIO_DISC_H__ +#define __CDIO_DISC_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + extern const char *discmode2str[]; + + /*! + Get the lsn of the end of the CD + + @return the leadout LSN or CDIO_INVALID_LSN if there is an error. + */ + unsigned int cdio_get_disc_last_lsn(const CdIo *p_cdio); + + /*! + Get disc mode - the kind of CD (CD-DA, CD-ROM mode 1, CD-MIXED, etc. + that we've got. The notion of "CD" is extended a little to include + DVD's. + */ + discmode_t cdio_get_discmode (CdIo_t *p_cdio); + + /*! + Get the lsn of the end of the CD + + @return the leadout LSN or CDIO_INVALID_LSN if there is an error. + */ + unsigned int cdio_get_disc_last_lsn(const CdIo *p_cdio); + + + /*! + Return the Joliet level recognized for p_cdio. + */ + uint8_t cdio_get_joliet_level(const CdIo_t *p_cdio); + + /*! + Get the media catalog number (MCN) from the CD. + + @return the media catalog number r NULL if there is none or we + don't have the ability to get it. + + Note: string is malloc'd so caller has to free() the returned + string when done with it. + + */ + char * cdio_get_mcn (const CdIo_t *p_cdio); + + /*! + Get the number of tracks on the CD. + + @return the number of tracks, or CDIO_INVALID_TRACK if there is + an error. + */ + track_t cdio_get_num_tracks (const CdIo_t *p_cdio); + + /*! + Reposition read offset + Similar to (if not the same as) libc's lseek() + + @param p_cdio object to get information from + @param offset amount to seek + @param whence like corresponding parameter in libc's lseek, e.g. + SEEK_SET or SEEK_END. + @return (off_t) -1 on error. + */ +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __CDIO_DISC_H__ */ + diff --git a/include/cdio/sector.h b/include/cdio/sector.h index 26e21a07..ee7fee97 100644 --- a/include/cdio/sector.h +++ b/include/cdio/sector.h @@ -1,5 +1,5 @@ /* - $Id: sector.h,v 1.30 2005/01/01 14:19:19 rocky Exp $ + $Id: sector.h,v 1.31 2005/01/04 04:33:36 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2003, 2004 Rocky Bernstein @@ -173,23 +173,10 @@ typedef enum { #define CDIO_CDROM_CDI_TRACK 0x10 #define CDIO_CDROM_XA_TRACK 0x20 -/*! The leadout track is always 0xAA, regardless of # of tracks on - disc, or what value may be used internally. For example although - OS X uses a different value for the lead-out track internally than - given below, programmers should use CDIO_CDROM_LEADOUT_TRACK and - not worry about this. - */ -#define CDIO_CDROM_LEADOUT_TRACK 0xAA - #define M2F2_SECTOR_SIZE 2324 #define M2SUB_SECTOR_SIZE 2332 #define M2RAW_SECTOR_SIZE 2336 -/*! Largest CD track number */ -#define CDIO_CD_MAX_TRACKS 99 -/*! Smallest CD track number */ -#define CDIO_CD_MIN_TRACK_NO 1 - /*! Largest CD session number */ #define CDIO_CD_MAX_SESSIONS 99 /*! Smallest CD session number */ diff --git a/include/cdio/track.h b/include/cdio/track.h index e6cd9992..4c396edd 100644 --- a/include/cdio/track.h +++ b/include/cdio/track.h @@ -1,5 +1,5 @@ /* -*- c -*- - $Id: track.h,v 1.2 2005/01/02 22:43:41 rocky Exp $ + $Id: track.h,v 1.3 2005/01/04 04:33:36 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -24,6 +24,24 @@ #ifndef __CDIO_TRACK_H__ #define __CDIO_TRACK_H__ +/*! The leadout track is always 0xAA, regardless of # of tracks on + disc, or what value may be used internally. For example although + OS X uses a different value for the lead-out track internally than + given below, programmers should use CDIO_CDROM_LEADOUT_TRACK and + not worry about this. + */ +#define CDIO_CDROM_LEADOUT_TRACK 0xAA + +/*! Largest CD track number */ +#define CDIO_CD_MAX_TRACKS 99 +/*! Smallest CD track number */ +#define CDIO_CD_MIN_TRACK_NO 1 + +/*! + Constant for invalid track number +*/ +#define CDIO_INVALID_TRACK 0xFF + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -52,6 +70,30 @@ extern "C" { int channels; } track_flags_t; + /*! + Get the number of the first track. + + @return the track number or CDIO_INVALID_TRACK + on error. + */ + track_t cdio_get_first_track_num(const CdIo_t *p_cdio); + + /*! + Return the last track number. + CDIO_INVALID_TRACK is returned on error. + */ + track_t cdio_get_last_track_num (const CdIo_t *p_cdio); + + + /*! Find the track which contans lsn. + CDIO_INVALID_TRACK is returned if the lsn outside of the CD or + if there was some error. + + If the lsn is before the pregap of the first track 0 is returned. + Otherwise we return the track that spans the lsn. + */ + track_t cdio_get_track(const CdIo_t *p_cdio, lsn_t lsn); + /*! Return number of channels in track: 2 or 4; -2 if not implemented or -1 for error. Not meaningful if track is not an audio track. @@ -76,8 +118,14 @@ extern "C" { FIXME: there's gotta be a better design for this and get_track_format? */ - bool cdio_get_track_green(const CdIo *p_cdio, track_t i_track); + bool cdio_get_track_green(const CdIo_t *p_cdio, track_t i_track); + /*! + Return the ending LSN for track number + i_track in cdio. CDIO_INVALID_LSN is returned on error. + */ + lsn_t cdio_get_track_last_lsn(const CdIo_t *p_cdio, track_t i_track); + /*! Get the starting LBA for track number i_track in p_cdio. Track numbers usually start at something @@ -90,7 +138,7 @@ extern "C" { @param i_track the track number we want the LSN for @return the starting LBA or CDIO_INVALID_LBA on error. */ - lba_t cdio_get_track_lba(const CdIo *p_cdio, track_t i_track); + lba_t cdio_get_track_lba(const CdIo_t *p_cdio, track_t i_track); /*! Return the starting MSF (minutes/secs/frames) for track number @@ -104,7 +152,7 @@ extern "C" { @param i_track the track number we want the LSN for @return the starting LSN or CDIO_INVALID_LSN on error. */ - lsn_t cdio_get_track_lsn(const CdIo *p_cdio, track_t i_track); + lsn_t cdio_get_track_lsn(const CdIo_t *p_cdio, track_t i_track); /*! Return the starting MSF (minutes/secs/frames) for track number @@ -116,13 +164,14 @@ extern "C" { @return true if things worked or false if there is no track entry. */ - bool cdio_get_track_msf(const CdIo *p_cdio, track_t i_track, + bool cdio_get_track_msf(const CdIo_t *p_cdio, track_t i_track, /*out*/ msf_t *msf); /*! Get linear preemphasis status on an audio track This is not meaningful if not an audio track? */ - track_flag_t cdio_get_track_preemphasis(const CdIo *p_cdio, track_t i_track); + track_flag_t cdio_get_track_preemphasis(const CdIo_t *p_cdio, + track_t i_track); /*! Get the number of sectors between this track an the next. This @@ -132,11 +181,11 @@ extern "C" { @return the number of sectors or 0 if there is an error. */ - unsigned int cdio_get_track_sec_count(const CdIo *p_cdio, track_t i_track); + unsigned int cdio_get_track_sec_count(const CdIo_t *p_cdio, track_t i_track); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __CDIO_H__ */ +#endif /* __CDIO_TRACK_H__ */ diff --git a/include/cdio/types.h b/include/cdio/types.h index dbe0214d..128ded9f 100644 --- a/include/cdio/types.h +++ b/include/cdio/types.h @@ -1,5 +1,5 @@ /* - $Id: types.h,v 1.24 2004/12/18 17:29:32 rocky Exp $ + $Id: types.h,v 1.25 2005/01/04 04:33:36 rocky Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004 Rocky Bernstein @@ -221,11 +221,6 @@ extern "C" { /*! The type of a track number 0..99. */ typedef uint8_t track_t; - /*! - Constant for invalid track number - */ -#define CDIO_INVALID_TRACK 0xFF - /*! The type of a session number 0..99. */ typedef uint8_t session_t; diff --git a/lib/driver/Makefile.am b/lib/driver/Makefile.am index b0426be6..df89e9fc 100644 --- a/lib/driver/Makefile.am +++ b/lib/driver/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.2 2004/12/31 07:51:43 rocky Exp $ +# $Id: Makefile.am,v 1.3 2005/01/04 04:33:36 rocky Exp $ # # Copyright (C) 2003, 2004 Rocky Bernstein # @@ -66,6 +66,7 @@ libcdio_sources = \ cdio.c \ cdtext.c \ cdtext_private.h \ + disc.c \ ds.c \ FreeBSD/freebsd.c \ FreeBSD/freebsd.h \ @@ -88,6 +89,7 @@ libcdio_sources = \ scsi_mmc.c \ scsi_mmc_private.h \ sector.c \ + track.c \ util.c lib_LTLIBRARIES = libcdio.la diff --git a/lib/driver/cdio.c b/lib/driver/cdio.c index bd8c018a..e8e1bce7 100644 --- a/lib/driver/cdio.c +++ b/lib/driver/cdio.c @@ -1,7 +1,7 @@ /* - $Id: cdio.c,v 1.4 2005/01/02 22:43:41 rocky Exp $ + $Id: cdio.c,v 1.5 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2003, 2004 Rocky Bernstein + Copyright (C) 2003, 2004, 2005 Rocky Bernstein Copyright (C) 2001 Herbert Valerio Riedel This program is free software; you can redistribute it and/or modify @@ -39,7 +39,7 @@ #include #include "cdio_private.h" -static const char _rcsid[] = "$Id: cdio.c,v 1.4 2005/01/02 22:43:41 rocky Exp $"; +static const char _rcsid[] = "$Id: cdio.c,v 1.5 2005/01/04 04:33:36 rocky Exp $"; const char *track_format2str[6] = @@ -489,21 +489,6 @@ cdio_get_devices_with_cap_ret (/*out*/ char* search_devices[], return drives_ret; } -/*! - Get medium associated with cd_obj. -*/ -discmode_t -cdio_get_discmode (CdIo *cd_obj) -{ - if (cd_obj == NULL) return CDIO_DISC_MODE_ERROR; - - if (cd_obj->op.get_discmode) { - return cd_obj->op.get_discmode (cd_obj->env); - } else { - return CDIO_DISC_MODE_NO_INFO; - } -} - /*! Return the the kind of drive capabilities of device. @@ -578,23 +563,6 @@ cdio_get_driver_id (const CdIo *cdio) return cdio->driver_id; } - -/*! - Return the number of the first track. - CDIO_INVALID_TRACK is returned on error. -*/ -track_t -cdio_get_first_track_num (const CdIo *p_cdio) -{ - if (NULL == p_cdio) return CDIO_INVALID_TRACK; - - if (p_cdio->op.get_first_track_num) { - return p_cdio->op.get_first_track_num (p_cdio->env); - } else { - return CDIO_INVALID_TRACK; - } -} - /*! Return a string containing the name of the driver in use. if CdIo is NULL (we haven't initialized a specific device driver), @@ -613,218 +581,12 @@ cdio_get_hwinfo (const CdIo *p_cdio, cdio_hwinfo_t *hw_info) } } -/*! - Return a string containing the name of the driver in use. - if CdIo is NULL (we haven't initialized a specific device driver), - then return NULL. -*/ -char * -cdio_get_mcn (const CdIo *p_cdio) -{ - if (p_cdio->op.get_mcn) { - return p_cdio->op.get_mcn (p_cdio->env); - } else { - return NULL; - } -} - -/*! - Return the number of tracks in the current medium. - CDIO_INVALID_TRACK is returned on error. -*/ -track_t -cdio_get_num_tracks (const CdIo *p_cdio) -{ - if (p_cdio == NULL) return CDIO_INVALID_TRACK; - - if (p_cdio->op.get_num_tracks) { - return p_cdio->op.get_num_tracks (p_cdio->env); - } else { - return CDIO_INVALID_TRACK; - } -} - -/*! Return number of channels in track: 2 or 4; -2 if not - implemented or -1 for error. - Not meaningful if track is not an audio track. -*/ -int -cdio_get_track_channels(const CdIo *p_cdio, track_t i_track) -{ - if (p_cdio->op.get_track_channels) { - return p_cdio->op.get_track_channels (p_cdio->env, i_track); - } else { - return -2; - } -} - -/*! Return copy protection status on a track. Is this meaningful - if not an audio track? -*/ -track_flag_t -cdio_get_track_copy_permit(const CdIo *p_cdio, track_t i_track) -{ - if (p_cdio->op.get_track_copy_permit) { - return p_cdio->op.get_track_copy_permit (p_cdio->env, i_track); - } else { - return CDIO_TRACK_FLAG_UNKNOWN; - } -} - -/*! - Get format of track. -*/ -track_format_t -cdio_get_track_format(const CdIo *p_cdio, track_t i_track) -{ - if (!p_cdio) return TRACK_FORMAT_ERROR; - - if (p_cdio->op.get_track_format) { - return p_cdio->op.get_track_format (p_cdio->env, i_track); - } else { - return TRACK_FORMAT_ERROR; - } -} - -/*! - Return true if we have XA data (green, mode2 form1) or - XA data (green, mode2 form2). That is track begins: - sync - header - subheader - 12 4 - 8 - - FIXME: there's gotta be a better design for this and get_track_format? -*/ -bool -cdio_get_track_green(const CdIo *cdio, track_t track_num) -{ - cdio_assert (cdio != NULL); - - if (cdio->op.get_track_green) { - return cdio->op.get_track_green (cdio->env, track_num); - } else { - return false; - } -} - -/*! - Return the starting LBA for track number - track_num in cdio. Tracks numbers start at 1. - The "leadout" track is specified either by - using track_num LEADOUT_TRACK or the total tracks+1. - CDIO_INVALID_LBA is returned on error. -*/ -lba_t -cdio_get_track_lba(const CdIo *cdio, track_t track_num) -{ - if (cdio == NULL) return CDIO_INVALID_LBA; - - if (cdio->op.get_track_lba) { - return cdio->op.get_track_lba (cdio->env, track_num); - } else { - msf_t msf; - if (cdio->op.get_track_msf) - if (cdio_get_track_msf(cdio, track_num, &msf)) - return cdio_msf_to_lba(&msf); - return CDIO_INVALID_LBA; - } -} - -/*! - Return the starting LSN for track number - track_num in cdio. Tracks numbers start at 1. - The "leadout" track is specified either by - using track_num LEADOUT_TRACK or the total tracks+1. - CDIO_INVALID_LBA is returned on error. -*/ -lsn_t -cdio_get_track_lsn(const CdIo *cdio, track_t track_num) -{ - if (cdio == NULL) return CDIO_INVALID_LBA; - - if (cdio->op.get_track_lba) { - return cdio_lba_to_lsn(cdio->op.get_track_lba (cdio->env, track_num)); - } else { - msf_t msf; - if (cdio_get_track_msf(cdio, track_num, &msf)) - return cdio_msf_to_lsn(&msf); - return CDIO_INVALID_LSN; - } -} - -/*! - Return the starting MSF (minutes/secs/frames) for track number - track_num in cdio. Track numbers start at 1. - The "leadout" track is specified either by - using track_num LEADOUT_TRACK or the total tracks+1. - False is returned if there is no track entry. -*/ -bool -cdio_get_track_msf(const CdIo *cdio, track_t track_num, /*out*/ msf_t *msf) -{ - cdio_assert (cdio != NULL); - - if (cdio->op.get_track_msf) { - return cdio->op.get_track_msf (cdio->env, track_num, msf); - } else if (cdio->op.get_track_lba) { - lba_t lba = cdio->op.get_track_lba (cdio->env, track_num); - if (lba == CDIO_INVALID_LBA) return false; - cdio_lba_to_msf(lba, msf); - return true; - } else { - return false; - } -} - -/*! Return copy protection status on a track. Is this meaningful - if not an audio track? -*/ -track_flag_t -cdio_get_track_preemphasis(const CdIo *p_cdio, track_t i_track) -{ - if (p_cdio->op.get_track_preemphasis) { - return p_cdio->op.get_track_preemphasis (p_cdio->env, i_track); - } else { - return CDIO_TRACK_FLAG_UNKNOWN; - } -} - -/*! - Return the number of sectors between this track an the next. This - includes any pregap sectors before the start of the next track. - Tracks start at 1. - 0 is returned if there is an error. -*/ -unsigned int -cdio_get_track_sec_count(const CdIo *cdio, track_t track_num) -{ - track_t num_tracks = cdio_get_num_tracks(cdio); - - if (track_num >=1 && track_num <= num_tracks) - return ( cdio_get_track_lba(cdio, track_num+1) - - cdio_get_track_lba(cdio, track_num) ); - return 0; -} - bool cdio_have_driver(driver_id_t driver_id) { return (*CdIo_all_drivers[driver_id].have_driver)(); } -/*! - Return the Joliet level recognized for p_cdio. -*/ -uint8_t -cdio_get_joliet_level(const CdIo *p_cdio) -{ - if (!p_cdio) return 0; - { - const generic_img_private_t *p_env - = (generic_img_private_t *) (p_cdio->env); - return p_env->i_joliet_level; - } -} - bool cdio_is_device(const char *psz_source, driver_id_t driver_id) { diff --git a/lib/driver/cdio_private.h b/lib/driver/cdio_private.h index a60b578c..11222c18 100644 --- a/lib/driver/cdio_private.h +++ b/lib/driver/cdio_private.h @@ -1,7 +1,7 @@ /* - $Id: cdio_private.h,v 1.3 2004/12/31 05:47:36 rocky Exp $ + $Id: cdio_private.h,v 1.4 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2003, 2004 Rocky Bernstein + Copyright (C) 2003, 2004, 2005 Rocky Bernstein 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 diff --git a/lib/driver/disc.c b/lib/driver/disc.c new file mode 100644 index 00000000..f41627b2 --- /dev/null +++ b/lib/driver/disc.c @@ -0,0 +1,65 @@ +/* + $Id: disc.c,v 1.1 2005/01/04 04:33:36 rocky Exp $ + + Copyright (C) 2003, 2004, 2005 Rocky Bernstein + Copyright (C) 2001 Herbert Valerio Riedel + + 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-1307 USA +*/ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include "cdio_private.h" + +/*! + Get medium associated with cd_obj. +*/ +discmode_t +cdio_get_discmode (CdIo *cd_obj) +{ + if (cd_obj == NULL) return CDIO_DISC_MODE_ERROR; + + if (cd_obj->op.get_discmode) { + return cd_obj->op.get_discmode (cd_obj->env); + } else { + return CDIO_DISC_MODE_NO_INFO; + } +} + +unsigned int +cdio_get_disc_last_lsn(const CdIo *p_cdio) +{ + return cdio_get_track_lsn(p_cdio, CDIO_CDROM_LEADOUT_TRACK); +} + +/*! + Return a string containing the name of the driver in use. + if CdIo is NULL (we haven't initialized a specific device driver), + then return NULL. +*/ +char * +cdio_get_mcn (const CdIo *p_cdio) +{ + if (p_cdio->op.get_mcn) { + return p_cdio->op.get_mcn (p_cdio->env); + } else { + return NULL; + } +} + diff --git a/lib/driver/generic.h b/lib/driver/generic.h index 435723e3..4194d4b1 100644 --- a/lib/driver/generic.h +++ b/lib/driver/generic.h @@ -1,7 +1,7 @@ /* - $Id: generic.h,v 1.4 2005/01/01 15:08:48 rocky Exp $ + $Id: generic.h,v 1.5 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2004 Rocky Bernstein + Copyright (C) 2004, 2005 Rocky Bernstein 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 diff --git a/lib/driver/image.h b/lib/driver/image.h index 25b632e6..115d19e1 100644 --- a/lib/driver/image.h +++ b/lib/driver/image.h @@ -1,7 +1,7 @@ /* - $Id: image.h,v 1.1 2004/12/18 17:29:32 rocky Exp $ + $Id: image.h,v 1.2 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2004 Rocky Bernstein + Copyright (C) 2004, 2005 Rocky Bernstein 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 diff --git a/lib/driver/image/bincue.c b/lib/driver/image/bincue.c index ec00af52..4e13e353 100644 --- a/lib/driver/image/bincue.c +++ b/lib/driver/image/bincue.c @@ -1,7 +1,7 @@ /* - $Id: bincue.c,v 1.3 2004/12/31 07:51:43 rocky Exp $ + $Id: bincue.c,v 1.4 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2002, 2003, 2004 Rocky Bernstein + Copyright (C) 2002, 2003, 2004, 2005 Rocky Bernstein Copyright (C) 2001 Herbert Valerio Riedel cue parsing routine adapted from cuetools Copyright (C) 2003 Svend Sanjay Sorensen @@ -26,7 +26,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: bincue.c,v 1.3 2004/12/31 07:51:43 rocky Exp $"; +static const char _rcsid[] = "$Id: bincue.c,v 1.4 2005/01/04 04:33:36 rocky Exp $"; #include "image.h" #include "cdio_assert.h" @@ -1185,6 +1185,7 @@ cdio_open_cue (const char *psz_cue_name) _set_arg_image (_data, "cue", psz_cue_name); _set_arg_image (_data, "source", psz_bin_name); + _set_arg_image (_data, "access-mode", "bincue"); free(psz_bin_name); if (_init_bincue(_data)) { diff --git a/lib/driver/image/cdrdao.c b/lib/driver/image/cdrdao.c index 702a1285..070cb2f9 100644 --- a/lib/driver/image/cdrdao.c +++ b/lib/driver/image/cdrdao.c @@ -1,7 +1,7 @@ /* - $Id: cdrdao.c,v 1.3 2004/12/31 07:51:43 rocky Exp $ + $Id: cdrdao.c,v 1.4 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2004 Rocky Bernstein + Copyright (C) 2004, 2005 Rocky Bernstein toc reading routine adapted from cuetools Copyright (C) 2003 Svend Sanjay Sorensen @@ -25,7 +25,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: cdrdao.c,v 1.3 2004/12/31 07:51:43 rocky Exp $"; +static const char _rcsid[] = "$Id: cdrdao.c,v 1.4 2005/01/04 04:33:36 rocky Exp $"; #include "image.h" #include "cdio_assert.h" @@ -1170,6 +1170,7 @@ cdio_open_cdrdao (const char *psz_cue_name) _set_arg_image (_data, "cue", psz_cue_name); _set_arg_image (_data, "source", psz_cue_name); + _set_arg_image (_data, "access-mode", "cdrdao"); if (_init_cdrdao(_data)) { return ret; diff --git a/lib/driver/image/nrg.c b/lib/driver/image/nrg.c index f9b6e205..edbb9aa1 100644 --- a/lib/driver/image/nrg.c +++ b/lib/driver/image/nrg.c @@ -1,5 +1,5 @@ /* - $Id: nrg.c,v 1.4 2005/01/01 14:55:58 rocky Exp $ + $Id: nrg.c,v 1.5 2005/01/04 04:33:36 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein Copyright (C) 2001, 2003 Herbert Valerio Riedel @@ -46,7 +46,7 @@ #include "_cdio_stdio.h" #include "nrg.h" -static const char _rcsid[] = "$Id: nrg.c,v 1.4 2005/01/01 14:55:58 rocky Exp $"; +static const char _rcsid[] = "$Id: nrg.c,v 1.5 2005/01/04 04:33:36 rocky Exp $"; /* reader */ @@ -1252,6 +1252,7 @@ cdio_open_nrg (const char *psz_source) _set_arg_image(_data, "source", (NULL == psz_source) ? DEFAULT_CDIO_DEVICE: psz_source); + _set_arg_image (_data, "access-mode", "Nero"); _data->psz_cue_name = strdup(_get_arg_image(_data, "source")); diff --git a/lib/driver/image_common.c b/lib/driver/image_common.c index 66ec5a69..fec4832b 100644 --- a/lib/driver/image_common.c +++ b/lib/driver/image_common.c @@ -1,5 +1,5 @@ /* - $Id: image_common.c,v 1.2 2005/01/01 15:08:48 rocky Exp $ + $Id: image_common.c,v 1.3 2005/01/04 04:33:36 rocky Exp $ Copyright (C) 2004 Rocky Bernstein @@ -72,6 +72,7 @@ _free_image (void *p_user_data) free_if_notnull(p_env->psz_mcn); free_if_notnull(p_env->psz_cue_name); + free_if_notnull(p_env->psz_access_mode); cdtext_destroy(&(p_env->gen.cdtext)); cdio_generic_stdio_free(p_env); free(p_env); @@ -239,27 +240,36 @@ get_track_preemphasis_image(const void *p_user_data, track_t i_track) 0 is returned if no error was found, and nonzero if there as an error. */ int -_set_arg_image (void *user_data, const char key[], const char value[]) +_set_arg_image (void *p_user_data, const char key[], const char value[]) { - _img_private_t *env = user_data; + _img_private_t *p_env = p_user_data; if (!strcmp (key, "source")) { - free_if_notnull (env->gen.source_name); + free_if_notnull (p_env->gen.source_name); if (!value) return -2; - env->gen.source_name = strdup (value); + p_env->gen.source_name = strdup (value); } else if (!strcmp (key, "cue")) { - free_if_notnull (env->psz_cue_name); + free_if_notnull (p_env->psz_cue_name); if (!value) return -2; - env->psz_cue_name = strdup (value); + p_env->psz_cue_name = strdup (value); + } + else if (!strcmp (key, "access-mode")) + { + free_if_notnull (p_env->psz_access_mode); + + if (!value) + return -2; + + p_env->psz_access_mode = strdup (value); } else return -1; diff --git a/lib/driver/image_common.h b/lib/driver/image_common.h index c05e63d1..b0e31490 100644 --- a/lib/driver/image_common.h +++ b/lib/driver/image_common.h @@ -1,7 +1,7 @@ /* - $Id: image_common.h,v 1.3 2004/12/31 07:51:43 rocky Exp $ + $Id: image_common.h,v 1.4 2005/01/04 04:33:36 rocky Exp $ - Copyright (C) 2004 Rocky Bernstein + Copyright (C) 2004, 2005 Rocky Bernstein 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 @@ -37,6 +37,10 @@ typedef struct { internal_position_t pos; char *psz_cue_name; + char *psz_access_mode; /* Just the name of the driver. + We add this for regularity with other + real CD drivers which has an access mode. + */ char *psz_mcn; /* Media Catalog Number (5.22.3) exactly 13 bytes */ track_info_t tocent[CDIO_CD_MAX_TRACKS+1]; /* entry info for each track diff --git a/lib/driver/libcdio.sym b/lib/driver/libcdio.sym index 65e29298..c644ccb5 100644 --- a/lib/driver/libcdio.sym +++ b/lib/driver/libcdio.sym @@ -44,6 +44,7 @@ cdio_get_devices_solaris cdio_get_devices_win32 cdio_get_devices_with_cap cdio_get_devices_with_cap_ret +cdio_get_disc_last_lsn cdio_get_discmode cdio_get_drive_cap cdio_get_drive_cap_dev @@ -52,12 +53,15 @@ cdio_get_driver_name cdio_get_first_track_num cdio_get_hwinfo cdio_get_joliet_level +cdio_get_last_track_num cdio_get_mcn cdio_get_num_tracks +cdio_get_track cdio_get_track_channels cdio_get_track_copy_permit cdio_get_track_format cdio_get_track_green +cdio_get_track_last_lsn cdio_get_track_lba cdio_get_track_lsn cdio_get_track_msf diff --git a/lib/driver/track.c b/lib/driver/track.c new file mode 100644 index 00000000..4b1f62dd --- /dev/null +++ b/lib/driver/track.c @@ -0,0 +1,306 @@ +/* + $Id: track.c,v 1.1 2005/01/04 04:33:36 rocky Exp $ + + Copyright (C) 2003, 2004, 2005 Rocky Bernstein + Copyright (C) 2001 Herbert Valerio Riedel + + 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-1307 USA +*/ + + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include "cdio_private.h" + +/*! + Return the number of the first track. + CDIO_INVALID_TRACK is returned on error. +*/ +track_t +cdio_get_first_track_num (const CdIo_t *p_cdio) +{ + if (NULL == p_cdio) return CDIO_INVALID_TRACK; + + if (p_cdio->op.get_first_track_num) { + return p_cdio->op.get_first_track_num (p_cdio->env); + } else { + return CDIO_INVALID_TRACK; + } +} + +/*! + Return the last track number. + CDIO_INVALID_TRACK is returned on error. +*/ +track_t +cdio_get_last_track_num (const CdIo_t *p_cdio) +{ + if (NULL == p_cdio) return CDIO_INVALID_TRACK; + { + const track_t i_first_track = cdio_get_first_track_num(p_cdio); + if ( CDIO_INVALID_TRACK != i_first_track ) { + const track_t i_tracks = cdio_get_num_tracks(p_cdio); + if ( CDIO_INVALID_TRACK != i_tracks ) + return i_first_track + i_tracks - 1; + } + return CDIO_INVALID_TRACK; + } +} + +/*! Return number of channels in track: 2 or 4; -2 if not + implemented or -1 for error. + Not meaningful if track is not an audio track. +*/ +int +cdio_get_track_channels(const CdIo_t *p_cdio, track_t i_track) +{ + if (p_cdio->op.get_track_channels) { + return p_cdio->op.get_track_channels (p_cdio->env, i_track); + } else { + return -2; + } +} + +/*! Return copy protection status on a track. Is this meaningful + if not an audio track? +*/ +track_flag_t +cdio_get_track_copy_permit(const CdIo_t *p_cdio, track_t i_track) +{ + if (p_cdio->op.get_track_copy_permit) { + return p_cdio->op.get_track_copy_permit (p_cdio->env, i_track); + } else { + return CDIO_TRACK_FLAG_UNKNOWN; + } +} + +/*! + Get format of track. +*/ +track_format_t +cdio_get_track_format(const CdIo_t *p_cdio, track_t i_track) +{ + if (!p_cdio) return TRACK_FORMAT_ERROR; + + if (p_cdio->op.get_track_format) { + return p_cdio->op.get_track_format (p_cdio->env, i_track); + } else { + return TRACK_FORMAT_ERROR; + } +} +/*! + Return the Joliet level recognized for p_cdio. +*/ +uint8_t +cdio_get_joliet_level(const CdIo_t *p_cdio) +{ + if (!p_cdio) return 0; + { + const generic_img_private_t *p_env + = (generic_img_private_t *) (p_cdio->env); + return p_env->i_joliet_level; + } +} + +/*! + Return the number of tracks in the current medium. + CDIO_INVALID_TRACK is returned on error. +*/ +track_t +cdio_get_num_tracks (const CdIo_t *p_cdio) +{ + if (p_cdio == NULL) return CDIO_INVALID_TRACK; + + if (p_cdio->op.get_num_tracks) { + return p_cdio->op.get_num_tracks (p_cdio->env); + } else { + return CDIO_INVALID_TRACK; + } +} + +/*! Find the track which contans lsn. + CDIO_INVALID_TRACK is returned if the lsn outside of the CD or + if there was some error. + + If the lsn is before the pregap of the first track 0 is returned. + Otherwise we return the track that spans the lsn. +*/ +track_t +cdio_get_track(const CdIo_t *p_cdio, lsn_t lsn) +{ + if (!p_cdio) return CDIO_INVALID_TRACK; + + { + track_t i_low_track = cdio_get_first_track_num(p_cdio); + track_t i_high_track = cdio_get_last_track_num(p_cdio)+1; /* LEADOUT */ + + if (CDIO_INVALID_TRACK == i_low_track + || CDIO_INVALID_TRACK == i_high_track ) return CDIO_INVALID_TRACK; + + if (lsn < cdio_get_track_lsn(p_cdio, i_low_track)) + return 0; /* We're in the pre-gap of first track */ + + if (lsn > cdio_get_track_lsn(p_cdio, i_high_track)) + return CDIO_INVALID_TRACK; /* We're beyond the end. */ + + do { + const track_t i_mid = (i_low_track + i_high_track) / 2; + if (lsn <= cdio_get_track_lsn(p_cdio, i_mid)) + i_high_track = i_mid; + else + i_low_track = i_mid + 1; + } while ( i_low_track < i_high_track ); + + return i_high_track; + } +} + +/*! + Return true if we have XA data (green, mode2 form1) or + XA data (green, mode2 form2). That is track begins: + sync - header - subheader + 12 4 - 8 + + FIXME: there's gotta be a better design for this and get_track_format? +*/ +bool +cdio_get_track_green(const CdIo_t *p_cdio, track_t i_track) +{ + if (p_cdio == NULL) { + return false; + } + + if (p_cdio->op.get_track_green) { + return p_cdio->op.get_track_green (p_cdio->env, i_track); + } else { + return false; + } +} + +/*! + Return the starting LBA for track number + track_num in cdio. Tracks numbers start at 1. + The "leadout" track is specified either by + using track_num LEADOUT_TRACK or the total tracks+1. + CDIO_INVALID_LBA is returned on error. +*/ +lba_t +cdio_get_track_lba(const CdIo_t *p_cdio, track_t i_track) +{ + if (!p_cdio) return CDIO_INVALID_LBA; + + if (p_cdio->op.get_track_lba) { + return p_cdio->op.get_track_lba (p_cdio->env, i_track); + } else { + msf_t msf; + if (p_cdio->op.get_track_msf) + if (cdio_get_track_msf(p_cdio, i_track, &msf)) + return cdio_msf_to_lba(&msf); + return CDIO_INVALID_LBA; + } +} + +/*! + Return the starting LSN for track number + i_track in cdio. Tracks numbers start at 1. + The "leadout" track is specified either by + using i_track LEADOUT_TRACK or the total tracks+1. + CDIO_INVALID_LBA is returned on error. +*/ +lsn_t +cdio_get_track_lsn(const CdIo_t *p_cdio, track_t i_track) +{ + if (p_cdio == NULL) return CDIO_INVALID_LSN; + + if (p_cdio->op.get_track_lba) { + return cdio_lba_to_lsn(p_cdio->op.get_track_lba (p_cdio->env, i_track)); + } else { + msf_t msf; + if (cdio_get_track_msf(p_cdio, i_track, &msf)) + return cdio_msf_to_lsn(&msf); + return CDIO_INVALID_LSN; + } +} + +/*! + Return the ending LSN for track number + i_track in cdio. CDIO_INVALID_LSN is returned on error. +*/ +lsn_t +cdio_get_track_last_lsn(const CdIo_t *p_cdio, track_t i_track) +{ + lsn_t lsn = cdio_get_track_lsn(p_cdio, i_track+1); + + if (CDIO_INVALID_LSN == lsn) return CDIO_INVALID_LSN; + /* Safe, we've always the leadout. */ + return lsn - 1; +} + +/*! + Return the starting MSF (minutes/secs/frames) for track number + i_track in cdio. Track numbers start at 1. + The "leadout" track is specified either by + using i_track LEADOUT_TRACK or the total tracks+1. + False is returned if there is no track entry. +*/ +bool +cdio_get_track_msf(const CdIo_t *p_cdio, track_t i_track, /*out*/ msf_t *msf) +{ + if (!p_cdio) return false; + + if (p_cdio->op.get_track_msf) { + return p_cdio->op.get_track_msf (p_cdio->env, i_track, msf); + } else if (p_cdio->op.get_track_lba) { + lba_t lba = p_cdio->op.get_track_lba (p_cdio->env, i_track); + if (lba == CDIO_INVALID_LBA) return false; + cdio_lba_to_msf(lba, msf); + return true; + } else { + return false; + } +} + +/*! Return copy protection status on a track. Is this meaningful + if not an audio track? +*/ +track_flag_t +cdio_get_track_preemphasis(const CdIo *p_cdio, track_t i_track) +{ + if (p_cdio->op.get_track_preemphasis) { + return p_cdio->op.get_track_preemphasis (p_cdio->env, i_track); + } else { + return CDIO_TRACK_FLAG_UNKNOWN; + } +} + +/*! + Return the number of sectors between this track an the next. This + includes any pregap sectors before the start of the next track. + Tracks start at 1. + 0 is returned if there is an error. +*/ +unsigned int +cdio_get_track_sec_count(const CdIo_t *p_cdio, track_t i_track) +{ + const track_t i_tracks = cdio_get_num_tracks(p_cdio); + + if (i_track >=1 && i_track <= i_tracks) + return ( cdio_get_track_lba(p_cdio, i_track+1) + - cdio_get_track_lba(p_cdio, i_track) ); + return 0; +}