[asterisk-commits] branch file/coremedia - r7317 /team/file/coremedia/shims/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Dec 3 16:42:08 CST 2005


Author: file
Date: Sat Dec  3 16:42:06 2005
New Revision: 7317

URL: http://svn.digium.com/view/asterisk?rev=7317&view=rev
Log:
Add another test shim - this one changes the volume of audio going to a person.

Added:
    team/file/coremedia/shims/shim_volume.c
Modified:
    team/file/coremedia/shims/Makefile

Modified: team/file/coremedia/shims/Makefile
URL: http://svn.digium.com/view/asterisk/team/file/coremedia/shims/Makefile?rev=7317&r1=7316&r2=7317&view=diff
==============================================================================
--- team/file/coremedia/shims/Makefile (original)
+++ team/file/coremedia/shims/Makefile Sat Dec  3 16:42:06 2005
@@ -11,7 +11,7 @@
 # the GNU General Public License
 #
 
-SHIMS=shim_test.so
+SHIMS=shim_test.so shim_volume.so
 
 ifeq (${OSARCH},CYGWIN)
 CYGSOLINK=-Wl,--out-implib=lib$@.a -Wl,--export-all-symbols

Added: team/file/coremedia/shims/shim_volume.c
URL: http://svn.digium.com/view/asterisk/team/file/coremedia/shims/shim_volume.c?rev=7317&view=auto
==============================================================================
--- team/file/coremedia/shims/shim_volume.c (added)
+++ team/file/coremedia/shims/shim_volume.c Sat Dec  3 16:42:06 2005
@@ -1,0 +1,155 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2005, Joshua Colp
+ *
+ * Joshua Colp <jcolp at asterlink.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Volume Changer application
+ * 
+ * \ingroup applications
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "asterisk.h"
+
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/lock.h"
+#include "asterisk/app.h"
+#include "asterisk/coremedia.h"
+
+static char *tdesc = "Volume Changer Application";
+static char *app = "Volume";
+static char *synopsis = 
+"Volume changer application.";
+static char *descrip = "This application changes the volume of received audio in realtime.\n";
+
+STANDARD_LOCAL_USER;
+
+LOCAL_USER_DECL;
+
+struct ast_coremedia_shim_pvt {
+  int volume;
+};
+
+/* Our shim callback */
+static struct ast_frame *volume_callback(struct ast_coremedia_shim_pvt *pvt, struct ast_frame *frame)
+{
+  int i = 0;
+  short *s = frame->data;
+
+  /* Using the private structure - adjust the audio */
+  if (pvt == NULL) /* No private structure - just return the audio */
+    return frame; 
+
+  /* Okay here is where it gets complicated */
+  for (i=0; i<frame->datalen; i++) {
+    if (0 > pvt->volume)
+      s[i] = s[i] / (short)pvt->volume;
+    else
+      s[i] = s[i] * (short)pvt->volume;
+  }
+
+  return frame;
+}
+
+/* Private structure destroyer */
+static void volume_destroy(struct ast_coremedia_shim_pvt *pvt)
+{
+  free(pvt);
+  return;
+}
+
+static struct ast_coremedia_shim volume =
+  { volume_callback,
+    volume_destroy,
+  };
+
+static int app_exec(struct ast_channel *chan, void *data)
+{
+	int res = 0;
+	struct localuser *u;
+	struct ast_coremedia_shim_pvt *new_pvt = NULL;
+
+	LOCAL_USER_ADD(u);
+
+	/* Allocate a new private structure for us */
+	new_pvt = (struct ast_coremedia_shim_pvt*)malloc(sizeof(struct ast_coremedia_shim_pvt));
+	memset(new_pvt, 0, sizeof(struct ast_coremedia_shim_pvt));
+
+	/* Take argument and use it as the volume */
+	if (data != NULL)
+	  new_pvt->volume = abs(atoi(data));
+	else
+	  new_pvt->volume = 1; /* Assume no change */
+
+	/* Add the shim to the channel */
+	ast_coremedia_shimmy(chan, &volume, new_pvt, 1);
+
+	LOCAL_USER_REMOVE(u);
+
+	return res;
+}
+
+int unload_module(void)
+{
+	int res;
+
+	res = ast_unregister_application(app);
+
+	STANDARD_HANGUP_LOCALUSERS;
+
+	return res;	
+}
+
+int load_module(void)
+{
+	return ast_register_application(app, app_exec, synopsis, descrip);
+}
+
+int reload(void)
+{
+	/* This function will be called if a 'reload' is requested */
+
+	return 0;
+}
+
+char *description(void)
+{
+	return tdesc;
+}
+
+int usecount(void)
+{
+	int res;
+
+	STANDARD_USECOUNT(res);
+
+	return res;
+}
+
+char *key()
+{
+	return ASTERISK_GPL_KEY;
+}



More information about the asterisk-commits mailing list