[svn-commits] qwell: branch qwell/ari_channel_mute r393423 - in /team/qwell/ari_channel_mut...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 2 10:07:24 CDT 2013


Author: qwell
Date: Tue Jul  2 10:07:23 2013
New Revision: 393423

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393423
Log:
Allow muting multiple streams, using multiple framehooks.

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=393423&r1=393422&r2=393423
==============================================================================
--- team/qwell/ari_channel_mute/include/asterisk/stasis_app.h (original)
+++ team/qwell/ari_channel_mute/include/asterisk/stasis_app.h Tue Jul  2 10:07:23 2013
@@ -166,9 +166,8 @@
 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,
+	STASIS_MUTE_READ,
+	STASIS_MUTE_WRITE,
 };
 
 /*!

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=393423&r1=393422&r2=393423
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis/control.c (original)
+++ team/qwell/ari_channel_mute/res/stasis/control.c Tue Jul  2 10:07:23 2013
@@ -207,19 +207,19 @@
 	return 0;
 }
 
-static void mute_datastore_destroy_cb(void *data) {
+static void mute_datastore_destroy_cb(void *data)
+{
 	ast_free(data);
 }
 
-static const struct ast_datastore_info mute_datastore = {
-	.type = "mute",
+static const struct ast_datastore_info mute_datastore_voice_read = {
+	.type = "mutevoiceread",
 	.destroy = mute_datastore_destroy_cb
 };
 
-struct mute_information {
-	int stream_type;
-	int mute_write;
-	int mute_read;
+static const struct ast_datastore_info mute_datastore_voice_write = {
+	.type = "mutevoicewrite",
+	.destroy = mute_datastore_destroy_cb
 };
 
 static void mute_framehook_destroy_cb(void *data)
@@ -227,22 +227,45 @@
 	ast_free(data);
 }
 
+static struct mute_data {
+	int frametype;
+	enum stasis_mute_direction direction;
+};
+
+static const struct ast_datastore_info *mute_get_datastore_information(enum stasis_mute_direction direction, int frametype)
+{
+	switch (direction) {
+	case STASIS_MUTE_READ:
+		if (frametype == AST_FRAME_VOICE) {
+			return &mute_datastore_voice_read;
+		}
+		break;
+	case STASIS_MUTE_WRITE:
+		if (frametype == AST_FRAME_VOICE) {
+			return &mute_datastore_voice_write;
+		}
+		break;
+	}
+
+	return NULL;
+}
+
 static struct ast_frame *mute_framehook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
 {
-	struct mute_information *mute = data;
+	struct mute_data *mute = data;
 	int mute_frame = 0;
 
 	if (!frame) {
 		return NULL;
 	}
 
-	if (frame->frametype != mute->stream_type) {
+	if (frame->frametype != mute->frametype) {
 		return frame;
 	}
 
-	if (event == AST_FRAMEHOOK_EVENT_WRITE && mute->mute_write) {
+	if (event == AST_FRAMEHOOK_EVENT_READ && mute->direction == STASIS_MUTE_READ) {
 		mute_frame = 1;
-	} else if (event == AST_FRAMEHOOK_EVENT_READ && mute->mute_read) {
+	} else if (event == AST_FRAMEHOOK_EVENT_WRITE && mute->direction == STASIS_MUTE_WRITE) {
 		mute_frame = 1;
 	}
 
@@ -259,10 +282,10 @@
 	return frame;
 }
 
-int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int stream_type)
+int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int frametype)
 {
 	SCOPED_CHANNELLOCK(lockvar, control->channel);
-	struct mute_information *mute;
+	struct mute_data *mute;
 	struct ast_framehook_interface interface = {
 		.version = AST_FRAMEHOOK_INTERFACE_VERSION,
 		.event_cb = mute_framehook_event_cb,
@@ -270,20 +293,18 @@
 	};
 	int hook_id;
 	struct ast_datastore *datastore = NULL;
+	const struct ast_datastore_info *datastore_info = NULL;
+
+	if (!(datastore_info = mute_get_datastore_information(direction, frametype))) {
+		return -1;
+	}
 
 	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->frametype = frametype;
+	mute->direction = direction;
 
 	interface.data = mute;
 
@@ -294,13 +315,13 @@
 		return -1;
 	}
 
-	if ((datastore = ast_channel_datastore_find(control->channel, &mute_datastore, NULL))) {
-		/* A datastore/audiohook already existed for mute.  Kill it. */
+	if ((datastore = ast_channel_datastore_find(control->channel, datastore_info, NULL))) {
+		/* A datastore/audiohook already existed for this type of mute.  Kill them. */
 		ast_framehook_detach(control->channel, *(int *)datastore->data);
 		ast_channel_datastore_remove(control->channel, datastore);
 	}
 
-	if (!(datastore = ast_datastore_alloc(&mute_datastore, NULL))) {
+	if (!(datastore = ast_datastore_alloc(datastore_info, NULL))) {
 		ast_framehook_detach(control->channel, hook_id);
 		return 0;
 	}

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=393423&r1=393422&r2=393423
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c (original)
+++ team/qwell/ari_channel_mute/res/stasis_http/resource_channels.c Tue Jul  2 10:07:23 2013
@@ -143,7 +143,8 @@
 void stasis_http_mute_channel(struct ast_variable *headers, struct ast_mute_channel_args *args, struct stasis_http_response *response)
 {
 	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
-	enum stasis_mute_direction direction;
+	int mute_in = 0;
+	int mute_out = 0;
 	int stream_type = AST_FRAME_VOICE;
 
 	control = find_control(response, args->channel_id);
@@ -152,11 +153,12 @@
 	}
 
 	if (!strcmp(args->direction, "in")) {
-		direction = STASIS_MUTE_IN;
+		mute_in = 1;
 	} else if (!strcmp(args->direction, "out")) {
-		direction = STASIS_MUTE_OUT;
+		mute_out = 1;
 	} else if (!strcmp(args->direction, "both")) {
-		direction = STASIS_MUTE_BOTH;
+		mute_in = 1;
+		mute_out = 1;
 	} else {
 		stasis_http_response_error(
 			response, 400, "Bad Request",
@@ -164,7 +166,13 @@
 		return;
 	}
 
-	stasis_app_control_mute(control, direction, stream_type);
+	if (mute_in) {
+		stasis_app_control_mute(control, STASIS_MUTE_READ, stream_type);
+	}
+
+	if (mute_out) {
+		stasis_app_control_mute(control, STASIS_MUTE_WRITE, stream_type);
+	}
 
 	stasis_http_response_no_content(response);
 }




More information about the svn-commits mailing list