aboutsummaryrefslogtreecommitdiffstats
path: root/src/encoder/LameEncoderPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-06 08:47:30 +0200
committerMax Kellermann <max@duempel.org>2013-08-06 09:02:48 +0200
commita32443c63b611a526008886dc61b1930599bb1d2 (patch)
treeb75cc1b40ae95e35a5cdc3f12499dbea9a8ef9f9 /src/encoder/LameEncoderPlugin.cxx
parent7e53934ce3a673e77d12f4e1595dc75192c23098 (diff)
downloadmpd-a32443c63b611a526008886dc61b1930599bb1d2.tar.gz
mpd-a32443c63b611a526008886dc61b1930599bb1d2.tar.xz
mpd-a32443c63b611a526008886dc61b1930599bb1d2.zip
encoder/lame: use offset variable instead of memmove()
Diffstat (limited to '')
-rw-r--r--src/encoder/LameEncoderPlugin.cxx23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/encoder/LameEncoderPlugin.cxx b/src/encoder/LameEncoderPlugin.cxx
index 9028fcac4..2411d3624 100644
--- a/src/encoder/LameEncoderPlugin.cxx
+++ b/src/encoder/LameEncoderPlugin.cxx
@@ -39,7 +39,7 @@ struct LameEncoder final {
lame_global_flags *gfp;
unsigned char output_buffer[32768];
- size_t output_buffer_length;
+ size_t output_buffer_length, output_buffer_position;
LameEncoder():encoder(lame_encoder_plugin) {}
@@ -210,6 +210,7 @@ lame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
}
encoder->output_buffer_length = 0;
+ encoder->output_buffer_position = 0;
return true;
}
@@ -230,7 +231,8 @@ lame_encoder_write(Encoder *_encoder,
LameEncoder *encoder = (LameEncoder *)_encoder;
const int16_t *src = (const int16_t*)data;
- assert(encoder->output_buffer_length == 0);
+ assert(encoder->output_buffer_position ==
+ encoder->output_buffer_length);
const unsigned num_frames =
length / encoder->audio_format.GetFrameSize();
@@ -259,6 +261,7 @@ lame_encoder_write(Encoder *_encoder,
}
encoder->output_buffer_length = (size_t)bytes_out;
+ encoder->output_buffer_position = 0;
return true;
}
@@ -267,14 +270,18 @@ lame_encoder_read(Encoder *_encoder, void *dest, size_t length)
{
LameEncoder *encoder = (LameEncoder *)_encoder;
- if (length > encoder->output_buffer_length)
- length = encoder->output_buffer_length;
+ assert(encoder->output_buffer_position <=
+ encoder->output_buffer_length);
- memcpy(dest, encoder->output_buffer, length);
+ const size_t remainning = encoder->output_buffer_length
+ - encoder->output_buffer_position;
+ if (length > remainning)
+ length = remainning;
- encoder->output_buffer_length -= length;
- memmove(encoder->output_buffer, encoder->output_buffer + length,
- encoder->output_buffer_length);
+ memcpy(dest, encoder->output_buffer + encoder->output_buffer_position,
+ length);
+
+ encoder->output_buffer_position += length;
return length;
}