diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-16 16:12:51 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-16 16:12:51 +0000 |
commit | 74600d9030a3cbd53b43ccda099e482aed7357cb (patch) | |
tree | 9833feece35fa9711477b198d46dab2c6d58e60d /formats/format_gsm.c | |
parent | 897d8edb51ed4288446304ec5c6811ea4cff540d (diff) |
Use FILE * instead of fd for files to support buffering
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6801 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'formats/format_gsm.c')
-rwxr-xr-x | formats/format_gsm.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/formats/format_gsm.c b/formats/format_gsm.c index 8a218024e..ec92f7138 100755 --- a/formats/format_gsm.c +++ b/formats/format_gsm.c @@ -62,7 +62,7 @@ struct ast_filestream { /* Believe it or not, we must decode/recode to account for the weird MS format */ /* This is what a filestream means to us */ - int fd; /* Descriptor */ + FILE *f; /* Descriptor */ struct ast_frame fr; /* Frame information */ char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */ char empty; /* Empty character */ @@ -77,7 +77,7 @@ static char *name = "gsm"; static char *desc = "Raw GSM data"; static char *exts = "gsm"; -static struct ast_filestream *gsm_open(int fd) +static struct ast_filestream *gsm_open(FILE *f) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check @@ -90,7 +90,7 @@ static struct ast_filestream *gsm_open(int fd) free(tmp); return NULL; } - tmp->fd = fd; + tmp->f = f; tmp->fr.data = tmp->gsm; tmp->fr.frametype = AST_FRAME_VOICE; tmp->fr.subclass = AST_FORMAT_GSM; @@ -104,7 +104,7 @@ static struct ast_filestream *gsm_open(int fd) return tmp; } -static struct ast_filestream *gsm_rewrite(int fd, const char *comment) +static struct ast_filestream *gsm_rewrite(FILE *f, const char *comment) { /* We don't have any header to read or anything really, but if we did, it would go here. We also might want to check @@ -117,7 +117,7 @@ static struct ast_filestream *gsm_rewrite(int fd, const char *comment) free(tmp); return NULL; } - tmp->fd = fd; + tmp->f = f; glistcnt++; ast_mutex_unlock(&gsm_lock); ast_update_use_count(); @@ -135,7 +135,7 @@ static void gsm_close(struct ast_filestream *s) glistcnt--; ast_mutex_unlock(&gsm_lock); ast_update_use_count(); - close(s->fd); + fclose(s->f); free(s); } @@ -149,7 +149,7 @@ static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext) s->fr.datalen = 33; s->fr.mallocd = 0; s->fr.data = s->gsm; - if ((res = read(s->fd, s->gsm, 33)) != 33) { + if ((res = fread(s->gsm, 1, 33, s->f)) != 33) { if (res) ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); return NULL; @@ -175,7 +175,7 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f) int len=0; while(len < f->datalen) { conv65(f->data + len, gsm); - if ((res = write(fs->fd, gsm, 66)) != 66) { + if ((res = fwrite(gsm, 1, 66, fs->f)) != 66) { ast_log(LOG_WARNING, "Bad write (%d/66): %s\n", res, strerror(errno)); return -1; } @@ -186,7 +186,7 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f) ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 33\n", f->datalen); return -1; } - if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) { + if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) { ast_log(LOG_WARNING, "Bad write (%d/33): %s\n", res, strerror(errno)); return -1; } @@ -199,8 +199,9 @@ static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence) off_t offset=0,min,cur,max,distance; min = 0; - cur = lseek(fs->fd, 0, SEEK_CUR); - max = lseek(fs->fd, 0, SEEK_END); + cur = ftell(fs->f); + fseek(fs->f, 0, SEEK_END); + max = ftell(fs->f); /* have to fudge to frame here, so not fully to sample */ distance = (sample_offset/160) * 33; if(whence == SEEK_SET) @@ -215,23 +216,23 @@ static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence) offset = (offset > max)?max:offset; } else if (offset > max) { int i; - lseek(fs->fd, 0, SEEK_END); + fseek(fs->f, 0, SEEK_END); for (i=0; i< (offset - max) / 33; i++) { - write(fs->fd, gsm_silence, 33); + fwrite(gsm_silence, 1, 33, fs->f); } } - return lseek(fs->fd, offset, SEEK_SET); + return fseek(fs->f, offset, SEEK_SET); } static int gsm_trunc(struct ast_filestream *fs) { - return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR)); + return ftruncate(fileno(fs->f), ftell(fs->f)); } static long gsm_tell(struct ast_filestream *fs) { off_t offset; - offset = lseek(fs->fd, 0, SEEK_CUR); + offset = ftell(fs->f); return (offset/33)*160; } |