Skip to content

Commit

Permalink
chan_pjsip: Add ability to send flash events.
Browse files Browse the repository at this point in the history
PJSIP currently is capable of receiving flash events
and converting them to FLASH control frames, but it
currently lacks support for doing the reverse: taking
a FLASH control frame and converting it into a flash
event in the SIP domain.

This adds the ability for PJSIP to process flash control
frames by converting them into the appropriate SIP INFO
message, which can then be sent to the peer. This allows,
for example, flash events to be sent between Asterisk
systems using PJSIP.

ASTERISK-29941 #close

Change-Id: I1590221a4d238597f79672fa5825dd4a920c94dd
  • Loading branch information
InterLinked1 authored and Friendly Automation committed Apr 26, 2022
1 parent 92d408f commit 193b7a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions channels/chan_pjsip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,10 @@ static int handle_topology_request_change(struct ast_sip_session *session,
SCOPE_EXIT_RTN_VALUE(res, "RC: %d\n", res);
}

/* Forward declarations */
static int transmit_info_dtmf(void *data);
static struct info_dtmf_data *info_dtmf_data_alloc(struct ast_sip_session *session, char digit, unsigned int duration);

/*! \brief Function called by core to ask the channel to indicate some sort of condition */
static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
{
Expand All @@ -1621,6 +1625,10 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi
.data.ptr = (void *)data,
};
char condition_name[256];
unsigned int duration;
char digit;
struct info_dtmf_data *dtmf_data;

SCOPE_ENTER(3, "%s: Indicated %s\n", ast_channel_name(ast),
ast_frame_subclass2str(&f, condition_name, sizeof(condition_name), NULL, 0));

Expand Down Expand Up @@ -1680,6 +1688,22 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi
}
ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "PJSIP/%s", ast_sorcery_object_get_id(channel->session->endpoint));
break;
case AST_CONTROL_FLASH:
duration = 300;
digit = '!';
dtmf_data = info_dtmf_data_alloc(channel->session, digit, duration);

if (!dtmf_data) {
res = -1;
break;
}

if (ast_sip_push_task(channel->session->serializer, transmit_info_dtmf, dtmf_data)) {
ast_log(LOG_WARNING, "Error sending FLASH via INFO on channel %s\n", ast_channel_name(ast));
ao2_ref(dtmf_data, -1); /* dtmf_data can't be null here */
res = -1;
}
break;
case AST_CONTROL_VIDUPDATE:
for (i = 0; i < AST_VECTOR_SIZE(&channel->session->active_media_state->sessions); ++i) {
media = AST_VECTOR_GET(&channel->session->active_media_state->sessions, i);
Expand Down
4 changes: 4 additions & 0 deletions doc/CHANGES-staging/chan_pjsip_flash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Subject: chan_pjsip

Hook flash events can now be sent on a PJSIP channel
if requested to do so.

0 comments on commit 193b7a8

Please sign in to comment.