From: William King Date: Thu, 1 Nov 2012 18:50:15 +0000 (-0700) Subject: Remove potential infinate loop when caller hung up before audio completed. Thanks... X-Git-Tag: v1.3.1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4502078cf2c75dac1720d45cbc147c261c81314;p=thirdparty%2Ffreeswitch.git Remove potential infinate loop when caller hung up before audio completed. Thanks to telapi.com for the patch --- diff --git a/src/mod/formats/mod_vlc/mod_vlc.c b/src/mod/formats/mod_vlc/mod_vlc.c index fb9c88b091..4984601618 100644 --- a/src/mod/formats/mod_vlc/mod_vlc.c +++ b/src/mod/formats/mod_vlc/mod_vlc.c @@ -340,19 +340,29 @@ static switch_status_t vlc_file_write(switch_file_handle_t *handle, void *data, static switch_status_t vlc_file_close(switch_file_handle_t *handle) { vlc_file_context_t *context = handle->private_info; + int sanity = 0; context->playing = 0; /* The clients need to empty the last of the audio buffer */ while ( switch_buffer_inuse(context->audio_buffer) > 0 ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC waiting to close the files: %d \n", (int) switch_buffer_inuse(context->audio_buffer)); - sleep(1); + switch_yield(500000); + if (++sanity > 10) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Giving up waiting for client to empty the audio buffer\n"); + break; + } } /* Let the clients get the last of the audio stream */ + sanity = 0; while ( 3 == libvlc_media_get_state(context->m) ) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VLC waiting for clients: %d \n", libvlc_media_get_state(context->m)); - sleep(1); + switch_yield(500000); + if (++sanity > 10) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Giving up waiting for client to get the last of the audio stream\n"); + break; + } } if( context->mp )