aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 18:02:44 +0200
committerMax Kellermann <max@duempel.org>2013-09-04 18:14:22 +0200
commit29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch)
tree79766830b55ebca38ddbce84d8d548227eedb69e /src/decoder
parentc9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff)
downloadmpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/AdPlugDecoderPlugin.cxx8
-rw-r--r--src/decoder/AudiofileDecoderPlugin.cxx22
-rw-r--r--src/decoder/DsdLib.cxx5
-rw-r--r--src/decoder/DsdiffDecoderPlugin.cxx10
-rw-r--r--src/decoder/DsfDecoderPlugin.cxx10
-rw-r--r--src/decoder/FaadDecoderPlugin.cxx33
-rw-r--r--src/decoder/FfmpegDecoderPlugin.cxx15
-rw-r--r--src/decoder/FlacCommon.cxx15
-rw-r--r--src/decoder/FlacDecoderPlugin.cxx3
-rw-r--r--src/decoder/FlacIOHandle.cxx16
-rw-r--r--src/decoder/FlacInput.cxx6
-rw-r--r--src/decoder/FluidsynthDecoderPlugin.cxx8
-rw-r--r--src/decoder/GmeDecoderPlugin.cxx8
-rw-r--r--src/decoder/MadDecoderPlugin.cxx12
-rw-r--r--src/decoder/MpcdecDecoderPlugin.cxx11
-rw-r--r--src/decoder/Mpg123DecoderPlugin.cxx8
-rw-r--r--src/decoder/OpusDecoderPlugin.cxx6
-rw-r--r--src/decoder/PcmDecoderPlugin.cxx9
-rw-r--r--src/decoder/SndfileDecoderPlugin.cxx22
-rw-r--r--src/decoder/VorbisDecoderPlugin.cxx14
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx18
-rw-r--r--src/decoder/WildmidiDecoderPlugin.cxx5
22 files changed, 134 insertions, 130 deletions
diff --git a/src/decoder/AdPlugDecoderPlugin.cxx b/src/decoder/AdPlugDecoderPlugin.cxx
index 47ab1a7f3..f3b986fc8 100644
--- a/src/decoder/AdPlugDecoderPlugin.cxx
+++ b/src/decoder/AdPlugDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "TagHandler.hxx"
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/Error.hxx"
#include <adplug/adplug.h>
#include <adplug/emuopl.h>
@@ -38,12 +39,11 @@ static unsigned sample_rate;
static bool
adplug_init(const config_param &param)
{
- GError *error = NULL;
+ Error error;
sample_rate = param.GetBlockValue("sample_rate", 48000u);
- if (!audio_check_sample_rate(sample_rate, &error)) {
- g_warning("%s\n", error->message);
- g_error_free(error);
+ if (!audio_check_sample_rate(sample_rate, error)) {
+ g_warning("%s", error.GetMessage());
return false;
}
diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx
index 9c00b20ce..c146466cb 100644
--- a/src/decoder/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/AudiofileDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
+#include "util/Error.hxx"
#include <audiofile.h>
#include <af_vfs.h>
@@ -53,13 +54,11 @@ static ssize_t
audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
{
struct input_stream *is = (struct input_stream *) vfile->closure;
- GError *error = nullptr;
- size_t nbytes;
- nbytes = input_stream_lock_read(is, data, length, &error);
- if (nbytes == 0 && error != nullptr) {
- g_warning("%s", error->message);
- g_error_free(error);
+ Error error;
+ size_t nbytes = input_stream_lock_read(is, data, length, error);
+ if (nbytes == 0 && error.IsDefined()) {
+ g_warning("%s", error.GetMessage());
return -1;
}
@@ -93,7 +92,9 @@ audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative)
{
struct input_stream *is = (struct input_stream *) vfile->closure;
int whence = (is_relative ? SEEK_CUR : SEEK_SET);
- if (input_stream_lock_seek(is, offset, whence, nullptr)) {
+
+ Error error;
+ if (input_stream_lock_seek(is, offset, whence, error)) {
return input_stream_get_offset(is);
} else {
return -1;
@@ -156,7 +157,6 @@ audiofile_setup_sample_format(AFfilehandle af_fp)
static void
audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
{
- GError *error = nullptr;
AFvirtualfile *vf;
int fs, frame_count;
AFfilehandle af_fp;
@@ -180,13 +180,13 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is)
return;
}
+ Error error;
if (!audio_format_init_checked(audio_format,
afGetRate(af_fp, AF_DEFAULT_TRACK),
audiofile_setup_sample_format(af_fp),
afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK),
- &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ error)) {
+ g_warning("%s", error.GetMessage());
afCloseFile(af_fp);
return;
}
diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx
index d18131184..a9cfc9147 100644
--- a/src/decoder/DsdLib.cxx
+++ b/src/decoder/DsdLib.cxx
@@ -29,6 +29,7 @@
#include "util/bit_reverse.h"
#include "TagHandler.hxx"
#include "TagId3.hxx"
+#include "util/Error.hxx"
#include <unistd.h>
#include <string.h>
@@ -64,7 +65,7 @@ dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
goffset offset)
{
if (input_stream_is_seekable(is))
- return input_stream_seek(is, offset, SEEK_SET, nullptr);
+ return input_stream_seek(is, offset, SEEK_SET, IgnoreError());
if (input_stream_get_offset(is) > offset)
return false;
@@ -97,7 +98,7 @@ dsdlib_skip(struct decoder *decoder, struct input_stream *is,
return true;
if (input_stream_is_seekable(is))
- return input_stream_seek(is, delta, SEEK_CUR, nullptr);
+ return input_stream_seek(is, delta, SEEK_CUR, IgnoreError());
char buffer[8192];
while (delta > 0) {
diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx
index b6d7f65cc..7c461f9c3 100644
--- a/src/decoder/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/DsdiffDecoderPlugin.cxx
@@ -31,6 +31,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "util/bit_reverse.h"
+#include "util/Error.hxx"
#include "TagHandler.hxx"
#include "DsdLib.hxx"
#include "TagHandler.hxx"
@@ -432,13 +433,12 @@ dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!dsdiff_read_metadata(decoder, is, &metadata, &chunk_header))
return;
- GError *error = nullptr;
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD,
- metadata.channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ metadata.channels, error)) {
+ g_warning("%s", error.GetMessage());
return;
}
@@ -490,7 +490,7 @@ dsdiff_scan_stream(struct input_stream *is,
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD,
- metadata.channels, nullptr))
+ metadata.channels, IgnoreError()))
/* refuse to parse files which we cannot play anyway */
return false;
diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx
index e487879cb..26ba0e2d6 100644
--- a/src/decoder/DsfDecoderPlugin.cxx
+++ b/src/decoder/DsfDecoderPlugin.cxx
@@ -32,6 +32,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "util/bit_reverse.h"
+#include "util/Error.hxx"
#include "DsdLib.hxx"
#include "TagHandler.hxx"
@@ -284,13 +285,12 @@ dsf_stream_decode(struct decoder *decoder, struct input_stream *is)
if (!dsf_read_metadata(decoder, is, &metadata))
return;
- GError *error = NULL;
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD,
- metadata.channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ metadata.channels, error)) {
+ g_warning("%s", error.GetMessage());
return;
}
/* Calculate song time from DSD chunk size and sample frequency */
@@ -320,7 +320,7 @@ dsf_scan_stream(struct input_stream *is,
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, metadata.sample_rate / 8,
SampleFormat::DSD,
- metadata.channels, NULL))
+ metadata.channels, IgnoreError()))
/* refuse to parse files which we cannot play anyway */
return false;
diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx
index 547ba24e0..1387dc45c 100644
--- a/src/decoder/FaadDecoderPlugin.cxx
+++ b/src/decoder/FaadDecoderPlugin.cxx
@@ -23,6 +23,8 @@
#include "DecoderBuffer.hxx"
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <neaacdec.h>
@@ -42,14 +44,7 @@ static const unsigned adts_sample_rates[] =
16000, 12000, 11025, 8000, 7350, 0, 0, 0
};
-/**
- * The GLib quark used for errors reported by this plugin.
- */
-static inline GQuark
-faad_decoder_quark(void)
-{
- return g_quark_from_static_string("faad");
-}
+static constexpr Domain faad_decoder_domain("faad_decoder");
/**
* Check whether the buffer head is an AAC frame, and return the frame
@@ -211,7 +206,7 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
/* obtain the duration from the ADTS header */
float song_length = adts_song_duration(buffer);
- input_stream_lock_seek(is, tagsize, SEEK_SET, nullptr);
+ input_stream_lock_seek(is, tagsize, SEEK_SET, IgnoreError());
data = (const uint8_t *)decoder_buffer_read(buffer, &length);
if (data != nullptr)
@@ -248,7 +243,7 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
*/
static bool
faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
- AudioFormat &audio_format, GError **error_r)
+ AudioFormat &audio_format, Error &error)
{
int32_t nbytes;
uint32_t sample_rate;
@@ -266,8 +261,7 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
const unsigned char *data = (const unsigned char *)
decoder_buffer_read(buffer, &length);
if (data == nullptr) {
- g_set_error(error_r, faad_decoder_quark(), 0,
- "Empty file");
+ error.Set(faad_decoder_domain, "Empty file");
return false;
}
@@ -277,15 +271,14 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
length,
sample_rate_p, &channels);
if (nbytes < 0) {
- g_set_error(error_r, faad_decoder_quark(), 0,
- "Not an AAC stream");
+ error.Set(faad_decoder_domain, "Not an AAC stream");
return false;
}
decoder_buffer_consume(buffer, nbytes);
return audio_format_init_checked(audio_format, sample_rate,
- SampleFormat::S16, channels, error_r);
+ SampleFormat::S16, channels, error);
}
/**
@@ -336,7 +329,8 @@ faad_get_file_time_float(struct input_stream *is)
decoder_buffer_fill(buffer);
- ret = faad_decoder_init(decoder, buffer, audio_format, nullptr);
+ ret = faad_decoder_init(decoder, buffer, audio_format,
+ IgnoreError());
if (ret)
length = 0;
@@ -368,7 +362,6 @@ faad_get_file_time(struct input_stream *is)
static void
faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
{
- GError *error = nullptr;
float total_time = 0;
AudioFormat audio_format;
bool ret;
@@ -400,10 +393,10 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
/* initialize it */
- ret = faad_decoder_init(decoder, buffer, audio_format, &error);
+ Error error;
+ ret = faad_decoder_init(decoder, buffer, audio_format, error);
if (!ret) {
- g_warning("%s", error->message);
- g_error_free(error);
+ g_warning("%s", error.GetMessage());
NeAACDecClose(decoder);
return;
}
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx
index cf162b918..305662e6c 100644
--- a/src/decoder/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/FfmpegDecoderPlugin.cxx
@@ -27,6 +27,7 @@
#include "TagHandler.hxx"
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -124,7 +125,8 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
if (whence == AVSEEK_SIZE)
return stream->input->size;
- if (!input_stream_lock_seek(stream->input, pos, whence, NULL))
+ Error error;
+ if (!input_stream_lock_seek(stream->input, pos, whence, error))
return -1;
return stream->input->offset;
@@ -343,10 +345,12 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
PADDING = 16,
};
+ Error error;
+
unsigned char *buffer = (unsigned char *)g_malloc(BUFFER_SIZE);
size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
if (nbytes <= PADDING ||
- !input_stream_lock_seek(is, 0, SEEK_SET, NULL)) {
+ !input_stream_lock_seek(is, 0, SEEK_SET, error)) {
g_free(buffer);
return NULL;
}
@@ -427,14 +431,13 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
if (sample_format == SampleFormat::UNDEFINED)
return;
- GError *error = NULL;
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format,
codec_context->sample_rate,
sample_format,
- codec_context->channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ codec_context->channels, error)) {
+ g_warning("%s", error.GetMessage());
avformat_close_input(&format_context);
return;
}
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index 5bcc20b97..62409d3cc 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -26,6 +26,7 @@
#include "FlacMetadata.hxx"
#include "FlacPcm.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -68,13 +69,12 @@ flac_got_stream_info(struct flac_data *data,
if (data->initialized || data->unsupported)
return;
- GError *error = nullptr;
+ Error error;
if (!audio_format_init_checked(data->audio_format,
stream_info->sample_rate,
flac_sample_format(stream_info->bits_per_sample),
- stream_info->channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ stream_info->channels, error)) {
+ g_warning("%s", error.GetMessage());
data->unsupported = true;
return;
}
@@ -131,13 +131,12 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
if (data->unsupported)
return false;
- GError *error = nullptr;
+ Error error;
if (!audio_format_init_checked(data->audio_format,
header->sample_rate,
flac_sample_format(header->bits_per_sample),
- header->channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ header->channels, error)) {
+ g_warning("%s", error.GetMessage());
data->unsupported = true;
return false;
}
diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx
index 5b02c1f9e..1693e109b 100644
--- a/src/decoder/FlacDecoderPlugin.cxx
+++ b/src/decoder/FlacDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "FlacCommon.hxx"
#include "FlacMetadata.hxx"
#include "OggCodec.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -330,7 +331,7 @@ oggflac_decode(struct decoder *decoder, struct input_stream *input_stream)
/* rewind the stream, because ogg_codec_detect() has
moved it */
- input_stream_lock_seek(input_stream, 0, SEEK_SET, nullptr);
+ input_stream_lock_seek(input_stream, 0, SEEK_SET, IgnoreError());
flac_decode_internal(decoder, input_stream, true);
}
diff --git a/src/decoder/FlacIOHandle.cxx b/src/decoder/FlacIOHandle.cxx
index 16a07a9d1..cf877414b 100644
--- a/src/decoder/FlacIOHandle.cxx
+++ b/src/decoder/FlacIOHandle.cxx
@@ -19,7 +19,7 @@
#include "config.h"
#include "FlacIOHandle.hxx"
-#include "io_error.h"
+#include "util/Error.hxx"
#include "gcc.h"
#include <errno.h>
@@ -35,21 +35,20 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
/* libFLAC is very picky about short reads, and expects the IO
callback to fill the whole buffer (undocumented!) */
- GError *error = nullptr;
+ Error error;
while (p < end) {
- size_t nbytes = input_stream_lock_read(is, p, end - p, &error);
+ size_t nbytes = input_stream_lock_read(is, p, end - p, error);
if (nbytes == 0) {
- if (error == nullptr)
+ if (!error.IsDefined())
/* end of file */
break;
- if (error->domain == errno_quark())
- errno = error->code;
+ if (error.IsDomain(errno_domain))
+ errno = error.GetCode();
else
/* just some random non-zero
errno value */
errno = EINVAL;
- g_error_free(error);
return 0;
}
@@ -67,7 +66,8 @@ FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
{
input_stream *is = (input_stream *)handle;
- return input_stream_lock_seek(is, offset, whence, nullptr) ? 0 : -1;
+ Error error;
+ return input_stream_lock_seek(is, offset, whence, error) ? 0 : -1;
}
static FLAC__int64
diff --git a/src/decoder/FlacInput.cxx b/src/decoder/FlacInput.cxx
index 0bb5ec7d7..46f213787 100644
--- a/src/decoder/FlacInput.cxx
+++ b/src/decoder/FlacInput.cxx
@@ -20,8 +20,9 @@
#include "config.h"
#include "FlacInput.hxx"
#include "DecoderAPI.hxx"
-#include "gcc.h"
#include "InputStream.hxx"
+#include "util/Error.hxx"
+#include "gcc.h"
FLAC__StreamDecoderReadStatus
FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
@@ -47,9 +48,10 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
if (!input_stream->seekable)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
+ ::Error error;
if (!input_stream_lock_seek(input_stream,
absolute_byte_offset, SEEK_SET,
- nullptr))
+ error))
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
diff --git a/src/decoder/FluidsynthDecoderPlugin.cxx b/src/decoder/FluidsynthDecoderPlugin.cxx
index 9e9c9b2ce..66345e293 100644
--- a/src/decoder/FluidsynthDecoderPlugin.cxx
+++ b/src/decoder/FluidsynthDecoderPlugin.cxx
@@ -21,6 +21,7 @@
#include "FluidsynthDecoderPlugin.hxx"
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/Error.hxx"
#include "conf.h"
#include <glib.h>
@@ -73,12 +74,11 @@ fluidsynth_mpd_log_function(int level, char *message, gcc_unused void *data)
static bool
fluidsynth_init(const config_param &param)
{
- GError *error = nullptr;
+ Error error;
sample_rate = param.GetBlockValue("sample_rate", 48000u);
- if (!audio_check_sample_rate(sample_rate, &error)) {
- g_warning("%s\n", error->message);
- g_error_free(error);
+ if (!audio_check_sample_rate(sample_rate, error)) {
+ g_warning("%s", error.GetMessage());
return false;
}
diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx
index d8edbe4cb..006161c78 100644
--- a/src/decoder/GmeDecoderPlugin.cxx
+++ b/src/decoder/GmeDecoderPlugin.cxx
@@ -23,6 +23,7 @@
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
#include "util/UriUtil.hxx"
+#include "util/Error.hxx"
#include <glib.h>
#include <assert.h>
@@ -152,13 +153,12 @@ gme_file_decode(struct decoder *decoder, const char *path_fs)
/* initialize the MPD decoder */
- GError *error = nullptr;
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, GME_SAMPLE_RATE,
SampleFormat::S16, GME_CHANNELS,
- &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ error)) {
+ g_warning("%s", error.GetMessage());
gme_free_info(ti);
gme_delete(emu);
return;
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index 29abfafbd..f77563fb2 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -25,6 +25,7 @@
#include "TagRva2.hxx"
#include "TagHandler.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/Error.hxx"
#include <assert.h>
#include <unistd.h>
@@ -203,8 +204,9 @@ MadDecoder::MadDecoder(struct decoder *_decoder,
inline bool
MadDecoder::Seek(long offset)
{
+ Error error;
if (!input_stream_lock_seek(input_stream, offset, SEEK_SET,
- nullptr))
+ error))
return false;
mad_stream_buffer(&stream, input_buffer, 0);
@@ -1124,16 +1126,14 @@ mp3_decode(struct decoder *decoder, struct input_stream *input_stream)
return;
}
+ Error error;
AudioFormat audio_format;
- GError *error = nullptr;
if (!audio_format_init_checked(audio_format,
data.frame.header.samplerate,
SampleFormat::S24_P32,
MAD_NCHANNELS(&data.frame.header),
- &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
-
+ error)) {
+ g_warning("%s", error.GetMessage());
delete tag;
return;
}
diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx
index cfb9c034b..35d5ce0df 100644
--- a/src/decoder/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/MpcdecDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
+#include "util/Error.hxx"
#include <mpc/mpcdec.h>
@@ -53,7 +54,8 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset)
struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data;
- return input_stream_lock_seek(data->is, offset, SEEK_SET, nullptr);
+ return input_stream_lock_seek(data->is, offset, SEEK_SET,
+ IgnoreError());
}
static mpc_int32_t
@@ -153,13 +155,12 @@ mpcdec_decode(struct decoder *mpd_decoder, struct input_stream *is)
mpc_streaminfo info;
mpc_demux_get_info(demux, &info);
- GError *error = nullptr;
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, info.sample_freq,
SampleFormat::S24_P32,
- info.channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ info.channels, error)) {
+ g_warning("%s", error.GetMessage());
mpc_demux_exit(demux);
return;
}
diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx
index 05fe4717c..c30455121 100644
--- a/src/decoder/Mpg123DecoderPlugin.cxx
+++ b/src/decoder/Mpg123DecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -58,7 +59,6 @@ static bool
mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
AudioFormat &audio_format)
{
- GError *gerror = nullptr;
char *path_dup;
int error;
int channels, encoding;
@@ -90,10 +90,10 @@ mpd_mpg123_open(mpg123_handle *handle, const char *path_fs,
return false;
}
+ Error error2;
if (!audio_format_init_checked(audio_format, rate, SampleFormat::S16,
- channels, &gerror)) {
- g_warning("%s", gerror->message);
- g_error_free(gerror);
+ channels, error2)) {
+ g_warning("%s", error2.GetMessage());
return false;
}
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx
index b6835f760..18da812ab 100644
--- a/src/decoder/OpusDecoderPlugin.cxx
+++ b/src/decoder/OpusDecoderPlugin.cxx
@@ -29,6 +29,7 @@
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
#include "InputStream.hxx"
+#include "util/Error.hxx"
#include <opus.h>
#include <ogg/ogg.h>
@@ -271,7 +272,7 @@ mpd_opus_stream_decode(struct decoder *decoder,
/* rewind the stream, because ogg_codec_detect() has
moved it */
- input_stream_lock_seek(input_stream, 0, SEEK_SET, nullptr);
+ input_stream_lock_seek(input_stream, 0, SEEK_SET, IgnoreError());
MPDOpusDecoder d(decoder, input_stream);
OggSyncState oy(*input_stream, decoder);
@@ -302,7 +303,8 @@ SeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet,
oy.Reset();
- return input_stream_lock_seek(is, -65536, SEEK_END, nullptr) &&
+ Error error;
+ return input_stream_lock_seek(is, -65536, SEEK_END, error) &&
oy.ExpectPageSeekIn(os) &&
OggFindEOS(oy, os, packet);
}
diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx
index 8976f511f..f47b54d03 100644
--- a/src/decoder/PcmDecoderPlugin.cxx
+++ b/src/decoder/PcmDecoderPlugin.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "decoder/PcmDecoderPlugin.hxx"
#include "DecoderAPI.hxx"
+#include "util/Error.hxx"
extern "C" {
#include "util/byte_reverse.h"
@@ -46,7 +47,6 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
const bool reverse_endian = mime != nullptr &&
strcmp(mime, "audio/x-mpd-cdda-pcm-reverse") == 0;
- GError *error = nullptr;
enum decoder_command cmd;
const double time_to_size = audio_format.GetTimeToSize();
@@ -81,12 +81,13 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
if (cmd == DECODE_COMMAND_SEEK) {
goffset offset = (goffset)(time_to_size *
decoder_seek_where(decoder));
+
+ Error error;
if (input_stream_lock_seek(is, offset, SEEK_SET,
- &error)) {
+ error)) {
decoder_command_finished(decoder);
} else {
- g_warning("seeking failed: %s", error->message);
- g_error_free(error);
+ g_warning("seeking failed: %s", error.GetMessage());
decoder_seek_error(decoder);
}
diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx
index 29911a04e..0b83c142a 100644
--- a/src/decoder/SndfileDecoderPlugin.cxx
+++ b/src/decoder/SndfileDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
+#include "util/Error.hxx"
#include <sndfile.h>
@@ -40,10 +41,8 @@ static sf_count_t
sndfile_vio_seek(sf_count_t offset, int whence, void *user_data)
{
struct input_stream *is = (struct input_stream *)user_data;
- bool success;
- success = input_stream_lock_seek(is, offset, whence, nullptr);
- if (!success)
+ if (!input_stream_lock_seek(is, offset, whence, IgnoreError()))
return -1;
return input_stream_get_offset(is);
@@ -53,13 +52,11 @@ static sf_count_t
sndfile_vio_read(void *ptr, sf_count_t count, void *user_data)
{
struct input_stream *is = (struct input_stream *)user_data;
- GError *error = nullptr;
- size_t nbytes;
- nbytes = input_stream_lock_read(is, ptr, count, &error);
- if (nbytes == 0 && error != nullptr) {
- g_warning("%s", error->message);
- g_error_free(error);
+ Error error;
+ size_t nbytes = input_stream_lock_read(is, ptr, count, error);
+ if (nbytes == 0 && error.IsDefined()) {
+ g_warning("%s", error.GetMessage());
return -1;
}
@@ -116,7 +113,6 @@ time_to_frame(float t, const AudioFormat *audio_format)
static void
sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
{
- GError *error = nullptr;
SNDFILE *sf;
SF_INFO info;
size_t frame_size;
@@ -135,12 +131,12 @@ sndfile_stream_decode(struct decoder *decoder, struct input_stream *is)
/* for now, always read 32 bit samples. Later, we could lower
MPD's CPU usage by reading 16 bit samples with
sf_readf_short() on low-quality source files. */
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, info.samplerate,
SampleFormat::S32,
- info.channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ info.channels, error)) {
+ g_warning("%s", error.GetMessage());
return;
}
diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx
index b9181ef75..3626fe162 100644
--- a/src/decoder/VorbisDecoderPlugin.cxx
+++ b/src/decoder/VorbisDecoderPlugin.cxx
@@ -23,6 +23,7 @@
#include "DecoderAPI.hxx"
#include "InputStream.hxx"
#include "OggCodec.hxx"
+#include "util/Error.hxx"
#include "util/UriUtil.hxx"
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
@@ -80,9 +81,10 @@ static int ogg_seek_cb(void *data, ogg_int64_t offset, int whence)
{
struct vorbis_input_stream *vis = (struct vorbis_input_stream *)data;
+ Error error;
return vis->seekable &&
(!vis->decoder || decoder_get_command(vis->decoder) != DECODE_COMMAND_STOP) &&
- input_stream_lock_seek(vis->input_stream, offset, whence, NULL)
+ input_stream_lock_seek(vis->input_stream, offset, whence, error)
? 0 : -1;
}
@@ -182,14 +184,12 @@ static void
vorbis_stream_decode(struct decoder *decoder,
struct input_stream *input_stream)
{
- GError *error = NULL;
-
if (ogg_codec_detect(decoder, input_stream) != OGG_CODEC_VORBIS)
return;
/* rewind the stream, because ogg_codec_detect() has
moved it */
- input_stream_lock_seek(input_stream, 0, SEEK_SET, NULL);
+ input_stream_lock_seek(input_stream, 0, SEEK_SET, IgnoreError());
struct vorbis_input_stream vis;
OggVorbis_File vf;
@@ -202,6 +202,7 @@ vorbis_stream_decode(struct decoder *decoder,
return;
}
+ Error error;
AudioFormat audio_format;
if (!audio_format_init_checked(audio_format, vi->rate,
#ifdef HAVE_TREMOR
@@ -209,9 +210,8 @@ vorbis_stream_decode(struct decoder *decoder,
#else
SampleFormat::FLOAT,
#endif
- vi->channels, &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ vi->channels, error)) {
+ g_warning("%s", error.GetMessage());
return;
}
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index 6b6c7f2ea..528ecdc3c 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -24,6 +24,7 @@
#include "CheckAudioFormat.hxx"
#include "TagHandler.hxx"
#include "ApeTag.hxx"
+#include "util/Error.hxx"
#include <wavpack/wavpack.h>
#include <glib.h>
@@ -137,7 +138,6 @@ wavpack_bits_to_sample_format(bool is_float, int bytes_per_sample)
static void
wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
{
- GError *error = NULL;
bool is_float;
SampleFormat sample_format;
AudioFormat audio_format;
@@ -150,12 +150,12 @@ wavpack_decode(struct decoder *decoder, WavpackContext *wpc, bool can_seek)
wavpack_bits_to_sample_format(is_float,
WavpackGetBytesPerSample(wpc));
+ Error error;
if (!audio_format_init_checked(audio_format,
WavpackGetSampleRate(wpc),
sample_format,
- WavpackGetNumChannels(wpc), &error)) {
- g_warning("%s", error->message);
- g_error_free(error);
+ WavpackGetNumChannels(wpc), error)) {
+ g_warning("%s", error.GetMessage());
return;
}
@@ -401,14 +401,16 @@ wavpack_input_get_pos(void *id)
static int
wavpack_input_set_pos_abs(void *id, uint32_t pos)
{
- return input_stream_lock_seek(wpin(id)->is, pos, SEEK_SET, NULL)
+ Error error;
+ return input_stream_lock_seek(wpin(id)->is, pos, SEEK_SET, error)
? 0 : -1;
}
static int
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
{
- return input_stream_lock_seek(wpin(id)->is, delta, mode, NULL)
+ Error error;
+ return input_stream_lock_seek(wpin(id)->is, delta, mode, error)
? 0 : -1;
}
@@ -476,7 +478,9 @@ wavpack_open_wvc(struct decoder *decoder, const char *uri,
return nullptr;
wvc_url = g_strconcat(uri, "c", NULL);
- is_wvc = input_stream_open(wvc_url, mutex, cond, NULL);
+
+ Error error;
+ is_wvc = input_stream_open(wvc_url, mutex, cond, error);
g_free(wvc_url);
if (is_wvc == NULL)
diff --git a/src/decoder/WildmidiDecoderPlugin.cxx b/src/decoder/WildmidiDecoderPlugin.cxx
index c7bd3985e..738073d52 100644
--- a/src/decoder/WildmidiDecoderPlugin.cxx
+++ b/src/decoder/WildmidiDecoderPlugin.cxx
@@ -21,6 +21,7 @@
#include "WildmidiDecoderPlugin.hxx"
#include "DecoderAPI.hxx"
#include "TagHandler.hxx"
+#include "util/Error.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "system/FatalError.hxx"
@@ -39,10 +40,10 @@ static constexpr unsigned WILDMIDI_SAMPLE_RATE = 48000;
static bool
wildmidi_init(const config_param &param)
{
- GError *error = nullptr;
+ Error error;
const Path path = param.GetBlockPath("config_file",
"/etc/timidity/timidity.cfg",
- &error);
+ error);
if (path.IsNull())
FatalError(error);