#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/audiohook.h"
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_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_datastore_info | volume_datastore |
Static structure for datastore information. | |
static struct ast_custom_function | volume_function |
Definition in file func_volume.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 173 of file func_volume.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 173 of file func_volume.c.
static void destroy_callback | ( | void * | data | ) | [static] |
Definition at line 65 of file func_volume.c.
References ast_audiohook_destroy(), ast_free, and volume_information::audiohook.
00066 { 00067 struct volume_information *vi = data; 00068 00069 /* Destroy the audiohook, and destroy ourselves */ 00070 ast_audiohook_destroy(&vi->audiohook); 00071 ast_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, and volume_function.
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(), and volume_function.
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, volume_information::audiohook, ast_datastore::data, ast_frame::frametype, ast_frame_subclass::integer, volume_information::rx_gain, ast_audiohook::status, ast_frame::subclass, volume_information::tx_gain, and volume_datastore.
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.integer == '*') { 00104 vi->tx_gain += 1; 00105 vi->rx_gain += 1; 00106 } else if (frame->subclass.integer == '#') { 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, volume_information::rx_gain, volume_information::tx_gain, volume_callback(), and volume_datastore.
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 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 173 of file func_volume.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 173 of file func_volume.c.
struct ast_datastore_info volume_datastore [static] |
Initial value:
{ .type = "volume", .destroy = destroy_callback }
Definition at line 77 of file func_volume.c.
Referenced by volume_callback(), and volume_write().
struct ast_custom_function volume_function [static] |
Initial value:
{ .name = "VOLUME", .write = volume_write, }
Definition at line 158 of file func_volume.c.
Referenced by load_module(), and unload_module().