Version 0.2.0 from FTP

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@516 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2002-09-04 05:09:41 +00:00
parent 1681e18ce8
commit 8cd708fbeb
2 changed files with 46 additions and 7 deletions

View File

@@ -214,6 +214,7 @@ int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len)
/* Date */ /* Date */
break; break;
case 2: /* Number */ case 2: /* Number */
case 3: /* Number (for Zebble) */
case 4: /* Number */ case 4: /* Number */
res = cid->rawdata[x]; res = cid->rawdata[x];
if (res > 32) { if (res > 32) {

View File

@@ -38,6 +38,7 @@ struct ast_filestream {
/* This is what a filestream means to us */ /* This is what a filestream means to us */
int fd; /* Descriptor */ int fd; /* Descriptor */
int bytes; int bytes;
int needsgain;
struct ast_channel *owner; struct ast_channel *owner;
struct ast_frame fr; /* Frame information */ struct ast_frame fr; /* Frame information */
char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
@@ -61,6 +62,8 @@ static char *exts = "wav";
#define BLOCKSIZE 160 #define BLOCKSIZE 160
#define GAIN 2 /* 2^GAIN is the multiple to increase the volume by */
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
#define htoll(b) (b) #define htoll(b) (b)
#define htols(b) (b) #define htols(b) (b)
@@ -306,6 +309,7 @@ static struct ast_filestream *wav_open(int fd)
glist = tmp; glist = tmp;
tmp->fd = fd; tmp->fd = fd;
tmp->owner = NULL; tmp->owner = NULL;
tmp->needsgain = 1;
tmp->fr.data = tmp->buf; tmp->fr.data = tmp->buf;
tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.frametype = AST_FRAME_VOICE;
tmp->fr.subclass = AST_FORMAT_SLINEAR; tmp->fr.subclass = AST_FORMAT_SLINEAR;
@@ -402,16 +406,33 @@ static int ast_read_callback(void *data)
int retval = 0; int retval = 0;
int res; int res;
int delay; int delay;
int x;
struct ast_filestream *s = data; struct ast_filestream *s = data;
short tmp[sizeof(s->buf) / 2];
/* Send a frame from the file to the appropriate channel */ /* Send a frame from the file to the appropriate channel */
if ( (res = read(s->fd, s->buf, sizeof(s->buf))) <= 0 ) { if ( (res = read(s->fd, tmp, sizeof(tmp))) <= 0 ) {
if (res) { if (res) {
ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
} }
s->owner->streamid = -1; s->owner->streamid = -1;
return 0; return 0;
} }
if (s->needsgain) {
for (x=0;x<sizeof(tmp)/2;x++)
if (tmp[x] & ((1 << GAIN) - 1)) {
/* If it has data down low, then it's not something we've artificially increased gain
on, so we don't need to gain adjust it */
s->needsgain = 0;
}
}
if (s->needsgain) {
for (x=0;x<sizeof(tmp)/2;x++) {
s->buf[x] = tmp[x] >> GAIN;
}
} else {
memcpy(s->buf, tmp, sizeof(s->buf));
}
delay = res / 16; delay = res / 16;
s->fr.frametype = AST_FRAME_VOICE; s->fr.frametype = AST_FRAME_VOICE;
@@ -451,9 +472,9 @@ static int wav_apply(struct ast_channel *c, struct ast_filestream *s)
static int wav_write(struct ast_filestream *fs, struct ast_frame *f) static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
{ {
int res = 0; int res = 0;
#if 0 int x;
int size = 0; short tmp[8000], *tmpi;
#endif float tmpf;
if (f->frametype != AST_FRAME_VOICE) { if (f->frametype != AST_FRAME_VOICE) {
ast_log(LOG_WARNING, "Asked to write non-voice frame!\n"); ast_log(LOG_WARNING, "Asked to write non-voice frame!\n");
return -1; return -1;
@@ -462,13 +483,30 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass); ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass);
return -1; return -1;
} }
if (f->datalen > sizeof(tmp)) {
ast_log(LOG_WARNING, "Data length is too long\n");
return -1;
}
if (!f->datalen)
return -1;
#if 0 #if 0
printf("Data Length: %d\n", f->datalen); printf("Data Length: %d\n", f->datalen);
#endif #endif
if (fs->buf) { if (fs->buf) {
if ((write (fs->fd, f->data, f->datalen) != f->datalen) ) { tmpi = f->data;
/* Volume adjust here to accomodate */
for (x=0;x<f->datalen/2;x++) {
tmpf = ((float)tmpi[x]) * ((float)(1 << GAIN));
if (tmpf > 32767.0)
tmpf = 32767.0;
if (tmpf < -32768.0)
tmpf = -32768.0;
tmp[x] = tmpf;
tmp[x] &= ~((1 << GAIN) - 1);
}
if ((write (fs->fd, tmp, f->datalen) != f->datalen) ) {
ast_log(LOG_WARNING, "Bad write (%d): %s\n", res, strerror(errno)); ast_log(LOG_WARNING, "Bad write (%d): %s\n", res, strerror(errno));
return -1; return -1;
} }
@@ -513,7 +551,7 @@ int unload_module()
tmp = glist; tmp = glist;
while(tmp) { while(tmp) {
if (tmp->owner) if (tmp->owner)
ast_softhangup(tmp->owner); ast_softhangup(tmp->owner, AST_SOFTHANGUP_APPUNLOAD);
tmpl = tmp; tmpl = tmp;
tmp = tmp->next; tmp = tmp->next;
free(tmpl); free(tmpl);