[asterisk-commits] qwell: branch qwell/ari_channel_mute r393325 - in /team/qwell/ari_channel_mut...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 1 13:01:32 CDT 2013


Author: qwell
Date: Mon Jul  1 13:01:30 2013
New Revision: 393325

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393325
Log:
Commit progress, so things can be moved around.

Modified:
    team/qwell/ari_channel_mute/include/asterisk/stasis_app.h
    team/qwell/ari_channel_mute/res/stasis/control.c
    team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c

Modified: team/qwell/ari_channel_mute/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/include/asterisk/stasis_app.h?view=diff&rev=393325&r1=393324&r2=393325
==============================================================================
--- team/qwell/ari_channel_mute/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_mute/include/asterisk/stasis_app.h Mon Jul  1 13:01:30 2013
@@ -151,6 +151,24 @@
  */
 int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority);
 
+enum stasis_mute_direction {
+	STASIS_MUTE_IN,
+	STASIS_MUTE_OUT,
+	STASIS_MUTE_BOTH,
+};
+
+/*!
+ * \brief Mute the channel associated with this control.
+ *
+ * \param control Control for \c res_stasis.
+ * \param direction The direction in which the audio should be muted.
+ * \param stream_type The type of stream that should be muted.
+ *
+ * \return 0 for success
+ * \return -1 for error.
+ */
+int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int stream_type);
+
 /*!
  * \brief Answer the channel associated with this control.
  * \param control Control for \c res_stasis.

Modified: team/qwell/ari_channel_mute/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis/control.c?view=diff&rev=393325&r1=393324&r2=393325
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis/control.c (original)
+++ team/qwell/ari_channel_mute/res/stasis/control.c Mon Jul  1 13:01:30 2013
@@ -131,6 +131,91 @@
 	return 0;
 }
 
+struct mute_information {
+	int hook_id;
+	int stream_type;
+	int mute_write;
+	int mute_read;
+};
+
+static void framehook_destroy_cb(void *data)
+{
+	ast_free(data);
+}
+
+static struct ast_frame *framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
+{
+	struct mute_information *mute = data;
+	int mute_frame = 0;
+
+	if (!frame) {
+		return NULL;
+	}
+
+	if (frame->frametype != mute->stream_type) {
+		return frame;
+	}
+
+	if (event == AST_FRAMEHOOK_EVENT_WRITE && mute->mute_write) {
+		mute_frame = 1;
+	} else if (event == AST_FRAMEHOOK_EVENT_READ && mute->mute_read) {
+		mute_frame = 1;
+	}
+
+	if (mute_frame) {
+		switch (frame->frametype) {
+		case AST_FRAME_VOICE:
+			frame = &ast_null_frame;
+			break;
+		default:
+			break;
+		}
+	}
+
+	return frame;
+}
+
+int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int stream_type)
+{
+	struct mute_information *mute;
+	struct ast_framehook_interface mute_interface = {
+		.version = AST_FRAMEHOOK_INTERFACE_VERSION,
+		.event_cb = framehook_event_cb,
+		.destroy_cb = framehook_destroy_cb,
+	};
+	int hook_id;
+
+	if (!(mute = ast_calloc(1, sizeof(*mute)))) {
+		return -1;
+	}
+
+	mute->stream_type = stream_type;
+
+	if (direction == STASIS_MUTE_IN || direction == STASIS_MUTE_BOTH) {
+		mute->mute_read = 1;
+	}
+
+	if (direction == STASIS_MUTE_OUT || direction == STASIS_MUTE_BOTH) {
+		mute->mute_write = 1;
+	}
+
+	mute_interface.data = mute;
+
+	ast_channel_lock(control->channel);
+	hook_id = ast_framehook_attach(control->channel, &mute_interface);
+	ast_channel_unlock(control->channel);
+
+	if (hook_id < 0) {
+		/* Hook attach failed.  Get rid of the evidence. */
+		ast_free(mute);
+		return -1;
+	}
+
+	mute->hook_id = hook_id;
+
+	return 0;
+}
+
 struct ast_channel_snapshot *stasis_app_control_get_snapshot(
 	const struct stasis_app_control *control)
 {

Modified: team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c?view=diff&rev=393325&r1=393324&r2=393325
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c Mon Jul  1 13:01:30 2013
@@ -128,7 +128,31 @@
 
 void stasis_http_mute_channel(struct ast_variable *headers, struct ast_mute_channel_args *args, struct stasis_http_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: stasis_http_mute_channel\n");
+	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+	enum stasis_mute_direction direction;
+	int stream_type = AST_FRAME_VOICE;
+
+	control = find_control(response, args->channel_id);
+	if (control == NULL) {
+		return;
+	}
+
+	if (!strcmp(args->direction, "in")) {
+		direction = STASIS_MUTE_IN;
+	} else if (!strcmp(args->direction, "out")) {
+		direction = STASIS_MUTE_OUT;
+	} else if (!strcmp(args->direction, "both")) {
+		direction = STASIS_MUTE_BOTH;
+	} else {
+		stasis_http_response_error(
+			response, 400, "Bad Request",
+			"Invalid direction specified");
+		return;
+	}
+
+	stasis_app_control_mute(control, direction, stream_type);
+
+	stasis_http_response_no_content(response);
 }
 void stasis_http_unmute_channel(struct ast_variable *headers, struct ast_unmute_channel_args *args, struct stasis_http_response *response)
 {




More information about the asterisk-commits mailing list