chan_bridge_media.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2013 Digium, Inc.
00005  *
00006  * Jonathan Rose <jrose@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*!
00020  * \file
00021  * \brief Bridge Media Channels driver
00022  *
00023  * \author Jonathan Rose <jrose@digium.com>
00024  * \author Richard Mudgett <rmudgett@digium.com>
00025  *
00026  * \brief Bridge Media Channels
00027  *
00028  * \ingroup channel_drivers
00029  */
00030 
00031 /*** MODULEINFO
00032    <support_level>core</support_level>
00033  ***/
00034 
00035 #include "asterisk.h"
00036 
00037 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 432834 $")
00038 
00039 #include "asterisk/channel.h"
00040 #include "asterisk/bridge.h"
00041 #include "asterisk/core_unreal.h"
00042 #include "asterisk/module.h"
00043 
00044 static int media_call(struct ast_channel *chan, const char *addr, int timeout)
00045 {
00046    /* ast_call() will fail unconditionally against channels provided by this driver */
00047    return -1;
00048 }
00049 
00050 static int media_hangup(struct ast_channel *ast)
00051 {
00052    struct ast_unreal_pvt *p = ast_channel_tech_pvt(ast);
00053    int res;
00054 
00055    if (!p) {
00056       return -1;
00057    }
00058 
00059    /* Give the pvt a ref to fulfill calling requirements. */
00060    ao2_ref(p, +1);
00061    res = ast_unreal_hangup(p, ast);
00062    ao2_ref(p, -1);
00063 
00064    return res;
00065 }
00066 
00067 static struct ast_channel *announce_request(const char *type, struct ast_format_cap *cap,
00068    const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause);
00069 
00070 static struct ast_channel *record_request(const char *type, struct ast_format_cap *cap,
00071    const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause);
00072 
00073 static struct ast_channel_tech announce_tech = {
00074    .type = "Announcer",
00075    .description = "Bridge Media Announcing Channel Driver",
00076    .requester = announce_request,
00077    .call = media_call,
00078    .hangup = media_hangup,
00079 
00080    .send_digit_begin = ast_unreal_digit_begin,
00081    .send_digit_end = ast_unreal_digit_end,
00082    .read = ast_unreal_read,
00083    .write = ast_unreal_write,
00084    .write_video = ast_unreal_write,
00085    .exception = ast_unreal_read,
00086    .indicate = ast_unreal_indicate,
00087    .fixup = ast_unreal_fixup,
00088    .send_html = ast_unreal_sendhtml,
00089    .send_text = ast_unreal_sendtext,
00090    .queryoption = ast_unreal_queryoption,
00091    .setoption = ast_unreal_setoption,
00092    .properties = AST_CHAN_TP_INTERNAL,
00093 };
00094 
00095 static struct ast_channel_tech record_tech = {
00096    .type = "Recorder",
00097    .description = "Bridge Media Recording Channel Driver",
00098    .requester = record_request,
00099    .call = media_call,
00100    .hangup = media_hangup,
00101 
00102    .send_digit_begin = ast_unreal_digit_begin,
00103    .send_digit_end = ast_unreal_digit_end,
00104    .read = ast_unreal_read,
00105    .write = ast_unreal_write,
00106    .write_video = ast_unreal_write,
00107    .exception = ast_unreal_read,
00108    .indicate = ast_unreal_indicate,
00109    .fixup = ast_unreal_fixup,
00110    .send_html = ast_unreal_sendhtml,
00111    .send_text = ast_unreal_sendtext,
00112    .queryoption = ast_unreal_queryoption,
00113    .setoption = ast_unreal_setoption,
00114    .properties = AST_CHAN_TP_INTERNAL,
00115 };
00116 
00117 static struct ast_channel *media_request_helper(struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids,
00118    const struct ast_channel *requestor, const char *data, struct ast_channel_tech *tech, const char *role)
00119 {
00120    struct ast_channel *chan;
00121    ast_callid callid;
00122 
00123    RAII_VAR(struct ast_unreal_pvt *, pvt, NULL, ao2_cleanup);
00124 
00125    if (!(pvt = ast_unreal_alloc(sizeof(*pvt), ast_unreal_destructor, cap))) {
00126       return NULL;
00127    }
00128 
00129    ast_copy_string(pvt->name, data, sizeof(pvt->name));
00130 
00131    ast_set_flag(pvt, AST_UNREAL_NO_OPTIMIZATION);
00132 
00133    callid = ast_read_threadstorage_callid();
00134 
00135    chan = ast_unreal_new_channels(pvt, tech,
00136       AST_STATE_UP, AST_STATE_UP, NULL, NULL, assignedids, requestor, callid);
00137    if (!chan) {
00138       return NULL;
00139    }
00140 
00141    ast_answer(pvt->owner);
00142    ast_answer(pvt->chan);
00143 
00144    if (ast_channel_add_bridge_role(pvt->chan, role)) {
00145       ast_hangup(chan);
00146       return NULL;
00147    }
00148 
00149    return chan;
00150 }
00151 
00152 static struct ast_channel *announce_request(const char *type, struct ast_format_cap *cap,
00153    const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
00154 {
00155    return media_request_helper(cap, assignedids, requestor, data, &announce_tech, "announcer");
00156 }
00157 
00158 static struct ast_channel *record_request(const char *type, struct ast_format_cap *cap,
00159    const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *data, int *cause)
00160 {
00161    return media_request_helper(cap, assignedids, requestor, data, &record_tech, "recorder");
00162 }
00163 
00164 static void cleanup_capabilities(void)
00165 {
00166    if (announce_tech.capabilities) {
00167       ao2_ref(announce_tech.capabilities, -1);
00168       announce_tech.capabilities = NULL;
00169    }
00170 
00171    if (record_tech.capabilities) {
00172       ao2_ref(record_tech.capabilities, -1);
00173       record_tech.capabilities = NULL;
00174    }
00175 }
00176 
00177 static int unload_module(void)
00178 {
00179    ast_channel_unregister(&announce_tech);
00180    ast_channel_unregister(&record_tech);
00181    cleanup_capabilities();
00182    return 0;
00183 }
00184 
00185 static int load_module(void)
00186 {
00187    announce_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00188    if (!announce_tech.capabilities) {
00189       return AST_MODULE_LOAD_DECLINE;
00190    }
00191 
00192    record_tech.capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
00193    if (!record_tech.capabilities) {
00194       return AST_MODULE_LOAD_DECLINE;
00195    }
00196 
00197    ast_format_cap_append_by_type(announce_tech.capabilities, AST_MEDIA_TYPE_UNKNOWN);
00198    ast_format_cap_append_by_type(record_tech.capabilities, AST_MEDIA_TYPE_UNKNOWN);
00199 
00200    if (ast_channel_register(&announce_tech)) {
00201       ast_log(LOG_ERROR, "Unable to register channel technology %s(%s).\n",
00202          announce_tech.type, announce_tech.description);
00203       cleanup_capabilities();
00204       return AST_MODULE_LOAD_DECLINE;
00205    }
00206 
00207    if (ast_channel_register(&record_tech)) {
00208       ast_log(LOG_ERROR, "Unable to register channel technology %s(%s).\n",
00209          record_tech.type, record_tech.description);
00210       cleanup_capabilities();
00211       return AST_MODULE_LOAD_DECLINE;
00212    }
00213 
00214    return AST_MODULE_LOAD_SUCCESS;
00215 }
00216 
00217 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Bridge Media Channel Driver",
00218    .support_level = AST_MODULE_SUPPORT_CORE,
00219     .load = load_module,
00220     .unload = unload_module,
00221 );

Generated on Thu Apr 16 06:27:18 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6