aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-09-27 22:31:24 +0200
committerMax Kellermann <max@duempel.org>2013-10-02 08:57:55 +0200
commit060814daa83f6a94f5934464ae42a406c5c7e947 (patch)
treef636ec6cdbb8e52fda6db987d2a28fc73c7b94b4 /src/decoder
parentc53492a76a8a05825e1c7f699c05645eee891199 (diff)
downloadmpd-060814daa83f6a94f5934464ae42a406c5c7e947.tar.gz
mpd-060814daa83f6a94f5934464ae42a406c5c7e947.tar.xz
mpd-060814daa83f6a94f5934464ae42a406c5c7e947.zip
Log: new logging library API
Prepare to migrate away from GLib. Currently, we're still using GLib as a backend.
Diffstat (limited to '')
-rw-r--r--src/decoder/AdPlugDecoderPlugin.cxx6
-rw-r--r--src/decoder/AudiofileDecoderPlugin.cxx28
-rw-r--r--src/decoder/DsdiffDecoderPlugin.cxx6
-rw-r--r--src/decoder/DsfDecoderPlugin.cxx6
-rw-r--r--src/decoder/FaadDecoderPlugin.cxx25
-rw-r--r--src/decoder/FfmpegDecoderPlugin.cxx60
-rw-r--r--src/decoder/FfmpegMetaData.cxx3
-rw-r--r--src/decoder/FlacCommon.cxx8
-rw-r--r--src/decoder/FlacCommon.hxx3
-rw-r--r--src/decoder/FlacDecoderPlugin.cxx35
-rw-r--r--src/decoder/FlacDomain.cxx24
-rw-r--r--src/decoder/FlacDomain.hxx27
-rw-r--r--src/decoder/FlacInput.cxx9
-rw-r--r--src/decoder/FluidsynthDecoderPlugin.cxx32
-rw-r--r--src/decoder/GmeDecoderPlugin.cxx25
-rw-r--r--src/decoder/MadDecoderPlugin.cxx48
-rw-r--r--src/decoder/MikmodDecoderPlugin.cxx16
-rw-r--r--src/decoder/ModplugDecoderPlugin.cxx15
-rw-r--r--src/decoder/MpcdecDecoderPlugin.cxx15
-rw-r--r--src/decoder/Mpg123DecoderPlugin.cxx36
-rw-r--r--src/decoder/OpusDecoderPlugin.cxx13
-rw-r--r--src/decoder/OpusDomain.cxx24
-rw-r--r--src/decoder/OpusDomain.hxx27
-rw-r--r--src/decoder/PcmDecoderPlugin.cxx6
-rw-r--r--src/decoder/SndfileDecoderPlugin.cxx14
-rw-r--r--src/decoder/VorbisDecoderPlugin.cxx20
-rw-r--r--src/decoder/VorbisDomain.cxx24
-rw-r--r--src/decoder/VorbisDomain.hxx27
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx26
-rw-r--r--src/decoder/WildmidiDecoderPlugin.cxx11
-rw-r--r--src/decoder/sidplay_decoder_plugin.cxx35
31 files changed, 424 insertions, 230 deletions
diff --git a/src/decoder/AdPlugDecoderPlugin.cxx b/src/decoder/AdPlugDecoderPlugin.cxx
index 5c04e116d..3ec48cb23 100644
--- a/src/decoder/AdPlugDecoderPlugin.cxx
+++ b/src/decoder/AdPlugDecoderPlugin.cxx
@@ -23,6 +23,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include <adplug/adplug.h>
#include <adplug/emuopl.h>
@@ -31,9 +32,6 @@
#include <assert.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "adplug"
-
static unsigned sample_rate;
static bool
@@ -43,7 +41,7 @@ adplug_init(const config_param &param)
sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return false;
}
diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx
index 1ee57de4a..c7b1b1016 100644
--- a/src/decoder/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/AudiofileDecoderPlugin.cxx
@@ -24,19 +24,19 @@
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <audiofile.h>
#include <af_vfs.h>
-#include <assert.h>
-#include <glib.h>
-#include <stdio.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "audiofile"
+#include <assert.h>
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020
+static constexpr Domain audiofile_domain("audiofile");
+
static int audiofile_get_duration(const char *file)
{
int total_time;
@@ -59,7 +59,7 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
Error error;
size_t nbytes = is->LockRead(data, length, error);
if (nbytes == 0 && error.IsDefined()) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return -1;
}
@@ -143,8 +143,9 @@ audiofile_setup_sample_format(AFfilehandle af_fp)
afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits);
if (!audio_valid_sample_format(audiofile_bits_to_sample_format(bits))) {
- g_debug("input file has %d bit samples, converting to 16",
- bits);
+ FormatDebug(audiofile_domain,
+ "input file has %d bit samples, converting to 16",
+ bits);
bits = 16;
}
@@ -168,7 +169,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
char chunk[CHUNK_SIZE];
if (!is->IsSeekable()) {
- g_warning("not seekable");
+ LogWarning(audiofile_domain, "not seekable");
return;
}
@@ -176,7 +177,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
af_fp = afOpenVirtualFile(vf, "r", nullptr);
if (af_fp == AF_NULL_FILEHANDLE) {
- g_warning("failed to input stream\n");
+ LogWarning(audiofile_domain, "failed to input stream");
return;
}
@@ -186,7 +187,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
audiofile_setup_sample_format(af_fp),
afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK),
error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
afCloseFile(af_fp);
return;
}
@@ -232,8 +233,9 @@ audiofile_scan_file(const char *file,
int total_time = audiofile_get_duration(file);
if (total_time < 0) {
- g_debug("Failed to get total song time from: %s\n",
- file);
+ FormatWarning(audiofile_domain,
+ "Failed to get total song time from: %s",
+ file);
return false;
}
diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx
index 80b88a2c2..43002768a 100644
--- a/src/decoder/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/DsdiffDecoderPlugin.cxx
@@ -35,13 +35,11 @@
#include "util/Error.hxx"
#include "tag/TagHandler.hxx"
#include "DsdLib.hxx"
+#include "Log.hxx"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "dsdiff"
-
struct DsdiffHeader {
struct dsdlib_id id;
uint32_t size_high, size_low;
@@ -437,7 +435,7 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD,
metadata.channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return;
}
diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx
index b327fc9dc..4c4a66aaa 100644
--- a/src/decoder/DsfDecoderPlugin.cxx
+++ b/src/decoder/DsfDecoderPlugin.cxx
@@ -36,13 +36,11 @@
#include "util/Error.hxx"
#include "DsdLib.hxx"
#include "tag/TagHandler.hxx"
+#include "Log.hxx"
#include <unistd.h>
#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "dsf"
-
struct DsfMetaData {
unsigned sample_rate, channels;
bool bitreverse;
@@ -290,7 +288,7 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD,
metadata.channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return;
}
/* Calculate song time from DSD chunk size and sample frequency */
diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx
index f026a6216..de846c61a 100644
--- a/src/decoder/FaadDecoderPlugin.cxx
+++ b/src/decoder/FaadDecoderPlugin.cxx
@@ -26,18 +26,14 @@
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
+#include "Log.hxx"
#include <neaacdec.h>
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
#include <unistd.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "faad"
-
#define AAC_MAX_CHANNELS 6
static const unsigned adts_sample_rates[] =
@@ -395,7 +391,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
Error error;
ret = faad_decoder_init(decoder, buffer, audio_format, error);
if (!ret) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
NeAACDecClose(decoder);
return;
}
@@ -424,21 +420,24 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
decoded = faad_decoder_decode(decoder, buffer, &frame_info);
if (frame_info.error > 0) {
- g_warning("error decoding AAC stream: %s\n",
- NeAACDecGetErrorMessage(frame_info.error));
+ FormatWarning(faad_decoder_domain,
+ "error decoding AAC stream: %s",
+ NeAACDecGetErrorMessage(frame_info.error));
break;
}
if (frame_info.channels != audio_format.channels) {
- g_warning("channel count changed from %u to %u",
- audio_format.channels, frame_info.channels);
+ FormatInfo(faad_decoder_domain,
+ "channel count changed from %u to %u",
+ audio_format.channels, frame_info.channels);
break;
}
if (frame_info.samplerate != audio_format.sample_rate) {
- g_warning("sample rate changed from %u to %lu",
- audio_format.sample_rate,
- (unsigned long)frame_info.samplerate);
+ FormatInfo(faad_decoder_domain,
+ "sample rate changed from %u to %lu",
+ audio_format.sample_rate,
+ (unsigned long)frame_info.samplerate);
break;
}
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx
index a725e1f7d..646b8f974 100644
--- a/src/decoder/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/FfmpegDecoderPlugin.cxx
@@ -28,6 +28,8 @@
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "LogV.hxx"
#include <glib.h>
@@ -50,27 +52,26 @@ extern "C" {
#include <libavutil/dict.h>
}
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "ffmpeg"
+static constexpr Domain ffmpeg_domain("ffmpeg");
/* suppress the ffmpeg compatibility macro */
#ifdef SampleFormat
#undef SampleFormat
#endif
-static GLogLevelFlags
-level_ffmpeg_to_glib(int level)
+static LogLevel
+import_ffmpeg_level(int level)
{
if (level <= AV_LOG_FATAL)
- return G_LOG_LEVEL_CRITICAL;
+ return LogLevel::ERROR;
- if (level <= AV_LOG_ERROR)
- return G_LOG_LEVEL_WARNING;
+ if (level <= AV_LOG_WARNING)
+ return LogLevel::WARNING;
if (level <= AV_LOG_INFO)
- return G_LOG_LEVEL_MESSAGE;
+ return LogLevel::INFO;
- return G_LOG_LEVEL_DEBUG;
+ return LogLevel::DEBUG;
}
static void
@@ -83,8 +84,9 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level,
cls = *(const AVClass *const*)ptr;
if (cls != NULL) {
- char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL);
- g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl);
+ char *domain = g_strconcat(ffmpeg_domain.GetName(), "/", cls->item_name(ptr), NULL);
+ const Domain d(domain);
+ LogFormatV(d, import_ffmpeg_level(level), fmt, vl);
g_free(domain);
}
}
@@ -287,7 +289,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
if (len < 0) {
/* if error, we skip the frame */
- g_message("decoding failed, frame skipped\n");
+ LogInfo(ffmpeg_domain,
+ "decoding failed, frame skipped");
break;
}
@@ -328,11 +331,13 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
sample_fmt);
if (name != NULL)
- g_warning("Unsupported libavcodec SampleFormat value: %s (%d)",
- name, sample_fmt);
+ FormatError(ffmpeg_domain,
+ "Unsupported libavcodec SampleFormat value: %s (%d)",
+ name, sample_fmt);
else
- g_warning("Unsupported libavcodec SampleFormat value: %d",
- sample_fmt);
+ FormatError(ffmpeg_domain,
+ "Unsupported libavcodec SampleFormat value: %d",
+ sample_fmt);
return SampleFormat::UNDEFINED;
}
@@ -377,12 +382,12 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (input_format == NULL)
return;
- g_debug("detected input format '%s' (%s)",
- input_format->name, input_format->long_name);
+ FormatDebug(ffmpeg_domain, "detected input format '%s' (%s)",
+ input_format->name, input_format->long_name);
AvioStream stream(decoder, input);
if (!stream.Open()) {
- g_warning("Failed to open stream");
+ LogError(ffmpeg_domain, "Failed to open stream");
return;
}
@@ -391,21 +396,21 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (mpd_ffmpeg_open_input(&format_context, stream.io,
input->uri.c_str(),
input_format) != 0) {
- g_warning("Open failed\n");
+ LogError(ffmpeg_domain, "Open failed");
return;
}
const int find_result =
avformat_find_stream_info(format_context, NULL);
if (find_result < 0) {
- g_warning("Couldn't find stream info\n");
+ LogError(ffmpeg_domain, "Couldn't find stream info");
avformat_close_input(&format_context);
return;
}
int audio_stream = ffmpeg_find_audio_stream(format_context);
if (audio_stream == -1) {
- g_warning("No audio stream inside\n");
+ LogError(ffmpeg_domain, "No audio stream inside");
avformat_close_input(&format_context);
return;
}
@@ -414,12 +419,13 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
AVCodecContext *codec_context = av_stream->codec;
if (codec_context->codec_name[0] != 0)
- g_debug("codec '%s'", codec_context->codec_name);
+ FormatDebug(ffmpeg_domain, "codec '%s'",
+ codec_context->codec_name);
AVCodec *codec = avcodec_find_decoder(codec_context->codec_id);
if (!codec) {
- g_warning("Unsupported audio codec\n");
+ LogError(ffmpeg_domain, "Unsupported audio codec");
avformat_close_input(&format_context);
return;
}
@@ -435,7 +441,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
codec_context->sample_rate,
sample_format,
codec_context->channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
avformat_close_input(&format_context);
return;
}
@@ -447,7 +453,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
const int open_result = avcodec_open2(codec_context, codec, NULL);
if (open_result < 0) {
- g_warning("Could not open codec\n");
+ LogError(ffmpeg_domain, "Could not open codec");
avformat_close_input(&format_context);
return;
}
@@ -461,7 +467,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
AVFrame *frame = avcodec_alloc_frame();
if (!frame) {
- g_warning("Could not allocate frame\n");
+ LogError(ffmpeg_domain, "Could not allocate frame");
avformat_close_input(&format_context);
return;
}
diff --git a/src/decoder/FfmpegMetaData.cxx b/src/decoder/FfmpegMetaData.cxx
index f4b7386ef..9965e4d28 100644
--- a/src/decoder/FfmpegMetaData.cxx
+++ b/src/decoder/FfmpegMetaData.cxx
@@ -25,9 +25,6 @@
#include "tag/TagTable.hxx"
#include "tag/TagHandler.hxx"
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "ffmpeg"
-
static const struct tag_table ffmpeg_tags[] = {
{ "year", TAG_DATE },
{ "author-sort", TAG_ARTIST_SORT },
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index 9f5d81f85..6bafeb9c2 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -27,8 +27,8 @@
#include "FlacPcm.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
-
-#include <glib.h>
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <assert.h>
@@ -74,7 +74,7 @@ flac_got_stream_info(struct flac_data *data,
stream_info->sample_rate,
flac_sample_format(stream_info->bits_per_sample),
stream_info->channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
data->unsupported = true;
return;
}
@@ -136,7 +136,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
header->sample_rate,
flac_sample_format(header->bits_per_sample),
header->channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
data->unsupported = true;
return false;
}
diff --git a/src/decoder/FlacCommon.hxx b/src/decoder/FlacCommon.hxx
index f9fade6fc..726e9de92 100644
--- a/src/decoder/FlacCommon.hxx
+++ b/src/decoder/FlacCommon.hxx
@@ -31,9 +31,6 @@
#include <FLAC/stream_decoder.h>
#include <FLAC/metadata.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "flac"
-
struct flac_data : public FlacInput {
PcmBuffer buffer;
diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx
index a6b10fbe2..7ce44febd 100644
--- a/src/decoder/FlacDecoderPlugin.cxx
+++ b/src/decoder/FlacDecoderPlugin.cxx
@@ -19,10 +19,12 @@
#include "config.h" /* must be first for large file support */
#include "FlacDecoderPlugin.h"
+#include "FlacDomain.hxx"
#include "FlacCommon.hxx"
#include "FlacMetadata.hxx"
#include "OggCodec.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include <glib.h>
@@ -54,7 +56,7 @@ static void flacPrintErroredState(FLAC__StreamDecoderState state)
break;
}
- g_warning("%s\n", FLAC__StreamDecoderStateString[state]);
+ LogError(flac_domain, FLAC__StreamDecoderStateString[state]);
}
static void flacMetadata(gcc_unused const FLAC__StreamDecoder * dec,
@@ -90,8 +92,9 @@ flac_scan_file(const char *file,
{
FlacMetadataChain chain;
if (!chain.Read(file)) {
- g_debug("Failed to read FLAC tags: %s",
- chain.GetStatusString());
+ FormatDebug(flac_domain,
+ "Failed to read FLAC tags: %s",
+ chain.GetStatusString());
return false;
}
@@ -105,8 +108,9 @@ flac_scan_stream(struct input_stream *is,
{
FlacMetadataChain chain;
if (!chain.Read(is)) {
- g_debug("Failed to read FLAC tags: %s",
- chain.GetStatusString());
+ FormatDebug(flac_domain,
+ "Failed to read FLAC tags: %s",
+ chain.GetStatusString());
return false;
}
@@ -122,12 +126,14 @@ flac_decoder_new(void)
{
FLAC__StreamDecoder *sd = FLAC__stream_decoder_new();
if (sd == nullptr) {
- g_warning("FLAC__stream_decoder_new() failed");
+ LogError(flac_domain,
+ "FLAC__stream_decoder_new() failed");
return nullptr;
}
if(!FLAC__stream_decoder_set_metadata_respond(sd, FLAC__METADATA_TYPE_VORBIS_COMMENT))
- g_debug("FLAC__stream_decoder_set_metadata_respond() has failed");
+ LogDebug(flac_domain,
+ "FLAC__stream_decoder_set_metadata_respond() has failed");
return sd;
}
@@ -139,7 +145,7 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
data->total_frames = duration;
if (!FLAC__stream_decoder_process_until_end_of_metadata(sd)) {
- g_warning("problem reading metadata");
+ LogWarning(flac_domain, "problem reading metadata");
return false;
}
@@ -265,7 +271,8 @@ flac_decode_internal(struct decoder * decoder,
stream_init(flac_dec, &data, is_ogg);
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_delete(flac_dec);
- g_warning("%s", FLAC__StreamDecoderInitStatusString[status]);
+ LogWarning(flac_domain,
+ FLAC__StreamDecoderInitStatusString[status]);
return;
}
@@ -299,8 +306,9 @@ oggflac_scan_file(const char *file,
{
FlacMetadataChain chain;
if (!chain.ReadOgg(file)) {
- g_debug("Failed to read OggFLAC tags: %s",
- chain.GetStatusString());
+ FormatDebug(flac_domain,
+ "Failed to read OggFLAC tags: %s",
+ chain.GetStatusString());
return false;
}
@@ -314,8 +322,9 @@ oggflac_scan_stream(struct input_stream *is,
{
FlacMetadataChain chain;
if (!chain.ReadOgg(is)) {
- g_debug("Failed to read OggFLAC tags: %s",
- chain.GetStatusString());
+ FormatDebug(flac_domain,
+ "Failed to read OggFLAC tags: %s",
+ chain.GetStatusString());
return false;
}
diff --git a/src/decoder/FlacDomain.cxx b/src/decoder/FlacDomain.cxx
new file mode 100644
index 000000000..2bc91079e
--- /dev/null
+++ b/src/decoder/FlacDomain.cxx
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "FlacDomain.hxx"
+#include "util/Domain.hxx"
+
+const Domain flac_domain("flac");
diff --git a/src/decoder/FlacDomain.hxx b/src/decoder/FlacDomain.hxx
new file mode 100644
index 000000000..8d5b825ed
--- /dev/null
+++ b/src/decoder/FlacDomain.hxx
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_FLAC_DOMAIN_HXX
+#define MPD_FLAC_DOMAIN_HXX
+
+#include "check.h"
+
+extern const class Domain flac_domain;
+
+#endif
diff --git a/src/decoder/FlacInput.cxx b/src/decoder/FlacInput.cxx
index 19abfca81..88b942971 100644
--- a/src/decoder/FlacInput.cxx
+++ b/src/decoder/FlacInput.cxx
@@ -19,9 +19,11 @@
#include "config.h"
#include "FlacInput.hxx"
+#include "FlacDomain.hxx"
#include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include "gcc.h"
FLAC__StreamDecoderReadStatus
@@ -49,8 +51,10 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
::Error error;
- if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error))
+ if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error)) {
+ LogError(error);
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
+ }
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
}
@@ -89,7 +93,8 @@ FlacInput::Error(FLAC__StreamDecoderErrorStatus status)
{
if (decoder == nullptr ||
decoder_get_command(decoder) != DecoderCommand::STOP)
- g_warning("%s", FLAC__StreamDecoderErrorStatusString[status]);
+ LogWarning(flac_domain,
+ FLAC__StreamDecoderErrorStatusString[status]);
}
FLAC__StreamDecoderReadStatus
diff --git a/src/decoder/FluidsynthDecoderPlugin.cxx b/src/decoder/FluidsynthDecoderPlugin.cxx
index 4db4f1618..99f1598c8 100644
--- a/src/decoder/FluidsynthDecoderPlugin.cxx
+++ b/src/decoder/FluidsynthDecoderPlugin.cxx
@@ -22,13 +22,14 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <glib.h>
#include <fluidsynth.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "fluidsynth"
+static constexpr Domain fluidsynth_domain("fluidsynth");
static unsigned sample_rate;
static const char *soundfont_path;
@@ -36,27 +37,27 @@ static const char *soundfont_path;
/**
* Convert a fluidsynth log level to a GLib log level.
*/
-static GLogLevelFlags
-fluidsynth_level_to_glib(enum fluid_log_level level)
+static LogLevel
+fluidsynth_level_to_mpd(enum fluid_log_level level)
{
switch (level) {
case FLUID_PANIC:
case FLUID_ERR:
- return G_LOG_LEVEL_CRITICAL;
+ return LogLevel::ERROR;
case FLUID_WARN:
- return G_LOG_LEVEL_WARNING;
+ return LogLevel::WARNING;
case FLUID_INFO:
- return G_LOG_LEVEL_INFO;
+ return LogLevel::INFO;
case FLUID_DBG:
case LAST_LOG_LEVEL:
- return G_LOG_LEVEL_DEBUG;
+ return LogLevel::DEBUG;
}
/* invalid fluidsynth log level */
- return G_LOG_LEVEL_MESSAGE;
+ return LogLevel::INFO;
}
/**
@@ -66,8 +67,9 @@ fluidsynth_level_to_glib(enum fluid_log_level level)
static void
fluidsynth_mpd_log_function(int level, char *message, gcc_unused void *data)
{
- g_log(G_LOG_DOMAIN, fluidsynth_level_to_glib(fluid_log_level(level)),
- "%s", message);
+ Log(fluidsynth_domain,
+ fluidsynth_level_to_mpd(fluid_log_level(level)),
+ message);
}
static bool
@@ -77,7 +79,7 @@ fluidsynth_init(const config_param &param)
sample_rate = param.GetBlockValue("sample_rate", 48000u);
if (!audio_check_sample_rate(sample_rate, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return false;
}
@@ -125,7 +127,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
ret = fluid_synth_sfload(synth, soundfont_path, true);
if (ret < 0) {
- g_warning("fluid_synth_sfload() failed");
+ LogWarning(fluidsynth_domain, "fluid_synth_sfload() failed");
delete_fluid_synth(synth);
delete_fluid_settings(settings);
return;
@@ -142,7 +144,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
ret = fluid_player_add(player, path_fs);
if (ret != 0) {
- g_warning("fluid_player_add() failed");
+ LogWarning(fluidsynth_domain, "fluid_player_add() failed");
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);
@@ -153,7 +155,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
ret = fluid_player_play(player);
if (ret != 0) {
- g_warning("fluid_player_play() failed");
+ LogWarning(fluidsynth_domain, "fluid_player_play() failed");
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);
diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx
index dbe1d000f..bbcc9618a 100644
--- a/src/decoder/GmeDecoderPlugin.cxx
+++ b/src/decoder/GmeDecoderPlugin.cxx
@@ -24,6 +24,8 @@
#include "tag/TagHandler.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <glib.h>
#include <assert.h>
@@ -32,11 +34,10 @@
#include <gme/gme.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "gme"
-
#define SUBTUNE_PREFIX "tune_"
+static constexpr Domain gme_domain("gme");
+
static constexpr unsigned GME_SAMPLE_RATE = 44100;
static constexpr unsigned GME_CHANNELS = 2;
static constexpr unsigned GME_BUFFER_FRAMES = 2048;
@@ -106,7 +107,7 @@ gme_container_scan(const char *path_fs, const unsigned int tnum)
Music_Emu *emu;
const char *gme_err = gme_open_file(path_fs, &emu, GME_SAMPLE_RATE);
if (gme_err != nullptr) {
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
return nullptr;
}
@@ -134,7 +135,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
gme_open_file(path_container, &emu, GME_SAMPLE_RATE);
g_free(path_container);
if (gme_err != nullptr) {
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
return;
}
@@ -142,7 +143,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
const int song_num = get_song_num(path_fs);
gme_err = gme_track_info(emu, &ti, song_num);
if (gme_err != nullptr) {
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
gme_delete(emu);
return;
}
@@ -158,7 +159,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
if (!audio_format_init_checked(audio_format, GME_SAMPLE_RATE,
SampleFormat::S16, GME_CHANNELS,
error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
gme_free_info(ti);
gme_delete(emu);
return;
@@ -168,7 +169,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
gme_err = gme_start_track(emu, song_num);
if (gme_err != nullptr)
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
if (ti->length > 0)
gme_set_fade(emu, ti->length);
@@ -179,7 +180,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
short buf[GME_BUFFER_SAMPLES];
gme_err = gme_play(emu, GME_BUFFER_SAMPLES, buf);
if (gme_err != nullptr) {
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
return;
}
@@ -188,7 +189,7 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
float where = decoder_seek_where(decoder);
gme_err = gme_seek(emu, int(where * 1000));
if (gme_err != nullptr)
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
decoder_command_finished(decoder);
}
@@ -211,7 +212,7 @@ gme_scan_file(const char *path_fs,
gme_open_file(path_container, &emu, GME_SAMPLE_RATE);
g_free(path_container);
if (gme_err != nullptr) {
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
return false;
}
@@ -220,7 +221,7 @@ gme_scan_file(const char *path_fs,
gme_info_t *ti;
gme_err = gme_track_info(emu, &ti, song_num);
if (gme_err != nullptr) {
- g_warning("%s", gme_err);
+ LogWarning(gme_domain, gme_err);
gme_delete(emu);
return false;
}
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index b7d90892b..1cce24f31 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -27,6 +27,8 @@
#include "tag/TagHandler.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <assert.h>
#include <unistd.h>
@@ -40,9 +42,6 @@
#include <id3tag.h>
#endif
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "mad"
-
#define FRAMES_CUSHION 2000
#define READ_BUFFER_SIZE 40960
@@ -65,6 +64,8 @@ enum muteframe {
#define DEFAULT_GAPLESS_MP3_PLAYBACK true
+static constexpr Domain mad_domain("mad");
+
static bool gapless_playback;
static inline int32_t
@@ -367,7 +368,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
}
if (count != tagsize) {
- g_debug("error parsing ID3 tag");
+ LogDebug(mad_domain, "error parsing ID3 tag");
g_free(allocated);
return;
}
@@ -482,9 +483,9 @@ MadDecoder::DecodeNextFrameHeader(Tag **tag)
if (stream.error == MAD_ERROR_BUFLEN)
return DECODE_CONT;
else {
- g_warning("unrecoverable frame level error "
- "(%s).\n",
- mad_stream_errorstr(&stream));
+ FormatWarning(mad_domain,
+ "unrecoverable frame level error: %s",
+ mad_stream_errorstr(&stream));
return DECODE_BREAK;
}
}
@@ -529,9 +530,9 @@ MadDecoder::DecodeNextFrame()
if (stream.error == MAD_ERROR_BUFLEN)
return DECODE_CONT;
else {
- g_warning("unrecoverable frame level error "
- "(%s).\n",
- mad_stream_errorstr(&stream));
+ FormatWarning(mad_domain,
+ "unrecoverable frame level error: %s",
+ mad_stream_errorstr(&stream));
return DECODE_BREAK;
}
}
@@ -702,8 +703,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
&lame->version.major, &lame->version.minor) != 2)
return false;
- g_debug("detected LAME version %i.%i (\"%s\")\n",
- lame->version.major, lame->version.minor, lame->encoder);
+ FormatDebug(mad_domain, "detected LAME version %i.%i (\"%s\")",
+ lame->version.major, lame->version.minor, lame->encoder);
/* The reference volume was changed from the 83dB used in the
* ReplayGain spec to 89dB in lame 3.95.1. Bump the gain for older
@@ -719,7 +720,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
mad_bit_read(ptr, 16);
lame->peak = mad_f_todouble(mad_bit_read(ptr, 32) << 5); /* peak */
- g_debug("LAME peak found: %f\n", lame->peak);
+ FormatDebug(mad_domain, "LAME peak found: %f", lame->peak);
lame->track_gain = 0;
name = mad_bit_read(ptr, 3); /* gain name */
@@ -728,7 +729,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
gain = mad_bit_read(ptr, 9); /* gain*10 */
if (gain && name == 1 && orig != 0) {
lame->track_gain = ((sign ? -gain : gain) / 10.0) + adj;
- g_debug("LAME track gain found: %f\n", lame->track_gain);
+ FormatDebug(mad_domain, "LAME track gain found: %f",
+ lame->track_gain);
}
/* tmz reports that this isn't currently written by any version of lame
@@ -743,7 +745,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
gain = mad_bit_read(ptr, 9); /* gain*10 */
if (gain && name == 2 && orig != 0) {
lame->album_gain = ((sign ? -gain : gain) / 10.0) + adj;
- g_debug("LAME album gain found: %f\n", lame->track_gain);
+ FormatDebug(mad_domain, "LAME album gain found: %f",
+ lame->track_gain);
}
#else
mad_bit_read(ptr, 16);
@@ -754,8 +757,8 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
lame->encoder_delay = mad_bit_read(ptr, 12);
lame->encoder_padding = mad_bit_read(ptr, 12);
- g_debug("encoder delay is %i, encoder padding is %i\n",
- lame->encoder_delay, lame->encoder_padding);
+ FormatDebug(mad_domain, "encoder delay is %i, encoder padding is %i",
+ lame->encoder_delay, lame->encoder_padding);
mad_bit_read(ptr, 80);
@@ -880,8 +883,9 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
return false;
if (max_frames > 8 * 1024 * 1024) {
- g_warning("mp3 file header indicates too many frames: %lu\n",
- max_frames);
+ FormatWarning(mad_domain,
+ "mp3 file header indicates too many frames: %lu",
+ max_frames);
return false;
}
@@ -1120,8 +1124,8 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
delete tag;
if (decoder_get_command(decoder) == DecoderCommand::NONE)
- g_warning
- ("Input does not appear to be a mp3 bit stream.\n");
+ LogError(mad_domain,
+ "Input does not appear to be a mp3 bit stream");
return;
}
@@ -1132,7 +1136,7 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
SampleFormat::S24_P32,
MAD_NCHANNELS(&data.frame.header),
error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
delete tag;
return;
}
diff --git a/src/decoder/MikmodDecoderPlugin.cxx b/src/decoder/MikmodDecoderPlugin.cxx
index 78a26891a..fb82eb732 100644
--- a/src/decoder/MikmodDecoderPlugin.cxx
+++ b/src/decoder/MikmodDecoderPlugin.cxx
@@ -22,13 +22,14 @@
#include "DecoderAPI.hxx"
#include "tag/TagHandler.hxx"
#include "system/FatalError.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <glib.h>
#include <mikmod.h>
#include <assert.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "mikmod"
+static constexpr Domain mikmod_domain("mikmod");
/* this is largely copied from alsaplayer */
@@ -127,8 +128,9 @@ mikmod_decoder_init(const config_param &param)
DMODE_16BITS);
if (MikMod_Init(params)) {
- g_warning("Could not init MikMod: %s\n",
- MikMod_strerror(MikMod_errno));
+ FormatError(mikmod_domain,
+ "Could not init MikMod: %s",
+ MikMod_strerror(MikMod_errno));
return false;
}
@@ -154,7 +156,8 @@ mikmod_decoder_file_decode(struct decoder *decoder, const char *path_fs)
g_free(path2);
if (handle == nullptr) {
- g_warning("failed to open mod: %s", path_fs);
+ FormatError(mikmod_domain,
+ "failed to open mod: %s", path_fs);
return;
}
@@ -187,7 +190,8 @@ mikmod_decoder_scan_file(const char *path_fs,
if (handle == nullptr) {
g_free(path2);
- g_debug("Failed to open file: %s", path_fs);
+ FormatDebug(mikmod_domain,
+ "Failed to open file: %s", path_fs);
return false;
}
diff --git a/src/decoder/ModplugDecoderPlugin.cxx b/src/decoder/ModplugDecoderPlugin.cxx
index 9cbf44b15..39c366492 100644
--- a/src/decoder/ModplugDecoderPlugin.cxx
+++ b/src/decoder/ModplugDecoderPlugin.cxx
@@ -22,6 +22,8 @@
#include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "tag/TagHandler.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <libmodplug/modplug.h>
@@ -29,8 +31,7 @@
#include <assert.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "modplug"
+static constexpr Domain modplug_domain("modplug");
static constexpr size_t MODPLUG_FRAME_SIZE = 4096;
static constexpr size_t MODPLUG_PREALLOC_BLOCK = 256 * 1024;
@@ -43,12 +44,12 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is)
const goffset size = is->GetSize();
if (size == 0) {
- g_warning("file is empty");
+ LogWarning(modplug_domain, "file is empty");
return nullptr;
}
if (size > MODPLUG_FILE_LIMIT) {
- g_warning("file too large");
+ LogWarning(modplug_domain, "file too large");
return nullptr;
}
@@ -77,7 +78,7 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is)
}
if (goffset(bdatas->len + ret) > MODPLUG_FILE_LIMIT) {
- g_warning("stream too large\n");
+ LogWarning(modplug_domain, "stream too large");
g_free(data);
g_byte_array_free(bdatas, TRUE);
return nullptr;
@@ -103,7 +104,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
bdatas = mod_loadfile(decoder, is);
if (!bdatas) {
- g_warning("could not load stream\n");
+ LogWarning(modplug_domain, "could not load stream");
return;
}
@@ -119,7 +120,7 @@ mod_decode(struct decoder *decoder, struct input_stream *is)
f = ModPlug_Load(bdatas->data, bdatas->len);
g_byte_array_free(bdatas, TRUE);
if (!f) {
- g_warning("could not decode stream\n");
+ LogWarning(modplug_domain, "could not decode stream");
return;
}
diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx
index 252fe92e6..c0785accc 100644
--- a/src/decoder/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/MpcdecDecoderPlugin.cxx
@@ -24,6 +24,8 @@
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <mpc/mpcdec.h>
@@ -32,14 +34,13 @@
#include <unistd.h>
#include <math.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "mpcdec"
-
struct mpc_decoder_data {
struct input_stream *is;
struct decoder *decoder;
};
+static constexpr Domain mpcdec_domain("mpcdec");
+
static mpc_int32_t
mpc_read_cb(mpc_reader *reader, void *ptr, mpc_int32_t size)
{
@@ -148,7 +149,8 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
mpc_demux *demux = mpc_demux_init(&reader);
if (demux == nullptr) {
if (decoder_get_command(mpd_decoder) != DecoderCommand::STOP)
- g_warning("Not a valid musepack stream");
+ LogWarning(mpcdec_domain,
+ "Not a valid musepack stream");
return;
}
@@ -160,7 +162,7 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, info.sample_freq,
SampleFormat::S24_P32,
info.channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
mpc_demux_exit(demux);
return;
}
@@ -199,7 +201,8 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
frame.buffer = (MPC_SAMPLE_FORMAT *)sample_buffer;
mpc_status status = mpc_demux_decode(demux, &frame);
if (status != MPC_STATUS_OK) {
- g_warning("Failed to decode sample");
+ LogWarning(mpcdec_domain,
+ "Failed to decode sample");
break;
}
diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx
index 3100a0f1c..928af39e6 100644
--- a/src/decoder/Mpg123DecoderPlugin.cxx
+++ b/src/decoder/Mpg123DecoderPlugin.cxx
@@ -23,14 +23,15 @@
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <glib.h>
#include <mpg123.h>
#include <stdio.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "mpg123"
+static constexpr Domain mpg123_domain("mpg123");
static bool
mpd_mpg123_init(gcc_unused const config_param &param)
@@ -70,8 +71,9 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
error = mpg123_open(handle, path_dup);
g_free(path_dup);
if (error != MPG123_OK) {
- g_warning("libmpg123 failed to open %s: %s",
- path_fs, mpg123_plain_strerror(error));
+ FormatWarning(mpg123_domain,
+ "libmpg123 failed to open %s: %s",
+ path_fs, mpg123_plain_strerror(error));
return false;
}
@@ -79,21 +81,24 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
error = mpg123_getformat(handle, &rate, &channels, &encoding);
if (error != MPG123_OK) {
- g_warning("mpg123_getformat() failed: %s",
- mpg123_plain_strerror(error));
+ FormatWarning(mpg123_domain,
+ "mpg123_getformat() failed: %s",
+ mpg123_plain_strerror(error));
return false;
}
if (encoding != MPG123_ENC_SIGNED_16) {
/* other formats not yet implemented */
- g_warning("expected MPG123_ENC_SIGNED_16, got %d", encoding);
+ FormatWarning(mpg123_domain,
+ "expected MPG123_ENC_SIGNED_16, got %d",
+ encoding);
return false;
}
Error error2;
if (!audio_format_init_checked(audio_format, rate, SampleFormat::S16,
channels, error2)) {
- g_warning("%s", error2.GetMessage());
+ LogError(error2);
return false;
}
@@ -112,8 +117,9 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
handle = mpg123_new(nullptr, &error);
if (handle == nullptr) {
- g_warning("mpg123_new() failed: %s",
- mpg123_plain_strerror(error));
+ FormatError(mpg123_domain,
+ "mpg123_new() failed: %s",
+ mpg123_plain_strerror(error));
return;
}
@@ -158,8 +164,9 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
error = mpg123_read(handle, buffer, sizeof(buffer), &nbytes);
if (error != MPG123_OK) {
if (error != MPG123_DONE)
- g_warning("mpg123_read() failed: %s",
- mpg123_plain_strerror(error));
+ FormatWarning(mpg123_domain,
+ "mpg123_read() failed: %s",
+ mpg123_plain_strerror(error));
break;
}
@@ -204,8 +211,9 @@ mpd_mpg123_scan_file(const char *path_fs,
handle = mpg123_new(nullptr, &error);
if (handle == nullptr) {
- g_warning("mpg123_new() failed: %s",
- mpg123_plain_strerror(error));
+ FormatError(mpg123_domain,
+ "mpg123_new() failed: %s",
+ mpg123_plain_strerror(error));
return false;
}
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx
index ea1d6660c..96c52a083 100644
--- a/src/decoder/OpusDecoderPlugin.cxx
+++ b/src/decoder/OpusDecoderPlugin.cxx
@@ -19,6 +19,7 @@
#include "config.h" /* must be first for large file support */
#include "OpusDecoderPlugin.h"
+#include "OpusDomain.hxx"
#include "OpusHead.hxx"
#include "OpusTags.hxx"
#include "OggUtil.hxx"
@@ -31,6 +32,7 @@
#include "tag/TagBuilder.hxx"
#include "InputStream.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include <opus.h>
#include <ogg/ogg.h>
@@ -40,9 +42,6 @@
#include <stdio.h>
#include <string.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "opus"
-
static const opus_int32 opus_sample_rate = 48000;
gcc_pure
@@ -62,7 +61,7 @@ IsOpusTags(const ogg_packet &packet)
static bool
mpd_opus_init(gcc_unused const config_param &param)
{
- g_debug("%s", opus_get_version_string());
+ LogDebug(opus_domain, opus_get_version_string());
return true;
}
@@ -199,8 +198,8 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet)
opus_decoder = opus_decoder_create(opus_sample_rate, channels,
&opus_error);
if (opus_decoder == nullptr) {
- g_warning("libopus error: %s",
- opus_strerror(opus_error));
+ FormatError(opus_domain, "libopus error: %s",
+ opus_strerror(opus_error));
return DecoderCommand::STOP;
}
@@ -249,7 +248,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
output_buffer, output_size,
0);
if (nframes < 0) {
- g_warning("%s", opus_strerror(nframes));
+ LogError(opus_domain, opus_strerror(nframes));
return DecoderCommand::STOP;
}
diff --git a/src/decoder/OpusDomain.cxx b/src/decoder/OpusDomain.cxx
new file mode 100644
index 000000000..2b8bb1bba
--- /dev/null
+++ b/src/decoder/OpusDomain.cxx
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "OpusDomain.hxx"
+#include "util/Domain.hxx"
+
+const Domain opus_domain("opus");
diff --git a/src/decoder/OpusDomain.hxx b/src/decoder/OpusDomain.hxx
new file mode 100644
index 000000000..488eca27d
--- /dev/null
+++ b/src/decoder/OpusDomain.hxx
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_OPUS_DOMAIN_HXX
+#define MPD_OPUS_DOMAIN_HXX
+
+#include "check.h"
+
+extern const class Domain opus_domain;
+
+#endif
diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx
index 94867f01d..6996b583a 100644
--- a/src/decoder/PcmDecoderPlugin.cxx
+++ b/src/decoder/PcmDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
extern "C" {
#include "util/byte_reverse.h"
@@ -32,9 +33,6 @@ extern "C" {
#include <string.h>
#include <stdio.h> /* for SEEK_SET */
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "pcm"
-
static void
pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
{
@@ -86,7 +84,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
if (is->LockSeek(offset, SEEK_SET, error)) {
decoder_command_finished(decoder);
} else {
- g_warning("seeking failed: %s", error.GetMessage());
+ LogError(error);
decoder_seek_error(decoder);
}
diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx
index 56853958c..5c7efe230 100644
--- a/src/decoder/SndfileDecoderPlugin.cxx
+++ b/src/decoder/SndfileDecoderPlugin.cxx
@@ -24,11 +24,12 @@
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <sndfile.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "sndfile"
+static constexpr Domain sndfile_domain("sndfile");
static sf_count_t
sndfile_vio_get_filelen(void *user_data)
@@ -57,7 +58,7 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data)
Error error;
size_t nbytes = is->LockRead(ptr, count, error);
if (nbytes == 0 && error.IsDefined()) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return -1;
}
@@ -124,7 +125,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
sf = sf_open_virtual(&vio, SFM_READ, &info, is);
if (sf == nullptr) {
- g_warning("sf_open_virtual() failed");
+ LogWarning(sndfile_domain, "sf_open_virtual() failed");
return;
}
@@ -136,7 +137,7 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!audio_format_init_checked(audio_format, info.samplerate,
SampleFormat::S32,
info.channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return;
}
@@ -187,7 +188,8 @@ sndfile_scan_file(const char *path_fs,
if (!audio_valid_sample_rate(info.samplerate)) {
sf_close(sf);
- g_warning("Invalid sample rate in %s\n", path_fs);
+ FormatWarning(sndfile_domain,
+ "Invalid sample rate in %s", path_fs);
return false;
}
diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx
index a4a938aa8..55ce943e8 100644
--- a/src/decoder/VorbisDecoderPlugin.cxx
+++ b/src/decoder/VorbisDecoderPlugin.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "VorbisDecoderPlugin.h"
#include "VorbisComments.hxx"
+#include "VorbisDomain.hxx"
#include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "OggCodec.hxx"
@@ -27,6 +28,7 @@
#include "util/UriUtil.hxx"
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
+#include "Log.hxx"
#ifndef HAVE_TREMOR
#define OV_EXCLUDE_STATIC_CALLBACKS
@@ -50,9 +52,6 @@
#include <errno.h>
#include <unistd.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "vorbis"
-
#if G_BYTE_ORDER == G_BIG_ENDIAN
#define VORBIS_BIG_ENDIAN true
#else
@@ -144,8 +143,9 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf,
if (ret < 0) {
if (decoder == NULL ||
decoder_get_command(decoder) == DecoderCommand::NONE)
- g_warning("Failed to open Ogg Vorbis stream: %s",
- vorbis_strerror(ret));
+ FormatWarning(vorbis_domain,
+ "Failed to open Ogg Vorbis stream: %s",
+ vorbis_strerror(ret));
return false;
}
@@ -198,7 +198,7 @@ vorbis_stream_decode(struct decoder *decoder,
const vorbis_info *vi = ov_info(&vf, -1);
if (vi == NULL) {
- g_warning("ov_info() has failed");
+ LogWarning(vorbis_domain, "ov_info() has failed");
return;
}
@@ -211,7 +211,7 @@ vorbis_stream_decode(struct decoder *decoder,
SampleFormat::FLOAT,
#endif
vi->channels, error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return;
}
@@ -272,7 +272,8 @@ vorbis_stream_decode(struct decoder *decoder,
if (current_section != prev_section) {
vi = ov_info(&vf, -1);
if (vi == NULL) {
- g_warning("ov_info() has failed");
+ LogWarning(vorbis_domain,
+ "ov_info() has failed");
break;
}
@@ -280,7 +281,8 @@ vorbis_stream_decode(struct decoder *decoder,
vi->channels != (int)audio_format.channels) {
/* we don't support audio format
change yet */
- g_warning("audio format change, stopping here");
+ LogWarning(vorbis_domain,
+ "audio format change, stopping here");
break;
}
diff --git a/src/decoder/VorbisDomain.cxx b/src/decoder/VorbisDomain.cxx
new file mode 100644
index 000000000..d7c70a641
--- /dev/null
+++ b/src/decoder/VorbisDomain.cxx
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "VorbisDomain.hxx"
+#include "util/Domain.hxx"
+
+const Domain vorbis_domain("vorbis");
diff --git a/src/decoder/VorbisDomain.hxx b/src/decoder/VorbisDomain.hxx
new file mode 100644
index 000000000..69e2e11cb
--- /dev/null
+++ b/src/decoder/VorbisDomain.hxx
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2003-2012 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_VORBIS_DOMAIN_HXX
+#define MPD_VORBIS_DOMAIN_HXX
+
+#include "check.h"
+
+extern const class Domain vorbis_domain;
+
+#endif
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index ecabafefe..8ee898e30 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -25,6 +25,8 @@
#include "tag/TagHandler.hxx"
#include "tag/ApeTag.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <wavpack/wavpack.h>
#include <glib.h>
@@ -33,11 +35,10 @@
#include <stdio.h>
#include <stdlib.h>
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "wavpack"
-
#define ERRORLEN 80
+static constexpr Domain wavpack_domain("wavpack");
+
/** A pointer type for format converter function. */
typedef void (*format_samples_t)(
int bytes_per_sample,
@@ -155,7 +156,7 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
WavpackGetSampleRate(wpc),
sample_format,
WavpackGetNumChannels(wpc), error)) {
- g_warning("%s", error.GetMessage());
+ LogError(error);
return;
}
@@ -294,10 +295,9 @@ wavpack_scan_file(const char *fname,
wpc = WavpackOpenFileInput(fname, error, OPEN_TAGS, 0);
if (wpc == NULL) {
- g_warning(
- "failed to open WavPack file \"%s\": %s\n",
- fname, error
- );
+ FormatError(wavpack_domain,
+ "failed to open WavPack file \"%s\": %s",
+ fname, error);
return false;
}
@@ -532,7 +532,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
);
if (wpc == NULL) {
- g_warning("failed to open WavPack stream: %s\n", error);
+ FormatError(wavpack_domain,
+ "failed to open WavPack stream: %s", error);
return;
}
@@ -558,10 +559,9 @@ wavpack_filedecode(struct decoder *decoder, const char *fname)
OPEN_TAGS | OPEN_WVC | OPEN_NORMALIZE, 23
);
if (wpc == NULL) {
- g_warning(
- "failed to open WavPack file \"%s\": %s\n",
- fname, error
- );
+ FormatWarning(wavpack_domain,
+ "failed to open WavPack file \"%s\": %s",
+ fname, error);
return;
}
diff --git a/src/decoder/WildmidiDecoderPlugin.cxx b/src/decoder/WildmidiDecoderPlugin.cxx
index 3a057ca2c..1a390706f 100644
--- a/src/decoder/WildmidiDecoderPlugin.cxx
+++ b/src/decoder/WildmidiDecoderPlugin.cxx
@@ -22,18 +22,17 @@
#include "DecoderAPI.hxx"
#include "tag/TagHandler.hxx"
#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "system/FatalError.hxx"
-
-#include <glib.h>
+#include "Log.hxx"
extern "C" {
#include <wildmidi_lib.h>
}
-#undef G_LOG_DOMAIN
-#define G_LOG_DOMAIN "wildmidi"
+static constexpr Domain wildmidi_domain("wildmidi");
static constexpr unsigned WILDMIDI_SAMPLE_RATE = 48000;
@@ -49,7 +48,9 @@ wildmidi_init(const config_param &param)
if (!FileExists(path)) {
const auto utf8 = path.ToUTF8();
- g_debug("configuration file does not exist: %s", utf8.c_str());
+ FormatDebug(wildmidi_domain,
+ "configuration file does not exist: %s",
+ utf8.c_str());
return false;
}
diff --git a/src/decoder/sidplay_decoder_plugin.cxx b/src/decoder/sidplay_decoder_plugin.cxx
index fed0476ec..486dd816f 100644
--- a/src/decoder/sidplay_decoder_plugin.cxx
+++ b/src/decoder/sidplay_decoder_plugin.cxx
@@ -20,6 +20,8 @@
#include "config.h"
#include "../DecoderAPI.hxx"
#include "tag/TagHandler.hxx"
+#include "util/Domain.hxx"
+#include "Log.hxx"
#include <errno.h>
#include <stdlib.h>
@@ -30,11 +32,10 @@
#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;
@@ -52,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;
}
@@ -68,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;
@@ -162,7 +165,8 @@ 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];
@@ -205,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;
}
@@ -220,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;
}
@@ -228,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;
}
@@ -274,7 +280,8 @@ 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;
}