diff options
author | Max Kellermann <max@duempel.org> | 2013-08-10 18:02:44 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-09-04 18:14:22 +0200 |
commit | 29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch) | |
tree | 79766830b55ebca38ddbce84d8d548227eedb69e /src/pcm | |
parent | c9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff) | |
download | mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip |
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/PcmConvert.cxx | 104 | ||||
-rw-r--r-- | src/pcm/PcmConvert.hxx | 19 | ||||
-rw-r--r-- | src/pcm/PcmResample.cxx | 12 | ||||
-rw-r--r-- | src/pcm/PcmResample.hxx | 13 | ||||
-rw-r--r-- | src/pcm/PcmResampleInternal.hxx | 8 | ||||
-rw-r--r-- | src/pcm/PcmResampleLibsamplerate.cxx | 49 |
6 files changed, 102 insertions, 103 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx index 7e71da283..38672810e 100644 --- a/src/pcm/PcmConvert.cxx +++ b/src/pcm/PcmConvert.cxx @@ -23,6 +23,8 @@ #include "PcmFormat.hxx" #include "pcm_pack.h" #include "AudioFormat.hxx" +#include "util/Error.hxx" +#include "util/Domain.hxx" #include <glib.h> @@ -32,6 +34,8 @@ #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "pcm" +const Domain pcm_convert_domain("pcm_convert"); + PcmConvert::PcmConvert() { } @@ -51,7 +55,7 @@ inline const int16_t * PcmConvert::Convert16(const AudioFormat src_format, const void *src_buffer, size_t src_size, const AudioFormat dest_format, size_t *dest_size_r, - GError **error_r) + Error &error) { const int16_t *buf; size_t len; @@ -63,9 +67,9 @@ PcmConvert::Convert16(const AudioFormat src_format, src_buffer, src_size, &len); if (buf == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %s to 16 bit is not implemented", - sample_format_to_string(src_format.format)); + error.Format(pcm_convert_domain, + "Conversion from %s to 16 bit is not implemented", + sample_format_to_string(src_format.format)); return NULL; } @@ -75,11 +79,11 @@ PcmConvert::Convert16(const AudioFormat src_format, src_format.channels, buf, len, &len); if (buf == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %u to %u channels " - "is not implemented", - src_format.channels, - dest_format.channels); + error.Format(pcm_convert_domain, + "Conversion from %u to %u channels " + "is not implemented", + src_format.channels, + dest_format.channels); return NULL; } } @@ -88,7 +92,7 @@ PcmConvert::Convert16(const AudioFormat src_format, buf = resampler.Resample16(dest_format.channels, src_format.sample_rate, buf, len, dest_format.sample_rate, &len, - error_r); + error); if (buf == NULL) return NULL; } @@ -101,7 +105,7 @@ inline const int32_t * PcmConvert::Convert24(const AudioFormat src_format, const void *src_buffer, size_t src_size, const AudioFormat dest_format, size_t *dest_size_r, - GError **error_r) + Error &error) { const int32_t *buf; size_t len; @@ -112,9 +116,9 @@ PcmConvert::Convert24(const AudioFormat src_format, src_format.format, src_buffer, src_size, &len); if (buf == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %s to 24 bit is not implemented", - sample_format_to_string(src_format.format)); + error.Format(pcm_convert_domain, + "Conversion from %s to 24 bit is not implemented", + sample_format_to_string(src_format.format)); return NULL; } @@ -124,11 +128,11 @@ PcmConvert::Convert24(const AudioFormat src_format, src_format.channels, buf, len, &len); if (buf == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %u to %u channels " - "is not implemented", - src_format.channels, - dest_format.channels); + error.Format(pcm_convert_domain, + "Conversion from %u to %u channels " + "is not implemented", + src_format.channels, + dest_format.channels); return NULL; } } @@ -137,7 +141,7 @@ PcmConvert::Convert24(const AudioFormat src_format, buf = resampler.Resample24(dest_format.channels, src_format.sample_rate, buf, len, dest_format.sample_rate, &len, - error_r); + error); if (buf == NULL) return NULL; } @@ -150,7 +154,7 @@ inline const int32_t * PcmConvert::Convert32(const AudioFormat src_format, const void *src_buffer, size_t src_size, const AudioFormat dest_format, size_t *dest_size_r, - GError **error_r) + Error &error) { const int32_t *buf; size_t len; @@ -161,9 +165,9 @@ PcmConvert::Convert32(const AudioFormat src_format, src_format.format, src_buffer, src_size, &len); if (buf == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %s to 32 bit is not implemented", - sample_format_to_string(src_format.format)); + error.Format(pcm_convert_domain, + "Conversion from %s to 32 bit is not implemented", + sample_format_to_string(src_format.format)); return NULL; } @@ -173,11 +177,11 @@ PcmConvert::Convert32(const AudioFormat src_format, src_format.channels, buf, len, &len); if (buf == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %u to %u channels " - "is not implemented", - src_format.channels, - dest_format.channels); + error.Format(pcm_convert_domain, + "Conversion from %u to %u channels " + "is not implemented", + src_format.channels, + dest_format.channels); return NULL; } } @@ -186,7 +190,7 @@ PcmConvert::Convert32(const AudioFormat src_format, buf = resampler.Resample32(dest_format.channels, src_format.sample_rate, buf, len, dest_format.sample_rate, &len, - error_r); + error); if (buf == NULL) return buf; } @@ -199,7 +203,7 @@ inline const float * PcmConvert::ConvertFloat(const AudioFormat src_format, const void *src_buffer, size_t src_size, const AudioFormat dest_format, size_t *dest_size_r, - GError **error_r) + Error &error) { const float *buffer = (const float *)src_buffer; size_t size = src_size; @@ -212,9 +216,9 @@ PcmConvert::ConvertFloat(const AudioFormat src_format, src_format.format, buffer, size, &size); if (buffer == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %s to float is not implemented", - sample_format_to_string(src_format.format)); + error.Format(pcm_convert_domain, + "Conversion from %s to float is not implemented", + sample_format_to_string(src_format.format)); return NULL; } @@ -226,11 +230,11 @@ PcmConvert::ConvertFloat(const AudioFormat src_format, src_format.channels, buffer, size, &size); if (buffer == NULL) { - g_set_error(error_r, pcm_convert_quark(), 0, - "Conversion from %u to %u channels " - "is not implemented", - src_format.channels, - dest_format.channels); + error.Format(pcm_convert_domain, + "Conversion from %u to %u channels " + "is not implemented", + src_format.channels, + dest_format.channels); return NULL; } } @@ -243,7 +247,7 @@ PcmConvert::ConvertFloat(const AudioFormat src_format, src_format.sample_rate, buffer, size, dest_format.sample_rate, - &size, error_r); + &size, error); if (buffer == NULL) return NULL; } @@ -257,7 +261,7 @@ PcmConvert::Convert(AudioFormat src_format, const void *src, size_t src_size, const AudioFormat dest_format, size_t *dest_size_r, - GError **error_r) + Error &error) { AudioFormat float_format; if (src_format.format == SampleFormat::DSD) { @@ -266,8 +270,8 @@ PcmConvert::Convert(AudioFormat src_format, false, (const uint8_t *)src, src_size, &f_size); if (f == NULL) { - g_set_error_literal(error_r, pcm_convert_quark(), 0, - "DSD to PCM conversion failed"); + error.Set(pcm_convert_domain, + "DSD to PCM conversion failed"); return NULL; } @@ -283,27 +287,27 @@ PcmConvert::Convert(AudioFormat src_format, case SampleFormat::S16: return Convert16(src_format, src, src_size, dest_format, dest_size_r, - error_r); + error); case SampleFormat::S24_P32: return Convert24(src_format, src, src_size, dest_format, dest_size_r, - error_r); + error); case SampleFormat::S32: return Convert32(src_format, src, src_size, dest_format, dest_size_r, - error_r); + error); case SampleFormat::FLOAT: return ConvertFloat(src_format, src, src_size, dest_format, dest_size_r, - error_r); + error); default: - g_set_error(error_r, pcm_convert_quark(), 0, - "PCM conversion to %s is not implemented", - sample_format_to_string(dest_format.format)); + error.Format(pcm_convert_domain, + "PCM conversion to %s is not implemented", + sample_format_to_string(dest_format.format)); return NULL; } } diff --git a/src/pcm/PcmConvert.hxx b/src/pcm/PcmConvert.hxx index 42b59e407..40f785179 100644 --- a/src/pcm/PcmConvert.hxx +++ b/src/pcm/PcmConvert.hxx @@ -25,9 +25,10 @@ #include "PcmResample.hxx" #include "PcmBuffer.hxx" -#include <glib.h> +#include <stddef.h> struct AudioFormat; +class Error; /** * This object is statically allocated (within another struct), and @@ -75,38 +76,34 @@ public: const void *src, size_t src_size, AudioFormat dest_format, size_t *dest_size_r, - GError **error_r); + Error &error); private: const int16_t *Convert16(AudioFormat src_format, const void *src_buffer, size_t src_size, AudioFormat dest_format, size_t *dest_size_r, - GError **error_r); + Error &error); const int32_t *Convert24(AudioFormat src_format, const void *src_buffer, size_t src_size, AudioFormat dest_format, size_t *dest_size_r, - GError **error_r); + Error &error); const int32_t *Convert32(AudioFormat src_format, const void *src_buffer, size_t src_size, AudioFormat dest_format, size_t *dest_size_r, - GError **error_r); + Error &error); const float *ConvertFloat(AudioFormat src_format, const void *src_buffer, size_t src_size, AudioFormat dest_format, size_t *dest_size_r, - GError **error_r); + Error &error); }; -static inline GQuark -pcm_convert_quark(void) -{ - return g_quark_from_static_string("pcm_convert"); -} +extern const class Domain pcm_convert_domain; #endif diff --git a/src/pcm/PcmResample.cxx b/src/pcm/PcmResample.cxx index 423e3d442..9ade8cf5b 100644 --- a/src/pcm/PcmResample.cxx +++ b/src/pcm/PcmResample.cxx @@ -39,7 +39,7 @@ pcm_resample_lsr_enabled(void) #endif bool -pcm_resample_global_init(GError **error_r) +pcm_resample_global_init(Error &error) { #ifdef HAVE_LIBSAMPLERATE const char *converter = @@ -47,11 +47,11 @@ pcm_resample_global_init(GError **error_r) lsr_enabled = strcmp(converter, "internal") != 0; if (lsr_enabled) - return pcm_resample_lsr_global_init(converter, error_r); + return pcm_resample_lsr_global_init(converter, error); else return true; #else - (void)error_r; + (void)error; return true; #endif } @@ -84,7 +84,7 @@ const float * PcmResampler::ResampleFloat(unsigned channels, unsigned src_rate, const float *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error_r) { #ifdef HAVE_LIBSAMPLERATE if (pcm_resample_lsr_enabled()) @@ -110,7 +110,7 @@ const int16_t * PcmResampler::Resample16(unsigned channels, unsigned src_rate, const int16_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error_r) { #ifdef HAVE_LIBSAMPLERATE if (pcm_resample_lsr_enabled()) @@ -131,7 +131,7 @@ const int32_t * PcmResampler::Resample32(unsigned channels, unsigned src_rate, const int32_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error_r) { #ifdef HAVE_LIBSAMPLERATE if (pcm_resample_lsr_enabled()) diff --git a/src/pcm/PcmResample.hxx b/src/pcm/PcmResample.hxx index db0bbff8d..8a740744a 100644 --- a/src/pcm/PcmResample.hxx +++ b/src/pcm/PcmResample.hxx @@ -22,7 +22,6 @@ #include "check.h" #include "PcmBuffer.hxx" -#include "gerror.h" #include <stdint.h> #include <stddef.h> @@ -31,6 +30,8 @@ #include <samplerate.h> #endif +class Error; + /** * This object is statically allocated (within another struct), and * holds buffer allocations and the state for the resampler. @@ -75,7 +76,7 @@ struct PcmResampler { const float *ResampleFloat(unsigned channels, unsigned src_rate, const float *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r); + Error &error_r); /** * Resamples 16 bit PCM data. @@ -91,7 +92,7 @@ struct PcmResampler { const int16_t *Resample16(unsigned channels, unsigned src_rate, const int16_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r); + Error &error_r); /** * Resamples 32 bit PCM data. @@ -107,7 +108,7 @@ struct PcmResampler { const int32_t *Resample32(unsigned channels, unsigned src_rate, const int32_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r); + Error &error_r); /** * Resamples 24 bit PCM data. @@ -123,7 +124,7 @@ struct PcmResampler { const int32_t *Resample24(unsigned channels, unsigned src_rate, const int32_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error_r) { /* reuse the 32 bit code - the resampler code doesn't care if the upper 8 bits are actually used */ @@ -133,6 +134,6 @@ struct PcmResampler { }; bool -pcm_resample_global_init(GError **error_r); +pcm_resample_global_init(Error &error); #endif diff --git a/src/pcm/PcmResampleInternal.hxx b/src/pcm/PcmResampleInternal.hxx index 5275c090a..59bb2f5df 100644 --- a/src/pcm/PcmResampleInternal.hxx +++ b/src/pcm/PcmResampleInternal.hxx @@ -33,7 +33,7 @@ #ifdef HAVE_LIBSAMPLERATE bool -pcm_resample_lsr_global_init(const char *converter, GError **error_r); +pcm_resample_lsr_global_init(const char *converter, Error &error); void pcm_resample_lsr_init(PcmResampler *state); @@ -50,7 +50,7 @@ pcm_resample_lsr_float(PcmResampler *state, unsigned src_rate, const float *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r); + Error &error); const int16_t * pcm_resample_lsr_16(PcmResampler *state, @@ -58,7 +58,7 @@ pcm_resample_lsr_16(PcmResampler *state, unsigned src_rate, const int16_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r); + Error &error); const int32_t * pcm_resample_lsr_32(PcmResampler *state, @@ -67,7 +67,7 @@ pcm_resample_lsr_32(PcmResampler *state, const int32_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r); + Error &error); #endif diff --git a/src/pcm/PcmResampleLibsamplerate.cxx b/src/pcm/PcmResampleLibsamplerate.cxx index d8dde62e9..6710c2070 100644 --- a/src/pcm/PcmResampleLibsamplerate.cxx +++ b/src/pcm/PcmResampleLibsamplerate.cxx @@ -20,6 +20,8 @@ #include "config.h" #include "PcmResampleInternal.hxx" #include "conf.h" +#include "util/Error.hxx" +#include "util/Domain.hxx" #include <glib.h> @@ -32,11 +34,7 @@ static int lsr_converter = SRC_SINC_FASTEST; -static inline GQuark -libsamplerate_quark(void) -{ - return g_quark_from_static_string("libsamplerate"); -} +static constexpr Domain libsamplerate_domain("libsamplerate"); static bool lsr_parse_converter(const char *s) @@ -69,11 +67,11 @@ lsr_parse_converter(const char *s) } bool -pcm_resample_lsr_global_init(const char *converter, GError **error_r) +pcm_resample_lsr_global_init(const char *converter, Error &error) { if (!lsr_parse_converter(converter)) { - g_set_error(error_r, libsamplerate_quark(), 0, - "unknown samplerate converter '%s'", converter); + error.Format(libsamplerate_domain, + "unknown samplerate converter '%s'", converter); return false; } @@ -109,7 +107,7 @@ pcm_resample_lsr_reset(PcmResampler *state) static bool pcm_resample_set(PcmResampler *state, unsigned channels, unsigned src_rate, unsigned dest_rate, - GError **error_r) + Error &error_r) { /* (re)set the state/ratio if the in or out format changed */ if (channels == state->prev.channels && @@ -128,9 +126,9 @@ pcm_resample_set(PcmResampler *state, int error; state->state = src_new(lsr_converter, channels, &error); if (!state->state) { - g_set_error(error_r, libsamplerate_quark(), state->error, - "libsamplerate initialization has failed: %s", - src_strerror(error)); + error_r.Format(libsamplerate_domain, error, + "libsamplerate initialization has failed: %s", + src_strerror(error)); return false; } @@ -144,14 +142,14 @@ pcm_resample_set(PcmResampler *state, } static bool -lsr_process(PcmResampler *state, GError **error_r) +lsr_process(PcmResampler *state, Error &error) { if (state->error == 0) state->error = src_process(state->state, &state->data); if (state->error) { - g_set_error(error_r, libsamplerate_quark(), state->error, - "libsamplerate has failed: %s", - src_strerror(state->error)); + error.Format(libsamplerate_domain, state->error, + "libsamplerate has failed: %s", + src_strerror(state->error)); return false; } @@ -164,16 +162,15 @@ pcm_resample_lsr_float(PcmResampler *state, unsigned src_rate, const float *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error) { SRC_DATA *data = &state->data; assert((src_size % (sizeof(*src_buffer) * channels)) == 0); - if (!pcm_resample_set(state, channels, src_rate, dest_rate, error_r)) + if (!pcm_resample_set(state, channels, src_rate, dest_rate, error)) return nullptr; - data->input_frames = src_size / sizeof(*src_buffer) / channels; data->data_in = const_cast<float *>(src_buffer); @@ -181,7 +178,7 @@ pcm_resample_lsr_float(PcmResampler *state, size_t data_out_size = data->output_frames * sizeof(float) * channels; data->data_out = (float *)state->out.Get(data_out_size); - if (!lsr_process(state, error_r)) + if (!lsr_process(state, error)) return nullptr; *dest_size_r = data->output_frames_gen * @@ -195,14 +192,14 @@ pcm_resample_lsr_16(PcmResampler *state, unsigned src_rate, const int16_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error) { SRC_DATA *data = &state->data; assert((src_size % (sizeof(*src_buffer) * channels)) == 0); if (!pcm_resample_set(state, channels, src_rate, dest_rate, - error_r)) + error)) return nullptr; data->input_frames = src_size / sizeof(*src_buffer) / channels; @@ -216,7 +213,7 @@ pcm_resample_lsr_16(PcmResampler *state, src_short_to_float_array(src_buffer, data->data_in, data->input_frames * channels); - if (!lsr_process(state, error_r)) + if (!lsr_process(state, error)) return nullptr; int16_t *dest_buffer; @@ -255,14 +252,14 @@ pcm_resample_lsr_32(PcmResampler *state, unsigned src_rate, const int32_t *src_buffer, size_t src_size, unsigned dest_rate, size_t *dest_size_r, - GError **error_r) + Error &error) { SRC_DATA *data = &state->data; assert((src_size % (sizeof(*src_buffer) * channels)) == 0); if (!pcm_resample_set(state, channels, src_rate, dest_rate, - error_r)) + error)) return nullptr; data->input_frames = src_size / sizeof(*src_buffer) / channels; @@ -276,7 +273,7 @@ pcm_resample_lsr_32(PcmResampler *state, src_int_to_float_array(src_buffer, data->data_in, data->input_frames * channels); - if (!lsr_process(state, error_r)) + if (!lsr_process(state, error)) return nullptr; int32_t *dest_buffer; |