aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoder
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoder')
-rw-r--r--src/encoder/FlacEncoderPlugin.cxx58
-rw-r--r--src/encoder/LameEncoderPlugin.cxx88
-rw-r--r--src/encoder/NullEncoderPlugin.cxx8
-rw-r--r--src/encoder/OpusEncoderPlugin.cxx57
-rw-r--r--src/encoder/TwolameEncoderPlugin.cxx83
-rw-r--r--src/encoder/VorbisEncoderPlugin.cxx66
-rw-r--r--src/encoder/WaveEncoderPlugin.cxx6
7 files changed, 174 insertions, 192 deletions
diff --git a/src/encoder/FlacEncoderPlugin.cxx b/src/encoder/FlacEncoderPlugin.cxx
index 509d9bfdd..5a77e24a7 100644
--- a/src/encoder/FlacEncoderPlugin.cxx
+++ b/src/encoder/FlacEncoderPlugin.cxx
@@ -22,6 +22,9 @@
#include "EncoderAPI.hxx"
#include "AudioFormat.hxx"
#include "pcm/PcmBuffer.hxx"
+#include "ConfigError.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include "util/fifo_buffer.h"
extern "C" {
@@ -58,15 +61,11 @@ struct flac_encoder {
flac_encoder():encoder(flac_encoder_plugin) {}
};
-static inline GQuark
-flac_encoder_quark(void)
-{
- return g_quark_from_static_string("flac_encoder");
-}
+static constexpr Domain flac_encoder_domain("vorbis_encoder");
static bool
flac_encoder_configure(struct flac_encoder *encoder, const config_param &param,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
encoder->compression = param.GetBlockValue("compression", 5u);
@@ -74,7 +73,7 @@ flac_encoder_configure(struct flac_encoder *encoder, const config_param &param,
}
static Encoder *
-flac_encoder_init(const config_param &param, GError **error)
+flac_encoder_init(const config_param &param, Error &error)
{
flac_encoder *encoder = new flac_encoder();
@@ -100,35 +99,35 @@ flac_encoder_finish(Encoder *_encoder)
static bool
flac_encoder_setup(struct flac_encoder *encoder, unsigned bits_per_sample,
- GError **error)
+ Error &error)
{
if ( !FLAC__stream_encoder_set_compression_level(encoder->fse,
encoder->compression)) {
- g_set_error(error, flac_encoder_quark(), 0,
- "error setting flac compression to %d",
- encoder->compression);
+ error.Format(config_domain,
+ "error setting flac compression to %d",
+ encoder->compression);
return false;
}
if ( !FLAC__stream_encoder_set_channels(encoder->fse,
encoder->audio_format.channels)) {
- g_set_error(error, flac_encoder_quark(), 0,
- "error setting flac channels num to %d",
- encoder->audio_format.channels);
+ error.Format(config_domain,
+ "error setting flac channels num to %d",
+ encoder->audio_format.channels);
return false;
}
if ( !FLAC__stream_encoder_set_bits_per_sample(encoder->fse,
bits_per_sample)) {
- g_set_error(error, flac_encoder_quark(), 0,
- "error setting flac bit format to %d",
- bits_per_sample);
+ error.Format(config_domain,
+ "error setting flac bit format to %d",
+ bits_per_sample);
return false;
}
if ( !FLAC__stream_encoder_set_sample_rate(encoder->fse,
encoder->audio_format.sample_rate)) {
- g_set_error(error, flac_encoder_quark(), 0,
- "error setting flac sample rate to %d",
- encoder->audio_format.sample_rate);
+ error.Format(config_domain,
+ "error setting flac sample rate to %d",
+ encoder->audio_format.sample_rate);
return false;
}
return true;
@@ -161,8 +160,7 @@ flac_encoder_close(Encoder *_encoder)
}
static bool
-flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
- GError **error)
+flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format, Error &error)
{
struct flac_encoder *encoder = (struct flac_encoder *)_encoder;
unsigned bits_per_sample;
@@ -191,8 +189,7 @@ flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
/* allocate the encoder */
encoder->fse = FLAC__stream_encoder_new();
if (encoder->fse == nullptr) {
- g_set_error(error, flac_encoder_quark(), 0,
- "flac_new() failed");
+ error.Set(flac_encoder_domain, "flac_new() failed");
return false;
}
@@ -213,9 +210,9 @@ flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
nullptr, nullptr, nullptr, encoder);
if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
- g_set_error(error, flac_encoder_quark(), 0,
- "failed to initialize encoder: %s\n",
- FLAC__StreamEncoderInitStatusString[init_status]);
+ error.Format(flac_encoder_domain,
+ "failed to initialize encoder: %s\n",
+ FLAC__StreamEncoderInitStatusString[init_status]);
flac_encoder_close(_encoder);
return false;
}
@@ -226,7 +223,7 @@ flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
static bool
-flac_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
+flac_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
{
struct flac_encoder *encoder = (struct flac_encoder *)_encoder;
@@ -255,7 +252,7 @@ pcm16_to_flac(int32_t *out, const int16_t *in, unsigned num_samples)
static bool
flac_encoder_write(Encoder *_encoder,
const void *data, size_t length,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
struct flac_encoder *encoder = (struct flac_encoder *)_encoder;
unsigned num_frames, num_samples;
@@ -298,8 +295,7 @@ flac_encoder_write(Encoder *_encoder,
if (!FLAC__stream_encoder_process_interleaved(encoder->fse,
(const FLAC__int32 *)buffer,
num_frames)) {
- g_set_error(error, flac_encoder_quark(), 0,
- "flac encoder process failed");
+ error.Set(flac_encoder_domain, "flac encoder process failed");
return false;
}
diff --git a/src/encoder/LameEncoderPlugin.cxx b/src/encoder/LameEncoderPlugin.cxx
index 36e60dc4d..d3ed49a31 100644
--- a/src/encoder/LameEncoderPlugin.cxx
+++ b/src/encoder/LameEncoderPlugin.cxx
@@ -21,8 +21,11 @@
#include "LameEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
#include "AudioFormat.hxx"
+#include "ConfigError.hxx"
#include "util/ReusableArray.hxx"
#include "util/Manual.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <lame/lame.h>
@@ -45,17 +48,13 @@ struct LameEncoder final {
LameEncoder():encoder(lame_encoder_plugin) {}
- bool Configure(const config_param &param, GError **error);
+ bool Configure(const config_param &param, Error &error);
};
-static inline GQuark
-lame_encoder_quark(void)
-{
- return g_quark_from_static_string("lame_encoder");
-}
+static constexpr Domain lame_encoder_domain("lame_encoder");
bool
-LameEncoder::Configure(const config_param &param, GError **error)
+LameEncoder::Configure(const config_param &param, Error &error)
{
const char *value;
char *endptr;
@@ -67,18 +66,18 @@ LameEncoder::Configure(const config_param &param, GError **error)
quality = g_ascii_strtod(value, &endptr);
if (*endptr != '\0' || quality < -1.0 || quality > 10.0) {
- g_set_error(error, lame_encoder_quark(), 0,
- "quality \"%s\" is not a number in the "
- "range -1 to 10, line %i",
- value, param.line);
+ error.Format(config_domain,
+ "quality \"%s\" is not a number in the "
+ "range -1 to 10, line %i",
+ value, param.line);
return false;
}
if (param.GetBlockValue("bitrate") != nullptr) {
- g_set_error(error, lame_encoder_quark(), 0,
- "quality and bitrate are "
- "both defined (line %i)",
- param.line);
+ error.Format(config_domain,
+ "quality and bitrate are "
+ "both defined (line %i)",
+ param.line);
return false;
}
} else {
@@ -86,10 +85,10 @@ LameEncoder::Configure(const config_param &param, GError **error)
value = param.GetBlockValue("bitrate");
if (value == nullptr) {
- g_set_error(error, lame_encoder_quark(), 0,
- "neither bitrate nor quality defined "
- "at line %i",
- param.line);
+ error.Format(config_domain,
+ "neither bitrate nor quality defined "
+ "at line %i",
+ param.line);
return false;
}
@@ -97,9 +96,9 @@ LameEncoder::Configure(const config_param &param, GError **error)
bitrate = g_ascii_strtoll(value, &endptr, 10);
if (*endptr != '\0' || bitrate <= 0) {
- g_set_error(error, lame_encoder_quark(), 0,
- "bitrate at line %i should be a positive integer",
- param.line);
+ error.Format(config_domain,
+ "bitrate at line %i should be a positive integer",
+ param.line);
return false;
}
}
@@ -108,12 +107,12 @@ LameEncoder::Configure(const config_param &param, GError **error)
}
static Encoder *
-lame_encoder_init(const config_param &param, GError **error_r)
+lame_encoder_init(const config_param &param, Error &error)
{
LameEncoder *encoder = new LameEncoder();
/* load configuration from "param" */
- if (!encoder->Configure(param, error_r)) {
+ if (!encoder->Configure(param, error)) {
/* configuration has failed, roll back and return error */
delete encoder;
return nullptr;
@@ -133,55 +132,55 @@ lame_encoder_finish(Encoder *_encoder)
}
static bool
-lame_encoder_setup(LameEncoder *encoder, GError **error)
+lame_encoder_setup(LameEncoder *encoder, Error &error)
{
if (encoder->quality >= -1.0) {
/* a quality was configured (VBR) */
if (0 != lame_set_VBR(encoder->gfp, vbr_rh)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error setting lame VBR mode");
+ error.Set(lame_encoder_domain,
+ "error setting lame VBR mode");
return false;
}
if (0 != lame_set_VBR_q(encoder->gfp, encoder->quality)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error setting lame VBR quality");
+ error.Set(lame_encoder_domain,
+ "error setting lame VBR quality");
return false;
}
} else {
/* a bit rate was configured */
if (0 != lame_set_brate(encoder->gfp, encoder->bitrate)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error setting lame bitrate");
+ error.Set(lame_encoder_domain,
+ "error setting lame bitrate");
return false;
}
}
if (0 != lame_set_num_channels(encoder->gfp,
encoder->audio_format.channels)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error setting lame num channels");
+ error.Set(lame_encoder_domain,
+ "error setting lame num channels");
return false;
}
if (0 != lame_set_in_samplerate(encoder->gfp,
encoder->audio_format.sample_rate)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error setting lame sample rate");
+ error.Set(lame_encoder_domain,
+ "error setting lame sample rate");
return false;
}
if (0 != lame_set_out_samplerate(encoder->gfp,
encoder->audio_format.sample_rate)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error setting lame out sample rate");
+ error.Set(lame_encoder_domain,
+ "error setting lame out sample rate");
return false;
}
if (0 > lame_init_params(encoder->gfp)) {
- g_set_error(error, lame_encoder_quark(), 0,
- "error initializing lame params");
+ error.Set(lame_encoder_domain,
+ "error initializing lame params");
return false;
}
@@ -189,8 +188,7 @@ lame_encoder_setup(LameEncoder *encoder, GError **error)
}
static bool
-lame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
- GError **error)
+lame_encoder_open(Encoder *_encoder, AudioFormat &audio_format, Error &error)
{
LameEncoder *encoder = (LameEncoder *)_encoder;
@@ -201,8 +199,7 @@ lame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
encoder->gfp = lame_init();
if (encoder->gfp == nullptr) {
- g_set_error(error, lame_encoder_quark(), 0,
- "lame_init() failed");
+ error.Set(lame_encoder_domain, "lame_init() failed");
return false;
}
@@ -229,7 +226,7 @@ lame_encoder_close(Encoder *_encoder)
static bool
lame_encoder_write(Encoder *_encoder,
const void *data, size_t length,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
LameEncoder *encoder = (LameEncoder *)_encoder;
const int16_t *src = (const int16_t*)data;
@@ -254,8 +251,7 @@ lame_encoder_write(Encoder *_encoder,
output_buffer_size);
if (bytes_out < 0) {
- g_set_error(error, lame_encoder_quark(), 0,
- "lame encoder failed");
+ error.Set(lame_encoder_domain, "lame encoder failed");
return false;
}
diff --git a/src/encoder/NullEncoderPlugin.cxx b/src/encoder/NullEncoderPlugin.cxx
index 5c01fbd98..38bc5cbe3 100644
--- a/src/encoder/NullEncoderPlugin.cxx
+++ b/src/encoder/NullEncoderPlugin.cxx
@@ -26,8 +26,6 @@ extern "C" {
}
#include "gcc.h"
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
@@ -41,7 +39,7 @@ struct NullEncoder final {
static Encoder *
null_encoder_init(gcc_unused const config_param &param,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
NullEncoder *encoder = new NullEncoder();
return &encoder->encoder;
@@ -67,7 +65,7 @@ null_encoder_close(Encoder *_encoder)
static bool
null_encoder_open(Encoder *_encoder,
gcc_unused AudioFormat &audio_format,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
NullEncoder *encoder = (NullEncoder *)_encoder;
encoder->buffer = growing_fifo_new();
@@ -77,7 +75,7 @@ null_encoder_open(Encoder *_encoder,
static bool
null_encoder_write(Encoder *_encoder,
const void *data, size_t length,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
NullEncoder *encoder = (NullEncoder *)_encoder;
diff --git a/src/encoder/OpusEncoderPlugin.cxx b/src/encoder/OpusEncoderPlugin.cxx
index 9bb339312..c6e523ec4 100644
--- a/src/encoder/OpusEncoderPlugin.cxx
+++ b/src/encoder/OpusEncoderPlugin.cxx
@@ -22,11 +22,15 @@
#include "OggStream.hxx"
#include "EncoderAPI.hxx"
#include "AudioFormat.hxx"
-#include "mpd_error.h"
+#include "ConfigError.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <opus.h>
#include <ogg/ogg.h>
+#include <glib.h>
+
#include <assert.h>
#undef G_LOG_DOMAIN
@@ -66,16 +70,11 @@ struct opus_encoder {
opus_encoder():encoder(opus_encoder_plugin) {}
};
-gcc_const
-static inline GQuark
-opus_encoder_quark(void)
-{
- return g_quark_from_static_string("opus_encoder");
-}
+static constexpr Domain opus_encoder_domain("opus_encoder");
static bool
opus_encoder_configure(struct opus_encoder *encoder,
- const config_param &param, GError **error_r)
+ const config_param &param, Error &error)
{
const char *value = param.GetBlockValue("bitrate", "auto");
if (strcmp(value, "auto") == 0)
@@ -87,16 +86,14 @@ opus_encoder_configure(struct opus_encoder *encoder,
encoder->bitrate = strtoul(value, &endptr, 10);
if (endptr == value || *endptr != 0 ||
encoder->bitrate < 500 || encoder->bitrate > 512000) {
- g_set_error(error_r, opus_encoder_quark(), 0,
- "Invalid bit rate");
+ error.Set(config_domain, "Invalid bit rate");
return false;
}
}
encoder->complexity = param.GetBlockValue("complexity", 10u);
if (encoder->complexity > 10) {
- g_set_error(error_r, opus_encoder_quark(), 0,
- "Invalid complexity");
+ error.Format(config_domain, "Invalid complexity");
return false;
}
@@ -108,8 +105,7 @@ opus_encoder_configure(struct opus_encoder *encoder,
else if (strcmp(value, "music") == 0)
encoder->signal = OPUS_SIGNAL_MUSIC;
else {
- g_set_error(error_r, opus_encoder_quark(), 0,
- "Invalid signal");
+ error.Format(config_domain, "Invalid signal");
return false;
}
@@ -117,7 +113,7 @@ opus_encoder_configure(struct opus_encoder *encoder,
}
static Encoder *
-opus_encoder_init(const config_param &param, GError **error)
+opus_encoder_init(const config_param &param, Error &error)
{
opus_encoder *encoder = new opus_encoder();
@@ -144,7 +140,7 @@ opus_encoder_finish(Encoder *_encoder)
static bool
opus_encoder_open(Encoder *_encoder,
AudioFormat &audio_format,
- GError **error_r)
+ Error &error)
{
struct opus_encoder *encoder = (struct opus_encoder *)_encoder;
@@ -171,14 +167,14 @@ opus_encoder_open(Encoder *_encoder,
encoder->audio_format = audio_format;
encoder->frame_size = audio_format.GetFrameSize();
- int error;
+ int error_code;
encoder->enc = opus_encoder_create(audio_format.sample_rate,
audio_format.channels,
OPUS_APPLICATION_AUDIO,
- &error);
+ &error_code);
if (encoder->enc == nullptr) {
- g_set_error_literal(error_r, opus_encoder_quark(), error,
- opus_strerror(error));
+ error.Set(opus_encoder_domain, error_code,
+ opus_strerror(error_code));
return false;
}
@@ -212,7 +208,7 @@ opus_encoder_close(Encoder *_encoder)
static bool
opus_encoder_do_encode(struct opus_encoder *encoder, bool eos,
- GError **error_r)
+ Error &error)
{
assert(encoder->buffer_position == encoder->buffer_size);
@@ -229,8 +225,7 @@ opus_encoder_do_encode(struct opus_encoder *encoder, bool eos,
encoder->buffer2,
sizeof(encoder->buffer2));
if (result < 0) {
- g_set_error_literal(error_r, opus_encoder_quark(), 0,
- "Opus encoder error");
+ error.Set(opus_encoder_domain, "Opus encoder error");
return false;
}
@@ -251,7 +246,7 @@ opus_encoder_do_encode(struct opus_encoder *encoder, bool eos,
}
static bool
-opus_encoder_end(Encoder *_encoder, GError **error_r)
+opus_encoder_end(Encoder *_encoder, Error &error)
{
struct opus_encoder *encoder = (struct opus_encoder *)_encoder;
@@ -261,11 +256,11 @@ opus_encoder_end(Encoder *_encoder, GError **error_r)
encoder->buffer_size - encoder->buffer_position);
encoder->buffer_position = encoder->buffer_size;
- return opus_encoder_do_encode(encoder, true, error_r);
+ return opus_encoder_do_encode(encoder, true, error);
}
static bool
-opus_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
+opus_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
{
struct opus_encoder *encoder = (struct opus_encoder *)_encoder;
@@ -275,7 +270,7 @@ opus_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
static bool
opus_encoder_write_silence(struct opus_encoder *encoder, unsigned fill_frames,
- GError **error_r)
+ Error &error)
{
size_t fill_bytes = fill_frames * encoder->frame_size;
@@ -291,7 +286,7 @@ opus_encoder_write_silence(struct opus_encoder *encoder, unsigned fill_frames,
fill_bytes -= nbytes;
if (encoder->buffer_position == encoder->buffer_size &&
- !opus_encoder_do_encode(encoder, false, error_r))
+ !opus_encoder_do_encode(encoder, false, error))
return false;
}
@@ -301,7 +296,7 @@ opus_encoder_write_silence(struct opus_encoder *encoder, unsigned fill_frames,
static bool
opus_encoder_write(Encoder *_encoder,
const void *_data, size_t length,
- GError **error_r)
+ Error &error)
{
struct opus_encoder *encoder = (struct opus_encoder *)_encoder;
const uint8_t *data = (const uint8_t *)_data;
@@ -313,7 +308,7 @@ opus_encoder_write(Encoder *_encoder,
assert(encoder->buffer_position == 0);
if (!opus_encoder_write_silence(encoder, encoder->lookahead,
- error_r))
+ error))
return false;
encoder->lookahead = 0;
@@ -332,7 +327,7 @@ opus_encoder_write(Encoder *_encoder,
encoder->buffer_position += nbytes;
if (encoder->buffer_position == encoder->buffer_size &&
- !opus_encoder_do_encode(encoder, false, error_r))
+ !opus_encoder_do_encode(encoder, false, error))
return false;
}
diff --git a/src/encoder/TwolameEncoderPlugin.cxx b/src/encoder/TwolameEncoderPlugin.cxx
index 4243a579b..a04c2afe2 100644
--- a/src/encoder/TwolameEncoderPlugin.cxx
+++ b/src/encoder/TwolameEncoderPlugin.cxx
@@ -21,6 +21,9 @@
#include "TwolameEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
#include "AudioFormat.hxx"
+#include "ConfigError.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <twolame.h>
@@ -50,17 +53,13 @@ struct TwolameEncoder final {
TwolameEncoder():encoder(twolame_encoder_plugin) {}
- bool Configure(const config_param &param, GError **error);
+ bool Configure(const config_param &param, Error &error);
};
-static inline GQuark
-twolame_encoder_quark(void)
-{
- return g_quark_from_static_string("twolame_encoder");
-}
+static constexpr Domain twolame_encoder_domain("twolame_encoder");
bool
-TwolameEncoder::Configure(const config_param &param, GError **error)
+TwolameEncoder::Configure(const config_param &param, Error &error)
{
const char *value;
char *endptr;
@@ -72,18 +71,18 @@ TwolameEncoder::Configure(const config_param &param, GError **error)
quality = g_ascii_strtod(value, &endptr);
if (*endptr != '\0' || quality < -1.0 || quality > 10.0) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "quality \"%s\" is not a number in the "
- "range -1 to 10, line %i",
- value, param.line);
+ error.Format(config_domain,
+ "quality \"%s\" is not a number in the "
+ "range -1 to 10, line %i",
+ value, param.line);
return false;
}
if (param.GetBlockValue("bitrate") != nullptr) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "quality and bitrate are "
- "both defined (line %i)",
- param.line);
+ error.Format(config_domain,
+ "quality and bitrate are "
+ "both defined (line %i)",
+ param.line);
return false;
}
} else {
@@ -91,10 +90,10 @@ TwolameEncoder::Configure(const config_param &param, GError **error)
value = param.GetBlockValue("bitrate");
if (value == nullptr) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "neither bitrate nor quality defined "
- "at line %i",
- param.line);
+ error.Format(config_domain,
+ "neither bitrate nor quality defined "
+ "at line %i",
+ param.line);
return false;
}
@@ -102,9 +101,9 @@ TwolameEncoder::Configure(const config_param &param, GError **error)
bitrate = g_ascii_strtoll(value, &endptr, 10);
if (*endptr != '\0' || bitrate <= 0) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "bitrate at line %i should be a positive integer",
- param.line);
+ error.Format(config_domain,
+ "bitrate at line %i should be a positive integer",
+ param.line);
return false;
}
}
@@ -113,7 +112,7 @@ TwolameEncoder::Configure(const config_param &param, GError **error)
}
static Encoder *
-twolame_encoder_init(const config_param &param, GError **error_r)
+twolame_encoder_init(const config_param &param, Error &error_r)
{
g_debug("libtwolame version %s", get_twolame_version());
@@ -140,48 +139,48 @@ twolame_encoder_finish(Encoder *_encoder)
}
static bool
-twolame_encoder_setup(TwolameEncoder *encoder, GError **error)
+twolame_encoder_setup(TwolameEncoder *encoder, Error &error)
{
if (encoder->quality >= -1.0) {
/* a quality was configured (VBR) */
if (0 != twolame_set_VBR(encoder->options, true)) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "error setting twolame VBR mode");
+ error.Set(twolame_encoder_domain,
+ "error setting twolame VBR mode");
return false;
}
if (0 != twolame_set_VBR_q(encoder->options, encoder->quality)) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "error setting twolame VBR quality");
+ error.Set(twolame_encoder_domain,
+ "error setting twolame VBR quality");
return false;
}
} else {
/* a bit rate was configured */
if (0 != twolame_set_brate(encoder->options, encoder->bitrate)) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "error setting twolame bitrate");
+ error.Set(twolame_encoder_domain,
+ "error setting twolame bitrate");
return false;
}
}
if (0 != twolame_set_num_channels(encoder->options,
encoder->audio_format.channels)) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "error setting twolame num channels");
+ error.Set(twolame_encoder_domain,
+ "error setting twolame num channels");
return false;
}
if (0 != twolame_set_in_samplerate(encoder->options,
encoder->audio_format.sample_rate)) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "error setting twolame sample rate");
+ error.Set(twolame_encoder_domain,
+ "error setting twolame sample rate");
return false;
}
if (0 > twolame_init_params(encoder->options)) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "error initializing twolame params");
+ error.Set(twolame_encoder_domain,
+ "error initializing twolame params");
return false;
}
@@ -190,7 +189,7 @@ twolame_encoder_setup(TwolameEncoder *encoder, GError **error)
static bool
twolame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
- GError **error)
+ Error &error)
{
TwolameEncoder *encoder = (TwolameEncoder *)_encoder;
@@ -201,8 +200,7 @@ twolame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
encoder->options = twolame_init();
if (encoder->options == nullptr) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "twolame_init() failed");
+ error.Set(twolame_encoder_domain, "twolame_init() failed");
return false;
}
@@ -227,7 +225,7 @@ twolame_encoder_close(Encoder *_encoder)
}
static bool
-twolame_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
+twolame_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
{
TwolameEncoder *encoder = (TwolameEncoder *)_encoder;
@@ -238,7 +236,7 @@ twolame_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
static bool
twolame_encoder_write(Encoder *_encoder,
const void *data, size_t length,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
TwolameEncoder *encoder = (TwolameEncoder *)_encoder;
const int16_t *src = (const int16_t*)data;
@@ -254,8 +252,7 @@ twolame_encoder_write(Encoder *_encoder,
encoder->output_buffer,
sizeof(encoder->output_buffer));
if (bytes_out < 0) {
- g_set_error(error, twolame_encoder_quark(), 0,
- "twolame encoder failed");
+ error.Set(twolame_encoder_domain, "twolame encoder failed");
return false;
}
diff --git a/src/encoder/VorbisEncoderPlugin.cxx b/src/encoder/VorbisEncoderPlugin.cxx
index 4fb6bb661..27a368766 100644
--- a/src/encoder/VorbisEncoderPlugin.cxx
+++ b/src/encoder/VorbisEncoderPlugin.cxx
@@ -23,10 +23,14 @@
#include "EncoderAPI.hxx"
#include "Tag.hxx"
#include "AudioFormat.hxx"
-#include "mpd_error.h"
+#include "ConfigError.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <vorbis/vorbisenc.h>
+#include <glib.h>
+
#include <assert.h>
#undef G_LOG_DOMAIN
@@ -54,15 +58,11 @@ struct vorbis_encoder {
vorbis_encoder():encoder(vorbis_encoder_plugin) {}
};
-static inline GQuark
-vorbis_encoder_quark(void)
-{
- return g_quark_from_static_string("vorbis_encoder");
-}
+static constexpr Domain vorbis_encoder_domain("vorbis_encoder");
static bool
vorbis_encoder_configure(struct vorbis_encoder *encoder,
- const config_param &param, GError **error)
+ const config_param &param, Error &error)
{
const char *value = param.GetBlockValue("quality");
if (value != nullptr) {
@@ -73,18 +73,18 @@ vorbis_encoder_configure(struct vorbis_encoder *encoder,
if (*endptr != '\0' || encoder->quality < -1.0 ||
encoder->quality > 10.0) {
- g_set_error(error, vorbis_encoder_quark(), 0,
- "quality \"%s\" is not a number in the "
- "range -1 to 10, line %i",
- value, param.line);
+ error.Format(config_domain,
+ "quality \"%s\" is not a number in the "
+ "range -1 to 10, line %i",
+ value, param.line);
return false;
}
if (param.GetBlockValue("bitrate") != nullptr) {
- g_set_error(error, vorbis_encoder_quark(), 0,
- "quality and bitrate are "
- "both defined (line %i)",
- param.line);
+ error.Format(config_domain,
+ "quality and bitrate are "
+ "both defined (line %i)",
+ param.line);
return false;
}
} else {
@@ -92,10 +92,10 @@ vorbis_encoder_configure(struct vorbis_encoder *encoder,
value = param.GetBlockValue("bitrate");
if (value == nullptr) {
- g_set_error(error, vorbis_encoder_quark(), 0,
- "neither bitrate nor quality defined "
- "at line %i",
- param.line);
+ error.Format(config_domain,
+ "neither bitrate nor quality defined "
+ "at line %i",
+ param.line);
return false;
}
@@ -104,9 +104,9 @@ vorbis_encoder_configure(struct vorbis_encoder *encoder,
char *endptr;
encoder->bitrate = g_ascii_strtoll(value, &endptr, 10);
if (*endptr != '\0' || encoder->bitrate <= 0) {
- g_set_error(error, vorbis_encoder_quark(), 0,
- "bitrate at line %i should be a positive integer",
- param.line);
+ error.Format(config_domain,
+ "bitrate at line %i should be a positive integer",
+ param.line);
return false;
}
}
@@ -115,7 +115,7 @@ vorbis_encoder_configure(struct vorbis_encoder *encoder,
}
static Encoder *
-vorbis_encoder_init(const config_param &param, GError **error)
+vorbis_encoder_init(const config_param &param, Error &error)
{
vorbis_encoder *encoder = new vorbis_encoder();
@@ -140,7 +140,7 @@ vorbis_encoder_finish(Encoder *_encoder)
}
static bool
-vorbis_encoder_reinit(struct vorbis_encoder *encoder, GError **error)
+vorbis_encoder_reinit(struct vorbis_encoder *encoder, Error &error)
{
vorbis_info_init(&encoder->vi);
@@ -151,8 +151,8 @@ vorbis_encoder_reinit(struct vorbis_encoder *encoder, GError **error)
encoder->audio_format.channels,
encoder->audio_format.sample_rate,
encoder->quality * 0.1)) {
- g_set_error(error, vorbis_encoder_quark(), 0,
- "error initializing vorbis vbr");
+ error.Set(vorbis_encoder_domain,
+ "error initializing vorbis vbr");
vorbis_info_clear(&encoder->vi);
return false;
}
@@ -163,8 +163,8 @@ vorbis_encoder_reinit(struct vorbis_encoder *encoder, GError **error)
encoder->audio_format.channels,
encoder->audio_format.sample_rate, -1.0,
encoder->bitrate * 1000, -1.0)) {
- g_set_error(error, vorbis_encoder_quark(), 0,
- "error initializing vorbis encoder");
+ error.Set(vorbis_encoder_domain,
+ "error initializing vorbis encoder");
vorbis_info_clear(&encoder->vi);
return false;
}
@@ -203,7 +203,7 @@ vorbis_encoder_send_header(struct vorbis_encoder *encoder)
static bool
vorbis_encoder_open(Encoder *_encoder,
AudioFormat &audio_format,
- GError **error)
+ Error &error)
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
@@ -250,7 +250,7 @@ vorbis_encoder_blockout(struct vorbis_encoder *encoder)
}
static bool
-vorbis_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
+vorbis_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
@@ -259,7 +259,7 @@ vorbis_encoder_flush(Encoder *_encoder, gcc_unused GError **error)
}
static bool
-vorbis_encoder_pre_tag(Encoder *_encoder, gcc_unused GError **error)
+vorbis_encoder_pre_tag(Encoder *_encoder, gcc_unused Error &error)
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
@@ -290,7 +290,7 @@ copy_tag_to_vorbis_comment(vorbis_comment *vc, const Tag *tag)
static bool
vorbis_encoder_tag(Encoder *_encoder, const Tag *tag,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
vorbis_comment comment;
@@ -324,7 +324,7 @@ interleaved_to_vorbis_buffer(float **dest, const float *src,
static bool
vorbis_encoder_write(Encoder *_encoder,
const void *data, size_t length,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder;
diff --git a/src/encoder/WaveEncoderPlugin.cxx b/src/encoder/WaveEncoderPlugin.cxx
index 17560dfea..493b07b61 100644
--- a/src/encoder/WaveEncoderPlugin.cxx
+++ b/src/encoder/WaveEncoderPlugin.cxx
@@ -84,7 +84,7 @@ fill_wave_header(struct wave_header *header, int channels, int bits,
static Encoder *
wave_encoder_init(gcc_unused const config_param &param,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
WaveEncoder *encoder = new WaveEncoder();
return &encoder->encoder;
@@ -101,7 +101,7 @@ wave_encoder_finish(Encoder *_encoder)
static bool
wave_encoder_open(Encoder *_encoder,
AudioFormat &audio_format,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
WaveEncoder *encoder = (WaveEncoder *)_encoder;
@@ -196,7 +196,7 @@ pcm24_to_wave(uint8_t *dst8, const uint32_t *src32, size_t length)
static bool
wave_encoder_write(Encoder *_encoder,
const void *src, size_t length,
- gcc_unused GError **error)
+ gcc_unused Error &error)
{
WaveEncoder *encoder = (WaveEncoder *)_encoder;