aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authoroej <oej@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-30 06:07:04 +0000
committeroej <oej@f38db490-d61c-443f-a65b-d21fe96a405b>2006-03-30 06:07:04 +0000
commit60636c259914d27a04b43c8bc26dece1871d876a (patch)
tree57c1cb7f263e43e28f5b083076ff222662216773 /apps
parenta9a990c34439999f57a0993ddf1b81c8501bae91 (diff)
Issue #5374 - Enable internal timing of generators (cmantunes)
Thanks everyone involved for hard work, testing and testing! git-svn-id: http://svn.digium.com/svn/asterisk/trunk@16473 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r--apps/app_milliwatt.c21
-rw-r--r--apps/app_sms.c27
2 files changed, 28 insertions, 20 deletions
diff --git a/apps/app_milliwatt.c b/apps/app_milliwatt.c
index 69fc3887f..27eb9adb5 100644
--- a/apps/app_milliwatt.c
+++ b/apps/app_milliwatt.c
@@ -71,20 +71,27 @@ static int milliwatt_generate(struct ast_channel *chan, void *data, int len, int
{
struct ast_frame wf;
unsigned char buf[AST_FRIENDLY_OFFSET + 640];
- int i,*indexp = (int *) data;
-
- if (len + AST_FRIENDLY_OFFSET > sizeof(buf))
- {
- ast_log(LOG_WARNING,"Only doing %d bytes (%d bytes requested)\n",(int)(sizeof(buf) - AST_FRIENDLY_OFFSET),len);
- len = sizeof(buf) - AST_FRIENDLY_OFFSET;
+ const int maxsamples = sizeof (buf) / sizeof (buf[0]);
+ int i, *indexp = (int *) data;
+
+ /* 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 samples (%d requested)\n", maxsamples, samples);
+ samples = maxsamples;
}
+ len = samples * sizeof (buf[0]);
wf.frametype = AST_FRAME_VOICE;
wf.subclass = AST_FORMAT_ULAW;
wf.offset = AST_FRIENDLY_OFFSET;
wf.mallocd = 0;
wf.data = buf + AST_FRIENDLY_OFFSET;
wf.datalen = len;
- wf.samples = wf.datalen;
+ wf.samples = samples;
wf.src = "app_milliwatt";
wf.delivery.tv_sec = 0;
wf.delivery.tv_usec = 0;
diff --git a/apps/app_sms.c b/apps/app_sms.c
index d9b85bfaa..a607d359e 100644
--- a/apps/app_sms.c
+++ b/apps/app_sms.c
@@ -1177,32 +1177,31 @@ static int sms_generate (struct ast_channel *chan, void *data, int len, int samp
{
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;
@@ -1254,6 +1253,8 @@ static int sms_generate (struct ast_channel *chan, void *data, int len, int samp
return -1;
}
return 0;
+#undef SAMPLE2LEN
+#undef MAXSAMPLES
}
static void sms_process (sms_t * h, int samples, signed short *data)