Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


func_frame_trace.c File Reference

Trace internal ast_frames on a channel. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/framehook.h"

Go to the source code of this file.

Data Structures

struct  frame_trace_data
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void datastore_destroy_cb (void *data)
 
static int frame_trace_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 void print_frame (struct ast_frame *frame)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Frame Trace for internal ast_frame debugging." , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_datastore_info frame_trace_datastore
 
static struct ast_custom_function frame_trace_function
 
struct {
   const char *   str
 
   enum ast_frame_type   type
 
frametype2str []
 

Detailed Description

Trace internal ast_frames on a channel.

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file func_frame_trace.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 384 of file func_frame_trace.c.

static void __unreg_module ( void  )
static

Definition at line 384 of file func_frame_trace.c.

static void datastore_destroy_cb ( void *  data)
static

Definition at line 104 of file func_frame_trace.c.

References ast_free.

104  {
105  ast_free(data);
106 }
#define ast_free(a)
Definition: astmm.h:97
static int frame_trace_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)
static

Definition at line 149 of file func_frame_trace.c.

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_log(), ast_datastore::data, ast_framehook_interface::data, frametype2str, hook_destroy_cb(), hook_event_cb(), id, frame_trace_data::list_type, LOG_WARNING, str, strcasestr(), frame_trace_data::values, and ast_framehook_interface::version.

150 {
151  struct frame_trace_data *framedata;
152  struct ast_datastore *datastore = NULL;
153  struct ast_framehook_interface interface = {
155  .event_cb = hook_event_cb,
156  .destroy_cb = hook_destroy_cb,
157  };
158  int i = 0;
159 
160  if (!chan) {
161  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
162  return -1;
163  }
164 
165  if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
166  return 0;
167  }
168 
169  interface.data = framedata;
170 
171  if (!strcasecmp(data, "black")) {
172  framedata->list_type = 1;
173  }
174  for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
175  if (strcasestr(value, frametype2str[i].str)) {
176  framedata->values[i] = 1;
177  }
178  }
179 
180  ast_channel_lock(chan);
181  i = ast_framehook_attach(chan, &interface);
182  if (i >= 0) {
183  int *id;
184  if ((datastore = ast_channel_datastore_find(chan, &frame_trace_datastore, NULL))) {
185  id = datastore->data;
186  ast_framehook_detach(chan, *id);
187  ast_channel_datastore_remove(chan, datastore);
188  ast_datastore_free(datastore);
189  }
190 
191  if (!(datastore = ast_datastore_alloc(&frame_trace_datastore, NULL))) {
192  ast_framehook_detach(chan, i);
193  ast_channel_unlock(chan);
194  return 0;
195  }
196 
197  if (!(id = ast_calloc(1, sizeof(int)))) {
198  ast_datastore_free(datastore);
199  ast_framehook_detach(chan, i);
200  ast_channel_unlock(chan);
201  return 0;
202  }
203 
204  *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
205  datastore->data = id;
206  ast_channel_datastore_add(chan, datastore);
207  }
208  ast_channel_unlock(chan);
209 
210  return 0;
211 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
static struct ast_frame * hook_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_framehook_event event, void *data)
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void hook_destroy_cb(void *framedata)
#define LOG_WARNING
Definition: logger.h:144
int ast_framehook_detach(struct ast_channel *chan, int framehook_id)
Detach an framehook from a channel.
Definition: framehook.c:130
static struct ast_datastore_info frame_trace_datastore
Structure for a data store object.
Definition: datastore.h:54
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:2604
const char * str
Definition: app_jack.c:144
int value
Definition: syslog.c:39
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:65
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:94
int values[ARRAY_LEN(frametype2str)]
#define AST_FRAMEHOOK_INTERFACE_VERSION
Definition: framehook.h:202
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_datastore * ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
Definition: datastore.c:98
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void * data
Definition: datastore.h:56
#define ast_calloc(a, b)
Definition: astmm.h:82
enum queue_result id
Definition: app_queue.c:1090
char * strcasestr(const char *, const char *)
static struct @133 frametype2str[]
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2590
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2599
static void hook_destroy_cb ( void *  framedata)
static

Definition at line 113 of file func_frame_trace.c.

References ast_free.

Referenced by frame_trace_helper().

114 {
115  ast_free(framedata);
116 }
#define ast_free(a)
Definition: astmm.h:97
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 118 of file func_frame_trace.c.

References ARRAY_LEN, AST_FRAMEHOOK_EVENT_READ, AST_FRAMEHOOK_EVENT_WRITE, ast_verbose(), ast_frame::frametype, frametype2str, frame_trace_data::list_type, ast_channel::name, print_frame(), show_frame(), and frame_trace_data::values.

Referenced by frame_trace_helper().

119 {
120  int i;
121  int show_frame = 0;
122  struct frame_trace_data *framedata = data;
123  if (!frame) {
124  return frame;
125  }
126 
127  if ((event != AST_FRAMEHOOK_EVENT_WRITE) && (event != AST_FRAMEHOOK_EVENT_READ)) {
128  return frame;
129  }
130 
131  for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
132  if (frame->frametype == frametype2str[i].type) {
133  if ((framedata->list_type == 0) && (framedata->values[i])) { /* white list */
134  show_frame = 1;
135  } else if ((framedata->list_type == 1) && (!framedata->values[i])){ /* black list */
136  show_frame = 1;
137  }
138  break;
139  }
140  }
141 
142  if (show_frame) {
143  ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name);
144  print_frame(frame);
145  }
146  return frame;
147 }
static void print_frame(struct ast_frame *frame)
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
static void show_frame(struct video_desc *env, int out)
Definition: console_gui.c:259
int values[ARRAY_LEN(frametype2str)]
const ast_string_field name
Definition: channel.h:787
enum ast_frame_type frametype
Definition: frame.h:144
static struct @133 frametype2str[]
static int load_module ( void  )
static

Definition at line 378 of file func_frame_trace.c.

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

379 {
382 }
static struct ast_custom_function frame_trace_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static void print_frame ( struct ast_frame frame)
static

Definition at line 213 of file func_frame_trace.c.

References _XXX_AST_CONTROL_T38, AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_END_OF_Q, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_READ_ACTION, AST_CONTROL_REDIRECTING, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_TAKEOFFHOOK, AST_CONTROL_TRANSFER, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, AST_FRAME_CNG, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IAX, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_NULL, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_getformatname(), ast_strlen_zero(), ast_verbose(), ast_frame_subclass::codec, ast_frame::datalen, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::len, ast_frame::samples, ast_frame::src, and ast_frame::subclass.

Referenced by hook_event_cb().

214 {
215  switch (frame->frametype) {
216  case AST_FRAME_DTMF_END:
217  ast_verbose("FrameType: DTMF END\n");
218  ast_verbose("Digit: %d\n", frame->subclass.integer);
219  break;
220  case AST_FRAME_VOICE:
221  ast_verbose("FrameType: VOICE\n");
222  ast_verbose("Codec: %s\n", ast_getformatname(frame->subclass.codec));
223  ast_verbose("MS: %ld\n", frame->len);
224  ast_verbose("Samples: %d\n", frame->samples);
225  ast_verbose("Bytes: %d\n", frame->datalen);
226  break;
227  case AST_FRAME_VIDEO:
228  ast_verbose("FrameType: VIDEO\n");
229  ast_verbose("Codec: %s\n", ast_getformatname(frame->subclass.codec));
230  ast_verbose("MS: %ld\n", frame->len);
231  ast_verbose("Samples: %d\n", frame->samples);
232  ast_verbose("Bytes: %d\n", frame->datalen);
233  break;
234  case AST_FRAME_CONTROL:
235  ast_verbose("FrameType: CONTROL\n");
236  switch ((enum ast_control_frame_type) frame->subclass.integer) {
237  case AST_CONTROL_HANGUP:
238  ast_verbose("SubClass: HANGUP\n");
239  break;
240  case AST_CONTROL_RING:
241  ast_verbose("SubClass: RING\n");
242  break;
243  case AST_CONTROL_RINGING:
244  ast_verbose("SubClass: RINGING\n");
245  break;
246  case AST_CONTROL_ANSWER:
247  ast_verbose("SubClass: ANSWER\n");
248  break;
249  case AST_CONTROL_BUSY:
250  ast_verbose("SubClass: BUSY\n");
251  break;
253  ast_verbose("SubClass: TAKEOFFHOOK\n");
254  break;
255  case AST_CONTROL_OFFHOOK:
256  ast_verbose("SubClass: OFFHOOK\n");
257  break;
259  ast_verbose("SubClass: CONGESTION\n");
260  break;
261  case AST_CONTROL_FLASH:
262  ast_verbose("SubClass: FLASH\n");
263  break;
264  case AST_CONTROL_WINK:
265  ast_verbose("SubClass: WINK\n");
266  break;
267  case AST_CONTROL_OPTION:
268  ast_verbose("SubClass: OPTION\n");
269  break;
271  ast_verbose("SubClass: RADIO KEY\n");
272  break;
274  ast_verbose("SubClass: RADIO UNKEY\n");
275  break;
277  ast_verbose("SubClass: PROGRESS\n");
278  break;
280  ast_verbose("SubClass: PROCEEDING\n");
281  break;
282  case AST_CONTROL_HOLD:
283  ast_verbose("SubClass: HOLD\n");
284  break;
285  case AST_CONTROL_UNHOLD:
286  ast_verbose("SubClass: UNHOLD\n");
287  break;
289  ast_verbose("SubClass: VIDUPDATE\n");
290  break;
292  ast_verbose("SubClass: XXX T38\n");
293  break;
295  ast_verbose("SubClass: SRCUPDATE\n");
296  break;
298  ast_verbose("SubClass: TRANSFER\n");
299  break;
301  ast_verbose("SubClass: CONNECTED LINE\n");
302  break;
304  ast_verbose("SubClass: REDIRECTING\n");
305  break;
307  ast_verbose("SubClass: T38 PARAMETERS\n");
308  break;
309  case AST_CONTROL_CC:
310  ast_verbose("SubClass: CC\n");
311  break;
313  ast_verbose("SubClass: SRCCHANGE\n");
314  break;
316  ast_verbose("SubClass: READ ACTION\n");
317  break;
318  case AST_CONTROL_AOC:
319  ast_verbose("SubClass: AOC\n");
320  break;
322  ast_verbose("SubClass: INCOMPLETE\n");
323  break;
325  ast_verbose("SubClass: END_OF_Q\n");
326  break;
328  ast_verbose("SubClass: UPDATE_RTP_PEER\n");
329  break;
330  }
331 
332  if (frame->subclass.integer == -1) {
333  ast_verbose("SubClass: %d\n", frame->subclass.integer);
334  }
335  ast_verbose("Bytes: %d\n", frame->datalen);
336  break;
337  case AST_FRAME_NULL:
338  ast_verbose("FrameType: NULL\n");
339  break;
340  case AST_FRAME_IAX:
341  ast_verbose("FrameType: IAX\n");
342  break;
343  case AST_FRAME_TEXT:
344  ast_verbose("FrameType: TXT\n");
345  break;
346  case AST_FRAME_IMAGE:
347  ast_verbose("FrameType: IMAGE\n");
348  break;
349  case AST_FRAME_HTML:
350  ast_verbose("FrameType: HTML\n");
351  break;
352  case AST_FRAME_CNG:
353  ast_verbose("FrameType: CNG\n");
354  break;
355  case AST_FRAME_MODEM:
356  ast_verbose("FrameType: MODEM\n");
357  break;
359  ast_verbose("FrameType: DTMF BEGIN\n");
360  ast_verbose("Digit: %d\n", frame->subclass.integer);
361  break;
362  }
363 
364  ast_verbose("Src: %s\n", ast_strlen_zero(frame->src) ? "NOT PRESENT" : frame->src);
365  ast_verbose("\n");
366 }
union ast_frame_subclass subclass
Definition: frame.h:146
void ast_verbose(const char *fmt,...)
Definition: logger.c:1568
format_t codec
Definition: frame.h:137
const char * src
Definition: frame.h:158
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int datalen
Definition: frame.h:148
ast_control_frame_type
Internal control frame subtype field values.
Definition: frame.h:319
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
enum ast_frame_type frametype
Definition: frame.h:144
long len
Definition: frame.h:170
int samples
Definition: frame.h:150
static int unload_module ( void  )
static

Definition at line 373 of file func_frame_trace.c.

References ast_custom_function_unregister().

374 {
376 }
static struct ast_custom_function frame_trace_function
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Frame Trace for internal ast_frame debugging." , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 384 of file func_frame_trace.c.

Definition at line 384 of file func_frame_trace.c.

struct ast_datastore_info frame_trace_datastore
static
Initial value:
= {
.type = "frametrace",
}
static void datastore_destroy_cb(void *data)

Definition at line 108 of file func_frame_trace.c.

struct ast_custom_function frame_trace_function
static
Initial value:
= {
.name = "FRAME_TRACE",
}
static int frame_trace_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)

Definition at line 368 of file func_frame_trace.c.

struct { ... } frametype2str[]
const char* str

Definition at line 83 of file func_frame_trace.c.

enum ast_frame_type type

Definition at line 82 of file func_frame_trace.c.