| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2006-04-17 16:42:21 +00:00
										 |  |  |  * Copyright (C) 1999 - 2006, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \brief Network broadcast sound support channel driver | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \ingroup channel_drivers | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<depend>nbs</depend> | 
					
						
							| 
									
										
										
										
											2011-07-14 20:28:54 +00:00
										 |  |  | 	<support_level>extended</support_level>	 | 
					
						
							| 
									
										
										
										
											2006-04-24 17:11:45 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | #include <sys/socket.h>
 | 
					
						
							|  |  |  | #include <sys/time.h>
 | 
					
						
							|  |  |  | #include <arpa/inet.h>
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #include <sys/ioctl.h>
 | 
					
						
							|  |  |  | #include <nbs.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							| 
									
										
										
										
											2005-10-27 02:19:37 +00:00
										 |  |  | #include "asterisk/utils.h"
 | 
					
						
							| 
									
										
										
										
											2005-06-06 21:09:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static const char tdesc[] = "Network Broadcast Sound Driver"; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Only linear is allowed */ | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | static struct ast_format prefformat; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char context[AST_MAX_EXTENSION] = "default"; | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const char type[] = "NBS"; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* NBS creates private structures on demand */ | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  | struct nbs_pvt { | 
					
						
							|  |  |  | 	NBS *nbs; | 
					
						
							|  |  |  | 	struct ast_channel *owner;		/* Channel we belong to, possibly NULL */ | 
					
						
							|  |  |  | 	char app[16];					/* Our app */ | 
					
						
							|  |  |  | 	char stream[80];				/* Our stream */ | 
					
						
							|  |  |  | 	struct ast_frame fr;			/* "null" frame */ | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	struct ast_module_user *u;		/*! for holding a reference to this module */ | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 19:53:38 +00:00
										 |  |  | 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 int nbs_call(struct ast_channel *ast, const char *dest, int timeout); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static int nbs_hangup(struct ast_channel *ast); | 
					
						
							|  |  |  | static struct ast_frame *nbs_xread(struct ast_channel *ast); | 
					
						
							|  |  |  | static int nbs_xwrite(struct ast_channel *ast, struct ast_frame *frame); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | static struct ast_channel_tech nbs_tech = { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	.type = type, | 
					
						
							|  |  |  | 	.description = tdesc, | 
					
						
							|  |  |  | 	.requester = nbs_request, | 
					
						
							|  |  |  | 	.call = nbs_call, | 
					
						
							|  |  |  | 	.hangup = nbs_hangup, | 
					
						
							|  |  |  | 	.read = nbs_xread, | 
					
						
							|  |  |  | 	.write = nbs_xwrite, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 19:53:38 +00:00
										 |  |  | static int nbs_call(struct ast_channel *ast, const char *dest, int timeout) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct nbs_pvt *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	p = ast_channel_tech_pvt(ast); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	if ((ast_channel_state(ast) != AST_STATE_DOWN) && (ast_channel_state(ast) != AST_STATE_RESERVED)) { | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "nbs_call called on %s, neither down nor reserved\n", ast_channel_name(ast)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* When we call, it just works, really, there's no destination...  Just
 | 
					
						
							|  |  |  | 	   ring the phone and wait for someone to answer */ | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 	ast_debug(1, "Calling %s on %s\n", dest, ast_channel_name(ast)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If we can't connect, return congestion */ | 
					
						
							|  |  |  | 	if (nbs_connect(p->nbs)) { | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "NBS Connection failed on %s\n", ast_channel_name(ast)); | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 		ast_queue_control(ast, AST_CONTROL_CONGESTION); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_setstate(ast, AST_STATE_RINGING); | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 		ast_queue_control(ast, AST_CONTROL_ANSWER); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void nbs_destroy(struct nbs_pvt *p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (p->nbs) | 
					
						
							|  |  |  | 		nbs_delstream(p->nbs); | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_user_remove(p->u); | 
					
						
							| 
									
										
										
										
											2007-06-03 06:10:27 +00:00
										 |  |  | 	ast_free(p); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 19:53:38 +00:00
										 |  |  | static struct nbs_pvt *nbs_alloc(const char *data) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct nbs_pvt *p; | 
					
						
							|  |  |  | 	int flags = 0; | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 	char stream[256]; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	char *opts; | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 	ast_copy_string(stream, data, sizeof(stream)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	if ((opts = strchr(stream, ':'))) { | 
					
						
							|  |  |  | 		*opts = '\0'; | 
					
						
							|  |  |  | 		opts++; | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		opts = ""; | 
					
						
							| 
									
										
										
										
											2007-06-03 06:10:27 +00:00
										 |  |  | 	p = ast_calloc(1, sizeof(*p)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	if (p) { | 
					
						
							| 
									
										
										
										
											2005-10-27 02:19:37 +00:00
										 |  |  | 		if (!ast_strlen_zero(opts)) { | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 			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; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 		ast_copy_string(p->stream, stream, sizeof(p->stream)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		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); | 
					
						
							| 
									
										
										
										
											2007-06-03 06:10:27 +00:00
										 |  |  | 			ast_free(p); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 			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_hangup(struct ast_channel *ast) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct nbs_pvt *p; | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	p = ast_channel_tech_pvt(ast); | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 	ast_debug(1, "nbs_hangup(%s)\n", ast_channel_name(ast)); | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	if (!ast_channel_tech_pvt(ast)) { | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Asked to hangup channel not connected\n"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	nbs_destroy(p); | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	ast_channel_tech_pvt_set(ast, NULL); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	ast_setstate(ast, AST_STATE_DOWN); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-20 07:16:27 +00:00
										 |  |  | static struct ast_frame  *nbs_xread(struct ast_channel *ast) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	struct nbs_pvt *p = ast_channel_tech_pvt(ast); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Some nice norms */ | 
					
						
							|  |  |  | 	p->fr.datalen = 0; | 
					
						
							|  |  |  | 	p->fr.samples = 0; | 
					
						
							| 
									
										
										
										
											2008-05-22 17:50:40 +00:00
										 |  |  | 	p->fr.data.ptr =  NULL; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	p->fr.src = type; | 
					
						
							|  |  |  | 	p->fr.offset = 0; | 
					
						
							|  |  |  | 	p->fr.mallocd=0; | 
					
						
							| 
									
										
										
										
											2004-06-24 13:27:44 +00:00
										 |  |  | 	p->fr.delivery.tv_sec = 0; | 
					
						
							|  |  |  | 	p->fr.delivery.tv_usec = 0; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 	ast_debug(1, "Returning null frame on %s\n", ast_channel_name(ast)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return &p->fr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int nbs_xwrite(struct ast_channel *ast, struct ast_frame *frame) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	struct nbs_pvt *p = ast_channel_tech_pvt(ast); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	/* 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; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | 	if (frame->subclass.format.id != (AST_FORMAT_SLINEAR)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(&frame->subclass.format)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 	if (ast_channel_state(ast) != AST_STATE_UP) { | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		/* Don't try tos end audio on-hook */ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-05-22 17:50:40 +00:00
										 |  |  | 	if (nbs_write(p->nbs, frame->data.ptr, frame->datalen / 2) < 0)  | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | static struct ast_channel *nbs_new(struct nbs_pvt *i, int state, const char *linkedid) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct ast_channel *tmp; | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 	tmp = ast_channel_alloc(1, state, 0, 0, "", "s", context, linkedid, 0, "NBS/%s", i->stream); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	if (tmp) { | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 		ast_channel_tech_set(tmp, &nbs_tech); | 
					
						
							| 
									
										
										
										
											2007-08-08 21:44:58 +00:00
										 |  |  | 		ast_channel_set_fd(tmp, 0, nbs_fd(i->nbs)); | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 		ast_format_cap_add(ast_channel_nativeformats(tmp), &prefformat); | 
					
						
							| 
									
										
										
										
											2012-02-24 00:32:20 +00:00
										 |  |  | 		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); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		if (state == AST_STATE_RING) | 
					
						
							| 
									
										
										
										
											2012-02-20 23:43:27 +00:00
										 |  |  | 			ast_channel_rings_set(tmp, 1); | 
					
						
							|  |  |  | 		ast_channel_tech_pvt_set(tmp, i); | 
					
						
							| 
									
										
										
										
											2012-02-13 17:27:06 +00:00
										 |  |  | 		ast_channel_context_set(tmp, context); | 
					
						
							|  |  |  | 		ast_channel_exten_set(tmp, "s"); | 
					
						
							| 
									
										
										
										
											2012-01-24 20:12:09 +00:00
										 |  |  | 		ast_channel_language_set(tmp, ""); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		i->owner = tmp; | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 		i->u = ast_module_user_add(tmp); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		if (state != AST_STATE_DOWN) { | 
					
						
							|  |  |  | 			if (ast_pbx_start(tmp)) { | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(tmp)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 				ast_hangup(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); | 
					
						
							|  |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-01 19:53:38 +00:00
										 |  |  | static struct ast_channel *nbs_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct nbs_pvt *p; | 
					
						
							|  |  |  | 	struct ast_channel *tmp = NULL; | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = nbs_alloc(data); | 
					
						
							| 
									
										
										
										
											2003-04-09 04:22:25 +00:00
										 |  |  | 	if (p) { | 
					
						
							| 
									
										
										
										
											2012-01-24 20:12:09 +00:00
										 |  |  | 		tmp = nbs_new(p, AST_STATE_DOWN, requestor ? ast_channel_linkedid(requestor) : NULL); | 
					
						
							| 
									
										
										
										
											2003-04-09 04:22:25 +00:00
										 |  |  | 		if (!tmp) | 
					
						
							|  |  |  | 			nbs_destroy(p); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* First, take us out of the channel loop */ | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	ast_channel_unregister(&nbs_tech); | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | 	nbs_tech.capabilities = ast_format_cap_destroy(nbs_tech.capabilities); | 
					
						
							| 
									
										
										
										
											2003-12-09 23:55:17 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | 	ast_format_set(&prefformat, AST_FORMAT_SLINEAR, 0); | 
					
						
							| 
									
										
										
										
											2011-03-04 17:40:02 +00:00
										 |  |  | 	if (!(nbs_tech.capabilities = ast_format_cap_alloc())) { | 
					
						
							|  |  |  | 		return AST_MODULE_LOAD_FAILURE; | 
					
						
							| 
									
										
										
										
											2011-02-03 16:22:10 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ast_format_cap_add(nbs_tech.capabilities, &prefformat); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	/* Make sure we can register our channel type */ | 
					
						
							|  |  |  | 	if (ast_channel_register(&nbs_tech)) { | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", type); | 
					
						
							| 
									
										
										
										
											2011-03-04 17:40:02 +00:00
										 |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-03-04 17:40:02 +00:00
										 |  |  | 	return AST_MODULE_LOAD_SUCCESS; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Network Broadcast Sound Support"); |