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"
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 __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Technology independent volume control" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
| 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 |
Technology independent volume control.
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(), volume_information::audiohook, and free.
{
struct volume_information *vi = data;
/* Destroy the audiohook, and destroy ourselves */
ast_audiohook_destroy(&vi->audiohook);
free(vi);
return;
}
| static int load_module | ( | void | ) | [static] |
Definition at line 168 of file func_volume.c.
References ast_custom_function_register.
{
return ast_custom_function_register(&volume_function);
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 163 of file func_volume.c.
References ast_custom_function_unregister().
{
return ast_custom_function_unregister(&volume_function);
}
| 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().
{
struct ast_datastore *datastore = NULL;
struct volume_information *vi = NULL;
int *gain = NULL;
/* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
if (audiohook->status == AST_AUDIOHOOK_STATUS_DONE)
return 0;
/* Grab datastore which contains our gain information */
if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL)))
return 0;
vi = datastore->data;
/* If this is DTMF then allow them to increase/decrease the gains */
if (frame->frametype == AST_FRAME_DTMF) {
/* Only use DTMF coming from the source... not going to it */
if (direction != AST_AUDIOHOOK_DIRECTION_READ)
return 0;
if (frame->subclass == '*') {
vi->tx_gain += 1;
vi->rx_gain += 1;
} else if (frame->subclass == '#') {
vi->tx_gain -= 1;
vi->rx_gain -= 1;
}
} else if (frame->frametype == AST_FRAME_VOICE) {
/* Based on direction of frame grab the gain, and confirm it is applicable */
if (!(gain = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? &vi->rx_gain : &vi->tx_gain) || !*gain)
return 0;
/* Apply gain to frame... easy as pi */
ast_frame_adjust_volume(frame, *gain);
}
return 0;
}
| 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().
{
struct ast_datastore *datastore = NULL;
struct volume_information *vi = NULL;
int is_new = 0;
if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
/* Allocate a new datastore to hold the reference to this volume and audiohook information */
if (!(datastore = ast_datastore_alloc(&volume_datastore, NULL)))
return 0;
if (!(vi = ast_calloc(1, sizeof(*vi)))) {
ast_datastore_free(datastore);
return 0;
}
ast_audiohook_init(&vi->audiohook, AST_AUDIOHOOK_TYPE_MANIPULATE, "Volume");
vi->audiohook.manipulate_callback = volume_callback;
ast_set_flag(&vi->audiohook, AST_AUDIOHOOK_WANTS_DTMF);
is_new = 1;
} else {
vi = datastore->data;
}
/* Adjust gain on volume information structure */
if (!strcasecmp(data, "tx"))
vi->tx_gain = atoi(value);
else if (!strcasecmp(data, "rx"))
vi->rx_gain = atoi(value);
if (is_new) {
datastore->data = vi;
ast_channel_datastore_add(chan, datastore);
ast_audiohook_attach(chan, &vi->audiohook);
}
return 0;
}
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Technology independent volume control" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [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] |
{
.type = "volume",
.destroy = destroy_callback
}
Static structure for datastore information.
Definition at line 77 of file func_volume.c.
struct ast_custom_function volume_function [static] |
{
.name = "VOLUME",
.write = volume_write,
}
Definition at line 158 of file func_volume.c.