From b99ef3af015f06fc119b6f97b9842a2313efcc71 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 15 Apr 2014 21:22:36 +0500 Subject: [PATCH] add SWITCH_MESSAGE_HEARTBEAT_EVENT indication to execute on a session when session heartbeat fires --- src/include/switch_types.h | 1 + src/switch_core_io.c | 5 +++++ src/switch_core_session.c | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 949958835b..b9c5b744ac 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -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; diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 4c7b7fd8b8..6b9a1dacf8 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -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); diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 5fa3feb344..d07a435b74 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -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); } }