aboutsummaryrefslogtreecommitdiffstats
path: root/formats/format_pcm.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-16 16:12:51 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-16 16:12:51 +0000
commit74600d9030a3cbd53b43ccda099e482aed7357cb (patch)
tree9833feece35fa9711477b198d46dab2c6d58e60d /formats/format_pcm.c
parent897d8edb51ed4288446304ec5c6811ea4cff540d (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_pcm.c')
-rwxr-xr-xformats/format_pcm.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index dc16935b9..dcfc3ea77 100755
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -48,7 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
struct ast_filestream {
void *reserved[AST_RESERVED_POINTERS];
/* This is what a filestream means to us */
- int fd; /* Descriptor */
+ FILE *f; /* Descriptor */
struct ast_channel *owner;
struct ast_frame fr; /* Frame information */
char waste[AST_FRIENDLY_OFFSET]; /* Buffer for sending frames, etc */
@@ -65,7 +65,7 @@ static char *name = "pcm";
static char *desc = "Raw uLaw 8khz Audio support (PCM)";
static char *exts = "pcm|ulaw|ul|mu";
-static struct ast_filestream *pcm_open(int fd)
+static struct ast_filestream *pcm_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
@@ -78,7 +78,7 @@ static struct ast_filestream *pcm_open(int fd)
free(tmp);
return NULL;
}
- tmp->fd = fd;
+ tmp->f = f;
tmp->fr.data = tmp->buf;
tmp->fr.frametype = AST_FRAME_VOICE;
tmp->fr.subclass = AST_FORMAT_ULAW;
@@ -92,7 +92,7 @@ static struct ast_filestream *pcm_open(int fd)
return tmp;
}
-static struct ast_filestream *pcm_rewrite(int fd, const char *comment)
+static struct ast_filestream *pcm_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
@@ -105,7 +105,7 @@ static struct ast_filestream *pcm_rewrite(int fd, const char *comment)
free(tmp);
return NULL;
}
- tmp->fd = fd;
+ tmp->f = f;
glistcnt++;
ast_mutex_unlock(&pcm_lock);
ast_update_use_count();
@@ -123,7 +123,7 @@ static void pcm_close(struct ast_filestream *s)
glistcnt--;
ast_mutex_unlock(&pcm_lock);
ast_update_use_count();
- close(s->fd);
+ fclose(s->f);
free(s);
s = NULL;
}
@@ -139,7 +139,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
s->fr.offset = AST_FRIENDLY_OFFSET;
s->fr.mallocd = 0;
s->fr.data = s->buf;
- if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+ if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
if (res)
ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
return NULL;
@@ -162,7 +162,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
ast_log(LOG_WARNING, "Asked to write non-ulaw frame (%d)!\n", f->subclass);
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/%d): %s\n", res, f->datalen, strerror(errno));
return -1;
}
@@ -174,8 +174,9 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
off_t offset=0,min,cur,max;
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);
if (whence == SEEK_SET)
offset = sample_offset;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -187,18 +188,18 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
}
/* always protect against seeking past begining. */
offset = (offset < min)?min:offset;
- return lseek(fs->fd, offset, SEEK_SET);
+ return fseek(fs->f, offset, SEEK_SET);
}
static int pcm_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 pcm_tell(struct ast_filestream *fs)
{
off_t offset;
- offset = lseek(fs->fd, 0, SEEK_CUR);
+ offset = ftell(fs->f);
return offset;
}