File indexing completed on 2024-04-28 04:49:50

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef K3B_CDPARANOIA_LIB_H
0007 #define K3B_CDPARANOIA_LIB_H
0008 
0009 // from cdda_interface.h
0010 #define CD_FRAMESIZE_RAW 2352
0011 
0012 #include "k3b_export.h"
0013 
0014 #include <QString>
0015 
0016 #include <sys/types.h>
0017 
0018 #ifdef Q_OS_WIN32
0019 #undef S_OK
0020 #endif
0021 
0022 namespace K3b {
0023     namespace Device {
0024         class Device;
0025         class Toc;
0026     }
0027 
0028 
0029     /**
0030      * CdparanoiaLib is a convenience wrapper around libcdda_interface
0031      * and libcdda_paranoia.
0032      *
0033      * It uses four paranoia levels 0-3 which can be set via setParanoiaMode
0034      * and are used the same way as in cdrdao:
0035      * \li 0: No checking, data is copied directly from the drive.
0036      * \li 1: Perform overlapped reading to avoid jitter.
0037      * \li 2: Like 1 but with additional checks of the read audio data.
0038      * \li 3: Like 2 but with additional scratch detection and repair.
0039      *
0040      * CdparanoiaLib is based on a shared data approach which makes sure
0041      * that each device can only be opened once. This is necessary since
0042      * libcdda_interface opens the device exclusively on most distributions.
0043      *
0044      * However, it is perfectly possible to have two instances of CdparanoiaLib
0045      * accessing the same device at the same time. CdparanoiaLib will take care
0046      * of the syncing and seeking issues automatically.
0047      *
0048      * CdparanoiaLib is thread-safe.
0049      *
0050      * Usage:
0051      * <pre>
0052      * CdparanoiaLib lib;
0053      * lib.initParanoia( mydevice );
0054      * lib.initReading( tracknumber );
0055      * while( char* data = lib.read() )
0056      *   dosomethingcoolwithdata( data );
0057      * </pre>
0058      */
0059     class LIBK3B_EXPORT CdparanoiaLib
0060     {
0061     public:
0062         ~CdparanoiaLib();
0063 
0064         /** default: 1 */
0065         void setParanoiaMode( int );
0066         void setNeverSkip( bool b );
0067 
0068         /** default: 5 */
0069         void setMaxRetries( int );
0070 
0071         /**
0072          * This will read the Toc and initialize some stuff.
0073          * It will also call paranoiaInit( const QString& )
0074          */
0075         bool initParanoia( Device::Device* dev );
0076 
0077         /**
0078          * Use for faster initialization without reading the toc
0079          */
0080         bool initParanoia( Device::Device* dev, const Device::Toc& );
0081 
0082         void close();
0083 
0084         /**
0085          * Call this after initParanoia to set the data to rip.
0086          *
0087          * Rip all audio tracks.
0088          */
0089         bool initReading();
0090 
0091         /**
0092          * Call this after initParanoia to set the data to rip.
0093          */
0094         bool initReading( int track );
0095 
0096         /**
0097          * Call this after initParanoia to set the data to rip.
0098          */
0099         bool initReading( long startSector, long endSector );
0100 
0101         /**
0102          * Read data.
0103          * \param statusCode If not 0 will be set.
0104          * \param track the tracknumer the data belongs to
0105          *
0106          * This method takes care of swapping the byte-order depending on the
0107          * machine type.
0108          *
0109          * \return The read sector data or 0 if all data within the specified range
0110          *         has been read or an error has occurred.
0111          */
0112         char* read( int* statusCode = 0, unsigned int* track = 0, bool littleEndian = true );
0113 
0114         /**
0115          * This only is valid after a call to read()
0116          */
0117         int status() const;
0118 
0119         enum Status {
0120             S_OK,
0121             S_ERROR
0122             // to be extended with Jitter and stuff...
0123         };
0124 
0125         /**
0126          * Only valid after a call to initParanoia()
0127          */
0128         const Device::Toc& toc() const;
0129 
0130         long rippedDataLength() const;
0131 
0132         /**
0133          * returns 0 if the cdparanoialib could not
0134          * be found on the system.
0135          * Otherwise you have to take care of
0136          * deleting.
0137          */
0138         static CdparanoiaLib* create();
0139 
0140     private:
0141         void cleanup();
0142 
0143         CdparanoiaLib();
0144         bool load();
0145 
0146         class Private;
0147         Private* d;
0148     };
0149 }
0150 
0151 
0152 #endif