MODFORM-21 add a bit more error checking to mod_shout write function

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10538 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-11-25 21:23:40 +00:00
parent 1a598b6db3
commit 02099953d5

View File

@ -902,12 +902,22 @@ static switch_status_t shout_file_read(switch_file_handle_t *handle, void *data,
static switch_status_t shout_file_write(switch_file_handle_t *handle, void *data, size_t *len)
{
shout_context_t *context = handle->private_info;
shout_context_t *context;
unsigned char mp3buf[8192] = "";
int rlen;
int16_t *audio = data;
int nsamples = *len;
if (!handle) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error no handle\n");
return SWITCH_STATUS_FALSE;
}
if (!(context = handle->private_info)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error no context\n");
return SWITCH_STATUS_FALSE;
}
if (context->shout && !context->shout_init) {
context->shout_init++;
if (shout_open(context->shout) != SHOUTERR_SUCCESS) {
@ -918,7 +928,7 @@ static switch_status_t shout_file_write(switch_file_handle_t *handle, void *data
launch_write_stream_thread(context);
}
if (handle->handler) {
if (handle->handler && context->audio_mutex) {
switch_mutex_lock(context->audio_mutex);
if (context->audio_buffer) {
if (!switch_buffer_write(context->audio_buffer, data, (nsamples * sizeof(int16_t) * handle->channels))) {
@ -928,11 +938,15 @@ static switch_status_t shout_file_write(switch_file_handle_t *handle, void *data
} else {
context->err++;
}
switch_mutex_unlock(context->audio_mutex);
if (context->err) {
return SWITCH_STATUS_FALSE;
}
} else {
handle->sample_count += *len;
return SWITCH_STATUS_SUCCESS;
}
if (!context->lame_ready) {
lame_init_params(context->gfp);
@ -970,7 +984,6 @@ static switch_status_t shout_file_write(switch_file_handle_t *handle, void *data
return SWITCH_STATUS_FALSE;
}
}
}
handle->sample_count += *len;