[svn-commits] dlee: branch dlee/stasis-dtmf r385542 - in /team/dlee/stasis-dtmf: apps/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Apr 12 16:30:37 CDT 2013


Author: dlee
Date: Fri Apr 12 16:30:33 2013
New Revision: 385542

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385542
Log:
Brought in line with AMI 1.4 spec.

* Send seperate DTMFBegin and DTMFEnd events.
  * Refactored the underlying stasis messages to be dtmf_begin and dtmf_end
    as well

Modified:
    team/dlee/stasis-dtmf/apps/app_stasis.c
    team/dlee/stasis-dtmf/main/channel.c
    team/dlee/stasis-dtmf/main/manager_channels.c

Modified: team/dlee/stasis-dtmf/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-dtmf/apps/app_stasis.c?view=diff&rev=385542&r1=385541&r2=385542
==============================================================================
--- team/dlee/stasis-dtmf/apps/app_stasis.c (original)
+++ team/dlee/stasis-dtmf/apps/app_stasis.c Fri Apr 12 16:30:33 2013
@@ -364,12 +364,7 @@
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 	const char *direction;
 
-	/* To simplify events, we'll only generate on DTMF end */
-	if (ast_json_is_false(ast_json_object_get(obj->blob, "end"))) {
-		return;
-	}
-
-	/* And only on receive */
+	/* To simplify events, we'll only generate on receive */
 	direction = ast_json_string_get(
 		ast_json_object_get(obj->blob, "direction"));
 
@@ -394,7 +389,8 @@
 
 static void blob_handler(struct app *app, struct ast_channel_blob *blob)
 {
-	if (strcmp(ast_channel_blob_json_type(blob), "dtmf") == 0) {
+	/* To simplify events, we'll only generate on DTMF end */
+	if (strcmp(ast_channel_blob_json_type(blob), "dtmf_end") == 0) {
 		dtmf_handler(app, blob);
 	}
 }

Modified: team/dlee/stasis-dtmf/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-dtmf/main/channel.c?view=diff&rev=385542&r1=385541&r2=385542
==============================================================================
--- team/dlee/stasis-dtmf/main/channel.c (original)
+++ team/dlee/stasis-dtmf/main/channel.c Fri Apr 12 16:30:33 2013
@@ -3731,19 +3731,34 @@
 	return "?";
 }
 
-static void send_dtmf_event(struct ast_channel *chan,
-			    enum DtmfDirection direction, const char digit,
-			    int begin, int end)
+static void send_dtmf_begin_event(struct ast_channel *chan,
+	enum DtmfDirection direction, const char digit)
 {
 	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
 	char digit_str[] = { digit, '\0' };
 
-	blob = ast_json_pack("{ s: s, s: s, s: s, s: b, s: b }",
-			     "type", "dtmf",
-			     "digit", digit_str,
-			     "direction", dtmf_direction_to_string(direction),
-			     "begin", begin,
-			     "end", end);
+	blob = ast_json_pack("{ s: s, s: s, s: s }",
+		"type", "dtmf_begin",
+		"digit", digit_str,
+		"direction", dtmf_direction_to_string(direction));
+	if (!blob) {
+		return;
+	}
+
+	publish_channel_blob(chan, blob);
+}
+
+static void send_dtmf_end_event(struct ast_channel *chan,
+	enum DtmfDirection direction, const char digit, long duration_ms)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	char digit_str[] = { digit, '\0' };
+
+	blob = ast_json_pack("{ s: s, s: s, s: s, s: i }",
+		"type", "dtmf_end",
+		"digit", digit_str,
+		"direction", dtmf_direction_to_string(direction),
+		"duration_ms", duration_ms);
 	if (!blob) {
 		return;
 	}
@@ -4103,7 +4118,7 @@
 			}
 			break;
 		case AST_FRAME_DTMF_END:
-			send_dtmf_event(chan, DTMF_RECEIVED, f->subclass.integer, 0, 1);
+			send_dtmf_end_event(chan, DTMF_RECEIVED, f->subclass.integer, f->len);
 			ast_log(LOG_DTMF, "DTMF end '%c' received on %s, duration %ld ms\n", f->subclass.integer, ast_channel_name(chan), f->len);
 			/* Queue it up if DTMF is deferred, or if DTMF emulation is forced. */
 			if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF) || ast_test_flag(ast_channel_flags(chan), AST_FLAG_EMULATE_DTMF)) {
@@ -4189,7 +4204,7 @@
 			}
 			break;
 		case AST_FRAME_DTMF_BEGIN:
-			send_dtmf_event(chan, DTMF_RECEIVED, f->subclass.integer, 1, 0);
+			send_dtmf_begin_event(chan, DTMF_RECEIVED, f->subclass.integer);
 			ast_log(LOG_DTMF, "DTMF begin '%c' received on %s\n", f->subclass.integer, ast_channel_name(chan));
 			if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_DEFER_DTMF | AST_FLAG_END_DTMF_ONLY | AST_FLAG_EMULATE_DTMF) ||
 			    (!ast_tvzero(*ast_channel_dtmf_tv(chan)) &&
@@ -5041,7 +5056,7 @@
 			if (old_frame != fr)
 				f = fr;
 		}
-		send_dtmf_event(chan, DTMF_SENT, fr->subclass.integer, 1, 0);
+		send_dtmf_begin_event(chan, DTMF_SENT, fr->subclass.integer);
 		ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
 		ast_channel_unlock(chan);
 		res = ast_senddigit_begin(chan, fr->subclass.integer);
@@ -5057,7 +5072,7 @@
 				ast_frfree(new_frame);
 			}
 		}
-		send_dtmf_event(chan, DTMF_SENT, fr->subclass.integer, 0, 1);
+		send_dtmf_end_event(chan, DTMF_SENT, fr->subclass.integer, fr->len);
 		ast_clear_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING);
 		ast_channel_unlock(chan);
 		res = ast_senddigit_end(chan, fr->subclass.integer, fr->len);

Modified: team/dlee/stasis-dtmf/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-dtmf/main/manager_channels.c?view=diff&rev=385542&r1=385541&r2=385542
==============================================================================
--- team/dlee/stasis-dtmf/main/manager_channels.c (original)
+++ team/dlee/stasis-dtmf/main/manager_channels.c Fri Apr 12 16:30:33 2013
@@ -678,15 +678,13 @@
 		      ast_str_buffer(extra));
 }
 
-static void channel_dtmf(struct ast_channel_blob *obj)
+static void channel_dtmf_begin(struct ast_channel_blob *obj)
 {
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *digit =
 		ast_json_string_get(ast_json_object_get(obj->blob, "digit"));
 	const char *direction =
 		ast_json_string_get(ast_json_object_get(obj->blob, "direction"));
-	int begin = ast_json_is_true(ast_json_object_get(obj->blob, "begin"));
-	int end = ast_json_is_true(ast_json_object_get(obj->blob, "end"));
 
 	channel_event_string = manager_build_channel_state_string(obj->snapshot);
 
@@ -696,7 +694,7 @@
 
 	/*** DOCUMENTATION
 		<managerEventInstance>
-			<synopsis>Raised when a DTMF digit has started or ended on a channel.</synopsis>
+			<synopsis>Raised when a DTMF digit has started on a channel.</synopsis>
 				<syntax>
 					<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
 					<parameter name="Digit">
@@ -708,29 +706,60 @@
 							<enum name="Sent"/>
 						</enumlist>
 					</parameter>
-					<parameter name="Begin">
+				</syntax>
+		</managerEventInstance>
+	***/
+	manager_event(EVENT_FLAG_DTMF, "DTMFBegin",
+		"%s"
+		"Digit: %s\r\n"
+		"Direction: %s\r\n",
+		ast_str_buffer(channel_event_string),
+		digit, direction);
+}
+
+static void channel_dtmf_end(struct ast_channel_blob *obj)
+{
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	const char *digit =
+		ast_json_string_get(ast_json_object_get(obj->blob, "digit"));
+	const char *direction =
+		ast_json_string_get(ast_json_object_get(obj->blob, "direction"));
+	long duration_ms =
+		ast_json_integer_get(ast_json_object_get(obj->blob, "duration_ms"));
+
+	channel_event_string = manager_build_channel_state_string(obj->snapshot);
+
+	if (!channel_event_string) {
+		return;
+	}
+
+	/*** DOCUMENTATION
+		<managerEventInstance>
+			<synopsis>Raised when a DTMF digit has ended on a channel.</synopsis>
+				<syntax>
+					<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+					<parameter name="Digit">
+						<para>DTMF digit received or transmitted (0-9, A-E, # or *</para>
+					</parameter>
+					<parameter name="DurationMs">
+						<para>Duration (in milliseconds) DTMF was sent/received</para>
+					</parameter>
+					<parameter name="Direction">
 						<enumlist>
-							<enum name="Yes"/>
-							<enum name="No"/>
-						</enumlist>
-					</parameter>
-					<parameter name="End">
-						<enumlist>
-							<enum name="Yes"/>
-							<enum name="No"/>
+							<enum name="Received"/>
+							<enum name="Sent"/>
 						</enumlist>
 					</parameter>
 				</syntax>
 		</managerEventInstance>
 	***/
-	manager_event(EVENT_FLAG_DTMF, "DTMF",
-		      "%s"
-		      "Digit: %s\r\n"
-		      "Direction: %s\r\n"
-		      "Begin: %s\r\n"
-		      "End: %s\r\n",
-		      ast_str_buffer(channel_event_string),
-		      digit, direction, AST_YESNO(begin), AST_YESNO(end));
+	manager_event(EVENT_FLAG_DTMF, "DTMFEnd",
+		"%s"
+		"Digit: %s\r\n"
+		"DurationMs: %ld\r\n"
+		"Direction: %s\r\n",
+		ast_str_buffer(channel_event_string),
+		digit, duration_ms, direction);
 }
 
 /*!
@@ -748,8 +777,10 @@
 		channel_userevent(obj);
 	} else if (strcmp("hangup_request", ast_channel_blob_json_type(obj)) == 0) {
 		channel_hangup_request(obj);
-	} else if (strcmp("dtmf", ast_channel_blob_json_type(obj)) == 0) {
-		channel_dtmf(obj);
+	} else if (strcmp("dtmf_begin", ast_channel_blob_json_type(obj)) == 0) {
+		channel_dtmf_begin(obj);
+	} else if (strcmp("dtmf_end", ast_channel_blob_json_type(obj)) == 0) {
+		channel_dtmf_end(obj);
 	}
 }
 




More information about the svn-commits mailing list