Bridge Interaction Channel. More...
#include "asterisk.h"
#include <fcntl.h>
#include <sys/signal.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/bridging.h"
Go to the source code of this file.
Data Structures | |
struct | bridge_pvt |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static struct ast_channel * | bridge_bridgedchannel (struct ast_channel *chan, struct ast_channel *bridge) |
Called when the user of this channel wants to get the actual channel in the bridge. | |
static int | bridge_call (struct ast_channel *ast, char *dest, int timeout) |
Called when the channel should actually be dialed. | |
static int | bridge_hangup (struct ast_channel *ast) |
Called when a channel should be hung up. | |
static void | bridge_queue_hangup (struct bridge_pvt *p, struct ast_channel *us) |
Helper function to not deadlock when queueing the hangup frame. | |
static struct ast_frame * | bridge_read (struct ast_channel *ast) |
Called when a frame should be read from the channel. | |
static struct ast_channel * | bridge_request (const char *type, int format, void *data, int *cause) |
Called when we want to place a call somewhere, but not actually call it... yet. | |
static int | bridge_write (struct ast_channel *ast, struct ast_frame *f) |
Called when a frame should be written out to a channel. | |
static int | load_module (void) |
Load module into PBX, register channel. | |
static int | unload_module (void) |
Unload the bridge interaction channel from Asterisk. | |
Variables | |
static struct ast_module_info __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Bridge Interaction Channel" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
static struct ast_module_info * | ast_module_info = &__mod_info |
static struct ast_channel_tech | bridge_tech |
Bridge Interaction Channel.
Definition in file chan_bridge.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 246 of file chan_bridge.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 246 of file chan_bridge.c.
static struct ast_channel * bridge_bridgedchannel | ( | struct ast_channel * | chan, |
struct ast_channel * | bridge | ||
) | [static, read] |
Called when the user of this channel wants to get the actual channel in the bridge.
Definition at line 78 of file chan_bridge.c.
References bridge_pvt::input, bridge_pvt::output, and ast_channel::tech_pvt.
{ struct bridge_pvt *p = chan->tech_pvt; return (chan == p->input) ? p->output : bridge; }
static int bridge_call | ( | struct ast_channel * | ast, |
char * | dest, | ||
int | timeout | ||
) | [static] |
Called when the channel should actually be dialed.
Definition at line 120 of file chan_bridge.c.
References ast_bridge_impart(), ast_channel::bridge, bridge_pvt::input, bridge_pvt::output, and ast_channel::tech_pvt.
{ struct bridge_pvt *p = ast->tech_pvt; /* If no bridge has been provided on the input channel, bail out */ if (!ast->bridge) { return -1; } /* Impart the output channel upon the given bridge of the input channel */ ast_bridge_impart(p->input->bridge, p->output, NULL, NULL); return 0; }
static int bridge_hangup | ( | struct ast_channel * | ast | ) | [static] |
Called when a channel should be hung up.
Definition at line 158 of file chan_bridge.c.
References ast_free, ast_mutex_destroy(), ast_mutex_lock(), ast_mutex_unlock(), bridge_queue_hangup(), bridge_pvt::input, bridge_pvt::lock, bridge_pvt::output, and ast_channel::tech_pvt.
{ struct bridge_pvt *p = ast->tech_pvt; ast_mutex_lock(&p->lock); /* Figure out which channel this is... and set it to NULL as it has gone, but also queue up a hangup frame. */ if (p->input == ast) { if (p->output) { bridge_queue_hangup(p, ast); } p->input = NULL; } else if (p->output == ast) { if (p->input) { bridge_queue_hangup(p, ast); } p->output = NULL; } /* Deal with the Asterisk portion of it */ ast->tech_pvt = NULL; /* If both sides have been terminated free the structure and be done with things */ if (!p->input && !p->output) { ast_mutex_unlock(&p->lock); ast_mutex_destroy(&p->lock); ast_free(p); } else { ast_mutex_unlock(&p->lock); } return 0; }
static void bridge_queue_hangup | ( | struct bridge_pvt * | p, |
struct ast_channel * | us | ||
) | [static] |
Helper function to not deadlock when queueing the hangup frame.
Definition at line 136 of file chan_bridge.c.
References ast_channel_trylock, ast_channel_unlock, ast_mutex_trylock(), ast_mutex_unlock(), ast_queue_hangup(), CHANNEL_DEADLOCK_AVOIDANCE, bridge_pvt::input, bridge_pvt::lock, and bridge_pvt::output.
Referenced by bridge_hangup().
{ struct ast_channel *other = (p->input == us ? p->output : p->input); while (other && ast_channel_trylock(other)) { ast_mutex_unlock(&p->lock); do { CHANNEL_DEADLOCK_AVOIDANCE(us); } while (ast_mutex_trylock(&p->lock)); other = (p->input == us ? p->output : p->input); } /* We basically queue the frame up on the other channel if present */ if (other) { ast_queue_hangup(other); ast_channel_unlock(other); } return; }
static struct ast_frame * bridge_read | ( | struct ast_channel * | ast | ) | [static, read] |
Called when a frame should be read from the channel.
Definition at line 85 of file chan_bridge.c.
References ast_null_frame.
{ return &ast_null_frame; }
static struct ast_channel * bridge_request | ( | const char * | type, |
int | format, | ||
void * | data, | ||
int * | cause | ||
) | [static, read] |
Called when we want to place a call somewhere, but not actually call it... yet.
Definition at line 193 of file chan_bridge.c.
References ast_calloc, ast_channel_alloc(), ast_channel_free(), AST_FORMAT_SLINEAR, ast_free, ast_mutex_init(), AST_STATE_UP, bridge_tech, bridge_pvt::input, bridge_pvt::lock, ast_channel::nativeformats, bridge_pvt::output, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.
{ struct bridge_pvt *p = NULL; /* Try to allocate memory for our very minimal pvt structure */ if (!(p = ast_calloc(1, sizeof(*p)))) { return NULL; } /* Try to grab two Asterisk channels to use as input and output channels */ if (!(p->input = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-input", p))) { ast_free(p); return NULL; } if (!(p->output = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", 0, "Bridge/%p-output", p))) { ast_channel_free(p->input); ast_free(p); return NULL; } /* Setup the lock on the pvt structure, we will need that */ ast_mutex_init(&p->lock); /* Setup parameters on both new channels */ p->input->tech = p->output->tech = &bridge_tech; p->input->tech_pvt = p->output->tech_pvt = p; p->input->nativeformats = p->output->nativeformats = AST_FORMAT_SLINEAR; p->input->readformat = p->output->readformat = AST_FORMAT_SLINEAR; p->input->rawreadformat = p->output->rawreadformat = AST_FORMAT_SLINEAR; p->input->writeformat = p->output->writeformat = AST_FORMAT_SLINEAR; p->input->rawwriteformat = p->output->rawwriteformat = AST_FORMAT_SLINEAR; return p->input; }
static int bridge_write | ( | struct ast_channel * | ast, |
struct ast_frame * | f | ||
) | [static] |
Called when a frame should be written out to a channel.
Definition at line 91 of file chan_bridge.c.
References ast_channel_trylock, ast_channel_unlock, ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), ast_queue_frame(), CHANNEL_DEADLOCK_AVOIDANCE, bridge_pvt::input, bridge_pvt::lock, bridge_pvt::output, and ast_channel::tech_pvt.
{ struct bridge_pvt *p = ast->tech_pvt; struct ast_channel *other; ast_mutex_lock(&p->lock); other = (p->input == ast ? p->output : p->input); while (other && ast_channel_trylock(other)) { ast_mutex_unlock(&p->lock); do { CHANNEL_DEADLOCK_AVOIDANCE(ast); } while (ast_mutex_trylock(&p->lock)); other = (p->input == ast ? p->output : p->input); } /* We basically queue the frame up on the other channel if present */ if (other) { ast_queue_frame(other, f); ast_channel_unlock(other); } ast_mutex_unlock(&p->lock); return 0; }
static int load_module | ( | void | ) | [static] |
Load module into PBX, register channel.
Definition at line 229 of file chan_bridge.c.
References ast_channel_register(), ast_log(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, and LOG_ERROR.
{ /* Make sure we can register our channel type */ if (ast_channel_register(&bridge_tech)) { ast_log(LOG_ERROR, "Unable to register channel class 'Bridge'\n"); return AST_MODULE_LOAD_FAILURE; } return AST_MODULE_LOAD_SUCCESS; }
static int unload_module | ( | void | ) | [static] |
Unload the bridge interaction channel from Asterisk.
Definition at line 240 of file chan_bridge.c.
References ast_channel_unregister().
{ ast_channel_unregister(&bridge_tech); return 0; }
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Bridge Interaction Channel" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 246 of file chan_bridge.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 246 of file chan_bridge.c.
struct ast_channel_tech bridge_tech [static] |
Definition at line 57 of file chan_bridge.c.
Referenced by bridge_request().