[asterisk-commits] file: branch file/ah r59250 - in /team/file/ah: funcs/ include/asterisk/ main/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Mar 26 20:59:44 MST 2007


Author: file
Date: Mon Mar 26 22:59:43 2007
New Revision: 59250

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59250
Log:
Allow DTMF to be passed through to manipulators. VOLUME() now looks for * and # DTMF keys and either increases the volume or decreases the volume.

Modified:
    team/file/ah/funcs/func_volume.c
    team/file/ah/include/asterisk/audiohook.h
    team/file/ah/main/audiohook.c
    team/file/ah/main/channel.c

Modified: team/file/ah/funcs/func_volume.c
URL: http://svn.digium.com/view/asterisk/team/file/ah/funcs/func_volume.c?view=diff&rev=59250&r1=59249&r2=59250
==============================================================================
--- team/file/ah/funcs/func_volume.c (original)
+++ team/file/ah/funcs/func_volume.c Mon Mar 26 22:59:43 2007
@@ -78,12 +78,25 @@
 
 	vi = datastore->data;
 
-	/* Based on direction of frame grab the gain, and confirm it is applicable */
-	if (!(gain = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? &vi->rx_gain : &vi->tx_gain) || !*gain)
-		return 0;
-
-	/* Apply gain to frame... easy as pi */
-	ast_frame_adjust_volume(frame, *gain);
+	/* If this is DTMF then allow them to increase/decrease the gains */
+	if (frame->frametype == AST_FRAME_DTMF) {
+		/* Only use DTMF coming from the source... not going to it */
+		if (direction != AST_AUDIOHOOK_DIRECTION_READ)
+			return 0;
+		if (frame->subclass == '*') {
+			vi->tx_gain += 1;
+			vi->rx_gain += 1;
+		} else if (frame->subclass == '#') {
+			vi->tx_gain -= 1;
+			vi->rx_gain -= 1;
+		}
+	} else if (frame->frametype == AST_FRAME_VOICE) {
+		/* Based on direction of frame grab the gain, and confirm it is applicable */
+		if (!(gain = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? &vi->rx_gain : &vi->tx_gain) || !*gain)
+			return 0;
+		/* Apply gain to frame... easy as pi */
+		ast_frame_adjust_volume(frame, *gain);
+	}
 
 	return 0;
 }
@@ -104,6 +117,7 @@
 		}
 		ast_audiohook_init(&vi->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "Volume");
 		vi->audiohook.manipulate_callback = volume_callback;
+		ast_set_flag(&vi->audiohook, AST_AUDIOHOOK_WANTS_DTMF);
 		is_new = 1;
 	} else {
 		vi = datastore->data;

Modified: team/file/ah/include/asterisk/audiohook.h
URL: http://svn.digium.com/view/asterisk/team/file/ah/include/asterisk/audiohook.h?view=diff&rev=59250&r1=59249&r2=59250
==============================================================================
--- team/file/ah/include/asterisk/audiohook.h (original)
+++ team/file/ah/include/asterisk/audiohook.h Mon Mar 26 22:59:43 2007
@@ -52,6 +52,7 @@
 	AST_AUDIOHOOK_TRIGGER_MODE = (3 << 0),
 	AST_AUDIOHOOK_TRIGGER_READ = (1 << 0),
 	AST_AUDIOHOOK_TRIGGER_WRITE = (2 << 0),
+	AST_AUDIOHOOK_WANTS_DTMF = (1 << 1),
 };
 
 struct ast_audiohook;

Modified: team/file/ah/main/audiohook.c
URL: http://svn.digium.com/view/asterisk/team/file/ah/main/audiohook.c?view=diff&rev=59250&r1=59249&r2=59250
==============================================================================
--- team/file/ah/main/audiohook.c (original)
+++ team/file/ah/main/audiohook.c Mon Mar 26 22:59:43 2007
@@ -358,14 +358,43 @@
 	return 0;
 }
 
-/*! \brief Pass a frame off to be handled by the audiohook core
+/*! \brief Pass a DTMF frame off to be handled by the audiohook core
  * \param chan Channel that the list is coming off of
  * \param audiohook_list List of audiohooks
  * \param direction Direction frame is coming in from
  * \param frame The frame itself
  * \return Return frame on success, NULL on failure
  */
-struct ast_frame *ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
+static struct ast_frame *dtmf_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
+{
+	struct ast_audiohook *audiohook = NULL;
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&audiohook_list->manipulate_list, audiohook, list) {
+		ast_audiohook_lock(audiohook);
+		if (audiohook->status != AST_AUDIOHOOK_STATUS_RUNNING) {
+			AST_LIST_REMOVE_CURRENT(&audiohook_list->manipulate_list, list);
+			audiohook->status = AST_AUDIOHOOK_STATUS_DONE;
+			ast_audiohook_unlock(audiohook);
+			audiohook->manipulate_callback(audiohook, NULL, NULL, 0);
+			continue;
+		}
+		if (ast_test_flag(audiohook, AST_AUDIOHOOK_WANTS_DTMF))
+			audiohook->manipulate_callback(audiohook, chan, frame, direction);
+		ast_audiohook_unlock(audiohook);
+	}
+	AST_LIST_TRAVERSE_SAFE_END
+
+	return frame;
+}
+
+/*! \brief Pass an AUDIO frame off to be handled by the audiohook core
+ * \param chan Channel that the list is coming off of
+ * \param audiohook_list List of audiohooks
+ * \param direction Direction frame is coming in from
+ * \param frame The frame itself
+ * \return Return frame on success, NULL on failure
+ */
+static struct ast_frame *audio_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
 {
 	struct ast_audiohook_translate *in_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->in_translate[0] : &audiohook_list->in_translate[1]);
 	struct ast_audiohook_translate *out_translate = (direction == AST_AUDIOHOOK_DIRECTION_READ ? &audiohook_list->out_translate[0] : &audiohook_list->out_translate[1]);
@@ -482,6 +511,25 @@
 	return end_frame;
 }
 
+/*! \brief Pass a frame off to be handled by the audiohook core
+ * \param chan Channel that the list is coming off of
+ * \param audiohook_list List of audiohooks
+ * \param direction Direction frame is coming in from
+ * \param frame The frame itself
+ * \return Return frame on success, NULL on failure
+ */
+struct ast_frame *ast_audiohook_write_list(struct ast_channel *chan, struct ast_audiohook_list *audiohook_list, enum ast_audiohook_direction direction, struct ast_frame *frame)
+{
+	/* Pass off frame to it's respective list write function */
+	if (frame->frametype == AST_FRAME_VOICE)
+		return audio_audiohook_write_list(chan, audiohook_list, direction, frame);
+	else if (frame->frametype == AST_FRAME_DTMF)
+		return dtmf_audiohook_write_list(chan, audiohook_list, direction, frame);
+	else
+		return frame;
+}
+			
+
 /*! \brief Wait for audiohook trigger to be triggered
  * \param audiohook Audiohook to wait on
  */

Modified: team/file/ah/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/ah/main/channel.c?view=diff&rev=59250&r1=59249&r2=59250
==============================================================================
--- team/file/ah/main/channel.c (original)
+++ team/file/ah/main/channel.c Mon Mar 26 22:59:43 2007
@@ -1866,10 +1866,14 @@
 					chan->emulate_dtmf_duration = f->len;
 				else
 					chan->emulate_dtmf_duration = AST_DEFAULT_EMULATE_DTMF_DURATION;
+				if (chan->audiohooks)
+					f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
 			} else {
 				ast_clear_flag(chan, AST_FLAG_IN_DTMF);
 				if (!f->len)
 					f->len = ast_tvdiff_ms(ast_tvnow(), chan->dtmf_begin_tv);
+				if (chan->audiohooks)
+					f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
 			}
 			break;
 		case AST_FRAME_DTMF_BEGIN:
@@ -1901,6 +1905,8 @@
 					f->frametype = AST_FRAME_DTMF_END;
 					f->subclass = chan->emulate_dtmf_digit;
 					f->len = ast_tvdiff_ms(ast_tvnow(), chan->dtmf_begin_tv);
+					if (chan->audiohooks)
+						f = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_READ, f);
 				} else {
 					chan->emulate_dtmf_duration -= f->samples / 8; /* XXX 8kHz */
 					ast_frfree(f);
@@ -2267,6 +2273,8 @@
 			chan->tech->indicate(chan, fr->subclass, fr->data, fr->datalen);
 		break;
 	case AST_FRAME_DTMF_BEGIN:
+		if (chan->audiohooks)
+			fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
 		ast_clear_flag(chan, AST_FLAG_BLOCKING);
 		ast_channel_unlock(chan);
 		res = ast_senddigit_begin(chan, fr->subclass);
@@ -2274,6 +2282,8 @@
 		CHECK_BLOCKING(chan);
 		break;
 	case AST_FRAME_DTMF_END:
+		if (chan->audiohooks)
+			fr = ast_audiohook_write_list(chan, chan->audiohooks, AST_AUDIOHOOK_DIRECTION_WRITE, fr);
 		ast_clear_flag(chan, AST_FLAG_BLOCKING);
 		ast_channel_unlock(chan);
 		res = ast_senddigit_end(chan, fr->subclass, fr->len);



More information about the asterisk-commits mailing list