encoder/lame: rename "buffer" to "output_buffer"

This commit is contained in:
Max Kellermann 2013-08-06 08:47:51 +02:00
parent 7c2b553364
commit 7e53934ce3
2 changed files with 33 additions and 31 deletions

View File

@ -38,8 +38,8 @@ struct LameEncoder final {
lame_global_flags *gfp; lame_global_flags *gfp;
unsigned char buffer[32768]; unsigned char output_buffer[32768];
size_t buffer_length; size_t output_buffer_length;
LameEncoder():encoder(lame_encoder_plugin) {} LameEncoder():encoder(lame_encoder_plugin) {}
@ -209,7 +209,7 @@ lame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
return false; return false;
} }
encoder->buffer_length = 0; encoder->output_buffer_length = 0;
return true; return true;
} }
@ -230,7 +230,7 @@ lame_encoder_write(Encoder *_encoder,
LameEncoder *encoder = (LameEncoder *)_encoder; LameEncoder *encoder = (LameEncoder *)_encoder;
const int16_t *src = (const int16_t*)data; const int16_t *src = (const int16_t*)data;
assert(encoder->buffer_length == 0); assert(encoder->output_buffer_length == 0);
const unsigned num_frames = const unsigned num_frames =
length / encoder->audio_format.GetFrameSize(); length / encoder->audio_format.GetFrameSize();
@ -245,8 +245,9 @@ lame_encoder_write(Encoder *_encoder,
} }
int bytes_out = lame_encode_buffer_float(encoder->gfp, left, right, int bytes_out = lame_encode_buffer_float(encoder->gfp, left, right,
num_frames, encoder->buffer, num_frames,
sizeof(encoder->buffer)); encoder->output_buffer,
sizeof(encoder->output_buffer));
g_free(left); g_free(left);
g_free(right); g_free(right);
@ -257,7 +258,7 @@ lame_encoder_write(Encoder *_encoder,
return false; return false;
} }
encoder->buffer_length = (size_t)bytes_out; encoder->output_buffer_length = (size_t)bytes_out;
return true; return true;
} }
@ -266,14 +267,14 @@ lame_encoder_read(Encoder *_encoder, void *dest, size_t length)
{ {
LameEncoder *encoder = (LameEncoder *)_encoder; LameEncoder *encoder = (LameEncoder *)_encoder;
if (length > encoder->buffer_length) if (length > encoder->output_buffer_length)
length = encoder->buffer_length; length = encoder->output_buffer_length;
memcpy(dest, encoder->buffer, length); memcpy(dest, encoder->output_buffer, length);
encoder->buffer_length -= length; encoder->output_buffer_length -= length;
memmove(encoder->buffer, encoder->buffer + length, memmove(encoder->output_buffer, encoder->output_buffer + length,
encoder->buffer_length); encoder->output_buffer_length);
return length; return length;
} }

View File

@ -38,11 +38,12 @@ struct TwolameEncoder final {
twolame_options *options; twolame_options *options;
unsigned char buffer[32768]; unsigned char output_buffer[32768];
size_t buffer_length; size_t output_buffer_length;
/** /**
* Call libtwolame's flush function when the buffer is empty? * Call libtwolame's flush function when the output_buffer is
* empty?
*/ */
bool flush; bool flush;
@ -209,7 +210,7 @@ twolame_encoder_open(Encoder *_encoder, AudioFormat &audio_format,
return false; return false;
} }
encoder->buffer_length = 0; encoder->output_buffer_length = 0;
encoder->flush = false; encoder->flush = false;
return true; return true;
@ -240,22 +241,22 @@ twolame_encoder_write(Encoder *_encoder,
TwolameEncoder *encoder = (TwolameEncoder *)_encoder; TwolameEncoder *encoder = (TwolameEncoder *)_encoder;
const int16_t *src = (const int16_t*)data; const int16_t *src = (const int16_t*)data;
assert(encoder->buffer_length == 0); assert(encoder->output_buffer_length == 0);
const unsigned num_frames = const unsigned num_frames =
length / encoder->audio_format.GetFrameSize(); length / encoder->audio_format.GetFrameSize();
int bytes_out = twolame_encode_buffer_interleaved(encoder->options, int bytes_out = twolame_encode_buffer_interleaved(encoder->options,
src, num_frames, src, num_frames,
encoder->buffer, encoder->output_buffer,
sizeof(encoder->buffer)); sizeof(encoder->output_buffer));
if (bytes_out < 0) { if (bytes_out < 0) {
g_set_error(error, twolame_encoder_quark(), 0, g_set_error(error, twolame_encoder_quark(), 0,
"twolame encoder failed"); "twolame encoder failed");
return false; return false;
} }
encoder->buffer_length = (size_t)bytes_out; encoder->output_buffer_length = (size_t)bytes_out;
return true; return true;
} }
@ -264,24 +265,24 @@ twolame_encoder_read(Encoder *_encoder, void *dest, size_t length)
{ {
TwolameEncoder *encoder = (TwolameEncoder *)_encoder; TwolameEncoder *encoder = (TwolameEncoder *)_encoder;
if (encoder->buffer_length == 0 && encoder->flush) { if (encoder->output_buffer_length == 0 && encoder->flush) {
int ret = twolame_encode_flush(encoder->options, int ret = twolame_encode_flush(encoder->options,
encoder->buffer, encoder->output_buffer,
sizeof(encoder->buffer)); sizeof(encoder->output_buffer));
if (ret > 0) if (ret > 0)
encoder->buffer_length = (size_t)ret; encoder->output_buffer_length = (size_t)ret;
encoder->flush = false; encoder->flush = false;
} }
if (length > encoder->buffer_length) if (length > encoder->output_buffer_length)
length = encoder->buffer_length; length = encoder->output_buffer_length;
memcpy(dest, encoder->buffer, length); memcpy(dest, encoder->output_buffer, length);
encoder->buffer_length -= length; encoder->output_buffer_length -= length;
memmove(encoder->buffer, encoder->buffer + length, memmove(encoder->output_buffer, encoder->output_buffer + length,
encoder->buffer_length); encoder->output_buffer_length);
return length; return length;
} }