Tue Aug 24 20:36:17 2010

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

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Technology independent volume control")
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_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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Technology independent volume control"   
)
static void destroy_callback ( void *  data  )  [static]

Definition at line 65 of file func_volume.c.

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

00066 {
00067    struct volume_information *vi = data;
00068 
00069    /* Destroy the audiohook, and destroy ourselves */
00070    ast_audiohook_destroy(&vi->audiohook);
00071    free(vi);
00072 
00073    return;
00074 }

static int load_module ( void   )  [static]

Definition at line 168 of file func_volume.c.

References ast_custom_function_register.

00169 {
00170    return ast_custom_function_register(&volume_function);
00171 }

static int unload_module ( void   )  [static]

Definition at line 163 of file func_volume.c.

References ast_custom_function_unregister().

00164 {
00165    return ast_custom_function_unregister(&volume_function);
00166 }

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 82 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().

00083 {
00084    struct ast_datastore *datastore = NULL;
00085    struct volume_information *vi = NULL;
00086    int *gain = NULL;
00087 
00088    /* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
00089    if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
00090       return 0;
00091 
00092    /* Grab datastore which contains our gain information */
00093    if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL)))
00094       return 0;
00095 
00096    vi = datastore->data;
00097 
00098    /* If this is DTMF then allow them to increase/decrease the gains */
00099    if (frame->frametype == AST_FRAME_DTMF) {
00100       /* Only use DTMF coming from the source... not going to it */
00101       if (direction != AST_AUDIOHOOK_DIRECTION_READ)
00102          return 0;
00103       if (frame->subclass == '*') {
00104          vi->tx_gain += 1;
00105          vi->rx_gain += 1;
00106       } else if (frame->subclass == '#') {
00107          vi->tx_gain -= 1;
00108          vi->rx_gain -= 1;
00109       }
00110    } else if (frame->frametype == AST_FRAME_VOICE) {
00111       /* Based on direction of frame grab the gain, and confirm it is applicable */
00112       if (!(gain = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? &vi->rx_gain : &vi->tx_gain) || !*gain)
00113          return 0;
00114       /* Apply gain to frame... easy as pi */
00115       ast_frame_adjust_volume(frame, *gain);
00116    }
00117 
00118    return 0;
00119 }

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

Definition at line 121 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().

00122 {
00123    struct ast_datastore *datastore = NULL;
00124    struct volume_information *vi = NULL;
00125    int is_new = 0;
00126 
00127    if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
00128       /* Allocate a new datastore to hold the reference to this volume and audiohook information */
00129       if (!(datastore = ast_datastore_alloc(&volume_datastore, NULL)))
00130          return 0;
00131       if (!(vi = ast_calloc(1, sizeof(*vi)))) {
00132          ast_datastore_free(datastore);
00133          return 0;
00134       }
00135       ast_audiohook_init(&vi->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "Volume");
00136       vi->audiohook.manipulate_callback = volume_callback;
00137       ast_set_flag(&vi->audiohook, AST_AUDIOHOOK_WANTS_DTMF);
00138       is_new = 1;
00139    } else {
00140       vi = datastore->data;
00141    }
00142 
00143    /* Adjust gain on volume information structure */
00144    if (!strcasecmp(data, "tx"))
00145       vi->tx_gain = atoi(value);
00146    else if (!strcasecmp(data, "rx"))
00147       vi->rx_gain = atoi(value);
00148 
00149    if (is_new) {
00150       datastore->data = vi;
00151       ast_channel_datastore_add(chan, datastore);
00152       ast_audiohook_attach(chan, &vi->audiohook);
00153    }
00154 
00155    return 0;
00156 }


Variable Documentation

Initial value:
 {
   .type = "volume",
   .destroy = destroy_callback
}

Static structure for datastore information.

Definition at line 77 of file func_volume.c.

Initial value:
 {
   .name = "VOLUME",
   .write = volume_write,
}

Definition at line 158 of file func_volume.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1