]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-6622: [mod_shout] set buffer size for streams based on the number of channels...
authorBrian West <brian@freeswitch.org>
Tue, 18 Nov 2014 15:47:43 +0000 (09:47 -0600)
committerBrian West <brian@freeswitch.org>
Tue, 18 Nov 2014 15:47:43 +0000 (09:47 -0600)
src/mod/formats/mod_shout/mod_shout.c

index 553ef4e889944b8657efcad4449f0f287d5e695d..e6ba9a94b20f39e3a65c1527ca3a13a344c4fabf 100644 (file)
@@ -123,6 +123,7 @@ struct shout_context {
        int lame_ready;
        int eof;
        int channels;
+       int stream_channels;
        int16_t *l;
        switch_size_t llen;
        int16_t *r;
@@ -371,14 +372,25 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
        shout_context_t *context = data;
        int decode_status = 0;
        size_t usedlen;
-       uint32_t buf_size = 1024 * 128;                 /* do not make this 64 or less, stutter will ensue after 
-                                                                                          first 64k buffer is dry */
+       uint32_t buf_size = 1024 * 128; /* do not make this 64 or less, stutter will ensue after first 64k buffer is dry */
        switch_size_t used;
 
+       if (!context->stream_channels) {
+               long rate = 0;
+               int channels = 0;
+               int encoding = 0;
+               mpg123_getformat(context->mh, &rate, &channels, &encoding);
+               context->stream_channels = channels;
+       }
+
        if (context->prebuf) {
                buf_size = context->prebuf;
        }
 
+       if (context->stream_channels) {
+               buf_size = buf_size * context->stream_channels;
+       }
+
        /* make sure we aren't over zealous by slowing down the stream when the buffer is too full */
        while (!context->err) {
                switch_mutex_lock(context->audio_mutex);