diff options
author | Max Kellermann <max@duempel.org> | 2013-01-21 17:58:30 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-21 17:58:30 +0100 |
commit | 9cc90b1fbe3ea1c3b84c169f94b998f63f50c384 (patch) | |
tree | d13bf2db3be47e3992e29190879d839be6f78df6 /src | |
parent | 0c9f22507f753aa9cdf68084c773c9438391fb1f (diff) | |
download | mpd-9cc90b1fbe3ea1c3b84c169f94b998f63f50c384.tar.gz mpd-9cc90b1fbe3ea1c3b84c169f94b998f63f50c384.tar.xz mpd-9cc90b1fbe3ea1c3b84c169f94b998f63f50c384.zip |
input/cdio_paranoia: convert to C++
Diffstat (limited to 'src')
-rw-r--r-- | src/InputRegistry.cxx | 2 | ||||
-rw-r--r-- | src/input/CdioParanoiaInputPlugin.cxx (renamed from src/input/cdio_paranoia_input_plugin.c) | 109 | ||||
-rw-r--r-- | src/input/CdioParanoiaInputPlugin.hxx (renamed from src/input/cdio_paranoia_input_plugin.h) | 6 |
3 files changed, 64 insertions, 53 deletions
diff --git a/src/InputRegistry.cxx b/src/InputRegistry.cxx index ecd892a5b..6c0898477 100644 --- a/src/InputRegistry.cxx +++ b/src/InputRegistry.cxx @@ -42,7 +42,7 @@ #endif #ifdef ENABLE_CDIO_PARANOIA -#include "input/cdio_paranoia_input_plugin.h" +#include "input/CdioParanoiaInputPlugin.hxx" #endif #ifdef ENABLE_DESPOTIFY diff --git a/src/input/cdio_paranoia_input_plugin.c b/src/input/CdioParanoiaInputPlugin.cxx index 1de7623a1..bf4ddc7f5 100644 --- a/src/input/cdio_paranoia_input_plugin.c +++ b/src/input/CdioParanoiaInputPlugin.cxx @@ -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 * * This program is free software; you can redistribute it and/or modify @@ -22,7 +22,7 @@ */ #include "config.h" -#include "input/cdio_paranoia_input_plugin.h" +#include "CdioParanoiaInputPlugin.hxx" #include "input_internal.h" #include "input_plugin.h" #include "refcount.h" @@ -38,7 +38,7 @@ #include <cdio/paranoia.h> #include <cdio/cd_types.h> -struct input_cdio_paranoia { +struct CdioParanoiaInputStream { struct input_stream base; cdrom_drive_t *drv; @@ -52,6 +52,26 @@ struct input_cdio_paranoia { char buffer[CDIO_CD_FRAMESIZE_RAW]; 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 @@ -63,17 +83,9 @@ cdio_quark(void) static void input_cdio_close(struct input_stream *is) { - struct input_cdio_paranoia *i = (struct input_cdio_paranoia *)is; - - if (i->para) - cdio_paranoia_free(i->para); - if (i->drv) - cdio_cddap_close_no_free_cdio( i->drv); - if (i->cdio) - cdio_destroy( i->cdio ); + CdioParanoiaInputStream *i = (CdioParanoiaInputStream *)is; - input_stream_deinit(&i->base); - g_free(i); + delete i; } 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, '/'); - if (slash == NULL) { + if (slash == nullptr) { /* play the whole CD in the specified drive */ g_strlcpy(dest->device, src, sizeof(dest->device)); dest->track = -1; @@ -131,9 +143,10 @@ parse_cdio_uri(struct cdio_uri *dest, const char *src, GError **error_r) static char * cdio_detect_device(void) { - char **devices = cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false); - if (devices == NULL) - return NULL; + char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO, + false); + if (devices == nullptr) + return nullptr; char *device = g_strdup(devices[0]); cdio_free_device_list(devices); @@ -146,52 +159,44 @@ input_cdio_open(const char *uri, GMutex *mutex, GCond *cond, GError **error_r) { - struct input_cdio_paranoia *i; - struct cdio_uri parsed_uri; if (!parse_cdio_uri(&parsed_uri, uri, error_r)) - return NULL; - - i = g_new(struct input_cdio_paranoia, 1); - input_stream_init(&i->base, &input_plugin_cdio_paranoia, uri, - mutex, cond); + return nullptr; - /* initialize everything (should be already) */ - i->drv = NULL; - i->cdio = NULL; - i->para = NULL; - i->trackno = parsed_uri.track; + CdioParanoiaInputStream *i = + new CdioParanoiaInputStream(uri, mutex, cond, + parsed_uri.track); /* get list of CD's supporting CD-DA */ char *device = parsed_uri.device[0] != 0 ? g_strdup(parsed_uri.device) : cdio_detect_device(); - if (device == NULL) { + if (device == nullptr) { g_set_error(error_r, cdio_quark(), 0, "Unable find or access a CD-ROM drive with an audio CD in it."); - input_cdio_close(&i->base); - return NULL; + delete i; + return nullptr; } /* Found such a CD-ROM with a CD-DA loaded. Use the first drive in the list. */ i->cdio = cdio_open(device, DRIVER_UNKNOWN); 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 ) { g_set_error(error_r, cdio_quark(), 0, "Unable to identify audio CD disc."); - input_cdio_close(&i->base); - return NULL; + delete i; + return nullptr; } cdda_verbose_set(i->drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT); if ( 0 != cdio_cddap_open(i->drv) ) { g_set_error(error_r, cdio_quark(), 0, "Unable to open disc."); - input_cdio_close(&i->base); - return NULL; + delete i; + return nullptr; } bool reverse_endian; @@ -212,8 +217,8 @@ input_cdio_open(const char *uri, g_set_error(error_r, cdio_quark(), 0, "Drive returns unknown data type %d", data_bigendianp(i->drv)); - input_cdio_close(&i->base); - return NULL; + delete i; + return nullptr; } i->lsn_relofs = 0; @@ -250,7 +255,7 @@ static bool input_cdio_seek(struct input_stream *is, goffset offset, int whence, GError **error_r) { - struct input_cdio_paranoia *cis = (struct input_cdio_paranoia *)is; + CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is; /* calculate absolute offset */ switch (whence) { @@ -288,7 +293,7 @@ static size_t input_cdio_read(struct input_stream *is, void *ptr, size_t length, GError **error_r) { - struct input_cdio_paranoia *cis = (struct input_cdio_paranoia *)is; + CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is; size_t nbytes = 0; int diff; size_t len, maxwrite; @@ -305,7 +310,7 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length, //current sector was changed ? 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); if (s_err) { @@ -356,16 +361,22 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length, static bool 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); } const struct input_plugin input_plugin_cdio_paranoia = { - .name = "cdio_paranoia", - .open = input_cdio_open, - .close = input_cdio_close, - .seek = input_cdio_seek, - .read = input_cdio_read, - .eof = input_cdio_eof + "cdio_paranoia", + nullptr, + nullptr, + input_cdio_open, + input_cdio_close, + nullptr, + nullptr, + nullptr, + nullptr, + input_cdio_read, + input_cdio_eof, + input_cdio_seek, }; diff --git a/src/input/cdio_paranoia_input_plugin.h b/src/input/CdioParanoiaInputPlugin.hxx index 71c5cbe8d..80d98b4bf 100644 --- a/src/input/cdio_paranoia_input_plugin.h +++ b/src/input/CdioParanoiaInputPlugin.hxx @@ -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 * * 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. */ -#ifndef MPD_CDIO_PARANOIA_INPUT_PLUGIN_H -#define MPD_CDIO_PARANOIA_INPUT_PLUGIN_H +#ifndef MPD_CDIO_PARANOIA_INPUT_PLUGIN_HXX +#define MPD_CDIO_PARANOIA_INPUT_PLUGIN_HXX /** * An input plugin based on libcdio_paranoia library. |