Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Data Structures | Enumerations | Functions | Variables
func_frame_drop.c File Reference

Function that drops specified frames from channels. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/framehook.h"
Include dependency graph for func_frame_drop.c:

Go to the source code of this file.

Data Structures

struct  frame_drop_data
 

Enumerations

enum  direction { TX = 0 , RX }
 

Functions

 AST_MODULE_INFO_STANDARD_EXTENDED (ASTERISK_GPL_KEY, "Function to drop frames on a channel.")
 
static void datastore_destroy_cb (void *data)
 
static int frame_drop_helper (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static void hook_destroy_cb (void *framedata)
 
static struct ast_framehook_event_cb (struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

struct {
   const char *   str
 
   int   type
 
controlframetype2str []
 
static const struct ast_datastore_info frame_drop_datastore
 
static struct ast_custom_function frame_drop_function
 
struct {
   const char *   str
 
   enum ast_frame_type   type
 
frametype2str []
 

Detailed Description

Function that drops specified frames from channels.

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

Definition in file func_frame_drop.c.

Enumeration Type Documentation

◆ direction

enum direction
Enumerator
TX 
RX 

Definition at line 147 of file func_frame_drop.c.

147 {
148 TX = 0,
149 RX,
150};
@ RX
@ TX

Function Documentation

◆ AST_MODULE_INFO_STANDARD_EXTENDED()

AST_MODULE_INFO_STANDARD_EXTENDED ( ASTERISK_GPL_KEY  ,
"Function to drop frames on a channel."   
)

◆ datastore_destroy_cb()

static void datastore_destroy_cb ( void *  data)
static

Definition at line 158 of file func_frame_drop.c.

158 {
159 ast_free(data);
160}
#define ast_free(a)
Definition: astmm.h:180

References ast_free.

◆ frame_drop_helper()

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

Definition at line 213 of file func_frame_drop.c.

214{
215 char *buffer;
216 struct frame_drop_data *framedata;
217 struct ast_datastore *datastore = NULL;
218 struct ast_framehook_interface interface = {
220 .event_cb = hook_event_cb,
221 .destroy_cb = hook_destroy_cb,
222 };
223 int i = 0;
224
225 if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
226 return 0;
227 }
228
229 interface.data = framedata;
230
231 if (!strcasecmp(data, "RX")) {
232 framedata->list_type = RX;
233 } else {
234 framedata->list_type = TX;
235 }
236
237 buffer = ast_malloc(sizeof(value) + 3); /* leading and trailing comma and null terminator */
238 snprintf(buffer, sizeof(value) + 2, ",%s,", value);
239 for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
240 if (strcasestr(buffer, frametype2str[i].str)) {
241 framedata->values[i] = 1;
242 }
243 }
244
245 for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
246 if (strcasestr(buffer, controlframetype2str[i].str)) {
247 framedata->controlvalues[i] = 1;
248 }
249 }
250 ast_free(buffer);
251
252 ast_channel_lock(chan);
253 i = ast_framehook_attach(chan, &interface);
254 if (i >= 0) {
255 int *id;
256 if ((datastore = ast_channel_datastore_find(chan, &frame_drop_datastore, NULL))) {
257 id = datastore->data;
258 ast_framehook_detach(chan, *id);
259 ast_channel_datastore_remove(chan, datastore);
260 ast_datastore_free(datastore);
261 }
262
263 if (!(datastore = ast_datastore_alloc(&frame_drop_datastore, NULL))) {
264 ast_framehook_detach(chan, i);
265 ast_channel_unlock(chan);
266 return 0;
267 }
268
269 if (!(id = ast_calloc(1, sizeof(int)))) {
270 ast_datastore_free(datastore);
271 ast_framehook_detach(chan, i);
272 ast_channel_unlock(chan);
273 return 0;
274 }
275
276 *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
277 datastore->data = id;
278 ast_channel_datastore_add(chan, datastore);
279 }
280 ast_channel_unlock(chan);
281
282 return 0;
283}
enum queue_result id
Definition: app_queue.c:1808
char * strcasestr(const char *, const char *)
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2414
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2423
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
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:2428
#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
int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interface *i)
Attach an framehook onto a channel for frame interception.
Definition: framehook.c:132
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
Definition: framehook.c:177
#define AST_FRAMEHOOK_INTERFACE_VERSION
Definition: framehook.h:227
static struct @170 frametype2str[]
static const struct ast_datastore_info frame_drop_datastore
static struct @171 controlframetype2str[]
static struct ast_frame * hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
static void hook_destroy_cb(void *framedata)
const char * str
#define NULL
Definition: resample.c:96
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
int values[ARRAY_LEN(frametype2str)]
int controlvalues[ARRAY_LEN(controlframetype2str)]
enum direction list_type
int value
Definition: syslog.c:37
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_remove(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), ast_framehook_attach(), ast_framehook_detach(), AST_FRAMEHOOK_INTERFACE_VERSION, ast_free, ast_malloc, controlframetype2str, frame_drop_data::controlvalues, ast_datastore::data, ast_framehook_interface::data, frame_drop_datastore, frametype2str, hook_destroy_cb(), hook_event_cb(), id, frame_drop_data::list_type, NULL, RX, str, strcasestr(), TX, value, frame_drop_data::values, and ast_framehook_interface::version.

◆ hook_destroy_cb()

static void hook_destroy_cb ( void *  framedata)
static

Definition at line 167 of file func_frame_drop.c.

168{
169 ast_free(framedata);
170}

References ast_free.

Referenced by frame_drop_helper().

◆ hook_event_cb()

static struct ast_frame * hook_event_cb ( struct ast_channel chan,
struct ast_frame frame,
enum ast_framehook_event  event,
void *  data 
)
static

Definition at line 172 of file func_frame_drop.c.

173{
174 int i;
175 int drop_frame = 0;
176 struct frame_drop_data *framedata = data;
177 if (!frame) {
178 return frame;
179 }
180
181 if (!((event == AST_FRAMEHOOK_EVENT_WRITE && framedata->list_type == TX) ||
182 (event == AST_FRAMEHOOK_EVENT_READ && framedata->list_type == RX))) {
183 return frame;
184 }
185
186 if (frame->frametype == AST_FRAME_CONTROL) {
187 for (i = 0; i < ARRAY_LEN(controlframetype2str); i++) {
188 if (frame->subclass.integer == controlframetype2str[i].type) {
189 if (framedata->controlvalues[i]) {
190 drop_frame = 1;
191 }
192 break;
193 }
194 }
195 } else {
196 for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
197 if (frame->frametype == frametype2str[i].type) {
198 if (framedata->values[i]) {
199 drop_frame = 1;
200 }
201 break;
202 }
203 }
204 }
205
206 if (drop_frame) {
207 ast_frfree(frame);
208 frame = &ast_null_frame;
209 }
210 return frame;
211}
@ AST_FRAMEHOOK_EVENT_WRITE
Definition: framehook.h:153
@ AST_FRAMEHOOK_EVENT_READ
Definition: framehook.h:152
#define ast_frfree(fr)
@ AST_FRAME_CONTROL
struct ast_frame ast_null_frame
Definition: main/frame.c:79
struct ast_frame_subclass subclass
enum ast_frame_type frametype
Definition: astman.c:222

References ARRAY_LEN, AST_FRAME_CONTROL, AST_FRAMEHOOK_EVENT_READ, AST_FRAMEHOOK_EVENT_WRITE, ast_frfree, ast_null_frame, controlframetype2str, frame_drop_data::controlvalues, ast_frame::frametype, frametype2str, ast_frame_subclass::integer, frame_drop_data::list_type, RX, ast_frame::subclass, TX, and frame_drop_data::values.

Referenced by frame_drop_helper().

◆ load_module()

static int load_module ( void  )
static

Definition at line 295 of file func_frame_drop.c.

296{
299}
static struct ast_custom_function frame_drop_function
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and frame_drop_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 290 of file func_frame_drop.c.

291{
293}
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References ast_custom_function_unregister(), and frame_drop_function.

Variable Documentation

◆ 

struct { ... } controlframetype2str[]

Referenced by frame_drop_helper(), and hook_event_cb().

◆ frame_drop_datastore

const struct ast_datastore_info frame_drop_datastore
static
Initial value:
= {
.type = "framedrop",
}
static void datastore_destroy_cb(void *data)

Definition at line 162 of file func_frame_drop.c.

Referenced by frame_drop_helper().

◆ frame_drop_function

struct ast_custom_function frame_drop_function
static
Initial value:
= {
.name = "FRAME_DROP",
}
static int frame_drop_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)

Definition at line 285 of file func_frame_drop.c.

Referenced by load_module(), and unload_module().

◆ 

struct { ... } frametype2str[]

Referenced by frame_drop_helper(), and hook_event_cb().

◆ str

const char* str

Definition at line 108 of file func_frame_drop.c.

Referenced by frame_drop_helper().

◆ type

int type

Definition at line 107 of file func_frame_drop.c.