diff options
Diffstat (limited to '')
-rw-r--r-- | src/encoder/LameEncoderPlugin.cxx | 23 |
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; } |