| 
									
										
										
										
											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> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 */ | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | static format_t prefformat = AST_FORMAT_SLINEAR; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | static struct ast_channel *nbs_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | static int nbs_call(struct ast_channel *ast, char *dest, int timeout); | 
					
						
							|  |  |  | 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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct ast_channel_tech nbs_tech = { | 
					
						
							|  |  |  | 	.type = type, | 
					
						
							|  |  |  | 	.description = tdesc, | 
					
						
							|  |  |  | 	.capabilities = AST_FORMAT_SLINEAR, | 
					
						
							|  |  |  | 	.requester = nbs_request, | 
					
						
							|  |  |  | 	.call = nbs_call, | 
					
						
							|  |  |  | 	.hangup = nbs_hangup, | 
					
						
							|  |  |  | 	.read = nbs_xread, | 
					
						
							|  |  |  | 	.write = nbs_xwrite, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | static int nbs_call(struct ast_channel *ast, char *dest, int timeout) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct nbs_pvt *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "nbs_call called on %s, neither down nor reserved\n", ast->name); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* When we call, it just works, really, there's no destination...  Just
 | 
					
						
							|  |  |  | 	   ring the phone and wait for someone to answer */ | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Calling %s on %s\n", dest, ast->name); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If we can't connect, return congestion */ | 
					
						
							|  |  |  | 	if (nbs_connect(p->nbs)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "NBS Connection failed on %s\n", ast->name); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct nbs_pvt *nbs_alloc(void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "nbs_hangup(%s)\n", ast->name); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	if (!ast->tech_pvt) { | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Asked to hangup channel not connected\n"); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	nbs_destroy(p); | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	ast->tech_pvt = 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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct nbs_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 	ast_debug(1, "Returning null frame on %s\n", ast->name); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return &p->fr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int nbs_xwrite(struct ast_channel *ast, struct ast_frame *frame) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 	struct nbs_pvt *p = ast->tech_pvt; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | 	if (!(frame->subclass.codec & | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		(AST_FORMAT_SLINEAR))) { | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Cannot handle frames in %s format\n", ast_getformatname(frame->subclass.codec)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ast->_state != AST_STATE_UP) { | 
					
						
							|  |  |  | 		/* 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) { | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		tmp->tech = &nbs_tech; | 
					
						
							| 
									
										
										
										
											2007-08-08 21:44:58 +00:00
										 |  |  | 		ast_channel_set_fd(tmp, 0, nbs_fd(i->nbs)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		tmp->nativeformats = prefformat; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		tmp->rawreadformat = prefformat; | 
					
						
							|  |  |  | 		tmp->rawwriteformat = prefformat; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		tmp->writeformat = prefformat; | 
					
						
							|  |  |  | 		tmp->readformat = prefformat; | 
					
						
							|  |  |  | 		if (state == AST_STATE_RING) | 
					
						
							|  |  |  | 			tmp->rings = 1; | 
					
						
							| 
									
										
										
										
											2005-03-04 06:47:24 +00:00
										 |  |  | 		tmp->tech_pvt = i; | 
					
						
							| 
									
										
										
										
											2006-10-25 14:44:50 +00:00
										 |  |  | 		ast_copy_string(tmp->context, context, sizeof(tmp->context)); | 
					
						
							|  |  |  | 		ast_copy_string(tmp->exten, "s",  sizeof(tmp->exten)); | 
					
						
							| 
									
										
										
										
											2006-02-02 18:33:23 +00:00
										 |  |  | 		ast_string_field_set(tmp, language, ""); | 
					
						
							| 
									
										
										
										
											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)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); | 
					
						
							|  |  |  | 				ast_hangup(tmp); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); | 
					
						
							|  |  |  | 	return tmp; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | static struct ast_channel *nbs_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause) | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | 	format_t oldformat; | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 	struct nbs_pvt *p; | 
					
						
							|  |  |  | 	struct ast_channel *tmp = NULL; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	oldformat = format; | 
					
						
							|  |  |  | 	format &= (AST_FORMAT_SLINEAR); | 
					
						
							|  |  |  | 	if (!format) { | 
					
						
							| 
									
										
										
										
											2009-11-06 19:38:33 +00:00
										 |  |  | 		ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%s'\n", ast_getformatname(oldformat)); | 
					
						
							| 
									
										
										
										
											2003-01-21 03:37:21 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = nbs_alloc(data); | 
					
						
							| 
									
										
										
										
											2003-04-09 04:22:25 +00:00
										 |  |  | 	if (p) { | 
					
						
							| 
									
										
										
										
											2009-06-26 15:28:53 +00:00
										 |  |  | 		tmp = nbs_new(p, AST_STATE_DOWN, requestor ? requestor->linkedid : 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); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | { | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Network Broadcast Sound Support"); |