add timout to record and time tables to all the channel events

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5236 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-05-31 14:42:23 +00:00
parent 1730f202dd
commit a1d4140ce6
9 changed files with 55 additions and 14 deletions

View File

@ -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;
};

View File

@ -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

View File

@ -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

View File

@ -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 */ "<uuid> [start|stop] <path>",
/*.syntax */ "<uuid> [start|stop] <path> [<limit>]",
/*.next */ &broadcast_api_interface
};

View File

@ -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);
}

View File

@ -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");
}

View File

@ -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) {

View File

@ -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;

View File

@ -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;