Skip to content

Commit

Permalink
mencoder: Support flushing audio encoders at end of stream.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@37195 b3059339-0415-0410-9bf9-f77b7e298cf2
  • Loading branch information
reimar committed May 10, 2014
1 parent a199fe1 commit e065b74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 3 additions & 1 deletion libmpcodecs/ae_lame.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ static int get_frame_size(audio_encoder_t *encoder)
static int encode_lame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
{
int n = 0;
if(encoder->params.channels == 1)
if (!src)
n = lame_encode_flush(lame, dest, max_size);
else if (encoder->params.channels == 1)
n = lame_encode_buffer(lame, (short *)src, (short *)src, len/2, dest, max_size);
else
n = lame_encode_buffer_interleaved(lame,(short *)src, len/4, dest, max_size);
Expand Down
3 changes: 3 additions & 0 deletions libmpcodecs/ae_twolame.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ static int encode_twolame(audio_encoder_t *encoder, uint8_t *dest, void *src, in
mpae_twolame_ctx *ctx = encoder->priv;
int ret_size = 0, r2;

if (!src)
return twolame_encode_flush(ctx->twolame_ctx, dest, max_size);

len /= (2*encoder->params.channels);
ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size);
r2 = mp_decode_mp3_header(dest);
Expand Down
13 changes: 8 additions & 5 deletions mencoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ if(sh_audio){

len = dec_audio(sh_audio, aencoder->decode_buffer, len);
mux_a->buffer_len += aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len,
aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len);
len <= 0 && sh_audio->ds->eof ? NULL : aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len);
if(mux_a->buffer_len < mux_a->wf->nBlockAlign)
len = 0;
else
Expand All @@ -1362,10 +1362,13 @@ if(sh_audio){
len = dec_audio(sh_audio,aencoder->decode_buffer, aencoder->decode_buffer_size);
if(len <= 0)
{
len = 0;
break;
}
len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len);
// try flushing encoder
if (sh_audio->ds->eof)
len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, NULL, 0, mux_a->buffer_size-mux_a->buffer_len);
if (len <= 0)
break;
} else
len = aencoder->encode(aencoder, mux_a->buffer + mux_a->buffer_len, aencoder->decode_buffer, len, mux_a->buffer_size-mux_a->buffer_len);
mux_a->buffer_len += len;
}
}
Expand Down

0 comments on commit e065b74

Please sign in to comment.