提交 f8d26368 authored 作者: Chris Rienzo's avatar Chris Rienzo

--resolve FS-5243 improve mod_unimrcp audio buffering

上级 49138460
...@@ -273,7 +273,8 @@ static switch_status_t audio_queue_destroy(audio_queue_t *queue); ...@@ -273,7 +273,8 @@ static switch_status_t audio_queue_destroy(audio_queue_t *queue);
* SPEECH_CHANNEL : speech functions common to recognizer and synthesizer * SPEECH_CHANNEL : speech functions common to recognizer and synthesizer
*/ */
#define SPEECH_CHANNEL_TIMEOUT_USEC (5 * 1000000) #define SPEECH_CHANNEL_TIMEOUT_USEC (5000 * 1000)
#define AUDIO_TIMEOUT_USEC (SWITCH_MAX_INTERVAL * 1000)
/** /**
* Type of MRCP channel * Type of MRCP channel
...@@ -725,11 +726,18 @@ static switch_status_t audio_queue_read(audio_queue_t *queue, void *data, switch ...@@ -725,11 +726,18 @@ static switch_status_t audio_queue_read(audio_queue_t *queue, void *data, switch
#endif #endif
switch_mutex_lock(queue->mutex); switch_mutex_lock(queue->mutex);
/* allow the initial frame to buffer */
if (!queue->read_bytes && switch_buffer_inuse(queue->buffer) < requested) {
*data_len = 0;
status = SWITCH_STATUS_SUCCESS;
goto done;
}
/* wait for data, if allowed */ /* wait for data, if allowed */
if (block) { if (block) {
while (switch_buffer_inuse(queue->buffer) < requested) { while (switch_buffer_inuse(queue->buffer) < requested) {
queue->waiting = requested; queue->waiting = requested;
if (switch_thread_cond_timedwait(queue->cond, queue->mutex, SPEECH_CHANNEL_TIMEOUT_USEC) == SWITCH_STATUS_TIMEOUT) { if (switch_thread_cond_timedwait(queue->cond, queue->mutex, AUDIO_TIMEOUT_USEC) == SWITCH_STATUS_TIMEOUT) {
break; break;
} }
} }
...@@ -774,6 +782,9 @@ static switch_status_t audio_queue_clear(audio_queue_t *queue) ...@@ -774,6 +782,9 @@ static switch_status_t audio_queue_clear(audio_queue_t *queue)
switch_buffer_zero(queue->buffer); switch_buffer_zero(queue->buffer);
switch_thread_cond_signal(queue->cond); switch_thread_cond_signal(queue->cond);
switch_mutex_unlock(queue->mutex); switch_mutex_unlock(queue->mutex);
queue->read_bytes = 0;
queue->write_bytes = 0;
queue->waiting = 0;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论