aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoder
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/encoder/FlacEncoderPlugin.cxx33
-rw-r--r--src/encoder/FlacEncoderPlugin.hxx2
-rw-r--r--src/encoder/LameEncoderPlugin.cxx2
-rw-r--r--src/encoder/LameEncoderPlugin.hxx2
-rw-r--r--src/encoder/NullEncoderPlugin.cxx32
-rw-r--r--src/encoder/NullEncoderPlugin.hxx2
-rw-r--r--src/encoder/OggSerial.cxx2
-rw-r--r--src/encoder/OggSerial.hxx2
-rw-r--r--src/encoder/OggStream.hxx2
-rw-r--r--src/encoder/OpusEncoderPlugin.cxx2
-rw-r--r--src/encoder/OpusEncoderPlugin.hxx2
-rw-r--r--src/encoder/ShineEncoderPlugin.cxx271
-rw-r--r--src/encoder/ShineEncoderPlugin.hxx25
-rw-r--r--src/encoder/TwolameEncoderPlugin.cxx2
-rw-r--r--src/encoder/TwolameEncoderPlugin.hxx2
-rw-r--r--src/encoder/VorbisEncoderPlugin.cxx4
-rw-r--r--src/encoder/VorbisEncoderPlugin.hxx2
-rw-r--r--src/encoder/WaveEncoderPlugin.cxx39
-rw-r--r--src/encoder/WaveEncoderPlugin.hxx2
19 files changed, 343 insertions, 87 deletions
diff --git a/src/encoder/FlacEncoderPlugin.cxx b/src/encoder/FlacEncoderPlugin.cxx
index fa7ed992d..83ceea699 100644
--- a/src/encoder/FlacEncoderPlugin.cxx
+++ b/src/encoder/FlacEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -23,16 +23,10 @@
#include "AudioFormat.hxx"
#include "pcm/PcmBuffer.hxx"
#include "ConfigError.hxx"
+#include "util/Manual.hxx"
+#include "util/DynamicFifoBuffer.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
-#include "util/fifo_buffer.h"
-
-extern "C" {
-#include "util/growing_fifo.h"
-}
-
-#include <assert.h>
-#include <string.h>
#include <FLAC/stream_encoder.h>
@@ -54,7 +48,7 @@ struct flac_encoder {
* This buffer will hold encoded data from libFLAC until it is
* picked up with flac_encoder_read().
*/
- struct fifo_buffer *output_buffer;
+ Manual<DynamicFifoBuffer<uint8_t>> output_buffer;
flac_encoder():encoder(flac_encoder_plugin) {}
};
@@ -141,7 +135,7 @@ flac_write_callback(gcc_unused const FLAC__StreamEncoder *fse,
struct flac_encoder *encoder = (struct flac_encoder *) client_data;
//transfer data to buffer
- growing_fifo_append(&encoder->output_buffer, data, bytes);
+ encoder->output_buffer->Append((const uint8_t *)data, bytes);
return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
}
@@ -154,7 +148,7 @@ flac_encoder_close(Encoder *_encoder)
FLAC__stream_encoder_delete(encoder->fse);
encoder->expand_buffer.Clear();
- fifo_buffer_free(encoder->output_buffer);
+ encoder->output_buffer.Destruct();
}
static bool
@@ -196,7 +190,7 @@ flac_encoder_open(Encoder *_encoder, AudioFormat &audio_format, Error &error)
return false;
}
- encoder->output_buffer = growing_fifo_new();
+ encoder->output_buffer.Construct(8192);
/* this immediately outputs data through callback */
@@ -305,18 +299,7 @@ flac_encoder_read(Encoder *_encoder, void *dest, size_t length)
{
struct flac_encoder *encoder = (struct flac_encoder *)_encoder;
- size_t max_length;
- const char *src = (const char *)
- fifo_buffer_read(encoder->output_buffer, &max_length);
- if (src == nullptr)
- return 0;
-
- if (length > max_length)
- length = max_length;
-
- memcpy(dest, src, length);
- fifo_buffer_consume(encoder->output_buffer, length);
- return length;
+ return encoder->output_buffer->Read((uint8_t *)dest, length);
}
static const char *
diff --git a/src/encoder/FlacEncoderPlugin.hxx b/src/encoder/FlacEncoderPlugin.hxx
index 928a7f93e..0cdc01600 100644
--- a/src/encoder/FlacEncoderPlugin.hxx
+++ b/src/encoder/FlacEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/LameEncoderPlugin.cxx b/src/encoder/LameEncoderPlugin.cxx
index 06082d16b..1f4ab2088 100644
--- a/src/encoder/LameEncoderPlugin.cxx
+++ b/src/encoder/LameEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/LameEncoderPlugin.hxx b/src/encoder/LameEncoderPlugin.hxx
index 49832baee..03e398f67 100644
--- a/src/encoder/LameEncoderPlugin.hxx
+++ b/src/encoder/LameEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/NullEncoderPlugin.cxx b/src/encoder/NullEncoderPlugin.cxx
index 3b1aae5e2..7ec351b71 100644
--- a/src/encoder/NullEncoderPlugin.cxx
+++ b/src/encoder/NullEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,21 +20,19 @@
#include "config.h"
#include "NullEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
-#include "util/fifo_buffer.h"
-extern "C" {
-#include "util/growing_fifo.h"
-}
+#include "util/Manual.hxx"
+#include "util/DynamicFifoBuffer.hxx"
#include "Compiler.h"
#include <assert.h>
-#include <string.h>
struct NullEncoder final {
Encoder encoder;
- struct fifo_buffer *buffer;
+ Manual<DynamicFifoBuffer<uint8_t>> buffer;
- NullEncoder():encoder(null_encoder_plugin) {}
+ NullEncoder()
+ :encoder(null_encoder_plugin) {}
};
static Encoder *
@@ -58,7 +56,7 @@ null_encoder_close(Encoder *_encoder)
{
NullEncoder *encoder = (NullEncoder *)_encoder;
- fifo_buffer_free(encoder->buffer);
+ encoder->buffer.Destruct();
}
@@ -68,7 +66,7 @@ null_encoder_open(Encoder *_encoder,
gcc_unused Error &error)
{
NullEncoder *encoder = (NullEncoder *)_encoder;
- encoder->buffer = growing_fifo_new();
+ encoder->buffer.Construct(8192);
return true;
}
@@ -79,7 +77,7 @@ null_encoder_write(Encoder *_encoder,
{
NullEncoder *encoder = (NullEncoder *)_encoder;
- growing_fifo_append(&encoder->buffer, data, length);
+ encoder->buffer->Append((const uint8_t *)data, length);
return length;
}
@@ -88,17 +86,7 @@ null_encoder_read(Encoder *_encoder, void *dest, size_t length)
{
NullEncoder *encoder = (NullEncoder *)_encoder;
- size_t max_length;
- const void *src = fifo_buffer_read(encoder->buffer, &max_length);
- if (src == nullptr)
- return 0;
-
- if (length > max_length)
- length = max_length;
-
- memcpy(dest, src, length);
- fifo_buffer_consume(encoder->buffer, length);
- return length;
+ return encoder->buffer->Read((uint8_t *)dest, length);
}
const EncoderPlugin null_encoder_plugin = {
diff --git a/src/encoder/NullEncoderPlugin.hxx b/src/encoder/NullEncoderPlugin.hxx
index b741a2f6d..6acf88e49 100644
--- a/src/encoder/NullEncoderPlugin.hxx
+++ b/src/encoder/NullEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/OggSerial.cxx b/src/encoder/OggSerial.cxx
index 0d4fc5a9f..677829439 100644
--- a/src/encoder/OggSerial.cxx
+++ b/src/encoder/OggSerial.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/OggSerial.hxx b/src/encoder/OggSerial.hxx
index 2e5a020c6..ceba8ebf9 100644
--- a/src/encoder/OggSerial.hxx
+++ b/src/encoder/OggSerial.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/OggStream.hxx b/src/encoder/OggStream.hxx
index e8dcdf970..805238c1d 100644
--- a/src/encoder/OggStream.hxx
+++ b/src/encoder/OggStream.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/OpusEncoderPlugin.cxx b/src/encoder/OpusEncoderPlugin.cxx
index 243dc0836..672ebf5e4 100644
--- a/src/encoder/OpusEncoderPlugin.cxx
+++ b/src/encoder/OpusEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/OpusEncoderPlugin.hxx b/src/encoder/OpusEncoderPlugin.hxx
index 3bb55e051..4e71694b9 100644
--- a/src/encoder/OpusEncoderPlugin.hxx
+++ b/src/encoder/OpusEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/ShineEncoderPlugin.cxx b/src/encoder/ShineEncoderPlugin.cxx
new file mode 100644
index 000000000..39e400a58
--- /dev/null
+++ b/src/encoder/ShineEncoderPlugin.cxx
@@ -0,0 +1,271 @@
+/*
+ * Copyright (C) 2003-2014 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 "ShineEncoderPlugin.hxx"
+#include "config.h"
+#include "EncoderAPI.hxx"
+#include "AudioFormat.hxx"
+#include "ConfigError.hxx"
+#include "util/Manual.hxx"
+#include "util/NumberParser.hxx"
+#include "util/DynamicFifoBuffer.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
+
+extern "C"
+{
+#include <shine/layer3.h>
+}
+
+static constexpr size_t BUFFER_INIT_SIZE = 8192;
+static constexpr unsigned CHANNELS = 2;
+
+struct ShineEncoder {
+ Encoder encoder;
+
+ AudioFormat audio_format;
+
+ shine_t shine;
+
+ shine_config_t config;
+
+ size_t frame_size;
+ size_t input_pos;
+ int16_t *stereo[CHANNELS];
+
+ Manual<DynamicFifoBuffer<uint8_t>> output_buffer;
+
+ ShineEncoder():encoder(shine_encoder_plugin){}
+
+ bool Configure(const config_param &param, Error &error);
+
+ bool Setup(Error &error);
+
+ bool WriteChunk(bool flush);
+};
+
+static constexpr Domain shine_encoder_domain("shine_encoder");
+
+inline bool
+ShineEncoder::Configure(const config_param &param,
+ gcc_unused Error &error)
+{
+ shine_set_config_mpeg_defaults(&config.mpeg);
+ config.mpeg.bitr = param.GetBlockValue("bitrate", 128);
+
+ return true;
+}
+
+static Encoder *
+shine_encoder_init(const config_param &param, Error &error)
+{
+ ShineEncoder *encoder = new ShineEncoder();
+
+ /* load configuration from "param" */
+ if (!encoder->Configure(param, error)) {
+ /* configuration has failed, roll back and return error */
+ delete encoder;
+ return nullptr;
+ }
+
+ return &encoder->encoder;
+}
+
+static void
+shine_encoder_finish(Encoder *_encoder)
+{
+ ShineEncoder *encoder = (ShineEncoder *)_encoder;
+
+ delete encoder;
+}
+
+inline bool
+ShineEncoder::Setup(Error &error)
+{
+ config.mpeg.mode = audio_format.channels == 2 ? STEREO : MONO;
+ config.wave.samplerate = audio_format.sample_rate;
+ config.wave.channels =
+ audio_format.channels == 2 ? PCM_STEREO : PCM_MONO;
+
+ if (shine_check_config(config.wave.samplerate, config.mpeg.bitr) < 0) {
+ error.Format(config_domain,
+ "error configuring shine. "
+ "samplerate %d and bitrate %d configuration"
+ " not supported.",
+ config.wave.samplerate,
+ config.mpeg.bitr);
+
+ return false;
+ }
+
+ shine = shine_initialise(&config);
+
+ if (!shine) {
+ error.Format(config_domain,
+ "error initializing shine.");
+
+ return false;
+ }
+
+ frame_size = shine_samples_per_pass(shine);
+
+ return true;
+}
+
+static bool
+shine_encoder_open(Encoder *_encoder, AudioFormat &audio_format, Error &error)
+{
+ ShineEncoder *encoder = (ShineEncoder *)_encoder;
+
+ audio_format.format = SampleFormat::S16;
+ audio_format.channels = CHANNELS;
+ encoder->audio_format = audio_format;
+
+ if (!encoder->Setup(error))
+ return false;
+
+ encoder->stereo[0] = new int16_t[encoder->frame_size];
+ encoder->stereo[1] = new int16_t[encoder->frame_size];
+ /* workaround for bug:
+ https://github.com/savonet/shine/issues/11 */
+ encoder->input_pos = SHINE_MAX_SAMPLES + 1;
+
+ encoder->output_buffer.Construct(BUFFER_INIT_SIZE);
+
+ return true;
+}
+
+static void
+shine_encoder_close(Encoder *_encoder)
+{
+ ShineEncoder *encoder = (ShineEncoder *)_encoder;
+
+ if (encoder->input_pos > SHINE_MAX_SAMPLES) {
+ /* write zero chunk */
+ encoder->input_pos = 0;
+ encoder->WriteChunk(true);
+ }
+
+ shine_close(encoder->shine);
+ delete[] encoder->stereo[0];
+ delete[] encoder->stereo[1];
+ encoder->output_buffer.Destruct();
+}
+
+bool
+ShineEncoder::WriteChunk(bool flush)
+{
+ if (flush || input_pos == frame_size) {
+ long written;
+
+ if (flush) {
+ /* fill remaining with 0s */
+ for (; input_pos < frame_size; input_pos++) {
+ stereo[0][input_pos] = stereo[1][input_pos] = 0;
+ }
+ }
+
+ const uint8_t *out =
+ shine_encode_buffer(shine, stereo, &written);
+
+ if (written > 0)
+ output_buffer->Append(out, written);
+
+ input_pos = 0;
+ }
+
+ return true;
+}
+
+static bool
+shine_encoder_write(Encoder *_encoder,
+ const void *_data, size_t length,
+ gcc_unused Error &error)
+{
+ ShineEncoder *encoder = (ShineEncoder *)_encoder;
+ const int16_t *data = (const int16_t*)_data;
+ length /= sizeof(*data) * encoder->audio_format.channels;
+ size_t written = 0;
+
+ if (encoder->input_pos > SHINE_MAX_SAMPLES) {
+ encoder->input_pos = 0;
+ }
+
+ /* write all data to de-interleaved buffers */
+ while (written < length) {
+ for (;
+ written < length
+ && encoder->input_pos < encoder->frame_size;
+ written++, encoder->input_pos++) {
+ const size_t base =
+ written * encoder->audio_format.channels;
+ encoder->stereo[0][encoder->input_pos] = data[base];
+ encoder->stereo[1][encoder->input_pos] = data[base + 1];
+ }
+ /* write if chunk is filled */
+ encoder->WriteChunk(false);
+ }
+
+ return true;
+}
+
+static bool
+shine_encoder_flush(Encoder *_encoder, gcc_unused Error &error)
+{
+ ShineEncoder *encoder = (ShineEncoder *)_encoder;
+ long written;
+
+ /* flush buffers and flush shine */
+ encoder->WriteChunk(true);
+ const uint8_t *data = shine_flush(encoder->shine, &written);
+
+ if (written > 0)
+ encoder->output_buffer->Append(data, written);
+
+ return true;
+}
+
+static size_t
+shine_encoder_read(Encoder *_encoder, void *dest, size_t length)
+{
+ ShineEncoder *encoder = (ShineEncoder *)_encoder;
+
+ return encoder->output_buffer->Read((uint8_t *)dest, length);
+}
+
+static const char *
+shine_encoder_get_mime_type(gcc_unused Encoder *_encoder)
+{
+ return "audio/mpeg";
+}
+
+const EncoderPlugin shine_encoder_plugin = {
+ "shine",
+ shine_encoder_init,
+ shine_encoder_finish,
+ shine_encoder_open,
+ shine_encoder_close,
+ shine_encoder_flush,
+ shine_encoder_flush,
+ nullptr,
+ nullptr,
+ shine_encoder_write,
+ shine_encoder_read,
+ shine_encoder_get_mime_type,
+};
diff --git a/src/encoder/ShineEncoderPlugin.hxx b/src/encoder/ShineEncoderPlugin.hxx
new file mode 100644
index 000000000..8b1520a74
--- /dev/null
+++ b/src/encoder/ShineEncoderPlugin.hxx
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2003-2014 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_SHINE_HXX
+#define MPD_ENCODER_SHINE_HXX
+
+extern const struct EncoderPlugin shine_encoder_plugin;
+
+#endif
diff --git a/src/encoder/TwolameEncoderPlugin.cxx b/src/encoder/TwolameEncoderPlugin.cxx
index 543e71d64..817590365 100644
--- a/src/encoder/TwolameEncoderPlugin.cxx
+++ b/src/encoder/TwolameEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/TwolameEncoderPlugin.hxx b/src/encoder/TwolameEncoderPlugin.hxx
index dd8a536f6..531dd3e90 100644
--- a/src/encoder/TwolameEncoderPlugin.hxx
+++ b/src/encoder/TwolameEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/VorbisEncoderPlugin.cxx b/src/encoder/VorbisEncoderPlugin.cxx
index 5b40aaea1..d82d85c17 100644
--- a/src/encoder/VorbisEncoderPlugin.cxx
+++ b/src/encoder/VorbisEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -33,8 +33,6 @@
#include <glib.h>
-#include <assert.h>
-
struct vorbis_encoder {
/** the base class */
Encoder encoder;
diff --git a/src/encoder/VorbisEncoderPlugin.hxx b/src/encoder/VorbisEncoderPlugin.hxx
index d5d6125d2..80703bf88 100644
--- a/src/encoder/VorbisEncoderPlugin.hxx
+++ b/src/encoder/VorbisEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/src/encoder/WaveEncoderPlugin.cxx b/src/encoder/WaveEncoderPlugin.cxx
index acae0be9e..732226128 100644
--- a/src/encoder/WaveEncoderPlugin.cxx
+++ b/src/encoder/WaveEncoderPlugin.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -21,10 +21,8 @@
#include "WaveEncoderPlugin.hxx"
#include "EncoderAPI.hxx"
#include "system/ByteOrder.hxx"
-#include "util/fifo_buffer.h"
-extern "C" {
-#include "util/growing_fifo.h"
-}
+#include "util/Manual.hxx"
+#include "util/DynamicFifoBuffer.hxx"
#include <assert.h>
#include <string.h>
@@ -33,7 +31,7 @@ struct WaveEncoder {
Encoder encoder;
unsigned bits;
- struct fifo_buffer *buffer;
+ Manual<DynamicFifoBuffer<uint8_t>> buffer;
WaveEncoder():encoder(wave_encoder_plugin) {}
};
@@ -128,9 +126,11 @@ wave_encoder_open(Encoder *_encoder,
break;
}
- encoder->buffer = growing_fifo_new();
- wave_header *header = (wave_header *)
- growing_fifo_write(&encoder->buffer, sizeof(*header));
+ encoder->buffer.Construct(8192);
+
+ auto range = encoder->buffer->Write();
+ assert(range.size >= sizeof(wave_header));
+ wave_header *header = (wave_header *)range.data;
/* create PCM wave header in initial buffer */
fill_wave_header(header,
@@ -138,7 +138,8 @@ wave_encoder_open(Encoder *_encoder,
encoder->bits,
audio_format.sample_rate,
(encoder->bits / 8) * audio_format.channels);
- fifo_buffer_append(encoder->buffer, sizeof(*header));
+
+ encoder->buffer->Append(sizeof(*header));
return true;
}
@@ -148,7 +149,7 @@ wave_encoder_close(Encoder *_encoder)
{
WaveEncoder *encoder = (WaveEncoder *)_encoder;
- fifo_buffer_free(encoder->buffer);
+ encoder->buffer.Destruct();
}
static size_t
@@ -198,7 +199,7 @@ wave_encoder_write(Encoder *_encoder,
{
WaveEncoder *encoder = (WaveEncoder *)_encoder;
- uint8_t *dst = (uint8_t *)growing_fifo_write(&encoder->buffer, length);
+ uint8_t *dst = encoder->buffer->Write(length);
if (IsLittleEndian()) {
switch (encoder->bits) {
@@ -230,7 +231,7 @@ wave_encoder_write(Encoder *_encoder,
}
}
- fifo_buffer_append(encoder->buffer, length);
+ encoder->buffer->Append(length);
return true;
}
@@ -239,17 +240,7 @@ wave_encoder_read(Encoder *_encoder, void *dest, size_t length)
{
WaveEncoder *encoder = (WaveEncoder *)_encoder;
- size_t max_length;
- const void *src = fifo_buffer_read(encoder->buffer, &max_length);
- if (src == NULL)
- return 0;
-
- if (length > max_length)
- length = max_length;
-
- memcpy(dest, src, length);
- fifo_buffer_consume(encoder->buffer, length);
- return length;
+ return encoder->buffer->Read((uint8_t *)dest, length);
}
static const char *
diff --git a/src/encoder/WaveEncoderPlugin.hxx b/src/encoder/WaveEncoderPlugin.hxx
index 190ee131e..341b98adc 100644
--- a/src/encoder/WaveEncoderPlugin.hxx
+++ b/src/encoder/WaveEncoderPlugin.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify