add SWITCH_MESSAGE_HEARTBEAT_EVENT indication to execute on a session when session heartbeat fires

This commit is contained in:
Anthony Minessale 2014-04-15 21:22:36 +05:00
parent 96523a9bef
commit b99ef3af01
3 changed files with 11 additions and 0 deletions

View File

@ -1014,6 +1014,7 @@ typedef enum {
SWITCH_MESSAGE_PROGRESS_EVENT,
SWITCH_MESSAGE_RING_EVENT,
SWITCH_MESSAGE_RESAMPLE_EVENT,
SWITCH_MESSAGE_HEARTBEAT_EVENT,
SWITCH_MESSAGE_INVALID
} switch_core_session_message_types_t;

View File

@ -226,8 +226,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
if (session->read_codec && !session->track_id && session->track_duration) {
if (session->read_frame_count == 0) {
switch_event_t *event;
switch_core_session_message_t msg = { 0 };
session->read_frame_count = (session->read_impl.actual_samples_per_second / session->read_impl.samples_per_packet) * session->track_duration;
msg.message_id = SWITCH_MESSAGE_HEARTBEAT_EVENT;
switch_core_session_receive_message(session, &msg);
switch_event_create(&event, SWITCH_EVENT_SESSION_HEARTBEAT);
switch_channel_event_set_data(session->channel, event);
switch_event_fire(&event);

View File

@ -755,6 +755,7 @@ static const char *message_names[] = {
"PROGRESS_EVENT",
"RING_EVENT",
"RESAMPLE_EVENT",
"HEARTBEAT_EVENT",
"INVALID"
};
@ -1494,6 +1495,7 @@ SWITCH_STANDARD_SCHED_FUNC(sch_heartbeat_callback)
switch_event_t *event;
switch_core_session_t *session;
char *uuid = task->cmd_arg;
switch_core_session_message_t msg = { 0 };
if ((session = switch_core_session_locate(uuid))) {
switch_event_create(&event, SWITCH_EVENT_SESSION_HEARTBEAT);
@ -1503,6 +1505,9 @@ SWITCH_STANDARD_SCHED_FUNC(sch_heartbeat_callback)
/* reschedule this task */
task->runtime = switch_epoch_time_now(NULL) + session->track_duration;
msg.message_id = SWITCH_MESSAGE_HEARTBEAT_EVENT;
switch_core_session_receive_message(session, &msg);
switch_core_session_rwunlock(session);
}
}