[asterisk-commits] branch bweschke/bug_5374 r8807 - in /team/bweschke/bug_5374: ./ channels/ cod...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Jan 28 06:33:42 MST 2006


Author: bweschke
Date: Sat Jan 28 07:33:32 2006
New Revision: 8807

URL: http://svn.digium.com/view/asterisk?rev=8807&view=rev
Log:
 Reverting changes - getting ready for an svnmerge 

Added:
    team/bweschke/bug_5374/doc/README.callingpres
      - copied unchanged from r8447, trunk/doc/README.callingpres
Modified:
    team/bweschke/bug_5374/callerid.c
    team/bweschke/bug_5374/channel.c
    team/bweschke/bug_5374/channels/chan_agent.c
    team/bweschke/bug_5374/channels/chan_iax2.c
    team/bweschke/bug_5374/channels/chan_sip.c
    team/bweschke/bug_5374/codecs/codec_a_mu.c
    team/bweschke/bug_5374/codecs/codec_adpcm.c
    team/bweschke/bug_5374/codecs/codec_alaw.c
    team/bweschke/bug_5374/codecs/codec_g723_1.c
    team/bweschke/bug_5374/codecs/codec_g726.c
    team/bweschke/bug_5374/codecs/codec_gsm.c
    team/bweschke/bug_5374/codecs/codec_ilbc.c
    team/bweschke/bug_5374/codecs/codec_lpc10.c
    team/bweschke/bug_5374/codecs/codec_speex.c
    team/bweschke/bug_5374/codecs/codec_ulaw.c
    team/bweschke/bug_5374/codecs/gsm/Makefile
    team/bweschke/bug_5374/configs/alsa.conf.sample
    team/bweschke/bug_5374/configs/sip.conf.sample
    team/bweschke/bug_5374/configs/zapata.conf.sample
    team/bweschke/bug_5374/doc/README.variables
    team/bweschke/bug_5374/formats/format_pcm.c
    team/bweschke/bug_5374/formats/format_pcm_alaw.c
    team/bweschke/bug_5374/funcs/func_cdr.c
    team/bweschke/bug_5374/funcs/func_cut.c
    team/bweschke/bug_5374/funcs/func_logic.c
    team/bweschke/bug_5374/funcs/func_math.c
    team/bweschke/bug_5374/funcs/func_md5.c
    team/bweschke/bug_5374/funcs/func_odbc.c
    team/bweschke/bug_5374/funcs/func_rand.c
    team/bweschke/bug_5374/funcs/func_strings.c
    team/bweschke/bug_5374/include/asterisk/astosp.h
    team/bweschke/bug_5374/include/asterisk/channel.h
    team/bweschke/bug_5374/include/asterisk/utils.h
    team/bweschke/bug_5374/pbx.c
    team/bweschke/bug_5374/res/res_agi.c
    team/bweschke/bug_5374/res/res_crypto.c
    team/bweschke/bug_5374/res/res_features.c
    team/bweschke/bug_5374/res/res_indications.c
    team/bweschke/bug_5374/res/res_monitor.c
    team/bweschke/bug_5374/res/res_musiconhold.c
    team/bweschke/bug_5374/res/res_osp.c

Modified: team/bweschke/bug_5374/callerid.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/callerid.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/callerid.c (original)
+++ team/bweschke/bug_5374/callerid.c Sat Jan 28 07:33:32 2006
@@ -862,6 +862,10 @@
 	return bytes;
 }
 
+/*
+ * remove '(', ' ', ')', non-trailing '.', and '-' not in square brackets.
+ * Basically, remove anything that could be invalid in a pattern.
+ */
 void ast_shrink_phone_number(char *n)
 {
 	int x,y=0;
@@ -908,53 +912,50 @@
 }
 
 /*! \brief parse string for caller id information 
-	\return returns -1 on failure, otherwise 0
+	\return always returns 0, as the code always returns something.
+  XXX note that 'name' is not parsed consistently e.g. we have
+
+	input			location	name
+	" foo bar " <123>	123		' foo bar ' (with spaces around)
+	" foo bar "		NULL		'foo bar' (without spaces around)
+	" foo bar  <123>"	123		'" foo bar'
+  The parsing of leading and trailing space/quotes should be more consistent.
 */
 int ast_callerid_parse(char *instr, char **name, char **location)
 {
-	char *ns, *ne;
-	char *ls, *le;
-	char tmp[256];
-	/* Try for "name" <location> format or 
-	   name <location> format */
+	char *ns, *ne, *ls, *le;
+
+	/* Try "name" <location> format or name <location> format */
 	if ((ls = strchr(instr, '<')) && (le = strchr(ls, '>'))) {
-		/* Found the location */
-		*le = '\0';
-		*ls = '\0';
-		*location = ls + 1;
-		if ((ns = strchr(instr, '\"')) && (ne = strchr(ns + 1, '\"'))) {
-			/* Get name out of quotes */
-			*ns = '\0';
-			*ne = '\0';
-			*name = ns + 1;
-			return 0;
-		} else {
-			/* Just trim off any trailing spaces */
-			*name = instr;
-			while(!ast_strlen_zero(instr) && (instr[strlen(instr) - 1] < 33))
-				instr[strlen(instr) - 1] = '\0';
-			/* And leading spaces */
-			*name = ast_skip_blanks(*name);
-			return 0;
-		}
-	} else {
+		*ls = *le = '\0';	/* location found, trim off the brackets */
+		*location = ls + 1;	/* and this is the result */
+		if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
+			*ns = *ne = '\0';	/* trim off the quotes */
+			*name = ns + 1;		/* and this is the name */
+		} else { /* no quotes, trim off leading and trailing spaces */
+			*name = ast_skip_blanks(instr);
+			ast_trim_blanks(*name);
+		}
+	} else {	/* no valid brackets */
+		char tmp[256];
 		ast_copy_string(tmp, instr, sizeof(tmp));
 		ast_shrink_phone_number(tmp);
-		if (ast_isphonenumber(tmp)) {
-			/* Assume it's just a location */
+		if (ast_isphonenumber(tmp)) {	/* Assume it's just a location */
 			*name = NULL;
+			strcpy(instr, tmp); /* safe, because tmp will always be the same size or smaller than instr */
 			*location = instr;
-		} else {
-			/* Assume it's just a name.  Make sure it's not quoted though */
-			*name = instr;
-			while(*(*name) && ((*(*name) < 33) || (*(*name) == '\"'))) (*name)++;
-			ne = *name + strlen(*name) - 1;
-			while((ne > *name) && ((*ne < 33) || (*ne == '\"'))) { *ne = '\0'; ne--; }
+		} else { /* Assume it's just a name. */
 			*location = NULL;
-		}
-		return 0;
-	}
-	return -1;
+			if ((ns = strchr(instr, '"')) && (ne = strchr(ns + 1, '"'))) {
+				*ns = *ne = '\0';	/* trim off the quotes */
+				*name = ns + 1;		/* and this is the name */
+			} else { /* no quotes, trim off leading and trailing spaces */
+				*name = ast_skip_blanks(instr);
+				ast_trim_blanks(*name);
+			}
+		}
+	}
+	return 0;
 }
 
 static int __ast_callerid_generate(unsigned char *buf, char *name, char *number, int callwaiting, int codec)

Modified: team/bweschke/bug_5374/channel.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channel.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/channel.c (original)
+++ team/bweschke/bug_5374/channel.c Sat Jan 28 07:33:32 2006
@@ -193,12 +193,92 @@
 
 }
 
+static int show_channeltype(int fd, int argc, char *argv[])
+{
+	struct chanlist *cl = NULL;
+
+	if (argc != 3)
+		return RESULT_SHOWUSAGE;
+	
+	if (ast_mutex_lock(&chlock)) {
+		ast_log(LOG_WARNING, "Unable to lock channel list\n");
+		return RESULT_FAILURE;
+	}
+
+	AST_LIST_TRAVERSE(&backends, cl, list) {
+		if (!strncasecmp(cl->tech->type, argv[2], strlen(cl->tech->type))) {
+			break;
+		}
+	}
+
+
+	if (!cl) {
+		ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[2]);
+		ast_mutex_unlock(&chlock);
+		return RESULT_FAILURE;
+	} 
+
+	ast_cli(fd,
+		"-- Info about channel driver: %s --\n"
+		"  Device State: %s\n"
+		"    Indication: %s\n"
+		"     Transfer : %s\n"
+		"  Capabilities: %d\n"
+		"    Send Digit: %s\n"
+		"    Send HTML : %s\n"
+		" Image Support: %s\n"
+		"  Text Support: %s\n",
+		cl->tech->type,
+		(cl->tech->devicestate) ? "yes" : "no",
+		(cl->tech->indicate) ? "yes" : "no",
+		(cl->tech->transfer) ? "yes" : "no",
+		(cl->tech->capabilities) ? cl->tech->capabilities : -1,
+		(cl->tech->send_digit) ? "yes" : "no",
+		(cl->tech->send_html) ? "yes" : "no",
+		(cl->tech->send_image) ? "yes" : "no",
+		(cl->tech->send_text) ? "yes" : "no"
+		
+	);
+
+	ast_mutex_unlock(&chlock);
+	return RESULT_SUCCESS;
+}
+
+static char *complete_channeltypes(const char *line, const char *word, int pos, int state)
+{
+	struct chanlist *cl;
+	int which = 0;
+	int wordlen;
+	char *ret = NULL;
+
+	if (pos != 2)
+		return NULL;
+
+	wordlen = strlen(word);
+
+	AST_LIST_TRAVERSE(&backends, cl, list) {
+		if (!strncasecmp(word, cl->tech->type, wordlen) && ++which > state) {
+			ret = strdup(cl->tech->type);
+			break;
+		}
+	}
+	
+	return ret;
+}
+
 static char show_channeltypes_usage[] = 
 "Usage: show channeltypes\n"
 "       Shows available channel types registered in your Asterisk server.\n";
 
+static char show_channeltype_usage[] = 
+"Usage: show channeltype <name>\n"
+"	Show details about the specified channel type, <name>.\n";
+
 static struct ast_cli_entry cli_show_channeltypes = 
 	{ { "show", "channeltypes", NULL }, show_channeltypes, "Show available channel types", show_channeltypes_usage };
+
+static struct ast_cli_entry cli_show_channeltype =
+	{ { "show", "channeltype", NULL }, show_channeltype, "Give more details on that channel type", show_channeltype_usage, complete_channeltypes };
 
 /*! \brief Checks to see if a channel is needing hang up */
 int ast_check_hangup(struct ast_channel *chan)
@@ -3704,6 +3784,8 @@
 	ast_group_t group = 0;
 
 	c = copy = ast_strdupa(s);
+	if (!copy)
+		return 0;
 	
 	while ((piece = strsep(&c, ","))) {
 		if (sscanf(piece, "%d-%d", &start, &finish) == 2) {
@@ -3775,6 +3857,7 @@
 void ast_channels_init(void)
 {
 	ast_cli_register(&cli_show_channeltypes);
+	ast_cli_register(&cli_show_channeltype);
 }
 
 /*! \brief Print call group and pickup group ---*/
@@ -3826,7 +3909,7 @@
 		}
 
 		tocopy = (f->samples > samples) ? samples : f->samples;
-		bytestocopy = ast_codec_get_len(queue->format, samples);
+		bytestocopy = ast_codec_get_len(queue->format, tocopy);
 		memcpy(buf, f->data, bytestocopy);
 		samples -= tocopy;
 		buf += tocopy;

Modified: team/bweschke/bug_5374/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/chan_agent.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/chan_agent.c (original)
+++ team/bweschke/bug_5374/channels/chan_agent.c Sat Jan 28 07:33:32 2006
@@ -328,7 +328,8 @@
 	char *agt = NULL;
 	struct agent_pvt *p, *prev;
 
-	parse = ast_strdupa(agent);
+	if (!(parse = ast_strdupa(agent)))
+		return NULL;
 
 	/* Extract username (agt), password and name from agent (args). */
 	AST_NONSTANDARD_APP_ARGS(args, parse, ',');
@@ -1763,7 +1764,10 @@
 
 	LOCAL_USER_ADD(u);
 
-	parse = ast_strdupa(data);
+	if (!(parse = ast_strdupa(data))) {
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
 
 	AST_STANDARD_APP_ARGS(args, parse);
 
@@ -2502,7 +2506,8 @@
 		return buf;	
 	}
 
-	item = ast_strdupa(data);
+	if (!(item = ast_strdupa(data)))
+		return buf;
 
 	agentid	= strsep(&item, ":");
 	if (!item)

Modified: team/bweschke/bug_5374/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/chan_iax2.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/chan_iax2.c (original)
+++ team/bweschke/bug_5374/channels/chan_iax2.c Sat Jan 28 07:33:32 2006
@@ -8024,7 +8024,8 @@
 	char *addr;
 	char *portstr;
 
-	tmp = ast_strdupa(srcaddr);
+	if (!(tmp = ast_strdupa(srcaddr)))
+		return -1;
 
 	addr = strsep(&tmp, ":");
 	portstr = tmp;
@@ -9161,7 +9162,8 @@
 	char *peername, *colname;
 	char iabuf[INET_ADDRSTRLEN];
 
-	peername = ast_strdupa(data);
+	if (!(peername = ast_strdupa(data)))
+		return ret;
 
 	/* if our channel, return the IP address of the endpoint of current channel */
 	if (!strcmp(peername,"CURRENTCHANNEL")) {

Modified: team/bweschke/bug_5374/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/channels/chan_sip.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/channels/chan_sip.c (original)
+++ team/bweschke/bug_5374/channels/chan_sip.c Sat Jan 28 07:33:32 2006
@@ -469,7 +469,7 @@
 /*! \brief Parameters to the transmit_invite function */
 struct sip_invite_param {
 	const char *distinctive_ring;	/*!< Distinctive ring header */
-	char *osptoken;		/*!< OSP token for this call */
+	const char *osptoken;		/*!< OSP token for this call */
 	int addsipheaders;	/*!< Add extra SIP headers */
 	const char *uri_options;	/*!< URI options to add to the URI */
 	const char *vxml_url;		/*!< VXML url for Cisco phones */
@@ -567,6 +567,8 @@
 #define SIP_CALL_LIMIT		(1 << 29)
 /* Remote Party-ID Support */
 #define SIP_SENDRPID		(1 << 30)
+/* Did this connection increment the counter of in-use calls? */
+#define SIP_INC_COUNT (1 << 31)
 
 #define SIP_FLAGS_TO_COPY \
 	(SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
@@ -1991,7 +1993,7 @@
 	int res;
 	struct sip_pvt *p;
 #ifdef OSP_SUPPORT
-	char *osphandle = NULL;
+	const char *osphandle = NULL;
 #endif	
 	struct varshead *headp;
 	struct ast_var_t *current;
@@ -2226,7 +2228,8 @@
 		/* incoming and outgoing affects the inUse counter */
 		case DEC_CALL_LIMIT:
 			if ( *inuse > 0 ) {
-				(*inuse)--;
+			         if (ast_test_flag(fup,SIP_INC_COUNT))
+				         (*inuse)--;
 			} else {
 				*inuse = 0;
 			}
@@ -2246,6 +2249,7 @@
 				}
 			}
 			(*inuse)++;
+	                ast_set_flag(fup,SIP_INC_COUNT);
 			if (option_debug > 1 || sipdebug) {
 				ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
 			}
@@ -9270,7 +9274,8 @@
 	char *peername, *colname;
 	char iabuf[INET_ADDRSTRLEN];
 
-	peername = ast_strdupa(data);
+	if (!(peername = ast_strdupa(data)))
+		return ret;
 
 	if ((colname = strchr(peername, ':'))) {
 		*colname = '\0';
@@ -12822,7 +12827,9 @@
 	char *extension, *host, *port;
 	char tmp[80];
 	
-	cdest = ast_strdupa(dest);
+	if (!(cdest = ast_strdupa(dest)))
+		return 0;
+	
 	extension = strsep(&cdest, "@");
 	host = strsep(&cdest, ":");
 	port = strsep(&cdest, ":");
@@ -12848,9 +12855,12 @@
 				ast_log(LOG_ERROR, "Can't find the host address\n");
 				return 0;
 			}
-			host = ast_strdupa(lhost);
-			if (!ast_strlen_zero(lport))
-				port = ast_strdupa(lport);
+			if (!(host = ast_strdupa(lhost)))
+				return 0;
+			if (!ast_strlen_zero(lport)) {
+				if (!(port = ast_strdupa(lport)))
+					return 0;
+			}
 		}
 	}
 

Modified: team/bweschke/bug_5374/codecs/codec_a_mu.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/codecs/codec_a_mu.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/codecs/codec_a_mu.c (original)
+++ team/bweschke/bug_5374/codecs/codec_a_mu.c Sat Jan 28 07:33:32 2006
@@ -41,6 +41,7 @@
 #include "asterisk/channel.h"
 #include "asterisk/alaw.h"
 #include "asterisk/ulaw.h"
+#include "asterisk/utils.h"
 
 #define BUFFER_SIZE   8096	/* size for the translation buffers */
 
@@ -62,10 +63,10 @@
 
 struct alaw_encoder_pvt
 {
-  struct ast_frame f;
-  char offset[AST_FRIENDLY_OFFSET];   /* Space to build offset */
-  unsigned char outbuf[BUFFER_SIZE];  /* Encoded alaw, two nibbles to a word */
-  int tail;
+	struct ast_frame f;
+	char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
+	unsigned char outbuf[BUFFER_SIZE];	/* Encoded alaw, two nibbles to a word */
+	int tail;
 };
 
 /*
@@ -74,99 +75,91 @@
 
 struct ulaw_encoder_pvt
 {
-  struct ast_frame f;
-  char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
-  unsigned char outbuf[BUFFER_SIZE];	/* Encoded ulaw values */
-  int tail;
+	struct ast_frame f;
+	char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
+	unsigned char outbuf[BUFFER_SIZE];	/* Encoded ulaw values */
+	int tail;
 };
 
-static struct ast_translator_pvt *
-alawtoulaw_new (void)
-{
-  struct ulaw_encoder_pvt *tmp;
-  tmp = malloc (sizeof (struct ulaw_encoder_pvt));
-  if (tmp)
-    {
-	  memset(tmp, 0, sizeof(*tmp));
-      tmp->tail = 0;
-      localusecnt++;
-      ast_update_use_count ();
-    }
-  return (struct ast_translator_pvt *) tmp;
-}
-
-static struct ast_translator_pvt *
-ulawtoalaw_new (void)
-{
-  struct alaw_encoder_pvt *tmp;
-  tmp = malloc (sizeof (struct alaw_encoder_pvt));
-  if (tmp)
-    {
-	  memset(tmp, 0, sizeof(*tmp));
-      localusecnt++;
-      ast_update_use_count ();
-      tmp->tail = 0;
-    }
-  return (struct ast_translator_pvt *) tmp;
-}
-
-static int
-alawtoulaw_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
-  struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *) pvt;
-  int x;
-  unsigned char *b;
-
-  if ((tmp->tail + f->datalen)> sizeof(tmp->outbuf)) {
-  	ast_log(LOG_WARNING, "Out of buffer space\n");
-	return -1;
-  }
-
-  /* Reset ssindex and signal to frame's specified values */
-  b = f->data;
-  for (x=0;x<f->datalen;x++)
-  	tmp->outbuf[tmp->tail + x] = a2mu[b[x]];
-
-  tmp->tail += f->datalen;
-  return 0;
-}
-
-static struct ast_frame *
-alawtoulaw_frameout (struct ast_translator_pvt *pvt)
-{
-  struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *) pvt;
-
-  if (!tmp->tail)
-    return NULL;
-
-  tmp->f.frametype = AST_FRAME_VOICE;
-  tmp->f.subclass = AST_FORMAT_ULAW;
-  tmp->f.datalen = tmp->tail;
-  tmp->f.samples = tmp->tail;
-  tmp->f.mallocd = 0;
-  tmp->f.offset = AST_FRIENDLY_OFFSET;
-  tmp->f.src = __PRETTY_FUNCTION__;
-  tmp->f.data = tmp->outbuf;
-  tmp->tail = 0;
-  return &tmp->f;
-}
-
-static int
-ulawtoalaw_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
-  struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *) pvt;
-  int x;
-  unsigned char *s;
-  if (tmp->tail + f->datalen >= sizeof(tmp->outbuf))
-    {
-      ast_log (LOG_WARNING, "Out of buffer space\n");
-      return -1;
-    }
-  s = f->data;
-  for (x=0;x<f->datalen;x++) 
-  	tmp->outbuf[x+tmp->tail] = mu2a[s[x]];
-  tmp->tail += f->datalen;
-  return 0;
+static struct ast_translator_pvt *alawtoulaw_new(void)
+{
+	struct ulaw_encoder_pvt *tmp;
+	
+	if ((tmp = ast_calloc(1, sizeof(*tmp)))) {
+		tmp->tail = 0;
+		localusecnt++;
+		ast_update_use_count();
+	}
+
+	return (struct ast_translator_pvt *)tmp;
+}
+
+static struct ast_translator_pvt *ulawtoalaw_new(void)
+{
+	struct alaw_encoder_pvt *tmp;
+	
+	if ((tmp = ast_calloc(1, sizeof(*tmp)))) {
+		localusecnt++;
+		ast_update_use_count();
+		tmp->tail = 0;
+	}
+
+	return (struct ast_translator_pvt *)tmp;
+}
+
+static int alawtoulaw_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
+{
+	struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *)pvt;
+	int x;
+	unsigned char *b;
+
+	if ((tmp->tail + f->datalen) > sizeof(tmp->outbuf)) {
+		ast_log(LOG_WARNING, "Out of buffer space\n");
+		return -1;
+	}
+
+	/* Reset ssindex and signal to frame's specified values */
+	b = f->data;
+	for (x=0;x<f->datalen;x++)
+		tmp->outbuf[tmp->tail + x] = a2mu[b[x]];
+
+	tmp->tail += f->datalen;
+	return 0;
+}
+
+static struct ast_frame *alawtoulaw_frameout(struct ast_translator_pvt *pvt)
+{
+	struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *)pvt;
+
+	if (!tmp->tail)
+		return NULL;
+
+	tmp->f.frametype = AST_FRAME_VOICE;
+	tmp->f.subclass = AST_FORMAT_ULAW;
+	tmp->f.datalen = tmp->tail;
+	tmp->f.samples = tmp->tail;
+	tmp->f.mallocd = 0;
+	tmp->f.offset = AST_FRIENDLY_OFFSET;
+	tmp->f.src = __PRETTY_FUNCTION__;
+	tmp->f.data = tmp->outbuf;
+	tmp->tail = 0;
+	return &tmp->f;
+}
+
+static int ulawtoalaw_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
+{
+	struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *)pvt;
+	int x;
+	unsigned char *s;
+	if (tmp->tail + f->datalen >= sizeof(tmp->outbuf)) {
+		ast_log(LOG_WARNING, "Out of buffer space\n");
+		return -1;
+	}
+	s = f->data;
+	for (x=0;x<f->datalen;x++) 
+		tmp->outbuf[x+tmp->tail] = mu2a[s[x]];
+	tmp->tail += f->datalen;
+	return 0;
 }
 
 /*
@@ -181,60 +174,56 @@
  *  Leftover inbuf data gets packed, tail gets updated.
  */
 
-static struct ast_frame *
-ulawtoalaw_frameout (struct ast_translator_pvt *pvt)
-{
-  struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *) pvt;
+static struct ast_frame *ulawtoalaw_frameout(struct ast_translator_pvt *pvt)
+{
+	struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *)pvt;
   
-  if (tmp->tail) {
-	  tmp->f.frametype = AST_FRAME_VOICE;
-	  tmp->f.subclass = AST_FORMAT_ALAW;
-	  tmp->f.samples = tmp->tail;
-	  tmp->f.mallocd = 0;
-	  tmp->f.offset = AST_FRIENDLY_OFFSET;
-	  tmp->f.src = __PRETTY_FUNCTION__;
-	  tmp->f.data = tmp->outbuf;
-	  tmp->f.datalen = tmp->tail;
-	  tmp->tail = 0;
-	  return &tmp->f;
-   } else return NULL;
-}
-
+	if (tmp->tail) {
+		tmp->f.frametype = AST_FRAME_VOICE;
+		tmp->f.subclass = AST_FORMAT_ALAW;
+		tmp->f.samples = tmp->tail;
+		tmp->f.mallocd = 0;
+		tmp->f.offset = AST_FRIENDLY_OFFSET;
+		tmp->f.src = __PRETTY_FUNCTION__;
+		tmp->f.data = tmp->outbuf;
+		tmp->f.datalen = tmp->tail;
+		tmp->tail = 0;
+		return &tmp->f;
+	} else
+		return NULL;
+}
 
 /*
  * alawToLin_Sample
  */
 
-static struct ast_frame *
-alawtoulaw_sample (void)
-{
-  static struct ast_frame f;
-  f.frametype = AST_FRAME_VOICE;
-  f.subclass = AST_FORMAT_ALAW;
-  f.datalen = sizeof (ulaw_slin_ex);
-  f.samples = sizeof(ulaw_slin_ex);
-  f.mallocd = 0;
-  f.offset = 0;
-  f.src = __PRETTY_FUNCTION__;
-  f.data = ulaw_slin_ex;
-  return &f;
-}
-
-static struct ast_frame *
-ulawtoalaw_sample (void)
-{
-  static struct ast_frame f;
-  f.frametype = AST_FRAME_VOICE;
-  f.subclass = AST_FORMAT_ULAW;
-  f.datalen = sizeof (ulaw_slin_ex);
-  f.samples = sizeof(ulaw_slin_ex);
-  f.mallocd = 0;
-  f.offset = 0;
-  f.src = __PRETTY_FUNCTION__;
-  f.data = ulaw_slin_ex;
-  return &f;
-}
-
+static struct ast_frame *alawtoulaw_sample(void)
+{
+	static struct ast_frame f;
+	f.frametype = AST_FRAME_VOICE;
+	f.subclass = AST_FORMAT_ALAW;
+	f.datalen = sizeof(ulaw_slin_ex);
+	f.samples = sizeof(ulaw_slin_ex);
+	f.mallocd = 0;
+	f.offset = 0;
+	f.src = __PRETTY_FUNCTION__;
+	f.data = ulaw_slin_ex;
+	return &f;
+}
+
+static struct ast_frame *ulawtoalaw_sample(void)
+{
+	static struct ast_frame f;
+	f.frametype = AST_FRAME_VOICE;
+	f.subclass = AST_FORMAT_ULAW;
+	f.datalen = sizeof(ulaw_slin_ex);
+	f.samples = sizeof(ulaw_slin_ex);
+	f.mallocd = 0;
+	f.offset = 0;
+	f.src = __PRETTY_FUNCTION__;
+	f.data = ulaw_slin_ex;
+	return &f;
+}
 
 /*
  * alaw_Destroy
@@ -247,12 +236,11 @@
  *  None.
  */
 
-static void
-alaw_destroy (struct ast_translator_pvt *pvt)
-{
-  free (pvt);
-  localusecnt--;
-  ast_update_use_count ();
+static void alaw_destroy(struct ast_translator_pvt *pvt)
+{
+	free(pvt);
+	localusecnt--;
+	ast_update_use_count();
 }
 
 /*
@@ -260,15 +248,15 @@
  */
 
 static struct ast_translator alawtoulaw = {
-  "alawtoulaw",
-  AST_FORMAT_ALAW,
-  AST_FORMAT_ULAW,
-  alawtoulaw_new,
-  alawtoulaw_framein,
-  alawtoulaw_frameout,
-  alaw_destroy,
-  /* NULL */
-  alawtoulaw_sample
+	"alawtoulaw",
+	AST_FORMAT_ALAW,
+	AST_FORMAT_ULAW,
+	alawtoulaw_new,
+	alawtoulaw_framein,
+	alawtoulaw_frameout,
+	alaw_destroy,
+	/* NULL */
+	alawtoulaw_sample
 };
 
 /*
@@ -276,68 +264,63 @@
  */
 
 static struct ast_translator ulawtoalaw = {
-  "ulawtoalaw",
-  AST_FORMAT_ULAW,
-  AST_FORMAT_ALAW,
-  ulawtoalaw_new,
-  ulawtoalaw_framein,
-  ulawtoalaw_frameout,
-  alaw_destroy,
-  /* NULL */
-  ulawtoalaw_sample
+	"ulawtoalaw",
+	AST_FORMAT_ULAW,
+	AST_FORMAT_ALAW,
+	ulawtoalaw_new,
+	ulawtoalaw_framein,
+	ulawtoalaw_frameout,
+	alaw_destroy,
+	/* NULL */
+	ulawtoalaw_sample
 };
 
-int
-unload_module (void)
-{
-  int res;
-  ast_mutex_lock (&localuser_lock);
-  res = ast_unregister_translator (&ulawtoalaw);
-  if (!res)
-    res = ast_unregister_translator (&alawtoulaw);
-  if (localusecnt)
-    res = -1;
-  ast_mutex_unlock (&localuser_lock);
-  return res;
-}
-
-int
-load_module (void)
-{
-  int res;
-  int x;
-  for (x=0;x<256;x++) {
-	mu2a[x] = AST_LIN2A(AST_MULAW(x));
-	a2mu[x] = AST_LIN2MU(AST_ALAW(x));
-  }
-  res = ast_register_translator (&alawtoulaw);
-  if (!res)
-    res = ast_register_translator (&ulawtoalaw);
-  else
-    ast_unregister_translator (&alawtoulaw);
-  return res;
+int unload_module(void)
+{
+	int res;
+	ast_mutex_lock(&localuser_lock);
+	res = ast_unregister_translator(&ulawtoalaw);
+	if (!res)
+		res = ast_unregister_translator(&alawtoulaw);
+	if (localusecnt)
+		res = -1;
+	ast_mutex_unlock(&localuser_lock);
+	return res;
+}
+
+int load_module(void)
+{
+	int res;
+	int x;
+	for (x=0;x<256;x++) {
+		mu2a[x] = AST_LIN2A(AST_MULAW(x));
+		a2mu[x] = AST_LIN2MU(AST_ALAW(x));
+	}
+	res = ast_register_translator(&alawtoulaw);
+	if (!res)
+		res = ast_register_translator(&ulawtoalaw);
+	else
+		ast_unregister_translator(&alawtoulaw);
+	return res;
 }
 
 /*
  * Return a description of this module.
  */
 
-char *
-description (void)
-{
-  return tdesc;
-}
-
-int
-usecount (void)
-{
-  int res;
-  STANDARD_USECOUNT (res);
-  return res;
-}
-
-char *
-key ()
-{
-  return ASTERISK_GPL_KEY;
-}
+char *description(void)
+{
+	return tdesc;
+}
+
+int usecount(void)
+{
+	int res;
+	STANDARD_USECOUNT(res);
+	return res;
+}
+
+char *key()
+{
+	return ASTERISK_GPL_KEY;
+}

Modified: team/bweschke/bug_5374/codecs/codec_adpcm.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_5374/codecs/codec_adpcm.c?rev=8807&r1=8806&r2=8807&view=diff
==============================================================================
--- team/bweschke/bug_5374/codecs/codec_adpcm.c (original)
+++ team/bweschke/bug_5374/codecs/codec_adpcm.c Sat Jan 28 07:33:32 2006
@@ -45,6 +45,7 @@
 #include "asterisk/options.h"
 #include "asterisk/translate.h"
 #include "asterisk/channel.h"
+#include "asterisk/utils.h"
 
 /* define NOT_BLI to use a faster but not bit-level identical version */
 /* #define NOT_BLI */
@@ -102,8 +103,7 @@
  *  Sets the index to the step size table for the next encode.
  */
 
-static inline short
-decode(int encoded, struct adpcm_state* state)
+static inline short decode(int encoded, struct adpcm_state *state)
 {
 	int diff;
 	int step;
@@ -117,9 +117,12 @@
 	diff = (((encoded << 1) + 1) * step) >> 3;
 #else /* BLI code */
 	diff = step >> 3;
-	if (encoded & 4) diff += step;
-	if (encoded & 2) diff += step >> 1;
-	if (encoded & 1) diff += step >> 2;
+	if (encoded & 4)
+		diff += step;
+	if (encoded & 2)
+		diff += step >> 1;
+	if (encoded & 1)
+		diff += step >> 2;
 	if ((encoded >> 1) & step & 0x1)
 		diff++;
 #endif
@@ -143,8 +146,7 @@
 #ifdef AUTO_RETURN
 	if (encoded)
 		state->zero_count = 0;
-	else if (++(state->zero_count) == 24)
-	{
+	else if (++(state->zero_count) == 24) {
 		state->zero_count = 0;
 		if (state->signal > 0)
 			state->next_flag = 0x1;
@@ -174,51 +176,43 @@
  *  signal gets updated with each pass.
  */
 
-static inline int
-adpcm(short csig, struct adpcm_state* state)
+static inline int adpcm(short csig, struct adpcm_state *state)
 {
 	int diff;
 	int step;
 	int encoded;
 
 	/* 
-	* Clip csig if too large or too small
-	*/
+	 * Clip csig if too large or too small
+	 */
 	csig >>= 4;
 
 	step = stpsz[state->ssindex];
 	diff = csig - state->signal;
 
 #ifdef NOT_BLI
-	if (diff < 0)
-	{
+	if (diff < 0) {
 		encoded = (-diff << 2) / step;
 		if (encoded > 7)
 			encoded = 7;
 		encoded |= 0x08;
-	}
-	else
-	{
+	} else {
 		encoded = (diff << 2) / step;
 		if (encoded > 7)
 			encoded = 7;
 	}
 #else /* BLI code */
-	if (diff < 0)
-	{
+	if (diff < 0) {
 		encoded = 8;
 		diff = -diff;
-	}
-	else
+	} else
 		encoded = 0;
-	if (diff >= step)
-	{
+	if (diff >= step) {
 		encoded |= 4;
 		diff -= step;
 	}
 	step >>= 1;
-	if (diff >= step)
-	{
+	if (diff >= step) {
 		encoded |= 2;
 		diff -= step;
 	}
@@ -239,12 +233,12 @@
 
 struct adpcm_encoder_pvt
 {
-  struct ast_frame f;
-  char offset[AST_FRIENDLY_OFFSET];   /* Space to build offset */
-  short inbuf[BUFFER_SIZE];           /* Unencoded signed linear values */
-  unsigned char outbuf[BUFFER_SIZE];  /* Encoded ADPCM, two nibbles to a word */
-  struct adpcm_state state;
-  int tail;
+	struct ast_frame f;
+	char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
+	short inbuf[BUFFER_SIZE];		/* Unencoded signed linear values */
+	unsigned char outbuf[BUFFER_SIZE];	/* Encoded ADPCM, two nibbles to a word */
+	struct adpcm_state state;
+	int tail;
 };
 
 /*
@@ -253,12 +247,12 @@
 
 struct adpcm_decoder_pvt
 {
-  struct ast_frame f;
-  char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
-  short outbuf[BUFFER_SIZE];	/* Decoded signed linear values */
-  struct adpcm_state state;
-  int tail;
-  plc_state_t plc;
+	struct ast_frame f;
+	char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
+	short outbuf[BUFFER_SIZE];		/* Decoded signed linear values */
+	struct adpcm_state state;
+	int tail;
+	plc_state_t plc;
 };
 
 /*
@@ -272,20 +266,18 @@
  *  None.
  */
 
-static struct ast_translator_pvt *
-adpcmtolin_new (void)
-{
-  struct adpcm_decoder_pvt *tmp;
-  tmp = malloc (sizeof (struct adpcm_decoder_pvt));
-  if (tmp)
-    {
-	  memset(tmp, 0, sizeof(*tmp));
-      tmp->tail = 0;
-      plc_init(&tmp->plc);
-      localusecnt++;
-      ast_update_use_count ();
-    }
-  return (struct ast_translator_pvt *) tmp;
+static struct ast_translator_pvt *adpcmtolin_new(void)
+{
+	struct adpcm_decoder_pvt *tmp;
+	
+	if ((tmp = ast_calloc(1, sizeof(*tmp)))) {
+		tmp->tail = 0;
+		plc_init(&tmp->plc);
+		localusecnt++;
+		ast_update_use_count();
+	}
+
+	return (struct ast_translator_pvt *)tmp;
 }
 
 /*
@@ -299,19 +291,17 @@
  *  None.
  */
 
-static struct ast_translator_pvt *
-lintoadpcm_new (void)
-{
-  struct adpcm_encoder_pvt *tmp;
-  tmp = malloc (sizeof (struct adpcm_encoder_pvt));
-  if (tmp)
-    {
-	  memset(tmp, 0, sizeof(*tmp));
-      localusecnt++;
-      ast_update_use_count ();
-      tmp->tail = 0;
-    }
-  return (struct ast_translator_pvt *) tmp;
+static struct ast_translator_pvt *lintoadpcm_new(void)
+{
+	struct adpcm_encoder_pvt *tmp;
+	
+	if ((tmp = ast_calloc(1, sizeof(*tmp)))) {
+		localusecnt++;
+		ast_update_use_count();
+		tmp->tail = 0;
+	}
+
+	return (struct ast_translator_pvt *)tmp;
 }
 
 /*
@@ -326,40 +316,40 @@
  *  tmp->tail is the number of packed values in the buffer.
  */
 
-static int
-adpcmtolin_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
-  struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *) pvt;
-  int x;
-  unsigned char *b;
-
-  if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
-        if((tmp->tail + 160) > sizeof(tmp->outbuf) / 2) {
-            ast_log(LOG_WARNING, "Out of buffer space\n");
-            return -1;
-        }
-        if(useplc) {
-	  plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160);
-	  tmp->tail += 160;
-	}
-        return 0;
-  }
-
-  if (f->datalen * 4 + tmp->tail * 2 > sizeof(tmp->outbuf)) {
-  	ast_log(LOG_WARNING, "Out of buffer space\n");
-	return -1;
-  }
-
-  b = f->data;
-
-  for (x=0;x<f->datalen;x++) {
-	tmp->outbuf[tmp->tail++] = decode((b[x] >> 4) & 0xf, &tmp->state);
-	tmp->outbuf[tmp->tail++] = decode(b[x] & 0x0f, &tmp->state);
-  }
-
-  if(useplc) plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2);
-
-  return 0;
+static int adpcmtolin_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
+{
+	struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *)pvt;
+	int x;
+	unsigned char *b;
+
+	if(f->datalen == 0) { /* perform PLC with nominal framesize of 20ms/160 samples */
+		if((tmp->tail + 160) > sizeof(tmp->outbuf) / 2) {
+			ast_log(LOG_WARNING, "Out of buffer space\n");
+			return -1;
+		}
+		if(useplc) {
+			plc_fillin(&tmp->plc, tmp->outbuf+tmp->tail, 160);
+			tmp->tail += 160;
+		}
+		return 0;
+	}
+
+	if (f->datalen * 4 + tmp->tail * 2 > sizeof(tmp->outbuf)) {
+		ast_log(LOG_WARNING, "Out of buffer space\n");
+		return -1;
+	}
+
+	b = f->data;
+
+	for (x=0;x<f->datalen;x++) {
+		tmp->outbuf[tmp->tail++] = decode((b[x] >> 4) & 0xf, &tmp->state);
+		tmp->outbuf[tmp->tail++] = decode(b[x] & 0x0f, &tmp->state);
+	}
+
+	if(useplc)
+		plc_rx(&tmp->plc, tmp->outbuf+tmp->tail-f->datalen*2, f->datalen*2);
+
+	return 0;
 }
 
 /*
@@ -374,24 +364,23 @@
  *  None.
  */
 
-static struct ast_frame *
-adpcmtolin_frameout (struct ast_translator_pvt *pvt)
-{
-  struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *) pvt;
-
-  if (!tmp->tail)
-    return NULL;
-
-  tmp->f.frametype = AST_FRAME_VOICE;
-  tmp->f.subclass = AST_FORMAT_SLINEAR;
-  tmp->f.datalen = tmp->tail *2;
-  tmp->f.samples = tmp->tail;
-  tmp->f.mallocd = 0;
-  tmp->f.offset = AST_FRIENDLY_OFFSET;
-  tmp->f.src = __PRETTY_FUNCTION__;
-  tmp->f.data = tmp->outbuf;
-  tmp->tail = 0;
-  return &tmp->f;
+static struct ast_frame *adpcmtolin_frameout(struct ast_translator_pvt *pvt)
+{
+	struct adpcm_decoder_pvt *tmp = (struct adpcm_decoder_pvt *)pvt;
+
+	if (!tmp->tail)
+		return NULL;
+
+	tmp->f.frametype = AST_FRAME_VOICE;
+	tmp->f.subclass = AST_FORMAT_SLINEAR;
+	tmp->f.datalen = tmp->tail * 2;
+	tmp->f.samples = tmp->tail;
+	tmp->f.mallocd = 0;
+	tmp->f.offset = AST_FRIENDLY_OFFSET;
+	tmp->f.src = __PRETTY_FUNCTION__;
+	tmp->f.data = tmp->outbuf;
+	tmp->tail = 0;
+	return &tmp->f;
 }
 
 /*
@@ -405,22 +394,18 @@
  *  tmp->tail is number of signal values in the input buffer.
  */
 
-static int
-lintoadpcm_framein (struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
-  struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *) pvt;
-
-  if ((tmp->tail + f->datalen / 2) < (sizeof (tmp->inbuf) / 2))
-    {
-      memcpy (&tmp->inbuf[tmp->tail], f->data, f->datalen);
-      tmp->tail += f->datalen / 2;
-    }
-  else
-    {
-      ast_log (LOG_WARNING, "Out of buffer space\n");
-      return -1;
-    }
-  return 0;
+static int lintoadpcm_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
+{
+	struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *)pvt;
+
+	if ((tmp->tail + f->datalen / 2) < (sizeof(tmp->inbuf) / 2)) {
+		memcpy(&tmp->inbuf[tmp->tail], f->data, f->datalen);
+		tmp->tail += f->datalen / 2;
+	} else {
+		ast_log(LOG_WARNING, "Out of buffer space\n");
+		return -1;
+	}
+	return 0;
 }
 
 /*
@@ -435,54 +420,50 @@
  *  Leftover inbuf data gets packed, tail gets updated.
  */
 
-static struct ast_frame *
-lintoadpcm_frameout (struct ast_translator_pvt *pvt)
-{
-  struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *) pvt;
-  int i_max, i;
+static struct ast_frame *lintoadpcm_frameout(struct ast_translator_pvt *pvt)
+{
+	struct adpcm_encoder_pvt *tmp = (struct adpcm_encoder_pvt *)pvt;
+	int i_max, i;
   
-  if (tmp->tail < 2) return NULL;
-
-
-  i_max = tmp->tail & ~1; /* atomic size is 2 samples */
-
-  /* What is this, state debugging? should be #ifdef'd then
-  tmp->outbuf[0] = tmp->ssindex & 0xff;
-  tmp->outbuf[1] = (tmp->signal >> 8) & 0xff;
-  tmp->outbuf[2] = (tmp->signal & 0xff);
-  tmp->outbuf[3] = tmp->zero_count;
-  tmp->outbuf[4] = tmp->next_flag;
-  */
-  for (i = 0; i < i_max; i+=2)
-  {
-    tmp->outbuf[i/2] =
-      (adpcm(tmp->inbuf[i  ], &tmp->state) << 4) |
-	  (adpcm(tmp->inbuf[i+1], &tmp->state)     );
-  };
-
-
-  tmp->f.frametype = AST_FRAME_VOICE;
-  tmp->f.subclass = AST_FORMAT_ADPCM;
-  tmp->f.samples = i_max;
-  tmp->f.mallocd = 0;
-  tmp->f.offset = AST_FRIENDLY_OFFSET;
-  tmp->f.src = __PRETTY_FUNCTION__;
-  tmp->f.data = tmp->outbuf;
-  tmp->f.datalen = i_max / 2;
-
-  /*
-   * If there is a signal left over (there should be no more than
-   * one) move it to the beginning of the input buffer.
-   */
-
-  if (tmp->tail == i_max)
-    tmp->tail = 0;
-  else
-    {
-      tmp->inbuf[0] = tmp->inbuf[tmp->tail];
-      tmp->tail = 1;
-    }
-  return &tmp->f;
+	if (tmp->tail < 2)
+		return NULL;
+
+	i_max = tmp->tail & ~1; /* atomic size is 2 samples */
+
+	/* What is this, state debugging? should be #ifdef'd then
+	tmp->outbuf[0] = tmp->ssindex & 0xff;
+	tmp->outbuf[1] = (tmp->signal >> 8) & 0xff;
+	tmp->outbuf[2] = (tmp->signal & 0xff);
+	tmp->outbuf[3] = tmp->zero_count;
+	tmp->outbuf[4] = tmp->next_flag;
+	*/
+	for (i = 0; i < i_max; i+=2) {
+		tmp->outbuf[i/2] =
+			(adpcm(tmp->inbuf[i  ], &tmp->state) << 4) |
+			(adpcm(tmp->inbuf[i+1], &tmp->state)     );
+	};
+
+	tmp->f.frametype = AST_FRAME_VOICE;
+	tmp->f.subclass = AST_FORMAT_ADPCM;
+	tmp->f.samples = i_max;
+	tmp->f.mallocd = 0;
+	tmp->f.offset = AST_FRIENDLY_OFFSET;
+	tmp->f.src = __PRETTY_FUNCTION__;
+	tmp->f.data = tmp->outbuf;
+	tmp->f.datalen = i_max / 2;
+
+	/*
+	 * If there is a signal left over (there should be no more than
+	 * one) move it to the beginning of the input buffer.
+	 */
+
+	if (tmp->tail == i_max)
+		tmp->tail = 0;
+	else {
+		tmp->inbuf[0] = tmp->inbuf[tmp->tail];
+		tmp->tail = 1;
+	}
+	return &tmp->f;
 }
 
 
@@ -490,39 +471,37 @@
  * AdpcmToLin_Sample
  */
 
-static struct ast_frame *
-adpcmtolin_sample (void)
-{
-  static struct ast_frame f;
-  f.frametype = AST_FRAME_VOICE;
-  f.subclass = AST_FORMAT_ADPCM;
-  f.datalen = sizeof (adpcm_slin_ex);
-  f.samples = sizeof(adpcm_slin_ex) * 2;
-  f.mallocd = 0;
-  f.offset = 0;
-  f.src = __PRETTY_FUNCTION__;
-  f.data = adpcm_slin_ex;
-  return &f;
+static struct ast_frame *adpcmtolin_sample(void)
+{
+	static struct ast_frame f;
+	f.frametype = AST_FRAME_VOICE;
+	f.subclass = AST_FORMAT_ADPCM;
+	f.datalen = sizeof(adpcm_slin_ex);
+	f.samples = sizeof(adpcm_slin_ex) * 2;
+	f.mallocd = 0;
+	f.offset = 0;
+	f.src = __PRETTY_FUNCTION__;
+	f.data = adpcm_slin_ex;
+	return &f;
 }
 
 /*
  * LinToAdpcm_Sample
  */
 
-static struct ast_frame *
-lintoadpcm_sample (void)
-{
-  static struct ast_frame f;
-  f.frametype = AST_FRAME_VOICE;
-  f.subclass = AST_FORMAT_SLINEAR;
-  f.datalen = sizeof (slin_adpcm_ex);
-  /* Assume 8000 Hz */
-  f.samples = sizeof (slin_adpcm_ex) / 2;
-  f.mallocd = 0;
-  f.offset = 0;
-  f.src = __PRETTY_FUNCTION__;
-  f.data = slin_adpcm_ex;
-  return &f;
+static struct ast_frame *lintoadpcm_sample(void)
+{
+	static struct ast_frame f;
+	f.frametype = AST_FRAME_VOICE;
+	f.subclass = AST_FORMAT_SLINEAR;
+	f.datalen = sizeof(slin_adpcm_ex);
+	/* Assume 8000 Hz */
+	f.samples = sizeof(slin_adpcm_ex) / 2;
+	f.mallocd = 0;
+	f.offset = 0;
+	f.src = __PRETTY_FUNCTION__;
+	f.data = slin_adpcm_ex;
+	return &f;
 }
 
 /*
@@ -536,12 +515,11 @@
  *  None.
  */
 
-static void
-adpcm_destroy (struct ast_translator_pvt *pvt)
-{
-  free (pvt);
-  localusecnt--;
-  ast_update_use_count ();
+static void adpcm_destroy(struct ast_translator_pvt *pvt)
+{
+	free(pvt);
+	localusecnt--;
+	ast_update_use_count();
 }
 
 /*
@@ -549,15 +527,15 @@
  */
 
 static struct ast_translator adpcmtolin = {
-  "adpcmtolin",
-  AST_FORMAT_ADPCM,
-  AST_FORMAT_SLINEAR,
-  adpcmtolin_new,
-  adpcmtolin_framein,
-  adpcmtolin_frameout,
-  adpcm_destroy,
-  /* NULL */
-  adpcmtolin_sample
+	"adpcmtolin",
+	AST_FORMAT_ADPCM,
+	AST_FORMAT_SLINEAR,
+	adpcmtolin_new,
+	adpcmtolin_framein,
+	adpcmtolin_frameout,
+	adpcm_destroy,
+	/* NULL */
+	adpcmtolin_sample
 };
 
 /*
@@ -565,91 +543,84 @@
  */
 
 static struct ast_translator lintoadpcm = {
-  "lintoadpcm",
-  AST_FORMAT_SLINEAR,
-  AST_FORMAT_ADPCM,
-  lintoadpcm_new,
-  lintoadpcm_framein,
-  lintoadpcm_frameout,
-  adpcm_destroy,
-  /* NULL */
-  lintoadpcm_sample
+	"lintoadpcm",
+	AST_FORMAT_SLINEAR,
+	AST_FORMAT_ADPCM,
+	lintoadpcm_new,
+	lintoadpcm_framein,
+	lintoadpcm_frameout,
+	adpcm_destroy,
+	/* NULL */
+	lintoadpcm_sample
 };
 
-static void 
-parse_config(void)
-{
-  struct ast_config *cfg;
-  struct ast_variable *var;
-  if ((cfg = ast_config_load("codecs.conf"))) {
-    if ((var = ast_variable_browse(cfg, "plc"))) {
-      while (var) {
-       if (!strcasecmp(var->name, "genericplc")) {
-         useplc = ast_true(var->value) ? 1 : 0;
-         if (option_verbose > 2)
-           ast_verbose(VERBOSE_PREFIX_3 "codec_adpcm: %susing generic PLC\n", useplc ? "" : "not ");
-       }
-       var = var->next;
-      }
-    }
-    ast_config_destroy(cfg);
-  }
-}
-
-int
-reload(void)
-{
-  parse_config();
-  return 0;
-}
-
-int
-unload_module (void)
-{
-  int res;
-  ast_mutex_lock (&localuser_lock);
-  res = ast_unregister_translator (&lintoadpcm);
-  if (!res)
-    res = ast_unregister_translator (&adpcmtolin);
-  if (localusecnt)
-    res = -1;
-  ast_mutex_unlock (&localuser_lock);
-  return res;
-}
-
-int
-load_module (void)
-{
-  int res;
-  parse_config();
-  res = ast_register_translator (&adpcmtolin);
-  if (!res)
-    res = ast_register_translator (&lintoadpcm);
-  else

[... 2831 lines stripped ...]


More information about the asterisk-commits mailing list