Network broadcast sound support channel driver. More...
#include "asterisk.h"#include <sys/socket.h>#include <sys/time.h>#include <arpa/inet.h>#include <fcntl.h>#include <sys/ioctl.h>#include <nbs.h>#include "asterisk/lock.h"#include "asterisk/channel.h"#include "asterisk/config.h"#include "asterisk/module.h"#include "asterisk/pbx.h"#include "asterisk/utils.h"
Go to the source code of this file.
Data Structures | |
| struct | nbs_pvt |
Functions | |
| static void | __reg_module (void) |
| static void | __unreg_module (void) |
| static int | load_module (void) |
| static struct nbs_pvt * | nbs_alloc (const char *data) |
| static int | nbs_call (struct ast_channel *ast, const char *dest, int timeout) |
| static void | nbs_destroy (struct nbs_pvt *p) |
| static int | nbs_hangup (struct ast_channel *ast) |
| static struct ast_channel * | nbs_new (struct nbs_pvt *i, int state, const char *linkedid) |
| static struct ast_channel * | nbs_request (const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause) |
| static struct ast_frame * | nbs_xread (struct ast_channel *ast) |
| static int | nbs_xwrite (struct ast_channel *ast, 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 = "Network Broadcast Sound Support" , .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_DEFAULT, } |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static char | context [AST_MAX_EXTENSION] = "default" |
| static struct ast_channel_tech | nbs_tech |
| static struct ast_format | prefformat |
| static const char | tdesc [] = "Network Broadcast Sound Driver" |
| static const char | type [] = "NBS" |
Network broadcast sound support channel driver.
Definition in file chan_nbs.c.
| static void __reg_module | ( | void | ) | [static] |
Definition at line 296 of file chan_nbs.c.
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 296 of file chan_nbs.c.
| static int load_module | ( | void | ) | [static] |
Definition at line 281 of file chan_nbs.c.
References ast_channel_register(), ast_format_cap_add(), ast_format_cap_alloc(), ast_format_set(), AST_FORMAT_SLINEAR, ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_channel_tech::capabilities, LOG_ERROR, and prefformat.
{
ast_format_set(&prefformat, AST_FORMAT_SLINEAR, 0);
if (!(nbs_tech.capabilities = ast_format_cap_alloc())) {
return AST_MODULE_LOAD_FAILURE;
}
ast_format_cap_add(nbs_tech.capabilities, &prefformat);
/* Make sure we can register our channel type */
if (ast_channel_register(&nbs_tech)) {
ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}
Definition at line 120 of file chan_nbs.c.
References ast_calloc, ast_copy_string(), ast_free, ast_log(), ast_strlen_zero(), LOG_WARNING, nbs_pvt::nbs, and nbs_pvt::stream.
Referenced by nbs_request().
{
struct nbs_pvt *p;
int flags = 0;
char stream[256];
char *opts;
ast_copy_string(stream, data, sizeof(stream));
if ((opts = strchr(stream, ':'))) {
*opts = '\0';
opts++;
} else
opts = "";
p = ast_calloc(1, sizeof(*p));
if (p) {
if (!ast_strlen_zero(opts)) {
if (strchr(opts, 'm'))
flags |= NBS_FLAG_MUTE;
if (strchr(opts, 'o'))
flags |= NBS_FLAG_OVERSPEAK;
if (strchr(opts, 'e'))
flags |= NBS_FLAG_EMERGENCY;
if (strchr(opts, 'O'))
flags |= NBS_FLAG_OVERRIDE;
} else
flags = NBS_FLAG_OVERSPEAK;
ast_copy_string(p->stream, stream, sizeof(p->stream));
p->nbs = nbs_newstream("asterisk", stream, flags);
if (!p->nbs) {
ast_log(LOG_WARNING, "Unable to allocate new NBS stream '%s' with flags %d\n", stream, flags);
ast_free(p);
p = NULL;
} else {
/* Set for 8000 hz mono, 640 samples */
nbs_setbitrate(p->nbs, 8000);
nbs_setchannels(p->nbs, 1);
nbs_setblocksize(p->nbs, 640);
nbs_setblocking(p->nbs, 0);
}
}
return p;
}
| static int nbs_call | ( | struct ast_channel * | ast, |
| const char * | dest, | ||
| int | timeout | ||
| ) | [static] |
Definition at line 86 of file chan_nbs.c.
References ast_channel_name(), ast_channel_tech_pvt(), AST_CONTROL_ANSWER, AST_CONTROL_CONGESTION, ast_debug, ast_log(), ast_queue_control(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RINGING, LOG_WARNING, and nbs_pvt::nbs.
{
struct nbs_pvt *p;
p = ast_channel_tech_pvt(ast);
if ((ast_channel_state(ast) != AST_STATE_DOWN) && (ast_channel_state(ast) != AST_STATE_RESERVED)) {
ast_log(LOG_WARNING, "nbs_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
return -1;
}
/* When we call, it just works, really, there's no destination... Just
ring the phone and wait for someone to answer */
ast_debug(1, "Calling %s on %s\n", dest, ast_channel_name(ast));
/* If we can't connect, return congestion */
if (nbs_connect(p->nbs)) {
ast_log(LOG_WARNING, "NBS Connection failed on %s\n", ast_channel_name(ast));
ast_queue_control(ast, AST_CONTROL_CONGESTION);
} else {
ast_setstate(ast, AST_STATE_RINGING);
ast_queue_control(ast, AST_CONTROL_ANSWER);
}
return 0;
}
| static void nbs_destroy | ( | struct nbs_pvt * | p | ) | [static] |
Definition at line 112 of file chan_nbs.c.
References ast_free, ast_module_user_remove, nbs_pvt::nbs, and nbs_pvt::u.
Referenced by nbs_hangup(), and nbs_request().
{
if (p->nbs)
nbs_delstream(p->nbs);
ast_module_user_remove(p->u);
ast_free(p);
}
| static int nbs_hangup | ( | struct ast_channel * | ast | ) | [static] |
Definition at line 164 of file chan_nbs.c.
References ast_channel_name(), ast_channel_tech_pvt(), ast_channel_tech_pvt_set(), ast_debug, ast_log(), ast_setstate(), AST_STATE_DOWN, LOG_WARNING, and nbs_destroy().
{
struct nbs_pvt *p;
p = ast_channel_tech_pvt(ast);
ast_debug(1, "nbs_hangup(%s)\n", ast_channel_name(ast));
if (!ast_channel_tech_pvt(ast)) {
ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
return 0;
}
nbs_destroy(p);
ast_channel_tech_pvt_set(ast, NULL);
ast_setstate(ast, AST_STATE_DOWN);
return 0;
}
| static struct ast_channel* nbs_new | ( | struct nbs_pvt * | i, |
| int | state, | ||
| const char * | linkedid | ||
| ) | [static, read] |
Definition at line 221 of file chan_nbs.c.
References ast_channel_alloc(), ast_channel_context_set(), ast_channel_exten_set(), ast_channel_name(), ast_channel_nativeformats(), ast_channel_rawreadformat(), ast_channel_rawwriteformat(), ast_channel_readformat(), ast_channel_rings_set(), ast_channel_set_fd(), ast_channel_tech_pvt_set(), ast_channel_tech_set(), ast_channel_writeformat(), ast_format_cap_add(), ast_format_copy(), ast_hangup(), ast_log(), ast_module_user_add, ast_pbx_start(), AST_STATE_DOWN, AST_STATE_RING, LOG_WARNING, nbs_pvt::nbs, nbs_pvt::owner, prefformat, nbs_pvt::stream, and nbs_pvt::u.
Referenced by nbs_request().
{
struct ast_channel *tmp;
tmp = ast_channel_alloc(1, state, 0, 0, "", "s", context, linkedid, 0, "NBS/%s", i->stream);
if (tmp) {
ast_channel_tech_set(tmp, &nbs_tech);
ast_channel_set_fd(tmp, 0, nbs_fd(i->nbs));
ast_format_cap_add(ast_channel_nativeformats(tmp), &prefformat);
ast_format_copy(ast_channel_rawreadformat(tmp), &prefformat);
ast_format_copy(ast_channel_rawwriteformat(tmp), &prefformat);
ast_format_copy(ast_channel_writeformat(tmp), &prefformat);
ast_format_copy(ast_channel_readformat(tmp), &prefformat);
if (state == AST_STATE_RING)
ast_channel_rings_set(tmp, 1);
ast_channel_tech_pvt_set(tmp, i);
ast_channel_context_set(tmp, context);
ast_channel_exten_set(tmp, "s");
ast_channel_language_set(tmp, "");
i->owner = tmp;
i->u = ast_module_user_add(tmp);
if (state != AST_STATE_DOWN) {
if (ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp));
ast_hangup(tmp);
}
}
} else
ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
return tmp;
}
| static struct ast_channel * nbs_request | ( | const char * | type, |
| struct ast_format_cap * | cap, | ||
| const struct ast_channel * | requestor, | ||
| const char * | data, | ||
| int * | cause | ||
| ) | [static, read] |
Definition at line 254 of file chan_nbs.c.
References ast_channel_linkedid(), ast_format_cap_iscompatible(), ast_getformatname_multiple(), ast_log(), AST_STATE_DOWN, LOG_NOTICE, nbs_alloc(), nbs_destroy(), nbs_new(), and prefformat.
{
struct nbs_pvt *p;
struct ast_channel *tmp = NULL;
if (!(ast_format_cap_iscompatible(cap, &prefformat))) {
char tmp[256];
ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname_multiple(tmp, sizeof(tmp), cap));
return NULL;
}
p = nbs_alloc(data);
if (p) {
tmp = nbs_new(p, AST_STATE_DOWN, requestor ? ast_channel_linkedid(requestor) : NULL);
if (!tmp)
nbs_destroy(p);
}
return tmp;
}
| static struct ast_frame * nbs_xread | ( | struct ast_channel * | ast | ) | [static, read] |
Definition at line 179 of file chan_nbs.c.
References ast_channel_name(), ast_channel_tech_pvt(), ast_debug, ast_frame::data, ast_frame::datalen, ast_frame::delivery, nbs_pvt::fr, ast_frame::mallocd, ast_frame::offset, ast_frame::ptr, ast_frame::samples, ast_frame::src, and type.
{
struct nbs_pvt *p = ast_channel_tech_pvt(ast);
/* Some nice norms */
p->fr.datalen = 0;
p->fr.samples = 0;
p->fr.data.ptr = NULL;
p->fr.src = type;
p->fr.offset = 0;
p->fr.mallocd=0;
p->fr.delivery.tv_sec = 0;
p->fr.delivery.tv_usec = 0;
ast_debug(1, "Returning null frame on %s\n", ast_channel_name(ast));
return &p->fr;
}
| static int nbs_xwrite | ( | struct ast_channel * | ast, |
| struct ast_frame * | frame | ||
| ) | [static] |
Definition at line 199 of file chan_nbs.c.
References ast_channel_tech_pvt(), AST_FORMAT_SLINEAR, AST_FRAME_IMAGE, AST_FRAME_VOICE, ast_getformatname(), ast_log(), AST_STATE_UP, ast_frame::data, ast_frame::datalen, ast_frame_subclass::format, ast_frame::frametype, ast_format::id, LOG_WARNING, nbs_pvt::nbs, ast_frame::ptr, and ast_frame::subclass.
{
struct nbs_pvt *p = ast_channel_tech_pvt(ast);
/* Write a frame of (presumably voice) data */
if (frame->frametype != AST_FRAME_VOICE) {
if (frame->frametype != AST_FRAME_IMAGE)
ast_log(LOG_WARNING, "Don't know what to do with frame type '%d'\n", frame->frametype);
return 0;
}
if (frame->subclass.format.id != (AST_FORMAT_SLINEAR)) {
ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(&frame->subclass.format));
return 0;
}
if (ast_channel_state(ast) != AST_STATE_UP) {
/* Don't try tos end audio on-hook */
return 0;
}
if (nbs_write(p->nbs, frame->data.ptr, frame->datalen / 2) < 0)
return -1;
return 0;
}
| static int unload_module | ( | void | ) | [static] |
Definition at line 273 of file chan_nbs.c.
References ast_channel_unregister(), ast_format_cap_destroy(), and ast_channel_tech::capabilities.
{
/* First, take us out of the channel loop */
ast_channel_unregister(&nbs_tech);
nbs_tech.capabilities = ast_format_cap_destroy(nbs_tech.capabilities);
return 0;
}
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Network Broadcast Sound Support" , .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_DEFAULT, } [static] |
Definition at line 296 of file chan_nbs.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 296 of file chan_nbs.c.
char context[AST_MAX_EXTENSION] = "default" [static] |
Definition at line 56 of file chan_nbs.c.
struct ast_channel_tech nbs_tech [static] |
Definition at line 76 of file chan_nbs.c.
struct ast_format prefformat [static] |
Definition at line 54 of file chan_nbs.c.
Referenced by load_module(), nbs_new(), and nbs_request().
const char tdesc[] = "Network Broadcast Sound Driver" [static] |
Definition at line 51 of file chan_nbs.c.
const char type[] = "NBS" [static] |
Definition at line 57 of file chan_nbs.c.
Referenced by __ast_data_add(), __ast_data_add_structure(), __ast_data_search_cmp_structure(), __send_command(), _build_port_config(), _fill_defaults(), _free_port_cfg(), aji_handle_presence(), ast_aoc_add_unit_entry(), ast_aoc_set_total_type(), ast_audiohook_init(), ast_call_forward(), ast_cc_monitor_count(), ast_do_masquerade(), ast_format_str_reduce(), ast_rtp_codecs_find_payload_code(), ast_rtp_codecs_get_payload_format(), ast_rtp_codecs_payload_code(), ast_rtp_codecs_payload_lookup(), ast_rtp_codecs_payloads_copy(), ast_rtp_codecs_payloads_default(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_rtp_instance_make_compatible(), ast_set_lock_type(), ast_var_channels_table(), ast_writestream(), check_header(), conf_run(), create_dtmf_frame(), dahdi_pri_cc_agent_init(), dahdi_setoption(), dahdiras_exec(), eventhandler(), find_agent_callbacks(), find_subscription_type(), flash_exec(), func_channel_read(), func_confbridge_info(), g723_len(), get_proto(), get_sdp_line(), h264_decap(), handle_cli_iax2_show_threads(), handle_missing_table(), handle_showchan(), hangupcause_read(), jingle_add_payloads_to_description(), jingle_interpret_ice_udp_transport(), link_option_to_types(), misdn_cfg_get(), misdn_cfg_get_config_string(), msg_timestamp(), multicast_rtp_new(), multiple_by_type_cb(), nbs_xread(), npval(), originate_exec(), osp_check_destination(), osp_lookup(), osp_next(), osplookup_exec(), ospnext_exec(), park_call_full(), parse_connect(), parse_facility(), parse_information(), parse_notify(), parse_setup(), process_category(), process_request(), process_sdp(), pvalCreateNode(), queue_put(), realtime_sqlite3_require(), remote_bridge_loop(), require_curl(), require_odbc(), require_pgsql(), rtp_payload_type_add_ast(), rtp_payload_type_add_nonast(), rtp_payload_type_find_format(), rtp_payload_type_find_nonast_format(), rtp_payload_type_hash(), schedule_delivery(), serialize_showchan(), set_next_mime_type(), setup_env(), sig_pri_aoc_d_from_pri(), sig_pri_aoc_e_from_pri(), sip_acf_channel_read(), sip_cc_agent_init(), sla_load_config(), sla_queue_event_full(), softhangup_exec(), subscription_type2str(), transfer_exec(), try_calling(), xmpp_pak_presence(), and yyparse().