aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoder
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-07-30 08:48:53 +0200
committerMax Kellermann <max@duempel.org>2013-07-30 08:48:53 +0200
commitda1f4b3ede750c83039bcd21647569bde00a2992 (patch)
treee28532c3126f75081b9d08829e6ee4267f928685 /src/encoder
parentdac740ee17aaaa368a9562db30bb687d700dbe1c (diff)
downloadmpd-da1f4b3ede750c83039bcd21647569bde00a2992.tar.gz
mpd-da1f4b3ede750c83039bcd21647569bde00a2992.tar.xz
mpd-da1f4b3ede750c83039bcd21647569bde00a2992.zip
encoder/wave: convert to C++
Diffstat (limited to 'src/encoder')
-rw-r--r--src/encoder/WaveEncoderPlugin.cxx (renamed from src/encoder/wave_encoder.c)59
-rw-r--r--src/encoder/WaveEncoderPlugin.hxx25
2 files changed, 58 insertions, 26 deletions
diff --git a/src/encoder/wave_encoder.c b/src/encoder/WaveEncoderPlugin.cxx
index 9b3c21fca..fb52d7906 100644
--- a/src/encoder/wave_encoder.c
+++ b/src/encoder/WaveEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,21 +18,28 @@
*/
#include "config.h"
+#include "WaveEncoderPlugin.hxx"
#include "encoder_api.h"
#include "encoder_plugin.h"
#include "util/fifo_buffer.h"
+extern "C" {
#include "util/growing_fifo.h"
+}
#include <glib.h>
#include <assert.h>
#include <string.h>
-struct wave_encoder {
+struct WaveEncoder {
struct encoder encoder;
unsigned bits;
struct fifo_buffer *buffer;
+
+ WaveEncoder() {
+ encoder_struct_init(&encoder, &wave_encoder_plugin);
+ }
};
struct wave_header {
@@ -84,18 +91,14 @@ static struct encoder *
wave_encoder_init(gcc_unused const struct config_param *param,
gcc_unused GError **error)
{
- struct wave_encoder *encoder;
-
- encoder = g_new(struct wave_encoder, 1);
- encoder_struct_init(&encoder->encoder, &wave_encoder_plugin);
-
+ WaveEncoder *encoder = new WaveEncoder();
return &encoder->encoder;
}
static void
wave_encoder_finish(struct encoder *_encoder)
{
- struct wave_encoder *encoder = (struct wave_encoder *)_encoder;
+ WaveEncoder *encoder = (WaveEncoder *)_encoder;
g_free(encoder);
}
@@ -105,7 +108,7 @@ wave_encoder_open(struct encoder *_encoder,
gcc_unused struct audio_format *audio_format,
gcc_unused GError **error)
{
- struct wave_encoder *encoder = (struct wave_encoder *)_encoder;
+ WaveEncoder *encoder = (WaveEncoder *)_encoder;
assert(audio_format_valid(audio_format));
@@ -133,7 +136,7 @@ wave_encoder_open(struct encoder *_encoder,
}
encoder->buffer = growing_fifo_new();
- struct wave_header *header =
+ wave_header *header = (wave_header *)
growing_fifo_write(&encoder->buffer, sizeof(*header));
/* create PCM wave header in initial buffer */
@@ -150,7 +153,7 @@ wave_encoder_open(struct encoder *_encoder,
static void
wave_encoder_close(struct encoder *_encoder)
{
- struct wave_encoder *encoder = (struct wave_encoder *)_encoder;
+ WaveEncoder *encoder = (WaveEncoder *)_encoder;
fifo_buffer_free(encoder->buffer);
}
@@ -200,9 +203,9 @@ wave_encoder_write(struct encoder *_encoder,
const void *src, size_t length,
gcc_unused GError **error)
{
- struct wave_encoder *encoder = (struct wave_encoder *)_encoder;
+ WaveEncoder *encoder = (WaveEncoder *)_encoder;
- void *dst = growing_fifo_write(&encoder->buffer, length);
+ uint8_t *dst = (uint8_t *)growing_fifo_write(&encoder->buffer, length);
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
switch (encoder->bits) {
@@ -212,7 +215,7 @@ wave_encoder_write(struct encoder *_encoder,
memcpy(dst, src, length);
break;
case 24:
- length = pcm24_to_wave(dst, src, length);
+ length = pcm24_to_wave(dst, (const uint32_t *)src, length);
break;
}
#elif (G_BYTE_ORDER == G_BIG_ENDIAN)
@@ -221,13 +224,13 @@ wave_encoder_write(struct encoder *_encoder,
memcpy(dst, src, length);
break;
case 16:
- length = pcm16_to_wave(dst, src, length);
+ length = pcm16_to_wave(dst, (const uint16_t *)src, length);
break;
case 24:
- length = pcm24_to_wave(dst, src, length);
+ length = pcm24_to_wave(dst, (const uint32_t *)src, length);
break;
case 32:
- length = pcm32_to_wave(dst, src, length);
+ length = pcm32_to_wave(dst, (const uint32_t *)src, length);
break;
}
#else
@@ -241,7 +244,7 @@ wave_encoder_write(struct encoder *_encoder,
static size_t
wave_encoder_read(struct encoder *_encoder, void *dest, size_t length)
{
- struct wave_encoder *encoder = (struct wave_encoder *)_encoder;
+ WaveEncoder *encoder = (WaveEncoder *)_encoder;
size_t max_length;
const void *src = fifo_buffer_read(encoder->buffer, &max_length);
@@ -263,12 +266,16 @@ wave_encoder_get_mime_type(gcc_unused struct encoder *_encoder)
}
const struct encoder_plugin wave_encoder_plugin = {
- .name = "wave",
- .init = wave_encoder_init,
- .finish = wave_encoder_finish,
- .open = wave_encoder_open,
- .close = wave_encoder_close,
- .write = wave_encoder_write,
- .read = wave_encoder_read,
- .get_mime_type = wave_encoder_get_mime_type,
+ "wave",
+ wave_encoder_init,
+ wave_encoder_finish,
+ wave_encoder_open,
+ wave_encoder_close,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ wave_encoder_write,
+ wave_encoder_read,
+ wave_encoder_get_mime_type,
};
diff --git a/src/encoder/WaveEncoderPlugin.hxx b/src/encoder/WaveEncoderPlugin.hxx
new file mode 100644
index 000000000..b50fe5514
--- /dev/null
+++ b/src/encoder/WaveEncoderPlugin.hxx
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2003-2013 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_ENCODER_WAVE_HXX
+#define MPD_ENCODER_WAVE_HXX
+
+extern const struct encoder_plugin wave_encoder_plugin;
+
+#endif