Index: channel.c =================================================================== RCS file: /usr/cvsroot/asterisk/channel.c,v retrieving revision 1.243 diff -u -r1.243 channel.c --- channel.c 29 Sep 2005 17:40:24 -0000 1.243 +++ channel.c 4 Oct 2005 15:43:34 -0000 @@ -1505,7 +1505,7 @@ static struct ast_frame null_frame = { AST_FRAME_NULL, }; - + ast_mutex_lock(&chan->lock); if (chan->masq) { if (ast_do_masquerade(chan)) { @@ -1682,18 +1682,18 @@ ast_cdr_answer(chan->cdr); } - /* Run any generator sitting on the line */ - if (f && (f->frametype == AST_FRAME_VOICE) && chan->generatordata) { - /* Mask generator data temporarily and apply. If there is a timing function, it - will be calling the generator instead */ + /* Run generator sitting on the line if timing device not available + * and synchronous generation of outgoing frames is necessary */ + if (f && (f->frametype == AST_FRAME_VOICE) && chan->generatordata && + !(chan->timingfunc && chan->timingfd > -1)) { void *tmp; int res; - int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples); + int (*generate)(struct ast_channel *chan, void *tmp, + int datalen, int samples); - if (chan->timingfunc) { - ast_log(LOG_DEBUG, "Generator got voice, switching to phase locked mode\n"); - ast_settimeout(chan, 0, NULL, NULL); - } +#if 1 + ast_log(LOG_DEBUG, "Synchronous generator used\n"); +#endif tmp = chan->generatordata; chan->generatordata = NULL; generate = chan->generator->generate; @@ -1703,12 +1703,8 @@ ast_log(LOG_DEBUG, "Auto-deactivating generator\n"); ast_deactivate_generator(chan); } - } else if (f && (f->frametype == AST_FRAME_CNG)) { - if (chan->generator && !chan->timingfunc && (chan->timingfd > -1)) { - ast_log(LOG_DEBUG, "Generator got CNG, switching to zap timed mode\n"); - ast_settimeout(chan, 160, generator_force, chan); - } } + /* High bit prints debugging */ if (chan->fin & 0x80000000) ast_frame_dump(chan->name, f, "<<"); Index: apps/app_milliwatt.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_milliwatt.c,v retrieving revision 1.12 diff -u -r1.12 app_milliwatt.c --- apps/app_milliwatt.c 14 Sep 2005 20:46:49 -0000 1.12 +++ apps/app_milliwatt.c 4 Oct 2005 15:43:34 -0000 @@ -74,13 +74,23 @@ struct ast_frame wf; unsigned char waste[AST_FRIENDLY_OFFSET]; unsigned char buf[640]; + const int maxsamples = sizeof(buf) / sizeof (buf[0]); int i,*indexp = (int *) data; - if (len > sizeof(buf)) + /* Instead of len, use samples, because channel.c generator_force + * generate(chan, tmp, 0, 160) ignores len. In any case, len is + * a multiple of samples, given by number of samples times bytes per + * sample. In the case of ulaw, len = samples. for signed linear + * len = 2 * samples */ + + if (samples > maxsamples) { - ast_log(LOG_WARNING,"Only doing %d bytes (%d bytes requested)\n",(int)sizeof(buf),len); - len = sizeof(buf); + ast_log(LOG_WARNING, "Only doing %d samples (%d requested)\n", + maxsamples, samples); + samples = maxsamples; } + len = samples * sizeof (buf[0]); + waste[0] = 0; /* make compiler happy */ wf.frametype = AST_FRAME_VOICE; wf.subclass = AST_FORMAT_ULAW; @@ -88,7 +98,7 @@ wf.mallocd = 0; wf.data = buf; wf.datalen = len; - wf.samples = wf.datalen; + wf.samples = samples; wf.src = "app_milliwatt"; wf.delivery.tv_sec = 0; wf.delivery.tv_usec = 0; Index: apps/app_sms.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_sms.c,v retrieving revision 1.27 diff -u -r1.27 app_sms.c --- apps/app_sms.c 14 Sep 2005 20:46:49 -0000 1.27 +++ apps/app_sms.c 4 Oct 2005 15:43:34 -0000 @@ -1178,32 +1178,31 @@ { struct ast_frame f = { 0 }; unsigned char waste[AST_FRIENDLY_OFFSET]; +#define MAXSAMPLES (800) #ifdef OUTALAW - unsigned char buf[800]; + unsigned char buf[MAXSAMPLES]; #else - signed short buf[800]; + signed short buf[MAXSAMPLES]; #endif +#define SAMPLE2LEN (sizeof (buf[0])) sms_t *h = data; int i; - if (len > sizeof (buf)) { - ast_log (LOG_WARNING, "Only doing %d bytes (%d bytes requested)\n", (int)(sizeof (buf) / sizeof (signed short)), len); - len = sizeof (buf); -#ifdef OUTALAW - samples = len; -#else - samples = len / 2; -#endif + if (samples > MAXSAMPLES) { + ast_log (LOG_WARNING, "Only doing %d samples (%d requested)\n", + MAXSAMPLES, samples); + samples = MAXSAMPLES; } - waste[0] = 0; /* make compiler happy */ + len = samples * SAMPLE2LEN; + + waste[0] = 0; /* make compiler happy */ f.frametype = AST_FRAME_VOICE; #ifdef OUTALAW f.subclass = AST_FORMAT_ALAW; - f.datalen = samples; #else f.subclass = AST_FORMAT_SLINEAR; - f.datalen = samples * 2; #endif + f.datalen = len; f.offset = AST_FRIENDLY_OFFSET; f.mallocd = 0; f.data = buf; @@ -1255,6 +1254,8 @@ return -1; } return 0; +#undef SAMPLE2LEN +#undef MAXSAMPLES } static void sms_process (sms_t * h, int samples, signed short *data) Index: apps/app_chanspy.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_chanspy.c,v retrieving revision 1.23 diff -u -r1.23 app_chanspy.c --- apps/app_chanspy.c 14 Sep 2005 20:46:49 -0000 1.23 +++ apps/app_chanspy.c 4 Oct 2005 15:43:34 -0000 @@ -258,6 +258,9 @@ return -1; } + /* We are using slin. len is 2 * samples */ + len = samples * 2; + ast_mutex_lock(&csth->spy.lock); while((f = csth->spy.queue[0])) { csth->spy.queue[0] = f->next;