Sat Mar 10 01:55:25 2012

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 = "88eaa8f5c1bd988bedd71113385e0886" , .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 <dvossel@digium.com>

Definition in file func_frame_trace.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 378 of file func_frame_trace.c.

static void __unreg_module ( void   )  [static]

Definition at line 378 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.

00104                                              {
00105    ast_free(data);
00106 }

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_datastore::data, ast_framehook_interface::data, frame_trace_datastore, frametype2str, hook_destroy_cb(), hook_event_cb(), id, str, strcasestr(), and ast_framehook_interface::version.

00150 {
00151    struct frame_trace_data *framedata;
00152    struct ast_datastore *datastore = NULL;
00153    struct ast_framehook_interface interface = {
00154       .version = AST_FRAMEHOOK_INTERFACE_VERSION,
00155       .event_cb = hook_event_cb,
00156       .destroy_cb = hook_destroy_cb,
00157    };
00158    int i = 0;
00159 
00160    if (!(framedata = ast_calloc(1, sizeof(*framedata)))) {
00161       return 0;
00162    }
00163 
00164    interface.data = framedata;
00165 
00166    if (!strcasecmp(data, "black")) {
00167       framedata->list_type = 1;
00168    }
00169    for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
00170       if (strcasestr(value, frametype2str[i].str)) {
00171          framedata->values[i] = 1;
00172       }
00173    }
00174 
00175    ast_channel_lock(chan);
00176    i = ast_framehook_attach(chan, &interface);
00177    if (i >= 0) {
00178       int *id;
00179       if ((datastore = ast_channel_datastore_find(chan, &frame_trace_datastore, NULL))) {
00180          id = datastore->data;
00181          ast_framehook_detach(chan, *id);
00182          ast_channel_datastore_remove(chan, datastore);
00183       }
00184 
00185       if (!(datastore = ast_datastore_alloc(&frame_trace_datastore, NULL))) {
00186          ast_framehook_detach(chan, i);
00187          ast_channel_unlock(chan);
00188          return 0;
00189       }
00190 
00191       if (!(id = ast_calloc(1, sizeof(int)))) {
00192          ast_datastore_free(datastore);
00193          ast_framehook_detach(chan, i);
00194          ast_channel_unlock(chan);
00195          return 0;
00196       }
00197 
00198       *id = i; /* Store off the id. The channel is still locked so it is safe to access this ptr. */
00199       datastore->data = id;
00200       ast_channel_datastore_add(chan, datastore);
00201    }
00202    ast_channel_unlock(chan);
00203 
00204    return 0;
00205 }

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().

00114 {
00115    ast_free(framedata);
00116 }

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().

00119 {
00120    int i;
00121    int show_frame = 0;
00122    struct frame_trace_data *framedata = data;
00123    if (!frame) {
00124       return frame;
00125    }
00126 
00127    if ((event != AST_FRAMEHOOK_EVENT_WRITE) && (event != AST_FRAMEHOOK_EVENT_READ)) {
00128       return frame;
00129    }
00130 
00131    for (i = 0; i < ARRAY_LEN(frametype2str); i++) {
00132       if (frame->frametype == frametype2str[i].type) {
00133          if ((framedata->list_type == 0) && (framedata->values[i])) { /* white list */
00134             show_frame = 1;
00135          } else if ((framedata->list_type == 1) && (!framedata->values[i])){ /* black list */
00136             show_frame = 1;
00137          }
00138          break;
00139       }
00140    }
00141 
00142    if (show_frame) {
00143       ast_verbose("%s on Channel %s\n", event == AST_FRAMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name);
00144       print_frame(frame);
00145    }
00146    return frame;
00147 }

static int load_module ( void   )  [static]

Definition at line 372 of file func_frame_trace.c.

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and frame_trace_function.

static void print_frame ( struct ast_frame frame  )  [static]

Definition at line 207 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().

00208 {
00209    switch (frame->frametype) {
00210    case AST_FRAME_DTMF_END:
00211       ast_verbose("FrameType: DTMF END\n");
00212       ast_verbose("Digit: %d\n", frame->subclass.integer);
00213       break;
00214    case AST_FRAME_VOICE:
00215       ast_verbose("FrameType: VOICE\n");
00216       ast_verbose("Codec: %s\n", ast_getformatname(frame->subclass.codec));
00217       ast_verbose("MS: %ld\n", frame->len);
00218       ast_verbose("Samples: %d\n", frame->samples);
00219       ast_verbose("Bytes: %d\n", frame->datalen);
00220       break;
00221    case AST_FRAME_VIDEO:
00222       ast_verbose("FrameType: VIDEO\n");
00223       ast_verbose("Codec: %s\n", ast_getformatname(frame->subclass.codec));
00224       ast_verbose("MS: %ld\n", frame->len);
00225       ast_verbose("Samples: %d\n", frame->samples);
00226       ast_verbose("Bytes: %d\n", frame->datalen);
00227       break;
00228    case AST_FRAME_CONTROL:
00229       ast_verbose("FrameType: CONTROL\n");
00230       switch ((enum ast_control_frame_type) frame->subclass.integer) {
00231       case AST_CONTROL_HANGUP:
00232          ast_verbose("SubClass: HANGUP\n");
00233          break;
00234       case AST_CONTROL_RING:
00235          ast_verbose("SubClass: RING\n");
00236          break;
00237       case AST_CONTROL_RINGING:
00238          ast_verbose("SubClass: RINGING\n");
00239          break;
00240       case AST_CONTROL_ANSWER:
00241          ast_verbose("SubClass: ANSWER\n");
00242          break;
00243       case AST_CONTROL_BUSY:
00244          ast_verbose("SubClass: BUSY\n");
00245          break;
00246       case AST_CONTROL_TAKEOFFHOOK:
00247          ast_verbose("SubClass: TAKEOFFHOOK\n");
00248          break;
00249       case AST_CONTROL_OFFHOOK:
00250          ast_verbose("SubClass: OFFHOOK\n");
00251          break;
00252       case AST_CONTROL_CONGESTION:
00253          ast_verbose("SubClass: CONGESTION\n");
00254          break;
00255       case AST_CONTROL_FLASH:
00256          ast_verbose("SubClass: FLASH\n");
00257          break;
00258       case AST_CONTROL_WINK:
00259          ast_verbose("SubClass: WINK\n");
00260          break;
00261       case AST_CONTROL_OPTION:
00262          ast_verbose("SubClass: OPTION\n");
00263          break;
00264       case AST_CONTROL_RADIO_KEY:
00265          ast_verbose("SubClass: RADIO KEY\n");
00266          break;
00267       case AST_CONTROL_RADIO_UNKEY:
00268          ast_verbose("SubClass: RADIO UNKEY\n");
00269          break;
00270       case AST_CONTROL_PROGRESS:
00271          ast_verbose("SubClass: PROGRESS\n");
00272          break;
00273       case AST_CONTROL_PROCEEDING:
00274          ast_verbose("SubClass: PROCEEDING\n");
00275          break;
00276       case AST_CONTROL_HOLD:
00277          ast_verbose("SubClass: HOLD\n");
00278          break;
00279       case AST_CONTROL_UNHOLD:
00280          ast_verbose("SubClass: UNHOLD\n");
00281          break;
00282       case AST_CONTROL_VIDUPDATE:
00283          ast_verbose("SubClass: VIDUPDATE\n");
00284          break;
00285       case _XXX_AST_CONTROL_T38:
00286          ast_verbose("SubClass: XXX T38\n");
00287          break;
00288       case AST_CONTROL_SRCUPDATE:
00289          ast_verbose("SubClass: SRCUPDATE\n");
00290          break;
00291       case AST_CONTROL_TRANSFER:
00292          ast_verbose("SubClass: TRANSFER\n");
00293          break;
00294       case AST_CONTROL_CONNECTED_LINE:
00295          ast_verbose("SubClass: CONNECTED LINE\n");
00296          break;
00297       case AST_CONTROL_REDIRECTING:
00298          ast_verbose("SubClass: REDIRECTING\n");
00299          break;
00300       case AST_CONTROL_T38_PARAMETERS:
00301          ast_verbose("SubClass: T38 PARAMETERS\n");
00302          break;
00303       case AST_CONTROL_CC:
00304          ast_verbose("SubClass: CC\n");
00305          break;
00306       case AST_CONTROL_SRCCHANGE:
00307          ast_verbose("SubClass: SRCCHANGE\n");
00308          break;
00309       case AST_CONTROL_READ_ACTION:
00310          ast_verbose("SubClass: READ ACTION\n");
00311          break;
00312       case AST_CONTROL_AOC:
00313          ast_verbose("SubClass: AOC\n");
00314          break;
00315       case AST_CONTROL_INCOMPLETE:
00316          ast_verbose("SubClass: INCOMPLETE\n");
00317          break;
00318       case AST_CONTROL_END_OF_Q:
00319          ast_verbose("SubClass: END_OF_Q\n");
00320          break;
00321       case AST_CONTROL_UPDATE_RTP_PEER:
00322          ast_verbose("SubClass: UPDATE_RTP_PEER\n");
00323          break;
00324       }
00325       
00326       if (frame->subclass.integer == -1) {
00327          ast_verbose("SubClass: %d\n", frame->subclass.integer);
00328       }
00329       ast_verbose("Bytes: %d\n", frame->datalen);
00330       break;
00331    case AST_FRAME_NULL:
00332       ast_verbose("FrameType: NULL\n");
00333       break;
00334    case AST_FRAME_IAX:
00335       ast_verbose("FrameType: IAX\n");
00336       break;
00337    case AST_FRAME_TEXT:
00338       ast_verbose("FrameType: TXT\n");
00339       break;
00340    case AST_FRAME_IMAGE:
00341       ast_verbose("FrameType: IMAGE\n");
00342       break;
00343    case AST_FRAME_HTML:
00344       ast_verbose("FrameType: HTML\n");
00345       break;
00346    case AST_FRAME_CNG:
00347       ast_verbose("FrameType: CNG\n");
00348       break;
00349    case AST_FRAME_MODEM:
00350       ast_verbose("FrameType: MODEM\n");
00351       break;
00352    case AST_FRAME_DTMF_BEGIN:
00353       ast_verbose("FrameType: DTMF BEGIN\n");
00354       ast_verbose("Digit: %d\n", frame->subclass.integer);
00355       break;
00356    }
00357 
00358    ast_verbose("Src: %s\n", ast_strlen_zero(frame->src) ? "NOT PRESENT" : frame->src);
00359    ast_verbose("\n");
00360 }

static int unload_module ( void   )  [static]

Definition at line 367 of file func_frame_trace.c.

References ast_custom_function_unregister(), and frame_trace_function.

00368 {
00369    return ast_custom_function_unregister(&frame_trace_function);
00370 }


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 = "88eaa8f5c1bd988bedd71113385e0886" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 378 of file func_frame_trace.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 378 of file func_frame_trace.c.

struct ast_datastore_info frame_trace_datastore [static]

Initial value:

 {
   .type = "frametrace",
   .destroy = datastore_destroy_cb
}

Definition at line 108 of file func_frame_trace.c.

Referenced by frame_trace_helper().

struct ast_custom_function frame_trace_function [static]

Initial value:

 {
   .name = "FRAME_TRACE",
   .write = frame_trace_helper,
}

Definition at line 362 of file func_frame_trace.c.

Referenced by load_module(), and unload_module().

struct { ... } frametype2str[] [static]

Referenced by frame_trace_helper(), and hook_event_cb().

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.


Generated on Sat Mar 10 01:55:25 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7