aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoder/null_encoder.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2011-11-28 11:56:01 +0100
committerMax Kellermann <max@duempel.org>2011-11-28 11:56:01 +0100
commit4f093d5b979c3547c8dd8045dde5d91e8cc93461 (patch)
tree94b1c12cfce14c90f26852e948ba419a8a7ba7eb /src/encoder/null_encoder.c
parent37420c342bf9582a0de32d46f78716e913119400 (diff)
parente1b032cbad5db7698104a93c2235fb7da1f8b580 (diff)
downloadmpd-4f093d5b979c3547c8dd8045dde5d91e8cc93461.tar.gz
mpd-4f093d5b979c3547c8dd8045dde5d91e8cc93461.tar.xz
mpd-4f093d5b979c3547c8dd8045dde5d91e8cc93461.zip
Merge branch 'v0.16.x'
Conflicts: Makefile.am NEWS configure.ac src/encoder/flac_encoder.c src/log.c src/pcm_buffer.c
Diffstat (limited to 'src/encoder/null_encoder.c')
-rw-r--r--src/encoder/null_encoder.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/encoder/null_encoder.c b/src/encoder/null_encoder.c
index e83eaf2ba..48cdf139b 100644
--- a/src/encoder/null_encoder.c
+++ b/src/encoder/null_encoder.c
@@ -20,7 +20,8 @@
#include "config.h"
#include "encoder_api.h"
#include "encoder_plugin.h"
-#include "pcm_buffer.h"
+#include "fifo_buffer.h"
+#include "growing_fifo.h"
#include <assert.h>
#include <string.h>
@@ -28,8 +29,7 @@
struct null_encoder {
struct encoder encoder;
- struct pcm_buffer buffer;
- size_t buffer_length;
+ struct fifo_buffer *buffer;
};
extern const struct encoder_plugin null_encoder_plugin;
@@ -65,7 +65,7 @@ null_encoder_close(struct encoder *_encoder)
{
struct null_encoder *encoder = (struct null_encoder *)_encoder;
- pcm_buffer_deinit(&encoder->buffer);
+ fifo_buffer_free(encoder->buffer);
}
@@ -76,9 +76,7 @@ null_encoder_open(struct encoder *_encoder,
{
struct null_encoder *encoder = (struct null_encoder *)_encoder;
- encoder->buffer_length = 0;
- pcm_buffer_init(&encoder->buffer);
-
+ encoder->buffer = growing_fifo_new();
return true;
}
@@ -88,28 +86,26 @@ null_encoder_write(struct encoder *_encoder,
G_GNUC_UNUSED GError **error)
{
struct null_encoder *encoder = (struct null_encoder *)_encoder;
- char *buffer = pcm_buffer_get(&encoder->buffer, encoder->buffer_length + length);
-
- memcpy(buffer+encoder->buffer_length, data, length);
- encoder->buffer_length += length;
- return true;
+ growing_fifo_append(&encoder->buffer, data, length);
+ return length;
}
static size_t
null_encoder_read(struct encoder *_encoder, void *dest, size_t length)
{
struct null_encoder *encoder = (struct null_encoder *)_encoder;
- char *buffer = pcm_buffer_get(&encoder->buffer, encoder->buffer_length);
-
- if (length > encoder->buffer_length)
- length = encoder->buffer_length;
- memcpy(dest, buffer, length);
+ size_t max_length;
+ const void *src = fifo_buffer_read(encoder->buffer, &max_length);
+ if (src == NULL)
+ return 0;
- encoder->buffer_length -= length;
- memmove(buffer, buffer + length, encoder->buffer_length);
+ if (length > max_length)
+ length = max_length;
+ memcpy(dest, src, length);
+ fifo_buffer_consume(encoder->buffer, length);
return length;
}