summaryrefslogtreecommitdiffstats
path: root/libk3b/tools/k3bcdparanoialib.h
blob: ff4a09a7d6d7eb4678b444ad3e836e4d13981a0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* 
 *
 * $Id: k3bcdparanoialib.h 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003 Sebastian Trueg <trueg@k3b.org>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
 *
 * 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.
 * See the file "COPYING" for the exact licensing terms.
 */


#ifndef K3B_CDPARANOIA_LIB_H
#define K3B_CDPARANOIA_LIB_H

// from cdda_interface.h
#define CD_FRAMESIZE_RAW 2352


#include <tqstring.h>

#include <sys/types.h>
#include "k3b_export.h"

namespace K3bDevice {
  class Device;
  class Toc;
}


/**
 * K3bCdparanoiaLib is a convenience wrapper around libcdda_interface
 * and libcdda_paranoia.
 *
 * It uses four paranoia levels 0-3 which can be set via setParanoiaMode
 * and are used the same way as in cdrdao:
 * \li 0: No checking, data is copied directly from the drive.
 * \li 1: Perform overlapped reading to avoid jitter.
 * \li 2: Like 1 but with additional checks of the read audio data.
 * \li 3: Like 2 but with additional scratch detection and repair.
 *
 * K3bCdparanoiaLib is based on a shared data approach which makes sure
 * that each device can only be opened once. This is necessary since 
 * libcdda_interface opens the device exclusively on most distributions.
 *
 * However, it is perfectly possible to have two instances of K3bCdparanoiaLib
 * accessing the same device at the same time. K3bCdparanoiaLib will take care
 * of the syncing and seeking issues automatically.
 *
 * K3bCdparanoiaLib is thread-safe.
 *
 * Usage:
 * <pre>
 * K3bCdparanoiaLib lib;
 * lib.initParanoia( mydevice );
 * lib.initReading( tracknumber );
 * while( char* data = lib.read() )
 *   dosomethingcoolwithdata( data );
 * </pre>
 */
class LIBK3B_EXPORT K3bCdparanoiaLib
{
 public:
  ~K3bCdparanoiaLib();

  /** default: 1 */
  void setParanoiaMode( int );
  void setNeverSkip( bool b );

  /** default: 5 */
  void setMaxRetries( int );

  /**
   * This will read the Toc and initialize some stuff.
   * It will also call paranoiaInit( const TQString& )
   */
  bool initParanoia( K3bDevice::Device* dev );

  /**
   * Use for faster initialization without reading the toc
   */
  bool initParanoia( K3bDevice::Device* dev, const K3bDevice::Toc& );

  void close();

  /**
   * Call this after initParanoia to set the data to rip.
   *
   * Rip all audio tracks.
   */
  bool initReading();

  /**
   * Call this after initParanoia to set the data to rip.
   */
  bool initReading( unsigned int track );

  /**
   * Call this after initParanoia to set the data to rip.
   */
  bool initReading( long startSector, long endSector );

  /**
   * Read data.
   * \param statusCode If not 0 will be set.
   * \param track the tracknumer the data belongs to
   *
   * This method takes care of swapping the byte-order depending on the
   * machine type.
   *
   * \return The read sector data or 0 if all data within the specified range
   *         has been read or an error has occured.
   */
  char* read( int* statusCode = 0, unsigned int* track = 0, bool littleEndian = true );

  /**
   * This only is valid after a call to read()
   */
  int status() const;

  enum Status {
    S_OK,
    S_ERROR
    // to be extended with Jitter and stuff...
  };

  /**
   * Only valid after a call to initParanoia()
   */
  const K3bDevice::Toc& toc() const;

  long rippedDataLength() const;

  /**
   * returns 0 if the cdparanoialib could not
   * be found on the system.
   * Otherwise you have to take care of
   * deleting.
   */
  static K3bCdparanoiaLib* create();

 private:
  void cleanup();

  K3bCdparanoiaLib();
  bool load();

  class Private;
  Private* d;

  static void* s_libInterface;
  static void* s_libParanoia;
  static int s_counter;
};


#endif