aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/sidplay_decoder_plugin.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder/sidplay_decoder_plugin.cxx')
-rw-r--r--src/decoder/sidplay_decoder_plugin.cxx78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/decoder/sidplay_decoder_plugin.cxx b/src/decoder/sidplay_decoder_plugin.cxx
index 5d162f179..486dd816f 100644
--- a/src/decoder/sidplay_decoder_plugin.cxx
+++ b/src/decoder/sidplay_decoder_plugin.cxx
@@ -18,25 +18,24 @@
*/
#include "config.h"
-
-extern "C" {
-#include "../decoder_api.h"
-#include "tag_handler.h"
-}
+#include "../DecoderAPI.hxx"
+#include "tag/TagHandler.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <glib.h>
#include <sidplay/sidplay2.h>
#include <sidplay/builders/resid.h>
#include <sidplay/utils/SidTuneMod.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "sidplay"
-
#define SUBTUNE_PREFIX "tune_"
+static constexpr Domain sidplay_domain("sidplay");
+
static GPatternSpec *path_with_subtune;
static const char *songlength_file;
static GKeyFile *songlength_database;
@@ -54,8 +53,9 @@ sidplay_load_songlength_db(const char *path)
gsize size;
if (!g_file_get_contents(path, &data, &size, &error)) {
- g_warning("unable to read songlengths file %s: %s",
- path, error->message);
+ FormatError(sidplay_domain,
+ "unable to read songlengths file %s: %s",
+ path, error->message);
g_error_free(error);
return NULL;
}
@@ -70,8 +70,9 @@ sidplay_load_songlength_db(const char *path)
G_KEY_FILE_NONE, &error);
g_free(data);
if (!success) {
- g_warning("unable to parse songlengths file %s: %s",
- path, error->message);
+ FormatError(sidplay_domain,
+ "unable to parse songlengths file %s: %s",
+ path, error->message);
g_error_free(error);
g_key_file_free(db);
return NULL;
@@ -82,29 +83,27 @@ sidplay_load_songlength_db(const char *path)
}
static bool
-sidplay_init(const struct config_param *param)
+sidplay_init(const config_param &param)
{
/* read the songlengths database file */
- songlength_file=config_get_block_string(param,
- "songlength_database", NULL);
+ songlength_file = param.GetBlockValue("songlength_database");
if (songlength_file != NULL)
songlength_database = sidplay_load_songlength_db(songlength_file);
- default_songlength=config_get_block_unsigned(param,
- "default_songlength", 0);
+ default_songlength = param.GetBlockValue("default_songlength", 0u);
- all_files_are_containers=config_get_block_bool(param,
- "all_files_are_containers", true);
+ all_files_are_containers =
+ param.GetBlockValue("all_files_are_containers", true);
path_with_subtune=g_pattern_spec_new(
"*/" SUBTUNE_PREFIX "???.sid");
- filter_setting=config_get_block_bool(param, "filter", true);
+ filter_setting = param.GetBlockValue("filter", true);
return true;
}
-void
+static void
sidplay_finish()
{
g_pattern_spec_free(path_with_subtune);
@@ -136,7 +135,7 @@ get_container_name(const char *path_fs)
* returns tune number from file.sid/tune_xxx.sid style path or 1 if
* no subtune is appended
*/
-static int
+static unsigned
get_song_num(const char *path_fs)
{
if(g_pattern_match(path_with_subtune,
@@ -166,13 +165,14 @@ get_song_length(const char *path_fs)
SidTuneMod tune(sid_file);
g_free(sid_file);
if(!tune) {
- g_warning("failed to load file for calculating md5 sum");
+ LogWarning(sidplay_domain,
+ "failed to load file for calculating md5 sum");
return -1;
}
char md5sum[SIDTUNE_MD5_LENGTH+1];
tune.createMD5(md5sum);
- int song_num=get_song_num(path_fs);
+ const unsigned song_num = get_song_num(path_fs);
gsize num_items;
gchar **values=g_key_file_get_string_list(songlength_database,
@@ -209,7 +209,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
SidTune tune(path_container, NULL, true);
g_free(path_container);
if (!tune) {
- g_warning("failed to load file");
+ LogWarning(sidplay_domain, "failed to load file");
return;
}
@@ -224,7 +224,8 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
sidplay2 player;
int iret = player.load(&tune);
if (iret != 0) {
- g_warning("sidplay2.load() failed: %s", player.error());
+ FormatWarning(sidplay_domain,
+ "sidplay2.load() failed: %s", player.error());
return;
}
@@ -232,19 +233,20 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
ReSIDBuilder builder("ReSID");
if (!builder) {
- g_warning("failed to initialize ReSIDBuilder");
+ LogWarning(sidplay_domain,
+ "failed to initialize ReSIDBuilder");
return;
}
builder.create(player.info().maxsids);
if (!builder) {
- g_warning("ReSIDBuilder.create() failed");
+ LogWarning(sidplay_domain, "ReSIDBuilder.create() failed");
return;
}
builder.filter(filter_setting);
if (!builder) {
- g_warning("ReSIDBuilder.filter() failed");
+ LogWarning(sidplay_domain, "ReSIDBuilder.filter() failed");
return;
}
@@ -278,24 +280,24 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
iret = player.config(config);
if (iret != 0) {
- g_warning("sidplay2.config() failed: %s", player.error());
+ FormatWarning(sidplay_domain,
+ "sidplay2.config() failed: %s", player.error());
return;
}
/* initialize the MPD decoder */
- struct audio_format audio_format;
- audio_format_init(&audio_format, 48000, SAMPLE_FORMAT_S16, channels);
- assert(audio_format_valid(&audio_format));
+ const AudioFormat audio_format(48000, SampleFormat::S16, channels);
+ assert(audio_format.IsValid());
- decoder_initialized(decoder, &audio_format, true, (float)song_len);
+ decoder_initialized(decoder, audio_format, true, (float)song_len);
/* .. and play */
const unsigned timebase = player.timebase();
song_len *= timebase;
- enum decoder_command cmd;
+ DecoderCommand cmd;
do {
char buffer[4096];
size_t nbytes;
@@ -308,7 +310,7 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
cmd = decoder_data(decoder, NULL, buffer, nbytes, 0);
- if(cmd==DECODE_COMMAND_SEEK) {
+ if (cmd == DecoderCommand::SEEK) {
unsigned data_time = player.time();
unsigned target_time = (unsigned)
(decoder_seek_where(decoder) * timebase);
@@ -330,10 +332,10 @@ sidplay_file_decode(struct decoder *decoder, const char *path_fs)
decoder_command_finished(decoder);
}
- if (song_len > 0 && player.time() >= song_len)
+ if (song_len > 0 && player.time() >= (unsigned)song_len)
break;
- } while (cmd != DECODE_COMMAND_STOP);
+ } while (cmd != DecoderCommand::STOP);
}
static bool