[asterisk-commits] branch rizzo/base r9530 - in /team/rizzo/base: ./ apps/ codecs/ funcs/ includ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Feb 11 08:29:02 MST 2006


Author: rizzo
Date: Sat Feb 11 09:28:49 2006
New Revision: 9530

URL: http://svn.digium.com/view/asterisk?rev=9530&view=rev
Log:
+ revised codecs implementation, see README.BRANCH
+ import config-based numbers and date/time spelling into
  app_playback.c
+ unlink slinfactory from the build, it is not used anywhere.


Modified:
    team/rizzo/base/Makefile
    team/rizzo/base/README.BRANCH
    team/rizzo/base/apps/app_playback.c
    team/rizzo/base/cli.c
    team/rizzo/base/codecs/codec_a_mu.c
    team/rizzo/base/codecs/codec_adpcm.c
    team/rizzo/base/codecs/codec_alaw.c
    team/rizzo/base/codecs/codec_g723_1.c
    team/rizzo/base/codecs/codec_g726.c
    team/rizzo/base/codecs/codec_gsm.c
    team/rizzo/base/codecs/codec_ilbc.c
    team/rizzo/base/codecs/codec_lpc10.c
    team/rizzo/base/codecs/codec_speex.c
    team/rizzo/base/codecs/codec_ulaw.c
    team/rizzo/base/config.c
    team/rizzo/base/file.c
    team/rizzo/base/funcs/func_env.c
    team/rizzo/base/include/asterisk/linkedlists.h
    team/rizzo/base/include/asterisk/module.h
    team/rizzo/base/include/asterisk/sha1.h
    team/rizzo/base/include/asterisk/translate.h
    team/rizzo/base/loader.c
    team/rizzo/base/pbx.c
    team/rizzo/base/res/res_smdi.c
    team/rizzo/base/say2.c
    team/rizzo/base/sha1.c
    team/rizzo/base/slinfactory.c
    team/rizzo/base/translate.c

Modified: team/rizzo/base/Makefile
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/Makefile?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/Makefile (original)
+++ team/rizzo/base/Makefile Sat Feb 11 09:28:49 2006
@@ -373,8 +373,11 @@
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
 	astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
-	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
+	netsock.o \
+	ast_expr2.o ast_expr2f.o \
 	cryptostub.o sha1.o
+
+# unused	slinfactory.o \
 
 SAY_SRCS=	say2.c	\
 		say/say_cz.c	say/say_da.c	say/say_de.c	\

Modified: team/rizzo/base/README.BRANCH
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/README.BRANCH?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/README.BRANCH (original)
+++ team/rizzo/base/README.BRANCH Sat Feb 11 09:28:49 2006
@@ -3,6 +3,38 @@
 in the main branch over time.
 
 A partial and possibly outdated list of changes follows:
+
+2006.02.11	app_playback.c
+	the code for config-file-based number spelling
+	has been moved here, and there is also an initial
+	implementation of support for date fields.
+	Needs to be documented and cleaned up a bit.
+
+2006.02.11	codecs refactoring
+	A revision of the interface to support codecs.
+	The various codec_*c files contained large sections of
+	replicated code, with various bugs (null pointer
+	dereferences, bogus error handling, etc.).
+	I have moved the common functionality in functions
+	in translate.c, and slightly modified the codec
+	descriptors so that common routines can be used
+	in many cases.
+	Also, the locking and usecount has been moved to a
+	structure ast_module_lock, which is practically the
+	same one used in file.c (not merged yet).
+	The next step will be to put this structure into
+	the module descriptor.
+
+	There is still a bit of work to do in the generation
+	of 'sample' frames - most codecs only produce blocks
+	of 0-valued bytes (i.e. perfect silence) which are
+	not the best input for codecs.
+	Given that all codecs so far support conversion from/to slin
+	a sensible approach would be to use a standard 'slin' frame
+	as input to produce the sample frame in all formats, still
+	leaving the chance for some 'special' codecs to
+	produce their own frame if there is no way to convert
+	to slinear.
 
 2006.02.03	file handlers
 	A revision of the interface to support file handlers,

Modified: team/rizzo/base/apps/app_playback.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/apps/app_playback.c?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/apps/app_playback.c (original)
+++ team/rizzo/base/apps/app_playback.c Sat Feb 11 09:28:49 2006
@@ -71,6 +71,169 @@
 
 LOCAL_USER_DECL;
 
+static struct ast_config *say_cfg;
+
+static void say_load(void)
+{
+        if (say_cfg == NULL)
+                say_cfg = ast_config_load("say.conf");
+}
+
+/* 
+ * Typical 'say' arguments in addition to the date or number or string
+ * to say. We do not include 'options' because they may be different
+ * in recursive calls, and so they are better left as an external
+ * parameter.
+ */
+typedef struct {
+        struct ast_channel *chan;
+        const char *ints;
+        const char *language;
+        int audiofd;
+        int ctrlfd;
+} say_args_t;
+
+static int s_streamwait3(const say_args_t *a, const char *fn)
+{
+        int res = ast_streamfile(a->chan, fn, a->language);
+        if (res) {
+                ast_log(LOG_WARNING, "Unable to play message %s\n", fn);
+                return res;
+        }
+        res = (a->audiofd  > -1 && a->ctrlfd > -1) ?
+                ast_waitstream_full(a->chan, a->ints, a->audiofd, a->ctrlfd) :
+                ast_waitstream(a->chan, a->ints);
+        ast_stopstream(a->chan);
+        return res;  
+}
+
+/*
+ * the %c or xxx: prefix is used in the match but not
+ * to set the 'SAY' string.
+ */
+static int do_say(say_args_t *a, const char *s, const char *options, int depth)
+{
+	struct ast_variable *v;
+	char *lang, *x, *rule = NULL;
+	int ret = 0;   
+	struct varshead head = { .first = NULL, .last = NULL };
+	struct ast_var_t *n;
+	char dbuf[64];
+
+	if (depth++ > 10) {
+		ast_log(LOG_WARNING, "recursion too deep, exiting\n");
+		return -1;
+	}
+
+	/*
+	 * '%c' prefixes are expanded using strftime values.
+	 */
+	if (s[0] == '%' && s[1] != '\0' && s[2] == '\0') {
+		time_t now = time(NULL);
+		struct tm t;
+		int d = 0;
+
+		localtime_r(&now, &t);
+
+		s++;
+		switch(*s) {
+		case 'm':	/* month, 0..11 */
+			d = t.tm_mon;
+			break;
+		case 'd': /* day of month, 1..31 */
+		case 'e': /* day of month, 1..31 */
+			d = t.tm_mday;
+			break;
+		case 'Y':	/* year, only above 1900 */
+			d = t.tm_year + 1900;
+			break;
+		case 'I':	/* 12-hour */
+		case 'l':	/* 12-hour */
+			d = (t.tm_hour + 11) % 12 + 1;
+			break;
+		case 'H':	/* 24 hours */
+		case 'k':	/* 24 hours */
+			d = t.tm_hour;
+			break;
+		case 'M':	/* minute */
+		case 'N':	/* minute */
+			d = t.tm_min;
+			break;
+		case 'S':	/* seconds */
+			d = t.tm_sec;
+			break;
+		default:
+			s--;
+		}
+		if (*s != '%') {
+			sprintf(dbuf, "%c:%d", *s, d);
+			s = dbuf;
+		}
+	}
+
+	/* scan languages same as in file.c */
+	if (a->language == NULL)
+		a->language = "en";     /* default */
+	ast_log(LOG_WARNING, "try <%s> in <%s>\n", s, a->language);
+	lang = ast_strdupa(a->language);
+	if (!lang)      /* no memory! */
+		return -1;
+	for (;;) {
+		for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) {
+			if (ast_extension_match(v->name, s)) {
+				rule = ast_strdupa(v->value);
+				break;
+			}
+		}
+		if (rule)
+			break;
+		if ( (x = strchr(lang, '_')) )
+			*x = '\0';      /* try without suffix */
+		else if (strcmp(lang, "en"))
+			lang = "en";    /* last resort, try 'en' if not done yet */
+		else
+			break;
+	}
+	if (!rule)
+		return 0;
+
+	if ( (x = strchr(s, ':')) )
+		s = x + 1;
+	ast_log(LOG_WARNING, "value is <%s>\n", s);
+	n = ast_var_assign("SAY", s);
+	AST_LIST_INSERT_HEAD(&head, n, entries);
+	while ( ret <= 0 && (x = strsep(&rule, ",")) ) { /* exit on key */
+		char fn[128];
+
+		x = ast_skip_blanks(x);
+		ast_trim_blanks(x);
+		memset(fn, 0, sizeof(fn)); /* XXX why isn't done in pbx_substitute_variables_helper! */
+		pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn));
+		ast_log(LOG_WARNING, "doing [%s]\n", fn);
+		if (strcasestr(fn, "say:") == fn) { /* recurse */
+			ret = do_say(a, fn+4, options, depth);
+		} else {
+			ret =  s_streamwait3(a, fn);
+		}
+	}
+	ast_var_delete(n);
+	return ret;
+}
+
+static int say_full(struct ast_channel *chan, const char *string,
+        const char *ints, const char *lang, const char *options,
+        int audiofd, int ctrlfd)
+{
+        say_args_t a = { chan, ints, lang, audiofd, ctrlfd };
+  
+        say_load();
+        if (!say_cfg) {
+                ast_log(LOG_WARNING, "no say.conf, cannot spell '%s'\n", string);
+                return -1;   
+        }
+        return do_say(&a, string, options, 0);
+}
+
 static int playback_exec(struct ast_channel *chan, void *data)
 {
 	int res = 0;
@@ -111,8 +274,7 @@
 	if (chan->_state != AST_STATE_UP) {
 		if (option_skip) {
 			/* At the user's option, skip if the line is not up */
-			LOCAL_USER_REMOVE(u);
-			return 0;
+			goto done;
 		} else if (!option_noanswer)
 			/* Otherwise answer unless we're supposed to send this while on-hook */
 			res = ast_answer(chan);
@@ -124,7 +286,7 @@
 		ast_stopstream(chan);
 		while (!res && (front = strsep(&tmp, "&"))) {
 			if (option_say)
-				res = ast_say_full(chan, front, "", chan->language, NULL, -1, -1);
+				res = say_full(chan, front, "", chan->language, NULL, -1, -1);
 			else
 				res = ast_streamfile(chan, front, chan->language);
 			if (!res) { 
@@ -140,6 +302,7 @@
 		}
 		pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", mres ? "FAILED" : "SUCCESS");
 	}
+done:
 	LOCAL_USER_REMOVE(u);
 	return res;
 }

Modified: team/rizzo/base/cli.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/cli.c?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/cli.c (original)
+++ team/rizzo/base/cli.c Sat Feb 11 09:28:49 2006
@@ -39,6 +39,7 @@
 #include "asterisk/logger.h"
 #include "asterisk/options.h"
 #include "asterisk/cli.h"
+#include "asterisk/linkedlists.h"
 #include "asterisk/module.h"
 #include "asterisk/pbx.h"
 #include "asterisk/channel.h"

Modified: team/rizzo/base/codecs/codec_a_mu.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/codecs/codec_a_mu.c?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/codecs/codec_a_mu.c (original)
+++ team/rizzo/base/codecs/codec_a_mu.c Sat Feb 11 09:28:49 2006
@@ -43,12 +43,7 @@
 #include "asterisk/ulaw.h"
 #include "asterisk/utils.h"
 
-#define BUFFER_SIZE   8096	/* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "A-law and Mulaw direct Coder/Decoder";
+#define BUFFER_SAMPLES   8000	/* size for the translation buffers */
 
 static unsigned char mu2a[256];
 static unsigned char a2mu[256];
@@ -57,146 +52,37 @@
 
 #include "ulaw_slin_ex.h"
 
-/*
- * Private workspace for translating signed linear signals to alaw.
- */
+/*! \brief convert frame data and store into the buffer */
+static int alawtoulaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	int x;
+	unsigned char *src = f->data;
+	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
 
-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;
-};
-
-/*
- * Private workspace for translating laws.
- */
-
-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;
-};
-
-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;
+	for ( x = 0 ; x < f->samples; x++)
+		dst[x] = a2mu[src[x]];
+	pvt->samples += f->samples;
+	pvt->datalen += f->datalen;
 	return 0;
 }
 
-static struct ast_frame *alawtoulaw_frameout(struct ast_translator_pvt *pvt)
+/*! \brief convert frame data and store into the buffer */
+static int ulawtoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	struct ulaw_encoder_pvt *tmp = (struct ulaw_encoder_pvt *)pvt;
+	int x;
+	unsigned char *src = f->data;
+	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->samples;
 
-	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;
+	for ( x = 0 ; x < f->samples; x++)
+		dst[x] = mu2a[src[x]];
+	pvt->samples += f->samples;
+	pvt->datalen += f->datalen;
 	return 0;
 }
 
 /*
- * LinToalaw_FrameOut
- *  Convert a buffer of raw 16-bit signed linear PCM to a buffer
- *  of 4-bit alaw packed two to a byte (Big Endian).
- *
- * Results:
- *  Foo
- *
- * Side effects:
- *  Leftover inbuf data gets packed, tail gets updated.
+ * alawToLin_Sample. Just random data, somehow...
  */
-
-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;
-}
-
-/*
- * alawToLin_Sample
- */
-
 static struct ast_frame *alawtoulaw_sample(void)
 {
 	static struct ast_frame f;
@@ -207,7 +93,7 @@
 	f.mallocd = 0;
 	f.offset = 0;
 	f.src = __PRETTY_FUNCTION__;
-	f.data = ulaw_slin_ex;
+	f.data = ulaw_slin_ex; /* XXX what ? */
 	return &f;
 }
 
@@ -225,66 +111,41 @@
 	return &f;
 }
 
-/*
- * alaw_Destroy
- *  Destroys a private workspace.
- *
- * Results:
- *  It's gone!
- *
- * Side effects:
- *  None.
- */
-
-static void alaw_destroy(struct ast_translator_pvt *pvt)
-{
-	free(pvt);
-	localusecnt--;
-	ast_update_use_count();
-}
-
-/*
- * The complete translator for alawToLin.
- */
+static struct ast_module_lock me = { .usecnt = -1 };
 
 static struct ast_translator alawtoulaw = {
-	"alawtoulaw",
-	AST_FORMAT_ALAW,
-	AST_FORMAT_ULAW,
-	alawtoulaw_new,
-	alawtoulaw_framein,
-	alawtoulaw_frameout,
-	alaw_destroy,
-	/* NULL */
-	alawtoulaw_sample
+	.name = "alawtoulaw",
+	.srcfmt = AST_FORMAT_ALAW,
+	.dstfmt = AST_FORMAT_ULAW,
+	.framein = alawtoulaw_framein,
+	.sample = alawtoulaw_sample,
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES,
+	.lockp = &me,
 };
 
-/*
- * The complete translator for LinToalaw.
- */
+static struct ast_translator ulawtoalaw = {
+	.name = "ulawtoalaw",
+	.srcfmt = AST_FORMAT_ULAW,
+	.dstfmt = AST_FORMAT_ALAW,
+	.framein = ulawtoalaw_framein,
+	.sample = ulawtoalaw_sample,
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES,
+	.lockp = &me,
+};
 
-static struct ast_translator ulawtoalaw = {
-	"ulawtoalaw",
-	AST_FORMAT_ULAW,
-	AST_FORMAT_ALAW,
-	ulawtoalaw_new,
-	ulawtoalaw_framein,
-	ulawtoalaw_frameout,
-	alaw_destroy,
-	/* NULL */
-	ulawtoalaw_sample
-};
+/*! \brief standard module glue */
 
 int unload_module(void)
 {
 	int res;
-	ast_mutex_lock(&localuser_lock);
+	ast_mutex_lock(&me.lock);
 	res = ast_unregister_translator(&ulawtoalaw);
-	if (!res)
-		res = ast_unregister_translator(&alawtoulaw);
-	if (localusecnt)
+	res |= ast_unregister_translator(&alawtoulaw);
+	if (me.usecnt)
 		res = -1;
-	ast_mutex_unlock(&localuser_lock);
+	ast_mutex_unlock(&me.lock);
 	return res;
 }
 
@@ -304,20 +165,14 @@
 	return res;
 }
 
-/*
- * Return a description of this module.
- */
-
 char *description(void)
 {
-	return tdesc;
+	return "A-law and Mulaw direct Coder/Decoder";
 }
 
 int usecount(void)
 {
-	int res;
-	STANDARD_USECOUNT(res);
-	return res;
+	return me.usecnt;
 }
 
 char *key()

Modified: team/rizzo/base/codecs/codec_adpcm.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/codecs/codec_adpcm.c?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/codecs/codec_adpcm.c (original)
+++ team/rizzo/base/codecs/codec_adpcm.c Sat Feb 11 09:28:49 2006
@@ -40,6 +40,7 @@
 
 #include "asterisk/lock.h"
 #include "asterisk/logger.h"
+#include "asterisk/linkedlists.h"
 #include "asterisk/module.h"
 #include "asterisk/config.h"
 #include "asterisk/options.h"
@@ -50,14 +51,7 @@
 /* define NOT_BLI to use a faster but not bit-level identical version */
 /* #define NOT_BLI */
 
-#define BUFFER_SIZE   8096	/* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "Adaptive Differential PCM Coder/Decoder";
-
-static int useplc = 0;
+#define BUFFER_SAMPLES   8096	/* size for the translation buffers */
 
 /* Sample frame data */
 
@@ -227,250 +221,81 @@
 	return encoded;
 }
 
-/*
- * Private workspace for translating signed linear signals to ADPCM.
- */
-
-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 */
+/*----------------- Asterisk-codec glue ------------*/
+
+/*! \brief Workspace for translating signed linear signals to ADPCM. */
+struct adpcm_encoder_pvt {
 	struct adpcm_state state;
-	int tail;
-};
-
-/*
- * Private workspace for translating ADPCM signals to signed linear.
- */
-
-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 */
+	int16_t inbuf[BUFFER_SAMPLES];	/* Unencoded signed linear values */
+};
+
+/*! \brief Workspace for translating ADPCM signals to signed linear. */
+struct adpcm_decoder_pvt {
 	struct adpcm_state state;
-	int tail;
-	plc_state_t plc;
-};
-
-/*
- * AdpcmToLin_New
- *  Create a new instance of adpcm_decoder_pvt.
- *
- * Results:
- *  Returns a pointer to the new instance.
- *
- * Side effects:
- *  None.
- */
-
-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;
-}
-
-/*
- * LinToAdpcm_New
- *  Create a new instance of adpcm_encoder_pvt.
- *
- * Results:
- *  Returns a pointer to the new instance.
- *
- * Side effects:
- *  None.
- */
-
-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;
-}
-
-/*
- * AdpcmToLin_FrameIn
- *  Take an input buffer with packed 4-bit ADPCM values and put decoded PCM in outbuf, 
- *  if there is room left.
- *
- * Results:
- *  Foo
- *
- * Side effects:
- *  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;
+};
+
+/*! \brief decode 4-bit adpcm frame data and store in output buffer */
+static int adpcmtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	struct adpcm_decoder_pvt *tmp = 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);
-
+	unsigned char *src = f->data;
+	int16_t *dst = (int16_t *)pvt->outbuf + pvt->samples;
+
+	for (x=0; x < f->datalen; x++) {
+		*dst++ = decode((src[x] >> 4) & 0xf, &tmp->state);
+		*dst++ = decode(src[x] & 0x0f, &tmp->state);
+	}
+	pvt->samples += f->samples;
+	pvt->datalen += 2*f->samples;
 	return 0;
 }
 
-/*
- * AdpcmToLin_FrameOut
- *  Convert 4-bit ADPCM encoded signals to 16-bit signed linear.
- *
- * Results:
- *  Converted signals are placed in tmp->f.data, tmp->f.datalen
- *  and tmp->f.samples are calculated.
- *
- * Side effects:
- *  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)
+/*! \brief fill input buffer with 16-bit signed linear PCM values. */
+static int lintoadpcm_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	struct adpcm_encoder_pvt *tmp = pvt->pvt;
+
+	memcpy(&tmp->inbuf[pvt->samples], f->data, f->datalen);
+	pvt->samples += f->samples;
+	return 0;
+}
+
+/*! \brief convert inbuf and store into frame */
+static struct ast_frame *lintoadpcm_frameout(struct ast_trans_pvt *pvt)
+{
+	struct adpcm_encoder_pvt *tmp = pvt->pvt;
+	struct ast_frame *f;
+	int i;
+	int samples = pvt->samples;	/* save original number */
+  
+	if (samples < 2)
 		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;
-}
-
-/*
- * LinToAdpcm_FrameIn
- *  Fill an input buffer with 16-bit signed linear PCM values.
- *
- * Results:
- *  None.
- *
- * Side effects:
- *  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;
-}
-
-/*
- * LinToAdpcm_FrameOut
- *  Convert a buffer of raw 16-bit signed linear PCM to a buffer
- *  of 4-bit ADPCM packed two to a byte (Big Endian).
- *
- * Results:
- *  Foo
- *
- * Side effects:
- *  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;
-  
-	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] =
+	pvt->samples &= ~1; /* atomic size is 2 samples */
+
+	for (i = 0; i < pvt->samples; i += 2) {
+		pvt->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;
+	f = ast_trans_frameout(pvt, pvt->samples/2, 0);
 
 	/*
-	 * If there is a signal left over (there should be no more than
-	 * one) move it to the beginning of the input buffer.
+	 * If there is a left over sample, 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;
-}
-
-
-/*
- * AdpcmToLin_Sample
- */
-
+	if (samples & 1) {	/* move the leftover sample at beginning */
+		tmp->inbuf[0] = tmp->inbuf[samples - 1];
+		pvt->samples = 1;
+	}
+	return f;
+}
+
+
+/*! \brief AdpcmToLin_Sample */
 static struct ast_frame *adpcmtolin_sample(void)
 {
 	static struct ast_frame f;
@@ -485,10 +310,7 @@
 	return &f;
 }
 
-/*
- * LinToAdpcm_Sample
- */
-
+/*! \brief LinToAdpcm_Sample */
 static struct ast_frame *lintoadpcm_sample(void)
 {
 	static struct ast_frame f;
@@ -504,75 +326,51 @@
 	return &f;
 }
 
-/*
- * Adpcm_Destroy
- *  Destroys a private workspace.
- *
- * Results:
- *  It's gone!
- *
- * Side effects:
- *  None.
- */
-
-static void adpcm_destroy(struct ast_translator_pvt *pvt)
-{
-	free(pvt);
-	localusecnt--;
-	ast_update_use_count();
-}
-
-/*
- * The complete translator for ADPCMToLin.
- */
+struct ast_module_lock me = { .usecnt = -1 };
 
 static struct ast_translator adpcmtolin = {
-	"adpcmtolin",
-	AST_FORMAT_ADPCM,
-	AST_FORMAT_SLINEAR,
-	adpcmtolin_new,
-	adpcmtolin_framein,
-	adpcmtolin_frameout,
-	adpcm_destroy,
-	/* NULL */
-	adpcmtolin_sample
-};
-
-/*
- * The complete translator for LinToADPCM.
- */
+	.name = "adpcmtolin",
+	.srcfmt = AST_FORMAT_ADPCM,
+	.dstfmt = AST_FORMAT_SLINEAR,
+	.framein = adpcmtolin_framein,
+	.sample = adpcmtolin_sample,
+	.desc_size = sizeof(struct adpcm_decoder_pvt),
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES * 2,
+	.plc_samples = 160,
+	.lockp = &me,
+};
 
 static struct ast_translator lintoadpcm = {
-	"lintoadpcm",
-	AST_FORMAT_SLINEAR,
-	AST_FORMAT_ADPCM,
-	lintoadpcm_new,
-	lintoadpcm_framein,
-	lintoadpcm_frameout,
-	adpcm_destroy,
-	/* NULL */
-	lintoadpcm_sample
+	.name = "lintoadpcm",
+	.srcfmt = AST_FORMAT_SLINEAR,
+	.dstfmt = AST_FORMAT_ADPCM,
+	.framein = lintoadpcm_framein,
+	.frameout = lintoadpcm_frameout,
+	.sample = lintoadpcm_sample,
+	.desc_size = sizeof (struct adpcm_encoder_pvt),
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES/ 2,	/* 2 samples per byte */
+	.lockp = &me,
 };
 
 static void parse_config(void)
 {
-	struct ast_config *cfg;
+	struct ast_config *cfg = ast_config_load("codecs.conf");
 	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;
-			}
+	if (cfg == NULL)
+		return;
+	for (var = ast_variable_browse(cfg, "plc"); var ; var = var->next) {
+		if (!strcasecmp(var->name, "genericplc")) {
+			adpcmtolin.useplc = ast_true(var->value) ? 1 : 0;
+			if (option_verbose > 2)
+				ast_verbose(VERBOSE_PREFIX_3 "codec_adpcm: %susing generic PLC\n", adpcmtolin.useplc ? "" : "not ");
 		}
-		ast_config_destroy(cfg);
-	}
-}
-
+	}
+	ast_config_destroy(cfg);
+}
+
+/*! \brief standard module glue */
 int reload(void)
 {
 	parse_config();
@@ -582,13 +380,12 @@
 int unload_module(void)
 {
 	int res;
-	ast_mutex_lock(&localuser_lock);
+	ast_mutex_lock(&me.lock);
 	res = ast_unregister_translator(&lintoadpcm);
-	if (!res)
-		res = ast_unregister_translator(&adpcmtolin);
-	if (localusecnt)
+	res |= ast_unregister_translator(&adpcmtolin);
+	if (me.usecnt)
 		res = -1;
-	ast_mutex_unlock(&localuser_lock);
+	ast_mutex_unlock(&me.lock);
 	return res;
 }
 
@@ -604,20 +401,14 @@
 	return res;
 }
 
-/*
- * Return a description of this module.
- */
-
 char *description(void)
 {
-	return tdesc;
+	return "Adaptive Differential PCM Coder/Decoder";
 }
 
 int usecount(void)
 {
-	int res;
-	STANDARD_USECOUNT(res);
-	return res;
+	return me.usecnt;
 }
 
 char *key()

Modified: team/rizzo/base/codecs/codec_alaw.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/codecs/codec_alaw.c?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/codecs/codec_alaw.c (original)
+++ team/rizzo/base/codecs/codec_alaw.c Sat Feb 11 09:28:49 2006
@@ -44,232 +44,42 @@
 #include "asterisk/alaw.h"
 #include "asterisk/utils.h"
 
-#define BUFFER_SIZE   8096	/* size for the translation buffers */
-
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt = 0;
-
-static char *tdesc = "A-law Coder/Decoder";
-
-static int useplc = 0;
+#define BUFFER_SAMPLES   8096	/* size for the translation buffers */
 
 /* Sample frame data (Mu data is okay) */
 
 #include "slin_ulaw_ex.h"
 #include "ulaw_slin_ex.h"
 
-/*!
- * \brief Private workspace for translating signed linear signals to alaw.
- */
-struct alaw_encoder_pvt
+/*! \brief decode frame into lin and fill output buffer. */
+static int alawtolin_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
-	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;
-};
+	int i;
+	unsigned char *src = f->data;
+	int16_t *dst = (int16_t *)pvt->outbuf;
 
-/*!
- * \brief Private workspace for translating alaw signals to signed linear.
- */
-struct alaw_decoder_pvt
-{
-	struct ast_frame f;
-	char offset[AST_FRIENDLY_OFFSET];	/* Space to build offset */
-	short outbuf[BUFFER_SIZE];		/* Decoded signed linear values */
-	int tail;
-	plc_state_t plc;
-};
-
-/*!
- * \brief alawToLin_New
- *  Create a new instance of alaw_decoder_pvt.
- *
- * Results:
- *  Returns a pointer to the new instance.
- *
- * Side effects:
- *  None.
- */
-
-static struct ast_translator_pvt *alawtolin_new(void)
-{
-	struct alaw_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;
-}
-
-/*!
- * \brief LinToalaw_New
- *  Create a new instance of alaw_encoder_pvt.
- *
- * Results:
- *  Returns a pointer to the new instance.
- *
- * Side effects:
- *  None.
- */
-
-static struct ast_translator_pvt *lintoalaw_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;
-}
-
-/*!
- * \brief alawToLin_FrameIn
- *  Fill an input buffer with packed 4-bit alaw values if there is room
- *  left.
- *
- * Results:
- *  Foo
- *
- * Side effects:
- *  tmp->tail is the number of packed values in the buffer.
- */
-
-static int alawtolin_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
-	struct alaw_decoder_pvt *tmp = (struct alaw_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) * 2 > sizeof(tmp->outbuf)) {
-			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 ((tmp->tail + f->datalen) * 2 > 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] = AST_ALAW(b[x]);
-
-	if(useplc)
-		plc_rx(&tmp->plc, tmp->outbuf+tmp->tail, f->datalen);
-
-	tmp->tail += f->datalen;
+	for ( i = 0; i < f->samples; i++)
+		dst[pvt->samples + i] = AST_ALAW(src[i]);
+	pvt->samples += f->samples;
+	pvt->datalen += 2*f->samples;	/* 2 bytes/sample */
 	return 0;
 }
 
-/*!
- * \brief alawToLin_FrameOut
- *  Convert 4-bit alaw encoded signals to 16-bit signed linear.
- *
- * Results:
- *  Converted signals are placed in tmp->f.data, tmp->f.datalen
- *  and tmp->f.samples are calculated.
- *
- * Side effects:
- *  None.
- */
+/*! \brief convert and store input samples in output buffer */
+static int lintoalaw_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
+{
+	int x;
+	char *dst = pvt->outbuf + pvt->samples;
+	int16_t *src = f->data;
 
-static struct ast_frame *alawtolin_frameout(struct ast_translator_pvt *pvt)
-{
-	struct alaw_decoder_pvt *tmp = (struct alaw_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;
-}
-
-/*!
- * \brief LinToalaw_FrameIn
- *  Fill an input buffer with 16-bit signed linear PCM values.
- *
- * Results:
- *  None.
- *
- * Side effects:
- *  tmp->tail is number of signal values in the input buffer.
- */
-
-static int lintoalaw_framein(struct ast_translator_pvt *pvt, struct ast_frame *f)
-{
-	struct alaw_encoder_pvt *tmp = (struct alaw_encoder_pvt *)pvt;
-	int x;
-	short *s;
-	if (tmp->tail + f->datalen / 2 >= sizeof(tmp->outbuf)) {
-		ast_log(LOG_WARNING, "Out of buffer space\n");
-		return -1;
-	}
-	s = f->data;
-	for (x=0;x<f->datalen/2;x++) 
-		tmp->outbuf[x+tmp->tail] = AST_LIN2A(s[x]);
-	tmp->tail += f->datalen/2;
+	for ( x = 0; x < f->samples; x++) 
+		*dst++ = AST_LIN2A(src[x]);
+	pvt->samples += f->samples;
+	pvt->datalen += f->samples;	/* 1 byte/sample */
 	return 0;
 }
 
-/*!
- * \brief LinToalaw_FrameOut
- *  Convert a buffer of raw 16-bit signed linear PCM to a buffer
- *  of 4-bit alaw packed two to a byte (Big Endian).
- *
- * Results:
- *  Foo
- *
- * Side effects:
- *  Leftover inbuf data gets packed, tail gets updated.
- */
-
-static struct ast_frame *lintoalaw_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;
-}
-
-/*!
- * \brief alawToLin_Sample
- */
-
+/*! \brief alawToLin_Sample */
 static struct ast_frame *alawtolin_sample(void)
 {
 	static struct ast_frame f;
@@ -284,17 +94,13 @@
 	return &f;
 }
 
-/*!
- * \brief LinToalaw_Sample
- */
-
+/*! \brief LinToalaw_Sample */
 static struct ast_frame *lintoalaw_sample(void)
 {
 	static struct ast_frame f;
 	f.frametype = AST_FRAME_VOICE;
 	f.subclass = AST_FORMAT_SLINEAR;
 	f.datalen = sizeof(slin_ulaw_ex);
-	/* Assume 8000 Hz */
 	f.samples = sizeof(slin_ulaw_ex) / 2;
 	f.mallocd = 0;
 	f.offset = 0;
@@ -303,75 +109,48 @@
 	return &f;
 }
 
-/*!
- * \brief alaw_Destroy
- *  Destroys a private workspace.
- *
- * Results:
- *  It's gone!
- *
- * Side effects:
- *  None.
- */
-
-static void alaw_destroy(struct ast_translator_pvt *pvt)
-{
-	free(pvt);
-	localusecnt--;
-	ast_update_use_count();
-}
-
-/*!
- * \brief The complete translator for alawToLin.
- */
+static struct ast_module_lock me = { .usecnt = -1 };
 
 static struct ast_translator alawtolin = {
-	"alawtolin",
-	AST_FORMAT_ALAW,
-	AST_FORMAT_SLINEAR,
-	alawtolin_new,
-	alawtolin_framein,
-	alawtolin_frameout,
-	alaw_destroy,
-	/* NULL */
-	alawtolin_sample
+	.name = "alawtolin",
+	.srcfmt = AST_FORMAT_ALAW,
+	.dstfmt = AST_FORMAT_SLINEAR,
+	.framein = alawtolin_framein,
+	.sample = alawtolin_sample,
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES * 2,
+	.plc_samples = 160,
+	.lockp = &me,
 };
-
-/*!
- * \brief The complete translator for LinToalaw.
- */
 
 static struct ast_translator lintoalaw = {
 	"lintoalaw",
-	AST_FORMAT_SLINEAR,
-	AST_FORMAT_ALAW,
-	lintoalaw_new,
-	lintoalaw_framein,
-	lintoalaw_frameout,
-	alaw_destroy,
-	/* NULL */
-	lintoalaw_sample
+	.srcfmt = AST_FORMAT_SLINEAR,
+	.dstfmt = AST_FORMAT_ALAW,
+	.framein = lintoalaw_framein,
+	.sample = lintoalaw_sample,
+	.buffer_samples = BUFFER_SAMPLES,
+	.buf_size = BUFFER_SAMPLES,
+	.lockp = &me,
 };
 
 static void parse_config(void)
 {
-	struct ast_config *cfg;
 	struct ast_variable *var;
+	struct ast_config *cfg = ast_config_load("codecs.conf");
+	if (!cfg)
+		return;
+	for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) {
+		if (!strcasecmp(var->name, "genericplc")) {
+			alawtolin.useplc = ast_true(var->value) ? 1 : 0;
+			if (option_verbose > 2)
+				ast_verbose(VERBOSE_PREFIX_3 "codec_alaw: %susing generic PLC\n", alawtolin.useplc ? "" : "not ");
+		}
+	}
+	ast_config_destroy(cfg);
+}
 
-	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_alaw: %susing generic PLC\n", useplc ? "" : "not ");
-				}
-				var = var->next;
-			}
-		}
-		ast_config_destroy(cfg);
-	}
-}
+/*! \brief standard module stuff */
 
 int reload(void)
 {
@@ -382,13 +161,12 @@
 int unload_module(void)
 {
 	int res;
-	ast_mutex_lock(&localuser_lock);
+	ast_mutex_lock(&me.lock);
 	res = ast_unregister_translator(&lintoalaw);
-	if (!res)
-		res = ast_unregister_translator(&alawtolin);
-	if (localusecnt)
+	res |= ast_unregister_translator(&alawtolin);
+	if (me.usecnt)
 		res = -1;
-	ast_mutex_unlock(&localuser_lock);
+	ast_mutex_unlock(&me.lock);
 	return res;
 }
 
@@ -404,20 +182,14 @@
 	return res;
 }
 
-/*
- * Return a description of this module.
- */
-
 char *description(void)
 {
-	return tdesc;
+	return "A-law Coder/Decoder";
 }
 
 int usecount(void)
 {
-	int res;
-	STANDARD_USECOUNT(res);
-	return res;
+	return me.usecnt;
 }
 
 char *key()

Modified: team/rizzo/base/codecs/codec_g723_1.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/base/codecs/codec_g723_1.c?rev=9530&r1=9529&r2=9530&view=diff
==============================================================================
--- team/rizzo/base/codecs/codec_g723_1.c (original)
+++ team/rizzo/base/codecs/codec_g723_1.c Sat Feb 11 09:28:49 2006
@@ -74,14 +74,11 @@
 #include "slin_g723_ex.h"
 #include "g723_slin_ex.h"
 
-AST_MUTEX_DEFINE_STATIC(localuser_lock);
-static int localusecnt=0;
-
-#ifdef ANNEX_B

[... 5325 lines stripped ...]


More information about the asterisk-commits mailing list