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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
/*****************************************************************
* gmerlin - a general purpose multimedia framework and applications
*
* Copyright (c) 2001 - 2024 Members of the Gmerlin project
* http://github.com/bplaum
*
* 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. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <config.h>
#include <gmerlin/translation.h>
#include "cdaudio.h"
#define DO_NOT_WANT_PARANOIA_COMPATIBILITY
#ifdef HAVE_CDIO_CDDA_H
#include <cdio/cdda.h>
#elif defined HAVE_CDIO_PARANOIA_CDDA_H
#include <cdio/paranoia/cdda.h>
#endif
#ifdef HAVE_CDIO_PARANOIA_H
#include <cdio/paranoia.h>
#elif defined HAVE_CDIO_PARANOIA_PARANOIA_H
#include <cdio/paranoia/paranoia.h>
#endif
/*
* Ripping support
* Several versions (cdparanoia, simple linux ripper) can go here
*/
typedef struct
{
cdrom_drive_t *drive;
cdrom_paranoia_t *paranoia;
/* Configuration options (mostly correspond to commandline options) */
int speed;
int disable_paranoia; // -Z
int disable_extra_paranoia; // -Y
int max_retries; // (0: unlimited)
CdIo_t *cdio;
int current_sector;
} cdparanoia_priv_t;
void * bg_cdaudio_rip_create()
{
cdparanoia_priv_t * ret;
ret = calloc(1, sizeof(*ret));
return ret;
}
int bg_cdaudio_rip_init(void * data,
CdIo_t *cdio, int start_sector)
{
char * msg = NULL;
int paranoia_mode;
cdparanoia_priv_t * priv;
priv = data;
priv->cdio = cdio;
/* cdparanoia */
if(!priv->disable_paranoia)
{
priv->drive = cdio_cddap_identify_cdio(cdio, 1, &msg);
if(!priv->drive)
return 0;
cdio_cddap_verbose_set(priv->drive,CDDA_MESSAGE_FORGETIT,CDDA_MESSAGE_FORGETIT);
if(priv->speed != -1)
cdio_cddap_speed_set(priv->drive, priv->speed);
cdio_cddap_open(priv->drive);
paranoia_mode=PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP;
if(priv->disable_extra_paranoia)
{
paranoia_mode|=PARANOIA_MODE_OVERLAP; /* cdda2wav style overlap
check only */
paranoia_mode&=~PARANOIA_MODE_VERIFY;
}
priv->paranoia = cdio_paranoia_init(priv->drive);
cdio_paranoia_seek(priv->paranoia, start_sector, SEEK_SET);
cdio_paranoia_modeset(priv->paranoia,paranoia_mode);
}
/* Simple audio reading */
else
{
priv->current_sector = start_sector;
}
return 1;
}
static void paranoia_callback(long inpos, paranoia_cb_mode_t function)
{
}
int bg_cdaudio_rip_rip(void * data, gavl_audio_frame_t * f)
{
cdparanoia_priv_t * priv = data;
if(!priv->disable_paranoia)
{
int16_t * samples;
// fprintf(stderr, "read sector paranoia...");
samples = cdio_paranoia_read(priv->paranoia, paranoia_callback);
// fprintf(stderr, "Ok: %d\n", f->valid_samples);
memcpy(f->samples.s_16, samples, 588 * 4);
}
else
{
driver_return_code_t err;
err = cdio_read_audio_sector(priv->cdio, f->samples.s_16, priv->current_sector);
if(err != DRIVER_OP_SUCCESS)
{
// fprintf(stderr, "Failed\n");
return 0;
}
priv->current_sector++;
}
return 1;
}
/* Sector is absolute */
void bg_cdaudio_rip_seek(void * data, int sector)
{
cdparanoia_priv_t * priv = data;
if(!priv->disable_paranoia)
cdio_paranoia_seek(priv->paranoia, sector, SEEK_SET);
else
priv->current_sector = sector;
}
void bg_cdaudio_rip_close(void * data)
{
cdparanoia_priv_t * priv = data;
if(priv->paranoia)
{
cdio_paranoia_free(priv->paranoia);
priv->paranoia = NULL;
}
if(priv->drive)
{
cdio_cddap_close(priv->drive);
priv->drive = NULL;
}
}
void bg_cdaudio_rip_destroy(void * data)
{
cdparanoia_priv_t * priv;
priv = data;
free(priv);
}
static const bg_parameter_info_t parameters[] =
{
{
.name = "cdparanoia",
.long_name = TRS("Cdparanoia"),
.type = BG_PARAMETER_SECTION,
},
{
.name = "cdparanoia_speed",
.long_name = TRS("Speed"),
.type = BG_PARAMETER_STRINGLIST,
.val_default = GAVL_VALUE_INIT_STRING("Auto"),
.multi_names = (char const *[]){ TRS("Auto"),
"4",
"8",
"16",
"32",
NULL },
},
{
.name = "cdparanoia_max_retries",
.long_name = TRS("Maximum retries"),
.type = BG_PARAMETER_INT,
.val_min = GAVL_VALUE_INIT_INT(0),
.val_max = GAVL_VALUE_INIT_INT(200),
.val_default = GAVL_VALUE_INIT_INT(20),
.help_string = TRS("Maximum number of retries, 0 = infinite")
},
{
.name = "cdparanoia_disable_paranoia",
.long_name = TRS("Disable paranoia"),
.type = BG_PARAMETER_CHECKBUTTON,
.val_default = GAVL_VALUE_INIT_INT(0),
.help_string = TRS("Disable all data verification and correction features.")
},
{
.name = "cdparanoia_disable_extra_paranoia",
.long_name = TRS("Disable extra paranoia"),
.type = BG_PARAMETER_CHECKBUTTON,
.val_default = GAVL_VALUE_INIT_INT(0),
.help_string = TRS("Disables intra-read data verification; only overlap checking at\
read boundaries is performed. It can wedge if errors occur in \
the attempted overlap area. Not recommended.")
},
{ /* End of parameters */ }
};
const bg_parameter_info_t * bg_cdaudio_rip_get_parameters()
{
return parameters;
}
int
bg_cdaudio_rip_set_parameter(void * data, const char * name,
const gavl_value_t * val)
{
cdparanoia_priv_t * priv;
priv = data;
if(!name)
return 0;
if(!strcmp(name, "cdparanoia_speed"))
{
if(!strcmp(val->v.str, "Auto"))
priv->speed = -1;
else
priv->speed = atoi(val->v.str);
return 1;
}
else if(!strcmp(name, "cdparanoia_max_retries"))
{
priv->max_retries = val->v.i;
return 1;
}
else if(!strcmp(name, "cdparanoia_disable_paranoia"))
{
priv->disable_paranoia = val->v.i;
return 1;
}
else if(!strcmp(name, "cdparanoia_disable_extra_paranoia"))
{
priv->disable_extra_paranoia = val->v.i;
return 1;
}
return 0;
}
|