Sat Feb 11 06:34:29 2012

Asterisk developer's documentation


chan_bridge.c File Reference

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/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/bridging.h"
#include "asterisk/astobj2.h"

Include dependency graph for chan_bridge.c:

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_channelbridge_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, const 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 struct ast_framebridge_read (struct ast_channel *ast)
 Called when a frame should be read from the channel.
static struct ast_channelbridge_request (const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *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 __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Bridge Interaction Channel" , .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_CHANNEL_DRIVER, }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_channel_tech bridge_tech


Detailed Description

Bridge Interaction Channel.

Author:
Joshua Colp <jcolp@digium.com>

Definition in file chan_bridge.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 234 of file chan_bridge.c.

static void __unreg_module ( void   )  [static]

Definition at line 234 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 80 of file chan_bridge.c.

References bridge_pvt::input, bridge_pvt::output, and ast_channel::tech_pvt.

00081 {
00082    struct bridge_pvt *p = chan->tech_pvt;
00083    return (chan == p->input) ? p->output : bridge;
00084 }

static int bridge_call ( struct ast_channel ast,
const char *  dest,
int  timeout 
) [static]

Called when the channel should actually be dialed.

Definition at line 119 of file chan_bridge.c.

References ast_bridge_impart(), ast_channel::bridge, bridge_pvt::input, bridge_pvt::output, and ast_channel::tech_pvt.

00120 {
00121    struct bridge_pvt *p = ast->tech_pvt;
00122 
00123    /* If no bridge has been provided on the input channel, bail out */
00124    if (!ast->bridge) {
00125       return -1;
00126    }
00127 
00128    /* Impart the output channel upon the given bridge of the input channel */
00129    ast_bridge_impart(p->input->bridge, p->output, NULL, NULL, 0);
00130 
00131    return 0;
00132 }

static int bridge_hangup ( struct ast_channel ast  )  [static]

Called when a channel should be hung up.

Definition at line 135 of file chan_bridge.c.

References ao2_lock, ao2_ref, ao2_unlock, bridge_pvt::input, bridge_pvt::output, and ast_channel::tech_pvt.

00136 {
00137    struct bridge_pvt *p = ast->tech_pvt;
00138 
00139    if (!p) {
00140       return 0;
00141    }
00142 
00143    ao2_lock(p);
00144    if (p->input == ast) {
00145       p->input = NULL;
00146    } else if (p->output == ast) {
00147       p->output = NULL;
00148    }
00149    ao2_unlock(p);
00150 
00151    ast->tech_pvt = NULL;
00152    ao2_ref(p, -1);
00153 
00154    return 0;
00155 }

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 87 of file chan_bridge.c.

References ast_null_frame.

00088 {
00089    return &ast_null_frame;
00090 }

static struct ast_channel * bridge_request ( const char *  type,
struct ast_format_cap cap,
const struct ast_channel requestor,
const char *  data,
int *  cause 
) [static, read]

Called when we want to place a call somewhere, but not actually call it... yet.

Definition at line 158 of file chan_bridge.c.

References ao2_alloc, ao2_ref, ast_answer(), ast_channel_alloc, ast_channel_linkedid(), ast_channel_release(), ast_format_cap_add(), ast_format_copy(), ast_format_set(), AST_FORMAT_SLINEAR, AST_STATE_UP, bridge_pvt::input, 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.

00159 {
00160    struct bridge_pvt *p = NULL;
00161    struct ast_format slin;
00162 
00163    /* Try to allocate memory for our very minimal pvt structure */
00164    if (!(p = ao2_alloc(sizeof(*p), NULL))) {
00165       return NULL;
00166    }
00167 
00168    /* Try to grab two Asterisk channels to use as input and output channels */
00169    if (!(p->input = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", requestor ? ast_channel_linkedid(requestor) : NULL, 0, "Bridge/%p-input", p))) {
00170       ao2_ref(p, -1);
00171       return NULL;
00172    }
00173    if (!(p->output = ast_channel_alloc(1, AST_STATE_UP, 0, 0, "", "", "", requestor ? ast_channel_linkedid(requestor) : NULL, 0, "Bridge/%p-output", p))) {
00174       p->input = ast_channel_release(p->input);
00175       ao2_ref(p, -1);
00176       return NULL;
00177    }
00178 
00179    /* Setup parameters on both new channels */
00180    p->input->tech = p->output->tech = &bridge_tech;
00181 
00182    ao2_ref(p, 2);
00183    p->input->tech_pvt = p->output->tech_pvt = p;
00184 
00185    ast_format_set(&slin, AST_FORMAT_SLINEAR, 0);
00186 
00187    ast_format_cap_add(p->input->nativeformats, &slin);
00188    ast_format_cap_add(p->output->nativeformats, &slin);
00189    ast_format_copy(&p->input->readformat, &slin);
00190    ast_format_copy(&p->output->readformat, &slin);
00191    ast_format_copy(&p->input->rawreadformat, &slin);
00192    ast_format_copy(&p->output->rawreadformat, &slin);
00193    ast_format_copy(&p->input->writeformat, &slin);
00194    ast_format_copy(&p->output->writeformat, &slin);
00195    ast_format_copy(&p->input->rawwriteformat, &slin);
00196    ast_format_copy(&p->output->rawwriteformat, &slin);
00197 
00198    ast_answer(p->output);
00199    ast_answer(p->input);
00200 
00201    /* remove the reference from the alloc. The channels now own the pvt. */
00202    ao2_ref(p, -1);
00203    return p->input;
00204 }

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 93 of file chan_bridge.c.

References ao2_lock, ao2_unlock, ast_channel_lock, ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_queue_frame(), bridge_pvt::input, bridge_pvt::output, and ast_channel::tech_pvt.

00094 {
00095    struct bridge_pvt *p = ast->tech_pvt;
00096    struct ast_channel *other = NULL;
00097 
00098    ao2_lock(p);
00099    /* only write frames to output. */
00100    if (p->input == ast) {
00101       other = p->output;
00102       if (other) {
00103          ast_channel_ref(other);
00104       }
00105    }
00106    ao2_unlock(p);
00107 
00108    if (other) {
00109       ast_channel_unlock(ast);
00110       ast_queue_frame(other, f);
00111       ast_channel_lock(ast);
00112       other = ast_channel_unref(other);
00113    }
00114 
00115    return 0;
00116 }

static int load_module ( void   )  [static]

Load module into PBX, register channel.

Definition at line 207 of file chan_bridge.c.

References ast_channel_register(), ast_format_cap_add_all(), ast_format_cap_alloc(), ast_log(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_channel_tech::capabilities, and LOG_ERROR.

00208 {
00209    if (!(bridge_tech.capabilities = ast_format_cap_alloc())) {
00210       return AST_MODULE_LOAD_FAILURE;
00211    }
00212 
00213    ast_format_cap_add_all(bridge_tech.capabilities);
00214    /* Make sure we can register our channel type */
00215    if (ast_channel_register(&bridge_tech)) {
00216       ast_log(LOG_ERROR, "Unable to register channel class 'Bridge'\n");
00217       return AST_MODULE_LOAD_FAILURE;
00218    }
00219    return AST_MODULE_LOAD_SUCCESS;
00220 }

static int unload_module ( void   )  [static]

Unload the bridge interaction channel from Asterisk.

Definition at line 223 of file chan_bridge.c.

References ast_channel_unregister(), ast_format_cap_destroy(), and ast_channel_tech::capabilities.


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Bridge Interaction Channel" , .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_CHANNEL_DRIVER, } [static]

Definition at line 234 of file chan_bridge.c.

Definition at line 234 of file chan_bridge.c.

struct ast_channel_tech bridge_tech [static]

Definition at line 61 of file chan_bridge.c.


Generated on Sat Feb 11 06:34:29 2012 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6