File: cdparanoia.cpp

package info (click to toggle)
cantata 3.4.0.ds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,428 kB
  • sloc: cpp: 109,584; perl: 1,366; xml: 722; python: 139; lex: 110; sh: 105; yacc: 78; makefile: 8
file content (175 lines) | stat: -rw-r--r-- 3,984 bytes parent folder | download
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Cantata
 *
 * Copyright (c) 2011-2022 Craig Drummond <craig.p.drummond@gmail.com>
 *
 * ----
 *
 * 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; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "cdparanoia.h"
#include "config.h"
#include <QMutex>
#include <QMutexLocker>
#include <QSet>

static QSet<QString> lockedDevices;
static QMutex mutex;

CdParanoia::CdParanoia(const QString& device, bool full, bool noSkip, bool playback, int offset)
	: drive(0), paranoia(0), paranoiaMode(0), neverSkip(noSkip), maxRetries(20), seekOffst(offset)
{
	QMutexLocker locker(&mutex);
	if (!lockedDevices.contains(device)) {
		dev = device;
		if (init()) {
			lockedDevices.insert(device);
		}
		else {
			dev = QString();
		}
	}

	if (!dev.isEmpty()) {
		setFullParanoiaMode(full);
		if (playback) {
			maxRetries = 1;
#if !defined LibCDIOParanoia_FOUND && defined CDPARANOIA_HAS_CACHEMODEL_SIZE
			paranoia_cachemodel_size(paranoia, 24);
#endif
		}
	}
}

CdParanoia::~CdParanoia()
{
	QMutexLocker locker(&mutex);
	free();
	if (!dev.isEmpty()) {
		lockedDevices.remove(dev);
	}
}

void CdParanoia::setParanoiaMode(int mode)
{
	// from cdrdao 1.1.7
	paranoiaMode = PARANOIA_MODE_FULL ^ PARANOIA_MODE_NEVERSKIP;

	switch (mode) {
	case 0: paranoiaMode = PARANOIA_MODE_DISABLE; break;
	case 1:
		paranoiaMode |= PARANOIA_MODE_OVERLAP;
		paranoiaMode &= ~PARANOIA_MODE_VERIFY;
		break;
	case 2: paranoiaMode &= ~(PARANOIA_MODE_SCRATCH | PARANOIA_MODE_REPAIR); break;
	}

	if (neverSkip) {
		paranoiaMode |= PARANOIA_MODE_NEVERSKIP;
	}

	if (paranoia) {
#ifdef LibCDIOParanoia_FOUND
		cdio_paranoia_modeset(paranoia, paranoiaMode);
#else
		paranoia_modeset(paranoia, paranoiaMode);
#endif
	}
}

qint16* CdParanoia::read()
{
#ifdef LibCDIOParanoia_FOUND
	return paranoia ? cdio_paranoia_read_limited(paranoia, 0, maxRetries) : 0;
#else
	return paranoia ? paranoia_read_limited(paranoia, 0, maxRetries) : 0;
#endif
}

int CdParanoia::seek(long sector, int mode)
{
#ifdef LibCDIOParanoia_FOUND
	return paranoia ? cdio_paranoia_seek(paranoia, sector + seekOffst, mode) : -1;
#else
	return paranoia ? paranoia_seek(paranoia, sector + seekOffst, mode) : -1;
#endif
}

int CdParanoia::firstSectorOfTrack(int track)
{
#ifdef LibCDIOParanoia_FOUND
	return paranoia ? cdio_cddap_track_firstsector(drive, track) : -1;
#else
	return paranoia ? cdda_track_firstsector(drive, track) : -1;
#endif
}

int CdParanoia::lastSectorOfTrack(int track)
{
#ifdef LibCDIOParanoia_FOUND
	return paranoia ? cdio_cddap_track_lastsector(drive, track) : -1;
#else
	return paranoia ? cdda_track_lastsector(drive, track) : -1;
#endif
}

bool CdParanoia::init()
{
	free();
#ifdef LibCDIOParanoia_FOUND
	drive = cdda_identify(dev.toLatin1().data(), 0, 0);
#else
	drive = cdda_identify(dev.toLatin1().data(), 0, 0);
#endif
	if (!drive) {
		return false;
	}

#ifdef LibCDIOParanoia_FOUND
	cdio_cddap_open(drive);
	paranoia = cdio_paranoia_init(drive);
#else
	cdda_open(drive);
	paranoia = paranoia_init(drive);
#endif
	if (paranoia == 0) {
		free();
		return false;
	}

	return true;
}

void CdParanoia::free()
{
	if (paranoia) {
#ifdef LibCDIOParanoia_FOUND
		cdio_paranoia_free(paranoia);
#else
		paranoia_free(paranoia);
#endif
		paranoia = 0;
	}
	if (drive) {
#ifdef LibCDIOParanoia_FOUND
		cdio_cddap_close(drive);
#else
		cdda_close(drive);
#endif
		drive = 0;
	}
}