Wed Oct 28 11:52:40 2009

Asterisk developer's documentation


func_volume.c File Reference

Technology independent volume control. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/audiohook.h"

Include dependency graph for func_volume.c:

Go to the source code of this file.

Data Structures

struct  volume_information

Functions

static void __reg_module (void)
static void __unreg_module (void)
static void destroy_callback (void *data)
static int load_module (void)
static int unload_module (void)
static int volume_callback (struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
static int volume_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Technology independent volume control" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_datastore_info volume_datastore
 Static structure for datastore information.
static struct ast_custom_function volume_function


Detailed Description

Technology independent volume control.

Author:
Joshua Colp <jcolp@digium.com>

Definition in file func_volume.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 160 of file func_volume.c.

static void __unreg_module ( void   )  [static]

Definition at line 160 of file func_volume.c.

static void destroy_callback ( void *  data  )  [static]

Definition at line 45 of file func_volume.c.

References ast_audiohook_destroy(), volume_information::audiohook, and free.

00046 {
00047    struct volume_information *vi = data;
00048 
00049    /* Destroy the audiohook, and destroy ourselves */
00050    ast_audiohook_destroy(&vi->audiohook);
00051    free(vi);
00052 
00053    return;
00054 }

static int load_module ( void   )  [static]

Definition at line 155 of file func_volume.c.

References ast_custom_function_register.

00156 {
00157    return ast_custom_function_register(&volume_function);
00158 }

static int unload_module ( void   )  [static]

Definition at line 150 of file func_volume.c.

References ast_custom_function_unregister().

00151 {
00152    return ast_custom_function_unregister(&volume_function);
00153 }

static int volume_callback ( struct ast_audiohook audiohook,
struct ast_channel chan,
struct ast_frame frame,
enum ast_audiohook_direction  direction 
) [static]

Definition at line 62 of file func_volume.c.

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_STATUS_DONE, ast_channel_datastore_find(), ast_frame_adjust_volume(), AST_FRAME_DTMF, AST_FRAME_VOICE, ast_datastore::data, ast_frame::frametype, volume_information::rx_gain, ast_audiohook::status, ast_frame::subclass, and volume_information::tx_gain.

Referenced by volume_write().

00063 {
00064    struct ast_datastore *datastore = NULL;
00065    struct volume_information *vi = NULL;
00066    int *gain = NULL;
00067 
00068    /* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
00069    if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
00070       return 0;
00071 
00072    /* Grab datastore which contains our gain information */
00073    if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL)))
00074       return 0;
00075 
00076    vi = datastore->data;
00077 
00078    /* If this is DTMF then allow them to increase/decrease the gains */
00079    if (frame->frametype == AST_FRAME_DTMF) {
00080       /* Only use DTMF coming from the source... not going to it */
00081       if (direction != AST_AUDIOHOOK_DIRECTION_READ)
00082          return 0;
00083       if (frame->subclass == '*') {
00084          vi->tx_gain += 1;
00085          vi->rx_gain += 1;
00086       } else if (frame->subclass == '#') {
00087          vi->tx_gain -= 1;
00088          vi->rx_gain -= 1;
00089       }
00090    } else if (frame->frametype == AST_FRAME_VOICE) {
00091       /* Based on direction of frame grab the gain, and confirm it is applicable */
00092       if (!(gain = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? &vi->rx_gain : &vi->tx_gain) || !*gain)
00093          return 0;
00094       /* Apply gain to frame... easy as pi */
00095       ast_frame_adjust_volume(frame, *gain);
00096    }
00097 
00098    return 0;
00099 }

static int volume_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
) [static]

Definition at line 101 of file func_volume.c.

References ast_audiohook_attach(), ast_audiohook_init(), AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_WANTS_DTMF, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), ast_set_flag, volume_information::audiohook, ast_datastore::data, ast_audiohook::manipulate_callback, volume_information::rx_gain, volume_information::tx_gain, and volume_callback().

00102 {
00103    struct ast_datastore *datastore = NULL;
00104    struct volume_information *vi = NULL;
00105    int is_new = 0;
00106 
00107    if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
00108       /* Allocate a new datastore to hold the reference to this volume and audiohook information */
00109       if (!(datastore = ast_datastore_alloc(&volume_datastore, NULL)))
00110          return 0;
00111       if (!(vi = ast_calloc(1, sizeof(*vi)))) {
00112          ast_datastore_free(datastore);
00113          return 0;
00114       }
00115       ast_audiohook_init(&vi->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "Volume");
00116       vi->audiohook.manipulate_callback = volume_callback;
00117       ast_set_flag(&vi->audiohook, AST_AUDIOHOOK_WANTS_DTMF);
00118       is_new = 1;
00119    } else {
00120       vi = datastore->data;
00121    }
00122 
00123    /* Adjust gain on volume information structure */
00124    if (!strcasecmp(data, "tx"))
00125       vi->tx_gain = atoi(value);
00126    else if (!strcasecmp(data, "rx"))
00127       vi->rx_gain = atoi(value);
00128 
00129    if (is_new) {
00130       datastore->data = vi;
00131       ast_channel_datastore_add(chan, datastore);
00132       ast_audiohook_attach(chan, &vi->audiohook);
00133    }
00134 
00135    return 0;
00136 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Technology independent volume control" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 160 of file func_volume.c.

Definition at line 160 of file func_volume.c.

Initial value:

 {
   .type = "volume",
   .destroy = destroy_callback
}
Static structure for datastore information.

Definition at line 57 of file func_volume.c.

Definition at line 138 of file func_volume.c.


Generated on Wed Oct 28 11:52:40 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6