diff options
author | Max Kellermann <max@duempel.org> | 2011-11-28 11:56:01 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-11-28 11:56:01 +0100 |
commit | 4f093d5b979c3547c8dd8045dde5d91e8cc93461 (patch) | |
tree | 94b1c12cfce14c90f26852e948ba419a8a7ba7eb /src/encoder | |
parent | 37420c342bf9582a0de32d46f78716e913119400 (diff) | |
parent | e1b032cbad5db7698104a93c2235fb7da1f8b580 (diff) | |
download | mpd-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 '')
-rw-r--r-- | src/encoder/flac_encoder.c | 36 | ||||
-rw-r--r-- | src/encoder/null_encoder.c | 34 | ||||
-rw-r--r-- | src/encoder/wave_encoder.c | 51 |
3 files changed, 67 insertions, 54 deletions
diff --git a/src/encoder/flac_encoder.c b/src/encoder/flac_encoder.c index 8b315d710..9f60bdae5 100644 --- a/src/encoder/flac_encoder.c +++ b/src/encoder/flac_encoder.c @@ -22,6 +22,8 @@ #include "encoder_plugin.h" #include "audio_format.h" #include "pcm_buffer.h" +#include "fifo_buffer.h" +#include "growing_fifo.h" #include <assert.h> #include <string.h> @@ -38,8 +40,11 @@ struct flac_encoder { struct pcm_buffer expand_buffer; - struct pcm_buffer buffer; - size_t buffer_length; + /** + * This buffer will hold encoded data from libFLAC until it is + * picked up with flac_encoder_read(). + */ + struct fifo_buffer *output_buffer; }; extern const struct encoder_plugin flac_encoder_plugin; @@ -140,11 +145,8 @@ flac_write_callback(G_GNUC_UNUSED const FLAC__StreamEncoder *fse, { struct flac_encoder *encoder = (struct flac_encoder *) client_data; - char *buffer = pcm_buffer_get(&encoder->buffer, encoder->buffer_length + bytes); - //transfer data to buffer - memcpy( buffer + encoder->buffer_length, data, bytes); - encoder->buffer_length += bytes; + growing_fifo_append(&encoder->output_buffer, data, bytes); return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; } @@ -156,8 +158,8 @@ flac_encoder_close(struct encoder *_encoder) FLAC__stream_encoder_delete(encoder->fse); - pcm_buffer_deinit(&encoder->buffer); pcm_buffer_deinit(&encoder->expand_buffer); + fifo_buffer_free(encoder->output_buffer); } static bool @@ -201,10 +203,10 @@ flac_encoder_open(struct encoder *_encoder, struct audio_format *audio_format, return false; } - encoder->buffer_length = 0; - pcm_buffer_init(&encoder->buffer); pcm_buffer_init(&encoder->expand_buffer); + encoder->output_buffer = growing_fifo_new(); + /* this immediately outputs data through callback */ #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 @@ -325,16 +327,18 @@ static size_t flac_encoder_read(struct encoder *_encoder, void *dest, size_t length) { struct flac_encoder *encoder = (struct flac_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 char *src = fifo_buffer_read(encoder->output_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->output_buffer, length); return length; } 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; } diff --git a/src/encoder/wave_encoder.c b/src/encoder/wave_encoder.c index 6ebacab7d..67c3ce085 100644 --- a/src/encoder/wave_encoder.c +++ b/src/encoder/wave_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> @@ -29,8 +30,7 @@ struct wave_encoder { struct encoder encoder; unsigned bits; - struct pcm_buffer buffer; - size_t buffer_length; + struct fifo_buffer *buffer; }; struct wave_header { @@ -92,7 +92,6 @@ wave_encoder_init(G_GNUC_UNUSED const struct config_param *param, encoder = g_new(struct wave_encoder, 1); encoder_struct_init(&encoder->encoder, &wave_encoder_plugin); - pcm_buffer_init(&encoder->buffer); return &encoder->encoder; } @@ -102,7 +101,6 @@ wave_encoder_finish(struct encoder *_encoder) { struct wave_encoder *encoder = (struct wave_encoder *)_encoder; - pcm_buffer_deinit(&encoder->buffer); g_free(encoder); } @@ -112,7 +110,6 @@ wave_encoder_open(struct encoder *_encoder, G_GNUC_UNUSED GError **error) { struct wave_encoder *encoder = (struct wave_encoder *)_encoder; - void *buffer; assert(audio_format_valid(audio_format)); @@ -125,6 +122,11 @@ wave_encoder_open(struct encoder *_encoder, encoder->bits = 16; break; + case SAMPLE_FORMAT_S24: + audio_format->format = SAMPLE_FORMAT_S24_P32; + encoder->bits = 24; + break; + case SAMPLE_FORMAT_S24_P32: encoder->bits = 24; break; @@ -139,19 +141,29 @@ wave_encoder_open(struct encoder *_encoder, break; } - buffer = pcm_buffer_get(&encoder->buffer, sizeof(struct wave_header) ); + encoder->buffer = growing_fifo_new(); + struct wave_header *header = + growing_fifo_write(&encoder->buffer, sizeof(*header)); /* create PCM wave header in initial buffer */ - fill_wave_header((struct wave_header *) buffer, + fill_wave_header(header, audio_format->channels, encoder->bits, audio_format->sample_rate, (encoder->bits / 8) * audio_format->channels ); + fifo_buffer_append(encoder->buffer, sizeof(*header)); - encoder->buffer_length = sizeof(struct wave_header); return true; } +static void +wave_encoder_close(struct encoder *_encoder) +{ + struct wave_encoder *encoder = (struct wave_encoder *)_encoder; + + fifo_buffer_free(encoder->buffer); +} + static inline size_t pcm16_to_wave(uint16_t *dst16, const uint16_t *src16, size_t length) { @@ -198,9 +210,8 @@ wave_encoder_write(struct encoder *_encoder, G_GNUC_UNUSED GError **error) { struct wave_encoder *encoder = (struct wave_encoder *)_encoder; - void *dst; - dst = pcm_buffer_get(&encoder->buffer, encoder->buffer_length + length); + void *dst = growing_fifo_write(&encoder->buffer, length); #if (G_BYTE_ORDER == G_LITTLE_ENDIAN) switch (encoder->bits) { @@ -232,7 +243,7 @@ wave_encoder_write(struct encoder *_encoder, #error G_BYTE_ORDER set to G_PDP_ENDIAN is not supported by wave_encoder #endif - encoder->buffer_length += length; + fifo_buffer_append(encoder->buffer, length); return true; } @@ -240,16 +251,17 @@ static size_t wave_encoder_read(struct encoder *_encoder, void *dest, size_t length) { struct wave_encoder *encoder = (struct wave_encoder *)_encoder; - uint8_t *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; } @@ -264,6 +276,7 @@ const struct encoder_plugin wave_encoder_plugin = { .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, |