summaryrefslogtreecommitdiff
path: root/main/bridge_channel.c
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2017-09-27 10:44:53 -0600
committerGeorge Joseph <gjoseph@digium.com>2018-04-17 10:30:23 -0600
commit4fb7967c7327fd73a93c587f3eca0564201be049 (patch)
tree0fb763353f2152e6f524f259e8f517685f3e7a9e /main/bridge_channel.c
parent38dae51b788cd7f9f69c88573d6ce769c80f07f0 (diff)
bridge_softmix: Forward TEXT frames
Core bridging and, more specifically, bridge_softmix have been enhanced to relay received frames of type TEXT or TEXT_DATA to all participants in a softmix bridge. res_pjsip_messaging and chan_pjsip have been enhanced to take advantage of this so when res_pjsip_messaging receives an in-dialog MESSAGE message from a user in a conference call, it's relayed to all other participants in the call. res_pjsip_messaging already queues TEXT frames to the channel when it receives an in-dialog MESSAGE from an endpoint and chan_pjsip will send an MESSAGE when it gets a TEXT frame. On a normal point-to-point call, the frames are forwarded between the two correctly. bridge_softmix was not though so messages weren't getting forwarded to conference bridge participants. Even if they were, the bridging code had no way to tell the participants who sent the message so it would look like it came from the bridge itself. * The TEXT frame type doesn't allow storage of any meta data, such as sender, on the frame so a new TEXT_DATA frame type was added that uses the new ast_msg_data structure as its payload. A channel driver can queue a frame of that type when it receives a message from outside. A channel driver can use it for sending messages by implementing the new send_text_data channel tech callback and setting the new AST_CHAN_TP_SEND_TEXT_DATA flag in its tech properties. If set, the bridging/channel core will use it instead of the original send_text callback and it will get the ast_msg_data structure. Channel drivers aren't required to implement this. Even if a TEXT_DATA enabled driver uses it for incoming messages, an outgoing channel driver that doesn't will still have it's send_text callback called with only the message text just as before. * res_pjsip_messaging now creates a TEXT_DATA frame for incoming in-dialog messages and sets the "from" to the display name in the "From" header, or if that's empty, the caller id name from the channel. This allows the chat client user to set a friendly name for the chat. * bridge_softmix now forwards TEXT and TEXT_DATA frames to all participants (except the sender). * A new function "ast_sendtext_data" was added to channel which takes an ast_msg_data structure and calls a channel's send_text_data callback, or if that's not defined, the original send_text callback. * bridge_channel now calls ast_sendtext_data for TEXT_DATA frame types and ast_sendtext for TEXT frame types. * chan_pjsip now uses the "from" name in the ast_msg_data structure (if it exists) to set the "From" header display name on outgoing text messages. Change-Id: Idacf5900bfd5f22ab8cd235aa56dfad090d18489
Diffstat (limited to 'main/bridge_channel.c')
-rw-r--r--main/bridge_channel.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/main/bridge_channel.c b/main/bridge_channel.c
index 3aac5eb25..eb4b9ad0e 100644
--- a/main/bridge_channel.c
+++ b/main/bridge_channel.c
@@ -56,6 +56,7 @@
#include "asterisk/test.h"
#include "asterisk/sem.h"
#include "asterisk/stream.h"
+#include "asterisk/message.h"
/*!
* \brief Used to queue an action frame onto a bridge channel and write an action frame into a bridge.
@@ -1055,6 +1056,20 @@ int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, st
return 0;
}
+ if (DEBUG_ATLEAST(1)) {
+ if (fr->frametype == AST_FRAME_TEXT) {
+ ast_log(LOG_DEBUG, "Queuing TEXT frame to '%s': %*.s\n", ast_channel_name(bridge_channel->chan),
+ fr->datalen, (char *)fr->data.ptr);
+ } else if (fr->frametype == AST_FRAME_TEXT_DATA) {
+ struct ast_msg_data *msg = fr->data.ptr;
+ ast_log(LOG_DEBUG, "Queueing TEXT_DATA frame from '%s' to '%s:%s': %s\n",
+ ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_FROM),
+ ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_TO),
+ ast_channel_name(bridge_channel->chan),
+ ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_BODY));
+ }
+ }
+
AST_LIST_INSERT_TAIL(&bridge_channel->wr_queue, dup, frame_list);
if (ast_alertpipe_write(bridge_channel->alert_pipe)) {
ast_log(LOG_ERROR, "We couldn't write alert pipe for %p(%s)... something is VERY wrong\n",
@@ -2349,6 +2364,7 @@ static void bridge_channel_handle_write(struct ast_bridge_channel *bridge_channe
struct ast_frame *fr;
struct sync_payload *sync_payload;
int num;
+ struct ast_msg_data *msg;
ast_bridge_channel_lock(bridge_channel);
@@ -2381,6 +2397,7 @@ static void bridge_channel_handle_write(struct ast_bridge_channel *bridge_channe
AST_LIST_TRAVERSE_SAFE_END;
ast_bridge_channel_unlock(bridge_channel);
+
if (!fr) {
/*
* Wait some to reduce CPU usage from a tight loop
@@ -2404,6 +2421,20 @@ static void bridge_channel_handle_write(struct ast_bridge_channel *bridge_channe
break;
case AST_FRAME_NULL:
break;
+ case AST_FRAME_TEXT:
+ ast_debug(1, "Sending TEXT frame to '%s': %*.s\n",
+ ast_channel_name(bridge_channel->chan), fr->datalen, (char *)fr->data.ptr);
+ ast_sendtext(bridge_channel->chan, fr->data.ptr);
+ break;
+ case AST_FRAME_TEXT_DATA:
+ msg = (struct ast_msg_data *)fr->data.ptr;
+ ast_debug(1, "Sending TEXT_DATA frame from '%s' to '%s:%s': %s\n",
+ ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_FROM),
+ ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_TO),
+ ast_channel_name(bridge_channel->chan),
+ ast_msg_data_get_attribute(msg, AST_MSG_DATA_ATTR_BODY));
+ ast_sendtext_data(bridge_channel->chan, msg);
+ break;
default:
/* Assume that there is no mapped stream for this */
num = -1;