Asterisk - The Open Source Telephony Project GIT-master-1f1c5bb
Data Structures | Functions | Variables
func_scramble.c File Reference

Frequency inverter. 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 <stdio.h>
#include <string.h>
Include dependency graph for func_scramble.c:

Go to the source code of this file.

Data Structures

struct  scramble_information
 

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 void freq_invert (short *amp, int samples)
 
static int load_module (void)
 
static int remove_scrambler (struct ast_channel *chan)
 
static int scramble_callback (struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
 
static int scramble_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Frequency inverting voice scrambler" , .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, .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 scramble_datastore
 Static structure for datastore information. More...
 
static struct ast_custom_function scramble_function
 

Detailed Description

Frequency inverter.

Author
Naveen Albert aster.nosp@m.isk@.nosp@m.phrea.nosp@m.knet.nosp@m..org

Definition in file func_scramble.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 241 of file func_scramble.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 241 of file func_scramble.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 241 of file func_scramble.c.

◆ destroy_callback()

static void destroy_callback ( void *  data)
static

Definition at line 82 of file func_scramble.c.

83{
84 struct scramble_information *ni = data;
85
86 /* Destroy the audiohook, and destroy ourselves */
91 ast_free(ni);
92
93 return;
94}
#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:550
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_scramble.c:76

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

◆ freq_invert()

static void freq_invert ( short *  amp,
int  samples 
)
inlinestatic

Definition at line 103 of file func_scramble.c.

104{
105 int i;
106 /* invert every other sample by 1 */
107 for (i = 0; i < samples; i += 2) {
108 amp[i] = -amp[i];
109 }
110}

Referenced by scramble_callback().

◆ load_module()

static int load_module ( void  )
static

Definition at line 236 of file func_scramble.c.

237{
239}
static struct ast_custom_function scramble_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558

References ast_custom_function_register, and scramble_function.

◆ remove_scrambler()

static int remove_scrambler ( struct ast_channel chan)
static

Definition at line 140 of file func_scramble.c.

141{
142 struct ast_datastore *datastore = NULL;
143 struct scramble_information *data;
144 SCOPED_CHANNELLOCK(chan_lock, chan);
145
147 if (!datastore) {
148 ast_log(AST_LOG_WARNING, "Cannot remove SCRAMBLE from %s: SCRAMBLE not currently enabled\n",
149 ast_channel_name(chan));
150 return -1;
151 }
152 data = datastore->data;
153
154 if (ast_audiohook_remove(chan, &data->audiohook)) {
155 ast_log(AST_LOG_WARNING, "Failed to remove SCRAMBLE audiohook from channel %s\n", ast_channel_name(chan));
156 return -1;
157 }
158
159 if (ast_channel_datastore_remove(chan, datastore)) {
160 ast_log(AST_LOG_WARNING, "Failed to remove SCRAMBLE datastore from channel %s\n",
161 ast_channel_name(chan));
162 return -1;
163 }
164 ast_datastore_free(datastore);
165
166 return 0;
167}
#define ast_log
Definition: astobj2.c:42
int ast_audiohook_remove(struct ast_channel *chan, struct ast_audiohook *audiohook)
Remove an audiohook from a specified channel.
Definition: audiohook.c:721
const char * ast_channel_name(const struct ast_channel *chan)
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2394
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:2399
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
static const struct ast_datastore_info scramble_datastore
Static structure for datastore information.
Definition: func_scramble.c:97
#define AST_LOG_WARNING
#define SCOPED_CHANNELLOCK(varname, chan)
scoped lock specialization for channels.
Definition: lock.h:619
#define NULL
Definition: resample.c:96
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66

References ast_audiohook_remove(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_name(), ast_datastore_free(), ast_log, AST_LOG_WARNING, scramble_information::audiohook, ast_datastore::data, NULL, SCOPED_CHANNELLOCK, and scramble_datastore.

Referenced by scramble_write().

◆ scramble_callback()

static int scramble_callback ( struct ast_audiohook audiohook,
struct ast_channel chan,
struct ast_frame frame,
enum ast_audiohook_direction  direction 
)
static

Definition at line 112 of file func_scramble.c.

113{
114 struct ast_datastore *datastore = NULL;
115 struct scramble_information *ni = NULL;
116
117 /* If the audiohook is stopping it means the channel is shutting down.... but we let the datastore destroy take care of it */
119 return 0;
120 }
121
122 /* Grab datastore which contains our gain information */
123 if (!(datastore = ast_channel_datastore_find(chan, &scramble_datastore, NULL))) {
124 return 0;
125 }
126
127 if (frame->frametype == AST_FRAME_VOICE) { /* only invert voice frequencies */
128 ni = datastore->data;
129 /* Based on direction of frame, and confirm it is applicable */
130 if (!(direction == AST_AUDIOHOOK_DIRECTION_READ ? ni->rx : ni->tx)) {
131 return 0;
132 }
133 /* Scramble the sample now */
134 freq_invert(frame->data.ptr, frame->samples);
135 }
136 return 0;
137}
@ AST_AUDIOHOOK_DIRECTION_READ
Definition: audiohook.h:49
@ AST_AUDIOHOOK_STATUS_DONE
Definition: audiohook.h:45
direction
static void freq_invert(short *amp, int samples)
@ AST_FRAME_VOICE
enum ast_audiohook_status status
Definition: audiohook.h:108
union ast_frame::@226 data
enum ast_frame_type frametype
unsigned short int tx
Definition: func_scramble.c:77
unsigned short int rx
Definition: func_scramble.c:78

References AST_AUDIOHOOK_DIRECTION_READ, AST_AUDIOHOOK_STATUS_DONE, ast_channel_datastore_find(), AST_FRAME_VOICE, scramble_information::audiohook, ast_datastore::data, ast_frame::data, ast_frame::frametype, freq_invert(), NULL, ast_frame::ptr, scramble_information::rx, ast_frame::samples, scramble_datastore, ast_audiohook::status, and scramble_information::tx.

Referenced by scramble_write().

◆ scramble_write()

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

Definition at line 169 of file func_scramble.c.

170{
171 char *parse;
172 struct ast_datastore *datastore = NULL;
173 struct scramble_information *ni = NULL;
174 int tx = 1, rx = 1;
175
178 );
179
180 if (!chan) {
181 ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
182 return -1;
183 }
184
185 parse = ast_strdupa(value);
187
188 if (!strcasecmp(args.direction, "remove")) {
189 return remove_scrambler(chan);
190 }
191 if (!strcasecmp(args.direction, "tx")) {
192 tx = 1;
193 rx = 0;
194 } else if (!strcasecmp(args.direction, "rx")) {
195 rx = 0;
196 tx = 1;
197 } else if (strcasecmp(args.direction, "both")) {
198 ast_log(LOG_ERROR, "Direction must be either RX, TX, both, or remove\n");
199 return -1;
200 }
201 ast_channel_lock(chan);
202 if (!(datastore = ast_channel_datastore_find(chan, &scramble_datastore, NULL))) {
203 /* Allocate a new datastore to hold the reference to this audiohook information */
204 if (!(datastore = ast_datastore_alloc(&scramble_datastore, NULL))) {
205 return 0;
206 }
207 if (!(ni = ast_calloc(1, sizeof(*ni)))) {
208 ast_datastore_free(datastore);
209 return 0;
210 }
213 datastore->data = ni;
214 ast_channel_datastore_add(chan, datastore);
216 } else {
217 ni = datastore->data;
218 }
219 ni->tx = tx;
220 ni->rx = rx;
221 ast_channel_unlock(chan);
222
223 return 0;
224}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#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
int ast_audiohook_attach(struct ast_channel *chan, struct ast_audiohook *audiohook)
Attach audiohook to channel.
Definition: audiohook.c:484
@ 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:2385
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
static int scramble_callback(struct ast_audiohook *audiohook, struct ast_channel *chan, struct ast_frame *frame, enum ast_audiohook_direction direction)
static int remove_scrambler(struct ast_channel *chan)
#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
ast_audiohook_manipulate_callback manipulate_callback
Definition: audiohook.h:118
int value
Definition: syslog.c:37
const char * args

References args, AST_APP_ARG, ast_audiohook_attach(), ast_audiohook_init(), AST_AUDIOHOOK_MANIPULATE_ALL_RATES, AST_AUDIOHOOK_TYPE_MANIPULATE, 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_STANDARD_APP_ARGS, ast_strdupa, scramble_information::audiohook, ast_datastore::data, LOG_ERROR, LOG_WARNING, ast_audiohook::manipulate_callback, NULL, remove_scrambler(), scramble_information::rx, scramble_callback(), scramble_datastore, scramble_information::tx, and value.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 231 of file func_scramble.c.

232{
234}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and scramble_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Frequency inverting voice scrambler" , .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, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 241 of file func_scramble.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 241 of file func_scramble.c.

◆ scramble_datastore

const struct ast_datastore_info scramble_datastore
static
Initial value:
= {
.type = "scramble",
.destroy = destroy_callback
}
static void destroy_callback(void *data)
Definition: func_scramble.c:82

Static structure for datastore information.

Definition at line 97 of file func_scramble.c.

Referenced by remove_scrambler(), scramble_callback(), and scramble_write().

◆ scramble_function

struct ast_custom_function scramble_function
static
Initial value:
= {
.name = "SCRAMBLE",
.write = scramble_write,
}
static int scramble_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)

Definition at line 226 of file func_scramble.c.

Referenced by load_module(), and unload_module().