[svn-commits] qwell: branch qwell/ari_channel_mute r393353 - /team/qwell/ari_channel_mute/r...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jul 1 15:20:51 CDT 2013


Author: qwell
Date: Mon Jul  1 15:20:49 2013
New Revision: 393353

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393353
Log:
Add a datastore so we can remove the audiohook.

Modified:
    team/qwell/ari_channel_mute/res/stasis/control.c

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=393353&r1=393352&r2=393353
==============================================================================
--- team/qwell/ari_channel_mute/res/stasis/control.c (original)
+++ team/qwell/ari_channel_mute/res/stasis/control.c Mon Jul  1 15:20:49 2013
@@ -207,19 +207,27 @@
 	return 0;
 }
 
+static void mute_datastore_destroy_cb(void *data) {
+	ast_free(data);
+}
+
+static const struct ast_datastore_info mute_datastore = {
+	.type = "mute",
+	.destroy = mute_datastore_destroy_cb
+};
+
 struct mute_information {
-	int hook_id;
 	int stream_type;
 	int mute_write;
 	int mute_read;
 };
 
-static void framehook_destroy_cb(void *data)
+static void mute_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)
+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;
 	int mute_frame = 0;
@@ -253,13 +261,15 @@
 
 int stasis_app_control_mute(struct stasis_app_control *control, enum stasis_mute_direction direction, int stream_type)
 {
+	SCOPED_CHANNELLOCK(lockvar, control->channel);
 	struct mute_information *mute;
-	struct ast_framehook_interface mute_interface = {
+	struct ast_framehook_interface interface = {
 		.version = AST_FRAMEHOOK_INTERFACE_VERSION,
-		.event_cb = framehook_event_cb,
-		.destroy_cb = framehook_destroy_cb,
+		.event_cb = mute_framehook_event_cb,
+		.destroy_cb = mute_framehook_destroy_cb,
 	};
 	int hook_id;
+	struct ast_datastore *datastore = NULL;
 
 	if (!(mute = ast_calloc(1, sizeof(*mute)))) {
 		return -1;
@@ -275,19 +285,34 @@
 		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);
-
+	interface.data = mute;
+
+	hook_id = ast_framehook_attach(control->channel, &interface);
 	if (hook_id < 0) {
 		/* Hook attach failed.  Get rid of the evidence. */
 		ast_free(mute);
 		return -1;
 	}
 
-	mute->hook_id = hook_id;
+	if ((datastore = ast_channel_datastore_find(control->channel, &mute_datastore, NULL))) {
+		/* A datastore/audiohook already existed for mute.  Kill it. */
+		ast_framehook_detach(control->channel, *(int *)datastore->data);
+		ast_channel_datastore_remove(control->channel, datastore);
+	}
+
+	if (!(datastore = ast_datastore_alloc(&mute_datastore, NULL))) {
+		ast_framehook_detach(control->channel, hook_id);
+		return 0;
+	}
+
+	if (!(datastore->data = ast_calloc(1, sizeof(int)))) {
+		ast_datastore_free(datastore);
+		ast_framehook_detach(control->channel, hook_id);
+	}
+
+	*(int *)datastore->data = hook_id;
+
+	ast_channel_datastore_add(control->channel, datastore);
 
 	return 0;
 }




More information about the svn-commits mailing list