1 /*  cdrdao - write audio CD-Rs in disc-at-once mode
2  *
3  *  Copyright (C) 1998-2002  Andreas Mueller <andreas@daneb.de>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef __CDRDRIVER_H__
21 #define __CDRDRIVER_H__
22 
23 #include "ScsiIf.h"
24 #include "Msf.h"
25 #include "TrackData.h"
26 #include "SubChannel.h"
27 #include "remote.h"
28 
29 class Toc;
30 class Track;
31 
32 #define OPT_DRV_GET_TOC_GENERIC   0x00010000
33 #define OPT_DRV_SWAP_READ_SAMPLES 0x00020000
34 #define OPT_DRV_NO_PREGAP_READ    0x00040000
35 #define OPT_DRV_RAW_TOC_BCD       0x00080000
36 #define OPT_DRV_RAW_TOC_HEX       0x00100000
37 #define OPT_DRV_NO_CDTEXT_READ    0x00200000
38 
39 
40 // reading capabilities
41 #define CDR_READ_CAP_AUDIO_PW_RAW    0x001
42 #define CDR_READ_CAP_AUDIO_RW_COOKED 0x002
43 #define CDR_READ_CAP_AUDIO_RW_RAW    0x004
44 #define CDR_READ_CAP_AUDIO_PQ_BCD    0x008
45 #define CDR_READ_CAP_AUDIO_PQ_HEX    0x010
46 #define CDR_READ_CAP_DATA_PW_RAW     0x020
47 #define CDR_READ_CAP_DATA_RW_COOKED  0x040
48 #define CDR_READ_CAP_DATA_RW_RAW     0x080
49 #define CDR_READ_CAP_DATA_PQ_BCD     0x100
50 #define CDR_READ_CAP_DATA_PQ_HEX     0x200
51 
52 #define CDR_AUDIO_SCAN_CAP (CDR_READ_CAP_AUDIO_PW_RAW|CDR_READ_CAP_AUDIO_PQ_BCD|CDR_READ_CAP_AUDIO_PQ_HEX)
53 
54 struct DiskInfo {
55   long capacity;          // recordable capacity of medium
56   Msf  manufacturerId;    // disk identification
57   int  recSpeedLow;       // lowest recording speed
58   int  recSpeedHigh;      // highest recording speed
59 
60   int sessionCnt;         // number of closed sessions
61   int lastTrackNr;        // number of last track on disk
62 
63   long lastSessionLba;    // start lba of first track of last closed session
64   long thisSessionLba;    // start lba of this session
65 
66   int diskTocType;        // type of CD TOC, only valid if CD-R is not empty
67 
68   unsigned int empty  : 1; // 1 for empty disk, else 0
69   unsigned int append : 1; // 1 if CD-R is appendable, else 0
70   unsigned int cdrw   : 1; // 1 if disk is a CD-RW
71 
72   struct {
73     unsigned int empty : 1;
74     unsigned int append : 1;
75     unsigned int cdrw : 1;
76     unsigned int capacity : 1;
77     unsigned int manufacturerId : 1;
78     unsigned int recSpeed : 1;
79   } valid;
80 };
81 
82 struct DriveInfo {
83   int maxReadSpeed;
84   int currentReadSpeed;
85   int maxWriteSpeed;
86   int currentWriteSpeed;
87 
88   unsigned int accurateAudioStream : 1;
89   unsigned int burnProof : 1;
90   unsigned int ricohJustLink : 1;
91   unsigned int ricohJustSpeed : 1;
92 };
93 
94 struct CdTextPack {
95   unsigned char packType;
96   unsigned char trackNumber;
97   unsigned char sequenceNumber;
98   unsigned char blockCharacter;
99   unsigned char data[12];
100   unsigned char crc0;
101   unsigned char crc1;
102 };
103 
104 struct CdToc {
105   int track;            // number
106   long start;           // LBA of track start
107   unsigned char adrCtl; // ADR/CTL field
108 };
109 
110 struct CdRawToc {
111   int sessionNr;
112   int point;
113   int min;
114   int sec;
115   int frame;
116   int pmin;
117   int psec;
118   int pframe;
119   unsigned char adrCtl;
120 };
121 
122 struct TrackInfo {
123   int trackNr;          // track number
124   unsigned char ctl;    // flags
125   TrackData::Mode mode; // track data mode
126   long start;           // absolute start position from CD TOC
127   long pregap;          // pre-gap length of track in blocks
128   long fill;            // number of blocks to fill with zero data at end
129   int indexCnt;         // number of index increments
130   long index[98];       // index marks
131   char isrcCode[13];    // ISRC code, valid if 'isrcCode[0] != 0'
132   char *filename;       // data file name
133   long bytesWritten;    // number of bytes written to file
134 };
135 
136 
137 class CdrDriver {
138 public:
139   CdrDriver(ScsiIf *scsiIf, unsigned long options);
140   virtual ~CdrDriver();
141 
142   // returns stored SCSI interface object
scsiIf()143   virtual ScsiIf *scsiIf() const { return scsiIf_; }
144 
145   // sets SCSI interface object
scsiIf(ScsiIf * i)146   void scsiIf(ScsiIf *i) { scsiIf_ = i; }
147 
148   // returns name of driver
driverName()149   virtual const char *driverName() const { return driverName_; }
150 
151   // returns options flags
options()152   virtual unsigned long options() const { return options_; }
153 
154   // returns 1 if drive takes audio samples in big endian byte order or
155   // 0 for little endian byte order
156   virtual int bigEndianSamples() const = 0;
157 
158   // return information about drive
driveInfo(bool showErrorMsg)159   virtual const DriveInfo *driveInfo(bool showErrorMsg) { return NULL; }
160 
161   // returns current writing speed
speed()162   virtual int speed() { return speed_; }
163 
164   // returns current reading speed
rspeed()165   virtual int rspeed() { return rspeed_; }
166 
167   // sets writing speed, returns 0 for OK or 1 for illegal speed,
168   // this function may send SCSI commands to the drive
169   virtual int speed(int) = 0;
170 
171   // sets reading speed, returns 0 for OK or 1 for illegal speed,
172   // this function may send SCSI commands to the drive
173   virtual bool rspeed(int);
174 
175   // sets/return buffer under run protection setting (if supported by
176   // the drive: 1 = enabled, 0 = disbaled
bufferUnderRunProtection()177   virtual int bufferUnderRunProtection() const {
178     return enableBufferUnderRunProtection_;
179   }
180 
bufferUnderRunProtection(int s)181   virtual void bufferUnderRunProtection(int s) {
182     enableBufferUnderRunProtection_ = s != 0 ? 1 : 0;
183   }
184 
185   // sets/return writing speed control setting (if supported by
186   // the drive: 1 = enabled, 0 = disbaled
writeSpeedControl()187   virtual int writeSpeedControl() const { return enableWriteSpeedControl_; }
188 
writeSpeedControl(int s)189   virtual void writeSpeedControl(int s) {
190     enableWriteSpeedControl_ = s != 0 ? 1 : 0; }
191 
192   // returns 1 if simulation mode, 0 for real writing
simulate()193   virtual bool simulate() const { return simulate_; }
194 
195   // sets simulation mode, returns 0 for OK, 1 if given mode is not supported
simulate(bool s)196   virtual void simulate(bool s) { simulate_ = s; }
197 
198   // Sets multi session mode (0: close session, 1: open next session).
199   // Returns 1 if multi session is not supported by driver, else 0
200   virtual int multiSession(bool);
201 
202   // Returns mutli session mode.
multiSession()203   virtual bool multiSession() const { return multiSession_; }
204 
205   // Returns/sets fast toc reading flag (no sub-channel analysis)
fastTocReading()206   virtual bool fastTocReading() const { return fastTocReading_; }
fastTocReading(bool f)207   virtual void fastTocReading(bool f) { fastTocReading_ = f; }
208 
209   // Returns/sets raw data track reading flag
rawDataReading()210   virtual bool rawDataReading() const { return rawDataReading_; }
rawDataReading(bool f)211   virtual void rawDataReading(bool f) { rawDataReading_ = f; }
212 
213   // Returns/sets mode2 mixed track reading flag
mode2Mixed()214   virtual bool mode2Mixed() const { return mode2Mixed_; }
mode2Mixed(bool f)215   virtual void mode2Mixed(bool f) { mode2Mixed_ = f; }
216 
subChanReadMode()217   virtual TrackData::SubChannelMode subChanReadMode() const { return subChanReadMode_; }
subChanReadMode(TrackData::SubChannelMode m)218   virtual void subChanReadMode(TrackData::SubChannelMode m) { subChanReadMode_ = m; }
219 
220   // Sets/returns the pad first pre-gap flag
padFirstPregap()221   virtual int padFirstPregap() const { return padFirstPregap_; }
padFirstPregap(int f)222   virtual void padFirstPregap(int f) { padFirstPregap_ = f != 0 ? 1 : 0; }
223 
224   // Returns the on-thy-fly flag.
onTheFly()225   virtual int onTheFly() const { return onTheFly_; }
226 
227   // Sets file descriptor for on the fly data and sets the on-the-fly flag
228   // if 'fd' is >= 0 and clears it otherwise
229   virtual void onTheFly(int fd);
230 
231   // Returns force flag
force()232   virtual bool force() const { return force_; }
233 
234   // Sets force flag
force(bool f)235   virtual void force(bool f) { force_ = f; }
236 
237   // Returns TAO source flag
taoSource()238   virtual bool taoSource() const { return taoSource_; }
239 
240   // Sets TAO source flag
taoSource(bool f)241   virtual void taoSource(bool f) { taoSource_ = f; }
242 
243   // Return number of adjust sectors for reading TAO source disks
taoSourceAdjust()244   virtual int taoSourceAdjust() const { return taoSourceAdjust_; }
245 
246   // Sets number of adjust sectors for reading TAO source disks
247   virtual void taoSourceAdjust(int val);
248 
249   // Sets remote mode
250   virtual void remote(int flag, int fd);
251 
252   // Return remote mode flag
remote()253   virtual int remote() { return remote_; }
254 
255   // Sets cdda paranoia mode
256   void paranoiaMode(int);
257 
258   // Sets user defined capacity
userCapacity(int c)259   virtual void userCapacity(int c) { userCapacity_ = c; }
260 
261   // Sets burning to the outer edge mode
fullBurn(bool f)262   virtual void fullBurn(bool f) { fullBurn_ = f; }
263 
264   // Return byte order of host (0: little endian, 1: big endian)
hostByteOrder()265   int hostByteOrder() const { return hostByteOrder_; }
266 
267   // general commands
268   virtual int testUnitReady(int) const;
269 
270   virtual int startStopUnit(int) const;
271 
272   virtual int preventMediumRemoval(int) const;
273 
274   virtual int rezeroUnit(int showMessage = 1) const;
275 
276   virtual int loadUnload(int) const = 0;
277 
278   virtual int flushCache() const;
279 
280   virtual int readCapacity(long *length, int showMessage = 1);
281 
readBufferCapacity(long * total,long * available)282   virtual bool readBufferCapacity(long* total, long* available) {
283     return false;
284   }
285 
286   // CD-RW specific commands
287 
288   enum BlankingMode { BLANK_FULL, BLANK_MINIMAL };
289   virtual int blankDisk(BlankingMode);
290 
291   // disk at once recording related commands
292 
293   // Returns acceptable sub-channel encoding mode for given sub-channel type:
294   //  -1: writing of sub-channel type not supported at all
295   //   0: accepts plain data without encoding
296   //   1: accepts only completely encoded data
297   virtual int subChannelEncodingMode(TrackData::SubChannelMode) const;
298 
299   // Should check if toc is suitable for DAO writing with the actual driver.
300   // Returns 0 if toc is OK, else 1.
301   // Usually all tocs are suitable for writing so that the base class
302   // implementation simply returns 0.
303   virtual int checkToc(const Toc *);
304 
305   // Used to make necessary initializations but without touching the CD-R.
306   // It should be possible to abort the writing process after this function
307   // has been called without destroying the CD-R.
308   virtual int initDao(const Toc *) = 0;
309 
310   // Performs all steps that must be done before the first user data block
311   // is written, e.g. sending cue sheet, writing lead-in.
312   virtual int startDao() = 0;
313 
314   // Performs all steps for successfully finishing the writing process,
315   // e.g. writing lead-out, flushing the cache.
316   virtual int finishDao() = 0;
317 
318   // Aborts writing process. Called if an error occurs or the user aborts
319   // recording prematurely.
320   virtual void abortDao() = 0;
321 
322   // Sends given data to drive. 'lba' should be the current writing address
323   // and will be updated according to the written number of blocks.
324   virtual int writeData(TrackData::Mode, TrackData::SubChannelMode sm,
325 			long &lba, const char *buf, long len);
326 
327   // returns mode for main channel data encoding, the value is used by
328   // Track::readData()
329   // 0: raw audio mode, all sectors must be encoded as audio sectors
330   // 1: no encoding for MODE1 and MODE2 sectors, MODE2_FORM1 and MODE2_FORM2
331   //    are extended by sub header and zero EDC/ECC data
encodingMode()332   int encodingMode() const { return encodingMode_; }
333 
334   // disk read commands
335 
336   // analyzes the CD structure (Q sub-channels) of the inserted CD
337   virtual Toc *readDiskToc(int session, const char *);
338 
339   // analyzes the CD structure and reads data
340   virtual Toc *readDisk(int session, const char *);
341 
342   // returns information about inserted medium
diskInfo()343   virtual DiskInfo *diskInfo() { return 0; }
344 
345 
346 
347   // Returns block size depending on given sector mode and 'encodingMode_'
348   // that must be used to send data to the recorder.
349   virtual long blockSize(TrackData::Mode, TrackData::SubChannelMode) const;
350 
351   // sends a status message to the driving application if in remote mode
352   enum WriteCdProgressType { WCD_LEADIN = PGSMSG_WCD_LEADIN,
353 			     WCD_DATA = PGSMSG_WCD_DATA,
354 			     WCD_LEADOUT = PGSMSG_WCD_LEADOUT };
355   int sendWriteCdProgressMsg(WriteCdProgressType type, int totalTracks,
356 			     int track, int trackProgress, int totalProgress,
357 			     int bufferFillRate, int writeBufferFill = 0);
358 
359   int sendBlankCdProgressMsg(int totalProgress);
360 
361 
362   // static functions
363 
364   // Selects driver id for given vendor/model string. NULL is returned if
365   // no driver could be selected.
366   // readWrite: 0: select a driver for read operations
367   //            1: select a driver for write operations
368   // options: filled with option flags for vendor/model
369   static const char *selectDriver(int readWrite, const char *vendor,
370 				  const char *model, unsigned long *options);
371 
372   // Creates instance of driver with specified id.
373   static CdrDriver *createDriver(const char *driverId, unsigned long options,
374 				 ScsiIf *);
375 
376   // Try to autodetect a driver on given Scsi interface.
377   static const char *detectDriver(ScsiIf *, unsigned long *options);
378 
379   // Prints list of all available driver ids.
380   static void printDriverIds();
381 
382   // returns vendor/type of CD-R medium
383   static int cdrVendor(Msf &, const char **vendor, const char** mediumType);
384 
385 protected:
386   struct ReadDiskInfo {
387     int tracks;    // total number of tracks
388     long startLba;      // LBA where extraction starts
389     long endLba;        // LBA where extraction ends
390   };
391 
392   unsigned long options_; // driver option flags
393   ScsiIf *scsiIf_;
394   int scsiMaxDataLen_;
395   const char *driverName_;
396 
397   int hostByteOrder_; // 0: little endian, 1: big endian
398 
399   unsigned long readCapabilities_;
400 
401   int blockLength_; // length of data block for 'writeData' command
402   long blocksPerWrite_; // number of blocks that can be written with a
403                         // single SCSI WRITE command
404   char *zeroBuffer_; // zeroed buffer for writing zeros
405 
406   int enableBufferUnderRunProtection_;
407   int enableWriteSpeedControl_;
408   int speed_;
409   int rspeed_;
410   bool simulate_;
411   bool multiSession_;
412   int encodingMode_; // mode for encoding data sectors
413   bool fastTocReading_;
414   bool rawDataReading_;
415   int mode2Mixed_;
416   TrackData::SubChannelMode subChanReadMode_;
417   int padFirstPregap_; // used by 'read-toc': defines if the first audio
418                        // track's pre-gap is padded with zeros in the toc-file
419                        // or if it is taken from the data file
420   int onTheFly_; // 1 if operating in on-the-fly mode
421   int onTheFlyFd_; // file descriptor for on the fly data
422   bool force_; // force flag to allow certain operations
423   int remote_; // 1 for remote mode, else 0
424   int remoteFd_; // file descriptor for remote messages
425   bool taoSource_; // 1 to indicate a TAO writting source CD for read-cd/read-toc
426   int taoSourceAdjust_; // number of unreadable sectors between two tracks
427                         // written in TAO mode
428   const Toc *toc_;
429 
430   SubChannel **scannedSubChannels_;
431   long maxScannedSubChannels_;
432 
433   unsigned char *transferBuffer_;
434 
435   // Byte order of audio samples read from the drive, e.g. with
436   // 'readSubChannels()'. 0: little endian, 1: big endian
437   int audioDataByteOrder_;
438 
439   int userCapacity_;
440   bool fullBurn_;
441 
442   static unsigned char syncPattern[12];
443   static unsigned char REMOTE_MSG_SYNC_[4];
444 
445   static int speed2Mult(int);
446   static int mult2Speed(int);
447 
448   virtual int sendCmd(const unsigned char *cmd, int cmdLen,
449 		      const unsigned char *dataOut, int dataOutLen,
450 		      unsigned char *dataIn, int dataInLen,
451 		      int showErrorMsg = 1) const;
452 
453   virtual int getModePage(int pageCode, unsigned char *buf, long bufLen,
454 			  unsigned char *modePageHeader,
455 			  unsigned char *blockDesc, int showErrorMsg);
456   virtual int setModePage(const unsigned char *buf,
457 			  const unsigned char *modePageHeader,
458 			  const unsigned char *blockDesc, int showErrorMsg);
459 
460   // some drives (e.g. Yamaha CDR100) don't implement mode sense/select(10)
461   virtual int getModePage6(int pageCode, unsigned char *buf, long bufLen,
462 			   unsigned char *modePageHeader,
463 			   unsigned char *blockDesc, int showErrorMsg);
464   virtual int setModePage6(const unsigned char *buf,
465 			   const unsigned char *modePageHeader,
466 			   const unsigned char *blockDesc, int showErrorMsg);
467 
468   virtual int writeZeros(TrackData::Mode, TrackData::SubChannelMode,
469 			 long &lba, long encLba, long count);
470 
471 
472   // Returns track control flags for given track, bits 0-3 are always zero
473   virtual unsigned char trackCtl(const Track *track);
474 
475   // Returns session format code for point A0 TOC entry, generated from
476   // stored 'toc_' object.
477   virtual unsigned char sessionFormat();
478 
479   // readToc related functions:
480 
481   // returns TOC data of specified session of inserted CD,
482   // a generic function is implemented in 'CdrDriver.cc', it will return
483   // the tracks of all session or of the first session depending on the
484   // drive
485   virtual CdToc *getToc(int sessionNr, int *nofTracks);
486 
487   // Generic function to retrieve basic TOC data. Cannot distinguish
488   // between different sessions.
489   CdToc *getTocGeneric(int *nofTracks);
490 
491   // Reads raw toc data of inserted CD. Used by base implementation of
492   // 'getToc()' and must be implemented by the actual driver.
493   virtual CdRawToc *getRawToc(int sessionNr, int *len) = 0;
494 
495   // Reads CD-TEXT packs from the lead-in of a CD. The base implementation
496   // uses the SCSI-3/mmc commands.
497   virtual CdTextPack *readCdTextPacks(long *);
498 
499   // reads CD-TEXT data and adds it to given 'Toc' object
500   int readCdTextData(Toc *);
501 
502   // Tries to determine the data mode of specified track.
503   virtual TrackData::Mode getTrackMode(int trackNr, long trackStartLba);
504 
505   // Determines mode of given sector, 'buf' should contain the sector header
506   // at the first 4 bytes followed by the sub-header for XA tracks.
507   // If an illegal mode is found in the sector header 'MODE0' will be
508   // returned.
509   TrackData::Mode determineSectorMode(unsigned char *buf);
510 
511   // analyzes given 8 byte sub header and returns wether the sector is
512   // a MODE2, MODE2_FORM1 or MODE2_FORM2 sector
513   TrackData::Mode analyzeSubHeader(unsigned char *);
514 
515   virtual unsigned long getReadCapabilities(const CdToc *, int) const = 0;
516 
517   // Called by 'readDiskToc()' to retrieve following information about
518   // the track 'trackNr' with given start/end lba addresses:
519   // - all index increments, filled into 'index'/'indexCnt'
520   // - ISRC Code, filled into provided buffer 'isrcCode' (13 bytes)
521   // - length of pre-gap of next track, filled into 'pregap'
522   // - control nibbles read from track, filled into bits 0-3 of 'ctrl',
523   //   bit 7 must be set to indicate valid data
524   // This function must be overloaded by an actual driver.
525   // return: 0: OK, 1: error occured
526   virtual int analyzeTrack(TrackData::Mode, int trackNr, long startLba,
527 			   long endLba, Msf *index,
528 			   int *indexCnt, long *pregap, char *isrcCode,
529 			   unsigned char *ctl) = 0;
530 
531   // Track analysis algorithm using the binary search method. The base
532   // class implements the basic algorithm. It uses 'findIndex()' which
533   // can be implemented by an actual driver to get the track and index
534   // number at a specific block address. This base class contains an
535   // implementation of 'findIndex()', too, that can be usually used.
536   // It'll be always better to use the linear scan algorithm (see below)
537   // if possible.
538   int analyzeTrackSearch(TrackData::Mode, int trackNr, long startLba,
539 			   long endLba, Msf *index,
540 			   int *indexCnt, long *pregap, char *isrcCode,
541 			   unsigned char *ctl);
542 
543   // finds position (lba) where index for given track number switches to
544   // 'index' (binary search, base algorithm is implemented in 'CdrDriver').
545   // It uses the method 'getTrackIndex()' which must be overloaded by
546   // the actual driver.
547   virtual long findIndex(int track, int index, long trackStart, long trackEnd);
548 
549   // Retrieves track, index and control nibbles at given lba address. Must
550   // be implemented by the driver if the binary search method
551   // ('analyzeTrackSearch()') should be used.
552   virtual int getTrackIndex(long lba, int *trackNr, int *indexNr,
553 			    unsigned char *ctl);
554 
555   // Basic track analyzis using the linear scan algorithm. The base class
556   // implements the basic algorithm which calls 'readSubChannels()' to
557   // read the sub-channel data. Actual drivers should overload the
558   // 'readSubChannels()' function.
559   int analyzeTrackScan(TrackData::Mode, int trackNr, long startLba,
560 		       long endLba, Msf *index, int *indexCnt, long *pregap,
561 		       char *isrcCode, unsigned char *ctl);
562 
563   // Reads 'len' sub-channels from sectors starting  at 'lba'.
564   // The returned vector contains 'len' pointers to 'SubChannel' objects.
565   // Audio data that is usually retrieved with the sub-channels is placed
566   // in 'buf' if it is not NULL.
567   // Used by 'analyzeTrackScan()' and 'readAudioRangeParanoia()'.
568   virtual int readSubChannels(TrackData::SubChannelMode, long lba, long len,
569 			      SubChannel ***, Sample *buf) = 0;
570 
571   // Determines the readable length of a data track and the pre-gap length
572   // of the following track. The implementation in the base class should
573   // be suitable for all drivers.
574   virtual int analyzeDataTrack(TrackData::Mode mode, int trackNr,
575 			       long startLba, long endLba, long *pregap);
576 
577   // Reads 'len' data sectors starting at 'lba' and returns the number of
578   // successfully read sectors. If the end of the current track is encountered
579   // the returned value will be smaller than 'len' down to 0. If a read
580   // error occus -1 is returned. If a L-EC error occures -2 is returned.
581   // This method is used by 'readDataTrack'/'analyzeDataTrack' and must be
582   // overloaded by the driver.
583   virtual long readTrackData(TrackData::Mode, TrackData::SubChannelMode,
584 			     long lba, long len, unsigned char *buf) = 0;
585 
586   // Reads a complete data track and saves data to a file.
587   virtual int readDataTrack(ReadDiskInfo *, int fp, long start, long end,
588 			    TrackInfo *trackInfo);
589 
590   // Reads the audio data of given audio track range 'startTrack', 'endTrack'.
591   // 'trackInfo' is am array of TrackInfo structures for all tracks.
592   // This function is called by 'readDisk()' and must be overloaded by the
593   // actual driver.
594   virtual int readAudioRange(ReadDiskInfo *, int fp, long start, long end,
595 			     int startTrack, int endTrack,
596 			     TrackInfo *) = 0;
597 
598   virtual int readAudioRangeStream(ReadDiskInfo *, int fd, long start,
599 				   long end, int startTrack, int endTrack,
600 				   TrackInfo *);
601 
602   // Reads catalog number by scanning the sub-channels.
603   // Uses 'readSubChannels()' to read the the sub-channels.
604   int readCatalogScan(char *mcnCode, long startLba, long endLba);
605 
606   // Reads catalog number and stores it in given 'Toc' object. Must be
607   // implemented by the actual driver. 'startLba' and 'endLba' specify
608   // the allowed range for sub-channel scanning.
609   virtual int readCatalog(Toc *toc, long startLba, long endLba) = 0;
610 
611   // Reads ISRC code and writes into provided 13 bytes buffer. Must be
612   // implemented by the actual driver.
613   virtual int readIsrc(int trackNr, char *) = 0;
614 
615   // Build Toc object from gathered TrackInfo data
616   Toc *buildToc(TrackInfo *trackInfos, long nofTrackInfos, int padFirstPregap);
617 
618   // sets block size for read/write operations
619   virtual int setBlockSize(long blocksize, unsigned char density = 0);
620 
621   // checks if drive capabilities support requested sub-channel reading mode
622   int checkSubChanReadCaps(TrackData::Mode, unsigned long caps);
623 
624   void printCdToc(CdToc *toc, int tocLen);
625 
626   enum ReadCdProgressType { RCD_ANALYZING = PGSMSG_RCD_ANALYZING,
627 			    RCD_EXTRACTING = PGSMSG_RCD_EXTRACTING };
628   void sendReadCdProgressMsg(ReadCdProgressType, int totalTracks, int track,
629 			     int trackProgress, int totalProgress);
630 
631 
632 public:
633   // function to read audio data and also the sub-channel data from
634   // specified lba,
635   // this function is called from 'cdda_read()', so that it is currently
636   // public because I did not manage to define a friend function that has
637   // C linkage :)
638   long audioRead(TrackData::SubChannelMode, int byteOrder,
639 		 Sample *buffer, long startLba, long len);
640 
641 
642   // Interface for Monty's paranoia library:
643 protected:
644   // Extracts audio data for given track range with the help of
645   // Monty's paranoia library.
646   int readAudioRangeParanoia(ReadDiskInfo *, int fp, long start, long end,
647 			     int startTrack, int endTrack,
648 			     TrackInfo *trackInfo);
649 
650 private:
651   // dynamic data
652   void *paranoia_;                    // paranoia structure
653   struct cdrom_drive *paranoiaDrive_; // paranoia device
654   int paranoiaMode_;                  // paranoia mode
655   ReadDiskInfo *audioReadInfo_;
656   TrackInfo *audioReadTrackInfo_;
657   int audioReadStartTrack_;
658   int audioReadEndTrack_;
659   long audioReadLastLba_;
660   long audioReadActLba_;
661   int audioReadActTrack_;
662   int audioReadActIndex_;
663   long audioReadCrcCount_;
664   int audioReadError_;
665   long audioReadProgress_;
666 
667   // callback for the paranoia library, does nothing, currently
668   static void paranoiaCallback(long, int);
669 
670 
671   // friend classes:
672   friend class CDD2600Base;
673 };
674 
675 #endif
676