add playback_timeout_sec to core and make it useful in valet_parking

This commit is contained in:
Anthony Minessale 2010-06-18 18:07:31 -05:00
parent 6f41b446cb
commit dac1243900
2 changed files with 30 additions and 3 deletions

View File

@ -279,11 +279,18 @@ SWITCH_STANDARD_APP(valet_parking_function)
args.buflen = sizeof(dbuf);
switch_mutex_unlock(lot->mutex);
if (!strcasecmp(music, "silence")) {
switch_ivr_collect_digits_callback(session, &args, 0, 0);
} else {
switch_ivr_play_file(session, NULL, music, &args);
music = "silence_stream://-1";
}
while(switch_channel_ready(channel)) {
switch_status_t pstatus = switch_ivr_play_file(session, NULL, music, &args);
if (pstatus == SWITCH_STATUS_BREAK || pstatus == SWITCH_STATUS_TIMEOUT) {
break;
}
}
switch_mutex_lock(lot->mutex);
switch_core_hash_delete(lot->hash, ext);
switch_mutex_unlock(lot->mutex);

View File

@ -913,9 +913,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
int argc;
int cur;
int done = 0;
int timeout_samples = 0;
const char *var;
switch_core_session_get_read_impl(session, &read_impl);
if ((var = switch_channel_get_variable(channel, "playback_timeout_sec"))) {
int tmp = atoi(var);
if (tmp > 1) {
timeout_samples = read_impl.actual_samples_per_second * tmp;
}
}
if ((play_delimiter_val = switch_channel_get_variable(channel, "playback_delimiter"))) {
play_delimiter = *play_delimiter_val;
@ -1402,6 +1411,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
fh->offset_pos += write_frame.samples / 2;
status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
if (timeout_samples) {
timeout_samples -= write_frame.samples;
if (timeout_samples <= 0) {
timeout_samples = 0;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "timeout reached playing file\n");
status = SWITCH_STATUS_TIMEOUT;
break;
}
}
if (status == SWITCH_STATUS_MORE_DATA) {
status = SWITCH_STATUS_SUCCESS;
continue;