From 69b8ce4d80b1454212cd6e4e43fc023c861dc972 Mon Sep 17 00:00:00 2001 From: dschreiber Date: Wed, 31 Aug 2011 13:35:13 -0700 Subject: [PATCH] Fix issue where mod_shout does not properly flush buffer on writing mp3 streams, resulting in incomplete files. TODO: Refactor as part of the while loop. --- src/mod/formats/mod_shout/mod_shout.c | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/mod/formats/mod_shout/mod_shout.c b/src/mod/formats/mod_shout/mod_shout.c index bc72038db5..ea6912b193 100644 --- a/src/mod/formats/mod_shout/mod_shout.c +++ b/src/mod/formats/mod_shout/mod_shout.c @@ -204,6 +204,35 @@ static inline void free_context(shout_context_t *context) } if (context->shout) { + if (context->gfp) { + unsigned char mp3buffer[8192]; + int len; + int16_t blank[2048] = { 0 }, *r = NULL; + + if (context->channels == 2) { + r = blank; + } + + len = lame_encode_buffer(context->gfp, blank, r, sizeof(blank) / 2, mp3buffer, sizeof(mp3buffer)); + + if (len) { + ret = shout_send(context->shout, mp3buffer, len); + if (ret == SHOUTERR_SUCCESS) { + shout_sync(context->shout); + } + } + + while ((len = lame_encode_flush(context->gfp, mp3buffer, sizeof(mp3buffer))) > 0) { + ret = shout_send(context->shout, mp3buffer, len); + + if (ret != SHOUTERR_SUCCESS) { + break; + } else { + shout_sync(context->shout); + } + } + } + shout_close(context->shout); context->shout = NULL; }