[asterisk-commits] file: branch file/bridging r99380 - in /team/file/bridging: include/asterisk/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 10:39:41 CST 2008


Author: file
Date: Mon Jan 21 13:57:48 2008
New Revision: 99380

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99380
Log:
Add an ast_bridge_dtmf_stream API call. This essentially streams a DTMF string to channels in a bridge.

Modified:
    team/file/bridging/include/asterisk/bridging.h
    team/file/bridging/main/bridging.c

Change Statistics:
 team/file/bridging/include/asterisk/bridging.h |   10 ++
 team/file/bridging/main/bridging.c             |   57 +++++++++++++
 2 files changed, 67 insertions(+)

Modified: team/file/bridging/include/asterisk/bridging.h
URL: http://svn.digium.com/view/asterisk/team/file/bridging/include/asterisk/bridging.h?view=diff&rev=99380&r1=99379&r2=99380
==============================================================================
--- team/file/bridging/include/asterisk/bridging.h (original)
+++ team/file/bridging/include/asterisk/bridging.h Mon Jan 21 13:57:48 2008
@@ -52,6 +52,7 @@
 	AST_BRIDGE_CHANNEL_STATE_SWAP,     /*! Channel is being swapped out */
 	AST_BRIDGE_CHANNEL_STATE_FEATURE,  /*! Channel is currently executing a feature */
 	AST_BRIDGE_CHANNEL_STATE_MERGE,    /*! Channel is part of a bridge merge operation */
+	AST_BRIDGE_CHANNEL_STATE_DTMF,     /*! A DTMF stream is playing/to be played on this channel */
 };
 
 /*! \brief Flags used for bridge features */
@@ -122,6 +123,7 @@
 	int suspended:1;                         /*! Is this bridged channel suspended from the bridge or not? */
 	int muted:1;                             /*! Is this bridged channel muted or not? */
 	struct ast_bridge_features *features;    /*! Enabled features information */
+	char dtmf_stream_q[8];                   /*! DTMF stream queue */
 	AST_LIST_ENTRY(ast_bridge_channel) list; /*! Linked list information */
 };
 
@@ -246,6 +248,14 @@
  */
 int ast_bridge_features_cleanup(struct ast_bridge_features *features);
 
+/*! \brief Play a DTMF stream into a bridge, optionally not to a given channel
+ * \param bridge Bridge to play stream into
+ * \param dtmf DTMF to play
+ * \param chan Channel to optionally not play to
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_dtmf_stream(struct ast_bridge *bridge, const char *dtmf, struct ast_channel *chan);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/file/bridging/main/bridging.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/main/bridging.c?view=diff&rev=99380&r1=99379&r2=99380
==============================================================================
--- team/file/bridging/main/bridging.c (original)
+++ team/file/bridging/main/bridging.c Mon Jan 21 13:57:48 2008
@@ -42,6 +42,7 @@
 #include "asterisk/lock.h"
 #include "asterisk/linkedlists.h"
 #include "asterisk/bridging.h"
+#include "asterisk/app.h"
 
 static AST_RWLIST_HEAD_STATIC(bridge_technologies, ast_bridge_technology);
 
@@ -612,6 +613,9 @@
 		} else if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_FEATURE) {
 			ast_debug(1, "Bridge channel %p entering feature state.\n", bridge_channel);
 			break;
+		} else if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_DTMF) {
+			ast_debug(1, "Bridge channel %p entering DTMF stream state.\n", bridge_channel);
+			break;
 		}
 	}
 
@@ -621,6 +625,25 @@
 /*! \brief Internal function that executes a feature on a bridge channel */
 static void bridge_channel_feature(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
 {
+	return;
+}
+
+/*! \brief Internal function that plays back DTMF on a bridge channel */
+static void bridge_channel_dtmf_stream(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
+{
+	char dtmf_q[8] = "";
+
+	ast_copy_string(dtmf_q, bridge_channel->dtmf_stream_q, sizeof(dtmf_q));
+	bridge_channel->dtmf_stream_q[0] = '\0';
+
+	ast_mutex_unlock(&bridge->lock);
+
+	ast_debug(1, "Playing DTMF stream '%s' out to bridge channel %p\n", dtmf_q, bridge_channel);
+	ast_dtmf_stream(bridge_channel->chan, NULL, dtmf_q, 250, 0);
+
+	ast_mutex_lock(&bridge->lock);
+	bridge_channel->state = AST_BRIDGE_CHANNEL_STATE_WAIT;
+
 	return;
 }
 
@@ -686,6 +709,9 @@
 		} else if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_FEATURE) {
 			bridge_channel_feature(bridge, bridge_channel);
 			/* Just in case... tell the bridge thread to rebuild */
+			ast_bridge_rebuild(bridge);
+		} else if (bridge_channel->state == AST_BRIDGE_CHANNEL_STATE_DTMF) {
+			bridge_channel_dtmf_stream(bridge, bridge_channel);
 			ast_bridge_rebuild(bridge);
 		}
 	}
@@ -993,6 +1019,10 @@
 	/* Right now this is simple... just set an integer */
 	bridge->rebuild = 1;
 
+	/* Poke the thread just in case */
+	if (bridge->thread != AST_PTHREADT_NULL && bridge->thread != AST_PTHREADT_STOP)
+		pthread_kill(bridge->thread, SIGURG);
+
 	return ast_cond_signal(&bridge->cond);
 }
 
@@ -1217,3 +1247,30 @@
 
 	return 0;
 }
+
+/*! \brief Play a DTMF stream into a bridge, optionally not to a given channel
+ * \param bridge Bridge to play stream into
+ * \param dtmf DTMF to play
+ * \param chan Channel to optionally not play to
+ * \return Returns 0 on success, -1 on failure
+ */
+int ast_bridge_dtmf_stream(struct ast_bridge *bridge, const char *dtmf, struct ast_channel *chan)
+{
+	struct ast_bridge_channel *bridge_channel = NULL;
+
+	ast_mutex_lock(&bridge->lock);
+
+	/* Trigger a rebuild now just in case */
+	ast_bridge_rebuild(bridge);
+
+	AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, list) {
+		if (bridge_channel->chan == chan)
+			continue;
+		ast_copy_string(bridge_channel->dtmf_stream_q, dtmf, sizeof(bridge_channel->dtmf_stream_q));
+		ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_DTMF);
+	}
+
+	ast_mutex_unlock(&bridge->lock);
+
+	return 0;
+}




More information about the asterisk-commits mailing list