diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 31561cd882..c10f7d253c 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -136,6 +136,7 @@ struct switch_media_bug { void *user_data; uint32_t flags; uint8_t ready; + time_t stop_time; struct switch_media_bug *next; }; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index afd85294c2..97586a2d06 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -130,7 +130,7 @@ struct switch_core_port_allocator; */ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session, switch_media_bug_callback_t callback, - void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug); + void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug); /*! \brief Obtain private data from a media bug \param bug the bug to get the data from diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 632e450bd7..dac4da79ef 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -198,7 +198,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech_unload_grammar(switch_c \param fh file handle to use (NULL for builtin one) \return SWITCH_STATUS_SUCCESS if all is well */ -SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh); +SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh); /*! \brief Stop Recording a session diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index a90011a34e..892473f52b 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -550,6 +550,7 @@ SWITCH_STANDARD_API(session_record_function) char *mycmd = NULL, *argv[4] = { 0 }; char *uuid = NULL, *action = NULL, *path = NULL; int argc = 0; + uint32_t limit = 0; if (session) { return SWITCH_STATUS_FALSE; @@ -570,7 +571,8 @@ SWITCH_STANDARD_API(session_record_function) uuid = argv[0]; action = argv[1]; path = argv[2]; - + limit = argv[3] ? atoi(argv[3]) : 0; + if (!(rsession = switch_core_session_locate(uuid))) { stream->write_function(stream, "-Error Cannot locate session!\n"); return SWITCH_STATUS_SUCCESS; @@ -581,7 +583,7 @@ SWITCH_STANDARD_API(session_record_function) } if (!strcasecmp(action, "start")) { - switch_ivr_record_session(rsession, path, NULL); + switch_ivr_record_session(rsession, path, limit, NULL); } else if (!strcasecmp(action, "stop")) { switch_ivr_stop_record_session(rsession, path); } else { @@ -1230,7 +1232,7 @@ static switch_api_interface_t session_record_api_interface = { /*.interface_name */ "session_record", /*.desc */ "session record", /*.function */ session_record_function, - /*.syntax */ " [start|stop] ", + /*.syntax */ " [start|stop] []", /*.next */ &broadcast_api_interface }; diff --git a/src/mod/applications/mod_playback/mod_playback.c b/src/mod/applications/mod_playback/mod_playback.c index 561474f14f..5382114e96 100644 --- a/src/mod/applications/mod_playback/mod_playback.c +++ b/src/mod/applications/mod_playback/mod_playback.c @@ -142,6 +142,11 @@ static void record_function(switch_core_session_t *session, char *data) path = switch_core_session_strdup(session, data); if ((p = strchr(path, '+'))) { + char *q = p - 1; + while(q && *q == ' ') { + *q = '\0'; + q--; + } *p++ = '\0'; limit = atoi(p); } @@ -158,10 +163,24 @@ static void record_function(switch_core_session_t *session, char *data) static void record_session_function(switch_core_session_t *session, char *data) { switch_channel_t *channel; + char *p, *path = NULL; + uint32_t limit = 0; + channel = switch_core_session_get_channel(session); assert(channel != NULL); - switch_ivr_record_session(session, data, NULL); + path = switch_core_session_strdup(session, data); + if ((p = strchr(path, '+'))) { + char *q = p - 1; + while(q && *q == ' ') { + *q = '\0'; + q--; + } + *p++ = '\0'; + limit = atoi(p); + } + + switch_ivr_record_session(session, path, limit, NULL); } diff --git a/src/switch_caller.c b/src/switch_caller.c index 3aab596fe8..e1a0a6f1c9 100644 --- a/src/switch_caller.c +++ b/src/switch_caller.c @@ -193,6 +193,16 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_ snprintf(header_name, sizeof(header_name), "%s-Channel-Name", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%s", caller_profile->chan_name); } + if (caller_profile->times) { + snprintf(header_name, sizeof(header_name), "%s-Channel-Created-Time", prefix); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->created); + snprintf(header_name, sizeof(header_name), "%s-Channel-Answered-Time", prefix); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->answered); + snprintf(header_name, sizeof(header_name), "%s-Channel-Hangup-Time", prefix); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup); + snprintf(header_name, sizeof(header_name), "%s-Channel-Transfer-Time", prefix); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, "%" SWITCH_TIME_T_FMT, caller_profile->times->transferred); + } snprintf(header_name, sizeof(header_name), "%s-Screen-Bit", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_SCREEN) ? "yes" : "no"); @@ -203,7 +213,7 @@ SWITCH_DECLARE(void) switch_caller_profile_event_set_data(switch_caller_profile_ snprintf(header_name, sizeof(header_name), "%s-Privacy-Hide-Number", prefix); switch_event_add_header(event, SWITCH_STACK_BOTTOM, header_name, switch_test_flag(caller_profile, SWITCH_CPF_HIDE_NUMBER) ? "yes" : "no"); - + } diff --git a/src/switch_core_io.c b/src/switch_core_io.c index cecf6dea78..a8fa5155f4 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -232,7 +232,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_mutex_lock(bp->read_mutex); switch_buffer_write(bp->raw_read_buffer, read_frame->data, read_frame->datalen); if (bp->callback) { - if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE) { + if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_READ) == SWITCH_FALSE || (bp->stop_time && bp->stop_time >= time(NULL))) { bp->ready = 0; if (last) { last->next = bp->next; @@ -505,6 +505,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess } } + if (bp->stop_time && bp->stop_time >= time(NULL)) { + ok = SWITCH_FALSE; + } + + if (ok == SWITCH_FALSE) { bp->ready = 0; if (last) { diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c index a81c5b7cb6..b615573280 100644 --- a/src/switch_core_media_bug.c +++ b/src/switch_core_media_bug.c @@ -144,7 +144,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *b #define MAX_BUG_BUFFER 1024 * 512 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t *session, switch_media_bug_callback_t callback, - void *user_data, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug) + void *user_data, time_t stop_time, switch_media_bug_flag_t flags, switch_media_bug_t **new_bug) { switch_media_bug_t *bug, *bp; switch_size_t bytes; @@ -170,6 +170,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t bug->session = session; bug->flags = flags; bug->ready = 1; + bug->stop_time = stop_time; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Attaching BUG to %s\n", switch_channel_get_name(session->channel)); bytes = session->read_codec->implementation->bytes_per_frame; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 5977b2cff2..5a4ee5a7ab 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -147,7 +147,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_stop_record_session(switch_core_sessi } -SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, switch_file_handle_t *fh) +SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t *session, char *file, uint32_t limit, switch_file_handle_t *fh) { switch_channel_t *channel; switch_codec_t *read_codec; @@ -155,6 +155,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t const char *vval; switch_media_bug_t *bug; switch_status_t status; + time_t to = 0; if (!fh) { if (!(fh = switch_core_session_alloc(session, sizeof(*fh)))) { @@ -220,9 +221,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_session(switch_core_session_t switch_channel_set_variable(channel, "RECORD_DATE", NULL); } + if (limit) { + to = time(NULL) + limit; + } - - if ((status = switch_core_media_bug_add(session, record_callback, fh, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) { + if ((status = switch_core_media_bug_add(session, record_callback, fh, to, SMBF_BOTH, &bug)) != SWITCH_STATUS_SUCCESS) { switch_core_file_close(fh); return status; } @@ -312,7 +315,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_sessi switch_channel_answer(channel); - if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) { + if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) { return status; } @@ -597,7 +600,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_detect_speech(switch_core_session_t * sth->session = session; sth->ah = ah; - if ((status = switch_core_media_bug_add(session, speech_callback, sth, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) { + if ((status = switch_core_media_bug_add(session, speech_callback, sth, 0, SMBF_READ_STREAM, &sth->bug)) != SWITCH_STATUS_SUCCESS) { switch_core_asr_close(ah, &flags); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); return status;