[Asterisk-code-review] app_mixmonitor: Add AMI events MixMonitorStart, -Stop and -Mute. (asterisk[18])

George Joseph asteriskteam at digium.com
Tue Feb 23 12:15:09 CST 2021


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15479 )

Change subject: app_mixmonitor: Add AMI events MixMonitorStart, -Stop and -Mute.
......................................................................

app_mixmonitor: Add AMI events MixMonitorStart, -Stop and -Mute.

ASTERISK-29244

Change-Id: I1862d58264c2c8b5d8983272cb29734b184d67c5
---
M apps/app_mixmonitor.c
M configs/samples/stasis.conf.sample
A doc/CHANGES-staging/mixmonitor_manager_events.txt
M include/asterisk/stasis_channels.h
M main/manager_channels.c
M main/stasis.c
M main/stasis_channels.c
7 files changed, 175 insertions(+), 1 deletion(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c
index 239901f..374c567 100644
--- a/apps/app_mixmonitor.c
+++ b/apps/app_mixmonitor.c
@@ -51,6 +51,8 @@
 #include "asterisk/channel.h"
 #include "asterisk/autochan.h"
 #include "asterisk/manager.h"
+#include "asterisk/stasis.h"
+#include "asterisk/stasis_channels.h"
 #include "asterisk/callerid.h"
 #include "asterisk/mod_format.h"
 #include "asterisk/linkedlists.h"
@@ -295,6 +297,51 @@
 			</parameter>
 		</syntax>
 	</function>
+	<managerEvent language="en_US" name="MixMonitorStart">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+			<synopsis>Raised when monitoring has started on a channel.</synopsis>
+			<syntax>
+				<channel_snapshot/>
+			</syntax>
+			<see-also>
+				<ref type="managerEvent">MixMonitorStop</ref>
+				<ref type="application">MixMonitor</ref>
+				<ref type="manager">MixMonitor</ref>
+			</see-also>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="MixMonitorStop">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+		<synopsis>Raised when monitoring has stopped on a channel.</synopsis>
+		<syntax>
+			<channel_snapshot/>
+		</syntax>
+		<see-also>
+			<ref type="managerEvent">MixMonitorStart</ref>
+			<ref type="application">StopMixMonitor</ref>
+			<ref type="manager">StopMixMonitor</ref>
+		</see-also>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="MixMonitorMute">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+		<synopsis>Raised when monitoring is muted or unmuted on a channel.</synopsis>
+		<syntax>
+			<channel_snapshot/>
+			<parameter name="Direction">
+				<para>Which part of the recording was muted or unmuted: read, write or both
+				(from channel, to channel or both directions).</para>
+			</parameter>
+			<parameter name="State">
+				<para>If the monitoring was muted or unmuted: 1 when muted, 0 when unmuted.</para>
+			</parameter>
+		</syntax>
+		<see-also>
+			<ref type="manager">MixMonitorMute</ref>
+		</see-also>
+		</managerEventInstance>
+	</managerEvent>
+
 
  ***/
 
@@ -1077,6 +1124,7 @@
 	struct ast_flags flags = { 0 };
 	char *recipients = NULL;
 	char *parse;
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(filename);
 		AST_APP_ARG(options);
@@ -1197,6 +1245,12 @@
 		ast_module_unref(ast_module_info->self);
 	}
 
+	message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
+		ast_channel_mixmonitor_start_type(), NULL);
+	if (message) {
+		stasis_publish(ast_channel_topic(chan), message);
+	}
+
 	return 0;
 }
 
@@ -1206,6 +1260,7 @@
 	char *parse = "";
 	struct mixmonitor_ds *mixmonitor_ds;
 	const char *beep_id = NULL;
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(mixmonid);
@@ -1263,6 +1318,13 @@
 		ast_beep_stop(chan, beep_id);
 	}
 
+	message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan),
+	                                             ast_channel_mixmonitor_stop_type(),
+	                                             NULL);
+	if (message) {
+		stasis_publish(ast_channel_topic(chan), message);
+	}
+
 	return 0;
 }
 
@@ -1350,6 +1412,8 @@
 	const char *direction = astman_get_header(m,"Direction");
 	int clearmute = 1;
 	enum ast_audiohook_flags flag;
+	RAII_VAR(struct stasis_message *, stasis_message, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, stasis_message_blob, NULL, ast_json_unref);
 
 	if (ast_strlen_zero(direction)) {
 		astman_send_error(s, m, "No direction specified. Must be read, write or both");
@@ -1391,6 +1455,17 @@
 		return AMI_SUCCESS;
 	}
 
+	stasis_message_blob = ast_json_pack("{s: s, s: b}",
+		"direction", direction,
+		"state", ast_true(state));
+
+	stasis_message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(c),
+		ast_channel_mixmonitor_mute_type(), stasis_message_blob);
+
+	if (stasis_message) {
+		stasis_publish(ast_channel_topic(c), stasis_message);
+	}
+
 	astman_append(s, "Response: Success\r\n");
 
 	if (!ast_strlen_zero(id)) {
diff --git a/configs/samples/stasis.conf.sample b/configs/samples/stasis.conf.sample
index e591e76..46a240e 100644
--- a/configs/samples/stasis.conf.sample
+++ b/configs/samples/stasis.conf.sample
@@ -63,6 +63,8 @@
 ; decline=ast_channel_moh_stop_type
 ; decline=ast_channel_monitor_start_type
 ; decline=ast_channel_monitor_stop_type
+; decline=ast_channel_mixmonitor_start_type
+; decline=ast_channel_mixmonitor_stop_type
 ; decline=ast_channel_agent_login_type
 ; decline=ast_channel_agent_logoff_type
 ; decline=ast_channel_talking_start
diff --git a/doc/CHANGES-staging/mixmonitor_manager_events.txt b/doc/CHANGES-staging/mixmonitor_manager_events.txt
new file mode 100644
index 0000000..64b63e5
--- /dev/null
+++ b/doc/CHANGES-staging/mixmonitor_manager_events.txt
@@ -0,0 +1,5 @@
+Subject: app_mixmonitor
+
+app_mixmonitor now sends manager events MixMonitorStart, MixMonitorStop and
+MixMonitorMute when the channel monitoring is started, stopped and muted (or
+unmuted) respectively.
diff --git a/include/asterisk/stasis_channels.h b/include/asterisk/stasis_channels.h
index 9c47984..02654e9 100644
--- a/include/asterisk/stasis_channels.h
+++ b/include/asterisk/stasis_channels.h
@@ -590,7 +590,31 @@
 struct stasis_message_type *ast_channel_monitor_stop_type(void);
 
 /*!
- * \since 12.0.0
+ * \since 18
+ * \brief Message type for starting mixmonitor on a channel
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_mixmonitor_start_type(void);
+
+/*!
+ * \since 18
+ * \brief Message type for stopping mixmonitor on a channel
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_mixmonitor_stop_type(void);
+
+/*!
+ * \since 18
+ * \brief Message type for muting or unmuting mixmonitor on a channel
+ *
+ * \retval A stasis message type
+ */
+struct stasis_message_type *ast_channel_mixmonitor_mute_type(void);
+
+/*!
+ * \since 18.0.0
  * \brief Message type for agent login on a channel
  *
  * \retval A stasis message type
diff --git a/main/manager_channels.c b/main/manager_channels.c
index 73b76c8..7f40efe 100644
--- a/main/manager_channels.c
+++ b/main/manager_channels.c
@@ -1116,6 +1116,53 @@
 	publish_basic_channel_event("MonitorStop", EVENT_FLAG_CALL, payload->snapshot);
 }
 
+static void channel_mixmonitor_start_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_message *message)
+{
+	struct ast_channel_blob *payload = stasis_message_data(message);
+
+	publish_basic_channel_event("MixMonitorStart", EVENT_FLAG_CALL, payload->snapshot);
+}
+
+static void channel_mixmonitor_stop_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_message *message)
+{
+	struct ast_channel_blob *payload = stasis_message_data(message);
+
+	publish_basic_channel_event("MixMonitorStop", EVENT_FLAG_CALL, payload->snapshot);
+}
+
+static void channel_mixmonitor_mute_cb(void *data, struct stasis_subscription *sub,
+		struct stasis_message *message)
+{
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	RAII_VAR(struct ast_str *, event_buffer, ast_str_create(64), ast_free);
+	struct ast_channel_blob *payload = stasis_message_data(message);
+	struct ast_json *direction = ast_json_object_get(payload->blob, "direction");
+	const int state = ast_json_is_true(ast_json_object_get(payload->blob, "state"));
+
+	if (!event_buffer) {
+		return;
+	}
+
+	channel_event_string = ast_manager_build_channel_state_string(payload->snapshot);
+	if (!channel_event_string) {
+		return;
+	}
+
+	if (direction) {
+		ast_str_append(&event_buffer, 0, "Direction: %s\r\n", ast_json_string_get(direction));
+	}
+	ast_str_append(&event_buffer, 0, "State: %s\r\n", state ? "1" : "0");
+
+	manager_event(EVENT_FLAG_CALL, "MixMonitorMute",
+		"%s"
+		"%s",
+		ast_str_buffer(channel_event_string),
+		ast_str_buffer(event_buffer));
+
+}
+
 static int dial_status_end(const char *dialstatus)
 {
 	return (strcmp(dialstatus, "RINGING") &&
@@ -1320,6 +1367,15 @@
 	ret |= stasis_message_router_add(message_router,
 		ast_channel_monitor_stop_type(), channel_monitor_stop_cb, NULL);
 
+	ret |= stasis_message_router_add(message_router,
+		ast_channel_mixmonitor_start_type(), channel_mixmonitor_start_cb, NULL);
+
+	ret |= stasis_message_router_add(message_router,
+		ast_channel_mixmonitor_stop_type(), channel_mixmonitor_stop_cb, NULL);
+
+	ret |= stasis_message_router_add(message_router,
+		ast_channel_mixmonitor_mute_type(), channel_mixmonitor_mute_cb, NULL);
+
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.
 	 */
diff --git a/main/stasis.c b/main/stasis.c
index 44d5973..4ae6d6a 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -130,6 +130,9 @@
 							<enum name="ast_channel_moh_stop_type" />
 							<enum name="ast_channel_monitor_start_type" />
 							<enum name="ast_channel_monitor_stop_type" />
+							<enum name="ast_channel_mixmonitor_start_type" />
+							<enum name="ast_channel_mixmonitor_stop_type" />
+							<enum name="ast_channel_mixmonitor_mute_type" />
 							<enum name="ast_channel_agent_login_type" />
 							<enum name="ast_channel_agent_logoff_type" />
 							<enum name="ast_channel_talking_start" />
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index 3d213c7..3f3312b 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -1606,6 +1606,9 @@
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_stop_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_start_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_stop_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_mixmonitor_start_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_mixmonitor_stop_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_mixmonitor_mute_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_agent_login_type,
 	.to_ami = agent_login_to_ami,
 	);
@@ -1649,6 +1652,9 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_moh_stop_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_start_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_stop_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_mixmonitor_start_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_mixmonitor_stop_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_mixmonitor_mute_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_agent_login_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_agent_logoff_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_talking_start);
@@ -1699,6 +1705,9 @@
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_stop_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_start_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_stop_type);
+	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_mixmonitor_start_type);
+	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_mixmonitor_stop_type);
+	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_mixmonitor_mute_type);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_talking_start);
 	res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_talking_stop);
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15479
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I1862d58264c2c8b5d8983272cb29734b184d67c5
Gerrit-Change-Number: 15479
Gerrit-PatchSet: 2
Gerrit-Owner: Sébastien Duthil <sduthil at wazo.community>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210223/6fb2f975/attachment-0001.html>


More information about the asterisk-code-review mailing list