input/cdio_paranoia: convert to C++
This commit is contained in:
parent
0c9f22507f
commit
9cc90b1fbe
@ -80,7 +80,6 @@ mpd_headers = \
|
|||||||
src/input_plugin.h \
|
src/input_plugin.h \
|
||||||
src/input_stream.h \
|
src/input_stream.h \
|
||||||
src/input/despotify_input_plugin.h \
|
src/input/despotify_input_plugin.h \
|
||||||
src/input/cdio_paranoia_input_plugin.h \
|
|
||||||
src/despotify_utils.h \
|
src/despotify_utils.h \
|
||||||
src/text_input_stream.h \
|
src/text_input_stream.h \
|
||||||
src/icy_server.h \
|
src/icy_server.h \
|
||||||
@ -741,7 +740,9 @@ libinput_a_SOURCES += \
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_CDIO_PARANOIA
|
if ENABLE_CDIO_PARANOIA
|
||||||
libinput_a_SOURCES += src/input/cdio_paranoia_input_plugin.c
|
libinput_a_SOURCES += \
|
||||||
|
src/input/CdioParanoiaInputPlugin.cxx \
|
||||||
|
src/input/CdioParanoiaInputPlugin.hxx
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if HAVE_FFMPEG
|
if HAVE_FFMPEG
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_CDIO_PARANOIA
|
#ifdef ENABLE_CDIO_PARANOIA
|
||||||
#include "input/cdio_paranoia_input_plugin.h"
|
#include "input/CdioParanoiaInputPlugin.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_DESPOTIFY
|
#ifdef ENABLE_DESPOTIFY
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -22,7 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "input/cdio_paranoia_input_plugin.h"
|
#include "CdioParanoiaInputPlugin.hxx"
|
||||||
#include "input_internal.h"
|
#include "input_internal.h"
|
||||||
#include "input_plugin.h"
|
#include "input_plugin.h"
|
||||||
#include "refcount.h"
|
#include "refcount.h"
|
||||||
@ -38,7 +38,7 @@
|
|||||||
#include <cdio/paranoia.h>
|
#include <cdio/paranoia.h>
|
||||||
#include <cdio/cd_types.h>
|
#include <cdio/cd_types.h>
|
||||||
|
|
||||||
struct input_cdio_paranoia {
|
struct CdioParanoiaInputStream {
|
||||||
struct input_stream base;
|
struct input_stream base;
|
||||||
|
|
||||||
cdrom_drive_t *drv;
|
cdrom_drive_t *drv;
|
||||||
@ -52,6 +52,26 @@ struct input_cdio_paranoia {
|
|||||||
|
|
||||||
char buffer[CDIO_CD_FRAMESIZE_RAW];
|
char buffer[CDIO_CD_FRAMESIZE_RAW];
|
||||||
int buffer_lsn;
|
int buffer_lsn;
|
||||||
|
|
||||||
|
CdioParanoiaInputStream(const char *uri, GMutex *mutex, GCond *cond,
|
||||||
|
int _trackno)
|
||||||
|
:drv(nullptr), cdio(nullptr), para(nullptr),
|
||||||
|
trackno(_trackno)
|
||||||
|
{
|
||||||
|
input_stream_init(&base, &input_plugin_cdio_paranoia, uri,
|
||||||
|
mutex, cond);
|
||||||
|
}
|
||||||
|
|
||||||
|
~CdioParanoiaInputStream() {
|
||||||
|
if (para != nullptr)
|
||||||
|
cdio_paranoia_free(para);
|
||||||
|
if (drv != nullptr)
|
||||||
|
cdio_cddap_close_no_free_cdio(drv);
|
||||||
|
if (cdio != nullptr)
|
||||||
|
cdio_destroy(cdio);
|
||||||
|
|
||||||
|
input_stream_deinit(&base);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline GQuark
|
static inline GQuark
|
||||||
@ -63,17 +83,9 @@ cdio_quark(void)
|
|||||||
static void
|
static void
|
||||||
input_cdio_close(struct input_stream *is)
|
input_cdio_close(struct input_stream *is)
|
||||||
{
|
{
|
||||||
struct input_cdio_paranoia *i = (struct input_cdio_paranoia *)is;
|
CdioParanoiaInputStream *i = (CdioParanoiaInputStream *)is;
|
||||||
|
|
||||||
if (i->para)
|
delete i;
|
||||||
cdio_paranoia_free(i->para);
|
|
||||||
if (i->drv)
|
|
||||||
cdio_cddap_close_no_free_cdio( i->drv);
|
|
||||||
if (i->cdio)
|
|
||||||
cdio_destroy( i->cdio );
|
|
||||||
|
|
||||||
input_stream_deinit(&i->base);
|
|
||||||
g_free(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cdio_uri {
|
struct cdio_uri {
|
||||||
@ -97,7 +109,7 @@ parse_cdio_uri(struct cdio_uri *dest, const char *src, GError **error_r)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *slash = strrchr(src, '/');
|
const char *slash = strrchr(src, '/');
|
||||||
if (slash == NULL) {
|
if (slash == nullptr) {
|
||||||
/* play the whole CD in the specified drive */
|
/* play the whole CD in the specified drive */
|
||||||
g_strlcpy(dest->device, src, sizeof(dest->device));
|
g_strlcpy(dest->device, src, sizeof(dest->device));
|
||||||
dest->track = -1;
|
dest->track = -1;
|
||||||
@ -131,9 +143,10 @@ parse_cdio_uri(struct cdio_uri *dest, const char *src, GError **error_r)
|
|||||||
static char *
|
static char *
|
||||||
cdio_detect_device(void)
|
cdio_detect_device(void)
|
||||||
{
|
{
|
||||||
char **devices = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
|
char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO,
|
||||||
if (devices == NULL)
|
false);
|
||||||
return NULL;
|
if (devices == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
char *device = g_strdup(devices[0]);
|
char *device = g_strdup(devices[0]);
|
||||||
cdio_free_device_list(devices);
|
cdio_free_device_list(devices);
|
||||||
@ -146,52 +159,44 @@ input_cdio_open(const char *uri,
|
|||||||
GMutex *mutex, GCond *cond,
|
GMutex *mutex, GCond *cond,
|
||||||
GError **error_r)
|
GError **error_r)
|
||||||
{
|
{
|
||||||
struct input_cdio_paranoia *i;
|
|
||||||
|
|
||||||
struct cdio_uri parsed_uri;
|
struct cdio_uri parsed_uri;
|
||||||
if (!parse_cdio_uri(&parsed_uri, uri, error_r))
|
if (!parse_cdio_uri(&parsed_uri, uri, error_r))
|
||||||
return NULL;
|
return nullptr;
|
||||||
|
|
||||||
i = g_new(struct input_cdio_paranoia, 1);
|
CdioParanoiaInputStream *i =
|
||||||
input_stream_init(&i->base, &input_plugin_cdio_paranoia, uri,
|
new CdioParanoiaInputStream(uri, mutex, cond,
|
||||||
mutex, cond);
|
parsed_uri.track);
|
||||||
|
|
||||||
/* initialize everything (should be already) */
|
|
||||||
i->drv = NULL;
|
|
||||||
i->cdio = NULL;
|
|
||||||
i->para = NULL;
|
|
||||||
i->trackno = parsed_uri.track;
|
|
||||||
|
|
||||||
/* get list of CD's supporting CD-DA */
|
/* get list of CD's supporting CD-DA */
|
||||||
char *device = parsed_uri.device[0] != 0
|
char *device = parsed_uri.device[0] != 0
|
||||||
? g_strdup(parsed_uri.device)
|
? g_strdup(parsed_uri.device)
|
||||||
: cdio_detect_device();
|
: cdio_detect_device();
|
||||||
if (device == NULL) {
|
if (device == nullptr) {
|
||||||
g_set_error(error_r, cdio_quark(), 0,
|
g_set_error(error_r, cdio_quark(), 0,
|
||||||
"Unable find or access a CD-ROM drive with an audio CD in it.");
|
"Unable find or access a CD-ROM drive with an audio CD in it.");
|
||||||
input_cdio_close(&i->base);
|
delete i;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */
|
/* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */
|
||||||
i->cdio = cdio_open(device, DRIVER_UNKNOWN);
|
i->cdio = cdio_open(device, DRIVER_UNKNOWN);
|
||||||
g_free(device);
|
g_free(device);
|
||||||
|
|
||||||
i->drv = cdio_cddap_identify_cdio(i->cdio, 1, NULL);
|
i->drv = cdio_cddap_identify_cdio(i->cdio, 1, nullptr);
|
||||||
|
|
||||||
if ( !i->drv ) {
|
if ( !i->drv ) {
|
||||||
g_set_error(error_r, cdio_quark(), 0,
|
g_set_error(error_r, cdio_quark(), 0,
|
||||||
"Unable to identify audio CD disc.");
|
"Unable to identify audio CD disc.");
|
||||||
input_cdio_close(&i->base);
|
delete i;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
cdda_verbose_set(i->drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
|
cdda_verbose_set(i->drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
|
||||||
|
|
||||||
if ( 0 != cdio_cddap_open(i->drv) ) {
|
if ( 0 != cdio_cddap_open(i->drv) ) {
|
||||||
g_set_error(error_r, cdio_quark(), 0, "Unable to open disc.");
|
g_set_error(error_r, cdio_quark(), 0, "Unable to open disc.");
|
||||||
input_cdio_close(&i->base);
|
delete i;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reverse_endian;
|
bool reverse_endian;
|
||||||
@ -212,8 +217,8 @@ input_cdio_open(const char *uri,
|
|||||||
g_set_error(error_r, cdio_quark(), 0,
|
g_set_error(error_r, cdio_quark(), 0,
|
||||||
"Drive returns unknown data type %d",
|
"Drive returns unknown data type %d",
|
||||||
data_bigendianp(i->drv));
|
data_bigendianp(i->drv));
|
||||||
input_cdio_close(&i->base);
|
delete i;
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
i->lsn_relofs = 0;
|
i->lsn_relofs = 0;
|
||||||
@ -250,7 +255,7 @@ static bool
|
|||||||
input_cdio_seek(struct input_stream *is,
|
input_cdio_seek(struct input_stream *is,
|
||||||
goffset offset, int whence, GError **error_r)
|
goffset offset, int whence, GError **error_r)
|
||||||
{
|
{
|
||||||
struct input_cdio_paranoia *cis = (struct input_cdio_paranoia *)is;
|
CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is;
|
||||||
|
|
||||||
/* calculate absolute offset */
|
/* calculate absolute offset */
|
||||||
switch (whence) {
|
switch (whence) {
|
||||||
@ -288,7 +293,7 @@ static size_t
|
|||||||
input_cdio_read(struct input_stream *is, void *ptr, size_t length,
|
input_cdio_read(struct input_stream *is, void *ptr, size_t length,
|
||||||
GError **error_r)
|
GError **error_r)
|
||||||
{
|
{
|
||||||
struct input_cdio_paranoia *cis = (struct input_cdio_paranoia *)is;
|
CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is;
|
||||||
size_t nbytes = 0;
|
size_t nbytes = 0;
|
||||||
int diff;
|
int diff;
|
||||||
size_t len, maxwrite;
|
size_t len, maxwrite;
|
||||||
@ -305,7 +310,7 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length,
|
|||||||
|
|
||||||
//current sector was changed ?
|
//current sector was changed ?
|
||||||
if (cis->lsn_relofs != cis->buffer_lsn) {
|
if (cis->lsn_relofs != cis->buffer_lsn) {
|
||||||
rbuf = cdio_paranoia_read(cis->para, NULL);
|
rbuf = cdio_paranoia_read(cis->para, nullptr);
|
||||||
|
|
||||||
s_err = cdda_errors(cis->drv);
|
s_err = cdda_errors(cis->drv);
|
||||||
if (s_err) {
|
if (s_err) {
|
||||||
@ -356,16 +361,22 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length,
|
|||||||
static bool
|
static bool
|
||||||
input_cdio_eof(struct input_stream *is)
|
input_cdio_eof(struct input_stream *is)
|
||||||
{
|
{
|
||||||
struct input_cdio_paranoia *cis = (struct input_cdio_paranoia *)is;
|
CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is;
|
||||||
|
|
||||||
return (cis->lsn_from + cis->lsn_relofs > cis->lsn_to);
|
return (cis->lsn_from + cis->lsn_relofs > cis->lsn_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct input_plugin input_plugin_cdio_paranoia = {
|
const struct input_plugin input_plugin_cdio_paranoia = {
|
||||||
.name = "cdio_paranoia",
|
"cdio_paranoia",
|
||||||
.open = input_cdio_open,
|
nullptr,
|
||||||
.close = input_cdio_close,
|
nullptr,
|
||||||
.seek = input_cdio_seek,
|
input_cdio_open,
|
||||||
.read = input_cdio_read,
|
input_cdio_close,
|
||||||
.eof = input_cdio_eof
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
input_cdio_read,
|
||||||
|
input_cdio_eof,
|
||||||
|
input_cdio_seek,
|
||||||
};
|
};
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -17,8 +17,8 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_CDIO_PARANOIA_INPUT_PLUGIN_H
|
#ifndef MPD_CDIO_PARANOIA_INPUT_PLUGIN_HXX
|
||||||
#define MPD_CDIO_PARANOIA_INPUT_PLUGIN_H
|
#define MPD_CDIO_PARANOIA_INPUT_PLUGIN_HXX
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An input plugin based on libcdio_paranoia library.
|
* An input plugin based on libcdio_paranoia library.
|
Loading…
Reference in New Issue
Block a user