Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions | Variables
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 "asterisk/app.h"
Include dependency graph for func_volume.c:

Go to the source code of this file.

Data Structures

struct  volume_information
 

Enumerations

enum  volume_flags { VOLUMEFLAG_CHANGE = (1 << 1) }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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_read (struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
 
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 = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_datastore_info volume_datastore
 Static structure for datastore information.
 
static struct ast_custom_function volume_function
 
static const struct ast_app_option volume_opts [128] = { [ 'p' ] = { .flag = VOLUMEFLAG_CHANGE }, }
 

Detailed Description

Technology independent volume control.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file func_volume.c.

Enumeration Type Documentation

◆ volume_flags

Enumerator
VOLUMEFLAG_CHANGE 

Definition at line 94 of file func_volume.c.

94 {
95 VOLUMEFLAG_CHANGE = (1 << 1),
96};
@ VOLUMEFLAG_CHANGE
Definition func_volume.c:95

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 301 of file func_volume.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 301 of file func_volume.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 301 of file func_volume.c.

◆ destroy_callback()

static void destroy_callback ( void *  data)
static

Definition at line 102 of file func_volume.c.

103{
104 struct volume_information *vi = data;
105
106 /* Destroy the audiohook, and destroy ourselves */
111 ast_free(vi);
112
113 return;
114}
#define ast_free(a)
Definition astmm.h:180
#define ast_audiohook_lock(ah)
Lock an audiohook.
Definition audiohook.h:313
int ast_audiohook_detach(struct ast_audiohook *audiohook)
Detach audiohook from channel.
Definition audiohook.c:587
int ast_audiohook_destroy(struct ast_audiohook *audiohook)
Destroys an audiohook structure.
Definition audiohook.c:124
#define ast_audiohook_unlock(ah)
Unlock an audiohook.
Definition audiohook.h:318
struct ast_audiohook audiohook
Definition func_volume.c:88

References ast_audiohook_destroy(), ast_audiohook_detach(), ast_audiohook_lock, ast_audiohook_unlock, ast_free, and volume_information::audiohook.

◆ load_module()

static int load_module ( void  )
static

Definition at line 296 of file func_volume.c.

297{
299}
static struct ast_custom_function volume_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References ast_custom_function_register, and volume_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 291 of file func_volume.c.

292{
294}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and volume_function.

◆ volume_callback()

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 122 of file func_volume.c.

123{
124 struct ast_datastore *datastore = NULL;
125 struct volume_information *vi = NULL;
126 float *gain = NULL;
127
128 /* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
130 return 0;
131
132 /* Grab datastore which contains our gain information */
133 if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL)))
134 return 0;
135
136 vi = datastore->data;
137
138 /* If this is DTMF then allow them to increase/decrease the gains */
140 if (frame->frametype == AST_FRAME_DTMF) {
141 /* Only use DTMF coming from the source... not going to it */
143 return 0;
144 if (frame->subclass.integer == '*') {
145 vi->tx_gain += 1;
146 vi->rx_gain += 1;
147 } else if (frame->subclass.integer == '#') {
148 vi->tx_gain -= 1;
149 vi->rx_gain -= 1;
150 }
151 }
152 }
153
154
155 if (frame->frametype == AST_FRAME_VOICE) {
156 /* Based on direction of frame grab the gain, and confirm it is applicable */
157 if (!(gain = (direction == AST_AUDIOHOOK_DIRECTION_READ) ? &vi->rx_gain : &vi->tx_gain) || !*gain)
158 return 0;
159 /* Apply gain to frame... easy as pi */
160 ast_frame_adjust_volume_float(frame, *gain);
161 }
162
163 return 0;
164}
@ AST_AUDIOHOOK_DIRECTION_READ
Definition audiohook.h:49
@ AST_AUDIOHOOK_STATUS_DONE
Definition audiohook.h:45
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition channel.c:2389
direction
static const struct ast_datastore_info volume_datastore
Static structure for datastore information.
#define AST_FRAME_DTMF
int ast_frame_adjust_volume_float(struct ast_frame *f, float adjustment)
Adjusts the volume of the audio samples contained in a frame.
Definition main/frame.c:812
#define NULL
Definition resample.c:96
enum ast_audiohook_status status
Definition audiohook.h:108
Structure for a data store object.
Definition datastore.h:64
void * data
Definition datastore.h:66
struct ast_frame_subclass subclass
enum ast_frame_type frametype
#define ast_test_flag(p, flag)
Definition utils.h:64

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_STATUS_DONE, ast_channel_datastore_find(), ast_frame_adjust_volume_float(), AST_FRAME_DTMF, AST_FRAME_VOICE, ast_test_flag, volume_information::audiohook, ast_datastore::data, ast_frame::frametype, ast_frame_subclass::integer, NULL, volume_information::rx_gain, ast_audiohook::status, ast_frame::subclass, volume_information::tx_gain, volume_datastore, and VOLUMEFLAG_CHANGE.

Referenced by volume_write().

◆ volume_read()

static int volume_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buffer,
size_t  buflen 
)
static

Definition at line 240 of file func_volume.c.

241{
242 struct ast_datastore *datastore = NULL;
243 struct volume_information *vi = NULL;
244
245 /* Separate options from argument */
246
250 );
251
252 if (!chan) {
253 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
254 return -1;
255 }
256
258
259 ast_channel_lock(chan);
260 if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
261 ast_channel_unlock(chan);
262 return -1; /* no active audiohook, nothing to read */
263 } else {
264 ast_channel_unlock(chan);
265 vi = datastore->data;
266 }
267
268 /* Obtain current gain using volume information structure */
269 if (ast_strlen_zero(args.direction)) {
270 ast_log(LOG_ERROR, "Direction must be specified for VOLUME function\n");
271 return -1;
272 }
273
274 if (!strcasecmp(args.direction, "tx")) {
275 snprintf(buffer, buflen, "%f", vi->tx_gain);
276 } else if (!strcasecmp(args.direction, "rx")) {
277 snprintf(buffer, buflen, "%f", vi->rx_gain);
278 } else {
279 ast_log(LOG_ERROR, "Direction must be either RX or TX\n");
280 }
281
282 return 0;
283}
#define ast_log
Definition astobj2.c:42
#define ast_channel_lock(chan)
Definition channel.h:2982
#define ast_channel_unlock(chan)
Definition channel.h:2983
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_ERROR
#define LOG_WARNING
static struct @519 args
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
static struct test_options options

References args, AST_APP_ARG, ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_datastore::data, LOG_ERROR, LOG_WARNING, NULL, options, volume_information::rx_gain, volume_information::tx_gain, and volume_datastore.

◆ volume_write()

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

Definition at line 166 of file func_volume.c.

167{
168 struct ast_datastore *datastore = NULL;
169 struct volume_information *vi = NULL;
170 int is_new = 0;
171
172 /* Separate options from argument */
173
177 );
178
179 if (!chan) {
180 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
181 return -1;
182 }
183
185
186 ast_channel_lock(chan);
187 if (!(datastore = ast_channel_datastore_find(chan, &volume_datastore, NULL))) {
188 ast_channel_unlock(chan);
189 /* Allocate a new datastore to hold the reference to this volume and audiohook information */
190 if (!(datastore = ast_datastore_alloc(&volume_datastore, NULL)))
191 return 0;
192 if (!(vi = ast_calloc(1, sizeof(*vi)))) {
193 ast_datastore_free(datastore);
194 return 0;
195 }
199 is_new = 1;
200 } else {
201 ast_channel_unlock(chan);
202 vi = datastore->data;
203 }
204
205 /* Adjust gain on volume information structure */
206 if (ast_strlen_zero(args.direction)) {
207 ast_log(LOG_ERROR, "Direction must be specified for VOLUME function\n");
208 return -1;
209 }
210
211 if (!strcasecmp(args.direction, "tx")) {
212 vi->tx_gain = atof(value);
213 } else if (!strcasecmp(args.direction, "rx")) {
214 vi->rx_gain = atof(value);
215 } else {
216 ast_log(LOG_ERROR, "Direction must be either RX or TX\n");
217 }
218
219 if (is_new) {
220 datastore->data = vi;
221 ast_channel_lock(chan);
222 ast_channel_datastore_add(chan, datastore);
223 ast_channel_unlock(chan);
225 }
226
227 /* Add Option data to struct */
228
229 if (!ast_strlen_zero(args.options)) {
230 struct ast_flags flags = { 0 };
232 vi->flags = flags.flags;
233 } else {
234 vi->flags = 0;
235 }
236
237 return 0;
238}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
@ AST_AUDIOHOOK_MANIPULATE_ALL_RATES
Definition audiohook.h:75
int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type type, const char *source, enum ast_audiohook_init_flags flags)
Initialize an audiohook structure.
Definition audiohook.c:100
@ AST_AUDIOHOOK_WANTS_DTMF
Definition audiohook.h:58
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
Definition audiohook.c:521
@ AST_AUDIOHOOK_TYPE_MANIPULATE
Definition audiohook.h:38
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2375
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition datastore.c:68
static const struct ast_app_option volume_opts[128]
static int volume_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition main/app.c:3066
ast_audiohook_manipulate_callback manipulate_callback
Definition audiohook.h:118
Structure used to handle boolean flags.
Definition utils.h:220
unsigned int flags
Definition utils.h:221
unsigned int flags
Definition func_volume.c:91
int value
Definition syslog.c:37
#define ast_set_flag(p, flag)
Definition utils.h:71

References args, AST_APP_ARG, ast_app_parse_options(), ast_audiohook_attach(), ast_audiohook_init(), AST_AUDIOHOOK_MANIPULATE_ALL_RATES, AST_AUDIOHOOK_TYPE_MANIPULATE, AST_AUDIOHOOK_WANTS_DTMF, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), AST_DECLARE_APP_ARGS, ast_log, ast_set_flag, AST_STANDARD_APP_ARGS, ast_strlen_zero(), volume_information::audiohook, ast_datastore::data, volume_information::flags, ast_flags::flags, LOG_ERROR, LOG_WARNING, ast_audiohook::manipulate_callback, NULL, options, volume_information::rx_gain, volume_information::tx_gain, value, volume_callback(), volume_datastore, and volume_opts.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Technology independent volume control" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 301 of file func_volume.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 301 of file func_volume.c.

◆ volume_datastore

const struct ast_datastore_info volume_datastore
static
Initial value:
= {
.type = "volume",
.destroy = destroy_callback
}
static void destroy_callback(void *data)

Static structure for datastore information.

Definition at line 117 of file func_volume.c.

117 {
118 .type = "volume",
119 .destroy = destroy_callback
120};

Referenced by volume_callback(), volume_read(), and volume_write().

◆ volume_function

struct ast_custom_function volume_function
static
Initial value:
= {
.name = "VOLUME",
.write = volume_write,
.read = volume_read,
}
static int volume_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
static int volume_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)

Definition at line 285 of file func_volume.c.

285 {
286 .name = "VOLUME",
287 .write = volume_write,
288 .read = volume_read,
289};

Referenced by load_module(), and unload_module().

◆ volume_opts

const struct ast_app_option volume_opts[128] = { [ 'p' ] = { .flag = VOLUMEFLAG_CHANGE }, }
static

Definition at line 100 of file func_volume.c.

Referenced by volume_write().