1 /*
2     Copyright (C) 2005, 2006, 2008, 2012 Rocky Bernstein <rocky@gnu.org>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 /** \file track.h
19  *  \brief  The top-level header for track-related libcdio calls.
20  */
21 #ifndef CDIO_TRACK_H_
22 #define CDIO_TRACK_H_
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27 
28   /*! Printable tags for track_format_t enumeration.  */
29   extern const char *track_format2str[6];
30 
31   typedef enum  {
32     TRACK_FORMAT_AUDIO,   /**< Audio track, e.g. CD-DA */
33     TRACK_FORMAT_CDI,     /**< CD-i. How this is different from DATA below? */
34     TRACK_FORMAT_XA,      /**< Mode2 of some sort */
35     TRACK_FORMAT_DATA,    /**< Mode1 of some sort */
36     TRACK_FORMAT_PSX,     /**< Playstation CD. Like audio but only 2336 bytes
37                            *   of user data.
38                            */
39     TRACK_FORMAT_ERROR    /**< Dunno what is, or some other error. */
40   } track_format_t;
41 
42   typedef enum {
43     CDIO_TRACK_FLAG_FALSE,
44     CDIO_TRACK_FLAG_TRUE,
45     CDIO_TRACK_FLAG_ERROR,
46     CDIO_TRACK_FLAG_UNKNOWN
47   } track_flag_t;
48 
49   /*! \brief Structure containing attributes associated with a track */
50   typedef struct {
51     track_flag_t preemphasis; /**< Linear preemphasis on an audio track */
52     track_flag_t copy_permit; /**< Whether copying is permitted */
53     int channels;             /**< Number of audio channels, 2, 4. -2 if not
54                                    implemented or -1 for error.
55                               */
56   } track_flags_t;
57 
58   /*! The leadout track is always 0xAA, regardless of # of tracks on
59     disc, or what value may be used internally. For example although
60     OS X uses a different value for the lead-out track internally than
61     given below, programmers should use CDIO_CDROM_LEADOUT_TRACK and
62     not worry about this.
63   */
64 
65   /*! An enumeration for some of the CDIO_CDROM_* \#defines below. This
66     isn't really an enumeration one would really use in a program; it
67     is to be helpful in debuggers where wants just to refer to the
68     CDIO_CDROM_* names and get something.
69   */
70   extern enum cdio_track_enums {
71     CDIO_CDROM_LBA           = 0x01, /**< "logical block": first frame is #0 */
72     CDIO_CDROM_MSF           = 0x02, /**< "minute-second-frame": binary, not
73                                         BCD here! */
74     CDIO_CDROM_DATA_TRACK    = 0x04,
75     CDIO_CDROM_CDI_TRACK     = 0x10,
76     CDIO_CDROM_XA_TRACK      = 0x20,
77     CDIO_CD_MAX_TRACKS       =   99, /**< Largest CD track number */
78     CDIO_CDROM_LEADOUT_TRACK = 0xAA, /**< Lead-out track number */
79     CDIO_INVALID_TRACK       = 0xFF, /**<  Constant for invalid track number */
80 
81    } cdio_track_enums;
82 
83 #define CDIO_CD_MIN_TRACK_NO  1 /**< Smallest CD track number */
84 
85   /*! track modes (Table 350)
86     reference: MMC-3 draft revsion - 10g
87   */
88   typedef enum {
89     AUDIO,                      /**< 2352 byte block length */
90     MODE1,                      /**< 2048 byte block length */
91     MODE1_RAW,                  /**< 2352 byte block length */
92     MODE2,                      /**< 2336 byte block length */
93     MODE2_FORM1,                /**< 2048 byte block length */
94     MODE2_FORM2,                /**< 2324 byte block length */
95     MODE2_FORM_MIX,             /**< 2336 byte block length */
96     MODE2_RAW                   /**< 2352 byte block length */
97   } trackmode_t;
98 
99   /*!
100     Get the number of the first track.
101 
102     @return the track number or CDIO_INVALID_TRACK
103     on error.
104   */
105   track_t cdio_get_first_track_num(const CdIo_t *p_cdio);
106 
107   /*!
108     Return the last track number.
109     CDIO_INVALID_TRACK is returned on error.
110   */
111   track_t cdio_get_last_track_num (const CdIo_t *p_cdio);
112 
113 
114   /*! Find the track which contains lsn.
115     CDIO_INVALID_TRACK is returned if the lsn outside of the CD or
116     if there was some error.
117 
118     If the lsn is before the pregap of the first track 0 is returned.
119     Otherwise we return the track that spans the lsn.
120   */
121   track_t cdio_get_track(const CdIo_t *p_cdio, lsn_t lsn);
122 
123   /*! Return number of channels in track: 2 or 4; -2 if not
124       implemented or -1 for error.
125       Not meaningful if track is not an audio track.
126   */
127   int cdio_get_track_channels(const CdIo_t *p_cdio, track_t i_track);
128 
129   /*! Return copy protection status on a track. Is this meaningful
130       if not an audio track?
131    */
132   track_flag_t cdio_get_track_copy_permit(const CdIo_t *p_cdio,
133                                           track_t i_track);
134 
135   /*!
136     Get the format (audio, mode2, mode1) of track.
137   */
138   track_format_t cdio_get_track_format(const CdIo_t *p_cdio, track_t i_track);
139 
140   /*!
141     Return true if we have XA data (green, mode2 form1) or
142     XA data (green, mode2 form2). That is track begins:
143     sync - header - subheader
144     12     4      -  8
145 
146     FIXME: there's gotta be a better design for this and get_track_format?
147   */
148   bool cdio_get_track_green(const CdIo_t *p_cdio, track_t i_track);
149 
150   /*!
151     Return the ending LSN for track number
152     i_track in cdio.  CDIO_INVALID_LSN is returned on error.
153   */
154   lsn_t cdio_get_track_last_lsn(const CdIo_t *p_cdio, track_t i_track);
155 
156   /*!
157     Get the starting LBA for track number
158     i_track in p_cdio.  Track numbers usually start at something
159     greater than 0, usually 1.
160 
161     The "leadout" track is specified either by
162     using i_track CDIO_CDROM_LEADOUT_TRACK or the total tracks+1.
163 
164     @param p_cdio object to get information from
165     @param i_track  the track number we want the LSN for
166     @return the starting LBA or CDIO_INVALID_LBA on error.
167   */
168   lba_t cdio_get_track_lba(const CdIo_t *p_cdio, track_t i_track);
169 
170   /*!
171     Return the starting LSN for track number
172     i_track in p_cdio.  Track numbers usually start at something
173     greater than 0, usually 1.
174 
175     The "leadout" track is specified either by
176     using i_track CDIO_CDROM_LEADOUT_TRACK or the total tracks+1.
177 
178     @param p_cdio object to get information from
179     @param i_track  the track number we want the LSN for
180     @return the starting LSN or CDIO_INVALID_LSN on error.
181   */
182   lsn_t cdio_get_track_lsn(const CdIo_t *p_cdio, track_t i_track);
183 
184   /*!
185     Return the starting LBA for the pregap for track number
186     i_track in p_cdio.  Track numbers usually start at something
187     greater than 0, usually 1.
188 
189     @param p_cdio object to get information from
190     @param i_track  the track number we want the LBA for
191     @return the starting LBA or CDIO_INVALID_LBA on error.
192   */
193   lba_t cdio_get_track_pregap_lba(const CdIo_t *p_cdio, track_t i_track);
194 
195   /*!
196     Return the starting LSN for the pregap for track number
197     i_track in p_cdio.  Track numbers usually start at something
198     greater than 0, usually 1.
199 
200     @param p_cdio object to get information from
201     @param i_track  the track number we want the LSN for
202     @return the starting LSN or CDIO_INVALID_LSN on error.
203   */
204   lsn_t cdio_get_track_pregap_lsn(const CdIo_t *p_cdio, track_t i_track);
205 
206   /*!
207     Get the International Standard Recording Code (ISRC) for track number
208     i_track in p_cdio.  Track numbers usually start at something
209     greater than 0, usually 1.
210 
211     @return the International Standard Recording Code (ISRC) or NULL
212     if there is none or we don't have the ability to get it.
213 
214     Note: The caller must free the returned string with cdio_free()
215     when done with it.
216 
217   */
218   char * cdio_get_track_isrc (const CdIo_t *p_cdio, track_t i_track);
219 
220   /*!
221     Return the starting MSF (minutes/secs/frames) for track number
222     i_track in p_cdio.  Track numbers usually start at something
223     greater than 0, usually 1.
224 
225     The "leadout" track is specified either by
226     using i_track CDIO_CDROM_LEADOUT_TRACK or the total tracks+1.
227 
228     @return true if things worked or false if there is no track entry.
229   */
230   bool cdio_get_track_msf(const CdIo_t *p_cdio, track_t i_track,
231                           /*out*/ msf_t *msf);
232 
233   /*! Get linear preemphasis status on an audio track
234       This is not meaningful if not an audio track?
235    */
236   track_flag_t cdio_get_track_preemphasis(const CdIo_t *p_cdio,
237                                           track_t i_track);
238 
239   /*!
240     Get the number of sectors between this track an the next.  This
241     includes any pregap sectors before the start of the next track.
242     Track numbers usually start at something
243     greater than 0, usually 1.
244 
245     @return the number of sectors or 0 if there is an error.
246   */
247   unsigned int cdio_get_track_sec_count(const CdIo_t *p_cdio, track_t i_track);
248 
249 #ifdef __cplusplus
250 }
251 #endif /* __cplusplus */
252 
253 #endif /* CDIO_TRACK_H_ */
254