[svn-commits] oej: branch oej/mutestream-trunk r215034 - /team/oej/mutestream-trunk/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Aug 31 13:22:48 CDT 2009


Author: oej
Date: Mon Aug 31 13:22:44 2009
New Revision: 215034

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=215034
Log:
Addressing most of Russell's good feedback in reviewboard. XML docs missing

Modified:
    team/oej/mutestream-trunk/res/res_mutestream.c

Modified: team/oej/mutestream-trunk/res/res_mutestream.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/oej/mutestream-trunk/res/res_mutestream.c?view=diff&rev=215034&r1=215033&r2=215034
==============================================================================
--- team/oej/mutestream-trunk/res/res_mutestream.c (original)
+++ team/oej/mutestream-trunk/res/res_mutestream.c Mon Aug 31 13:22:44 2009
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 2009, Olle E. Johansson
  *
  * Olle E. Johansson <oej at edvina.net>
  *
@@ -18,7 +18,7 @@
 
 /*! \file
  *
- * \brief MUTE audiohooks
+ * \brief MUTESTREAM audiohooks
  *
  * \author Olle E. Johansson <oej at edvina.net>
  *
@@ -33,7 +33,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <math.h>
 #include <errno.h>
 
 #include "asterisk/options.h"
@@ -50,7 +49,7 @@
 
 
 
-/* Our own datastore */
+/*! Our own datastore */
 struct mute_information {
 	struct ast_audiohook audiohook;
 	int mute_write;
@@ -68,7 +67,7 @@
 
 	/* Destroy the audiohook, and destroy ourselves */
 	ast_audiohook_destroy(&mute->audiohook);
-	free(mute);
+	ast_free(mute);
 	ast_module_unref(ast_module_info->self);
 
 	return;
@@ -108,8 +107,7 @@
 	ast_channel_lock(chan);
 	/* Grab datastore which contains our mute information */
 	if (!(datastore = ast_channel_datastore_find(chan, &mute_datastore, NULL))) {
-		if (option_debug > 1)
-			ast_log(LOG_DEBUG, " *** Can't find any datastore to use. Bad. \n");
+		ast_debug(2, " *** Can't find any datastore to use. Bad. \n");
 		return 0;
 	}
 
@@ -118,8 +116,7 @@
 
 	/* If this is audio then allow them to increase/decrease the gains */
 	if (frame->frametype == AST_FRAME_VOICE) {
-		if (option_debug > 3)
-			ast_log(LOG_DEBUG, "Audio frame - direction %s  mute READ %s WRITE %s\n", direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write", mute->mute_read ? "on" : "off", mute->mute_write ? "on" : "off");
+		ast_debug(2, "Audio frame - direction %s  mute READ %s WRITE %s\n", direction == AST_AUDIOHOOK_DIRECTION_READ ? "read" : "write", mute->mute_read ? "on" : "off", mute->mute_write ? "on" : "off");
 
 		/* Based on direction of frame grab the gain, and confirm it is applicable */
 		if ((direction == AST_AUDIOHOOK_DIRECTION_READ && mute->mute_read) || (direction == AST_AUDIOHOOK_DIRECTION_WRITE && mute->mute_write)) {
@@ -132,14 +129,15 @@
 	return 0;
 }
 
-/*! \brief Initialize mute hook on channel, but don't activate it */
+/*! \brief Initialize mute hook on channel, but don't activate it 
+	Assumes that the channel is locked
+*/
 static struct ast_datastore *initialize_mutehook(struct ast_channel *chan)
 {
 	struct ast_datastore *datastore = NULL;
 	struct mute_information *mute = NULL;
 
-	if (option_debug > 2 )
-		ast_log(LOG_DEBUG, "Initializing new Mute Audiohook \n");
+	ast_debug(2, "Initializing new Mute Audiohook \n");
 
 	/* Allocate a new datastore to hold the reference to this mute_datastore and audiohook information */
 	if (!(datastore = ast_datastore_alloc(&mute_datastore, NULL))) {
@@ -156,20 +154,20 @@
 	return datastore;
 }
 
-/*! \brief Add or activate mute audiohook on channel */
+/*! \brief Add or activate mute audiohook on channel 
+	Assumes channel is locked
+*/
 static int mute_add_audiohook(struct ast_channel *chan, struct mute_information *mute, struct ast_datastore *datastore)
 {
-		/* Activate the settings */
-		ast_channel_datastore_add(chan, datastore);
-		if(ast_audiohook_attach(chan, &mute->audiohook)) {
-			ast_log(LOG_ERROR, "Failed to attach audiohook for muting channel %s\n", chan->name);
-			return -1;
-		}
-		ast_module_ref(ast_module_info->self);
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "*** Initialized audiohook on channel %s\n", chan->name);
-		}
-		return 0;
+	/* Activate the settings */
+	ast_channel_datastore_add(chan, datastore);
+	if (ast_audiohook_attach(chan, &mute->audiohook)) {
+		ast_log(LOG_ERROR, "Failed to attach audiohook for muting channel %s\n", chan->name);
+		return -1;
+	}
+	ast_module_ref(ast_module_info->self);
+	ast_debug(2, "*** Initialized audiohook on channel %s\n", chan->name);
+	return 0;
 }
 
 /*! \brief Mute dialplan function */
@@ -180,7 +178,9 @@
 	int is_new = 0;
 
 	if (!(datastore = ast_channel_datastore_find(chan, &mute_datastore, NULL))) {
+		ast_channel_lock(chan);
 		if (!(datastore = initialize_mutehook(chan))) {
+			ast_channel_unlock(chan);
 			return 0;
 		}
 		is_new = 1;
@@ -190,14 +190,10 @@
 
 	if (!strcasecmp(data, "out")) {
 		mute->mute_write = ast_true(value);
-		if (option_debug > 1) {
-			ast_log(LOG_DEBUG, "%s channel - outbound *** \n", ast_true(value) ? "Muting" : "Unmuting");
-		}
+		ast_debug(1, "%s channel - outbound *** \n", ast_true(value) ? "Muting" : "Unmuting");
 	} else if (!strcasecmp(data, "in")) {
 		mute->mute_read = ast_true(value);
-		if (option_debug > 1) {
-			ast_log(LOG_DEBUG, "%s channel - inbound *** \n", ast_true(value) ? "Muting" : "Unmuting");
-		}
+		ast_debug(1, "%s channel - inbound *** \n", ast_true(value) ? "Muting" : "Unmuting");
 	} else if (!strcasecmp(data,"all")) {
 		mute->mute_write = mute->mute_read = ast_true(value);
 	}
@@ -205,6 +201,7 @@
 	if (is_new) {
 		mute_add_audiohook(chan, mute, datastore);
 	}
+	ast_channel_unlock(chan);
 
 	return 0;
 }
@@ -255,8 +252,11 @@
 		return 0;
 	}
 
+	ast_channel_lock(c);
+
 	if (!(datastore = ast_channel_datastore_find(c, &mute_datastore, NULL))) {
 		if (!(datastore = initialize_mutehook(c))) {
+			ast_channel_unref(c);
 			return 0;
 		}
 		is_new = 1;
@@ -275,6 +275,8 @@
 	if (is_new) {
 		mute_add_audiohook(c, mute, datastore);
 	}
+	ast_channel_unref(c);
+	ast_channel_unlock(c);
 
 	astman_append(s, "Response: Success\r\n"
 				   "%s"
@@ -303,7 +305,7 @@
 
 	ast_manager_register2("MuteStream", EVENT_FLAG_SYSTEM, manager_mutestream,
                         "Mute an audio stream", mandescr_mutestream);
-	return 0;
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
 static int unload_module(void)




More information about the svn-commits mailing list